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

Revision 23605, 9.5 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 * おすすめ商品管理 のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Admin_Contents_Recommend 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/recommend.tpl';
44        $this->tpl_mainno = 'contents';
45        $this->tpl_subno = 'recommend';
46        $this->tpl_maintitle = 'コンテンツ管理';
47        $this->tpl_subtitle = 'おすすめ商品管理';
48        //最大登録数の表示
49        $this->tpl_disp_max = RECOMMEND_NUM;
50    }
51
52    /**
53     * Page のプロセス.
54     *
55     * @return void
56     */
57    public function process()
58    {
59        $this->action();
60        $this->sendResponse();
61    }
62
63    /**
64     * Page のアクション.
65     *
66     * @return void
67     */
68    public function action()
69    {
70        $objFormParam = new SC_FormParam_Ex();
71        $this->lfInitParam($objFormParam);
72        $objFormParam->setParam($_POST);
73        $objFormParam->convParam();
74        $arrPost = $objFormParam->getHashArray();
75
76        $objRecommend = new SC_Helper_BestProducts_Ex();
77
78        switch ($this->getMode()) {
79            case 'down': //商品の並び替えをする。
80                $objRecommend->rankDown($arrPost['best_id']);
81                $arrItems = $this->getRecommendProducts($objRecommend);
82                break;
83
84            case 'up': //商品の並び替えをする。
85                $objRecommend->rankUp($arrPost['best_id']);
86                $arrItems = $this->getRecommendProducts($objRecommend);
87                break;
88
89            case 'regist': // 商品を登録する。
90                $this->arrErr[$arrPost['rank']] = $this->lfCheckError($objFormParam);
91                // 登録処理にエラーがあった場合は商品選択の時と同じ処理を行う。
92                if (SC_Utils_Ex::isBlank($this->arrErr)) {
93                    $member_id = $_SESSION['member_id'];
94                    $this->insertRecommendProduct($arrPost, $member_id, $objRecommend);
95                    $arrItems = $this->getRecommendProducts($objRecommend);
96                    $this->tpl_onload = "window.alert('編集が完了しました');";
97                } else {
98                    $arrItems = $this->getRecommendProducts($objRecommend);
99                    $rank = $arrPost['rank'];
100                    $arrItems[$rank]['comment'] = $arrPost['comment'];;
101                    if ($arrPost['best_id']) {
102                    } else {
103                        $arrItems = $this->setProducts($arrPost, $arrItems);
104                        $this->checkRank = $arrPost['rank'];
105                    }
106                }
107                break;
108            case 'delete': // 商品を削除する。
109                if ($arrPost['best_id']) {
110                    $this->deleteProduct($arrPost, $objRecommend);
111                }
112                $arrItems = $this->getRecommendProducts($objRecommend);
113                $this->tpl_onload = "window.alert('削除しました');";
114                break;
115            case 'set_item': // 商品を選択する。
116                $this->arrErr = $this->lfCheckError($objFormParam);
117                if (SC_Utils_Ex::isBlank($this->arrErr['rank']) && SC_Utils_Ex::isBlank($this->arrErr['product_id'])) {
118                    $arrItems = $this->setProducts($arrPost, $this->getRecommendProducts($objRecommend));
119                    $this->checkRank = $arrPost['rank'];
120                }
121                break;
122            default:
123                $arrItems = $this->getRecommendProducts($objRecommend);
124                break;
125        }
126
127        $this->category_id = intval($arrPost['category_id']);
128        $this->arrItems = $arrItems;
129
130        // カテゴリ取得
131        $objDb = new SC_Helper_DB_Ex();
132        $this->arrCatList = $objDb->sfGetCategoryList('level = 1');
133    }
134
135    /**
136     * パラメーターの初期化を行う
137     * @param SC_FormParam_Ex $objFormParam
138     */
139    public function lfInitParam(&$objFormParam)
140    {
141        $objFormParam->addParam('おすすめ商品ID', 'best_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
142        $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
143        $objFormParam->addParam('カテゴリID', 'category_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
144        $objFormParam->addParam('ランク', 'rank', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
145        $objFormParam->addParam('コメント', 'comment', LTEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
146    }
147
148    /**
149     * 入力されたパラメーターのエラーチェックを行う。
150     * @param  Object $objFormParam
151     * @return Array  エラー内容
152     */
153    public function lfCheckError(&$objFormParam)
154    {
155        $objErr = new SC_CheckError_Ex($objFormParam->getHashArray());
156        $objErr->arrErr = $objFormParam->checkError();
157
158        return $objErr->arrErr;
159    }
160
161    /**
162     * 既に登録されている内容を取得する
163     * @param  SC_Helper_BestProducts_Ex $objRecommend
164     * @return Array  $arrReturnProducts データベースに登録されているおすすめ商品の配列
165     */
166    public function getRecommendProducts(SC_Helper_BestProducts_Ex &$objRecommend)
167    {
168        $arrList = $objRecommend->getList();
169        // product_id の一覧を作成
170        $product_ids = array();
171        foreach ($arrList as $value) {
172            $product_ids[] = $value['product_id'];
173        }
174
175        $objProduct = new SC_Product_Ex;
176        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
177        $arrProducts = $objProduct->getListByProductIds($objQuery, $product_ids);
178
179        $arrReturnProducts = array();
180        foreach ($arrList as $data) {
181            $data['main_list_image'] = $arrProducts[$data['product_id']]['main_list_image'];
182            $data['name'] = $arrProducts[$data['product_id']]['name'];
183            $arrReturnProducts[$data['rank']] = $data;
184        }
185
186        return $arrReturnProducts;
187    }
188
189    /**
190     * おすすめ商品の新規登録を行う。
191     * @param Array   $arrPost      POSTの値を格納した配列
192     * @param Integer $member_id    登録した管理者を示すID
193     * @param SC_Helper_BestProducts_Ex  $objRecommend
194     */
195    public function insertRecommendProduct($arrPost, $member_id, SC_Helper_BestProducts_Ex &$objRecommend)
196    {
197        $sqlval = array();
198        $sqlval['best_id'] = $arrPost['best_id'];
199        $sqlval['product_id'] = $arrPost['product_id'];
200        $sqlval['category_id'] = $arrPost['category_id'];
201        $sqlval['rank'] = $arrPost['rank'];
202        $sqlval['comment'] = $arrPost['comment'];
203        $sqlval['creator_id'] = $member_id;
204
205        $objRecommend->saveBestProducts($sqlval);
206    }
207
208    /**
209     * データを削除する
210     * @param  Array  $arrPost      POSTの値を格納した配列
211     * @param  SC_Helper_BestProducts_Ex $objRecommend
212     * @return void
213     */
214    public function deleteProduct($arrPost, SC_Helper_BestProducts_Ex &$objRecommend)
215    {
216        if ($arrPost['best_id']) {
217            $target = $arrPost['best_id'];
218        } else {
219            $recommend = $objRecommend->getByRank($arrPost['rank']);
220            $target = $recommend['best_id'];
221        }
222        $objRecommend->deleteBestProducts($target);
223    }
224
225    /**
226     * 商品情報を取得する
227     * @param  Integer $product_id 商品ID
228     * @return Array   $return 商品のデータを格納した配列
229     */
230    public function getProduct($product_id)
231    {
232        $objProduct = new SC_Product_Ex();
233        $arrProduct = $objProduct->getDetail($product_id);
234        $return = array(
235            'product_id' => $arrProduct['product_id'],
236            'main_list_image' => $arrProduct['main_list_image'],
237            'name' => $arrProduct['name']
238        );
239
240        return $return;
241    }
242
243    /**
244     * 商品のデータを表示用に処理する
245     * @param Array $arrPost  POSTのデータを格納した配列
246     * @param Array $arrItems フロントに表示される商品の情報を格納した配列
247     */
248    public function setProducts($arrPost, $arrItems)
249    {
250        $arrProduct = $this->getProduct($arrPost['product_id']);
251        if (count($arrProduct) > 0) {
252            $rank = $arrPost['rank'];
253            foreach ($arrProduct as $key => $val) {
254                $arrItems[$rank][$key] = $val;
255            }
256            $arrItems[$rank]['rank'] = $rank;
257        }
258
259        return $arrItems;
260    }
261}
Note: See TracBrowser for help on using the repository browser.