Ignore:
Timestamp:
2013/05/02 18:11:36 (11 years ago)
Author:
h_yoshimoto
Message:

#2236 2.12.3リリース以降の2.12-devへのコミット差し戻し

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_12-dev/data/class/pages/admin/design/LC_Page_Admin_Design_Bloc.php

    r22610 r22796  
    3232 * @version $Id$ 
    3333 */ 
    34 class LC_Page_Admin_Design_Bloc extends LC_Page_Admin_Ex  
    35 { 
     34class LC_Page_Admin_Design_Bloc extends LC_Page_Admin_Ex { 
    3635 
    3736    // }}} 
     
    4342     * @return void 
    4443     */ 
    45     function init() 
    46     { 
     44    function init() { 
    4745        parent::init(); 
    4846        $this->tpl_mainpage = 'design/bloc.tpl'; 
     
    6260     * @return void 
    6361     */ 
    64     function process() 
    65     { 
     62    function process() { 
    6663        $this->action(); 
    6764        $this->sendResponse(); 
     
    7370     * @return void 
    7471     */ 
    75     function action() 
    76     { 
     72    function action() { 
    7773 
    7874        $objFormParam = new SC_FormParam_Ex(); 
     
    8682        $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC); 
    8783 
    88         $objBloc = new SC_Helper_Bloc_Ex($this->device_type_id); 
    8984        $objLayout = new SC_Helper_PageLayout_Ex(); 
    9085 
     
    9388            case 'confirm': 
    9489                if (!$is_error) { 
    95                     $this->arrErr = $this->lfCheckError($objFormParam, $this->arrErr, $objBloc); 
     90                    $this->arrErr = $this->lfCheckError($objFormParam, $this->arrErr, $objLayout); 
    9691                    if (SC_Utils_Ex::isBlank($this->arrErr)) { 
    97                         $result = $this->doRegister($objFormParam, $objBloc); 
     92                        $result = $this->doRegister($objFormParam, $objLayout); 
    9893                        if ($result !== false) { 
    9994                            $arrPram = array( 
     
    113108            case 'delete': 
    114109                if (!$is_error) { 
    115                     if ($this->doDelete($objFormParam, $objBloc)) { 
     110                    if ($this->doDelete($objFormParam, $objLayout)) { 
    116111                        $arrPram = array( 
    117112                            'device_type_id' => $this->device_type_id, 
     
    135130        if (!$is_error) { 
    136131            // ブロック一覧を取得 
    137             $this->arrBlocList = $objBloc->getList(); 
     132            $this->arrBlocList = $objLayout->getBlocs($this->device_type_id); 
    138133            // bloc_id が指定されている場合にはブロックデータの取得 
    139134            if (!SC_Utils_Ex::isBlank($this->bloc_id)) { 
    140                 $arrBloc = $this->getBlocTemplate($this->bloc_id, $objBloc); 
     135                $arrBloc = $this->getBlocTemplate($this->device_type_id, $this->bloc_id, $objLayout); 
    141136                $objFormParam->setParam($arrBloc); 
    142137            } 
     
    155150     * @return void 
    156151     */ 
    157     function destroy() 
    158     { 
     152    function destroy() { 
    159153        parent::destroy(); 
    160154    } 
     
    166160     * @return void 
    167161     */ 
    168     function lfInitParam(&$objFormParam) 
    169     { 
     162    function lfInitParam(&$objFormParam) { 
    170163        $objFormParam->addParam('ブロックID', 'bloc_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); 
    171164        $objFormParam->addParam('端末種別ID', 'device_type_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); 
     
    178171     * ブロックのテンプレートを取得する. 
    179172     * 
     173     * @param integer $device_type_id 端末種別ID 
    180174     * @param integer $bloc_id ブロックID 
    181      * @param SC_Helper_Bloc_Ex $objBloc SC_Helper_Bloc_Ex インスタンス 
     175     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス 
    182176     * @return array ブロック情報の配列 
    183177     */ 
    184     function getBlocTemplate($bloc_id, SC_Helper_Bloc_Ex &$objBloc) 
    185     { 
    186         $arrBloc = $objBloc->get($bloc_id); 
    187         return $arrBloc; 
     178    function getBlocTemplate($device_type_id, $bloc_id, &$objLayout) { 
     179        $arrBloc = $objLayout->getBlocs($device_type_id, 'bloc_id = ?', array($bloc_id)); 
     180        if (SC_Utils_Ex::isAbsoluteRealPath($arrBloc[0]['tpl_path'])) { 
     181            $tpl_path = $arrBloc[0]['tpl_path']; 
     182        } else { 
     183            $tpl_path = SC_Helper_PageLayout_Ex::getTemplatePath($device_type_id) . BLOC_DIR . $arrBloc[0]['tpl_path']; 
     184        } 
     185        if (file_exists($tpl_path)) { 
     186            $arrBloc[0]['bloc_html'] = file_get_contents($tpl_path); 
     187        } 
     188        return $arrBloc[0]; 
    188189    } 
    189190 
     
    195196     * 
    196197     * @param SC_FormParam $objFormParam SC_FormParam インスタンス 
    197      * @param SC_Helper_Bloc $objBloc SC_Helper_Bloc インスタンス 
     198     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス 
    198199     * @return integer|boolean 登録が成功した場合, 登録したブロックID; 
    199200     *                         失敗した場合 false 
    200201     */ 
    201     function doRegister(&$objFormParam, SC_Helper_Bloc_Ex &$objBloc) 
    202     { 
     202    function doRegister(&$objFormParam, &$objLayout) { 
    203203        $arrParams = $objFormParam->getHashArray(); 
    204         $result = $objBloc->save($arrParams); 
    205  
    206         if (!$result) { 
     204 
     205        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     206        $objQuery->begin(); 
     207 
     208        // blod_id が空の場合は新規登録 
     209        $is_new = SC_Utils_Ex::isBlank($arrParams['bloc_id']); 
     210        $bloc_dir = $objLayout->getTemplatePath($arrParams['device_type_id']) . BLOC_DIR; 
     211        // 既存データの重複チェック 
     212        if (!$is_new) { 
     213            $arrExists = $objLayout->getBlocs($arrParams['device_type_id'], 'bloc_id = ?', array($arrParams['bloc_id'])); 
     214 
     215            // 既存のファイルが存在する場合は削除しておく 
     216            $exists_file = $bloc_dir . $arrExists[0]['filename'] . '.tpl'; 
     217            if (file_exists($exists_file)) { 
     218                unlink($exists_file); 
     219            } 
     220        } 
     221 
     222        $table = 'dtb_bloc'; 
     223        $arrValues = $objQuery->extractOnlyColsOf($table, $arrParams); 
     224        $arrValues['tpl_path'] = $arrParams['filename'] . '.tpl'; 
     225        $arrValues['update_date'] = 'CURRENT_TIMESTAMP'; 
     226 
     227        // 新規登録 
     228        if ($is_new || SC_Utils_Ex::isBlank($arrExists)) { 
     229            $objQuery->setOrder(''); 
     230            $arrValues['bloc_id'] = 1 + $objQuery->max('bloc_id', $table, 'device_type_id = ?', 
     231                                                       array($arrValues['device_type_id'])); 
     232            $arrValues['create_date'] = 'CURRENT_TIMESTAMP'; 
     233            $objQuery->insert($table, $arrValues); 
     234        } 
     235        // 更新 
     236        else { 
     237            $objQuery->update($table, $arrValues, 'bloc_id = ? AND device_type_id = ?', 
     238                              array($arrValues['bloc_id'], $arrValues['device_type_id'])); 
     239        } 
     240 
     241        $bloc_path = $bloc_dir . $arrValues['tpl_path']; 
     242        if (!SC_Helper_FileManager_Ex::sfWriteFile($bloc_path, $arrParams['bloc_html'])) { 
    207243            $this->arrErr['err'] = '※ ブロックの書き込みに失敗しました<br />'; 
    208         } 
    209  
    210         return $result; 
     244            $objQuery->rollback(); 
     245            return false; 
     246        } 
     247 
     248        $objQuery->commit(); 
     249        return $arrValues['bloc_id']; 
    211250    } 
    212251 
     
    215254     * 
    216255     * @param SC_FormParam $objFormParam SC_FormParam インスタンス 
    217      * @param SC_Helper_Bloc $objBloc SC_Helper_Bloc インスタンス 
     256     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス 
    218257     * @return boolean 登録が成功した場合 true; 失敗した場合 false 
    219258     */ 
    220     function doDelete(&$objFormParam, SC_Helper_Bloc_Ex &$objBloc) 
    221     { 
     259    function doDelete(&$objFormParam, &$objLayout) { 
    222260        $arrParams = $objFormParam->getHashArray(); 
    223         $result = $objBloc->delete($arrParams['bloc_id']); 
    224  
    225         if (!$result) { 
     261        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     262        $objQuery->begin(); 
     263 
     264        $arrExists = $objLayout->getBlocs($arrParams['device_type_id'], 'bloc_id = ? AND deletable_flg = 1', 
     265                                          array($arrParams['bloc_id'])); 
     266        $is_error = false; 
     267        if (!SC_Utils_Ex::isBlank($arrExists)) { 
     268            $objQuery->delete('dtb_bloc', 'bloc_id = ? AND device_type_id = ?', 
     269                              array($arrExists[0]['bloc_id'], $arrExists[0]['device_type_id'])); 
     270            $objQuery->delete('dtb_blocposition', 'bloc_id = ? AND device_type_id = ?', 
     271                              array($arrExists[0]['bloc_id'], $arrExists[0]['device_type_id'])); 
     272 
     273            $bloc_dir = $objLayout->getTemplatePath($arrParams['device_type_id']) . BLOC_DIR; 
     274            $exists_file = $bloc_dir . $arrExists[0]['filename'] . '.tpl'; 
     275 
     276            // ファイルの削除 
     277            if (file_exists($exists_file)) { 
     278                if (!unlink($exists_file)) { 
     279                    $is_error = true; 
     280                } 
     281            } 
     282        } else { 
     283            $is_error = true; 
     284        } 
     285 
     286        if ($is_error) { 
    226287            $this->arrErr['err'] = '※ ブロックの削除に失敗しました<br />'; 
    227         } 
    228  
    229         return $result; 
     288            $objQuery->rollback(); 
     289            return false; 
     290        } 
     291        $objQuery->commit(); 
     292        return true; 
    230293    } 
    231294 
     
    236299     * @return array エラーメッセージの配列 
    237300     */ 
    238     function lfCheckError(&$objFormParam, &$arrErr, SC_Helper_Bloc_Ex &$objBloc) 
    239     { 
     301    function lfCheckError(&$objFormParam, &$arrErr, &$objLayout) { 
    240302        $arrParams = $objFormParam->getHashArray(); 
    241303        $objErr = new SC_CheckError_Ex($arrParams); 
     
    252314            $arrValues[] = $arrParams['bloc_id']; 
    253315        } 
    254         $arrBloc = $objBloc->getWhere($where, $arrValues); 
     316        $arrBloc = $objLayout->getBlocs($arrParams['device_type_id'], $where, $arrValues); 
    255317        if (!SC_Utils_Ex::isBlank($arrBloc)) { 
    256318            $objErr->arrErr['filename'] = '※ 同じファイル名のデータが存在しています。別のファイル名を入力してください。<br />'; 
Note: See TracChangeset for help on using the changeset viewer.