From 66fa4239a32678496c8a025b2e13efe406cf44af Mon Sep 17 00:00:00 2001 From: Cake Date: Thu, 4 Feb 2010 15:03:33 +0900 Subject: [PATCH] =?utf8?q?CharacterHasProfiles=20View=E8=A1=A8=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- app/controllers/characters_controller.php | 102 +++++++++++++++----- app/controllers/systems_controller.php | 6 ++ app/models/character.php | 19 +++- app/models/characters_has_profile.php | 4 - app/models/profile.php | 12 ++- app/models/profile_select.php | 3 +- app/models/profile_table.php | 3 +- app/models/system.php | 10 +- app/views/characters/admin_view.ctp | 54 ++--------- app/views/characters/edit.ctp | 2 + app/views/characters/view.ctp | 52 +++-------- app/views/elements/character_view.thtml | 148 ++++++++++++++++++++++++++++++ app/views/helpers/profiledisp.php | 80 ++++++++++++++-- app/webroot/css/base.css | 6 ++ 14 files changed, 366 insertions(+), 135 deletions(-) create mode 100644 app/views/elements/character_view.thtml diff --git a/app/controllers/characters_controller.php b/app/controllers/characters_controller.php index f0b671e..e81ff10 100644 --- a/app/controllers/characters_controller.php +++ b/app/controllers/characters_controller.php @@ -44,7 +44,30 @@ class CharactersController extends AppController { } function view($id = null) { - $this->_view($id); + if (!$id) { + $this->Session->setFlash(__('Invalid Character.', true)); + $this->redirect(array('action'=>'index')); + } + + $conditions = array( + 'Character.id' => $id, + 'Character.deleted' => 0, + // todo:public_flagチェック + ); + + $character = $this->_view($id, $conditions); + if (!$character['Character']) { + $this->Session->setFlash(__('Invalid Character.', true)); + $this->redirect(array('action'=>'index')); + } + + $this->set('character', $this->HtmlEscape->nl2br_escaped($character)); + + $is_owner = false; + if ($this->isOwner($character['Character'], $this->user_id)) { + $is_owner = true; + } + $this->set('is_owner', $is_owner); } function add() { @@ -69,11 +92,13 @@ class CharactersController extends AppController { $this->redirect(array('action'=>'index')); } + // キャラデータ取得 $conditions = array( 'Character.id' => $id, ); + $this->Character->System->hasMany['Profile']['fields'] = ''; + $this->Character->System->Profile->hasMany['CharactersHasProfile']['fields'] = ''; - // キャラデータ取得 if (!empty($this->data)) { $character = $this->Character->find('first', array( 'conditions' => $conditions, @@ -302,7 +327,22 @@ class CharactersController extends AppController { } function admin_view($id = null) { - $this->_view($id); + if (!$id) { + $this->Session->setFlash(__('Invalid Character.', true)); + $this->redirect(array('action'=>'admin_index')); + } + + $conditions = array( + 'Character.id' => $id, + ); + + $character = $this->_view($id, $conditions); + if (!$character['Character']) { + $this->Session->setFlash(__('Invalid Character.', true)); + $this->redirect(array('action'=>'admin_index')); + } + + $this->set('character', $this->HtmlEscape->nl2br_escaped($character)); } function admin_delete($id = null) { @@ -323,38 +363,50 @@ class CharactersController extends AppController { $this->set('characters', $this->HtmlEscape->nl_unescape($this->paginate())); } - function _view($id = null) { - if (!$id) { - $this->Session->setFlash(__('Invalid Character.', true)); - $this->redirect(array('action'=>'index')); - } - - $conditions = array( - 'Character.id' => $id, - ); - - $character = $this->Character->find('first', array( + function _view($id, $conditions) { + // キャラデータ取得 + $orig_character = $this->Character->find('first', array( 'conditions' => $conditions, 'contain' => array( 'User', 'System' => array( - 'Profile', - ), - 'CharactersHasProfile' => array( - 'ProfileSelect', + 'Profile' => array( + 'CharactersHasProfile', + 'ProfileTable', + ), ), - 'CharacterProfileArchive', ), + 'recursive' => 3, )); - $this->set('character', $this->HtmlEscape->nl2br_escaped($character)); + if (empty($orig_character['Character'])) { + return $orig_character; + } - $editable = false; - if ($this->isOwner($character['Character'], $this->user_id)) { - $editable = true; + if (!empty($orig_character['System']['Profile'])) { + $new_profile = array(); + foreach ($orig_character['System']['Profile'] as $k => $profile) { + $new_profile[$profile['key_name']]['name'] = $profile['name']; + $new_profile[$profile['key_name']]['profile_type'] = $profile['profile_type']; + if (!empty($profile['ProfileTable'])) { + $new_profile[$profile['key_name']]['ProfileTable'] = $profile['ProfileTable']; + } + $new_profile[$profile['key_name']]['CharactersHasProfile'] = $profile['CharactersHasProfile']; + } + + $orig_character['System']['Profile'] = $new_profile; } - $this->set('editable', $editable); - } + + $character = array( + 'Character' => $orig_character['Character'], + 'System' => $orig_character['System'], + 'User' => $orig_character['User'] + ); + + + return $character; + } + /* 共通関数 */ function _restore_html_character($data, $nl2br = false) { diff --git a/app/controllers/systems_controller.php b/app/controllers/systems_controller.php index 2966998..e35a360 100644 --- a/app/controllers/systems_controller.php +++ b/app/controllers/systems_controller.php @@ -124,7 +124,13 @@ class SystemsController extends AppController { $this->Session->setFlash(__('Invalid System.', true)); $this->redirect(array('action'=>'index')); } + + // 抽出 $conditions['System.id'] = $id; + if ($this->isAdmin) { + $this->System->hasMany['Profile']['fields'] = ''; + } + $system = $this->System->find('first', array( 'conditions' => $conditions, 'contain' => array( diff --git a/app/models/character.php b/app/models/character.php index 2dcafbd..8a22ad7 100644 --- a/app/models/character.php +++ b/app/models/character.php @@ -16,7 +16,7 @@ class Character extends AppModel { 'html' => true, 'all' => true, ), - 'detail' => array( + 'notes' => array( 'html' => true, 'images' => true, 'sctipts' => true, @@ -72,18 +72,31 @@ class Character extends AppModel { 'foreignKey' => 'system_id', 'conditions' => '', 'fields' => array('id', 'name'), - 'order' => array('System.sort_order' => 'asc') ), 'User' => array( 'className' => 'User', 'foreignKey' => 'user_id', 'conditions' => '', 'fields' => array('id', 'name'), - 'order' => array('User.id' => 'asc') ) ); var $hasMany = array( + 'CharactersHasProfile' => array( + 'className' => 'CharactersHasProfile', + 'foreignKey' => 'character_id', + 'associationForeignKey' => 'id', + 'dependent' => false, +// 'conditions' => array('CharactersHasProfile.public_flag' => 'public'), + 'conditions' => '', + 'fields' => '', + 'order' => array('CharactersHasProfile.id' => 'asc'), + 'limit' => '', + 'offset' => '', + 'finderQuery' => '', + 'deleteQuery' => '', + 'insertQuery' => '' + ), 'CharacterProfileArchive' => array( 'className' => 'CharacterProfileArchive', 'foreignKey' => 'character_id', diff --git a/app/models/characters_has_profile.php b/app/models/characters_has_profile.php index 0dc88bb..874d08b 100644 --- a/app/models/characters_has_profile.php +++ b/app/models/characters_has_profile.php @@ -36,28 +36,24 @@ class CharactersHasProfile extends AppModel { 'foreignKey' => 'character_id', 'conditions' => '', 'fields' => '', - 'order' => '' ), 'Profile' => array( 'className' => 'Profile', 'foreignKey' => 'profile_id', 'conditions' => '', 'fields' => '', - 'order' => '' ), 'ProfileSelect' => array( 'className' => 'ProfileSelect', 'foreignKey' => 'profile_select_id', 'conditions' => '', 'fields' => '', - 'order' => '', ), 'ProfileTable' => array( 'className' => 'ProfileTable', 'foreignKey' => 'profile_table_id', 'conditions' => '', 'fields' => '', - 'order' => '', ) ); diff --git a/app/models/profile.php b/app/models/profile.php index 0306f20..288e0af 100644 --- a/app/models/profile.php +++ b/app/models/profile.php @@ -81,7 +81,6 @@ class Profile extends AppModel { 'foreignKey' => 'system_id', 'conditions' => '', 'fields' => array('id', 'name'), - 'order' => '' ) ); @@ -118,9 +117,14 @@ class Profile extends AppModel { 'associationForeignKey' => 'id', 'dependent' => true, 'conditions' => '', - 'fields' => array("id", "profile_id", "profile_select_id", "profile_table_id", "value", "public_flag", "link_value"), - 'order' => '', - 'limit' => 10, + 'fields' => array( + 'CharactersHasProfile.profile_table_id', + 'CharactersHasProfile.value', + 'CharactersHasProfile.public_flag', + 'CharactersHasProfile.link_value', + ), + 'order' => array('CharactersHasProfile.id' => 'asc'), + 'limit' => '', 'offset' => '', 'finderQuery' => '', 'deleteQuery' => '', diff --git a/app/models/profile_select.php b/app/models/profile_select.php index 2795a0a..81a82e6 100644 --- a/app/models/profile_select.php +++ b/app/models/profile_select.php @@ -35,7 +35,6 @@ class ProfileSelect extends AppModel { 'foreignKey' => 'profile_id', 'conditions' => '', 'fields' => '', - 'order' => '' ) ); @@ -47,7 +46,7 @@ class ProfileSelect extends AppModel { 'dependent' => true, 'conditions' => '', 'fields' => '', - 'order' => '', + 'order' => array('CharactersHasProfile.id' => 'asc'), 'limit' => 10, 'offset' => '', 'finderQuery' => '', diff --git a/app/models/profile_table.php b/app/models/profile_table.php index 77b5655..a41de8a 100644 --- a/app/models/profile_table.php +++ b/app/models/profile_table.php @@ -49,7 +49,6 @@ class ProfileTable extends AppModel { 'foreignKey' => 'profile_id', 'conditions' => '', 'fields' => '', - 'order' => '' ) ); @@ -61,7 +60,7 @@ class ProfileTable extends AppModel { 'dependent' => true, 'conditions' => '', 'fields' => '', - 'order' => '', + 'order' => array('CharactersHasProfile.id' => 'asc'), 'limit' => 10, 'offset' => '', 'finderQuery' => '', diff --git a/app/models/system.php b/app/models/system.php index 90688d6..e639916 100644 --- a/app/models/system.php +++ b/app/models/system.php @@ -61,19 +61,25 @@ class System extends AppModel { 'Character' => array( 'className' => 'Character', 'foreignKey' => 'system_id', - 'dependent' => false, + 'dependent' => true, 'conditions' => array( 'Character.public_flag' => 'public', 'Character.deleted' => '0', ), 'fields' => '', 'order' => 'Character.modified DESC', - 'limit' => '10', + 'limit' => '20', ), 'Profile' => array( 'className' => 'Profile', 'foreignKey' => 'system_id', 'dependent' => true, + 'fields' => array( + 'Profile.id', + 'Profile.name', + 'Profile.key_name', + 'Profile.profile_type', + ), 'order' => 'Profile.sort_order ASC', ) ); diff --git a/app/views/characters/admin_view.ctp b/app/views/characters/admin_view.ctp index 64cf173..d2cd789 100644 --- a/app/views/characters/admin_view.ctp +++ b/app/views/characters/admin_view.ctp @@ -1,47 +1,13 @@ -
-

-
- > - > - link(''.$character['Character']['name'].'', array('action' => 'view', $character['Character']['id']), array(), false, false); ?>
- link($character['Character']['name'], array('action' => 'view', $character['Character']['id'])); ?> - - > - > - link($character['System']['name'], array('controller' => 'systems', 'action' => 'view', $character['System']['id'])); ?> - - > - > - get_i18n_status($character['Character']['status'], $status); ?> - - > - > - get_i18n_public_flag($character['Character']['public_flag'], $public_flags) ?> - - > - > - link($character['User']['name'], array('controller' => 'users', 'action' => 'view', $character['User']['id']), array(), false, false); ?> - - > - > - -   - - > - > - - - > - > - - - > - > - -   - -
-
+renderElement( + 'character_view', + array( + 'character' => $character, + 'is_owner' => true, + ) +); +?> +