OSDN Git Service

status表示をSelectヘルパー対応
authorCake <cake_67@users.sourceforge.jp>
Fri, 22 Jan 2010 06:38:01 +0000 (15:38 +0900)
committerCake <cake_67@users.sourceforge.jp>
Fri, 22 Jan 2010 06:38:01 +0000 (15:38 +0900)
app/controllers/characters_controller.php
app/views/characters/add.ctp
app/views/characters/admin_index.ctp
app/views/characters/admin_view.ctp
app/views/characters/edit.ctp
app/views/characters/index.ctp
app/views/characters/view.ctp
app/views/helpers/select.php

index f382f07..4d29793 100644 (file)
@@ -34,6 +34,7 @@ class CharactersController extends AppController {
                parent::beforeRender();
 
                        $this->set_public_flag4view();
+                       $this->set_status4view();
        }
 
 
@@ -178,5 +179,17 @@ class CharactersController extends AppController {
                return $data;
        }
 
+       /* status設定をview用にセット */
+       function set_status4view()
+       {
+               $model_status = $this->get_status();
+
+               $this->set('status', $model_status);
+       }
+       function get_status()
+       {
+               return $this->Character->status;
+       }
+
 }
-?>
+?>
\ No newline at end of file
index 40183c1..7589547 100644 (file)
@@ -21,7 +21,7 @@
                        'label' => __('Sort Order', true)
                )
        );
-       echo $form->input('status', array(
+       echo $select->create_status_select($status, 'status', array(
                        'label' => __('Status', true)
                )
        );
index ca1c421..0c73bba 100644 (file)
@@ -44,7 +44,7 @@ foreach ($characters as $character):
                        <?php echo $character['Character']['sort_order']; ?>
                </td>
                <td>
-                       <?php echo $character['Character']['status']; ?>
+                       <?php echo $select->get_i18n_status($character['Character']['status'], $status); ?>
                </td>
                <td>
                        <?php echo $select->get_i18n_public_flag($character['Character']['public_flag'], $public_flags) ?>
index 8fa8bed..64cf173 100644 (file)
@@ -12,7 +12,7 @@
                </dd>
                <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Status'); ?></dt>
                <dd<?php if ($i++ % 2 == 0) echo $class;?>>
-                       <?php echo $character['Character']['status']; ?>
+                       <?php echo $select->get_i18n_status($character['Character']['status'], $status); ?>
                </dd>
                <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Public Flag'); ?></dt>
                <dd<?php if ($i++ % 2 == 0) echo $class;?>>
index 291af22..cf6cdd5 100644 (file)
@@ -20,7 +20,7 @@
        echo $form->input('sort_order', array(
                        'label' => __('Sort Order', true)               )
        );
-       echo $form->input('status', array(
+       echo $select->create_status_select($status, 'status', array(
                        'label' => __('Status', true)
                )
        );
index 8c50ae0..8102047 100644 (file)
@@ -38,7 +38,7 @@ foreach ($characters as $character):
                        <?php echo $html->link($character['System']['name'], array('controller' => 'systems', 'action' => 'view', $character['System']['id'])); ?>
                </td>
                <td>
-                       <?php echo $character['Character']['status']; ?>
+                       <?php echo $select->get_i18n_status($character['Character']['status'], $status); ?>
                </td>
                <td>
                        <?php echo $html->link($character['User']['name'], array('controller' => 'users', 'action' => 'view', $character['User']['id']), array(), false, false); ?>
index a6e1579..7e43091 100644 (file)
@@ -13,7 +13,7 @@
                </dd>
                <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Status'); ?></dt>
                <dd<?php if ($i++ % 2 == 0) echo $class;?>>
-                       <?php echo $character['Character']['status']; ?>
+                       <?php echo $select->get_i18n_status($character['Character']['status'], $status); ?>
                        &nbsp;
                </dd>
                <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Public Flag'); ?></dt>
index 499894f..44df649 100644 (file)
@@ -7,6 +7,7 @@ class SelectHelper extends Helper {
        var $helpers = array('Form');
 
        var $default_public_flags = array('public_flag', 'private');
+       var $default_status = array('active', 'inactive');
 
        /**
         * public_flagの設定をview表示形式に変換
@@ -74,6 +75,68 @@ class SelectHelper extends Helper {
                return $i18n_public_flag;
        }
 
+       /**
+        * statusの設定をview表示形式に変換
+        */
+       function get_i18n_status($status, $status_list)
+       {
+               if (empty($status)) {
+                       return null;
+               }
+
+               $status_list = $this->set_status($status_list);
+               return $status_list[$status];
+       }
+
+       /**
+        * statusの選択プルダウン出力
+        * i18n対応
+        */
+       function create_status_select($status_list = array(), $fieldName = 'status', $options = array('type' => 'select'))
+       {
+               if (!isset($options['type'])) {
+                       $options['type'] = 'select';
+               }
+               if (!isset($options['options'])) {
+                       $options['options'] = array();
+               }
+               $options['options'] = $this->set_status($status_list, $options['options']);
+
+               return $this->Form->input($fieldName, $options);
+       }
+
+       /* statusの設定を、key->value(多言語化対応)に変換 */
+       function set_status($status_list = array(), $options = array())
+       {
+               static $i18n_status;
+
+               if (is_array($i18n_status)) {
+                       return $i18n_status;
+               }
+
+               if (!empty($options)) {
+                       $i18n_status = $options;
+               }
+
+               if (empty($status_list)) {
+                       $status_list = $this->default_status;
+               }
+
+               foreach ($status_list as $k => $v) {
+                       if ($v == 'active') {
+                               $i18n_status[$v] = __('Active', true);
+                       } elseif($v == 'npc') {
+                               $i18n_status[$v] = __('NPC', true);
+                       } elseif($v == 'inactive') {
+                               $i18n_status[$v] = __('Inactive', true);
+                       } else {
+                               $i18n_status[$v] = $v;
+                       }
+               }
+
+               return $i18n_status;
+       }
+
 }