JSlip  1.0
UserEraController.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__) . '/UserEraModel.php');
11 
13 {
14  public $rest;
15  public $param;
16  public $model;
17  public $view;
18  public $viewName;
19  public $dat;
20  public $err;
21  public $bid;
22  public $basic;
23 
24  public function main($param) {
25 
26  $this->rest = '';
27  $this->param = $param;
28  $this->bid = $_SESSION['minfo']['bid'];
29  $this->model = new UserEraModel($this->bid);
30  $this->view = new View();
31 
32  $this->param['base'] = dirname(__FILE__);
33 
34  $basic = $this->model->getBasicByBid($this->bid);
35 
36  if (empty($basic[0])) {
37  $this->_error('基本情報が見つかりません。');
38  return;
39  } else {
40  $this->basic = $basic[0];
41  }
42 
43  if (empty($this->param['act'])) {
44  $this->_list();
45  } else {
46  switch ($this->param['act']) {
47  case 'create': $this->_create(); break;
48  case 'drop': $this->_drop(); break;
49  case 'edit': $this->_edit(); break;
50  case 'check': $this->_check(); break;
51  case 'regist': $this->_regist(); break;
52  default: $this->_list(); break;
53  }
54  }
55  }
56 
57  private function _error($err) {
58 
59  $this->viewName = 'user_era_err';
60  $this->err = $err;
61  }
62 
63  private function _list() {
64 
65  $this->viewName = 'user_era_list';
66 
67  $this->dat['list'] = $this->model->getList();
68  }
69 
70  private function _create() {
71 
72  $this->viewName = 'user_era_create';
73  }
74 
75  private function _edit() {
76 
77  $this->viewName = 'user_era_edit';
78  $this->dat = $this->model->getData($this->param['id']);
79  }
80 
81  private function _check() {
82 
83  $err = [];
84 
85  $insert = (empty($this->param['insert'])) ? false : true;
86  $ymd = $this->param['ymd'];
87  $era = $this->param['era'];
88  $abr = $this->param['abr'];
89 
90  if (empty($ymd)) {
91  $err[] = '開始日は必須です。';
92  } else {
93  if (!$this->chkYmd($ymd)) {
94  $err[] = '不正な開始日です。';
95  }
96  }
97 
98  if (empty($era)) {
99  $err[] = '名称は必須です。';
100  }
101 
102  if (empty($abr)) {
103  $err[] = '略儀は必須です。';
104  }
105 
106  if (empty($err)) {
107  $this->rest = json_encode(['sts' => 'OK']);
108  } else {
109  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
110  }
111  }
112 
113  private function _regist() {
114 
115  $insert = (empty($this->param['insert'])) ? false : true;
116 
117  if ($insert) {
118  $err = $this->model->insert($this->param);
119  } else {
120  $err = $this->model->regist($this->param);
121  }
122 
123  if (!empty($err)) {
124  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
125  return;
126  }
127 
128  $this->rest = json_encode(['sts' => 'OK']);
129  }
130 
131  private function _drop() {
132 
133  $err = $this->model->delete($this->param);
134 
135  if (!empty($err)) {
136  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
137  return;
138  }
139 
140  $this->rest = json_encode(['sts' => 'OK']);
141  }
142 }
UserEraController\$rest
$rest
Definition: UserEraController.php:14
UserEraController\$param
$param
Definition: UserEraController.php:15
UserEraController\_list
_list()
Definition: UserEraController.php:63
UserEraController\_error
_error($err)
Definition: UserEraController.php:57
UserEraModel
Definition: UserEraModel.php:10
UserEraController\_edit
_edit()
Definition: UserEraController.php:75
View
Definition: View.php:8
Controller\chkYmd
chkYmd($dt)
Definition: Controller.php:32
UserEraController\$viewName
$viewName
Definition: UserEraController.php:18
Controller
Definition: Controller.php:15
UserEraController\$dat
$dat
Definition: UserEraController.php:19
UserEraController\$model
$model
Definition: UserEraController.php:16
UserEraController\_regist
_regist()
Definition: UserEraController.php:113
UserEraController\_drop
_drop()
Definition: UserEraController.php:131
UserEraController\$basic
$basic
Definition: UserEraController.php:22
UserEraController\$bid
$bid
Definition: UserEraController.php:21
UserEraController\$err
$err
Definition: UserEraController.php:20
UserEraController\_check
_check()
Definition: UserEraController.php:81
UserEraController\_create
_create()
Definition: UserEraController.php:70
UserEraController\main
main($param)
Definition: UserEraController.php:24
UserEraController\$view
$view
Definition: UserEraController.php:17
UserEraController
Definition: UserEraController.php:12