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 if (isset($this->params['named']['num'])) {
332 $form_nums = $this->params['named']['num'];
336 $this->set('form_nums', $form_nums);
338 $this->pageTitle .= " ". sprintf(__('Edit %s', true), $character['Character']['name']);
341 function change_system($id = null) {
343 $this->Session->setFlash(__('Invalid ID.', true));
344 $this->redirect(array('action'=>'index'));
348 $this->Character->System->hasMany['Profile']['fields'] = '';
349 $this->Character->System->Profile->hasMany['CharactersHasProfile']['fields'] = '';
351 $character = $this->_get_character($id);
352 if (!$this->isOwner($character['Character'], $this->user_id)) {
353 $this->Session->setFlash(__('No Permission', true));
354 $this->redirect(array('action'=>'index'));
358 if (isset($character['System']) && !empty($character['System'])) {
360 if ($this->check_public_flag($character['System'])) {
361 $this->redirect(array('action'=>'edit', $id));
364 $this->set('isChange', true);
368 if (!empty($this->data)) {
369 $this->data['clearCache'] = array(
370 'character_id' => $id,
371 'user_id' => $this->user_id,
372 'system_id' => $character['System']['id'],
375 $this->data['Character']['id'] = $id;
377 // validateはsystem_idのみ
378 $this->Cahracter['validate'] = array(
379 'system_id' => array(
380 'validSystemId' => array(
381 'rule' => array('validSystemId', true),
382 'allowEmpty' => false,
387 if ($this->Character->save(
391 'fieldList' => array('system_id'),
394 $this->Session->setFlash(__('The new system has been saved', true));
395 $this->redirect(array('action'=>'view', $id));
397 $this->Session->setFlash(__('The data could not be saved. Please, try again.', true));
401 $this->set('isOwner', true);
402 $this->set('character', $character);
404 $systems = $this->_get_systems();
405 $this->set('systems', $systems);
407 $this->pageTitle .= " ". sprintf(__('%s Change System', true), $character['Character']['name']);
411 function set_status($id = null) {
412 if (!$id || !isset($this->params['named']['mode'])) {
413 $this->Session->setFlash(__('Invalid ID.', true));
414 $this->redirect(array('controller' => 'characters', 'action'=>'index'));
417 $character = $this->_get_character4character_id($id, $this->user_id, 'public');
419 if ($this->params['named']['mode'] != 'main_picture' && $this->params['named']['mode'] != 'full_length') {
420 $this->Session->setFlash(__('Invalid URL.', true));
421 $this->redirect(array('controller' => 'character_pictures', 'action'=>'index', $id));
425 $new_character_picture = null;
426 if (isset($this->params['named']['new_picture_id']) && $this->params['named']['new_picture_id'] != 'null') {
427 if ($character['CharacterPicture']) {
428 foreach($character['CharacterPicture'] as $k => $v) {
429 if ($v['id'] == $this->params['named']['new_picture_id']) {
430 $new_character_picture = CorePlus::get_value($v, 'Attachment.0.basename');
435 if (!$new_character_picture) {
436 $this->Session->setFlash(__('Invalid data.', true));
437 $this->redirect(array('controller' => 'character_pictures', 'action'=>'listview', $id));
442 $this->data['clearCache'] = array(
443 'character_id' => $id,
444 'user_id' => $this->user_id,
445 'system_id' => $character['Character']['system_id'],
449 $this->Character->id = $id;
450 $this->data['Character'][$this->params['named']['mode']] = $new_character_picture;
451 $this->Character->save(
454 'fieldList' => array(
455 $this->params['named']['mode']
460 $this->Character->deleteCache4CharacterPicture($id);
463 $this->Session->setFlash(__('CharacterPicture Configuration has been saved.', true));
464 $this->redirect(array('controller' => 'character_pictures', 'action' => 'listview', $id));
467 function delete($id = null) {
469 $this->Session->setFlash(__('Invalid id for Character', true));
470 $this->redirect(array('action'=>'index'));
473 if ($this->_delete($id)) {
474 $this->redirect(array('controller' => 'users', 'action'=>'index'));
477 $this->pageTitle .= " - ". __('Delete Character', true);
480 function admin_index($id = null) {
481 unset($this->Character->belongsTo['System']['conditions']['System.public_flag']);
482 $this->_index($id, array('isAdmin' => true));
485 function admin_view($id = null) {
487 $this->Session->setFlash(__('Invalid Character.', true));
488 $this->redirect(array('action' => 'admin_index'));
491 $character = $this->_view($id, array(), true);
493 $this->set('character', $this->HtmlEscape->nl2br_escaped($character));
496 function admin_edit($id = null) {
497 if (!$id && empty($this->data)) {
498 $this->Session->setFlash(__('Invalid ID.', true));
499 $this->redirect(array('action'=>'index'));
503 $this->Character->System->hasMany['Profile']['fields'] = '';
504 $this->Character->System->Profile->hasMany['CharactersHasProfile']['fields'] = '';
505 unset($this->Character->hasMany['CharacterProfileArchive']);
507 $character = $this->_get_character($id, array(), true);
509 $this->Session->setFlash(__('No Character', true));
510 $this->redirect(array('action'=>'index'));
513 if (empty($this->data)) {
514 $character['System']['Profile'] = $this->_set_profile_table2characters_has_profiles($character['System']['Profile']);
517 if (!empty($this->data)) {
519 $this->data['clearCache'] = array(
520 'character_id' => $id,
521 'user_id' => $this->user_id,
522 'system_id' => $character['System']['id'],
525 if (isset($this->data['Character']['mode']) && $this->data['Character']['mode'] == 'set_private') {
526 $this->data['Character']['public_flag'] = 'private';
527 } elseif (isset($this->data['Character']['mode']) && $this->data['Character']['mode'] == 'set_public') {
528 $this->data['Character']['public_flag'] = 'public';
529 } elseif (isset($this->data['Character']['mode']) && $this->data['Character']['mode'] == 'delete_confirm') {
530 $this->redirect(array('controller' => 'characters', 'action'=>'admin_delete', $id));
532 $this->Session->setFlash(sprintf(__('Invalid data.', true), $this->data['Character']['name']));
533 $this->redirect(array('action'=>'view', $id));
536 $this->data['Character']['id'] = $id;
537 $this->Character->create();
538 if ($this->Character->save($this->data, array(
540 'fieldList' => array(
545 $this->Session->setFlash(sprintf(__('%s has been saved.', true), $character['Character']['name']));
546 $this->redirect(array('action'=>'view', $id));
549 $this->data = array_merge($character, $this->data);
550 $this->data['Character']['id'] = $id;
553 if (empty($this->data)) {
554 $this->data = $character;
555 $this->data['Character'] = $this->_restore_html_character($this->data['Character'], true);
557 $this->data['System']['Profile'] = $this->_restore_html_characters_has_profiles($this->data['System']['Profile'], true);
560 $this->pageTitle .= " ". sprintf(__('Edit %s', true), $character['Character']['name']);
563 function admin_delete($id = null) {
565 $this->Session->setFlash(__('Invalid id for Character', true));
566 $this->redirect(array('action'=>'index'));
569 if ($this->_delete($id, array(), true)) {
570 $this->redirect(array('action'=>'index'));
573 $this->pageTitle .= " - ". __('Delete Character', true);
578 function _index($id, $conditions = array(), $limit = 20, $fields = array(), $contain = array(), $order = array(), $page = 1) {
579 if (isset($conditions['isAdmin']) && $conditions['isAdmin'] === true) {
584 unset($conditions['isAdmin']);
586 $title = __('List of All Characters', true);
589 if (isset($this->params['named']['system']) && intval($this->params['named']['system'])) {
591 $conditions['System.id'] = $this->params['named']['system'];
592 if ($isAdmin === false) {
593 $conditions['System.public_flag'] = 'public';
596 $this_system = $this->Character->System->find('first', array(
597 'conditions' => $conditions,
601 if (!isset($this_system['System'])) {
602 $this->Session->setFlash(__('Invalid System.', true));
603 $this->redirect(array('controller' => 'systems', 'action' => 'index'));
605 $this_system = $this->_restore_html_system($this_system);
607 $title = $this_system['System']['name']. " ". $title;
609 $this->set('this_system', $this_system);
611 $contain = array_merge(array('System'), (array)$contain);
615 $conditions = array('User.id' => $id);
618 $user = $this->Character->User->find('first', array(
619 'conditions' => $conditions,
628 $this->Session->setFlash(__('Invalid Id.', true));
629 $this->redirect(array('action'=>'index'));
632 $title = $user['User']['name']. " ". $title;
634 $contain = array_merge($contain, array('User'));
636 $this->set('userSet', $user);
638 $conditions = array();
640 $conditions['Character.user_id'] = $id;
641 if ($id == $this->user_id) {
642 unset($this->paginate['conditions']['Character.public_flag']);
645 if ($isAdmin === true) {
646 $conditions['isAdmin'] = true;
648 if (isset($this->params['named']['system']) && intval($this->params['named']['system'])) {
649 $conditions['Character.system_id'] = $this->params['named']['system'];
651 $characters = $this->HtmlEscape->nl_unescape($this->_get_characters_page4user_id($id, $conditions, $limit, $fields, $contain, $order, $page));
653 $this->set('characters', $characters);
655 $this->pageTitle .= " - ". $title;
658 function _view($id, $conditions = array(), $isAdmin = false) {
659 $this->helpers[] = 'CharacterSheet';
663 if (isset($this->params['named']['mode']) && !empty($this->params['named']['mode'])) {
664 $this->view = 'Theme';
665 $this->theme = $this->params['named']['mode'];
670 $orig_character = $this->_get_character($id, $conditions, $isAdmin);
671 $character = $this->Character->set_profiles2view($orig_character);
673 Configure::write('isOwner', false);
674 if ($isAdmin || CorePlus::isOwner($character['Character'], $this->user_id)) {
675 Configure::write('isOwner', true);
679 $this->set('systemValid', 'public');
680 if (!$character['System']) {
681 $this->set('systemValid', false);
683 if (!$this->check_public_flag($character['System'])) {
684 $this->set('systemValid', 'unpublic');
686 $character = $this->_restore_html_system($character);
688 $this->pageTitle .= " - ". $character['Character']['name'];
693 function _delete($id = null, $conditions = array(), $isAdmin = false) {
695 $this->Session->setFlash(__('Invalid id for Character', true));
696 $this->redirect(array('action'=>'index'));
699 $character = $this->_view($id, $conditions, $isAdmin);
700 if (empty($character)) {
701 $this->Session->setFlash(__('No Character', true));
702 $this->redirect(array('action'=>'index'));
704 $this->set('character', $character);
706 if (!$isAdmin && !$this->isOwner($character['Character'], $this->user_id)) {
707 $this->Session->setFlash(__('No Permission', true));
708 $this->redirect(array('action'=>'index'));
710 $this->set('isOwner', true);
712 if (!empty($this->data)) {
714 $this->data['clearCache'] = array(
715 'character_id' => $id,
716 'user_id' => $this->user_id,
717 'system_id' => $character['System']['id'],
720 if ($this->data['Character']['confirm'] == 'yes') {
722 $this->data['Character']['id'] = $id;
723 $this->data['Character']['main_picture'] = null;
724 $this->data['Character']['full_length'] = null;
725 $this->data['Character']['deleted'] = true;
726 $this->data['Character']['deleted_date'] = date('Y-m-d H:i:s');
728 $this->Character->create();
729 if ($this->Character->save(
733 'fieldList' => array(
742 // CharactersHasProfiles
743 $this->Character->CharactersHasProfile->updateAll(
745 'CharactersHasProfile.public_flag' => "'private'",
748 'CharactersHasProfile.character_id' => $id
752 // CharacterProfileArchives
753 $date = date('Y-m-d H:i:s');
754 $this->Character->CharacterProfileArchive->updateAll(
756 'CharacterProfileArchive.deleted' => true,
757 'CharacterProfileArchive.deleted_date' => "'$date'",
760 'CharacterProfileArchive.character_id' => $id
765 if (isset($character['CharacterPicture']) && !empty($character['CharacterPicture'])) {
766 foreach ($character['CharacterPicture'] as $picture) {
767 $this->Character->CharacterPicture->delete($picture['id']);
771 $this->Session->setFlash(__('Character deleted', true));
775 $this->Session->setFlash(__('The Character could not be deleted.', true));
784 function _get_character($id, $conditions = array(), $isAdmin = false)
786 $character = $this->Character->get_character($id, $conditions, $isAdmin);
788 if (empty($character)) {
789 $this->Session->setFlash(__('No Character', true));
790 $this->redirect(array('action'=>'index'));
793 if ($isAdmin === false && !$this->check_public_flag($character['Character'])) {
794 $this->Session->setFlash(__('No Permission', true));
795 $this->redirect(array('action'=>'index'));
798 if (isset($character['System']['Profile'])) {
799 $character['System'] = $this->_restore_html_profile($character['System']);
805 // ProfileTableをCharacterHasProfilesのTableの形式にセット
806 function _set_profile_table2characters_has_profiles($profile)
808 if (!empty($profile[0]['CharactersHasProfile'])) {
812 foreach($profile as $k => $v) {
813 if (empty($v['ProfileTable'])) {
817 $rows = count($v['CharactersHasProfile']);
818 for($i=0; $i<$rows; $i++) {
819 foreach($v['ProfileTable'] as $k2 => $v2) {
820 if (isset($v2['CharactersHasProfile'][$i])) {
821 $tmp[] = $v2['CharactersHasProfile'][$i];
822 } elseif (isset($v['CharactersHasProfile'][$i])) {
823 $tmp[] = $v['CharactersHasProfile'][$i];
831 $profile[$k]['CharactersHasProfile'] = $tmp;
837 /* POSTのCharactersHasProfileを処理 */
838 function _set_new_characters_has_profile($characters_has_profiles, $profile_id = null, $now_data = array())
840 $prev_profile_id = null;
841 $profileTable_tmp = array();
844 foreach ($characters_has_profiles as $k => $v) {
845 if (!empty($character_id)) {
846 $characters_has_profiles[$k]['character_id'] = $character_id;
849 if (is_array($v['value'])) {
850 $characters_has_profiles[$k]['value'] = $v['value'][0];
854 $characters_has_profiles[$k]['value'] = Sanitize::html($characters_has_profiles[$k]['value']);
855 $characters_has_profiles[$k]['value'] = preg_replace('/[\\\n]/', '', $characters_has_profiles[$k]['value']);
856 $characters_has_profiles[$k]['value'] = preg_replace('/[\\\r]/', '', $characters_has_profiles[$k]['value']);
858 if (isset($v['is_textarea']) && $v['is_textarea'] == 1) {
859 $characters_has_profiles[$k]['value'] = str_replace(array("\n\r", '\n', "\r"), '<br />', $characters_has_profiles[$k]['value']);
860 $characters_has_profiles[$k]['value'] = str_replace("\\", '', $characters_has_profiles[$k]['value']);
862 $characters_has_profiles[$k]['value'] = Sanitize::stripAll($characters_has_profiles[$k]['value']);
864 // 空の値処理, public_flag
865 // table: 一時保管して全項目空の場合行削除
866 if (CorePlus::is_valid($v, 'profile_table_id')) {
867 if (isset($profileTable_tmp[$v['profile_id']][$i][$v['profile_table_id']])) {
873 if ($public == null && isset($characters_has_profiles[$k]['public_flag'])) {
874 $public = $v['public_flag'];
876 if ($v['profile_table_static_id']) {
877 $characters_has_profiles[$k]['public_flag'] = 'public';
880 $characters_has_profiles[$k]['public_flag'] = $public;
883 $profileTable_tmp[$v['profile_id']][$i][$v['profile_table_id']] = array($characters_has_profiles[$k], $k);
885 } elseif (empty($v['value'])) {
886 unset($characters_has_profiles[$k]);
890 // table: 空行削除、不正profile_table_idデータ削除
891 if (!empty($profileTable_tmp)) {
892 if (!isset($this->Character->ProfileTable)) {
893 $this->Character->ProfileTable = CorePlus::set_model('ProfileTable');
895 foreach($profileTable_tmp as $profile_id => $v) {
896 $profile_table_columns = $this->Character->ProfileTable->find('list', array(
897 'conditions' => array('ProfileTable.profile_id' => $profile_id),
898 'fields' => array('ProfileTable.id'),
899 'order' => array('ProfileTable.sort_order' => 'asc'),
903 foreach ($v as $i => $profile_tables) {
905 $diff_keys = array_diff_key($profile_tables, $profile_table_columns);
906 if (!empty($diff_keys)) {
907 foreach($diff_keys as $dvalue) {
908 unset($characters_has_profiles[$dvalue[1]]);
914 foreach($profile_table_columns as $k2 => $columns) {
915 if (CorePlus::is_valid($profile_tables, $columns.'.0.value')) {
920 if ($delete_flg === true) {
921 foreach ($profile_tables as $delk) {
922 unset($characters_has_profiles[$delk[1]]);
930 if (!is_null($profile_id) && !empty($now_data)) {
933 foreach($now_data as $k => $v) {
934 if ($v['id'] == $profile_id) {
935 $v['CharactersHasProfile'] = $characters_has_profiles;
938 foreach ($v['CharactersHasProfile'] as $k2 => $v2) {
940 if (isset($tmp[$i]['id'])) {
941 unset($tmp[$i]['id']);
943 if (isset($tmp[$i]['character_id'])) {
944 unset($tmp[$i]['character_id']);
951 $characters_has_profiles = $tmp;
954 return $characters_has_profiles;
957 // CharactersHasProfileの追加valiadte設定
958 function _set_validate4characters_has_profile($system_id)
960 $this->Character->CharactersHasProfile->validate['profile_id']['validProfileId'] = array(
961 'rule' => array('validProfileId', $system_id),
963 $this->Character->CharactersHasProfile->validate['profile_select_id']['validProfileSelectId'] = array(
964 'rule' => array('validProfileSelectId', $system_id),
965 'allowEmpty' => true,
967 $this->Character->CharactersHasProfile->validate['profile_table_id']['validProfiletableId'] = array(
968 'rule' => array('validProfiletableId', $system_id),
969 'allowEmpty' => true,
974 function _restore_html_character($data, $nl2br = false) {
975 $data['name'] = $this->{$this->modelClass}->restore_html($data['name'], false, false, false);
976 $data['notes'] = $this->{$this->modelClass}->restore_html($data['notes'], false, false, false);
978 $data['notes'] = str_replace('<br />', "\n", $data['notes']);
984 function _restore_html_characters_has_profiles($profile, $nl2br = false) {
985 if (empty($profile)) {
989 foreach($profile as $k => $v) {
990 if (empty($v['CharactersHasProfile'])) {
993 $profile[$k]['CharactersHasProfile'] = $this->__restore_html_characters_has_profiles($v['CharactersHasProfile'], $nl2br, $v['profile_type']);
998 function __restore_html_characters_has_profiles($data, $nl2br = false, $profile_type = null) {
1003 foreach ($data as $k => $v) {
1004 if (isset($v['value'])) {
1005 $data[$k]['value'] = $this->{$this->modelClass}->restore_html($v['value'], false, false, false);
1006 if ($nl2br && $profile_type == 'textarea') {
1007 $data[$k]['value'] = str_replace('<br />', "\n", $data[$k]['value']);