OSDN Git Service

キャラクター一覧でシステム絞込み対応
authorCake <cake_67@users.sourceforge.jp>
Fri, 26 Mar 2010 02:57:18 +0000 (11:57 +0900)
committerCake <cake_67@users.sourceforge.jp>
Fri, 26 Mar 2010 02:57:18 +0000 (11:57 +0900)
app/controllers/characters_controller.php
app/models/character.php
app/views/characters/admin_index.ctp
app/views/characters/index.ctp
app/webroot/css/base.css

index 3ba742b..75e1da9 100644 (file)
@@ -350,13 +350,14 @@ class CharactersController extends AppController {
 
 
        function admin_index($id = null) {
+               unset($this->Character->belongsTo['System']['conditions']['System.public_flag']);
                $this->_index($id, array('isAdmin' => true));
        }
 
        function admin_view($id = null) {
                if (!$id) {
                        $this->Session->setFlash(__('Invalid Character.', true));
-                       $this->redirect(array('action'=>'admin_index'));
+                       $this->redirect(array('action' => 'admin_index'));
                }
 
                $conditions = array(
@@ -386,14 +387,43 @@ class CharactersController extends AppController {
 
        /* 共通化アクションメソッド */
        function _index($id, $conditions = array(), $limit = 20, $fields = array(), $contain = array(), $order = array(), $page = 1) {
-               $contain = array_merge(array('System'), (array)$contain);
+               if (isset($conditions['isAdmin']) && $conditions['isAdmin'] === true) {
+                       $isAdmin = true;
+               } else {
+                       $isAdmin = false;
+               }
+               unset($conditions['isAdmin']);
+
+               // System指定分岐
+               if (isset($this->params['named']['system']) && intval($this->params['named']['system'])) {
+                       //情報取得
+                       $conditions['System.id'] = $this->params['named']['system'];
+                       if ($isAdmin !== true) {
+                               $conditions['System.public_flag'] = 'public';
+                       }
+
+                       $this_system = $this->Character->System->find('first', array(
+                               'conditions' => $conditions,
+                               'recursive' => -1,
+                       ));
+
+                       if (!isset($this_system['System'])) {
+                               $this->Session->setFlash(__('Invalid System.', true));
+                               $this->redirect(array('controller' => 'systems', 'action' => 'index'));
+                       }
+
+                       $this->set('this_system', $this_system);
+               } else {
+                       $contain = array_merge(array('System'), (array)$contain);
+               }
 
                $isOwner = false;
                $user = array();
 
+               $conditions = array('User.id' => $id);
                if (!empty($id)) {
                        $user = $this->Character->User->find('first', array(
-                               'conditions' => array('User.id' => $id),
+                               'conditions' => $conditions,
                                'recursive' => -1,
                                'fields' => array(
                                        'User.id',
@@ -416,6 +446,13 @@ class CharactersController extends AppController {
                        }
                }
 
+               $conditions = array();
+               if (!empty($id)) {
+                       $conditions['Character.user_id'] = $id;
+               }
+               if (isset($this->params['named']['system']) && intval($this->params['named']['system'])) {
+                       $conditions['Character.system_id'] = $this->params['named']['system'];
+               }
                 $characters =  $this->HtmlEscape->nl_unescape($this->_get_characters_page4user_id($id, $conditions, $limit, $fields, $contain, $order, $page));
 
                $this->set('characters', $characters);
index 8256c84..7745cae 100644 (file)
@@ -64,7 +64,9 @@ class Character extends AppModel {
                'System' => array(
                        'className' => 'System',
                        'foreignKey' => 'system_id',
-                       'conditions' => '',
+                       'conditions' => array(
+                               'System.public_flag' => 'public',
+                       ),
                        'fields' => array('id', 'name'),
                ),
                'User' => array(
index 53a7b15..c714c88 100644 (file)
@@ -1,5 +1,19 @@
 <div class="characters index">
-<h2><?php if (!empty($userSet)): ?><?php echo $html->link($userSet['User']['name'], array('controller' => 'users', 'action' => 'view', $userSet['User']['id']), array(), false, false) ?><?php __("'s "); ?><?php else: ?><?php __('All ') ?><?php endif; ?><?php __('Characters');?></h2>
+<h2>
+<?php if (isset($this_system)): ?>
+       <?php echo $html->link($this_system['System']['name'], array('controller' => 'systems', 'action' => 'view', $this_system['System']['id']), array(), false, false) ?>
+<?php endif; ?>
+<?php if (!empty($userSet)): ?>
+ <?php
+       echo $html->link(
+               sprintf(__("%s's", true), $userSet['User']['name']), 
+               array('controller' => 'users', 'action' => 'view', $userSet['User']['id']), 
+               array(), false, false);
+?>
+<?php else: ?>
+       <?php __('All') ?>
+<?php endif; ?>
+ <?php __('Characters');?></h2>
 <p>
 <?php
 $paginator->options(array('url' => $this->passedArgs));
@@ -8,12 +22,20 @@ echo $paginator->counter(array(
 'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
 ));
 ?></p>
+
+<div class="paging">
+<?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?>
+ | <?php echo $paginator->numbers();?> | 
+<?php echo $paginator->next(__('next', true).' >>', array(), null, array('class' => 'disabled'));?>
+</div>
 <table>
 <tr>
        <th><?php echo $paginator->sort('id');?></th>
        <th><?php echo $paginator->sort('name');?></th>
        <th><?php __('Picture');?></th>
+<?php if (!isset($this->params['named']['system'])): ?>
        <th><?php echo $paginator->sort('system_id');?></th>
+<?php endif; ?>
 <?php if (empty($userSet)): ?>
        <th><?php echo $paginator->sort('user_id');?></th>
 <?php endif; ?>
@@ -52,12 +74,33 @@ echo $paginator->counter(array(
        echo $html->div('attachments', $picture);
 ?>
 </td>
+<?php 
+       $character_list_url = array(
+               'controller' => 'characters', 
+               'action' => 'index'
+       );
+
+       if (!empty($userSet)) {
+               $character_list_url[] = $userSet['User']['id'];
+       }
+
+ ?>
+<?php if (!isset($this_system)): ?>
 <td>
-       <?php echo $html->link($character['System']['name'], array('controller' => 'systems', 'action' => 'view', $character['System']['id'])); ?>&nbsp;
+<?php 
+       echo $html->link($character['System']['name'], array_merge($character_list_url, array('system:'.$character['System']['id'])));
+?>
 </td>
+<?php endif; ?>
 <?php if (empty($userSet)): ?>
 <td>
-       <?php echo $html->link($character['User']['name'], array('controller' => 'characters', 'action' => 'admin_index', $character['User']['id']), array(), false, false); ?>
+<?php 
+       $character_list_url[] = $character['User']['id'];
+       if (isset($this_system)) {
+               $character_list_url[] = 'system:'.$this_system['System']['id'];
+       }
+       echo $html->link($text->truncate($character['User']['name'], 16), $character_list_url); 
+?>
 </td>
 <?php endif; ?>
 <td>
index 94b3621..b375c76 100644 (file)
@@ -1,5 +1,19 @@
 <div class="characters index">
-<h2><?php if (!empty($userSet)): ?><?php echo $html->link($userSet['User']['name'], array('controller' => 'users', 'action' => 'view', $userSet['User']['id']), array(), false, false) ?><?php __("'s "); ?><?php else: ?><?php __('All ') ?><?php endif; ?><?php __('Characters');?></h2>
+<h2>
+<?php if (isset($this_system)): ?>
+       <?php echo $html->link($this_system['System']['name'], array('controller' => 'systems', 'action' => 'view', $this_system['System']['id']), array(), false, false) ?>
+<?php endif; ?>
+<?php if (!empty($userSet)): ?>
+ <?php
+       echo $html->link(
+               sprintf(__("%s's", true), $userSet['User']['name']), 
+               array('controller' => 'users', 'action' => 'view', $userSet['User']['id']), 
+               array(), false, false);
+?>
+<?php else: ?>
+       <?php __('All') ?>
+<?php endif; ?>
+ <?php __('Characters');?></h2>
 <p>
 <?php
 $paginator->options(array('url' => $this->passedArgs));
@@ -8,11 +22,20 @@ echo $paginator->counter(array(
 'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
 ));
 ?></p>
+
+<div class="paging">
+<?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?>
+ | <?php echo $paginator->numbers();?> | 
+<?php echo $paginator->next(__('next', true).' >>', array(), null, array('class' => 'disabled'));?>
+</div>
+
 <table>
 <tr>
        <th><?php echo $paginator->sort('name');?></th>
        <th><?php __('Picture');?></th>
+<?php if (!isset($this_system)): ?>
        <th><?php echo $paginator->sort('system_id');?></th>
+<?php endif; ?>
 <?php if (empty($userSet)): ?>
        <th><?php echo $paginator->sort('user_id');?></th>
 <?php endif; ?>
@@ -32,7 +55,7 @@ foreach ($characters as $character):
 <td>
        <?php echo $html->link($text->truncate($character['Character']['name'], 32), array('action' => 'view', $character['Character']['id'])); ?>
 <?php if ($isOwner_userSet && $character['Character']['public_flag'] != 'public'): ?>
-       <?php echo $select->get_i18n_public_flag($character['Character']['public_flag'], $public_flags) ?>
+<span class="publicFlag"><?php echo $select->get_i18n_unpublic_flag($character['Character']['public_flag'], $public_flags) ?></span>
 <?php endif; ?>
 </td>
 <td class="center">
@@ -51,12 +74,33 @@ foreach ($characters as $character):
        echo $html->div('attachments', $picture);
 ?>
 </td>
+<?php 
+       $character_list_url = array(
+               'controller' => 'characters', 
+               'action' => 'index'
+       );
+
+       if (!empty($userSet)) {
+               $character_list_url[] = $userSet['User']['id'];
+       }
+
+ ?>
+<?php if (!isset($this_system)): ?>
 <td>
-       <?php echo $html->link($character['System']['name'], array('controller' => 'systems', 'action' => 'view', $character['System']['id'])); ?>
+<?php 
+       echo $html->link($character['System']['name'], array_merge($character_list_url, array('system:'.$character['System']['id'])));
+?>
 </td>
+<?php endif; ?>
 <?php if (empty($userSet)): ?>
 <td>
-       <?php echo $html->link($character['User']['name'], array('controller' => 'characters', 'action' => 'index', $character['User']['id']), array(), false, false); ?>
+<?php 
+       $character_list_url[] = $character['User']['id'];
+       if (isset($this_system)) {
+               $character_list_url[] = 'system:'.$this_system['System']['id'];
+       }
+       echo $html->link($text->truncate($character['User']['name'], 16), $character_list_url); 
+?>
 </td>
 <?php endif; ?>
 <td>
index 590391e..2c65cdb 100644 (file)
@@ -315,6 +315,7 @@ ul#navAdmin li {
 /* Paging */
 div.paging {
        background: transparent;
+       margin-bottom: 5px;
 }
 
 /* Forms */