Changeset 22610


Ignore:
Timestamp:
2013/03/06 23:09:54 (11 years ago)
Author:
pineray
Message:

#2176 pageクラスからdtb_blocテーブルを直接指定している箇所をなくす

Location:
branches/version-2_12-dev/data
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_12-dev/data/class/helper/SC_Helper_PageLayout.php

    r22567 r22610  
    138138    function getBlocs($device_type_id = DEVICE_TYPE_PC, $where = '', $arrParams = array(), $has_realpath = true) 
    139139    { 
    140         $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    141         $where = 'device_type_id = ? ' . (SC_Utils_Ex::isBlank($where) ? $where : 'AND ' . $where); 
    142         $arrParams = array_merge(array($device_type_id), $arrParams); 
    143         $objQuery->setOrder('bloc_id'); 
    144         $arrBlocs = $objQuery->select('*', 'dtb_bloc', $where, $arrParams); 
     140        $objBloc = new SC_Helper_Bloc_Ex($device_type_id); 
     141        $arrBlocs = $objBloc->getWhere($where, $arrParams); 
    145142        if ($has_realpath) { 
    146143            $this->setBlocPathTo($device_type_id, $arrBlocs); 
  • branches/version-2_12-dev/data/class/pages/admin/design/LC_Page_Admin_Design_Bloc.php

    r22567 r22610  
    8686        $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC); 
    8787 
     88        $objBloc = new SC_Helper_Bloc_Ex($this->device_type_id); 
    8889        $objLayout = new SC_Helper_PageLayout_Ex(); 
    8990 
     
    9293            case 'confirm': 
    9394                if (!$is_error) { 
    94                     $this->arrErr = $this->lfCheckError($objFormParam, $this->arrErr, $objLayout); 
     95                    $this->arrErr = $this->lfCheckError($objFormParam, $this->arrErr, $objBloc); 
    9596                    if (SC_Utils_Ex::isBlank($this->arrErr)) { 
    96                         $result = $this->doRegister($objFormParam, $objLayout); 
     97                        $result = $this->doRegister($objFormParam, $objBloc); 
    9798                        if ($result !== false) { 
    9899                            $arrPram = array( 
     
    112113            case 'delete': 
    113114                if (!$is_error) { 
    114                     if ($this->doDelete($objFormParam, $objLayout)) { 
     115                    if ($this->doDelete($objFormParam, $objBloc)) { 
    115116                        $arrPram = array( 
    116117                            'device_type_id' => $this->device_type_id, 
     
    134135        if (!$is_error) { 
    135136            // ブロック一覧を取得 
    136             $this->arrBlocList = $objLayout->getBlocs($this->device_type_id); 
     137            $this->arrBlocList = $objBloc->getList(); 
    137138            // bloc_id が指定されている場合にはブロックデータの取得 
    138139            if (!SC_Utils_Ex::isBlank($this->bloc_id)) { 
    139                 $arrBloc = $this->getBlocTemplate($this->device_type_id, $this->bloc_id, $objLayout); 
     140                $arrBloc = $this->getBlocTemplate($this->bloc_id, $objBloc); 
    140141                $objFormParam->setParam($arrBloc); 
    141142            } 
     
    177178     * ブロックのテンプレートを取得する. 
    178179     * 
    179      * @param integer $device_type_id 端末種別ID 
    180180     * @param integer $bloc_id ブロックID 
    181      * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス 
     181     * @param SC_Helper_Bloc_Ex $objBloc SC_Helper_Bloc_Ex インスタンス 
    182182     * @return array ブロック情報の配列 
    183183     */ 
    184     function getBlocTemplate($device_type_id, $bloc_id, &$objLayout) 
    185     { 
    186         $arrBloc = $objLayout->getBlocs($device_type_id, 'bloc_id = ?', array($bloc_id)); 
    187         if (SC_Utils_Ex::isAbsoluteRealPath($arrBloc[0]['tpl_path'])) { 
    188             $tpl_path = $arrBloc[0]['tpl_path']; 
    189         } else { 
    190             $tpl_path = SC_Helper_PageLayout_Ex::getTemplatePath($device_type_id) . BLOC_DIR . $arrBloc[0]['tpl_path']; 
    191         } 
    192         if (file_exists($tpl_path)) { 
    193             $arrBloc[0]['bloc_html'] = file_get_contents($tpl_path); 
    194         } 
    195         return $arrBloc[0]; 
     184    function getBlocTemplate($bloc_id, SC_Helper_Bloc_Ex &$objBloc) 
     185    { 
     186        $arrBloc = $objBloc->get($bloc_id); 
     187        return $arrBloc; 
    196188    } 
    197189 
     
    203195     * 
    204196     * @param SC_FormParam $objFormParam SC_FormParam インスタンス 
    205      * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス 
     197     * @param SC_Helper_Bloc $objBloc SC_Helper_Bloc インスタンス 
    206198     * @return integer|boolean 登録が成功した場合, 登録したブロックID; 
    207199     *                         失敗した場合 false 
    208200     */ 
    209     function doRegister(&$objFormParam, &$objLayout) 
     201    function doRegister(&$objFormParam, SC_Helper_Bloc_Ex &$objBloc) 
    210202    { 
    211203        $arrParams = $objFormParam->getHashArray(); 
    212  
    213         $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    214         $objQuery->begin(); 
    215  
    216         // blod_id が空の場合は新規登録 
    217         $is_new = SC_Utils_Ex::isBlank($arrParams['bloc_id']); 
    218         $bloc_dir = $objLayout->getTemplatePath($arrParams['device_type_id']) . BLOC_DIR; 
    219         // 既存データの重複チェック 
    220         if (!$is_new) { 
    221             $arrExists = $objLayout->getBlocs($arrParams['device_type_id'], 'bloc_id = ?', array($arrParams['bloc_id'])); 
    222  
    223             // 既存のファイルが存在する場合は削除しておく 
    224             $exists_file = $bloc_dir . $arrExists[0]['filename'] . '.tpl'; 
    225             if (file_exists($exists_file)) { 
    226                 unlink($exists_file); 
    227             } 
    228         } 
    229  
    230         $table = 'dtb_bloc'; 
    231         $arrValues = $objQuery->extractOnlyColsOf($table, $arrParams); 
    232         $arrValues['tpl_path'] = $arrParams['filename'] . '.tpl'; 
    233         $arrValues['update_date'] = 'CURRENT_TIMESTAMP'; 
    234  
    235         // 新規登録 
    236         if ($is_new || SC_Utils_Ex::isBlank($arrExists)) { 
    237             $objQuery->setOrder(''); 
    238             $arrValues['bloc_id'] = 1 + $objQuery->max('bloc_id', $table, 'device_type_id = ?', 
    239                                                        array($arrValues['device_type_id'])); 
    240             $arrValues['create_date'] = 'CURRENT_TIMESTAMP'; 
    241             $objQuery->insert($table, $arrValues); 
    242         } 
    243         // 更新 
    244         else { 
    245             $objQuery->update($table, $arrValues, 'bloc_id = ? AND device_type_id = ?', 
    246                               array($arrValues['bloc_id'], $arrValues['device_type_id'])); 
    247         } 
    248  
    249         $bloc_path = $bloc_dir . $arrValues['tpl_path']; 
    250         if (!SC_Helper_FileManager_Ex::sfWriteFile($bloc_path, $arrParams['bloc_html'])) { 
     204        $result = $objBloc->save($arrParams); 
     205 
     206        if (!$result) { 
    251207            $this->arrErr['err'] = '※ ブロックの書き込みに失敗しました<br />'; 
    252             $objQuery->rollback(); 
    253             return false; 
    254         } 
    255  
    256         $objQuery->commit(); 
    257         return $arrValues['bloc_id']; 
     208        } 
     209 
     210        return $result; 
    258211    } 
    259212 
     
    262215     * 
    263216     * @param SC_FormParam $objFormParam SC_FormParam インスタンス 
    264      * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス 
     217     * @param SC_Helper_Bloc $objBloc SC_Helper_Bloc インスタンス 
    265218     * @return boolean 登録が成功した場合 true; 失敗した場合 false 
    266219     */ 
    267     function doDelete(&$objFormParam, &$objLayout) 
     220    function doDelete(&$objFormParam, SC_Helper_Bloc_Ex &$objBloc) 
    268221    { 
    269222        $arrParams = $objFormParam->getHashArray(); 
    270         $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    271         $objQuery->begin(); 
    272  
    273         $arrExists = $objLayout->getBlocs($arrParams['device_type_id'], 'bloc_id = ? AND deletable_flg = 1', 
    274                                           array($arrParams['bloc_id'])); 
    275         $is_error = false; 
    276         if (!SC_Utils_Ex::isBlank($arrExists)) { 
    277             $objQuery->delete('dtb_bloc', 'bloc_id = ? AND device_type_id = ?', 
    278                               array($arrExists[0]['bloc_id'], $arrExists[0]['device_type_id'])); 
    279             $objQuery->delete('dtb_blocposition', 'bloc_id = ? AND device_type_id = ?', 
    280                               array($arrExists[0]['bloc_id'], $arrExists[0]['device_type_id'])); 
    281  
    282             $bloc_dir = $objLayout->getTemplatePath($arrParams['device_type_id']) . BLOC_DIR; 
    283             $exists_file = $bloc_dir . $arrExists[0]['filename'] . '.tpl'; 
    284  
    285             // ファイルの削除 
    286             if (file_exists($exists_file)) { 
    287                 if (!unlink($exists_file)) { 
    288                     $is_error = true; 
    289                 } 
    290             } 
    291         } else { 
    292             $is_error = true; 
    293         } 
    294  
    295         if ($is_error) { 
     223        $result = $objBloc->delete($arrParams['bloc_id']); 
     224 
     225        if (!$result) { 
    296226            $this->arrErr['err'] = '※ ブロックの削除に失敗しました<br />'; 
    297             $objQuery->rollback(); 
    298             return false; 
    299         } 
    300         $objQuery->commit(); 
    301         return true; 
     227        } 
     228 
     229        return $result; 
    302230    } 
    303231 
     
    308236     * @return array エラーメッセージの配列 
    309237     */ 
    310     function lfCheckError(&$objFormParam, &$arrErr, &$objLayout) 
     238    function lfCheckError(&$objFormParam, &$arrErr, SC_Helper_Bloc_Ex &$objBloc) 
    311239    { 
    312240        $arrParams = $objFormParam->getHashArray(); 
     
    324252            $arrValues[] = $arrParams['bloc_id']; 
    325253        } 
    326         $arrBloc = $objLayout->getBlocs($arrParams['device_type_id'], $where, $arrValues); 
     254        $arrBloc = $objBloc->getWhere($where, $arrValues); 
    327255        if (!SC_Utils_Ex::isBlank($arrBloc)) { 
    328256            $objErr->arrErr['filename'] = '※ 同じファイル名のデータが存在しています。別のファイル名を入力してください。<br />'; 
Note: See TracChangeset for help on using the changeset viewer.