1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2010 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 | class SC_Model { |
---|
25 | |
---|
26 | var $arrRegistColumn; |
---|
27 | var $select_key; |
---|
28 | var $select_key_seq; |
---|
29 | var $select_table; |
---|
30 | var $insert_table; |
---|
31 | |
---|
32 | function __construct() { |
---|
33 | $this->objQuery = new SC_Query(); |
---|
34 | if (!$this->insert_table) { |
---|
35 | $this->insert_table = array($this->select_table); |
---|
36 | } |
---|
37 | if (!$this->select_key_seq) { |
---|
38 | $this->select_key_seq = $this->select_table . '_' . $this->select_key; |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | function regist($array) { |
---|
43 | |
---|
44 | //-- 編集登録実行 |
---|
45 | $this->objQuery->begin(); |
---|
46 | |
---|
47 | $regist_key = $this->objQuery->nextVal($this->select_key_seq); |
---|
48 | |
---|
49 | foreach ($this->insert_table as $key => $table) { |
---|
50 | $arrRegist = array(); |
---|
51 | foreach ($this->arrRegistColumn as $data) { |
---|
52 | if ($data["db"] == $table) { |
---|
53 | $arrRegist[$data["column"]] = ($array[$data["column"]] != "") ? $array[$data["column"]] : NULL; |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | $arrRegist["update_date"] = "Now()"; |
---|
58 | $arrRegist[$this->select_key] = $regist_key; |
---|
59 | |
---|
60 | $this->objQuery->insert($table, $arrRegist); |
---|
61 | } |
---|
62 | |
---|
63 | $this->objQuery->commit(); |
---|
64 | } |
---|
65 | |
---|
66 | function update($array) { |
---|
67 | |
---|
68 | //-- 編集登録実行 |
---|
69 | $this->objQuery->begin(); |
---|
70 | |
---|
71 | foreach ($this->insert_table as $table) { |
---|
72 | $arrRegist = array(); |
---|
73 | foreach ($this->arrRegistColumn as $data) { |
---|
74 | if ($data["db"] == $table) { |
---|
75 | $arrRegist[$data["column"]] = ($array[$data["column"]] != "") ? $array[$data["column"]] : NULL; |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | $arrRegist["update_date"] = "Now()"; |
---|
80 | $id = $array[$this->select_key]; |
---|
81 | $where = $this->select_key ." = ?"; |
---|
82 | $arrval = array($id); |
---|
83 | $this->objQuery->update($table, $arrRegist, $where, $arrval); |
---|
84 | } |
---|
85 | |
---|
86 | $this->objQuery->commit(); |
---|
87 | } |
---|
88 | |
---|
89 | function getData($id) { |
---|
90 | $col = "*"; |
---|
91 | $table = $this->select_table; |
---|
92 | $where = $this->select_key ." = ?"; |
---|
93 | $arrval = array($id); |
---|
94 | $result = $this->objQuery->select($col, $table, $where , $arrval); |
---|
95 | return $result[0]; |
---|
96 | } |
---|
97 | |
---|
98 | function getList($search_condition, $page_max, $offset) { |
---|
99 | $col = "*"; |
---|
100 | $table = $this->select_table; |
---|
101 | $this->arrval = array(); |
---|
102 | $this->setWhere($search_condition); |
---|
103 | $this->objQuery->setLimitOffset($page_max, $offset); |
---|
104 | $this->setOrder(); |
---|
105 | $result = $this->objQuery->select($col, $table, $this->where , $this->arrval); |
---|
106 | return $result; |
---|
107 | } |
---|
108 | |
---|
109 | function setWhere($search_condition) { |
---|
110 | } |
---|
111 | |
---|
112 | function setOrder() { |
---|
113 | $this->objQuery->setOrder($this->select_key . " DESC"); |
---|
114 | } |
---|
115 | |
---|
116 | function delete($id) { |
---|
117 | $arrRegist = array( |
---|
118 | "del_flg" => 1, |
---|
119 | "update_date" => "NOW()", |
---|
120 | ); |
---|
121 | |
---|
122 | //-- 編集登録実行 |
---|
123 | $this->objQuery->begin(); |
---|
124 | foreach ($this->insert_table as $table) { |
---|
125 | $where = $this->select_key ." = ?"; |
---|
126 | $arrval = array($id); |
---|
127 | $this->objQuery->update($table, $arrRegist, $where, $arrval); |
---|
128 | } |
---|
129 | $this->objQuery->commit(); |
---|
130 | } |
---|
131 | |
---|
132 | //---- 取得文字列の変換 |
---|
133 | function convertParam($array) { |
---|
134 | /* |
---|
135 | * 文字列の変換 |
---|
136 | * K : 「半角(ハンカク)片仮名」を「全角片仮名」に変換 |
---|
137 | * C : 「全角ひら仮名」を「全角かた仮名」に変換 |
---|
138 | * V : 濁点付きの文字を一文字に変換。"K","H"と共に使用します |
---|
139 | * n : 「全角」数字を「半角(ハンカク)」に変換 |
---|
140 | * a : 全角英数字を半角英数字に変換する |
---|
141 | */ |
---|
142 | // カラム名とコンバート情報 |
---|
143 | foreach ($this->arrRegistColumn as $data) { |
---|
144 | $arrConvList[ $data["column"] ] = $data["convert"]; |
---|
145 | } |
---|
146 | // 文字変換 |
---|
147 | foreach ($arrConvList as $key => $val) { |
---|
148 | // POSTされてきた値のみ変換する。 |
---|
149 | if(strlen(($array[$key])) > 0) { |
---|
150 | $array[$key] = mb_convert_kana($array[$key] ,$val); |
---|
151 | } |
---|
152 | } |
---|
153 | return $array; |
---|
154 | } |
---|
155 | |
---|
156 | //---- 入力エラーチェック |
---|
157 | function errorCheck($array) { |
---|
158 | $this->arrForm = $array; |
---|
159 | $this->objErr = new SC_CheckError($this->arrForm); |
---|
160 | |
---|
161 | foreach ($this->arrRegistColumn as $column) { |
---|
162 | if (!empty($column['check'])) { |
---|
163 | $value = ($column['length']) ? array($column['name'], $column['column'], $column['length']) : array($column['name'], $column['column']); |
---|
164 | $this->objErr->doFunc($value, $column['check']); |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | $this->customErrorCheck(); |
---|
169 | return $this->objErr->arrErr; |
---|
170 | |
---|
171 | } |
---|
172 | |
---|
173 | function customErrorCheck() { |
---|
174 | } |
---|
175 | } |
---|
176 | ?> |
---|