/** * ブロックのレイアウト情報を取得する. * * @param integer $device_type_id 端末種別ID * @param integer $page_id ページID * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス * @return array レイアウト情報の配列 */ function getLayout($device_type_id, $page_id, &$objLayout) { $arrResults = array(); $i = 0; // レイアウト済みのブロックデータを追加 $arrBlocPos = $objLayout->getBlocPositions($device_type_id, $page_id); foreach ($arrBlocPos as $arrBloc) { $this->copyBloc($arrResults, $arrBloc, $i); $i++; } // 未使用のブロックデータを追加 $arrBloc = $objLayout->getBlocs($device_type_id); foreach ($arrBloc as $arrBloc) { if (!$this->existsBloc($arrBloc, $arrResults)) { $arrBloc['target_id'] = TARGET_ID_UNUSED; $this->copyBloc($arrResults, $arrBloc, $i); $i++; } } return $arrResults; }
/** * 削除を実行する. * * @param SC_FormParam $objFormParam SC_FormParam インスタンス * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス * @return boolean 登録が成功した場合 true; 失敗した場合 false */ function doDelete(&$objFormParam, &$objLayout) { $arrParams = $objFormParam->getHashArray(); $objQuery =& SC_Query_Ex::getSingletonInstance(); $objQuery->begin(); $arrExists = $objLayout->getBlocs($arrParams['device_type_id'], 'bloc_id = ? AND deletable_flg = 1', array($arrParams['bloc_id'])); $is_error = false; if (!SC_Utils_Ex::isBlank($arrExists)) { $objQuery->delete('dtb_bloc', 'bloc_id = ? AND device_type_id = ?', array($arrExists[0]['bloc_id'], $arrExists[0]['device_type_id'])); $objQuery->delete('dtb_blocposition', 'bloc_id = ? AND device_type_id = ?', array($arrExists[0]['bloc_id'], $arrExists[0]['device_type_id'])); $bloc_dir = $objLayout->getTemplatePath($arrParams['device_type_id']) . BLOC_DIR; $exists_file = $bloc_dir . $arrExists[0]['filename'] . '.tpl'; // ファイルの削除 if (file_exists($exists_file)) { if (!unlink($exists_file)) { $is_error = true; } } } else { $is_error = true; } if ($is_error) { $this->arrErr['err'] = '※ ブロックの削除に失敗しました<br />'; $objQuery->rollback(); return false; } $objQuery->commit(); return true; }
/** * 登録を実行する. * * ファイルの作成に失敗した場合は, エラーメッセージを出力し, * データベースをロールバックする. * * @param SC_FormParam $objFormParam SC_FormParam インスタンス * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス * @return integer|boolean 登録が成功した場合, 登録したブロックID; * 失敗した場合 false */ function doRegister(&$objFormParam, &$objLayout) { $arrParams = $objFormParam->getHashArray(); $objQuery =& SC_Query_Ex::getSingletonInstance(); $objQuery->begin(); // blod_id が空の場合は新規登録 $is_new = SC_Utils_Ex::isBlank($arrParams['bloc_id']); $bloc_dir = $objLayout->getTemplatePath($arrParams['device_type_id']) . BLOC_DIR; // 既存データの重複チェック if (!$is_new) { $arrExists = $objLayout->getBlocs($arrParams['device_type_id'], 'bloc_id = ?', array($arrParams['bloc_id'])); // 既存のファイルが存在する場合は削除しておく $exists_file = $bloc_dir . $arrExists[0]['filename'] . '.tpl'; if (file_exists($exists_file)) { unlink($exists_file); } } $table = 'dtb_bloc'; $arrValues = $objQuery->extractOnlyColsOf($table, $arrParams); $arrValues['tpl_path'] = $arrParams['filename'] . '.tpl'; $arrValues['update_date'] = 'CURRENT_TIMESTAMP'; $objBlob = new SC_Helper_Blob_Ex(); $containerName = $objBlob->getTemplateContainerName($arrParams['device_type_id']); // 新規登録 if ($is_new || SC_Utils_Ex::isBlank($arrExists)) { $objQuery->setOrder(''); $arrValues['bloc_id'] = 1 + $objQuery->max('bloc_id', $table, 'device_type_id = ?', array($arrValues['device_type_id'])); $arrValues['create_date'] = 'CURRENT_TIMESTAMP'; $objQuery->insert($table, $arrValues); } else { $objQuery->update($table, $arrValues, 'bloc_id = ? AND device_type_id = ?', array($arrValues['bloc_id'], $arrValues['device_type_id'])); } $bloc_path = $bloc_dir . $arrValues['tpl_path']; if (!$objBlob->putBlobData($containerName, BLOC_DIR . $arrValues['tpl_path'], $arrParams['bloc_html'])) { $this->arrErr['err'] = '※ ブロックの書き込みに失敗しました<br />'; $objQuery->rollback(); return false; } $objQuery->commit(); return $arrValues['bloc_id']; }