OSDN Git Service

CharacterPicture View表示変更
authorCake <cake_67@users.sourceforge.jp>
Fri, 12 Mar 2010 05:16:56 +0000 (14:16 +0900)
committerCake <cake_67@users.sourceforge.jp>
Fri, 12 Mar 2010 06:28:04 +0000 (15:28 +0900)
app/controllers/app_controller.php
app/controllers/character_pictures_controller.php
app/models/character_picture.php
app/views/character_pictures/view.ctp
app/views/elements/character_picture.ctp

index 46f6091..26936b9 100644 (file)
@@ -139,6 +139,18 @@ class AppController extends Controller
        {
                return $this->{$this->modelClass}->public_flag;
        }
+       function check_public_flag($data, $key = null)
+       {
+               if ($this->isOwner($data, $this->user_id)) {
+                       return true;
+               }
+
+               if ($data['public_flag'] == 'public') {
+                       return true;
+               }
+
+               return false;
+       }
 
        /* isOwner */
        function isOwner($data, $user_id)
index c8be50e..4dd6464 100644 (file)
@@ -94,10 +94,45 @@ class CharacterPicturesController extends AppController {
 
        function view($id = null) {
                if (!$id) {
+                       $this->Session->setFlash(__('Invalid Id.', true));
+                       $this->redirect(array('action'=>'index'));
+               }
+
+               $character_picture = $this->CharacterPicture->find('first', array(
+                       'conditions' => array(
+                               'CharacterPicture.id' => $id,
+                       ),
+                       'fields' => array(
+                               'CharacterPicture.id',
+                               'CharacterPicture.public_flag',
+                               'CharacterPicture.created',
+                       ),
+                       'contain' => array(
+                               'Character',
+                               'Attachment',
+                       ),
+                       'recursive' => 1,
+               ));
+
+               if (empty($character_picture)) {
                        $this->Session->setFlash(__('Invalid CharacterPicture.', true));
                        $this->redirect(array('action'=>'index'));
                }
-               $this->set('characterPicture', $this->CharacterPicture->read(null, $id));
+
+               // public_flagチェック
+               if (!$this->check_public_flag($character_picture['Character'])) {
+                       $this->Session->setFlash(__('No Permission.', true));
+                       $this->redirect(array('controller' => 'character', 'action'=>'index'));
+               }
+               if (!$this->check_public_flag($character_picture['CharacterPicture'])) {
+                       $this->Session->setFlash(__('No Permission.', true));
+                       $this->redirect(array('action'=>'view', $character_picture['Character']['id']));
+               }
+
+               $isOwner = $this->isOwner($character_picture['CharacterPicture'], $this->user_id);
+               $this->set('isOwner', $isOwner);
+
+               $this->set('characterPicture', $character_picture);
        }
 
        function add($character_id = null) {
index 541ceda..e15c9b8 100644 (file)
@@ -44,7 +44,12 @@ class CharacterPicture extends AppModel {
                        'className' => 'Character',
                        'foreignKey' => 'character_id',
                        'conditions' => '',
-                       'fields' => '',
+                       'fields' => array(
+                               'Character.id',
+                               'Character.name',
+                               'Character.main_picture',
+                               'Character.full_length',
+                       ),
                        'order' => ''
                )
        );
index fa35fc3..d942218 100644 (file)
 <div class="characterPictures view">
-<h2><?php  __('CharacterPicture');?></h2>
-       <dl><?php $i = 0; $class = ' class="altrow"';?>
-               <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Id'); ?></dt>
-               <dd<?php if ($i++ % 2 == 0) echo $class;?>>
-                       <?php echo $characterPicture['CharacterPicture']['id']; ?>
-                       &nbsp;
-               </dd>
-               <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('User'); ?></dt>
-               <dd<?php if ($i++ % 2 == 0) echo $class;?>>
-                       <?php echo $html->link($characterPicture['User']['name'], array('controller' => 'users', 'action' => 'view', $characterPicture['User']['id'])); ?>
-                       &nbsp;
-               </dd>
-               <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Character'); ?></dt>
-               <dd<?php if ($i++ % 2 == 0) echo $class;?>>
-                       <?php echo $html->link($characterPicture['Character']['name'], array('controller' => 'characters', 'action' => 'view', $characterPicture['Character']['id'])); ?>
-                       &nbsp;
-               </dd>
-               <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Public Flag'); ?></dt>
-               <dd<?php if ($i++ % 2 == 0) echo $class;?>>
-                       <?php echo $characterPicture['CharacterPicture']['public_flag']; ?>
-                       &nbsp;
-               </dd>
-               <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Created'); ?></dt>
-               <dd<?php if ($i++ % 2 == 0) echo $class;?>>
-                       <?php echo $characterPicture['CharacterPicture']['created']; ?>
-                       &nbsp;
-               </dd>
-               <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Modified'); ?></dt>
-               <dd<?php if ($i++ % 2 == 0) echo $class;?>>
-                       <?php echo $characterPicture['CharacterPicture']['modified']; ?>
-                       &nbsp;
-               </dd>
-       </dl>
+<h2><?php  echo $html->link($characterPicture['Character']['name'].__("'s Picture", true), array('controller' => 'characters', 'action' => 'view', $characterPicture['Character']['id']));?></h2>
+
+<p>
+<?php if ($characterPicture['Attachment'][0]['alternative']):?>
+<div class="title"><?php echo $characterPicture['Attachment'][0]['alternative']; ?></div>
+<?php endif; ?>
+<div class="image">
+<?php 
+       echo $this->renderElement('character_picture_image', array(
+               'attachment' => $characterPicture['Attachment'][0],
+               'options' => array(
+                       'previewVersion' => 'orig',
+                       'class' => 'shadow',
+               )
+       ));
+ ?>
 </div>
+<?php if ($isOwner): ?>
+<div><?php echo $select->get_i18n_public_flag($characterPicture['CharacterPicture']['public_flag'], $public_flags); ?></div>
+<?php endif; ?>
+</p>
+
+<p>
 <div class="actions">
        <ul>
-               <li><?php echo $html->link(__('Edit CharacterPicture', true), array('action' => 'edit', $characterPicture['CharacterPicture']['id'])); ?> </li>
-               <li><?php echo $html->link(__('Delete CharacterPicture', true), array('action' => 'delete', $characterPicture['CharacterPicture']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $characterPicture['CharacterPicture']['id'])); ?> </li>
-               <li><?php echo $html->link(__('List CharacterPictures', true), array('action' => 'index')); ?> </li>
-               <li><?php echo $html->link(__('New CharacterPicture', true), array('action' => 'add')); ?> </li>
-               <li><?php echo $html->link(__('List Users', true), array('controller' => 'users', 'action' => 'index')); ?> </li>
-               <li><?php echo $html->link(__('New User', true), array('controller' => 'users', 'action' => 'add')); ?> </li>
-               <li><?php echo $html->link(__('List Characters', true), array('controller' => 'characters', 'action' => 'index')); ?> </li>
-               <li><?php echo $html->link(__('New Character', true), array('controller' => 'characters', 'action' => 'add')); ?> </li>
-               <li><?php echo $html->link(__('List Attachments', true), array('controller' => 'attachments', 'action' => 'index')); ?> </li>
-               <li><?php echo $html->link(__('New Attachment', true), array('controller' => 'attachments', 'action' => 'add')); ?> </li>
+               <li><?php echo $html->link(__('Edit', true), array('action' => 'edit', $characterPicture['CharacterPicture']['id'])); ?> </li>
+               <li><?php echo $html->link(__('Delete', true), array('action' => 'delete', $characterPicture['CharacterPicture']['id']), null, __('Are you sure you want to delete it?', true)); ?> </li>
+               <li><?php echo $html->link(__('List Pictures', true), array('action' => 'index', $characterPicture['Character']['id'])); ?> </li>
+               <li><?php echo $html->link(__('New Picture', true), array('action' => 'add')); ?> </li>
        </ul>
 </div>
-<div class="related">
-       <h3><?php __('Related Attachments');?></h3>
-       <?php if (!empty($characterPicture['Attachment'])):?>
-       <table cellpadding = "0" cellspacing = "0">
-       <tr>
-               <th><?php __('Id'); ?></th>
-               <th><?php __('User Id'); ?></th>
-               <th><?php __('Model'); ?></th>
-               <th><?php __('Foreign Key'); ?></th>
-               <th><?php __('Dirname'); ?></th>
-               <th><?php __('Basename'); ?></th>
-               <th><?php __('Checksum'); ?></th>
-               <th><?php __('Size'); ?></th>
-               <th><?php __('Alternative'); ?></th>
-               <th><?php __('Group'); ?></th>
-               <th><?php __('Created'); ?></th>
-               <th><?php __('Modified'); ?></th>
-               <th class="actions"><?php __('Actions');?></th>
-       </tr>
-       <?php
-               $i = 0;
-               foreach ($characterPicture['Attachment'] as $attachment):
-                       $class = null;
-                       if ($i++ % 2 == 0) {
-                               $class = ' class="altrow"';
-                       }
-               ?>
-               <tr<?php echo $class;?>>
-                       <td><?php echo $attachment['id'];?></td>
-                       <td><?php echo $attachment['user_id'];?></td>
-                       <td><?php echo $attachment['model'];?></td>
-                       <td><?php echo $attachment['foreign_key'];?></td>
-                       <td><?php echo $attachment['dirname'];?></td>
-                       <td><?php echo $attachment['basename'];?></td>
-                       <td><?php echo $attachment['checksum'];?></td>
-                       <td><?php echo $attachment['size'];?></td>
-                       <td><?php echo $attachment['alternative'];?></td>
-                       <td><?php echo $attachment['group'];?></td>
-                       <td><?php echo $attachment['created'];?></td>
-                       <td><?php echo $attachment['modified'];?></td>
-                       <td class="actions">
-                               <?php echo $html->link(__('View', true), array('controller' => 'attachments', 'action' => 'view', $attachment['id'])); ?>
-                               <?php echo $html->link(__('Edit', true), array('controller' => 'attachments', 'action' => 'edit', $attachment['id'])); ?>
-                               <?php echo $html->link(__('Delete', true), array('controller' => 'attachments', 'action' => 'delete', $attachment['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $attachment['id'])); ?>
-                       </td>
-               </tr>
-       <?php endforeach; ?>
-       </table>
-<?php endif; ?>
-
-       <div class="actions">
-               <ul>
-                       <li><?php echo $html->link(__('New Attachment', true), array('controller' => 'attachments', 'action' => 'add'));?> </li>
-               </ul>
-       </div>
-</div>
+</p>
\ No newline at end of file