JSlip  1.0
UserItemController.php
Go to the documentation of this file.
1 <?php
8 require_once(dirname(__FILE__) . '/../../lib/View.php');
9 require_once(dirname(__FILE__) . '/../../lib/Controller.php');
10 require_once(dirname(__FILE__) . '/UserItemModel.php');
11 
12 define('PAGER_RPP', 10);
13 
15 {
16  public $rest;
17  public $param;
18  public $model;
19  public $view;
20  public $viewName;
21  public $dat;
22  public $pager;
23  public $err;
24  public $bid;
25  public $basic;
26  public $acitm;
27  public $kcode;
28  public $const;
29 
30  public function main($param) {
31 
32  $this->rest = '';
33  $this->param = $param;
34  $this->bid = $_SESSION['minfo']['bid'];
35  $this->model = new UserItemModel($this->bid);
36  $this->view = new View();
37 
38  $this->param['base'] = dirname(__FILE__);
39 
40  $basic = $this->model->getBasicByBid($this->bid);
41  $this->_getConst();
42 
43  if (empty($basic[0])) {
44  $this->_error('基本情報が見つかりません。');
45  return;
46  } else {
47  $this->basic = $basic[0];
48  }
49 
50  if (empty($this->param['act'])) {
51  $this->_list();
52  } else {
53  switch ($this->param['act']) {
54  case 'create': $this->_create(); break;
55  case 'drop': $this->_drop(); break;
56  case 'edit': $this->_edit(); break;
57  case 'use': $this->_use(); break;
58  case 'remember': $this->_remember(); break;
59  case 'search': $this->_search(); break;
60  case 'check': $this->_check(); break;
61  case 'regist': $this->_regist(); break;
62  default: $this->_list(); break;
63  }
64  }
65  }
66 
67  private function _error($err) {
68 
69  $this->viewName = 'user_item_err';
70  $this->err = $err;
71  }
72 
73  private function _list() {
74 
75  $this->viewName = 'user_item_list';
76 
77  $this->dat['cnd'] = [
78  'cnd_name' => '',
79  'cnd_kana' => '',
80  'pager' => ['page' => 1, 'rpp' => PAGER_RPP],
81  ];
82 
83  $this->dat['list'] = $this->model->getList($this->dat['cnd']);
84  $this->acitm = $this->model->getAcitm($this->bid);
85 
86  $_SESSION['user_item_list_cnd'] = $this->dat['cnd'];
87  }
88 
89  private function _getConst() {
90  $this->const['c_c1'] = $this->model->getConst('c_c1');
91  $this->const['c_c2'] = $this->model->getConst('c_c2');
92  $this->const['c_c3'] = $this->model->getConst('c_c3');
93  $this->const['c_c4'] = $this->model->getConst('c_c4');
94  }
95 
96  private function _search() {
97 
98  $this->viewName = 'user_item_list';
99 
100  $this->dat['cnd'] = [
101  'cnd_name' => $this->param['cnd_name'],
102  'cnd_kana' => $this->param['cnd_kana'],
103  'pager' => ['page' => $this->param['page_curr'], 'rpp' => PAGER_RPP],
104  ];
105 
106  $this->dat['list'] = $this->model->getList($this->dat['cnd']);
107 
108  $_SESSION['user_item_list_cnd'] = $this->dat['cnd'];
109  }
110 
111  private function _remember() {
112 
113  $this->viewName = 'user_item_list';
114  $this->dat['cnd'] = $_SESSION['user_item_list_cnd'];
115  $this->dat['list'] = $this->model->getList($this->dat['cnd']);
116  $this->acitm = $this->model->getAcitm($this->bid);
117  }
118 
119  private function _edit() {
120 
121  $this->viewName = 'user_item_edit';
122  $this->kcode = $this->model->getKcode($this->bid);
123  $this->dat = $this->model->getData($this->param['id']);
124  }
125 
126  private function _use() {
127 
128  $err = $this->model->setValidFlg($this->param);
129 
130  if (empty($err)) {
131  $this->rest = json_encode(['sts' => 'OK']);
132  } else {
133  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
134  }
135  }
136 
137  private function _check() {
138 
139  $err = [];
140 
141  $insert = (empty($this->param['insert'])) ? false : true;
142  $item = $this->param['item'];
143  $kana = $this->param['kana'];
144  $name = $this->param['name'];
145 
146  if (empty($kana)) {
147  $err[] = '科目名(かな)は必須です。';
148  }
149 
150  if (empty($name)) {
151  $err[] = '科目名は必須です。';
152  }
153 
154  if ($item == '') {
155  $err[] = '科目細分コードは必須です。';
156  } else {
157  $v = (int)$item;
158  if ($v < 0 || $v > 99) {
159  $err[] = '科目細分コードが不正です。';
160  }
161  }
162 
163  if (empty($err)) {
164  if ($this->model->chkDup($this->param) > 0) {
165  $err[] = 'コードが重複しています。';
166  }
167  }
168 
169  if (empty($err)) {
170  $this->rest = json_encode(['sts' => 'OK']);
171  } else {
172  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
173  }
174  }
175 
176  private function _regist() {
177 
178  $insert = (empty($this->param['insert'])) ? false : true;
179 
180  if ($insert) {
181  $err = $this->model->insert($this->param);
182  } else {
183  $err = $this->model->regist($this->param);
184  }
185 
186  if (!empty($err)) {
187  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
188  return;
189  }
190 
191  $this->rest = json_encode(['sts' => 'OK']);
192  }
193 
194  private function _create() {
195 
196  $this->viewName = 'user_item_create';
197  $this->kcode = $this->model->getKcode($this->bid);
198  }
199 
200  private function _drop() {
201 
202  $err = $this->model->delete($this->param);
203 
204  if (!empty($err)) {
205  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
206  return;
207  }
208 
209  $this->rest = json_encode(['sts' => 'OK']);
210  }
211 }
UserItemController\_list
_list()
Definition: UserItemController.php:73
UserItemController\$basic
$basic
Definition: UserItemController.php:25
PAGER_RPP
const PAGER_RPP
Definition: UserItemController.php:12
UserItemController\$model
$model
Definition: UserItemController.php:18
View
Definition: View.php:8
UserItemController\$rest
$rest
Definition: UserItemController.php:16
UserItemController\_drop
_drop()
Definition: UserItemController.php:200
UserItemController\$param
$param
Definition: UserItemController.php:17
UserItemController\$dat
$dat
Definition: UserItemController.php:21
UserItemModel
Definition: UserItemModel.php:10
UserItemController\$bid
$bid
Definition: UserItemController.php:24
UserItemController\$const
$const
Definition: UserItemController.php:28
UserItemController\_use
_use()
Definition: UserItemController.php:126
UserItemController\$err
$err
Definition: UserItemController.php:23
Controller
Definition: Controller.php:15
UserItemController\_create
_create()
Definition: UserItemController.php:194
UserItemController\_remember
_remember()
Definition: UserItemController.php:111
UserItemController\_check
_check()
Definition: UserItemController.php:137
UserItemController\_error
_error($err)
Definition: UserItemController.php:67
UserItemController\_getConst
_getConst()
Definition: UserItemController.php:89
UserItemController\$viewName
$viewName
Definition: UserItemController.php:20
UserItemController\_search
_search()
Definition: UserItemController.php:96
UserItemController\_edit
_edit()
Definition: UserItemController.php:119
UserItemController\$acitm
$acitm
Definition: UserItemController.php:26
UserItemController\_regist
_regist()
Definition: UserItemController.php:176
UserItemController\$pager
$pager
Definition: UserItemController.php:22
UserItemController\$view
$view
Definition: UserItemController.php:19
UserItemController\main
main($param)
Definition: UserItemController.php:30
UserItemController\$kcode
$kcode
Definition: UserItemController.php:27
UserItemController
Definition: UserItemController.php:14