source: branches/version-2_13-dev/data/class/helper/SC_Helper_Kiyaku.php @ 22735

Revision 22735, 4.8 KB checked in by h_yoshimoto, 11 years ago (diff)

#2193 ユニットテストチームのコミットをマージ(from camp/camp-2_13-tests)

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_Kiyaku
32{
33    /**
34     * 会員規約の情報を取得.
35     *
36     * @param integer $kiyaku_id 会員規約ID
37     * @param boolean $has_deleted 削除された会員規約も含む場合 true; 初期値 false
38     * @return array
39     */
40    public function getKiyaku($kiyaku_id, $has_deleted = false)
41    {
42        $objQuery =& SC_Query_Ex::getSingletonInstance();
43        $where = 'kiyaku_id = ?';
44        if (!$has_deleted) {
45            $where .= ' AND del_flg = 0';
46        }
47        $arrRet = $objQuery->select('*', 'dtb_kiyaku', $where, array($kiyaku_id));
48        return $arrRet[0];
49    }
50
51    /**
52     * 会員規約一覧の取得.
53     *
54     * @param boolean $has_deleted 削除された会員規約も含む場合 true; 初期値 false
55     * @return array
56     */
57    public function getList($has_deleted = false)
58    {
59        $objQuery =& SC_Query_Ex::getSingletonInstance();
60        $col = 'kiyaku_id, kiyaku_title, kiyaku_text';
61        $where = '';
62        if (!$has_deleted) {
63            $where .= 'del_flg = 0';
64        }
65        $table = 'dtb_kiyaku';
66        $objQuery->setOrder('rank DESC');
67        $arrRet = $objQuery->select($col, $table, $where);
68        return $arrRet;
69    }
70
71    /**
72     * 会員規約の登録.
73     *
74     * @param array $sqlval
75     * @return multiple 登録成功:会員規約ID, 失敗:FALSE
76     */
77    public function saveKiyaku($sqlval)
78    {
79        $objQuery =& SC_Query_Ex::getSingletonInstance();
80
81        $kiyaku_id = $sqlval['kiyaku_id'];
82        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
83        // 新規登録
84        if ($kiyaku_id == '') {
85            // INSERTの実行
86            $sqlval['rank'] = $objQuery->max('rank', 'dtb_kiyaku') + 1;
87            $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
88            $sqlval['kiyaku_id'] = $objQuery->nextVal('dtb_kiyaku_kiyaku_id');
89            $ret = $objQuery->insert('dtb_kiyaku', $sqlval);
90        // 既存編集
91        } else {
92            unset($sqlval['creator_id']);
93            unset($sqlval['create_date']);
94            $where = 'kiyaku_id = ?';
95            $ret = $objQuery->update('dtb_kiyaku', $sqlval, $where, array($kiyaku_id));
96        }
97        return ($ret) ? $sqlval['kiyaku_id'] : FALSE;
98    }
99
100    /**
101     * 会員規約の削除.
102     *
103     * @param integer $kiyaku_id 会員規約ID
104     * @return void
105     */
106    public function deleteKiyaku($kiyaku_id)
107    {
108        $objDb = new SC_Helper_DB_Ex();
109        // ランク付きレコードの削除
110        $objDb->sfDeleteRankRecord('dtb_kiyaku', 'kiyaku_id', $kiyaku_id);
111    }
112
113    /**
114     * 会員規約の表示順をひとつ上げる.
115     *
116     * @param integer $kiyaku_id 会員規約ID
117     * @return void
118     */
119    public function rankUp($kiyaku_id)
120    {
121        $objDb = new SC_Helper_DB_Ex();
122        $objDb->sfRankUp('dtb_kiyaku', 'kiyaku_id', $kiyaku_id);
123    }
124
125    /**
126     * 会員規約の表示順をひとつ下げる.
127     *
128     * @param integer $kiyaku_id 会員規約ID
129     * @return void
130     */
131    public function rankDown($kiyaku_id)
132    {
133        $objDb = new SC_Helper_DB_Ex();
134        $objDb->sfRankDown('dtb_kiyaku', 'kiyaku_id', $kiyaku_id);
135    }
136
137    /**
138     * 同じタイトルの規約が存在するか確認.
139     *
140     * @param string $title 規約タイトル
141     * @param integer $kiyaku_id 会員規約ID
142     * @return boolean 同名のタイトルが存在:TRUE
143     */
144    public function isTitleExist($title, $kiyaku_id = NULL)
145    {
146        $objQuery =& SC_Query_Ex::getSingletonInstance();
147       
148        $where  = 'del_flg = 0 AND kiyaku_title = ?';
149        $arrVal = array($title);
150       
151        if(!SC_Utils_Ex::isBlank($kiyaku_id)) {
152            $where   .= ' AND kiyaku_id <> ?';
153            $arrVal[] = $kiyaku_id;
154        }
155       
156        $arrRet = $objQuery->select('kiyaku_id, kiyaku_title', 'dtb_kiyaku', $where, $arrVal);
157
158        return !SC_Utils_Ex::isBlank($arrRet);
159    }
160}
Note: See TracBrowser for help on using the repository browser.