JSlip  1.0
UserSectionController.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__) . '/UserSectionModel.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 
27  public function main($param) {
28 
29  $this->rest = '';
30  $this->param = $param;
31  $this->bid = $_SESSION['minfo']['bid'];
32  $this->model = new UserSectionModel($this->bid);
33  $this->view = new View();
34 
35  $this->param['base'] = dirname(__FILE__);
36 
37  $basic = $this->model->getBasicByBid($this->bid);
38 
39  if (empty($basic[0])) {
40  $this->_error('基本情報が見つかりません。');
41  return;
42  } else {
43  $this->basic = $basic[0];
44  }
45 
46  if (empty($this->param['act'])) {
47  $this->_list();
48  } else {
49  switch ($this->param['act']) {
50  case 'create': $this->_create(); break;
51  case 'drop': $this->_drop(); break;
52  case 'edit': $this->_edit(); break;
53  case 'remember': $this->_remember(); break;
54  case 'search': $this->_search(); break;
55  case 'check': $this->_check(); break;
56  case 'regist': $this->_regist(); break;
57  default: $this->_list(); break;
58  }
59  }
60  }
61 
62  private function _error($err) {
63 
64  $this->viewName = 'user_section_err';
65  $this->err = $err;
66  }
67 
68  private function _list() {
69 
70  $this->viewName = 'user_section_list';
71 
72  $this->dat['cnd'] = [
73  'cnd_kana' => '',
74  'cnd_name' => '',
75  'pager' => ['page' => 1, 'rpp' => PAGER_RPP],
76  ];
77 
78  $this->dat['list'] = $this->model->getList($this->dat['cnd']);
79 
80  $_SESSION['user_section_list_cnd'] = $this->dat['cnd'];
81  }
82 
83  private function _search() {
84 
85  $this->viewName = 'user_section_list';
86 
87  $this->dat['cnd'] = [
88  'cnd_kana' => $this->param['cnd_kana'],
89  'cnd_name' => $this->param['cnd_name'],
90  'pager' => ['page' => $this->param['page_curr'], 'rpp' => PAGER_RPP],
91  ];
92 
93  $this->dat['list'] = $this->model->getList($this->dat['cnd']);
94 
95  $_SESSION['user_section_list_cnd'] = $this->dat['cnd'];
96  }
97 
98  private function _remember() {
99 
100  $this->viewName = 'user_section_list';
101  $this->dat['cnd'] = $_SESSION['user_section_list_cnd'];
102  $this->dat['list'] = $this->model->getList($this->dat['cnd']);
103  }
104 
105  private function _edit() {
106 
107  $this->viewName = 'user_section_edit';
108  $this->dat = $this->model->getData($this->param['id']);
109  }
110 
111  private function _check() {
112 
113  $err = [];
114 
115  $insert = (empty($this->param['insert'])) ? false : true;
116  $kana = $this->param['kana'];
117  $name = $this->param['name'];
118 
119  if (empty($kana)) {
120  $err[] = '部門(かな)は必須です。';
121  }
122 
123  if (empty($name)) {
124  $err[] = '部門は必須です。';
125  }
126 
127  if ($this->model->chkDup($name) > 0) {
128  $err[] = '部門名は既に存在します。';
129  }
130 
131  if (empty($err)) {
132  $this->rest = json_encode(['sts' => 'OK']);
133  } else {
134  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
135  }
136  }
137 
138  private function _regist() {
139 
140  $insert = (empty($this->param['insert'])) ? false : true;
141 
142  if ($insert) {
143  $err = $this->model->insert($this->param);
144  } else {
145  $err = $this->model->regist($this->param);
146  }
147 
148  if (!empty($err)) {
149  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
150  return;
151  }
152 
153  $this->rest = json_encode(['sts' => 'OK']);
154  }
155 
156  private function _create() {
157 
158  $this->viewName = 'user_section_create';
159  }
160 
161  private function _drop() {
162 
163  $err = $this->model->delete($this->param);
164 
165  if (!empty($err)) {
166  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
167  return;
168  }
169 
170  $this->rest = json_encode(['sts' => 'OK']);
171  }
172 }
UserSectionController\_edit
_edit()
Definition: UserSectionController.php:105
UserSectionController\_remember
_remember()
Definition: UserSectionController.php:98
UserSectionController\$view
$view
Definition: UserSectionController.php:19
UserSectionController\_check
_check()
Definition: UserSectionController.php:111
UserSectionController\_search
_search()
Definition: UserSectionController.php:83
UserSectionController\$rest
$rest
Definition: UserSectionController.php:16
UserSectionController\main
main($param)
Definition: UserSectionController.php:27
UserSectionController
Definition: UserSectionController.php:14
UserSectionController\_create
_create()
Definition: UserSectionController.php:156
UserSectionController\$basic
$basic
Definition: UserSectionController.php:25
UserSectionController\_list
_list()
Definition: UserSectionController.php:68
UserSectionController\$model
$model
Definition: UserSectionController.php:18
View
Definition: View.php:8
UserSectionController\_regist
_regist()
Definition: UserSectionController.php:138
UserSectionController\$bid
$bid
Definition: UserSectionController.php:24
UserSectionModel
Definition: UserSectionModel.php:10
Controller
Definition: Controller.php:15
UserSectionController\$dat
$dat
Definition: UserSectionController.php:21
UserSectionController\$pager
$pager
Definition: UserSectionController.php:22
UserSectionController\$err
$err
Definition: UserSectionController.php:23
UserSectionController\_drop
_drop()
Definition: UserSectionController.php:161
UserSectionController\$viewName
$viewName
Definition: UserSectionController.php:20
UserSectionController\_error
_error($err)
Definition: UserSectionController.php:62
UserSectionController\$param
$param
Definition: UserSectionController.php:17
PAGER_RPP
const PAGER_RPP
Definition: UserSectionController.php:12