JSlip  1.0
UserSectionModel.php
Go to the documentation of this file.
1 <?php
8 require_once(dirname(__FILE__) . '/../../lib/Model.php');
9 
10 class UserSectionModel 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_section`" . $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_section`" . $where
62  . " ORDER BY `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_section` 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_section` SET"
97  . " `bid`" . " = '" . $this->esc($param['bid']) . "'"
98  . ", `kana`" . " = '" . $this->esc($param['kana']) . "'"
99  . ", `name`" . " = '" . $this->esc($param['name']) . "'"
100  . ", `update_person`" . " = " . $_SESSION['minfo']['mid']
101  . " WHERE `id` = '" . $this->esc($param['id']) . "'"
102  ;
103  $ans = $this->query($sql);
104 
105  } catch(Exception $e) {
106  $err = $e->getMessage();
107  }
108 
109  if (empty($err)) {
110  $this->commit();
111  } else {
112  $this->rollback();
113  }
114 
115  $this->close();
116 
117  return $err;
118  }
119 
120  public function insert($param) {
121 
122  $err = '';
123 
124  $this->connect();
125  $this->begin();
126 
127  try {
128 
129  $sql = "INSERT INTO `t_section`"
130  . " (`bid`, `kana`, `name`, `update_person`)"
131  . " VALUES"
132  . " ('" . $this->esc($param['bid']) . "'"
133  . ", '" . $this->esc($param['kana']) . "'"
134  . ", '" . $this->esc($param['name']) . "'"
135  . ", '" . $_SESSION['minfo']['mid']. "'"
136  . ")"
137  ;
138  $ans = $this->query($sql);
139 
140  } catch(Exception $e) {
141  $err = $e->getMessage();
142  }
143 
144  if (empty($err)) {
145  $this->commit();
146  } else {
147  $this->rollback();
148  }
149 
150  $this->close();
151 
152  return $err;
153  }
154 
155  public function delete($param) {
156 
157  $err = '';
158  $id = $param['id'];
159 
160  $this->connect();
161  $this->begin();
162 
163  try {
164 
165  $sql = "DELETE FROM `t_section` WHERE `id` = '" . $this->esc($id) . "'";
166  $ans = $this->query($sql);
167 
168  } catch(Exception $e) {
169  $err = $e->getMessage();
170  }
171 
172  if (empty($err)) {
173  $this->commit();
174  } else {
175  $this->rollback();
176  }
177 
178  $this->close();
179 
180  return $err;
181  }
182 
183  public function chkDup($name) {
184 
185  $this->connect();
186  $sql = "SELECT COUNT(*) AS `cnt` FROM `t_section` WHERE `name` = '" . $this->esc($name) . "'";
187  $rec = $this->getRecord($sql);
188  $this->close();
189 
190  return $rec[0]['cnt'];
191  }
192 }
UserSectionModel\_getListCnt
_getListCnt($where)
Definition: UserSectionModel.php:46
UserSectionModel\$bid
$bid
Definition: UserSectionModel.php:12
UserSectionModel\chkDup
chkDup($name)
Definition: UserSectionModel.php:183
UserSectionModel\_getListDat
_getListDat($where, $cnt, $pager)
Definition: UserSectionModel.php:54
Model\connect
connect()
Definition: Model.php:12
Model\begin
begin()
Definition: Model.php:31
UserSectionModel\insert
insert($param)
Definition: UserSectionModel.php:120
Model\query
query($sql)
Definition: Model.php:47
Model\getRecord
getRecord($sql)
Definition: Model.php:55
UserSectionModel
Definition: UserSectionModel.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
UserSectionModel\__construct
__construct($bid)
Definition: UserSectionModel.php:14
UserSectionModel\getList
getList($cnd)
Definition: UserSectionModel.php:18
UserSectionModel\getData
getData($id)
Definition: UserSectionModel.php:77
$cnt
$cnt
Definition: tex_tmplt_bs.php:319
UserSectionModel\_getListWhere
_getListWhere($cnd)
Definition: UserSectionModel.php:31
UserSectionModel\regist
regist($param)
Definition: UserSectionModel.php:87
Model\rollback
rollback()
Definition: Model.php:39