JSlip  1.0
UserAcitmModel.php
Go to the documentation of this file.
1 <?php
8 require_once(dirname(__FILE__) . '/../../lib/Model.php');
9 
10 class UserAcitmModel extends Model
11 {
12  public $bid;
13 
14  function __construct($bid) {
15  $this->bid = $bid;
16  }
17 
18  public function getList($cnd) {
19 
20  $this->connect();
21 
22  $where = $this->_getListWhere($cnd);
23  $cnt = $this->_getListCnt($where);
24  $list = $this->_getListDat($where, $cnt, $cnd['pager']);
25 
26  $this->close();
27 
28  return $list;
29  }
30 
31  private function _getListWhere($cnd) {
32 
33  $where = " WHERE `bid` = '" . $this->esc($this->bid) . "'";
34 
35  if ($cnd['cnd_kana'] != '') {
36  $where .= " AND `kana` LIKE '%" . $this->esc($cnd['cnd_kana']) . "%'";
37  }
38 
39  if ($cnd['cnd_name'] != '') {
40  $where .= " AND `name` LIKE '%" . $this->esc($cnd['cnd_name']) . "%'";
41  }
42 
43  return $where;
44  }
45 
46  private function _getListCnt($where) {
47 
48  $sql = "SELECT COUNT(*) AS `cnt` FROM `t_account`" . $where;
49  $rec = $this->getRecord($sql);
50 
51  return $rec[0]['cnt'];
52  }
53 
54  private function _getListDat($where, $cnt, $pager) {
55 
56  $pg = $this->getPaging($cnt, $pager['page'], $pager['rpp']);
57 
58  if ($cnt < 0) {
59  $rec = [];
60  } else {
61  $sql = "SELECT * FROM `t_account`" . $where
62  . " ORDER BY `ccd`, `item`, `item_ccd`, `kana`"
63  . " LIMIT " . $pg['ofst'] . ", " . $pg['rpp']
64  ;
65  $rec = $this->getRecord($sql);
66  }
67 
68  return [
69  'cnt' => $pg['cnt'],
70  'rpp' => $pg['rpp'],
71  'last' => $pg['last'],
72  'page' => $pg['page'],
73  'rec' => $rec,
74  ];
75  }
76 
77  public function getData($id) {
78 
79  $this->connect();
80  $sql = "SELECT * FROM `t_account` WHERE `id` = '" . $this->esc($id) . "'";
81  $rec = $this->getRecord($sql);
82  $this->close();
83 
84  return (empty($rec[0])) ? [] : $rec[0];
85  }
86 
87  public function regist($param) {
88 
89  $err = '';
90 
91  $this->connect();
92  $this->begin();
93 
94  try {
95 
96  $sql = "UPDATE `t_account` SET"
97  . " `ccd`" . " = '" . $this->esc($param['ccd']) . "'"
98  . ", `item`" . " = '" . $this->esc($param['item']) . "'"
99  . ", `item_ccd`" . " = '" . $this->esc($param['item_ccd']) . "'"
100  . ", `division`" . " = '" . $this->esc($param['division']) . "'"
101  . ", `kana`" . " = '" . $this->esc($param['kana']) . "'"
102  . ", `name`" . " = '" . $this->esc($param['name']) . "'"
103  . ", `update_person`" . " = " . $_SESSION['minfo']['mid']
104  . " WHERE `id` = '" . $this->esc($param['id']) . "'"
105  ;
106  $ans = $this->query($sql);
107 
108  } catch(Exception $e) {
109  $err = $e->getMessage();
110  }
111 
112  if (empty($err)) {
113  $this->commit();
114  } else {
115  $this->rollback();
116  }
117 
118  $this->close();
119 
120  return $err;
121  }
122 
123  public function insert($param) {
124 
125  $err = '';
126 
127  $this->connect();
128  $this->begin();
129 
130  try {
131 
132  $sql = "INSERT INTO `t_account`"
133  . " (`bid`, `ccd`, `item`, `item_ccd`, `division`, `kana`, `name`, `delete_flg`, `edit_flg`, `update_person`)"
134  . " VALUES"
135  . " ('" . $this->esc($param['bid']) . "'"
136  . ", '" . $this->esc($param['ccd']) . "'"
137  . ", '" . $this->esc($param['item']) . "'"
138  . ", '" . $this->esc($param['item_ccd']) . "'"
139  . ", '" . $this->esc($param['division']) . "'"
140  . ", '" . $this->esc($param['kana']) . "'"
141  . ", '" . $this->esc($param['name']) . "'"
142  . ", TRUE"
143  . ", TRUE"
144  . ", '" . $_SESSION['minfo']['mid']. "'"
145  . ")"
146  ;
147  $ans = $this->query($sql);
148 
149  } catch(Exception $e) {
150  $err = $e->getMessage();
151  }
152 
153  if (empty($err)) {
154  $this->commit();
155  } else {
156  $this->rollback();
157  }
158 
159  $this->close();
160 
161  return $err;
162  }
163 
164  public function delete($param) {
165 
166  $err = '';
167  $id = $param['id'];
168 
169  $this->connect();
170  $this->begin();
171 
172  try {
173 
174  $sql = "DELETE FROM `t_account` WHERE `id` = '" . $this->esc($id) . "'";
175  $ans = $this->query($sql);
176 
177  } catch(Exception $e) {
178  $err = $e->getMessage();
179  }
180 
181  if (empty($err)) {
182  $this->commit();
183  } else {
184  $this->rollback();
185  }
186 
187  $this->close();
188 
189  return $err;
190  }
191 
192  public function chkDup($param) {
193 
194  $this->connect();
195 
196  $sql = "SELECT COUNT(*) AS `cnt`"
197  . " FROM `t_account`"
198  . " WHERE `bid` = '" . $this->esc($this->bid) . "'"
199  . " AND `ccd` = '" . $this->esc($param['ccd']) . "'"
200  . " AND `item` = '" . $this->esc($param['item']) . "'"
201  ;
202 
203  $rec = $this->getRecord($sql);
204 
205  $this->close();
206 
207  return $rec[0]['cnt'];
208  }
209 }
UserAcitmModel\_getListWhere
_getListWhere($cnd)
Definition: UserAcitmModel.php:31
UserAcitmModel\chkDup
chkDup($param)
Definition: UserAcitmModel.php:192
Model\connect
connect()
Definition: Model.php:12
Model\begin
begin()
Definition: Model.php:31
Model\query
query($sql)
Definition: Model.php:47
Model\getRecord
getRecord($sql)
Definition: Model.php:55
UserAcitmModel\$bid
$bid
Definition: UserAcitmModel.php:12
UserAcitmModel\getData
getData($id)
Definition: UserAcitmModel.php:77
UserAcitmModel\getList
getList($cnd)
Definition: UserAcitmModel.php:18
UserAcitmModel\insert
insert($param)
Definition: UserAcitmModel.php:123
UserAcitmModel
Definition: UserAcitmModel.php:10
Model
Definition: Model.php:8
Model\commit
commit()
Definition: Model.php:35
Model\close
close()
Definition: Model.php:27
Model\esc
esc($str)
Definition: Model.php:43
Model\getPaging
getPaging($cnt, $page, $rpp)
Definition: Model.php:69
UserAcitmModel\_getListDat
_getListDat($where, $cnt, $pager)
Definition: UserAcitmModel.php:54
UserAcitmModel\__construct
__construct($bid)
Definition: UserAcitmModel.php:14
$cnt
$cnt
Definition: tex_tmplt_bs.php:319
UserAcitmModel\regist
regist($param)
Definition: UserAcitmModel.php:87
Model\rollback
rollback()
Definition: Model.php:39
UserAcitmModel\_getListCnt
_getListCnt($where)
Definition: UserAcitmModel.php:46