source: branches/version-2_12-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents_CSV.php @ 21693

Revision 21693, 8.3 KB checked in by h_yoshimoto, 12 years ago (diff)

#1692 フックポイント名を変更

  • 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 * CSV項目設定 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Contents_CSV 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 = 'contents/csv.tpl';
47        $this->tpl_subno = 'csv';
48        $this->tpl_mainno = 'contents';
49        $this->tpl_maintitle = 'コンテンツ管理';
50        $this->tpl_subtitle = 'CSV出力設定';
51
52        $objCSV = new SC_Helper_CSV_Ex();
53        $this->arrSubnavi = $objCSV->arrSubnavi; // 別名
54        $this->tpl_subno_csv = $objCSV->arrSubnavi[1]; //デフォルト
55        $this->arrSubnaviName = $objCSV->arrSubnaviName; // 表示名
56    }
57
58    /**
59     * Page のプロセス.
60     *
61     * @return void
62     */
63    function process() {
64        $this->action();
65        $this->sendResponse();
66    }
67
68    /**
69     * Page のアクション.
70     *
71     * @return void
72     */
73    function action() {
74        // フックポイント.
75        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
76        $objPlugin->doAction('LC_Page_Admin_Contents_CSV_action_before', array($this));
77
78        // パラメーター管理クラス
79        $objFormParam = new SC_FormParam_Ex();
80        // パラメーター設定
81        $this->lfInitParam($objFormParam);
82        $objFormParam->setParam($_POST);
83        $objFormParam->setParam($_GET);
84        $objFormParam->convParam();
85
86        // CSV_IDの読み込み
87        $this->tpl_subno_csv = $objFormParam->getValue('tpl_subno_csv');
88        $this->tpl_csv_id = $this->lfGetCsvId($this->tpl_subno_csv);
89
90        switch ($this->getMode()) {
91            case 'confirm':
92                // 入力パラメーターチェック
93                $this->arrErr = $objFormParam->checkError();
94                if (SC_Utils_Ex::isBlank($this->arrErr)) {
95                    // 更新
96                    $this->tpl_is_update = $this->lfUpdCsvOutput($this->tpl_csv_id, $objFormParam->getValue('output_list'));
97                }
98                break;
99            case 'defaultset':
100                //初期値に戻す
101                $this->tpl_is_update = $this->lfSetDefaultCsvOutput($this->tpl_csv_id);
102                break;
103            default:
104                break;
105        }
106        $this->arrSelected = $this->lfGetSelected($this->tpl_csv_id);
107        $this->arrOptions = $this->lfGetOptions($this->tpl_csv_id);
108        $this->tpl_subtitle .= '>' . $this->arrSubnaviName[ $this->tpl_csv_id ];
109
110        if ($this->tpl_is_update) {
111            $this->tpl_onload = "window.alert('正常に更新されました。');";
112        }
113
114        // フックポイント.
115        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
116        $objPlugin->doAction('LC_Page_Admin_Contents_CSV_action_after', array($this));
117    }
118
119    /**
120     * パラメーター情報の初期化
121     *
122     * @param array $objFormParam フォームパラメータークラス
123     * @return void
124     */
125    function lfInitParam(&$objFormParam) {
126        $objFormParam->addParam('編集種別', 'tpl_subno_csv', STEXT_LEN, 'a', array('ALNUM_CHECK', 'MAX_LENGTH_CHECK'), 'product');
127        $objFormParam->addParam('出力設定リスト', 'output_list', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK', 'EXIST_CHECK'));
128        //デフォルト値で上書き
129        $objFormParam->setParam(array('tpl_subno_csv' => 'product'));
130    }
131
132    /**
133     * CSVカラム設定の読み込み
134     *
135     * @param integer $csv_id CSV ID
136     * @param integer $csv_status_flg 読み込む対象のフラグ CSV_COLUMN_STATUS_FLG_ENABLE or ''
137     * @return array SwapArrayしたカラム設定
138     */
139    function lfGetCSVColumn($csv_id, $csv_status_flg = '', $order ='rank, no') {
140        $objCSV = new SC_Helper_CSV_Ex();
141        if (SC_Utils_Ex::sfIsInt($csv_id)) {
142            if ($csv_status_flg !='') {
143                $arrData = $objCSV->sfGetCsvOutput($csv_id, 'status = ?' , array($csv_status_flg), $order);
144            } else {
145                $arrData = $objCSV->sfGetCsvOutput($csv_id, '', array(), $order);
146            }
147            $arrData = SC_Utils_Ex::sfSwapArray($arrData);
148        } else {
149            $arrData = array();
150        }
151        return $arrData;
152    }
153
154    /**
155     * 選択済みカラム列情報を取得
156     *
157     * @param integer $csv_id CSV ID
158     * @return array 選択済みカラム列情報
159     */
160    function lfGetSelected($csv_id) {
161        $arrData = $this->lfGetCSVColumn($csv_id, CSV_COLUMN_STATUS_FLG_ENABLE);
162        if (!isset($arrData['no'])) {
163            $arrData['no'] = array();
164        }
165        return $arrData['no'];
166    }
167
168    /**
169     * カラム列情報と表示名情報を取得
170     *
171     * @param integer $csv_id CSV ID
172     * @return array 選択済みカラム列情報
173     */
174    function lfGetOptions($csv_id) {
175        $arrData = $this->lfGetCSVColumn($csv_id);
176        if (!isset($arrData['no'])) {
177            $arrData['no'] = array();
178            $arrData['disp_name'] = array();
179        }
180        $arrData = SC_Utils_Ex::sfArrCombine($arrData['no'], $arrData['disp_name']);
181        return $arrData;
182    }
183
184    /**
185     * デストラクタ.
186     *
187     * @return void
188     */
189    function destroy() {
190        parent::destroy();
191    }
192
193    /**
194     * CSV名からCSV_IDを取得する。
195     *
196     * @param string $subno_csv CSV名
197     * @return integer CSV_ID
198     */
199    function lfGetCsvId($subno_csv) {
200        $objCSV = new SC_Helper_CSV_Ex();
201        $arrKey = array_keys($objCSV->arrSubnavi,$subno_csv);
202        $csv_id = $arrKey[0];
203        if (!SC_Utils_Ex::sfIsInt($csv_id)) {
204            //初期値取りだし
205            $arrKey = array_keys($objCSV->arrSubnavi);
206            $csv_id = $arrKey[0];
207        }
208        return $csv_id;
209    }
210
211    /**
212     * CSV出力項目設定を初期化する
213     *
214     * @param integer $csv_id CSV_ID
215     * @return boolean 成功:true
216     */
217    function lfSetDefaultCsvOutput($csv_id) {
218        $arrData = $this->lfGetCSVColumn($csv_id, '', $order = 'no');
219        if (!isset($arrData['no'])) {
220            $arrData['no'] = array();
221        }
222        return $this->lfUpdCsvOutput($csv_id, $arrData['no']);
223    }
224
225    /**
226     * CSV出力項目設定を更新する処理
227     *
228     * @param integer $csv_id CSV_ID
229     * @param array $arrData 有効にするCSV列データ配列
230     * @return boolean 成功:true
231     */
232    function lfUpdCsvOutput($csv_id, $arrData = array()) {
233        $objQuery =& SC_Query_Ex::getSingletonInstance();
234        // ひとまず、全部使用しないで更新する
235        $table = 'dtb_csv';
236        $where = 'csv_id = ?';
237        $arrWhereVal = array($csv_id);
238        $arrUpdVal = array('status' => '2', 'rank' => NULL, 'update_date' => 'CURRENT_TIMESTAMP');
239
240        $objQuery->begin();
241        $objQuery->update($table, $arrUpdVal, $where, $arrWhereVal);
242        // 使用するものだけ、再更新する。
243        if (is_array($arrData)) {
244            $where .= ' AND no = ?';
245            $arrUpdVal = array('status' => '1');
246            foreach ($arrData as $key => $val) {
247                $arrWhereVal = array($csv_id, $val);
248                $arrUpdVal['rank'] = $key + 1;
249                $objQuery->update($table, $arrUpdVal, $where, $arrWhereVal);
250            }
251        }
252        $objQuery->commit();
253        return true;
254    }
255}
Note: See TracBrowser for help on using the repository browser.