JSlip  1.0
BasicInfoModel.php
Go to the documentation of this file.
1 <?php
8 require_once(dirname(__FILE__) . '/../../lib/Model.php');
9 
10 class BasicInfoModel extends Model
11 {
12  public function getList($cnd) {
13 
14  $this->connect();
15 
16  $where = $this->_getListWhere($cnd);
17  $cnt = $this->_getListCnt($where);
18  $list = $this->_getListDat($where, $cnt, $cnd['pager']);
19 
20  $this->close();
21 
22  $dat = [];
23  foreach ($list['rec'] as $k => $d) {
24  $dat[$k] = $d;
25  $dat[$k]['era'] = $this->era($d['id'], $d['term_begin']);
26  $dat[$k]['jcnt'] = $this->cntJournal($d['id']);
27  }
28 
29  $list['rec'] = $dat;
30 
31  return $list;
32  }
33 
34  private function _getListWhere($cnd) {
35 
36  $where = " WHERE (TRUE)";
37 
38  if (trim($cnd['cnd_year']) != '') {
39  $where .= " AND `term_year` = '" . $this->esc($cnd['cnd_year']) . "'";
40  }
41 
42  if ($cnd['cnd_name'] != '') {
43  $where .= " AND ((`name` LIKE '%" . $this->esc($cnd['cnd_name']) . "%') OR (`disp_name` LIKE '%" . $this->esc($cnd['cnd_name']) . "%'))";
44  }
45 
46  return $where;
47  }
48 
49  private function _getListCnt($where) {
50 
51  $sql = "SELECT COUNT(*) AS `cnt` FROM `t_basic`" . $where;
52  $rec = $this->getRecord($sql);
53 
54  return $rec[0]['cnt'];
55  }
56 
57  private function _getListDat($where, $cnt, $pager) {
58 
59  $pg = $this->getPaging($cnt, $pager['page'], $pager['rpp']);
60 
61  if ($cnt < 0) {
62  $rec = [];
63  } else {
64  $sql = "SELECT"
65  . " `id`, `valid_flg`, `name`, `disp_name`, `term_year`, `term_begin`, `term_end`, `mid`"
66  . " FROM `t_basic`"
67  . $where
68  . " ORDER BY `id` ASC"
69  . " LIMIT " . $pg['ofst'] . ", " . $pg['rpp']
70  ;
71  $rec = $this->getRecord($sql);
72  }
73 
74  return [
75  'cnt' => $pg['cnt'],
76  'rpp' => $pg['rpp'],
77  'last' => $pg['last'],
78  'page' => $pg['page'],
79  'rec' => $rec,
80  ];
81  }
82 
83  public function getMember() {
84 
85  $this->connect();
86  $sql = "SELECT"
87  . " `m`.`mid`, `a`.`login_id`, `m`.`name`, `m`.`role`"
88  . " FROM `t_auth` `a` INNER JOIN `t_member` `m` ON `a`.`aid` = `m`.`aid`"
89  . " ORDER BY `m`.`name`"
90  ;
91  $rec = $this->getRecord($sql);
92  $this->close();
93 
94  return $rec;
95  }
96 
97  public function getData($bid) {
98 
99  $this->connect();
100  $sql = "SELECT * FROM `t_basic` WHERE `id` = '" . $this->esc($bid) . "'";
101  $rec = $this->getRecord($sql);
102  $this->close();
103 
104  return (empty($rec[0])) ? [] : $rec[0];
105  }
106 
107  public function regist($param) {
108 
109  $err = '';
110 
111  $this->connect();
112  $this->begin();
113 
114  try {
115 
116  $sql = "UPDATE `t_basic` SET"
117  . " `name`" . " = '" . $this->esc($param['name']) . "'"
118  . ", `disp_name`" . " = '" . $this->esc($param['disp_name']) . "'"
119  . ", `term_year`" . " = '" . $this->esc($param['term_year']) . "'"
120  . ", `term_begin`" . " = '" . $this->esc($param['term_begin']) . "'"
121  . ", `term_end`" . " = '" . $this->esc($param['term_end']) . "'"
122  . ", `mid`" . " = '" . $this->esc($param['mid']) . "'"
123  . ", `valid_flg`" . " = " . $param['valid_flg']
124  . ", `update_person`" . " = " . $_SESSION['minfo']['mid']
125  . " WHERE `id` = '" . $this->esc($param['bid']) . "'"
126  ;
127  $ans = $this->query($sql);
128 
129  } catch(Exception $e) {
130  $err = $e->getMessage();
131  }
132 
133  if (empty($err)) {
134  $this->commit();
135  } else {
136  $this->rollback();
137  }
138 
139  $this->close();
140 
141  return $err;
142  }
143 
144  public function getMemberList($list) {
145 
146  $mid = [];
147  foreach ($list as $rec) {
148  if (!empty($rec['mid'])) {
149  $mid[] = $rec['mid'];
150  }
151  }
152 
153  $ans = [];
154 
155  if (!empty($mid)) {
156 
157  $this->connect();
158 
159  $sql = "SELECT `mid`, `name` FROM `t_member` WHERE `mid` IN (" . implode(',', $mid) . ")";
160  $rec = $this->getRecord($sql);
161 
162  $this->close();
163 
164  foreach ($rec as $r) {
165  $ans[$r['mid']] = $r['name'];
166  }
167  }
168 
169  return $ans;
170  }
171 }
Model\connect
connect()
Definition: Model.php:12
Model\cntJournal
cntJournal($bid)
Definition: Model.php:494
Model\begin
begin()
Definition: Model.php:31
BasicInfoModel\getMember
getMember()
Definition: BasicInfoModel.php:83
Model\query
query($sql)
Definition: Model.php:47
Model\getRecord
getRecord($sql)
Definition: Model.php:55
BasicInfoModel\_getListDat
_getListDat($where, $cnt, $pager)
Definition: BasicInfoModel.php:57
BasicInfoModel\_getListCnt
_getListCnt($where)
Definition: BasicInfoModel.php:49
BasicInfoModel\_getListWhere
_getListWhere($cnd)
Definition: BasicInfoModel.php:34
Model\era
era($bid, $day)
Definition: Model.php:464
$dat
$dat
Definition: tex_tmplt_bs.php:291
Model
Definition: Model.php:8
Model\commit
commit()
Definition: Model.php:35
BasicInfoModel\regist
regist($param)
Definition: BasicInfoModel.php:107
BasicInfoModel
Definition: BasicInfoModel.php:10
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
BasicInfoModel\getList
getList($cnd)
Definition: BasicInfoModel.php:12
BasicInfoModel\getData
getData($bid)
Definition: BasicInfoModel.php:97
BasicInfoModel\getMemberList
getMemberList($list)
Definition: BasicInfoModel.php:144
$cnt
$cnt
Definition: tex_tmplt_bs.php:319
Model\rollback
rollback()
Definition: Model.php:39