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

Revision 22567, 7.9 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

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