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']))) {
105 $this->Session->setFlash(sprintf(__('%s has been saved.', true), $this->data['Character']['name']));
106 $this->redirect(array('controller' => 'characters', 'action'=>'view', $this->Character->id));
108 $this->Session->setFlash(__('The data could not be saved. Please, try again.', true));
112 $this->set('systems', $systems);
113 $this->set('isOwner', false);
115 $this->pageTitle .= " ". __('Add Character', true);
118 function edit($id = null) {
119 if (!$id && empty($this->data)) {
120 $this->Session->setFlash(__('Invalid ID.', true));
121 $this->redirect(array('action'=>'index'));
125 $this->Character->System->hasMany['Profile']['fields'] = '';
126 $this->Character->System->Profile->hasMany['CharactersHasProfile']['fields'] = '';
127 unset($this->Character->hasMany['CharacterProfileArchive']);
129 $character = $this->_get_character($id, array(), false);
130 if (!$this->isOwner($character['Character'], $this->user_id)) {
131 $this->Session->setFlash(__('No Permission', true));
132 $this->redirect(array('action'=>'index'));
136 if (!$this->check_public_flag($character['System'])) {
137 $this->redirect(array('action'=>'change_system', $id));
140 if (empty($this->data)) {
141 $character['System']['Profile'] = $this->_set_profile_table2characters_has_profiles($character['System']['Profile']);
144 if (!empty($this->data)) {
145 $this->post_data = $this->data;
147 $this->data['clearCache'] = array(
148 'character_id' => $id,
149 'user_id' => $this->user_id,
150 'system_id' => $character['System']['id'],
154 if (isset($this->data['CharactersHasProfile'])) {
155 $this->data['CharactersHasProfile'] = $this->_set_new_characters_has_profile($this->data['CharactersHasProfile']);
159 $this->_set_validate4characters_has_profile($character['System']['id']);
160 if ($this->Character->saveAll($this->data, array('validate' => 'only'))) {
163 $this->Character->CharactersHasProfile->deleteAll(array(
164 'CharactersHasProfile.character_id' => $id
168 $this->data['Character']['id'] = $id;
169 $this->Character->create();
171 if ($this->Character->saveAll($this->data, array(
173 'fieldList' => array_merge(
174 $this->Character->fields['edit'],
175 $this->Character->CharactersHasProfile->fields['add']
180 if (isset($this->data['Character']['archive']) && $this->data['Character']['archive'] == 1) {
181 $this->Character->saveCharacterProfile($this->Character->id, $this->data);
184 $this->Session->setFlash(sprintf(__('%s has been saved.', true), $this->data['Character']['name']));
185 $this->redirect(array('action'=>'view', $id));
189 $this->data = array_merge($character, $this->data);
190 $this->data['Character'] = $this->post_data['Character'];
191 $this->data['Character']['id'] = $id;
193 foreach($this->data['System']['Profile'] as $k1 => $profile) {
194 foreach($profile['CharactersHasProfile'] as $k2 => $v) {
195 $postdata = array_shift($this->post_data['CharactersHasProfile']);
196 if (isset($v['profile_select_id']) && !isset($postdata['profile_select_id'])) {
197 array_unshift($this->post_data['CharactersHasProfile'], $postdata);
200 if (is_array($postdata['value'])) {
201 $postdata['value'] = $postdata['value'][0];
203 $this->data['System']['Profile'][$k1]['CharactersHasProfile'][$k2]['value'] = $postdata['value'];
204 if (isset($postdata['profile_select_id'])) {
205 $this->data['System']['Profile'][$k1]['CharactersHasProfile'][$k2]['profile_select_id'] = $postdata['profile_select_id'];
211 if (empty($this->data)) {
212 $this->data = $character;
213 $this->data['Character'] = $this->_restore_html_character($this->data['Character'], true);
215 $this->data['System']['Profile'] = $this->_restore_html_characters_has_profiles($this->data['System']['Profile'], true);
217 $this->set('isOwner', true);
219 $this->pageTitle .= " ". sprintf(__('Edit %s', true), $character['Character']['name']);
222 function add_milti_profiles($id = null) {
223 if (!$id || !CorePlus::is_valid($this->params['named'], 'profile_id')) {
224 $this->Session->setFlash(__('Invalid ID.', true));
225 $this->redirect(array('action'=>'index'));
229 $this->Character->System->hasMany['Profile']['fields'] = '';
230 $this->Character->System->Profile->hasMany['CharactersHasProfile']['fields'] = '';
231 unset($this->Character->hasMany['CharacterProfileArchive']);
233 $character = $this->_get_character($id);
234 if (!$this->isOwner($character['Character'], $this->user_id)) {
235 $this->Session->setFlash(__('No Permission', true));
236 $this->redirect(array('action'=>'index'));
239 if (!$this->check_public_flag($character['System'])) {
240 $this->redirect(array('action'=>'change_system', $id));
244 if (empty($character['System']['Profile'])) {
245 $this->Session->setFlash(__('Invalid Profile.', true));
246 $this->redirect(array('action'=>'view', $id));
249 $profile_id = $this->params['named']['profile_id'];
251 if (empty($this->data)) {
253 foreach ($character['System']['Profile'] as $profile) {
254 if ($profile['id'] == $profile_id) {
261 $this->Session->setFlash(__('No Profile.', true));
262 $this->redirect(array('action'=>'view', $id));
265 $character['System']['Profile'] = array();
266 $character['System']['Profile'][0] = $target;
268 $character['System']['Profile'] = $this->_set_profile_table2characters_has_profiles($character['System']['Profile']);
271 if (!empty($this->data)) {
272 $this->data['clearCache'] = array(
273 'character_id' => $id,
274 'user_id' => $this->user_id,
275 'system_id' => $character['System']['id'],
278 $this->post_data = $this->data;
280 $this->data['Character'] = array_merge($character['Character'], $this->data['Character']);
281 $this->data['Character'] = $this->_restore_html_character($this->data['Character']);
282 $this->data['Character']['__Token'] = $this->post_data['Character']['__Token'];
283 $this->data['Character']['modified'] = null;
286 $this->data['CharactersHasProfile'] = $this->_set_new_characters_has_profile($this->data['CharactersHasProfile'], $profile_id, $character['System']['Profile']);
289 $this->_set_validate4characters_has_profile($character['System']['id']);
290 if ($this->Character->saveAll($this->data, array('validate' => 'only'))) {
293 $this->Character->CharactersHasProfile->deleteAll(array(
294 'CharactersHasProfile.character_id' => $id
298 $this->Character->create();
299 if ($this->Character->saveAll($this->data, array(
301 'fieldList' => array_merge(
302 $this->Character->CharactersHasProfile->fields['add']
307 if (isset($this->data['Character']['archive']) && $this->data['Character']['archive'] == 1) {
308 $this->Character->saveCharacterProfile($this->Character->id, $this->data);
311 $this->Session->setFlash(sprintf(__('%s has been saved.', true), $this->data['Character']['name']));
312 $this->redirect(array('action'=>'view', $id));
314 $this->data = array_merge($character, $this->data);
318 $this->data = $character;
319 $this->data['Character'] = $this->post_data['Character'];
320 $this->data['Character']['id'] = $id;
324 if (empty($this->data)) {
325 $this->data = $character;
326 $this->data['System']['Profile'] = $this->_restore_html_characters_has_profiles($this->data['System']['Profile']);
329 $this->set('isOwner', true);
331 $this->pageTitle .= " ". sprintf(__('Edit %s', true), $character['Character']['name']);
334 function change_system($id = null) {
336 $this->Session->setFlash(__('Invalid ID.', true));
337 $this->redirect(array('action'=>'index'));
341 $this->Character->System->hasMany['Profile']['fields'] = '';
342 $this->Character->System->Profile->hasMany['CharactersHasProfile']['fields'] = '';
344 $character = $this->_get_character($id);
345 if (!$this->isOwner($character['Character'], $this->user_id)) {
346 $this->Session->setFlash(__('No Permission', true));
347 $this->redirect(array('action'=>'index'));
351 if (isset($character['System']) && !empty($character['System'])) {
353 if ($this->check_public_flag($character['System'])) {
354 $this->redirect(array('action'=>'edit', $id));
357 $this->set('isChange', true);
361 if (!empty($this->data)) {
362 $this->data['clearCache'] = array(
363 'character_id' => $id,
364 'user_id' => $this->user_id,
365 'system_id' => $character['System']['id'],
368 $this->data['Character']['id'] = $id;
370 // validateはsystem_idのみ
371 $this->Cahracter['validate'] = array(
372 'system_id' => array(
373 'validSystemId' => array(
374 'rule' => array('validSystemId', true),
375 'allowEmpty' => false,
380 if ($this->Character->save(
384 'fieldList' => array('system_id'),
387 $this->Session->setFlash(__('The new system has been saved', true));
388 $this->redirect(array('action'=>'view', $id));
390 $this->Session->setFlash(__('The data could not be saved. Please, try again.', true));
394 $this->set('isOwner', true);
395 $this->set('character', $character);
397 $systems = $this->_get_systems();
398 $this->set('systems', $systems);
400 $this->pageTitle .= " ". sprintf(__('%s Change System', true), $character['Character']['name']);
404 function set_status($id = null) {
405 if (!$id || !isset($this->params['named']['mode'])) {
406 $this->Session->setFlash(__('Invalid ID.', true));
407 $this->redirect(array('controller' => 'characters', 'action'=>'index'));
410 $character = $this->_get_character4character_id($id, $this->user_id, 'public');
412 if ($this->params['named']['mode'] != 'main_picture' && $this->params['named']['mode'] != 'full_length') {
413 $this->Session->setFlash(__('Invalid URL.', true));
414 $this->redirect(array('controller' => 'character_pictures', 'action'=>'index', $id));
418 $new_character_picture = null;
419 if (isset($this->params['named']['new_picture_id']) && $this->params['named']['new_picture_id'] != 'null') {
420 if ($character['CharacterPicture']) {
421 foreach($character['CharacterPicture'] as $k => $v) {
422 if ($v['id'] == $this->params['named']['new_picture_id']) {
423 $new_character_picture = CorePlus::get_value($v, 'Attachment.0.basename');
428 if (!$new_character_picture) {
429 $this->Session->setFlash(__('Invalid data.', true));
430 $this->redirect(array('controller' => 'character_pictures', 'action'=>'listview', $id));
435 $this->data['clearCache'] = array(
436 'character_id' => $id,
437 'user_id' => $this->user_id,
438 'system_id' => $character['Character']['system_id'],
442 $this->Character->id = $id;
443 $this->data['Character'][$this->params['named']['mode']] = $new_character_picture;
444 $this->Character->save(
447 'fieldList' => array(
448 $this->params['named']['mode']
453 $this->Character->deleteCache4CharacterPicture($id);
456 $this->Session->setFlash(__('CharacterPicture Configuration has been saved.', true));
457 $this->redirect(array('controller' => 'character_pictures', 'action' => 'listview', $id));
460 function delete($id = null) {
462 $this->Session->setFlash(__('Invalid id for Character', true));
463 $this->redirect(array('action'=>'index'));
466 if ($this->_delete($id)) {
467 $this->redirect(array('controller' => 'users', 'action'=>'index'));
470 $this->pageTitle .= " - ". __('Delete Character', true);
473 function admin_index($id = null) {
474 unset($this->Character->belongsTo['System']['conditions']['System.public_flag']);
475 $this->_index($id, array('isAdmin' => true));
478 function admin_view($id = null) {
480 $this->Session->setFlash(__('Invalid Character.', true));
481 $this->redirect(array('action' => 'admin_index'));
484 $character = $this->_view($id, array(), true);
486 $this->set('character', $this->HtmlEscape->nl2br_escaped($character));
489 function admin_edit($id = null) {
490 if (!$id && empty($this->data)) {
491 $this->Session->setFlash(__('Invalid ID.', true));
492 $this->redirect(array('action'=>'index'));
496 $this->Character->System->hasMany['Profile']['fields'] = '';
497 $this->Character->System->Profile->hasMany['CharactersHasProfile']['fields'] = '';
498 unset($this->Character->hasMany['CharacterProfileArchive']);
500 $character = $this->_get_character($id, array(), true);
502 $this->Session->setFlash(__('No Character', true));
503 $this->redirect(array('action'=>'index'));
506 if (empty($this->data)) {
507 $character['System']['Profile'] = $this->_set_profile_table2characters_has_profiles($character['System']['Profile']);
510 if (!empty($this->data)) {
512 $this->data['clearCache'] = array(
513 'character_id' => $id,
514 'user_id' => $this->user_id,
515 'system_id' => $character['System']['id'],
518 if (isset($this->data['Character']['mode']) && $this->data['Character']['mode'] == 'set_private') {
519 $this->data['Character']['public_flag'] = 'private';
520 } elseif (isset($this->data['Character']['mode']) && $this->data['Character']['mode'] == 'set_public') {
521 $this->data['Character']['public_flag'] = 'public';
522 } elseif (isset($this->data['Character']['mode']) && $this->data['Character']['mode'] == 'delete_confirm') {
523 $this->redirect(array('controller' => 'characters', 'action'=>'admin_delete', $id));
525 $this->Session->setFlash(sprintf(__('Invalid data.', true), $this->data['Character']['name']));
526 $this->redirect(array('action'=>'view', $id));
529 $this->data['Character']['id'] = $id;
530 $this->Character->create();
531 if ($this->Character->save($this->data, array(
533 'fieldList' => array(
538 $this->Session->setFlash(sprintf(__('%s has been saved.', true), $character['Character']['name']));
539 $this->redirect(array('action'=>'view', $id));
542 $this->data = array_merge($character, $this->data);
543 $this->data['Character']['id'] = $id;
546 if (empty($this->data)) {
547 $this->data = $character;
548 $this->data['Character'] = $this->_restore_html_character($this->data['Character'], true);
550 $this->data['System']['Profile'] = $this->_restore_html_characters_has_profiles($this->data['System']['Profile'], true);
553 $this->pageTitle .= " ". sprintf(__('Edit %s', true), $character['Character']['name']);
556 function admin_delete($id = null) {
558 $this->Session->setFlash(__('Invalid id for Character', true));
559 $this->redirect(array('action'=>'index'));
562 if ($this->_delete($id, array(), true)) {
563 $this->redirect(array('action'=>'index'));
566 $this->pageTitle .= " - ". __('Delete Character', true);
571 function _index($id, $conditions = array(), $limit = 20, $fields = array(), $contain = array(), $order = array(), $page = 1) {
572 if (isset($conditions['isAdmin']) && $conditions['isAdmin'] === true) {
577 unset($conditions['isAdmin']);
579 $title = __('List of All Characters', true);
582 if (isset($this->params['named']['system']) && intval($this->params['named']['system'])) {
584 $conditions['System.id'] = $this->params['named']['system'];
585 if ($isAdmin === false) {
586 $conditions['System.public_flag'] = 'public';
589 $this_system = $this->Character->System->find('first', array(
590 'conditions' => $conditions,
594 if (!isset($this_system['System'])) {
595 $this->Session->setFlash(__('Invalid System.', true));
596 $this->redirect(array('controller' => 'systems', 'action' => 'index'));
598 $this_system = $this->_restore_html_system($this_system);
600 $title = $this_system['System']['name']. " ". $title;
602 $this->set('this_system', $this_system);
604 $contain = array_merge(array('System'), (array)$contain);
608 $conditions = array('User.id' => $id);
611 $user = $this->Character->User->find('first', array(
612 'conditions' => $conditions,
621 $this->Session->setFlash(__('Invalid Id.', true));
622 $this->redirect(array('action'=>'index'));
625 $title = $user['User']['name']. " ". $title;
627 $contain = array_merge($contain, array('User'));
629 $this->set('userSet', $user);
631 $conditions = array();
633 $conditions['Character.user_id'] = $id;
634 if ($id == $this->user_id) {
635 unset($this->paginate['conditions']['Character.public_flag']);
638 if ($isAdmin === true) {
639 $conditions['isAdmin'] = true;
641 if (isset($this->params['named']['system']) && intval($this->params['named']['system'])) {
642 $conditions['Character.system_id'] = $this->params['named']['system'];
644 $characters = $this->HtmlEscape->nl_unescape($this->_get_characters_page4user_id($id, $conditions, $limit, $fields, $contain, $order, $page));
646 $this->set('characters', $characters);
648 $this->pageTitle .= " - ". $title;
651 function _view($id, $conditions = array(), $isAdmin = false) {
652 $this->helpers[] = 'CharacterSheet';
656 if (isset($this->params['named']['mode']) && !empty($this->params['named']['mode'])) {
657 $this->view = 'Theme';
658 $this->theme = $this->params['named']['mode'];
663 $orig_character = $this->_get_character($id, $conditions, $isAdmin);
664 $character = $this->Character->set_profiles2view($orig_character);
666 Configure::write('isOwner', false);
667 if ($isAdmin || CorePlus::isOwner($character['Character'], $this->user_id)) {
668 Configure::write('isOwner', true);
672 $this->set('systemValid', 'public');
673 if (!$character['System']) {
674 $this->set('systemValid', false);
676 if (!$this->check_public_flag($character['System'])) {
677 $this->set('systemValid', 'unpublic');
679 $character = $this->_restore_html_system($character);
681 $this->pageTitle .= " - ". $character['Character']['name'];
686 function _delete($id = null, $conditions = array(), $isAdmin = false) {
688 $this->Session->setFlash(__('Invalid id for Character', true));
689 $this->redirect(array('action'=>'index'));
692 $character = $this->_view($id, $conditions, $isAdmin);
693 if (empty($character)) {
694 $this->Session->setFlash(__('No Character', true));
695 $this->redirect(array('action'=>'index'));
697 $this->set('character', $character);
699 if (!$isAdmin && !$this->isOwner($character['Character'], $this->user_id)) {
700 $this->Session->setFlash(__('No Permission', true));
701 $this->redirect(array('action'=>'index'));
703 $this->set('isOwner', true);
705 if (!empty($this->data)) {
707 $this->data['clearCache'] = array(
708 'character_id' => $id,
709 'user_id' => $this->user_id,
710 'system_id' => $character['System']['id'],
713 if ($this->data['Character']['confirm'] == 'yes') {
715 $this->data['Character']['id'] = $id;
716 $this->data['Character']['main_picture'] = null;
717 $this->data['Character']['full_length'] = null;
718 $this->data['Character']['deleted'] = true;
719 $this->data['Character']['deleted_date'] = date('Y-m-d H:i:s');
721 $this->Character->create();
722 if ($this->Character->save(
726 'fieldList' => array(
735 // CharactersHasProfiles
736 $this->Character->CharactersHasProfile->updateAll(
738 'CharactersHasProfile.public_flag' => "'private'",
741 'CharactersHasProfile.character_id' => $id
745 // CharacterProfileArchives
746 $date = date('Y-m-d H:i:s');
747 $this->Character->CharacterProfileArchive->updateAll(
749 'CharacterProfileArchive.deleted' => true,
750 'CharacterProfileArchive.deleted_date' => "'$date'",
753 'CharacterProfileArchive.character_id' => $id
758 if (isset($character['CharacterPicture']) && !empty($character['CharacterPicture'])) {
759 foreach ($character['CharacterPicture'] as $picture) {
760 $this->Character->CharacterPicture->delete($picture['id']);
764 $this->Session->setFlash(__('Character deleted', true));
768 $this->Session->setFlash(__('The Character could not be deleted.', true));
777 function _get_character($id, $conditions = array(), $isAdmin = false)
779 $character = $this->Character->get_character($id, $conditions, $isAdmin);
781 if (empty($character)) {
782 $this->Session->setFlash(__('No Character', true));
783 $this->redirect(array('action'=>'index'));
786 if ($isAdmin === false && !$this->check_public_flag($character['Character'])) {
787 $this->Session->setFlash(__('No Permission', true));
788 $this->redirect(array('action'=>'index'));
794 // ProfileTableをCharacterHasProfilesのTableの形式にセット
795 function _set_profile_table2characters_has_profiles($profile)
797 if (!empty($profile[0]['CharactersHasProfile'])) {
801 foreach($profile as $k => $v) {
802 if (empty($v['ProfileTable'])) {
806 $rows = count($v['CharactersHasProfile']);
807 for($i=0; $i<$rows; $i++) {
808 foreach($v['ProfileTable'] as $k2 => $v2) {
809 if (isset($v2['CharactersHasProfile'][$i])) {
810 $tmp[] = $v2['CharactersHasProfile'][$i];
811 } elseif (isset($v['CharactersHasProfile'][$i])) {
812 $tmp[] = $v['CharactersHasProfile'][$i];
820 $profile[$k]['CharactersHasProfile'] = $tmp;
826 /* POSTのCharactersHasProfileを処理 */
827 function _set_new_characters_has_profile($characters_has_profiles, $profile_id = null, $now_data = array())
829 $prev_profile_id = null;
830 $profileTable_tmp = array();
833 foreach ($characters_has_profiles as $k => $v) {
834 if (!empty($character_id)) {
835 $characters_has_profiles[$k]['character_id'] = $character_id;
838 if (is_array($v['value'])) {
839 $characters_has_profiles[$k]['value'] = $v['value'][0];
843 $characters_has_profiles[$k]['value'] = Sanitize::html($characters_has_profiles[$k]['value']);
844 $characters_has_profiles[$k]['value'] = preg_replace('/[\\\n]/', '', $characters_has_profiles[$k]['value']);
845 $characters_has_profiles[$k]['value'] = preg_replace('/[\\\r]/', '', $characters_has_profiles[$k]['value']);
847 if (isset($v['is_textarea']) && $v['is_textarea'] == 1) {
848 $characters_has_profiles[$k]['value'] = str_replace(array("\n\r", '\n', "\r"), '<br />', $characters_has_profiles[$k]['value']);
849 $characters_has_profiles[$k]['value'] = str_replace("\\", '', $characters_has_profiles[$k]['value']);
851 $characters_has_profiles[$k]['value'] = Sanitize::stripAll($characters_has_profiles[$k]['value']);
853 // 空の値処理, public_flag
854 // table: 一時保管して全項目空の場合行削除
855 if (CorePlus::is_valid($v, 'profile_table_id')) {
856 if (isset($profileTable_tmp[$v['profile_id']][$i][$v['profile_table_id']])) {
862 if ($public == null && isset($characters_has_profiles[$k]['public_flag'])) {
863 $public = $v['public_flag'];
865 if ($v['profile_table_static_id']) {
866 $characters_has_profiles[$k]['public_flag'] = 'public';
869 $characters_has_profiles[$k]['public_flag'] = $public;
872 $profileTable_tmp[$v['profile_id']][$i][$v['profile_table_id']] = array($characters_has_profiles[$k], $k);
874 } elseif (empty($v['value'])) {
875 unset($characters_has_profiles[$k]);
879 // table: 空行削除、不正profile_table_idデータ削除
880 if (!empty($profileTable_tmp)) {
881 if (!isset($this->Character->ProfileTable)) {
882 $this->Character->ProfileTable = CorePlus::set_model('ProfileTable');
884 foreach($profileTable_tmp as $profile_id => $v) {
885 $profile_table_columns = $this->Character->ProfileTable->find('list', array(
886 'conditions' => array('ProfileTable.profile_id' => $profile_id),
887 'fields' => array('ProfileTable.id'),
888 'order' => array('ProfileTable.sort_order' => 'asc'),
892 foreach ($v as $i => $profile_tables) {
894 $diff_keys = array_diff_key($profile_tables, $profile_table_columns);
895 if (!empty($diff_keys)) {
896 foreach($diff_keys as $dvalue) {
897 unset($characters_has_profiles[$dvalue[1]]);
903 foreach($profile_table_columns as $k2 => $columns) {
904 if (CorePlus::is_valid($profile_tables, $columns.'.0.value')) {
909 if ($delete_flg === true) {
910 foreach ($profile_tables as $delk) {
911 unset($characters_has_profiles[$delk[1]]);
919 if (!is_null($profile_id) && !empty($now_data)) {
922 foreach($now_data as $k => $v) {
923 if ($v['id'] == $profile_id) {
924 $v['CharactersHasProfile'] = $characters_has_profiles;
927 foreach ($v['CharactersHasProfile'] as $k2 => $v2) {
929 if (isset($tmp[$i]['id'])) {
930 unset($tmp[$i]['id']);
932 if (isset($tmp[$i]['character_id'])) {
933 unset($tmp[$i]['character_id']);
940 $characters_has_profiles = $tmp;
943 return $characters_has_profiles;
946 // CharactersHasProfileの追加valiadte設定
947 function _set_validate4characters_has_profile($system_id)
949 $this->Character->CharactersHasProfile->validate['profile_id']['validProfileId'] = array(
950 'rule' => array('validProfileId', $system_id),
952 $this->Character->CharactersHasProfile->validate['profile_select_id']['validProfileSelectId'] = array(
953 'rule' => array('validProfileSelectId', $system_id),
954 'allowEmpty' => true,
956 $this->Character->CharactersHasProfile->validate['profile_table_id']['validProfiletableId'] = array(
957 'rule' => array('validProfiletableId', $system_id),
958 'allowEmpty' => true,
963 function _restore_html_character($data, $nl2br = false) {
964 $data['name'] = $this->{$this->modelClass}->restore_html($data['name'], false, false, false);
965 $data['notes'] = $this->{$this->modelClass}->restore_html($data['notes'], false, false, false);
967 $data['notes'] = str_replace('<br />', "\n", $data['notes']);
973 function _restore_html_characters_has_profiles($profile, $nl2br = false) {
974 if (empty($profile)) {
978 foreach($profile as $k => $v) {
979 if (empty($v['CharactersHasProfile'])) {
982 $profile[$k]['CharactersHasProfile'] = $this->__restore_html_characters_has_profiles($v['CharactersHasProfile'], $nl2br, $v['profile_type']);
987 function __restore_html_characters_has_profiles($data, $nl2br = false, $profile_type = null) {
992 foreach ($data as $k => $v) {
993 if (isset($v['value'])) {
994 $data[$k]['value'] = $this->{$this->modelClass}->restore_html($v['value'], false, false, false);
995 if ($nl2br && $profile_type == 'textarea') {
996 $data[$k]['value'] = str_replace('<br />', "\n", $data[$k]['value']);