OSDN Git Service

Document追加
[trpgtools-onweb/cake-frame.git] / app / controllers / profile_table_statics_controller.php
1 <?php
2 class ProfileTableStaticsController extends AppController {
3
4         var $name = 'ProfileTableStatics';
5         var $helpers = array(
6                 'Profiledisp',
7         );
8
9         // POSTのTokenチェックをしないアクション
10         var $disableTokenActions = array();
11
12         function admin_edit($profile_table_id = null) {
13                 if (!$profile_table_id && empty($this->data)) {
14                         $this->Session->setFlash(__('Invalid Static ProfileTable', true));
15                         $this->redirect(array('controller'=>'systems', 'action'=>'admin_index'));
16                 }
17                 $profileTable = $this->ProfileTableStatic->ProfileTable->find(
18                         'first',
19                         array(
20                                 'conditions' => array(
21                                         'ProfileTable.id' => $profile_table_id,
22                                 ),
23                                 'fields' => '',
24                                 'contain' => array(
25                                         'Profile' => array(                                             'System',
26                                         ),
27                                         'ProfileTableStatic',
28                                 ),
29                                 'recursive' => 2,
30                         )
31                 );
32
33                 if (empty($profileTable['ProfileTable'])) {
34                         $this->Session->setFlash(__('Invalid ID.', true));
35                         $this->redirect(array('controller'=>'systems', 'action'=>'admin_index'));
36                 }
37
38                 foreach ($profileTable['ProfileTableStatic'] as $k => $v) {
39                         if (isset($v['sort_order'])  && !empty($v['sort_order'])) {
40                                 $sort_order[$k] = $v['sort_order'];
41                         } else {
42                                 $sort_order[$k] = 0;
43                         }
44                 }
45                 $profileTable['ProfileTableStatic'] = $this->sort4sort_order($profileTable['ProfileTableStatic'], $sort_order);
46
47                 if (!empty($this->data)) {
48                         // POSTデータ処理
49                         $this->_set_new_profile_table_static($profileTable['ProfileTable']['id']);
50
51                         $this->ProfileTableStatic->create();
52                         if ($this->ProfileTableStatic->saveAll(
53                                 $this->data['ProfileTableStatic'],
54                                 array(
55                                         'validate' => 'first',
56                                         'fieldList' => $this->ProfileTableStatic->fields['edit'],
57                                 )
58                         )) {
59                                 $this->Session->setFlash(__('The Static ProfileTable has been saved', true));
60                                 $this->redirect(array('controller'=>'profile_tables', 'action'=>'admin_listview', $profileTable['ProfileTable']['profile_id']));
61                         } else {
62                                 $this->Session->setFlash(__('The data could not be saved. Please, try again.', true));
63
64                                 unset($this->data['ProfileTableStatic']['__Token']);
65                                 $this->data['Profile'] = $profileTable['Profile'];
66                                 $this->data['ProfileTable'] = $profileTable['ProfileTable'];
67                         }
68                 }
69                 if (empty($this->data)) {
70                         $this->data = $profileTable;
71                 }
72
73                 $this->pageTitle .= " - ". __('Edit Static ProfileTable', true);
74         }
75
76         function admin_delete($id = null) {
77                 if (!$id) {
78                         $this->Session->setFlash(__('Invalid URL.', true));
79                         $this->redirect(array('controller' => 'systems', 'action'=>'admin_index'));
80                 }
81
82                 $profileTableStatic = $this->ProfileTableStatic->find(
83                         'first',
84                         array(
85                                 'conditions' => array(
86                                         'ProfileTableStatic.id' => $id,
87                                 ),
88                                 'contain' => array(
89                                         'ProfileTable',
90                                 ),
91                                 'recursive' => 1,
92                         )
93                 );
94                 if (empty($profileTableStatic)) {
95                         $this->Session->setFlash(__('Invalid ID.', true));
96                         $this->redirect(array('controller'=>'systems', 'action'=>'admin_index'));
97                 }
98
99                 if ($this->ProfileTableStatic->delete($id)) {
100                         $this->Session->setFlash(__('ProfileTable Static has deleted', true));
101                 } else {
102                         $this->Session->setFlash(__('The data has not been deleted', true));
103                 }
104
105                 $this->redirect(array('action'=>'admin_edit', $profileTableStatic['ProfileTable']['id']));
106         }
107
108         function _set_new_profile_table_static($profile_table_id)
109         {
110                 if (!isset($this->data['ProfileTableStatic']) || empty($profile_table_id)) {
111                         return array();
112                 }
113
114                 foreach ($this->data['ProfileTableStatic'] as $k => $v) {
115                         if (isset($v['__Token'])) {
116                                 continue;
117                         }
118
119                         // 空の値:name空の場合行削除
120                         if (!CorePlus::is_valid($v, 'title')) {
121                                 unset($this->data['ProfileTableStatic'][$k]);
122                                 continue;
123                         }
124
125                         $this->data['ProfileTableStatic'][$k]['profile_table_id'] = $profile_table_id;
126
127                         if (empty($v['sort_order'])) {
128                                 $this->data['ProfileTableStatic'][$k]['sort_order'] = 0;
129                         }
130                 }
131                 unset($this->data['ProfileTableStatic']['__Token']);
132
133         }
134
135 }
136