[23461] | 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 | */
|
---|
| 31 | class SC_Helper_Review
|
---|
| 32 | {
|
---|
| 33 | /**
|
---|
| 34 | * レビュー情報のDB取得
|
---|
| 35 | *
|
---|
| 36 | * @param int $review_id レビューID
|
---|
| 37 | * @return array レビュー情報
|
---|
| 38 | */
|
---|
| 39 | public function get($review_id)
|
---|
| 40 | {
|
---|
| 41 | $objQuery =& SC_Query_Ex::getSingletonInstance();
|
---|
| 42 | $select='review_id, A.product_id, reviewer_name, sex, recommend_level, ';
|
---|
| 43 | $select.='reviewer_url, title, comment, A.status, A.create_date, A.update_date, name';
|
---|
| 44 | $from = 'dtb_review AS A LEFT JOIN dtb_products AS B ON A.product_id = B.product_id ';
|
---|
| 45 | $where = 'A.del_flg = 0 AND B.del_flg = 0 AND review_id = ? ';
|
---|
| 46 | $arrReview = $objQuery->select($select, $from, $where, array($review_id));
|
---|
| 47 |
|
---|
| 48 | return $arrReview[0];
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | /**
|
---|
| 52 | * 商品に紐付いたレビューの一覧を取得
|
---|
| 53 | *
|
---|
| 54 | * @param $product_id
|
---|
| 55 | * @return array|null
|
---|
| 56 | */
|
---|
| 57 | public function getListByProductId($product_id)
|
---|
| 58 | {
|
---|
| 59 | $query = array(
|
---|
| 60 | 'product_id' => $product_id
|
---|
| 61 | );
|
---|
| 62 | $arrReview = $this->find(array('query' => $query));
|
---|
| 63 |
|
---|
| 64 | return $arrReview;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | /**
|
---|
| 68 | * レビュー情報を登録する.
|
---|
| 69 | *
|
---|
| 70 | * @param $data
|
---|
| 71 | * @return bool
|
---|
| 72 | */
|
---|
| 73 | public function save($data)
|
---|
| 74 | {
|
---|
| 75 | $objQuery =& SC_Query_Ex::getSingletonInstance();
|
---|
| 76 |
|
---|
| 77 | $review_id = $data['review_id'];
|
---|
| 78 | $data['update_date'] = 'CURRENT_TIMESTAMP';
|
---|
| 79 | // 新規登録
|
---|
| 80 | if ($review_id == '') {
|
---|
| 81 | // INSERTの実行
|
---|
| 82 | $data['creator_id'] = '0';
|
---|
| 83 | $data['create_date'] = 'CURRENT_TIMESTAMP';
|
---|
| 84 | $data['review_id'] = $objQuery->nextVal('dtb_review_review_id');
|
---|
| 85 | $ret = $objQuery->insert('dtb_review', $data);
|
---|
| 86 | // 既存編集
|
---|
| 87 | } else {
|
---|
| 88 | unset($data['creator_id']);
|
---|
| 89 | unset($data['create_date']);
|
---|
| 90 | $where = 'review_id = ?';
|
---|
| 91 | $ret = $objQuery->update('dtb_review', $data, $where, array($review_id));
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | return ($ret) ? $data['review_id'] : FALSE;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | /**
|
---|
| 98 | * レビューを削除する(論理削除).
|
---|
| 99 | *
|
---|
| 100 | * @param $review_id
|
---|
| 101 | */
|
---|
| 102 | public function delete($review_id)
|
---|
| 103 | {
|
---|
| 104 | $objQuery =& SC_Query_Ex::getSingletonInstance();
|
---|
| 105 | $data['del_flg'] = 1;
|
---|
| 106 | $objQuery->update('dtb_review', $data, 'review_id = ?', array($review_id));
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | /**
|
---|
| 110 | * 条件に合うレビュー情報の一覧を取得.
|
---|
| 111 | *
|
---|
| 112 | * @param array $params
|
---|
| 113 | * @return array|null
|
---|
| 114 | */
|
---|
| 115 | public function find($params = array())
|
---|
| 116 | {
|
---|
| 117 | $objQuery =& SC_Query_Ex::getSingletonInstance();
|
---|
| 118 |
|
---|
| 119 | // 検索条件を作成
|
---|
| 120 | $query = (isset($params['query'])) ? $params['query'] : array();
|
---|
| 121 | list($where, $values) = $this->makeWhere($query);
|
---|
| 122 |
|
---|
| 123 | // 表示件数
|
---|
| 124 | if (isset($params['limit'])) {
|
---|
| 125 | if (isset($params['offset'])) {
|
---|
| 126 | $objQuery->setLimitOffset($params['limit'], $params['offset']);
|
---|
| 127 | } else {
|
---|
| 128 | $objQuery->setLimit($params['limit']);
|
---|
| 129 | }
|
---|
| 130 | } elseif (isset($params['offset'])) {
|
---|
| 131 | $objQuery->setOffset($params['offset']);
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | // 表示順序
|
---|
| 135 | $order = (isset($params['order'])) ? $params['order'] : 'A.create_date DESC';
|
---|
| 136 | $objQuery->setOrder($order);
|
---|
| 137 |
|
---|
| 138 | //検索結果の取得
|
---|
| 139 | //レビュー情報のカラムの取得
|
---|
| 140 | $col = 'review_id, A.product_id, reviewer_name, sex, recommend_level, ';
|
---|
| 141 | $col .= 'reviewer_url, title, comment, A.status, A.create_date, A.update_date, name';
|
---|
| 142 | $from = 'dtb_review AS A LEFT JOIN dtb_products AS B ON A.product_id = B.product_id ';
|
---|
| 143 | $arrReview = $objQuery->select($col, $from, $where, $values);
|
---|
| 144 |
|
---|
| 145 | return $arrReview;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | /**
|
---|
| 149 | * 条件に合うレビュー情報の件数を取得.
|
---|
| 150 | *
|
---|
| 151 | * @param array $query
|
---|
| 152 | * @return int
|
---|
| 153 | */
|
---|
| 154 | public function count($query = array())
|
---|
| 155 | {
|
---|
| 156 | $objQuery =& SC_Query_Ex::getSingletonInstance();
|
---|
| 157 | // 検索条件を作成
|
---|
| 158 | list($where, $values) = $this->makeWhere($query);
|
---|
| 159 | $from = 'dtb_review AS A LEFT JOIN dtb_products AS B ON A.product_id = B.product_id ';
|
---|
| 160 | return $objQuery->count($from, $where, $values);
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | /**
|
---|
| 164 | * WHERE文の作成
|
---|
| 165 | *
|
---|
| 166 | * @param array $query フォームデータ
|
---|
| 167 | * @return array WHERE文、判定値
|
---|
| 168 | */
|
---|
| 169 | private function makeWhere($query = array())
|
---|
| 170 | {
|
---|
| 171 | //削除されていない商品を検索
|
---|
| 172 | $where = 'A.del_flg = 0 AND B.del_flg = 0';
|
---|
| 173 | $values = array();
|
---|
| 174 |
|
---|
| 175 | foreach ($query AS $key => $val) {
|
---|
| 176 | if (empty($val)) continue;
|
---|
| 177 |
|
---|
| 178 | switch ($key) {
|
---|
| 179 | case 'product_id':
|
---|
| 180 | if (is_array($val)) {
|
---|
| 181 | $where.= ' AND A.product_id IN (' . SC_Utils_Ex::sfGetCommaList($val) . ')';
|
---|
| 182 | } else {
|
---|
| 183 | $where.= ' AND A.product_id = ?';
|
---|
| 184 | $values[] = $val;
|
---|
| 185 | }
|
---|
| 186 | break;
|
---|
| 187 |
|
---|
| 188 | case 'reviewer_name':
|
---|
| 189 | $val = preg_replace('/ /', '%', $val);
|
---|
| 190 | $where.= ' AND reviewer_name LIKE ? ';
|
---|
| 191 | $values[] = "%$val%";
|
---|
| 192 | break;
|
---|
| 193 |
|
---|
| 194 | case 'reviewer_url':
|
---|
| 195 | $val = preg_replace('/ /', '%', $val);
|
---|
| 196 | $where.= ' AND reviewer_url LIKE ? ';
|
---|
| 197 | $values[] = "%$val%";
|
---|
| 198 | break;
|
---|
| 199 |
|
---|
| 200 | case 'product_name':
|
---|
| 201 | $val = preg_replace('/ /', '%', $val);
|
---|
| 202 | $where.= ' AND name LIKE ? ';
|
---|
| 203 | $values[] = "%$val%";
|
---|
| 204 | break;
|
---|
| 205 |
|
---|
| 206 | case 'product_code':
|
---|
| 207 | $val = preg_replace('/ /', '%', $val);
|
---|
| 208 | $where.= ' AND A.product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ?)';
|
---|
| 209 | $values[] = "%$val%";
|
---|
| 210 | break;
|
---|
| 211 |
|
---|
| 212 | case 'reviewer_sex':
|
---|
| 213 | $tmp_where = '';
|
---|
| 214 | //$val=配列の中身,$element=各キーの値(1,2)
|
---|
| 215 | if (is_array($val)) {
|
---|
| 216 | foreach ($val as $element) {
|
---|
| 217 | if ($element != '') {
|
---|
| 218 | if ($tmp_where == '') {
|
---|
| 219 | $tmp_where .= ' AND (sex = ?';
|
---|
| 220 | } else {
|
---|
| 221 | $tmp_where .= ' OR sex = ?';
|
---|
| 222 | }
|
---|
| 223 | $values[] = $element;
|
---|
| 224 | }
|
---|
| 225 | }
|
---|
| 226 | if ($tmp_where != '') {
|
---|
| 227 | $tmp_where .= ')';
|
---|
| 228 | $where .= " $tmp_where ";
|
---|
| 229 | }
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | break;
|
---|
| 233 |
|
---|
| 234 | case 'recommend_level':
|
---|
| 235 | $where.= ' AND recommend_level = ? ';
|
---|
| 236 | $values[] = $val;
|
---|
| 237 | break;
|
---|
| 238 |
|
---|
| 239 | case 'date_from':
|
---|
| 240 | $where.= ' AND A.create_date >= ? ';
|
---|
| 241 | $values[] = $val;
|
---|
| 242 | break;
|
---|
| 243 |
|
---|
| 244 | case 'date_to':
|
---|
| 245 | $where.= " AND A.create_date <= cast( ? as date) ";
|
---|
| 246 | $values[] = $val;
|
---|
| 247 | break;
|
---|
| 248 |
|
---|
| 249 | default:
|
---|
| 250 | break;
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | return array($where, $values);
|
---|
| 256 | }
|
---|
| 257 | } |
---|