/* validate */
$this->_set_validate4characters_has_profile($character['System']['id']);
if ($this->Character->saveAll($this->data, array('validate' => 'only'))) {
+ // requiredのチェック
+ $requiredCheck = $this->_checkRequiredProfile($character['System']['Profile']);
- // 現在のhas_profiles削除
- $this->Character->CharactersHasProfile->deleteAll(array(
- 'CharactersHasProfile.character_id' => $id
- ));
+ if ($requiredCheck) {
+ // 現在のhas_profiles削除
+ $this->Character->CharactersHasProfile->deleteAll(array(
+ 'CharactersHasProfile.character_id' => $id
+ ));
- /* データ保存 */
- $this->data['Character']['id'] = $id;
- $this->Character->create();
+ /* データ保存 */
+ $this->data['Character']['id'] = $id;
+ $this->Character->create();
- if ($this->Character->saveAll($this->data, array(
- 'validate' => false,
- 'fieldList' => array_merge(
- $this->Character->fields['edit'],
- $this->Character->CharactersHasProfile->fields['add']
- )
- ))) {
-
- // Archives保存
- if (isset($this->data['Character']['archive']) && $this->data['Character']['archive'] == 1) {
- $this->Character->saveCharacterProfile($this->Character->id, $this->data);
- }
+ if ($this->Character->saveAll($this->data, array(
+ 'validate' => false,
+ 'fieldList' => array_merge(
+ $this->Character->fields['edit'],
+ $this->Character->CharactersHasProfile->fields['add']
+ )
+ ))) {
+
+ // Archives保存
+ if (isset($this->data['Character']['archive']) && $this->data['Character']['archive'] == 1) {
+ $this->Character->saveCharacterProfile($this->Character->id, $this->data);
+ }
- $this->Session->setFlash(sprintf(__('%s has been saved.', true), $this->data['Character']['name']));
- $this->redirect(array('action'=>'view', $id));
+ $this->Session->setFlash(sprintf(__('%s has been saved.', true), $this->data['Character']['name']));
+ $this->redirect(array('action'=>'view', $id));
+ }
}
}
$this->data = array_merge($character, $this->data);
$this->data['Character'] = $this->post_data['Character'];
+ $this->data['Character']['main_picture'] = $character['Character']['main_picture'];
$this->data['Character']['id'] = $id;
+ foreach ($this->data['System']['Profile'] as $k1 => $profile) {
+ if ($profile['profile_type'] == 'table') {
+ $colum_num = count($profile['CharactersHasProfile']);
+ } elseif ($profile['profile_type'] == 's-table') {
+ $colum_num = count($profile['CharactersHasProfile']);
+ } elseif ($profile['profile_type'] == 'checkbox') {
+ $colum_num = count($profile['ProfileSelect']);
+ } elseif ($profile['profile_type'] == 'm-input') {
+ $colum_num = count($profile['CharactersHasProfile']);
+ } else {
+ $colum_num = 1;
+ }
+
+ if ($colum_num == 0) {
+ if ($profile['profile_type'] == 's-table') {
+ $colum_num = count($profile['ProfileTable']) * count($profile['ProfileTable'][0]['ProfileTableStatic']);
+ } elseif ($profile['profile_type'] == 'table') {
+ $colum_num = count($profile['ProfileTable']) * 4;
+ } elseif ($profile['profile_type'] == 'checkbox') {
+ $colum_num = count($profile['ProfileSelect']);
+ } elseif ($profile['profile_type'] == 'm-input') {
+ $colum_num = 5;
+ } else {
+ $colum_num = 1;
+ }
+ }
+
+ for ($i=0; $i<$colum_num; $i++) {
+ if (!isset($profile['CharactersHasProfile'][$i])) {
+ $profile['CharactersHasProfile'][$i] = array('character_id' => $character['Character']['id']);
+ }
- foreach($this->data['System']['Profile'] as $k1 => $profile) {
- foreach($profile['CharactersHasProfile'] as $k2 => $v) {
$postdata = array_shift($this->post_data['CharactersHasProfile']);
- if (isset($v['profile_select_id']) && !isset($postdata['profile_select_id'])) {
- array_unshift($this->post_data['CharactersHasProfile'], $postdata);
- continue;
- }
+
if (is_array($postdata['value'])) {
$postdata['value'] = $postdata['value'][0];
}
- $this->data['System']['Profile'][$k1]['CharactersHasProfile'][$k2]['value'] = $postdata['value'];
- if (isset($postdata['profile_select_id'])) {
- $this->data['System']['Profile'][$k1]['CharactersHasProfile'][$k2]['profile_select_id'] = $postdata['profile_select_id'];
+
+ if (isset($postdata[$i])) {
+ $this->data['System']['Profile'][$k1]['CharactersHasProfile'][$i] = array_merge($profile['CharactersHasProfile'][$i], $postdata[$i]);
+ } else {
+ $this->data['System']['Profile'][$k1]['CharactersHasProfile'][$i] = array_merge($profile['CharactersHasProfile'][$i], $postdata);
}
}
}
}
- if (empty($this->data)) {
+ elseif (empty($this->data)) {
$this->data = $character;
$this->data['Character'] = $this->_restore_html_character($this->data['Character'], true);
- $this->data['System']['Profile'] = $this->_restore_html_characters_has_profiles($this->data['System']['Profile'], true);
}
+ $this->data['System']['Profile'] = $this->_restore_html_characters_has_profiles($this->data['System']['Profile'], true);
+
$this->set('isOwner', true);
$this->pageTitle .= " ". sprintf(__('Edit %s', true), $character['Character']['name']);
$profile_id = $this->params['named']['profile_id'];
- if (empty($this->data)) {
- $target = array();
- foreach ($character['System']['Profile'] as $profile) {
- if ($profile['id'] == $profile_id) {
- $target = $profile;
- break;
- }
+ $target = array();
+ foreach ($character['System']['Profile'] as $profile) {
+ if ($profile['id'] == $profile_id) {
+ $target = $profile;
+ break;
}
+ }
- if (!$target) {
- $this->Session->setFlash(__('No Profile.', true));
- $this->redirect(array('action'=>'view', $id));
- }
+ if (!$target) {
+ $this->Session->setFlash(__('No Profile.', true));
+ $this->redirect(array('action'=>'view', $id));
+ }
- $character['System']['Profile'] = array();
- $character['System']['Profile'][0] = $target;
+ $character['System']['Profile'] = array();
+ $character['System']['Profile'][0] = $target;
- $character['System']['Profile'] = $this->_set_profile_table2characters_has_profiles($character['System']['Profile']);
- }
+ $character['System']['Profile'] = $this->_set_profile_table2characters_has_profiles($character['System']['Profile']);
if (!empty($this->data)) {
$this->data['clearCache'] = array(
/* validate */
$this->_set_validate4characters_has_profile($character['System']['id']);
if ($this->Character->saveAll($this->data, array('validate' => 'only'))) {
+ // requiredのチェック
+ $requiredCheck = $this->_checkRequiredProfile($character['System']['Profile']);
+
+ if ($requiredCheck) {
+ // 現在のhas_profiles削除
+ $this->Character->CharactersHasProfile->deleteAll(array(
+ 'CharactersHasProfile.profile_id' => $target['id'],
+ 'CharactersHasProfile.character_id' => $id
+ ));
+
+ /* データ保存 */
+ $this->Character->create();
+ if ($this->Character->saveAll($this->data, array(
+ 'validate' => false,
+ 'fieldList' => array_merge(
+ $this->Character->CharactersHasProfile->fields['add']
+ )
+ ))) {
+
+ // Archives保存
+ if (isset($this->data['Character']['archive']) && $this->data['Character']['archive'] == 1) {
+ $this->Character->saveCharacterProfile($this->Character->id, $this->data);
+ }
- // 現在のhas_profiles削除
- $this->Character->CharactersHasProfile->deleteAll(array(
- 'CharactersHasProfile.character_id' => $id
- ));
-
- /* データ保存 */
- $this->Character->create();
- if ($this->Character->saveAll($this->data, array(
- 'validate' => false,
- 'fieldList' => array_merge(
- $this->Character->CharactersHasProfile->fields['add']
- )
- ))) {
-
- // Archives保存
- if (isset($this->data['Character']['archive']) && $this->data['Character']['archive'] == 1) {
- $this->Character->saveCharacterProfile($this->Character->id, $this->data);
+ $this->Session->setFlash(sprintf(__('%s has been saved.', true), $this->data['Character']['name']));
+ $this->redirect(array('action'=>'view', $id));
+ } else {
+ $this->data = array_merge($character, $this->data);
}
-
- $this->Session->setFlash(sprintf(__('%s has been saved.', true), $this->data['Character']['name']));
- $this->redirect(array('action'=>'view', $id));
} else {
- $this->data = array_merge($character, $this->data);
}
}
- $this->data = $character;
- $this->data['Character'] = $this->post_data['Character'];
+ $this->data = array_merge($character, $this->data);
$this->data['Character']['id'] = $id;
+ unset($this->data['Character']['__Token']);
}
if (empty($this->data)) {
$this->data = $character;
- $this->data['System']['Profile'] = $this->_restore_html_characters_has_profiles($this->data['System']['Profile']);
}
+ $this->data['System']['Profile'] = $this->_restore_html_characters_has_profiles($this->data['System']['Profile']);
$this->set('isOwner', true);
return $data;
}
+ function _checkRequiredProfile($profile)
+ {
+ if (empty($profile) || !isset($this->data['CharactersHasProfile'])) {
+ return true;
+ }
+
+ $requireCheck = array();
+ foreach($this->data['CharactersHasProfile'] as $k => $v) {
+ if (!isset($requireCheck[$v['profile_id']])) {
+ $requireCheck[$v['profile_id']] = null;
+ }
+
+ if (isset($requireCheck[$v['profile_id']]['value']) && !empty($requireCheck[$v['profile_id']]['value'])) {
+ continue;
+ }
+
+ if (empty($v['value'])) {
+ continue;
+ }
+
+ if (isset($v['profile_table_static_id']) && !empty($v['profile_table_static_id'])) {
+ if (!isset($requireCheck[$v['profile_id']]['profile_table_id']) || empty($requireCheck[$v['profile_id']]['profile_table_id'])) {
+ $requireCheck[$v['profile_id']]['profile_table_id'] = $v['profile_table_id'];
+ }
+
+ if ($requireCheck[$v['profile_id']]['profile_table_id'] == $v['profile_table_id']) {
+ continue;
+ }
+ }
+
+ $requireCheck[$v['profile_id']]['value'] = $v['value'];
+ }
+
+ $errors = array();
+ foreach ($profile as $k => $v) {
+ if ($v['required']) {
+ if (!isset($requireCheck[$v['id']]) || empty($requireCheck[$v['id']]['value'])) {
+ $errors[] = $v['name'];
+ }
+ }
+ }
+
+ if ($errors) {
+ $this->Session->setFlash(sprintf(__('%s is required.', true), implode(',', $errors)));
+ return false;
+ } else {
+ return true;
+ }
+ }
+
}