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

Revision 21743, 7.9 KB checked in by AMUAMU, 12 years ago (diff)

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