source: branches/version-2_13-dev/data/class/helper/SC_Helper_BestProducts.php @ 23546

Revision 23546, 6.0 KB checked in by shutta, 10 years ago (diff)

#2580 Copyrightを更新
Copyrightを2014に更新

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