source: branches/version-2_12-dev/data/class/helper/SC_Helper_Recommend.php @ 22582

Revision 22582, 5.9 KB checked in by pineray, 11 years ago (diff)

#2162 pageクラスからdtb_best_productsテーブルを直接指定している箇所をなくす

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/**
25 * おすすめ商品を管理するヘルパークラス.
26 *
27 * @package Helper
28 * @author pineray
29 * @version $Id:$
30 */
31class SC_Helper_Recommend
32{
33    /**
34     * おすすめ商品の情報を取得.
35     *
36     * @param integer $best_id おすすめ商品ID
37     * @param boolean $has_deleted 削除されたおすすめ商品も含む場合 true; 初期値 false
38     * @return array
39     */
40    public function get($best_id, $has_deleted = false)
41    {
42        $objQuery =& SC_Query_Ex::getSingletonInstance();
43        $col = '*';
44        $where = 'best_id = ?';
45        if (!$has_deleted) {
46            $where .= ' AND del_flg = 0';
47        }
48        $arrRet = $objQuery->select($col, 'dtb_best_products', $where, array($best_id));
49        return $arrRet[0];
50    }
51
52    /**
53     * おすすめ商品の情報をランクから取得.
54     *
55     * @param integer $rank ランク
56     * @param boolean $has_deleted 削除されたおすすめ商品も含む場合 true; 初期値 false
57     * @return array
58     */
59    public function getByRank($rank, $has_deleted = false)
60    {
61        $objQuery =& SC_Query_Ex::getSingletonInstance();
62        $col = '*';
63        $where = 'rank = ?';
64        if (!$has_deleted) {
65            $where .= ' AND del_flg = 0';
66        }
67        $arrRet = $objQuery->select($col, 'dtb_best_products', $where, array($rank));
68        return $arrRet[0];
69    }
70
71    /**
72     * おすすめ商品一覧の取得.
73     *
74     * @param integer $dispNumber 表示件数
75     * @param integer $pageNumber ページ番号
76     * @param boolean $has_deleted 削除されたおすすめ商品も含む場合 true; 初期値 false
77     * @return array
78     */
79    public function getList($dispNumber = 0, $pageNumber = 0, $has_deleted = false)
80    {
81        $objQuery =& SC_Query_Ex::getSingletonInstance();
82        $col = '*';
83        $where = '';
84        if (!$has_deleted) {
85            $where .= 'del_flg = 0';
86        }
87        $table = 'dtb_best_products';
88        $objQuery->setOrder('rank');
89        if ($dispNumber > 0) {
90            if ($pageNumber > 0) {
91                $objQuery->setLimitOffset($dispNumber, (($pageNumber - 1) * $dispNumber));
92            } else {
93                $objQuery->setLimit($dispNumber);
94            }
95        }
96        $arrRet = $objQuery->select($col, $table, $where);
97        return $arrRet;
98    }
99
100    /**
101     * おすすめ商品の登録.
102     *
103     * @param array $sqlval
104     * @return multiple 登録成功:おすすめ商品ID, 失敗:FALSE
105     */
106    public function save($sqlval)
107    {
108        $objQuery =& SC_Query_Ex::getSingletonInstance();
109
110        $best_id = $sqlval['best_id'];
111        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
112        // 新規登録
113        if ($best_id == '') {
114            // INSERTの実行
115            if (!$sqlval['rank']) {
116                $sqlval['rank'] = $objQuery->max('rank', 'dtb_best_products') + 1;
117            }
118            $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
119            $sqlval['best_id'] = $objQuery->nextVal('dtb_best_products_best_id');
120            $ret = $objQuery->insert('dtb_best_products', $sqlval);
121        // 既存編集
122        } else {
123            unset($sqlval['creator_id']);
124            unset($sqlval['create_date']);
125            $where = 'best_id = ?';
126            $ret = $objQuery->update('dtb_best_products', $sqlval, $where, array($best_id));
127        }
128        return ($ret) ? $sqlval['best_id'] : FALSE;
129    }
130
131    /**
132     * おすすめ商品の削除.
133     *
134     * @param integer $best_id おすすめ商品ID
135     * @return void
136     */
137    public function delete($best_id)
138    {
139        $objDb = new SC_Helper_DB_Ex();
140        // ランク付きレコードの削除
141        $objDb->sfDeleteRankRecord('dtb_best_products', 'best_id', $best_id, TRUE);
142    }
143
144    /**
145     * 商品IDの配列からおすすめ商品を削除.
146     *
147     * @param array $productIDs 商品ID
148     * @return void
149     */
150    public function deleteByProductIDs($productIDs)
151    {
152        $objDb = new SC_Helper_DB_Ex();
153        $arrList = $this->getList();
154        foreach ($arrList as $recommend) {
155            if (in_array($recommend['product_id'], $productIDs)) {
156                $objDb->sfDeleteRankRecord('dtb_best_products', 'best_id', $recommend['best_id'], TRUE);
157            }
158        }
159    }
160
161    /**
162     * おすすめ商品の表示順をひとつ上げる.
163     *
164     * @param integer $best_id おすすめ商品ID
165     * @return void
166     */
167    public function rankUp($best_id)
168    {
169        $objDb = new SC_Helper_DB_Ex();
170        //おすすめはデータベースの登録が昇順なので、Modeを逆にする。
171        $objDb->sfRankDown('dtb_best_products', 'best_id', $best_id);
172    }
173
174    /**
175     * おすすめ商品の表示順をひとつ下げる.
176     *
177     * @param integer $best_id おすすめ商品ID
178     * @return void
179     */
180    public function rankDown($best_id)
181    {
182        $objDb = new SC_Helper_DB_Ex();
183        //おすすめはデータベースの登録が昇順なので、Modeを逆にする。
184        $objDb->sfRankUp('dtb_best_products', 'best_id', $best_id);
185    }
186}
Note: See TracBrowser for help on using the repository browser.