var $disableTokenActions = array();
+ var $post_data = array();
+
/* メソッド */
function beforeFilter() {
'conditions' => $conditions,
'contain' => array(
'User',
- 'CharactersHasProfile',
'System' => array(
'Profile' => array(
'ProfileSelect',
'ProfileTable',
- )
+ 'CharactersHasProfile',
+ ),
),
),
+ 'recursive' => 3,
));
if (empty($character)) {
// select設定のvalue
if (isset($v['profile_select_id'])) {
- $this->data['CharactersHasProfile'][$k]['value'] = null;
+ if (!isset($this->Character->ProfileSelect)) {
+ $this->Character->set_model('ProfileSelect');
+
+ }
+ $selected_profile_value = $this->Character->ProfileSelect->find('list', array('conditions' => array('ProfileSelect.id' => $v['value']), 'fields' => array('ProfileSelect.value')));
+ if (is_array($v['value'])) {
+ $this->data['CharactersHasProfile'][$k]['value'] = $v['value'][0];
+ }
+ $this->data['CharactersHasProfile'][$k]['profile_select_id'] = $this->data['CharactersHasProfile'][$k]['value'];
+ $this->data['CharactersHasProfile'][$k]['value'] = current($selected_profile_value);
}
}
}
$this->redirect(array('action'=>'view', $id));
}
}
+ $this->post_data = $this->data;
+
+ $this->data = $character;
+ $this->data['Character'] = $this->post_data['Character'];
$this->data['Character']['id'] = $id;
}
if (empty($this->data)) {
$this->data = $character;
$this->data['Character'] = $this->_restore_html_character($this->data['Character']);
+
+ $this->data['System']['Profile'] = $this->_restore_html_characters_has_profiles($this->data['System']['Profile']);
}
}
'conditions' => $conditions,
'contain' => array(
'User',
- 'System',
-/* 'System' => array(
- 'Profile' => array(
- 'ProfileSelect',
- 'ProfileTable',
- )
+ 'System' => array(
+ 'Profile',
+ ),
+ 'CharactersHasProfile' => array(
+ 'ProfileSelect',
),
-*/
- 'CharactersHasProfile',
'CharacterProfileArchive',
),
));
$data['name'] = $this->{$this->modelClass}->restore_html($data['name'], false, false, false);
$data['notes'] = $this->{$this->modelClass}->restore_html($data['notes'], false, false, false);
if ($nl2br) {
- $data['detail'] = nl2br($data['notes']);
+ $data['notes'] = nl2br($data['notes']);
+ }
+
+ return $data;
+ }
+
+ function _restore_html_characters_has_profiles($profile, $nl2br = false) {
+ if (empty($profile)) {
+ return null;
+ }
+
+ foreach($profile as $k => $v) {
+ if (empty($v['CharactersHasProfile'])) {
+ continue;
+ }
+ $profile[$k]['CharactersHasProfile'] = $this->__restore_html_characters_has_profiles($v['CharactersHasProfile'], $nl2br);
+ }
+
+ return $profile;
+ }
+ function __restore_html_characters_has_profiles($data, $nl2br = false) {
+ if (empty($data)) {
+ return null;
+ }
+
+ foreach ($data as $k => $v) {
+ $data[$k]['value'] = $this->{$this->modelClass}->restore_html($v['value'], false, false, false);
+ if ($nl2br) {
+ }
}
return $data;
var $character_has_profile_num = 0;
+ var $form_id = 0;
+
/**
* profile_typeの設定をview表示形式に変換
*/
$this->character_has_profile_num++;
}
- /* profile_selectsの設定をプルダウンで出力 */
- function disp_select4profile_selects($profile_selects, $option = array(), $label = false, $legend = false)
+ /* profile_selectsの設定を出力 */
+ function disp4profile_selects($profile_selects, $option = array())
{
- if (empty($profile_selects)) {
- return null;
- }
-
foreach ($profile_selects as $k => $v) {
$options[$v['id']] = stripcslashes($v['value']);
}
$option = array_merge(
array(
'type' => 'select',
- 'label' => $label,
- 'legend' => $legend,
'options' => $options,
- ),
+ ),
$option
);
$this->character_has_profile_num++;
}
- /* profile_selectsの設定をラジオボタンで出力 */
- function disp_radio4profile_selects($profile_selects, $label = false, $legend = false)
+
+ /* profile_selectsの設定をプルダウンで出力 */
+ function disp_select4profile_selects($profile_selects, $characters_has_profile = array(), $option = array(), $label = false, $legend = false)
{
if (empty($profile_selects)) {
return null;
}
- $first = reset($profile_selects);
- $this->disp_select4profile_selects(
- $profile_selects,
+ $selected = $this->set_form_value($profile_selects, $characters_has_profile);
+
+ $option = array_merge(
array(
- 'type' => 'radio',
- 'value' => $first['id'],
+ 'type' => 'select',
'label' => $label,
'legend' => $legend,
- 'div' => array(
- 'class' => 'input radio inline'
- ),
- )
+ 'selected' => $selected['value'],
+ ),
+ $option
);
+
+ $this->disp4profile_selects($profile_selects, $option);
}
+ /* profile_selectsの設定をラジオボタンで出力 */
+ function disp_radio4profile_selects($profile_selects, $characters_has_profile = array(), $label = false, $legend = false)
+ {
+ if (empty($profile_selects)) {
+ return null;
+ }
+
+ $selected = $this->set_form_value($profile_selects, $characters_has_profile);
+ if ($selected['value']) {
+ $selected_value = $selected['value'];
+ } else {
+ $first = reset($profile_selects);
+ $selected_value = $first['id'];
+ }
+
+ $option = array(
+ 'type' => 'radio',
+ 'value' => $selected_value,
+ 'label' => $label,
+ 'legend' => $legend,
+ 'div' => array(
+ 'class' => 'input radio inline'
+ ),
+ );
+
+ return $this->disp4profile_selects($profile_selects, $option);
+
+ }
/* profile_selectsの設定をチェックボックスで出力 */
- function disp_checkbox4profile_selects($profile_selects, $label = false, $legend = false)
+ function disp_checkbox4profile_selects($profile_selects, $characters_has_profile = array(), $label = false, $legend = false)
{
if (empty($profile_selects)) {
return null;
}
- foreach($profile_selects as $v) {
+ foreach($profile_selects as $k => $v) {
+ if (empty($v)) {
+ continue;
+ }
+
$profile_select[0] = $v;
+ $has_profile[0] = $this->get_selected_profile($v, $characters_has_profile);
$this->disp_select4profile_selects(
$profile_select,
+ $has_profile,
array(
'multiple' => 'checkbox',
'label' => $label,
{
if ($this->profile_type['is_select'] || $this->profile_type['is_radio'] || $this->profile_type['is_checkbox']) {
if ($this->profile_type['is_select']) {
- $this->disp_select4profile_selects($profile['ProfileSelect']);
+ $this->disp_select4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile']);
} elseif ($this->profile_type['is_radio']) {
- $this->disp_radio4profile_selects($profile['ProfileSelect']);
+ $this->disp_radio4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile']);
} elseif ($this->profile_type['is_checkbox']) {
- $this->disp_checkbox4profile_selects($profile['ProfileSelect']);
+ $this->disp_checkbox4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile']);
}
if ($admin === true) {
echo '<span class="edit_link">'.$this->Html->link(__('Edit Items', true), array('controller' => 'profile_selects', 'action' => 'admin_listview', $profile['id'])).'</span>';
}
} elseif ($this->profile_type['is_table']) {
echo '<table>';
- $this->disp_th4profile_tables($profile['ProfileTable']);
+ $this->disp_th4profile_tables($profile['ProfileTable'], $profile['CharactersHasProfile']);
if (empty($profile['CharacterHasProfile'])) {
echo '<tbody>';
+ if (!empty($profile['CharactersHasProfile'])) {
+ foreach($profile['CharactersHasProfile'] as $v) {
+ $this->disp_form4profile_tables($profile['ProfileTable'], $v);
+ }
+ }
if (intval($form_num) > 0) {
for ($i=0; $i<$form_num; $i++) {
$this->disp_form4profile_tables($profile['ProfileTable']);
}
}
+
+ /* View表示 */
+
+ /* フォームに値入力 */
+ function set_form_value($profile_selects, $characters_has_profile)
+ {
+ echo $this->form_id;
+
+ $this->form_id++;
+
+ if ($this->profile_type['is_select'] || $this->profile_type['is_radio'] || $this->profile_type['is_checkbox']) {
+ return $this->set_form_value_select($profile_selects, $characters_has_profile);
+ } elseif ($this->profile_type['is_table']) {
+ return $this->set_form_value_table($profile_selects, $characters_has_profile);
+ } else {
+ return $this->set_form_value_profile($profile_selects, $characters_has_profile);
+ }
+
+ }
+
+ /* profile_select */
+ /* profile_select_id->profile_idで抽出 */
+ function set_form_value_select($profile_selects, $characters_has_profile)
+ {
+ if (isset($characters_has_profile[0]['id'])) {
+ $selected = array(
+ 'value' => $characters_has_profile[0]['profile_select_id'],
+ 'public_flag' => $characters_has_profile[0]['public_flag'],
+ 'link_value' => $characters_has_profile[0]['link_value'],
+ );
+ } else {
+ $selected = array(
+ 'value' => '',
+ 'public_flag' => '',
+ 'link_value' => '',
+ );
+ }
+
+ return $selected;
+ }
+ /* profile_table */
+ function set_form_value_table($profile_selects, $characters_has_profile)
+ {
+ }
+
+ /* postからprofile_select_id->profile_idで抽出 */
+ function get_selected_profile($profile_select, $characters_has_profile)
+ {
+ $profile = array(
+ 'profile_select_id' => $profile_select['id'],
+ 'profile_id' => $profile_select['profile_id'],
+ 'value' => $profile_select['value'],
+ );
+
+ foreach ($characters_has_profile as $v) {
+ if (Set::contains($v, $profile)) {
+ return $v;
+ }
+ }
+
+ return array();
+ }
+
}