source: branches/version-2_11-dev/data/class/pages/admin/design/LC_Page_Admin_Design.php @ 20830

Revision 20830, 11.0 KB checked in by nanasess, 13 years ago (diff)

#972 (リファクタリング開発:[管理画面]デザイン管理)

  • LC_Page_Admin_Design.php
  • SC_Helper_PageLayout もリファクタリング

#1254 (SC_FormParam::getValue() の第二引数が無効)

  • SC_Utils::isBlank() でチェックするよう修正
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24// {{{ requires
25require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
26
27/**
28 * デザイン管理 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Design extends LC_Page_Admin_Ex {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'design/index.tpl';
47        $this->tpl_subnavi = 'design/subnavi.tpl';
48        $this->tpl_subno = 'layout';
49        $this->tpl_mainno = 'design';
50        $this->tpl_subtitle = 'レイアウト設定';
51        $masterData = new SC_DB_MasterData_Ex();
52        $this->arrTarget = $masterData->getMasterData("mtb_target");
53        $this->arrDeviceType = $masterData->getMasterData('mtb_device_type');
54    }
55
56    /**
57     * Page のプロセス.
58     *
59     * @return void
60     */
61    function process() {
62        $this->action();
63        $this->sendResponse();
64    }
65
66    /**
67     * Page のアクション.
68     *
69     * @return void
70     */
71    function action() {
72        $objLayout = new SC_Helper_PageLayout_Ex();
73        $objFormParam = new SC_FormParam_Ex();
74        $this->lfInitParam($objFormParam, intval($_REQUEST['bloc_cnt']));
75        $objFormParam->setParam($_REQUEST);
76
77        $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC);
78        $this->page_id = $objFormParam->getValue('page_id', 1);
79
80        switch ($this->getMode()) {
81        // 新規ブロック作成
82        case 'new_bloc':
83            SC_Response_Ex::sendRedirect('bloc.php', array("device_type_id" => $this->device_type_id));
84            exit;
85            break;
86
87        // 新規ページ作成
88        case 'new_page':
89            SC_Response_Ex::sendRedirect('main_edit.php', array("device_type_id" => $this->device_type_id));
90            exit;
91            break;
92
93        // プレビュー
94        case 'preview':
95            $this->placingBlocs($objFormParam, true);
96            $filename = $this->savePreviewData($this->page_id, $objLayout);
97            $_SESSION['preview'] = 'ON';
98            SC_Response_Ex::sendRedirectFromUrlPath('preview/' . DIR_INDEX_PATH, array('filename' => $filename));
99            exit;
100
101        // 編集実行
102        case 'confirm':
103            $this->placingBlocs($objFormParam);
104            $arrQueryString = array("device_type_id" => $this->device_type_id, "page_id" => $this->page_id, 'msg' => 'on');
105            SC_Response_Ex::reload($arrQueryString, true);
106            exit;
107
108        break;
109
110        // データ削除処理
111        case 'delete':
112            //ベースデータでなければファイルを削除
113            if ($objLayout->isEditablePage($this->device_type_id, $this->page_id)) {
114                $objLayout->lfDelPageData($this->page_id, $this->device_type_id);
115                SC_Response_Ex::reload(array('device_type_id' => $this->device_type_id), true);
116                exit;
117            }
118        break;
119
120        default:
121            // 完了メッセージ表示
122            if (isset($_GET['msg']) && $_GET['msg'] == 'on') {
123                $this->tpl_onload="alert('登録が完了しました。');";
124            }
125        }
126
127        $this->arrBlocs = $this->getLayout($this->device_type_id, $this->page_id, $objLayout);
128        $this->bloc_cnt = count($this->arrBlocs);
129        // 編集中のページ
130        $this->arrPageData = $objLayout->getPageProperties($this->device_type_id, $this->page_id);
131        // 編集可能ページ一覧
132        $this->arrEditPage = $objLayout->getPageProperties($this->device_type_id, null);
133        //サブタイトルを取得
134        $this->tpl_subtitle .= ' - ' . $this->arrDeviceType[$this->device_type_id];
135    }
136
137    /**
138     * デストラクタ.
139     *
140     * @return void
141     */
142    function destroy() {
143        parent::destroy();
144    }
145
146    /**
147     * フォームパラメータの初期化を行う.
148     *
149     * @param SC_FormParam $objFormParam SC_FormParam インスタンス.
150     * @param integer $bloc_cnt ブロック数
151     * @return void
152     */
153    function lfInitParam(&$objFormParam, $bloc_cnt = 0) {
154        $objFormParam->addParam("ページID", "page_id", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"));
155        $objFormParam->addParam("端末種別ID", "device_type_id", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"));
156        $objFormParam->addParam("ブロック数", "bloc_cnt", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"));
157
158        for ($i = 1; $i <= $bloc_cnt; $i++) {
159            $objFormParam->addParam("ブロック名", "name_" . $i, STEXT_LEN, 'a', array("MAX_LENGTH_CHECK", "GRAPH_CHECK"));
160            $objFormParam->addParam("ブロックID", "id_" . $i, INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"));
161            $objFormParam->addParam("ターゲットID", "target_id_" . $i, STEXT_LEN, 'a', array("MAX_LENGTH_CHECK", "ALNUM_CHECK"));
162            $objFormParam->addParam("TOP座標", "top_" . $i, INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"));
163            $objFormParam->addParam("全ページ", "anywhere_" . $i, INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"));
164        }
165    }
166
167    /**
168     * ブロックのレイアウト情報を取得する.
169     *
170     * @param integer $device_type_id 端末種別ID
171     * @param integer $page_id ページID
172     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
173     * @return array レイアウト情報の配列
174     */
175    function getLayout($device_type_id, $page_id, &$objLayout) {
176        $arrResults = array();
177        $i = 0;
178
179        // レイアウト済みのブロックデータを追加
180        $arrBlocPos = $objLayout->getBlocPositions($device_type_id, $page_id);
181        foreach($arrBlocPos as $arrBloc){
182            $this->copyBloc($arrResults, $arrBloc, $i);
183            $i++;
184        }
185
186        // 未使用のブロックデータを追加
187        $arrBloc = $objLayout->getBlocs($device_type_id);
188        foreach($arrBloc as $arrBloc){
189            if (!$this->existsBloc($arrBloc, $arrResults)) {
190                $arrBloc['target_id'] = TARGET_ID_UNUSED;
191                $this->copyBloc($arrResults, $arrBloc, $i);
192                $i++;
193            }
194        }
195        return $arrResults;
196    }
197
198    /**
199     * ブロック情報の配列をコピーする.
200     *
201     * @param array $arrDest コピー先ブロック情報
202     * @param array $arrFrom コピー元ブロック情報
203     * @param integer $cnt 配列番号
204     * @return void
205     */
206    function copyBloc(&$arrDest, $arrFrom, $cnt) {
207        $arrDest[$cnt]['target_id'] = $this->arrTarget[$arrFrom['target_id']];
208        $arrDest[$cnt]['bloc_id'] = $arrFrom['bloc_id'];
209        $arrDest[$cnt]['bloc_row'] = $arrFrom['bloc_row'];
210        $arrDest[$cnt]['anywhere'] = $arrFrom['anywhere'];
211        $arrDest[$cnt]['name'] = $arrFrom['bloc_name'];
212    }
213
214    /**
215     * ブロックIDがコピー先の配列に追加されているかのチェックを行う.
216     *
217     * @param array $arrBloc ブロックの配列
218     * @param array $arrToBlocs チェックを行うデータ配列
219     * @return bool 存在する場合 true
220     */
221    function existsBloc($arrBloc, $arrToBlocs) {
222        foreach($arrToBlocs as $arrToBloc){
223            if ($arrBloc['bloc_id'] === $arrToBloc['bloc_id'] ) {
224                return true;
225            }
226        }
227        return false;
228    }
229
230    /**
231     * プレビューするデータを DB に保存する.
232     *
233     * @param integer $page_id プレビューを行うページID
234     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
235     * @return string プレビューを行う tpl_mainpage ファイル名
236     */
237    function savePreviewData($page_id, &$objLayout){
238        $arrPageData = $objLayout->getPageProperties(DEVICE_TYPE_PC, $page_id);
239        $objQuery =& SC_Query_Ex::getSingletonInstance();
240        $arrPageData[0]['page_id'] = 0;
241        $objQuery->update('dtb_pagelayout', $arrPageData[0], 'page_id = 0 AND device_type_id = ?', array(DEVICE_TYPE_PC));
242        return $arrPageData[0]['filename'];
243    }
244
245    /**
246     * ブロックを配置する.
247     *
248     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
249     * @param boolean $is_preview プレビュー時の場合 true
250     * @return void
251     */
252    function placingBlocs(&$objFormParam, $is_preview = false) {
253        $page_id = $is_preview ? 0 : $objFormParam->getValue('page_id');
254        $device_type_id = $objFormParam->getValue('device_type_id');
255        $bloc_cnt = $objFormParam->getValue('bloc_cnt');
256        $objQuery =& SC_Query_Ex::getSingletonInstance();
257        $objQuery->begin();
258        $objQuery->delete("dtb_blocposition", "page_id = ? AND device_type_id = ?",
259                          array($page_id, $device_type_id));
260        $arrTargetFlip = array_flip($this->arrTarget);
261        var_dump($objFormParam->getHashArray());
262        var_dump($_POST);
263        for ($i = 1; $i <= $bloc_cnt; $i++) {
264            // bloc_id が取得できない場合は INSERT しない
265            $id = $objFormParam->getValue('id_' . $i);
266            if (SC_Utils_Ex::isBlank($id)) {
267                continue;
268            }
269            // 未使用は INSERT しない
270            $arrParams['target_id']  = $arrTargetFlip[$objFormParam->getValue('target_id_' . $i)];
271            if ($arrParams['target_id'] == TARGET_ID_UNUSED) {
272                continue;
273            }
274
275            // 他のページに anywhere が存在する場合は INSERT しない
276            $arrParams['anywhere'] = intval($objFormParam->getValue('anywhere_' . $i));
277            if ($arrParams['anywhere'] == 1) {
278                $count = $objQuery->count('dtb_blocposition', 'anywhere = 1 AND bloc_id = ? AND device_type_id = ?',
279                                          array($id, $device_type_id));
280                if ($count > 0) {
281                    continue;
282                }
283            }
284
285            $arrParams['device_type_id'] = $device_type_id;
286            $arrParams['page_id'] = $page_id;
287            $arrParams['bloc_id'] = $id;
288            $arrParams['bloc_row'] = $objFormParam->getValue('top_' . $i);
289
290            $objQuery->insert("dtb_blocposition", $arrParams);
291        }
292        $objQuery->commit();
293    }
294}
295?>
Note: See TracBrowser for help on using the repository browser.