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

Revision 20318, 8.2 KB checked in by AMUAMU, 13 years ago (diff)

#476 (CSV出力項目設定(高度な設定)で、一部テーブルの項目一覧が表示されない) に伴う改修
#657 (CSVダウンロードの改善) の改修
#938 (CSV出力 高度な設定 SQL登録できない) の不具合修正
#939 (CSV出力 高度な設定 出力操作で「sfGetCSVData()に移行してね。」と表示) の不具合修正
#971 (リファクタリング [管理画面]コンテンツ管理(CSV出力項目設定)) の改修

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