parent::beforeRender();
$this->set_public_flag4view();
+ $this->set_status4view();
}
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
'label' => __('Sort Order', true)
)
);
- echo $form->input('status', array(
+ echo $select->create_status_select($status, 'status', array(
'label' => __('Status', true)
)
);
<?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) ?>
</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;?>>
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)
)
);
<?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); ?>
</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>
var $helpers = array('Form');
var $default_public_flags = array('public_flag', 'private');
+ var $default_status = array('active', 'inactive');
/**
* public_flagの設定をview表示形式に変換
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;
+ }
+
}