OSDN Git Service

CharacterプロフのsaveAll修正
authorCake <cake_67@users.sourceforge.jp>
Fri, 29 Jan 2010 03:20:14 +0000 (12:20 +0900)
committerCake <cake_67@users.sourceforge.jp>
Fri, 29 Jan 2010 03:20:14 +0000 (12:20 +0900)
app/controllers/characters_controller.php
app/models/character.php
app/models/characters_has_profile.php

index fb8e083..3816017 100644 (file)
@@ -96,6 +96,22 @@ class CharactersController extends AppController {
 
                if (!empty($this->data)) {
 
+                       // 新hasProfile処理
+                       if ($this->data['CharactersHasProfile']) {
+                               foreach ($this->data['CharactersHasProfile'] as $k => $v) {
+                                       // 空の値は保存しない
+                                       if (empty($v['value'])) {
+                                               unset($this->data['CharactersHasProfile'][$k]);
+                                               continue;
+                                       }
+
+                                       // select設定のvalue
+                                       if (isset($v['profile_select_id'])) {
+                                               $this->data['CharactersHasProfile'][$k]['value'] = null;
+                                       }
+                               }
+                       }
+
                        /* validate */
                        $this->Character->CharactersHasProfile->validate['profile_id']['validProfileId'] = array(
                                'rule' => array('validProfileId', $character['System']['id']),
@@ -109,38 +125,28 @@ class CharactersController extends AppController {
                                'allowEmpty' => true,
                        );
 
+                       /* validate */
                        if ($this->Character->saveAll($this->data, array('validate' => 'only'))) {
 
-                               /* 空のProfile設定削除 */
-                               if (isset($this->data['CharactersHasProfile'])) {
-                                       foreach ($this->data['CharactersHasProfile'] as $k => $v) {
-                                               if (empty($v['value'])) {
-                                                       unset($this->data['CharactersHasProfile'][$k]);
-                                                       continue;
-                                               }
-                                               if (isset($v['profile_select_id'])) {
-                                                       $this->data['CharactersHasProfile'][$k]['value'] = null;
-                                               }
-
-                                       }
-                               }
-
                                // 現在のhas_profiles削除
                                $this->Character->CharactersHasProfile->deleteAll(array(
                                        'CharactersHasProfile.character_id' => $id
                                ));
 
 
-                               /* 保存 */
+                               /* データ保存 */
                                $this->data['Character']['id'] = $id;
+                               $this->Character->create();
+
                                if ($this->Character->saveAll($this->data, array(
                                        'validate' => false,
-                                       'atomic' => true,
-                                       'fieldList' => array_merge($this->Character->fields['edit'], $this->Character->CharactersHasProfile->fields['add'])))) {
-                                       $this->Session->setFlash(__('The Character has been saved', true));
+                                        'fieldList' => array_merge(
+                                               $this->Character->fields['edit'], 
+                                               $this->Character->CharactersHasProfile->fields['add']
+                                        )
+                               ))) {
+                                       $this->Session->setFlash(__('The Character has been saved.', true));
                                        $this->redirect(array('action'=>'view', $id));
-                               } else {
-                                       $this->Session->setFlash(__('The Character could not be saved. Please, try again.', true));
                                }
                        }
                        $this->data['Character']['id'] = $id;
@@ -262,4 +268,4 @@ class CharactersController extends AppController {
        }
 
 }
-?>
+
index 4b12605..2dcafbd 100644 (file)
@@ -9,8 +9,8 @@ class Character extends AppModel {
        );
 
        var $fields = array(
-               'add' => array('name', 'system_id', 'sort_order', 'status', 'public_flag', 'user_id', 'detail'),
-               'edit' => array('Character.name', 'Character.sort_order', 'Character.status', 'Character.public_flag', 'Character.detail'),
+               'add' => array('name', 'system_id', 'sort_order', 'status', 'public_flag', 'user_id', 'notes'),
+               'edit' => array('name', 'sort_order', 'status', 'public_flag', 'notes'),
                'escape' => array(
                        'name' => array(
                                'html' => true,
index ab4ba6d..e817d27 100644 (file)
@@ -4,7 +4,7 @@ class CharactersHasProfile extends AppModel {
        var $name = 'CharactersHasProfile';
 
        var $fields = array(
-               'add' => array('CharactersHasProfile.profile_id', 'CharactersHasProfile.profile_select_id', 'CharactersHasProfile.profile_table_id', 'CharactersHasProfile.value', 'CharactersHasProfile.public_flag', 'CharactersHasProfile.link_value'), // Character\98A\8cg\91Î\89\9e
+               'add' => array('character_id', 'profile_id', 'profile_select_id', 'profile_table_id', 'value', 'public_flag', 'link_value'),
                'escape' => array(
                        'value' => array(
                                'html' => true,