2 class SystemsController extends AppController {
10 // listView用のpagenate設定
11 var $paginate = array(
12 'conditions' => array(
28 // 'System.sort_order' => 'asc'
32 var $disableTokenActions = array(
35 function beforeFilter() {
37 parent::beforeFilter();
40 $this->cacheAction = array(
41 'index' => Configure::read('Cache.expireLong'),
42 'view/' => Configure::read('Cache.expire'),
46 $this->AuthPlus->allow('index');
47 $this->AuthPlus->allow('view');
50 function beforeRender()
52 parent::beforeRender();
54 $this->set_public_flag4view();
60 if ($this->site_configs['System.singleSystem']['value']) {
61 $this->Session->setFlash(__('Invalid URL.', true));
62 $this->redirect(array('controller'=>'users', 'action'=>'index'));
65 $this->paginate['conditions']['public_flag'] = 'public';
66 $this->System->hasMany['Character']['limit'] = 8;
70 function view($id = null) {
71 $this->System->hasMany['Character']['limit'] = 60;
75 function admin_index() {
76 unset($this->System->hasMany['Character']['conditions']['Character.public_flag']);
80 function admin_view($id = null) {
81 $this->System->hasMany['Character']['limit'] = 30;
82 unset($this->System->hasMany['CharacterSheet']['conditions']['CharacterSheet.public_flag']);
83 unset($this->System->hasMany['Character']['conditions']['Character.public_flag']);
87 function admin_add() {
88 if (!empty($this->data)) {
89 if (empty($this->data['Attachment'][0]['file']['tmp_name'])) {
90 unset($this->data['Attachment']);
93 $this->System->create();
94 if ($this->System->saveAll($this->data, array('fieldList' => array_merge($this->System->fields['add'], $this->System->fields['image'])))) {
95 $this->Session->setFlash(sprintf(__('%s has been saved', true), $this->data['System']['name']));
96 $this->redirect(array('action'=>'index'));
98 $this->Session->setFlash(__('The data could not be saved. Please, try again.', true));
102 $this->pageTitle .= " - ". __('Add New System', true);
105 function admin_edit($id = null) {
106 if (!$id && empty($this->data)) {
107 $this->Session->setFlash(__('Inview System', true));
108 $this->redirect(array('action'=>'index'));
111 $system = $this->System->find('first', array(
112 'conditions' => array('System.id' => $id),
119 $system = $this->_restore_html_system($system, true);
121 if (!empty($this->data)) {
122 $this->data['System']['id'] = $id;
124 if ($this->System->saveAll($this->data, array('fieldList' => array_merge($this->System->fields['edit'], $this->System->fields['image'])))) {
125 $this->Session->setFlash(sprintf(__('%s has been saved', true), $this->data['System']['name']));
127 if ($this->data['System']['public_flag'] != 'public') {
128 $this->System->Character->updateAll(array('Character.public_flag' => "'private'"), array('Character.system_id' => $id));
131 $this->redirect(array('action'=>'view', $id));
133 $this->Session->setFlash(__('The data could not be saved. Please, try again.', true));
134 $this->data['System']['id'] = $id;
135 if (isset($this->data['Attachment'][1])) {
136 list($alternative, $delete) = array($this->data['Attachment'][1]['alternative'], $this->data['Attachment'][1]['delete']);
138 $this->data['Attachment'] = $system['Attachment'];
139 if (isset($alternative)) {
140 $this->data['Attachment'][0]['alternative'] = $alternative;
141 $this->data['Attachment'][0]['delete'] = $delete;
146 if (empty($this->data)) {
147 $this->data = $system;
150 $this->pageTitle .= " - ". __('Edit System', true);
153 function admin_delete($id = null) {
155 if ($this->site_configs['System.singleSystem']['value']) {
156 $this->Session->setFlash(__('Invalid URL.', true));
157 $this->redirect(array('controller'=>'site_configs', 'action'=>'admin_edit'));
161 $this->Session->setFlash(__('Invalid id for System', true));
162 $this->redirect(array('action'=>'index'));
164 if (isset($this->data['System']['confirm']) && $this->data['System']['confirm'] == 'yes') {
165 if ($this->System->del($id)) {
166 $this->Session->setFlash(__('System deleted', true));
167 $this->redirect(array('action'=>'index'));
171 $this->pageTitle .= " - ". __('Delete System', true);
173 $this->admin_view($id);
177 function _index($limit = null)
180 $this->paginate['limit'] = $limit;
182 $systems = $this->paginate();
184 if (!empty($systems)) {
185 $sort_order = array();
186 foreach ($systems as $k => $v) {
187 $systems[$k] = $this->_restore_html_system($v);
189 if (isset($v['System']['sort_order']) && !empty($v['System']['sort_order'])) {
190 $sort_order[$k] = $v['System']['sort_order'];
196 if (empty($v['Character'])) {
197 $systems[$k]['System']['character_num'] = 0;
201 $systems[$k]['System']['character_num'] = $this->System->Character->find('count', array(
202 'conditions' => array_merge($this->System->hasMany['Character']['conditions'],
203 array('Character.system_id' => $v['System']['id'])),
208 $systems = $this->sort4sort_order($systems, $sort_order);
210 $systems = $this->HtmlEscape->nl_unescape($systems);
213 $this->set('systems', $systems);
215 $this->pageTitle .= " - ". __('List of All Systems', true);
218 function _view($id = null, $conditions = array())
221 $this->Session->setFlash(__('Invalid System.', true));
222 $this->redirect(array('action'=>'index'));
226 $conditions['System.id'] = $id;
227 if ($this->isAdmin) {
228 $this->System->hasMany['Profile']['fields'] = '';
234 'ProfileTable' => array(
235 'ProfileTableStatic',
249 $system = $this->System->find('first', array(
250 'conditions' => $conditions,
251 'contain' => $contain,
252 'recursive' => $recursive,
255 if (!isset($system['System']) || empty($system['System'])) {
256 $this->Session->setFlash(__('No System.', true));
257 $this->redirect(array('action'=>'index'));
259 $system = $this->_restore_html_system($system, true);
262 if (empty($system['Character'])) {
263 $system['System']['character_num'] = 0;
266 $system['System']['character_num'] = $this->System->Character->find('count', array(
267 'conditions' => array_merge($this->System->hasMany['Character']['conditions'],
268 array('Character.system_id' => $system['System']['id'])),
272 $this->set('system', $this->HtmlEscape->nl2br_escaped($system));
273 $this->set('profile_types', $this->System->Profile->profile_type);
275 $this->pageTitle .= " - ". $system['System']['name'];