Changeset 22796 for branches/version-2_12-dev/data/class/pages/admin/design/LC_Page_Admin_Design_Bloc.php
- Timestamp:
- 2013/05/02 18:11:36 (11 years ago)
- 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 32 32 * @version $Id$ 33 33 */ 34 class LC_Page_Admin_Design_Bloc extends LC_Page_Admin_Ex 35 { 34 class LC_Page_Admin_Design_Bloc extends LC_Page_Admin_Ex { 36 35 37 36 // }}} … … 43 42 * @return void 44 43 */ 45 function init() 46 { 44 function init() { 47 45 parent::init(); 48 46 $this->tpl_mainpage = 'design/bloc.tpl'; … … 62 60 * @return void 63 61 */ 64 function process() 65 { 62 function process() { 66 63 $this->action(); 67 64 $this->sendResponse(); … … 73 70 * @return void 74 71 */ 75 function action() 76 { 72 function action() { 77 73 78 74 $objFormParam = new SC_FormParam_Ex(); … … 86 82 $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC); 87 83 88 $objBloc = new SC_Helper_Bloc_Ex($this->device_type_id);89 84 $objLayout = new SC_Helper_PageLayout_Ex(); 90 85 … … 93 88 case 'confirm': 94 89 if (!$is_error) { 95 $this->arrErr = $this->lfCheckError($objFormParam, $this->arrErr, $obj Bloc);90 $this->arrErr = $this->lfCheckError($objFormParam, $this->arrErr, $objLayout); 96 91 if (SC_Utils_Ex::isBlank($this->arrErr)) { 97 $result = $this->doRegister($objFormParam, $obj Bloc);92 $result = $this->doRegister($objFormParam, $objLayout); 98 93 if ($result !== false) { 99 94 $arrPram = array( … … 113 108 case 'delete': 114 109 if (!$is_error) { 115 if ($this->doDelete($objFormParam, $obj Bloc)) {110 if ($this->doDelete($objFormParam, $objLayout)) { 116 111 $arrPram = array( 117 112 'device_type_id' => $this->device_type_id, … … 135 130 if (!$is_error) { 136 131 // ブロック一覧を取得 137 $this->arrBlocList = $obj Bloc->getList();132 $this->arrBlocList = $objLayout->getBlocs($this->device_type_id); 138 133 // bloc_id が指定されている場合にはブロックデータの取得 139 134 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); 141 136 $objFormParam->setParam($arrBloc); 142 137 } … … 155 150 * @return void 156 151 */ 157 function destroy() 158 { 152 function destroy() { 159 153 parent::destroy(); 160 154 } … … 166 160 * @return void 167 161 */ 168 function lfInitParam(&$objFormParam) 169 { 162 function lfInitParam(&$objFormParam) { 170 163 $objFormParam->addParam('ブロックID', 'bloc_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); 171 164 $objFormParam->addParam('端末種別ID', 'device_type_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); … … 178 171 * ブロックのテンプレートを取得する. 179 172 * 173 * @param integer $device_type_id 端末種別ID 180 174 * @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 インスタンス 182 176 * @return array ブロック情報の配列 183 177 */ 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]; 188 189 } 189 190 … … 195 196 * 196 197 * @param SC_FormParam $objFormParam SC_FormParam インスタンス 197 * @param SC_Helper_ Bloc $objBloc SC_Helper_Blocインスタンス198 * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス 198 199 * @return integer|boolean 登録が成功した場合, 登録したブロックID; 199 200 * 失敗した場合 false 200 201 */ 201 function doRegister(&$objFormParam, SC_Helper_Bloc_Ex &$objBloc) 202 { 202 function doRegister(&$objFormParam, &$objLayout) { 203 203 $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'])) { 207 243 $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']; 211 250 } 212 251 … … 215 254 * 216 255 * @param SC_FormParam $objFormParam SC_FormParam インスタンス 217 * @param SC_Helper_ Bloc $objBloc SC_Helper_Blocインスタンス256 * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス 218 257 * @return boolean 登録が成功した場合 true; 失敗した場合 false 219 258 */ 220 function doDelete(&$objFormParam, SC_Helper_Bloc_Ex &$objBloc) 221 { 259 function doDelete(&$objFormParam, &$objLayout) { 222 260 $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) { 226 287 $this->arrErr['err'] = '※ ブロックの削除に失敗しました<br />'; 227 } 228 229 return $result; 288 $objQuery->rollback(); 289 return false; 290 } 291 $objQuery->commit(); 292 return true; 230 293 } 231 294 … … 236 299 * @return array エラーメッセージの配列 237 300 */ 238 function lfCheckError(&$objFormParam, &$arrErr, SC_Helper_Bloc_Ex &$objBloc) 239 { 301 function lfCheckError(&$objFormParam, &$arrErr, &$objLayout) { 240 302 $arrParams = $objFormParam->getHashArray(); 241 303 $objErr = new SC_CheckError_Ex($arrParams); … … 252 314 $arrValues[] = $arrParams['bloc_id']; 253 315 } 254 $arrBloc = $obj Bloc->getWhere($where, $arrValues);316 $arrBloc = $objLayout->getBlocs($arrParams['device_type_id'], $where, $arrValues); 255 317 if (!SC_Utils_Ex::isBlank($arrBloc)) { 256 318 $objErr->arrErr['filename'] = '※ 同じファイル名のデータが存在しています。別のファイル名を入力してください。<br />';
Note: See TracChangeset
for help on using the changeset viewer.