OSDN Git Service

CharacterHasProfiles SELECTの編集値フォーム表示
authorCake <cake_67@users.sourceforge.jp>
Tue, 2 Feb 2010 04:47:44 +0000 (13:47 +0900)
committerCake <cake_67@users.sourceforge.jp>
Tue, 2 Feb 2010 04:47:44 +0000 (13:47 +0900)
app/controllers/characters_controller.php
app/models/characters_has_profile.php
app/models/profile.php
app/views/characters/edit.ctp
app/views/helpers/profiledisp.php

index 3816017..8f56b74 100644 (file)
@@ -14,6 +14,8 @@ class CharactersController extends AppController {
 
        var $disableTokenActions = array();
 
+       var $post_data = array();
+
        /* メソッド */
 
        function beforeFilter() {
@@ -74,14 +76,15 @@ class CharactersController extends AppController {
                        'conditions' => $conditions,
                        'contain' => array(
                                'User',
-                               'CharactersHasProfile',
                                'System' => array(
                                        'Profile' => array(
                                                'ProfileSelect',
                                                'ProfileTable',
-                                       )
+                                               'CharactersHasProfile',
+                                       ),
                                ),
                        ),
+                       'recursive' => 3,
                ));
 
                if (empty($character)) {
@@ -107,7 +110,16 @@ class CharactersController extends AppController {
 
                                        // 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);
                                        }
                                }
                        }
@@ -149,12 +161,18 @@ class CharactersController extends AppController {
                                        $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']);
                }
        }
 
@@ -222,15 +240,12 @@ class CharactersController extends AppController {
                        'conditions' => $conditions,
                        'contain' => array(
                                'User',
-                               'System',
-/*                             'System' => array(
-                                       'Profile' => array(
-                                               'ProfileSelect',
-                                               'ProfileTable',
-                                       )
+                               'System' => array(
+                                       'Profile',
+                               ),
+                               'CharactersHasProfile' => array(
+                                       'ProfileSelect',
                                ),
-*/
-                               'CharactersHasProfile',
                                'CharacterProfileArchive',
                        ),
                ));
@@ -249,7 +264,35 @@ class CharactersController extends AppController {
                $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;
index e817d27..0dc88bb 100644 (file)
@@ -45,19 +45,19 @@ class CharactersHasProfile extends AppModel {
                        'fields' => '',
                        'order' => ''
                ),
-               'ProfileSelects' => array(
-                       'className' => 'ProfileSelects',
+               'ProfileSelect' => array(
+                       'className' => 'ProfileSelect',
                        'foreignKey' => 'profile_select_id',
                        'conditions' => '',
                        'fields' => '',
-                       'order' => ''
+                       'order' => '',
                ),
-               'ProfileTables' => array(
-                       'className' => 'ProfileTables',
+               'ProfileTable' => array(
+                       'className' => 'ProfileTable',
                        'foreignKey' => 'profile_table_id',
                        'conditions' => '',
                        'fields' => '',
-                       'order' => ''
+                       'order' => '',
                )
        );
 
index fe8bbda..e155e9a 100644 (file)
@@ -118,7 +118,7 @@ class Profile extends AppModel {
                        'associationForeignKey' => 'id',
                        'dependent' => true,
                        'conditions' => '',
-                       'fields' => array('id', 'value', 'public_flag'),
+                       'fields' => array("id", "profile_id", "profile_select_id", "profile_table_id", "value", "public_flag", "link_value"),
                        'order' => '',
                        'limit' => 10,
                        'offset' => '',
index e29feef..ad4dddf 100644 (file)
 
 <!-- Profiles -->
 <?php
-//if (!empty($this->data['CharactersHasProfile'])) {
-//     $profiles = $this->data['CharactersHasProfile'];
-//} else {
+       // profile設定の表示
        $profiles = $this->data['System']['Profile'];
-//}
 ?>
 <?php foreach($profiles as $profile): ?>
 <?php 
 <td colspan="3"<?php if ($profiledisp->profile_type['is_table']): ?> class="table"<?php endif; ?>>
 <?php 
        $profiledisp->disp_forms4profile_type($profile, false, 2, 0);
+//     $profiledisp->disp_forms4profile_type($profile, false, 2, 0, $this->data['PrePostData']);
  ?>
 </td>
 </tr>
index e67e2bd..579622a 100644 (file)
@@ -15,6 +15,8 @@ class ProfiledispHelper extends Helper {
 
        var $character_has_profile_num = 0;
 
+       var $form_id = 0;
+
        /**
         * profile_typeの設定をview表示形式に変換
         */
@@ -115,23 +117,17 @@ class ProfiledispHelper extends Helper {
                $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
                );
 
@@ -149,40 +145,75 @@ class ProfiledispHelper extends Helper {
                $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,
@@ -326,20 +357,25 @@ class ProfiledispHelper extends Helper {
        {
                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']);
@@ -359,5 +395,68 @@ class ProfiledispHelper extends Helper {
                }
        }
 
+
+       /* 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();
+       }
+
 }