* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @link http://trpgtools-onweb.sourceforge.jp/ */ class DefaultProfilesController extends AppController { var $name = 'DefaultProfiles'; var $helpers = array( 'Profiledisp', 'Select', ); var $disableTokenActions = array(); /* メソッド */ function beforeFilter() { parent::beforeFilter(); // Cache $this->cacheAction = array( ); // 認証なしアクセス可 } function beforeRender() { parent::beforeRender(); $this->set_public_flag4view(); } /* アクションメソッド */ function admin_edit($profile_id = null) { if (!$profile_id ) { $this->Session->setFlash(__('Invalid data.', true)); $this->redirect(array('controller' => 'systems', 'action'=>'admin_index')); } $profile = $this->get_profile4profile_id($profile_id); if (empty($profile)) { $this->Session->setFlash(__('Invalid Profile', true)); $this->redirect(array('controller' => 'systems', 'action'=>'admin_index')); } // 「その他」システム設定 $this->checkEditOtherSystem($profile['Profile']['system_id']); if (!empty($this->data)) { $this->post_data = $this->data; $this->data = array(); $allow_blank = false; if ($profile['Profile']['profile_type'] == 'checkbox') { $allow_blank = true; } $this->data['CharactersHasProfile'] = $this->_set_new_characters_has_profile($this->post_data['CharactersHasProfile'], $profile_id, array(), $allow_blank); foreach ($this->data['CharactersHasProfile'] as $k => $v) { $this->data['DefaultProfile'][$k]['profile_id'] = $profile_id; if (!empty($v['profile_select_id'])) { $this->data['DefaultProfile'][$k]['profile_select_id'] = $v['profile_select_id']; } if (!empty($v['profile_table_id'])) { $this->data['DefaultProfile'][$k]['profile_table_id'] = $v['profile_table_id']; } if (!empty($v['profile_table_static_id'])) { $this->data['DefaultProfile'][$k]['profile_table_static_id'] = $v['profile_table_static_id']; } if (!isset($v['value'])) { $this->data['DefaultProfile'][$k]['value'] = ''; } else { $this->data['DefaultProfile'][$k]['value'] = $v['value']; } if (!isset($v['public_flag'])) { $this->data['DefaultProfile'][$k]['public_flag'] = 'public'; } else { $this->data['DefaultProfile'][$k]['public_flag'] = $v['public_flag']; } } unset($this->data["CharactersHasProfile"]); // $this->data['DefaultProfile']['__Token'] = $this->post_data['DefaultProfile']['__Token']; /* validate */ if ($this->DefaultProfile->saveAll($this->data['DefaultProfile'], array('validate' => 'only'))) { // 現在のdefault_profiles削除 $this->DefaultProfile->deleteAll(array( 'DefaultProfile.profile_id' => $profile_id )); /* データ保存 */ $this->DefaultProfile->create(); if ($this->DefaultProfile->saveAll($this->data['DefaultProfile'], array( 'validate' => false, 'fieldList' => $this->DefaultProfile->fields['edit'], ))) { $this->Session->setFlash(__('The default profile has been saved', true)); // $this->redirect(array('controller' => 'systems', 'action' => 'view', $profile['Profile']['system_id'])); $this->redirect(array('action' => 'edit', $profile_id)); } $this->Session->setFlash(__('The default profile could not be saved. Please, try again.', true)); $this->data = $this->post_data; } } $this->data['System'] = $profile['System']; unset($profile['System']); $profile['Profile']['CharactersHasProfile'] = $profile['DefaultProfile']; $profile['Profile']['ProfileSelect'] = $profile['ProfileSelect']; unset($profile['ProfileSelect']); $profile['Profile']['ProfileTable'] = $profile['ProfileTable']; unset($profile['ProfileTable']); $this->data['System']['Profile'][0] = $profile['Profile']; $this->set('form_nums', count($profile['Profile']['CharactersHasProfile']) + 3); $this->set('title_for_layout', " - ". sprintf(__('DefaultProfile for %s %s', true), $this->data['System']['name'], $this->data['System']['Profile'][0]['name'])); } function admin_delete($id = null) { if (!$id) { $this->Session->setFlash(__('Invalid id for default profile', true)); $this->redirect(array('action'=>'index')); } if ($this->DefaultProfile->delete($id)) { $this->Session->setFlash(__('Default profile deleted', true)); $this->redirect(array('action'=>'index')); } $this->Session->setFlash(__('Default profile was not deleted', true)); $this->redirect(array('action' => 'index')); } function get_profile4profile_id($profile_id) { if (!$profile_id) { $this->Session->setFlash(__('Invalid ProfileTable.', true)); $this->redirect(array('controller' => 'systems', 'action'=>'admin_index')); } $profile = $this->DefaultProfile->Profile->find('first', array( 'conditions' => array( 'Profile.id' => $profile_id, ), 'contain' => array( 'System', 'DefaultProfile', 'ProfileSelect', 'ProfileTable' => array( 'ProfileTableStatic', ), ), )); if (!empty($profile['ProfileSelect'])) { foreach ($profile['ProfileSelect'] as $k => $v) { if (isset($v['sort_order']) && !empty($v['sort_order'])) { $sort_order[$k] = $v['sort_order']; } else { $sort_order[$k] = 0; } } if (!empty($sort_order)) { $profile['ProfileSelect'] = $this->sort4sort_order($profile['ProfileSelect'], $sort_order); } } if (!empty($profile['ProfileTable'])) { foreach ($profile['ProfileTable'] as $k => $v) { if (isset($v['sort_order']) && !empty($v['sort_order'])) { $sort_order[$k] = $v['sort_order']; } else { $sort_order[$k] = 0; } } if (!empty($sort_order)) { $profile['ProfileTable'] = $this->sort4sort_order($profile['ProfileTable'], $sort_order); } } return $profile; } }