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

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