source: branches/version-2_13_3/data/class/helper/SC_Helper_Address.php @ 23605

Revision 23605, 5.8 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
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_Address
32{
33    /**
34     * お届け先を登録
35     *
36     * @param  array   $sqlval
37     * @return array()
38     */
39    public function registAddress($sqlval)
40    {
41        if (self::delivErrorCheck($sqlval)) {
42            return false;
43        }
44       
45        $objQuery =& SC_Query_Ex::getSingletonInstance();
46        $customer_id = $sqlval['customer_id'];
47        $other_deliv_id = $sqlval['other_deliv_id'];
48
49        // 追加
50        if (strlen($other_deliv_id == 0)) {
51            // 別のお届け先最大登録数に達している場合、エラー
52            $from   = 'dtb_other_deliv';
53            $where  = 'customer_id = ?';
54            $arrVal = array($customer_id);
55            $deliv_count = $objQuery->count($from, $where, $arrVal);
56            if ($deliv_count >= DELIV_ADDR_MAX) {
57                return false;
58            }
59
60            // 別のお届け先を追加
61            $sqlval['other_deliv_id'] = $objQuery->nextVal('dtb_other_deliv_other_deliv_id');
62            $ret = $objQuery->insert($from, $sqlval);
63
64        // 変更
65        } else {
66            $from   = 'dtb_other_deliv';
67            $where  = 'customer_id = ? AND other_deliv_id = ?';
68            $arrVal = array($customer_id, $other_deliv_id);
69            $deliv_count = $objQuery->count($from, $where, $arrVal);
70            if ($deliv_count != 1) {
71                return false;
72            }
73
74            // 別のお届け先を変更
75            $ret = $objQuery->update($from, $sqlval, $where, $arrVal);
76        }
77       
78        return $ret;
79    }
80
81    /**
82     * お届け先を取得
83     *
84     * @param integer $other_deliv_id
85     * @return array()
86     */
87    public function getAddress($other_deliv_id, $customer_id = '')
88    {
89        if (self::delivErrorCheck(array('customer_id' => $customer_id, 'other_deliv_id' => $other_deliv_id))) {
90            return false;
91        }
92       
93        $objQuery =& SC_Query_Ex::getSingletonInstance();
94       
95        $col    = '*';
96        $from   = 'dtb_other_deliv';
97        $where  = 'customer_id = ? AND other_deliv_id = ?';
98        $arrVal = array($customer_id, $other_deliv_id);
99        $address = $objQuery->getRow($col, $from, $where, $arrVal);
100
101        return $address;
102    }
103
104    /**
105     * お届け先の一覧を取得
106     *
107     * @param  integer $customer_id
108     * @param  integer $startno
109     * @return array
110     */
111    public function getList($customer_id, $startno = '')
112    {
113        if (self::delivErrorCheck(array('customer_id' => $customer_id))) {
114            return false;
115        }
116       
117        $objQuery =& SC_Query_Ex::getSingletonInstance();
118        $objQuery->setOrder('other_deliv_id DESC');
119        //スマートフォン用の処理
120        if ($startno != '') {
121            $objQuery->setLimitOffset(SEARCH_PMAX, $startno);
122        }
123
124        $col    = '*';
125        $from   = 'dtb_other_deliv';
126        $where  = 'customer_id = ?';
127        $arrVal = array($customer_id);
128        return $objQuery->select($col, $from, $where, $arrVal);
129    }
130
131    /**
132     * お届け先の削除
133     *
134     * @return void
135     */
136    public function deleteAddress($other_deliv_id, $customer_id = '')
137    {
138        if (self::delivErrorCheck(array('customer_id' => $customer_id, 'other_deliv_id' => $other_deliv_id))) {
139            return false;
140        }
141       
142        $objQuery   =& SC_Query_Ex::getSingletonInstance();
143
144        $from   = 'dtb_other_deliv';
145        $where  = 'customer_id = ? AND other_deliv_id = ?';
146        $arrVal = array($customer_id, $other_deliv_id);
147        return $objQuery->delete($from, $where, $arrVal);
148    }
149
150    /**
151     * お届け先フォーム初期化
152     *
153     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
154     * @return void
155     */
156    public function setFormParam(&$objFormParam)
157    {
158        SC_Helper_Customer_Ex::sfCustomerCommonParam($objFormParam);
159        $objFormParam->addParam('', 'other_deliv_id');
160    }
161
162    /**
163     * お届け先フォームエラーチェック
164     *
165     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
166     * @return void
167     */
168    public function errorCheck(&$objFormParam)
169    {
170        $objErr = SC_Helper_Customer_Ex::sfCustomerCommonErrorCheck($objFormParam);
171
172        return $objErr->arrErr;
173    }
174   
175    /**
176     * お届け先エラーチェック
177     *
178     * @param array $arrParam
179     * @return boolean / false
180     */
181    public function delivErrorCheck($arrParam)
182    {
183        $error_flg = false;
184       
185        if (is_null($arrParam['customer_id']) || !is_numeric($arrParam['customer_id']) || !preg_match("/^\d+$/", $arrParam['customer_id'])) {
186            $error_flg = true;
187        }
188
189        if (strlen($arrParam['other_deliv_id']) > 0 && (!is_numeric($arrParam['other_deliv_id']) || !preg_match("/^\d+$/", $arrParam['other_deliv_id']))) {
190            $error_flg = true;
191        }
192       
193        return $error_flg;
194    }
195}
Note: See TracBrowser for help on using the repository browser.