JSlip  1.0
UserBasicInfoController.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__) . '/UserBasicInfoModel.php');
11 
13 {
14  public $param;
15  public $rest;
16  public $model;
17  public $view;
18  public $viewName;
19  public $dat;
20  public $bid;
21 
22  public function main($param) {
23 
24  $this->rest = '';
25  $this->param = $param;
26  $this->model = new UserBasicInfoModel();
27  $this->view = new View();
28  $this->bid = $_SESSION['minfo']['bid'];
29 
30  $this->param['base'] = dirname(__FILE__);
31 
32  if (empty($this->param['act'])) {
33  $this->_edit();
34  } else {
35  switch ($this->param['act']) {
36  case 'check': $this->_check(); break;
37  case 'regist': $this->_regist(); break;
38  default: $this->_edit(); break;
39  }
40  }
41  }
42 
43  private function _edit() {
44 
45  $this->viewName = 'user_basic_info_edit';
46  $this->dat = $this->model->getData($this->bid);
47  $this->round = $this->model->getRound();
48  }
49 
50  private function _check() {
51 
52  $err = [];
53  $disp_name = $this->param['disp_name'];
54  $term_year = $this->param['term_year'] + 0;
55  $term_begin = $this->param['term_begin'];
56  $term_end = $this->param['term_end'];
57 
58  if (empty($disp_name)) {
59  $err[] = '表示名称は必須です。';
60  }
61 
62  if (empty($term_year)) {
63  $err[] = '年度は必須です。';
64  } else {
65  if ($term_year < YEARS[0] || YEARS[1] < $term_year) {
66  $err[] = '不正な年度です。';
67  }
68  }
69 
70  if (empty($term_begin)) {
71  $err[] = '期首は必須です。';
72  } else {
73  if (!$this->chkYmd($term_begin)) {
74  $err[] = '不正な期首です。';
75  }
76  }
77 
78  if (empty($term_end)) {
79  $err[] = '期末は必須です。';
80  } else {
81  if (!$this->chkYmd($term_end)) {
82  $err[] = '不正な期末です。';
83  }
84  }
85 
86  if (empty($err)) {
87  $this->rest = json_encode(['sts' => 'OK']);
88  } else {
89  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
90  }
91  }
92 
93  private function _regist() {
94 
95  $err = $this->model->regist($this->param);
96 
97  if (!empty($err)) {
98  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
99  return;
100  }
101 
102  $this->rest = json_encode(['sts' => 'OK']);
103  }
104 }
UserBasicInfoController\$viewName
$viewName
Definition: UserBasicInfoController.php:18
UserBasicInfoController
Definition: UserBasicInfoController.php:12
YEARS
const YEARS
Definition: local.php:14
UserBasicInfoController\_edit
_edit()
Definition: UserBasicInfoController.php:43
UserBasicInfoController\_regist
_regist()
Definition: UserBasicInfoController.php:93
View
Definition: View.php:8
Controller\chkYmd
chkYmd($dt)
Definition: Controller.php:32
Controller
Definition: Controller.php:15
UserBasicInfoModel
Definition: UserBasicInfoModel.php:10
UserBasicInfoController\$param
$param
Definition: UserBasicInfoController.php:14
UserBasicInfoController\$dat
$dat
Definition: UserBasicInfoController.php:19
UserBasicInfoController\$rest
$rest
Definition: UserBasicInfoController.php:15
UserBasicInfoController\$model
$model
Definition: UserBasicInfoController.php:16
UserBasicInfoController\_check
_check()
Definition: UserBasicInfoController.php:50
UserBasicInfoController\$view
$view
Definition: UserBasicInfoController.php:17
UserBasicInfoController\$bid
$bid
Definition: UserBasicInfoController.php:20
UserBasicInfoController\main
main($param)
Definition: UserBasicInfoController.php:22