JSlip  1.0
BasicInfoController.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__) . '/BasicInfoModel.php');
11 
12 define('PAGER_RPP', 10);
13 
15 {
16  public $param;
17  public $rest;
18  public $viewName;
19  public $dat;
20  public $mem;
21  public $pager;
22  public $model;
23  public $view;
24 
25  public function main($param) {
26 
27  if ($_SESSION['minfo']['role'] != 'root') {
28  $this->viewName = 'basic_info_err';
29  return;
30  }
31 
32  $this->rest = '';
33  $this->param = $param;
34  $this->model = new BasicInfoModel();
35  $this->view = new View();
36 
37  $this->param['base'] = dirname(__FILE__);
38 
39  if (empty($this->param['act'])) {
40  $this->_list();
41  } else {
42  switch ($this->param['act']) {
43  case 'edit': $this->_edit(); break;
44  case 'remember': $this->_remember(); break;
45  case 'search': $this->_search(); break;
46  case 'check': $this->_check(); break;
47  case 'regist': $this->_regist(); break;
48  default: $this->_list(); break;
49  }
50  }
51  }
52 
53  private function _list() {
54 
55  $this->viewName = 'basic_info_list';
56 
57  $this->dat['cnd'] = [
58  'cnd_name' => '',
59  'cnd_year' => '',
60  'pager' => ['page' => 1, 'rpp' => PAGER_RPP],
61  ];
62 
63  $this->dat['list'] = $this->model->getList($this->dat['cnd']);
64  $this->dat['member'] = $this->model->getMemberList($this->dat['list']['rec']);
65 
66  $_SESSION['basic_info_list_cnd'] = $this->dat['cnd'];
67  }
68 
69  private function _search() {
70 
71  $this->viewName = 'basic_info_list';
72 
73  $this->dat['cnd'] = [
74  'cnd_name' => $this->param['cnd_name'],
75  'cnd_year' => $this->param['cnd_year'],
76  'pager' => ['page' => $this->param['page_curr'], 'rpp' => PAGER_RPP],
77  ];
78 
79  $this->dat['list'] = $this->model->getList($this->dat['cnd']);
80  $this->dat['member'] = $this->model->getMemberList($this->dat['list']['rec']);
81 
82  $_SESSION['basic_info_list_cnd'] = $this->dat['cnd'];
83  }
84 
85  private function _remember() {
86 
87  $this->viewName = 'basic_info_list';
88  $this->dat['cnd'] = $_SESSION['basic_info_list_cnd'];
89  $this->dat['list'] = $this->model->getList($this->dat['cnd']);
90  $this->dat['member'] = $this->model->getMemberList($this->dat['list']['rec']);
91  }
92 
93  private function _edit() {
94 
95  $this->viewName = 'basic_info_edit';
96  $this->dat = $this->model->getData($this->param['bid']);
97  $this->mem = $this->model->getMember();
98  }
99 
100  private function _check() {
101 
102  $err = [];
103  $name = $this->param['name'];
104  $disp_name = $this->param['disp_name'];
105  $term_year = $this->param['term_year'] + 0;
106  $term_begin = $this->param['term_begin'];
107  $term_end = $this->param['term_end'];
108 
109  if (empty($name)) {
110  $err[] = '名称は必須です。';
111  }
112 
113  if (empty($disp_name)) {
114  $err[] = '表示名称は必須です。';
115  }
116 
117  if (empty($term_year)) {
118  $err[] = '年度は必須です。';
119  } else {
120  if ($term_year < YEARS[0] || YEARS[1] < $term_year) {
121  $err[] = '不正な年度です。';
122  }
123  }
124 
125  if (empty($term_begin)) {
126  $err[] = '期首は必須です。';
127  } else {
128  if (!$this->chkYmd($term_begin)) {
129  $err[] = '不正な期首です。';
130  }
131  }
132 
133  if (empty($term_end)) {
134  $err[] = '期末は必須です。';
135  } else {
136  if (!$this->chkYmd($term_end)) {
137  $err[] = '不正な期末です。';
138  }
139  }
140 
141  if (empty($err)) {
142  $this->rest = json_encode(['sts' => 'OK']);
143  } else {
144  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
145  }
146  }
147 
148  private function _regist() {
149 
150  $err = $this->model->regist($this->param);
151 
152  if (!empty($err)) {
153  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
154  return;
155  }
156 
157  $this->rest = json_encode(['sts' => 'OK']);
158  }
159 }
BasicInfoController\_check
_check()
Definition: BasicInfoController.php:100
BasicInfoController\$view
$view
Definition: BasicInfoController.php:23
BasicInfoController\$rest
$rest
Definition: BasicInfoController.php:17
BasicInfoController\$dat
$dat
Definition: BasicInfoController.php:19
YEARS
const YEARS
Definition: local.php:14
BasicInfoController\_regist
_regist()
Definition: BasicInfoController.php:148
PAGER_RPP
const PAGER_RPP
Definition: BasicInfoController.php:12
BasicInfoController\_list
_list()
Definition: BasicInfoController.php:53
BasicInfoController\_search
_search()
Definition: BasicInfoController.php:69
View
Definition: View.php:8
Controller\chkYmd
chkYmd($dt)
Definition: Controller.php:32
BasicInfoController\main
main($param)
Definition: BasicInfoController.php:25
Controller
Definition: Controller.php:15
BasicInfoController\$mem
$mem
Definition: BasicInfoController.php:20
BasicInfoController
Definition: BasicInfoController.php:14
BasicInfoController\$model
$model
Definition: BasicInfoController.php:22
BasicInfoController\$param
$param
Definition: BasicInfoController.php:16
BasicInfoController\$viewName
$viewName
Definition: BasicInfoController.php:18
BasicInfoModel
Definition: BasicInfoModel.php:10
BasicInfoController\_edit
_edit()
Definition: BasicInfoController.php:93
BasicInfoController\$pager
$pager
Definition: BasicInfoController.php:21
BasicInfoController\_remember
_remember()
Definition: BasicInfoController.php:85