3 class CharactersController extends AppController {
5 var $name = 'Characters';
15 var $disableTokenActions = array();
16 var $post_data = array();
20 function beforeFilter() {
22 parent::beforeFilter();
25 $this->cacheAction = array(
26 'index' => Configure::read('Cache.expireShort'),
30 $this->AuthPlus->allow('view');
31 $this->AuthPlus->allow('index');
34 function beforeRender()
36 parent::beforeRender();
38 $this->set_public_flag4view();
39 $this->set_status4view();
45 function index($id = null) {
46 if (!empty($id) && $id == $this->user_id) {
47 $this->redirect(array('action'=>'mycharacter'));
50 $this->set('isOwner', false);
51 $this->set('isOwner_userSet', false);
56 function mycharacter(){
58 $this->set('isOwner', true);
59 $this->set('isOwner_userSet', true);
61 $this->_index($this->user_id);
64 function view($id = null) {
66 $this->Session->setFlash(__('Invalid Character.', true));
67 $this->redirect(array('action'=>'index'));
70 $character = $this->_view($id, array(), false);
72 if (!$this->check_public_flag($character['System'])) {
73 unset($character['System']['Profile']);
76 $this->set('maxPictures', $this->check_character_picture_max(count($character['CharacterPicture'])));
79 if ($this->isOwner($character['Character'], $this->user_id)) {
82 $this->set('isOwner', $isOwner);
84 // キャラ画像のpublic_flagチェック
85 if ($isOwner !== true && !empty($character['CharacterPicture'])) {
86 foreach($character['CharacterPicture'] as $k => $v) {
87 if (!$this->check_public_flag2($v)) {
88 unset($character['CharacterPicture'][$k]);
93 $this->set('character', $this->HtmlEscape->nl2br_escaped($character));
97 $systems = $this->_get_systems();
99 if (!empty($this->data)) {
100 $this->data['Character']['user_id'] = $this->user_id;
102 $this->Character->create();
103 if ($this->Character->save($this->data, array('fieldList' => $this->Character->fields['add']))) {
106 $this->Session->setFlash(sprintf(__('%s has been saved.', true), $this->data['Character']['name']));
107 $this->redirect(array('controller' => 'characters', 'action'=>'view', $this->Character->id));
109 $this->Session->setFlash(__('The data could not be saved. Please, try again.', true));
113 $this->set('systems', $systems);
114 $this->set('isOwner', false);
116 $this->pageTitle .= " ". __('Add Character', true);
119 function edit($id = null) {
120 if (!$id && empty($this->data)) {
121 $this->Session->setFlash(__('Invalid ID.', true));
122 $this->redirect(array('action'=>'index'));
126 $this->Character->System->hasMany['Profile']['fields'] = '';
127 $this->Character->System->Profile->hasMany['CharactersHasProfile']['fields'] = '';
128 unset($this->Character->hasMany['CharacterProfileArchive']);
130 $character = $this->_get_character($id, array(), false);
131 if (!$this->isOwner($character['Character'], $this->user_id)) {
132 $this->Session->setFlash(__('No Permission', true));
133 $this->redirect(array('action'=>'index'));
137 if (!$this->check_public_flag($character['System'])) {
138 $this->redirect(array('action'=>'change_system', $id));
141 if (empty($this->data)) {
142 $character['System']['Profile'] = $this->_set_profile_table2characters_has_profiles($character['System']['Profile']);
145 if (!empty($this->data)) {
146 $this->post_data = $this->data;
148 $this->data['clearCache'] = array(
149 'character_id' => $id,
150 'user_id' => $this->user_id,
151 'system_id' => $character['System']['id'],
155 if (isset($this->data['CharactersHasProfile'])) {
156 $this->data['CharactersHasProfile'] = $this->_set_new_characters_has_profile($this->data['CharactersHasProfile']);
160 $this->_set_validate4characters_has_profile($character['System']['id']);
161 if ($this->Character->saveAll($this->data, array('validate' => 'only'))) {
164 $this->Character->CharactersHasProfile->deleteAll(array(
165 'CharactersHasProfile.character_id' => $id
169 $this->data['Character']['id'] = $id;
170 $this->Character->create();
172 if ($this->Character->saveAll($this->data, array(
174 'fieldList' => array_merge(
175 $this->Character->fields['edit'],
176 $this->Character->CharactersHasProfile->fields['add']
182 if (isset($this->data['Character']['archive']) && $this->data['Character']['archive'] == 1) {
183 $this->Character->saveCharacterProfile($this->Character->id, $this->data);
186 $this->Session->setFlash(sprintf(__('%s has been saved.', true), $this->data['Character']['name']));
187 $this->redirect(array('action'=>'view', $id));
191 $this->data = array_merge($character, $this->data);
192 $this->data['Character'] = $this->post_data['Character'];
193 $this->data['Character']['id'] = $id;
195 foreach($this->data['System']['Profile'] as $k1 => $profile) {
196 foreach($profile['CharactersHasProfile'] as $k2 => $v) {
197 $postdata = array_shift($this->post_data['CharactersHasProfile']);
198 if (isset($v['profile_select_id']) && !isset($postdata['profile_select_id'])) {
199 array_unshift($this->post_data['CharactersHasProfile'], $postdata);
202 if (is_array($postdata['value'])) {
203 $postdata['value'] = $postdata['value'][0];
205 $this->data['System']['Profile'][$k1]['CharactersHasProfile'][$k2]['value'] = $postdata['value'];
206 if (isset($postdata['profile_select_id'])) {
207 $this->data['System']['Profile'][$k1]['CharactersHasProfile'][$k2]['profile_select_id'] = $postdata['profile_select_id'];
213 if (empty($this->data)) {
214 $this->data = $character;
215 $this->data['Character'] = $this->_restore_html_character($this->data['Character'], true);
217 $this->data['System']['Profile'] = $this->_restore_html_characters_has_profiles($this->data['System']['Profile'], true);
219 $this->set('isOwner', true);
221 $this->pageTitle .= " ". sprintf(__('Edit %s', true), $character['Character']['name']);
224 function add_milti_profiles($id = null) {
225 if (!$id || !CorePlus::is_valid($this->params['named'], 'profile_id')) {
226 $this->Session->setFlash(__('Invalid ID.', true));
227 $this->redirect(array('action'=>'index'));
231 $this->Character->System->hasMany['Profile']['fields'] = '';
232 $this->Character->System->Profile->hasMany['CharactersHasProfile']['fields'] = '';
233 unset($this->Character->hasMany['CharacterProfileArchive']);
235 $character = $this->_get_character($id);
236 if (!$this->isOwner($character['Character'], $this->user_id)) {
237 $this->Session->setFlash(__('No Permission', true));
238 $this->redirect(array('action'=>'index'));
241 if (!$this->check_public_flag($character['System'])) {
242 $this->redirect(array('action'=>'change_system', $id));
246 if (empty($character['System']['Profile'])) {
247 $this->Session->setFlash(__('Invalid Profile.', true));
248 $this->redirect(array('action'=>'view', $id));
251 $profile_id = $this->params['named']['profile_id'];
253 if (empty($this->data)) {
254 $this->data['clearCache'] = array(
255 'character_id' => $id,
256 'user_id' => $this->user_id,
257 'system_id' => $character['System']['id'],
261 foreach ($character['System']['Profile'] as $profile) {
262 if ($profile['id'] == $profile_id) {
269 $this->Session->setFlash(__('No Profile.', true));
270 $this->redirect(array('action'=>'view', $id));
273 $character['System']['Profile'] = array();
274 $character['System']['Profile'][0] = $target;
276 $character['System']['Profile'] = $this->_set_profile_table2characters_has_profiles($character['System']['Profile']);
279 if (!empty($this->data)) {
280 $this->post_data = $this->data;
282 $this->data['Character'] = array_merge($character['Character'], $this->data['Character']);
283 $this->data['Character'] = $this->_restore_html_character($this->data['Character']);
284 $this->data['Character']['__Token'] = $this->post_data['Character']['__Token'];
285 $this->data['Character']['modified'] = null;
288 $this->data['CharactersHasProfile'] = $this->_set_new_characters_has_profile($this->data['CharactersHasProfile'], $profile_id, $character['System']['Profile']);
291 $this->_set_validate4characters_has_profile($character['System']['id']);
292 if ($this->Character->saveAll($this->data, array('validate' => 'only'))) {
295 $this->Character->CharactersHasProfile->deleteAll(array(
296 'CharactersHasProfile.character_id' => $id
300 $this->Character->create();
301 if ($this->Character->saveAll($this->data, array(
303 'fieldList' => array_merge(
304 $this->Character->CharactersHasProfile->fields['add']
310 if (isset($this->data['Character']['archive']) && $this->data['Character']['archive'] == 1) {
311 $this->Character->saveCharacterProfile($this->Character->id, $this->data);
314 $this->Session->setFlash(sprintf(__('%s has been saved.', true), $this->data['Character']['name']));
316 $this->redirect(array('action'=>'view', $id));
318 $this->data = array_merge($character, $this->data);
322 $this->data = $character;
323 $this->data['Character'] = $this->post_data['Character'];
324 $this->data['Character']['id'] = $id;
328 if (empty($this->data)) {
329 $this->data = $character;
330 $this->data['System']['Profile'] = $this->_restore_html_characters_has_profiles($this->data['System']['Profile']);
333 $this->set('isOwner', true);
335 $this->pageTitle .= " ". sprintf(__('Edit %s', true), $character['Character']['name']);
338 function change_system($id = null) {
340 $this->Session->setFlash(__('Invalid ID.', true));
341 $this->redirect(array('action'=>'index'));
345 $this->Character->System->hasMany['Profile']['fields'] = '';
346 $this->Character->System->Profile->hasMany['CharactersHasProfile']['fields'] = '';
348 $character = $this->_get_character($id);
349 if (!$this->isOwner($character['Character'], $this->user_id)) {
350 $this->Session->setFlash(__('No Permission', true));
351 $this->redirect(array('action'=>'index'));
355 if (isset($character['System']) && !empty($character['System'])) {
357 if ($this->check_public_flag($character['System'])) {
358 $this->redirect(array('action'=>'edit', $id));
361 $this->set('isChange', true);
365 if (!empty($this->data)) {
366 $this->data['clearCache'] = array(
367 'character_id' => $id,
368 'user_id' => $this->user_id,
369 'system_id' => $character['System']['id'],
372 $this->data['Character']['id'] = $id;
374 // validateはsystem_idのみ
375 $this->Cahracter['validate'] = array(
376 'system_id' => array(
377 'validSystemId' => array(
378 'rule' => array('validSystemId', true),
379 'allowEmpty' => false,
384 if ($this->Character->save(
388 'fieldList' => array('system_id'),
391 $this->Session->setFlash(__('The new system has been saved', true));
393 $this->redirect(array('action'=>'view', $id));
395 $this->Session->setFlash(__('The data could not be saved. Please, try again.', true));
399 $this->set('isOwner', true);
400 $this->set('character', $character);
402 $systems = $this->_get_systems();
403 $this->set('systems', $systems);
405 $this->pageTitle .= " ". sprintf(__('%s Change System', true), $character['Character']['name']);
409 function set_status($id = null) {
410 if (!$id || !isset($this->params['named']['mode'])) {
411 $this->Session->setFlash(__('Invalid ID.', true));
412 $this->redirect(array('controller' => 'characters', 'action'=>'index'));
415 $character = $this->_get_character4character_id($id, $this->user_id, 'public');
417 if ($this->params['named']['mode'] != 'main_picture' && $this->params['named']['mode'] != 'full_length') {
418 $this->Session->setFlash(__('Invalid URL.', true));
419 $this->redirect(array('controller' => 'character_pictures', 'action'=>'index', $id));
423 $new_character_picture = null;
424 if (isset($this->params['named']['new_picture_id']) && $this->params['named']['new_picture_id'] != 'null') {
425 if ($character['CharacterPicture']) {
426 foreach($character['CharacterPicture'] as $k => $v) {
427 if ($v['id'] == $this->params['named']['new_picture_id']) {
428 $new_character_picture = CorePlus::get_value($v, 'Attachment.0.basename');
433 if (!$new_character_picture) {
434 $this->Session->setFlash(__('Invalid data.', true));
435 $this->redirect(array('controller' => 'character_pictures', 'action'=>'index', $id));
440 $this->data['clearCache'] = array(
441 'character_id' => $id,
442 'user_id' => $this->user_id,
443 'system_id' => $character['System']['id'],
447 $this->Character->id = $id;
448 $this->data['Character'][$this->params['named']['mode']] = $new_character_picture;
449 $this->Character->save(
452 'fieldList' => array(
453 $this->params['named']['mode']
458 $this->Session->setFlash(__('CharacterPicture Configuration has been saved.', true));
459 $this->redirect(array('controller' => 'character_pictures', 'action' => 'index', $id));
462 function delete($id = null) {
464 $this->Session->setFlash(__('Invalid id for Character', true));
465 $this->redirect(array('action'=>'index'));
468 if ($this->_delete($id)) {
469 $this->redirect(array('controller' => 'users', 'action'=>'index'));
472 $this->pageTitle .= " - ". __('Delete Character', true);
475 function admin_index($id = null) {
476 unset($this->Character->belongsTo['System']['conditions']['System.public_flag']);
477 $this->_index($id, array('isAdmin' => true));
480 function admin_view($id = null) {
482 $this->Session->setFlash(__('Invalid Character.', true));
483 $this->redirect(array('action' => 'admin_index'));
486 $character = $this->_view($id, array(), true);
488 $this->set('character', $this->HtmlEscape->nl2br_escaped($character));
491 function admin_edit($id = null) {
492 if (!$id && empty($this->data)) {
493 $this->Session->setFlash(__('Invalid ID.', true));
494 $this->redirect(array('action'=>'index'));
498 $this->Character->System->hasMany['Profile']['fields'] = '';
499 $this->Character->System->Profile->hasMany['CharactersHasProfile']['fields'] = '';
500 unset($this->Character->hasMany['CharacterProfileArchive']);
502 $character = $this->_get_character($id, array(), true);
504 $this->Session->setFlash(__('No Character', true));
505 $this->redirect(array('action'=>'index'));
508 if (empty($this->data)) {
509 $character['System']['Profile'] = $this->_set_profile_table2characters_has_profiles($character['System']['Profile']);
512 if (!empty($this->data)) {
514 $this->data['clearCache'] = array(
515 'character_id' => $id,
516 'user_id' => $this->user_id,
517 'system_id' => $character['System']['id'],
520 if (isset($this->data['Character']['mode']) && $this->data['Character']['mode'] == 'set_private') {
521 $this->data['Character']['public_flag'] = 'private';
522 } elseif (isset($this->data['Character']['mode']) && $this->data['Character']['mode'] == 'set_public') {
523 $this->data['Character']['public_flag'] = 'public';
524 } elseif (isset($this->data['Character']['mode']) && $this->data['Character']['mode'] == 'delete_confirm') {
525 $this->redirect(array('controller' => 'characters', 'action'=>'admin_delete', $id));
527 $this->Session->setFlash(sprintf(__('Invalid data.', true), $this->data['Character']['name']));
528 $this->redirect(array('action'=>'view', $id));
531 $this->data['Character']['id'] = $id;
532 $this->Character->create();
533 if ($this->Character->save($this->data, array(
535 'fieldList' => array(
541 $this->Session->setFlash(sprintf(__('%s has been saved.', true), $character['Character']['name']));
542 $this->redirect(array('action'=>'view', $id));
545 $this->data = array_merge($character, $this->data);
546 $this->data['Character']['id'] = $id;
549 if (empty($this->data)) {
550 $this->data = $character;
551 $this->data['Character'] = $this->_restore_html_character($this->data['Character'], true);
553 $this->data['System']['Profile'] = $this->_restore_html_characters_has_profiles($this->data['System']['Profile'], true);
556 $this->pageTitle .= " ". sprintf(__('Edit %s', true), $character['Character']['name']);
559 function admin_delete($id = null) {
561 $this->Session->setFlash(__('Invalid id for Character', true));
562 $this->redirect(array('action'=>'index'));
565 if ($this->_delete($id, array(), true)) {
566 $this->redirect(array('action'=>'index'));
569 $this->pageTitle .= " - ". __('Delete Character', true);
574 function _index($id, $conditions = array(), $limit = 20, $fields = array(), $contain = array(), $order = array(), $page = 1) {
575 if (isset($conditions['isAdmin']) && $conditions['isAdmin'] === true) {
580 unset($conditions['isAdmin']);
582 $title = __('List of All Characters', true);
585 if (isset($this->params['named']['system']) && intval($this->params['named']['system'])) {
587 $conditions['System.id'] = $this->params['named']['system'];
588 if ($isAdmin === false) {
589 $conditions['System.public_flag'] = 'public';
592 $this_system = $this->Character->System->find('first', array(
593 'conditions' => $conditions,
597 if (!isset($this_system['System'])) {
598 $this->Session->setFlash(__('Invalid System.', true));
599 $this->redirect(array('controller' => 'systems', 'action' => 'index'));
601 $this_system = $this->_restore_html_system($this_system);
603 $title = $this_system['System']['name']. " ". $title;
605 $this->set('this_system', $this_system);
607 $contain = array_merge(array('System'), (array)$contain);
611 $conditions = array('User.id' => $id);
614 $user = $this->Character->User->find('first', array(
615 'conditions' => $conditions,
624 $this->Session->setFlash(__('Invalid Id.', true));
625 $this->redirect(array('action'=>'index'));
628 $title = $user['User']['name']. " ". $title;
630 $contain = array_merge($contain, array('User'));
632 $this->set('userSet', $user);
634 $conditions = array();
636 $conditions['Character.user_id'] = $id;
637 if ($id == $this->user_id) {
638 unset($this->paginate['conditions']['Character.public_flag']);
641 if ($isAdmin === true) {
642 $conditions['isAdmin'] = true;
644 if (isset($this->params['named']['system']) && intval($this->params['named']['system'])) {
645 $conditions['Character.system_id'] = $this->params['named']['system'];
647 $characters = $this->HtmlEscape->nl_unescape($this->_get_characters_page4user_id($id, $conditions, $limit, $fields, $contain, $order, $page));
649 $this->set('characters', $characters);
651 $this->pageTitle .= " - ". $title;
654 function _view($id, $conditions = array(), $isAdmin = false) {
655 $this->helpers[] = 'CharacterSheet';
659 if (isset($this->params['named']['mode']) && !empty($this->params['named']['mode'])) {
660 $this->view = 'Theme';
661 $this->theme = $this->params['named']['mode'];
666 $orig_character = $this->_get_character($id, $conditions, $isAdmin);
667 $character = $this->Character->set_profiles2view($orig_character);
669 Configure::write('isOwner', false);
670 if ($isAdmin || CorePlus::isOwner($character['Character'], $this->user_id)) {
671 Configure::write('isOwner', true);
675 $this->set('systemValid', 'public');
676 if (!$character['System']) {
677 $this->set('systemValid', false);
679 if (!$this->check_public_flag($character['System'])) {
680 $this->set('systemValid', 'unpublic');
682 $character = $this->_restore_html_system($character);
684 $this->pageTitle .= " - ". $character['Character']['name'];
689 function _delete($id = null, $conditions = array(), $isAdmin = false) {
691 $this->Session->setFlash(__('Invalid id for Character', true));
692 $this->redirect(array('action'=>'index'));
695 $character = $this->_view($id, $conditions, $isAdmin);
696 if (empty($character)) {
697 $this->Session->setFlash(__('No Character', true));
698 $this->redirect(array('action'=>'index'));
700 $this->set('character', $character);
702 if (!$isAdmin && !$this->isOwner($character['Character'], $this->user_id)) {
703 $this->Session->setFlash(__('No Permission', true));
704 $this->redirect(array('action'=>'index'));
706 $this->set('isOwner', true);
708 if (!empty($this->data)) {
710 $this->data['clearCache'] = array(
711 'character_id' => $id,
712 'user_id' => $this->user_id,
713 'system_id' => $character['System']['id'],
716 if ($this->data['Character']['confirm'] == 'yes') {
718 $this->data['Character']['id'] = $id;
719 $this->data['Character']['main_picture'] = null;
720 $this->data['Character']['full_length'] = null;
721 $this->data['Character']['deleted'] = true;
722 $this->data['Character']['deleted_date'] = date('Y-m-d H:i:s');
724 $this->Character->create();
725 if ($this->Character->save(
729 'fieldList' => array(
738 // CharactersHasProfiles
739 $this->Character->CharactersHasProfile->updateAll(
741 'CharactersHasProfile.public_flag' => "'private'",
744 'CharactersHasProfile.character_id' => $id
748 // CharacterProfileArchives
749 $date = date('Y-m-d H:i:s');
750 $this->Character->CharacterProfileArchive->updateAll(
752 'CharacterProfileArchive.deleted' => true,
753 'CharacterProfileArchive.deleted_date' => "'$date'",
756 'CharacterProfileArchive.character_id' => $id
761 if (isset($character['CharacterPicture']) && !empty($character['CharacterPicture'])) {
762 foreach ($character['CharacterPicture'] as $picture) {
763 $this->Character->CharacterPicture->delete($picture['id']);
767 $this->Session->setFlash(__('Character deleted', true));
771 $this->Session->setFlash(__('The Character could not be deleted.', true));
780 function _get_character($id, $conditions = array(), $isAdmin = false)
782 $character = $this->Character->get_character($id, $conditions, $isAdmin);
784 if (empty($character)) {
785 $this->Session->setFlash(__('No Character', true));
786 $this->redirect(array('action'=>'index'));
789 if ($isAdmin === false && !$this->check_public_flag($character['Character'])) {
790 $this->Session->setFlash(__('No Permission', true));
791 $this->redirect(array('action'=>'index'));
797 // ProfileTableをCharacterHasProfilesのTableの形式にセット
798 function _set_profile_table2characters_has_profiles($profile)
800 if (!empty($profile[0]['CharactersHasProfile'])) {
804 foreach($profile as $k => $v) {
805 if (empty($v['ProfileTable'])) {
809 $rows = count($v['CharactersHasProfile']);
810 for($i=0; $i<$rows; $i++) {
811 foreach($v['ProfileTable'] as $k2 => $v2) {
812 if (isset($v2['CharactersHasProfile'][$i])) {
813 $tmp[] = $v2['CharactersHasProfile'][$i];
814 } elseif (isset($v['CharactersHasProfile'][$i])) {
815 $tmp[] = $v['CharactersHasProfile'][$i];
823 $profile[$k]['CharactersHasProfile'] = $tmp;
829 /* POSTのCharactersHasProfileを処理 */
830 function _set_new_characters_has_profile($characters_has_profiles, $profile_id = null, $now_data = array())
832 $prev_profile_id = null;
833 $profileTable_tmp = array();
836 foreach ($characters_has_profiles as $k => $v) {
837 if (!empty($character_id)) {
838 $characters_has_profiles[$k]['character_id'] = $character_id;
841 if (is_array($v['value'])) {
842 $characters_has_profiles[$k]['value'] = $v['value'][0];
846 $characters_has_profiles[$k]['value'] = Sanitize::html($characters_has_profiles[$k]['value']);
847 $characters_has_profiles[$k]['value'] = preg_replace('/[\\\n]/', '', $characters_has_profiles[$k]['value']);
848 $characters_has_profiles[$k]['value'] = preg_replace('/[\\\r]/', '', $characters_has_profiles[$k]['value']);
850 if (isset($v['is_textarea']) && $v['is_textarea'] == 1) {
851 $characters_has_profiles[$k]['value'] = str_replace(array("\n\r", '\n', "\r"), '<br />', $characters_has_profiles[$k]['value']);
852 $characters_has_profiles[$k]['value'] = str_replace("\\", '', $characters_has_profiles[$k]['value']);
854 $characters_has_profiles[$k]['value'] = Sanitize::stripAll($characters_has_profiles[$k]['value']);
856 // 空の値処理, public_flag
857 // table: 一時保管して全項目空の場合行削除
858 if (CorePlus::is_valid($v, 'profile_table_id')) {
859 if (isset($profileTable_tmp[$v['profile_id']][$i][$v['profile_table_id']])) {
865 if ($public == null && isset($characters_has_profiles[$k]['public_flag'])) {
866 $public = $v['public_flag'];
868 if ($v['profile_table_static_id']) {
869 $characters_has_profiles[$k]['public_flag'] = 'public';
872 $characters_has_profiles[$k]['public_flag'] = $public;
875 $profileTable_tmp[$v['profile_id']][$i][$v['profile_table_id']] = array($characters_has_profiles[$k], $k);
877 } elseif (empty($v['value'])) {
878 unset($characters_has_profiles[$k]);
882 // table: 空行削除、不正profile_table_idデータ削除
883 if (!empty($profileTable_tmp)) {
884 if (!isset($this->Character->ProfileTable)) {
885 $this->Character->ProfileTable = CorePlus::set_model('ProfileTable');
887 foreach($profileTable_tmp as $profile_id => $v) {
888 $profile_table_columns = $this->Character->ProfileTable->find('list', array(
889 'conditions' => array('ProfileTable.profile_id' => $profile_id),
890 'fields' => array('ProfileTable.id'),
891 'order' => array('ProfileTable.sort_order' => 'asc'),
895 foreach ($v as $i => $profile_tables) {
897 $diff_keys = array_diff_key($profile_tables, $profile_table_columns);
898 if (!empty($diff_keys)) {
899 foreach($diff_keys as $dvalue) {
900 unset($characters_has_profiles[$dvalue[1]]);
906 foreach($profile_table_columns as $k2 => $columns) {
907 if (CorePlus::is_valid($profile_tables, $columns.'.0.value')) {
912 if ($delete_flg === true) {
913 foreach ($profile_tables as $delk) {
914 unset($characters_has_profiles[$delk[1]]);
922 if (!is_null($profile_id) && !empty($now_data)) {
925 foreach($now_data as $k => $v) {
926 if ($v['id'] == $profile_id) {
927 $v['CharactersHasProfile'] = $characters_has_profiles;
930 foreach ($v['CharactersHasProfile'] as $k2 => $v2) {
932 if (isset($tmp[$i]['id'])) {
933 unset($tmp[$i]['id']);
935 if (isset($tmp[$i]['character_id'])) {
936 unset($tmp[$i]['character_id']);
943 $characters_has_profiles = $tmp;
946 return $characters_has_profiles;
949 // CharactersHasProfileの追加valiadte設定
950 function _set_validate4characters_has_profile($system_id)
952 $this->Character->CharactersHasProfile->validate['profile_id']['validProfileId'] = array(
953 'rule' => array('validProfileId', $system_id),
955 $this->Character->CharactersHasProfile->validate['profile_select_id']['validProfileSelectId'] = array(
956 'rule' => array('validProfileSelectId', $system_id),
957 'allowEmpty' => true,
959 $this->Character->CharactersHasProfile->validate['profile_table_id']['validProfiletableId'] = array(
960 'rule' => array('validProfiletableId', $system_id),
961 'allowEmpty' => true,
966 function _restore_html_character($data, $nl2br = false) {
967 $data['name'] = $this->{$this->modelClass}->restore_html($data['name'], false, false, false);
968 $data['notes'] = $this->{$this->modelClass}->restore_html($data['notes'], false, false, false);
970 $data['notes'] = str_replace('<br />', "\n", $data['notes']);
976 function _restore_html_characters_has_profiles($profile, $nl2br = false) {
977 if (empty($profile)) {
981 foreach($profile as $k => $v) {
982 if (empty($v['CharactersHasProfile'])) {
985 $profile[$k]['CharactersHasProfile'] = $this->__restore_html_characters_has_profiles($v['CharactersHasProfile'], $nl2br, $v['profile_type']);
990 function __restore_html_characters_has_profiles($data, $nl2br = false, $profile_type = null) {
995 foreach ($data as $k => $v) {
996 if (isset($v['value'])) {
997 $data[$k]['value'] = $this->{$this->modelClass}->restore_html($v['value'], false, false, false);
998 if ($nl2br && $profile_type == 'textarea') {
999 $data[$k]['value'] = str_replace('<br />', "\n", $data[$k]['value']);