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

Revision 23605, 7.9 KB checked in by kimoto, 10 years ago (diff)

#2448 typo修正・ソース整形・ソースコメントの改善 for 2.13.3

Scrutinizer Auto-Fixes

This patch was automatically generated as part of the following inspection:
 https://scrutinizer-ci.com/g/nobuhiko/EC-CUBE/inspections/d8722894-69a6-4b1b-898d-43618035c60d

Enabled analysis tools:

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