6 class ProfiledispHelper extends Helper {
14 var $i18n_profile_types = array();
16 var $profile_type = array();
18 var $public_flags= array();
20 var $character_has_profile_num = 0;
21 var $character_has_profile_cols = 0;
25 function __construct()
27 parent::__construct();
29 $this->Character = CorePlus::set_model('Character');
30 $this->public_flags = $this->Character->public_flag;
35 * profile_typeの設定をview表示形式に変換
37 function get_i18n_profile_type($profile_type, $profile_types)
39 if (empty($profile_type)) {
43 if (empty($this->i18n_profile_types)) {
44 $this->i18n_profile_types = $this->set_profile_type($profile_types);
47 return $this->i18n_profile_types[$profile_type];
50 * profile_typeの選択プルダウン出力
53 function create_profile_type_select($profile_types = array(), $fieldName = 'profile_type', $options = array('type' => 'select'))
55 if (!isset($options['type'])) {
56 $options['type'] = 'select';
58 if (!isset($options['options'])) {
59 $options['options'] = array();
61 $options['options'] = $this->set_profile_type($profile_types, $options['options']);
63 return $this->Form->input($fieldName, $options);
65 /* profile_typeの設定を、key->value(多言語化対応)に変換 */
66 function set_profile_type($profile_types = array(), $options = array())
68 if (!empty($options)) {
69 $this->i18n_profile_types = $options;
72 if (empty($profile_types)) {
73 App::import('Model', 'Profile');
74 $Profile = new ProfileModel;
75 $profile_types = $Profile->profile_type;
78 foreach ($profile_types as $k => $v) {
80 $this->i18n_profile_types[$v] = __('input', true);
81 } elseif($v == 'textarea') {
82 $this->i18n_profile_types[$v] = __('textarea', true);
83 } elseif($v == 'select') {
84 $this->i18n_profile_types[$v] = __('select', true);
85 } elseif($v == 'radio') {
86 $this->i18n_profile_types[$v] = __('radio', true);
87 } elseif($v == 'checkbox') {
88 $this->i18n_profile_types[$v] = __('checkbox', true);
89 } elseif($v == 'm-input') {
90 $this->i18n_profile_types[$v] = __('multi input', true);
91 } elseif($v == 'table') {
92 $this->i18n_profile_types[$v] = __('table', true);
93 } elseif($v == 's-table') {
94 $this->i18n_profile_types[$v] = __('static table', true);
96 $this->i18n_profile_types[$v] = $v;
100 return $this->i18n_profile_types;
103 /* profileの設定をフォームで出力 */
104 function disp_form4profile($profile, $form_num = 2, $disp_add_link = false, $disp_public = false, $options = array())
106 if ($profile['profile_type'] == 'textarea') {
107 $options['type'] = 'textarea';
109 $options['type'] = 'text';
112 $character_id = null;
113 if (isset($options['character_id'])) {
114 $character_id = $options['character_id'];
118 if ($options['type'] == 'textarea') {
122 if (!CorePlus::is_valid($profile, 'CharactersHasProfile.0.value')) {
123 $profile['CharactersHasProfile'][0]['value'] = null;
126 foreach ($profile['CharactersHasProfile'] as $k => $v) {
127 $disp_profile = $this->_get_profile_tag($profile['id'], $v['value'], false, $options);
130 echo $this->dispPublicFlag4Profile($disp_profile, $this->character_has_profile_num, $v, false)."<br>\n";
135 $this->character_has_profile_num++;
138 if ($this->profile_type['is_multi']) {
139 for ($i=0;$i<$form_num;$i++) {
140 $disp_profile = $this->_get_profile_tag($profile['id'], null, false, $options);
143 echo $this->dispPublicFlag4Profile($disp_profile, $this->character_has_profile_num, $profile, $isMulti)."<br>\n";
148 $this->character_has_profile_num++;
151 if ($disp_add_link) {
152 echo $this->Html->div('editLink', $this->Html->link(
155 'action' => 'add_milti_profiles',
156 $options['character_id'].
157 '/profile_id:'.$profile['id']
160 __('If some data have been changed, you should save before click it. OK?', true)
165 function _get_profile_tag($profile_id, $value = null, $label = false, $options = array())
167 if (empty($profile_id)) {
171 $name1 = sprintf('CharactersHasProfile.%s.value', $this->character_has_profile_num);
172 $name2 = sprintf('CharactersHasProfile.%s.profile_id', $this->character_has_profile_num);
173 $options = array_merge(array(
180 $this->Form->input($name1, $options).
181 $this->Form->input($name2, array(
183 'value' => $profile_id,
185 if ($options['type'] == 'textarea') {
186 $name3 = sprintf('CharactersHasProfile.%s.is_textarea', $this->character_has_profile_num);
187 $profile_tag .= $this->Form->input($name3, array(
196 function dispPublicFlag4Profile($profile, $profile_num, $public_flag = null, $isMulti = false)
198 $profilePublicName = sprintf('CharactersHasProfile.%d.public_flag', $profile_num);
200 if (is_array($profile) && isset($profile['CharactersHasProfile'][0]['public_flag'])) {
201 $selected_public_flag = $profile['CharactersHasProfile'][0]['public_flag'];
202 } elseif(is_array($public_flag) && isset($public_flag['public_flag'])) {
203 $selected_public_flag = $public_flag['public_flag'];
204 } elseif (is_string($public_flag)) {
205 $selected_public_flag = $public_flag;
207 $selected_public_flag = null;
210 $publicSelect = array(
212 'div' => 'profilePublic',
213 'value' => $selected_public_flag,
215 if ($isMulti === true) {
216 $publicSelect['div'] = 'profilePublic profilePublicMulti';
219 if (!empty($profile)) {
220 $publicSelect['before'] = $profile;
223 $public_select = $this->Select->create_publicflag_select($this->public_flags, $profilePublicName, $publicSelect);
224 if (!empty($profile)) {
225 $public_select .= '<WBR>';
228 return $public_select;
231 /* profile_selectsの設定を出力 */
232 function disp4profile_selects($profile_selects, $disp_public = false, $option = array())
234 foreach ($profile_selects as $k => $v) {
235 $options[stripcslashes($v['value'])] = stripcslashes($v['value']);
237 $options = array_merge(
240 'options' => $options,
245 $profile_select_tag =
246 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.value', $options).
247 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_id', array(
249 'value' => $profile_selects[0]['profile_id'],
251 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_select_id', array(
253 'value' => $profile_selects[0]['id'],
255 $profile = $profile_select_tag;
258 echo $this->dispPublicFlag4Profile($profile, $this->character_has_profile_num, $options['public_flag']);
263 $this->character_has_profile_num++;
267 /* profile_selectsの設定をプルダウンで出力 */
268 function disp_select4profile_selects($profile_selects, $characters_has_profile = array(), $options = array(), $label = false, $legend = false, $disp_public = false, $isProfileDefault = false)
270 if (empty($profile_selects)) {
274 $selected = $this->set_form_value($profile_selects, $characters_has_profile, $isProfileDefault);
277 if (isset($characters_has_profile[0]['public_flag'])) {
278 $public_flag = $characters_has_profile[0]['public_flag'];
281 $options = array_merge(
286 'selected' => $selected['value'],
287 'public_flag' => $public_flag,
292 $this->disp4profile_selects($profile_selects, $disp_public, $options);
295 /* profile_selectsの設定をラジオボタンで出力 */
296 function disp_radio4profile_selects($profile_selects, $characters_has_profile = array(), $label = false, $legend = false, $disp_public = false)
298 if (empty($profile_selects)) {
302 $selected = $this->set_form_value($profile_selects, $characters_has_profile);
303 if ($selected['value']) {
304 $selected_value = $selected['value'];
306 $first = reset($profile_selects);
307 $selected_value = $first['value'];
311 if (isset($characters_has_profile[0]['public_flag'])) {
312 $public_flag = $characters_has_profile[0]['public_flag'];
317 'value' => $selected_value,
320 'public_flag' => $public_flag,
322 'class' => 'input radio inline'
326 return $this->disp4profile_selects($profile_selects, $disp_public, $options);
330 /* profile_selectsの設定をチェックボックスで出力 */
331 function disp_checkbox4profile_selects($profile_selects, $characters_has_profile = array(), $label = false, $legend = false, $disp_public = false, $isProfileDefault = false)
333 if (empty($profile_selects)) {
337 foreach($profile_selects as $k => $v) {
342 $profile_select[0] = $v;
343 $has_profile[0] = $this->get_selected_profile($v, $characters_has_profile, $isProfileDefault);
344 $this->disp_select4profile_selects(
348 'multiple' => 'checkbox',
352 'class' => 'input checkbox inline'
354 ), $label, $legend, $disp_public, $isProfileDefault
359 /* profile_tablesの設定からtableHeadersを出力 */
360 function disp_th4profile_tables($profile_tables, $tableId = null, $disp_public = false, $tr_options = array(), $th_options = array())
362 if (empty($profile_tables)) {
367 $style_options = array();
369 foreach ($profile_tables as $k => $v) {
370 $values[$k] = $v['title'];
373 $key = '#'.$tableId.' td.column-' . $i;
374 $style_options[$key] = array('width' => $v['width']."px");
375 $key = '#'.$tableId.' td.column-' . $i. ' input';
376 $style_options[$key] = array('width' => $v['width']."px");
381 if ($disp_public === true) {
382 $values[] = __('Public Flag', true);
385 if (!empty($style_options)) {
386 echo '<style type="text/css"><!--'."\n";
387 foreach($style_options as $k => $v) {
389 echo $this->Html->style($v);
395 $table_header = $this->Html->tableHeaders(
401 $table_header = '<thead>'.$table_header.'</thead>';
406 /* characters_has_profilesの設定からtableCellsを出力 */
407 function disp_td4characters_has_profiles($characters_has_profiles, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
409 if (empty($characters_has_profiles)) {
413 if (isset($characters_has_profiles[0]['ProfileTableStatic'])) {
414 $statics = $characters_has_profiles[0]['ProfileTableStatic'];
418 foreach ($characters_has_profiles as $k => $v) {
422 $values[$k] = $v['value'];
426 $table_cells = $this->Html->tableCells($values, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
431 /* characters_has_profileからtable td出力 */
432 function disp_tds4characters_has_profiles($characters_has_profile, $type = 'view', $publicOnly = true, $profile_type = null, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true, $isProfileDefault = false)
436 $profiles[$i] = array();
438 foreach($characters_has_profile as $k => $v) {
439 if (is_null($profile_id) && CorePlus::is_valid($v, 'profile_id')) {
440 $profile_id = $v['profile_id'];
442 if (!CorePlus::is_valid($v, 'profile_id')) {
443 if (!is_null($profile_id) && !CorePlus::is_valid($v, 'profile_id')) {
444 $v['profile_id'] = $profile_id;
450 if (!CorePlus::is_valid($v, 'profile_table_id')) {
451 $profile_table_ids = array_keys(Set::combine($characters_has_profile, '{n}.profile_table_id'));
453 if (!empty($prof_table_ids)) {
454 $v['profile_table_id'] = current(array_slice($prof_table_ids, $profile_num+1, 1));
457 $v['profile_table_id'] = null;
463 $v['id'] = $v['profile_table_id'];
465 if (isset($profiles[$i][$v['profile_table_id']])) {
468 $profiles[$i][$v['profile_table_id']] = $v;
474 foreach($profiles as $k => $v) {
475 if ($type == 'form') {
476 $tds = $this->disp_form4profile_tables($v, $publicOnly, $oddTrOptions, $evenTrOptions, true, true, $isProfileDefault);
478 $tds = $this->disp_value4profile_tables($v, $publicOnly, $profile_type, null, null, true, $isProfileDefault);
481 $this->character_has_profile_cols = 0;
483 $this->disp_td4characters_has_profiles($tds, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
487 /* characters_has_profileからvalue出力 */
488 function disp_value_td4characters_has_profiles($characters_has_profile, $publicOnly = true, $profile_type = null)
490 $this->disp_tds4characters_has_profiles($characters_has_profile, 'view', $publicOnly, $profile_type, null, null, true);
493 /* characters_has_profileからtdフォーム出力 */
494 function disp_form_td4characters_has_profiles($characters_has_profile, $disp_public = false, $profile_type = null, $isProfileDefault = false)
496 if ($disp_public === true) {
501 $this->disp_tds4characters_has_profiles($characters_has_profile, 'form', $publicOnly, $profile_type, null, null, true, true, $isProfileDefault);
504 /* profile_tablesの設定からView表示を出力 */
505 function disp_value4profile_tables($profile_tables, $publicOnly = true, $profile_type = null, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true, $isProfileDefault = false)
507 if (empty($profile_tables)) {
513 foreach ($profile_tables as $k => $v) {
514 if (!Set::check($v, 'value')) {
515 $v['value'] = " ";
516 } elseif (!$this->isPublic($v, $publicOnly)) {
517 $v['value'] = " ";
519 if(!$publicOnly && $v['public_flag'] != 'public') {
520 $v['value'] = $this->Html->tag('span', $v['value'], array('class' => 'publicFlagBg'));
522 if ($this->isPublic($v, $publicOnly)|| $profile_type != 'table') {
523 $tds[] = $v['value'];
528 $this->disp_td4characters_has_profiles($tds, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
531 /* profile_tablesの設定から入力フォームを出力 */
532 function disp_form4profile_tables($profile_tables, $publicOnly = true, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true, $isProfileDefault = false)
534 if (empty($profile_tables)) {
537 $first = reset($profile_tables);
539 if (isset($first['ProfileTableStatic'])) {
540 $statics = $first['ProfileTableStatic'];
545 $first_num = $this->character_has_profile_num;
546 $first = reset($profile_tables);
547 foreach ($profile_tables as $k => $v) {
548 if (!Set::check($v, 'profile_id')) {
551 if (!Set::check($v, 'id')) {
552 if (Set::check($v, 'profile_table_id')) {
553 $v['id'] = $v['profile_table_id'];
559 if (!Set::check($v, 'value')) {
563 if ($i == 0 && (isset($statics[$this->character_has_profile_cols]) || (isset($v['profile_table_static_id']) && !empty($v['profile_table_static_id'])))) {
564 $value = isset($v['profile_table_static_id']) ? $v['value']: $statics[$this->character_has_profile_cols]['title'];
565 $form = '<span class="staticHead">'.$value.'</span>'.
566 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.value', array(
571 $form = $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.value', array(
574 'class' => 'longInput',
575 'value' => $v['value'],
579 if (isset($v['profile_table_static_id'])) {
580 $profile_table_static_id = $v['profile_table_static_id'];
581 } elseif (isset($profile_tables[0]['ProfileTableStatic'][$this->character_has_profile_cols]['id'])) {
582 $profile_table_static_id = $profile_tables[0]['ProfileTableStatic'][$this->character_has_profile_cols]['id'];
584 $profile_table_static_id = null;
589 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_id', array(
591 'value' => $v['profile_id'],
593 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_table_id', array(
597 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_table_static_id', array(
599 'value' => $profile_table_static_id,
601 $this->character_has_profile_num++;
605 if ($publicOnly === false) {
606 if ($isProfileDefault && isset($last["public_flag"])) {
607 $last = end($profile_tables);
608 $forms[] = $this->dispPublicFlag4Profile(null, $first_num, $last["public_flag"], false);
610 $forms[] = $this->dispPublicFlag4Profile(null, $first_num, $first, false);
614 $this->character_has_profile_cols++;
616 $this->disp_td4characters_has_profiles($forms, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
619 /* profile_tablesの設定からブランクのtableCellsを出力 */
620 function disp_blank_td4profile_tables($profile_tables, $num = 2, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
622 if (empty($profile_tables)) {
626 $blank = array_fill(0, count($profile_tables), $this->Html->div('blank', " "));
628 for ($i=0; $i<$num; $i++) {
629 $this->disp_td4characters_has_profiles($blank, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
634 function set_profile_type4view($profile)
636 $this->profile_type = array(
637 'is_subsetting' => false,
638 'is_select' => false,
640 'is_checkbox' => false,
645 if ($profile['profile_type'] == 'select' || $profile['profile_type'] == 'radio' || $profile['profile_type'] == 'checkbox' || $profile['profile_type'] == 'table' ) {
646 $this->profile_type['is_subsetting'] = true;
648 if ($profile['profile_type'] == 'select') {
649 $this->profile_type['is_select'] = true;
651 if ($profile['profile_type'] == 'radio') {
652 $this->profile_type['is_radio'] = true;
654 if ($profile['profile_type'] == 'checkbox') {
655 $this->profile_type['is_checkbox'] = true;
657 if ($profile['profile_type'] == 'table' || $profile['profile_type'] == 's-table') {
658 $this->profile_type['is_table'] = true;
660 if ($profile['profile_type'] == 'm-input') {
661 $this->profile_type['is_multi'] = true;
665 /* profile_typeの設定に応じてフォーム表示
666 * set_profile_type4view($profile)チェック済み前提。
668 function disp_forms4profile_type($profile, $form_num = 2, $table_blank = 2, $disp_add_link = false, $character_id = null, $disp_public = false, $options = array(), $isProfileDefault = false)
670 if (!isset($profile['CharactersHasProfile']) || empty($profile['CharactersHasProfile'])) {
671 if (isset($profile['DefaultProfile']) && !empty($profile['DefaultProfile'])) {
672 $profile['CharactersHasProfile'] = $profile['DefaultProfile'];
673 $form_num = $form_num - count($profile['DefaultProfile']) +1;
675 $profile['CharactersHasProfile'] = array();
679 if ($this->profile_type['is_select'] || $this->profile_type['is_radio'] || $this->profile_type['is_checkbox']) {
680 if ($this->profile_type['is_select']) {
681 $this->disp_select4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile'], array('div' => array('class' => 'inline')), false, false, $disp_public);
682 } elseif ($this->profile_type['is_radio']) {
683 $this->disp_radio4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile'], false, false, $disp_public);
684 } elseif ($this->profile_type['is_checkbox']) {
685 $this->disp_checkbox4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile'], false, false, $disp_public, $isProfileDefault);
687 } elseif ($this->profile_type['is_table']) {
688 if ($disp_public == true) {
694 if (isset($profile['id'])) {
695 $tableId = 'TableProfileId'. $profile['id'];
697 $tableId = 'TableProfileId'. $profile['Profile']['id'];
699 echo '<table id="'.$tableId.'">';
700 $this->disp_th4profile_tables($profile['ProfileTable'], $tableId, $disp_public);
702 if (!empty($profile['CharactersHasProfile'])) {
703 $this->disp_form_td4characters_has_profiles($profile['CharactersHasProfile'], $disp_public, null, $isProfileDefault);
706 if (intval($form_num) > 0
707 && ((isset ($profile['Profile']['profile_type']) && $profile['Profile']['profile_type'] != 's-table') || (isset($profile['profile_type']) && $profile['profile_type'] != 's-table'))
708 || empty($profile['CharactersHasProfile'])) {
709 for ($i=0; $i<$form_num; $i++) {
710 $this->disp_form4profile_tables($profile['ProfileTable'], $publicOnly, array(), array(), true);
712 $this->character_has_profile_cols = 0;
714 if (intval($table_blank) > 0 && $profile['profile_type'] != 's-table') {
715 $this->disp_blank_td4profile_tables($profile['ProfileTable'], intval($table_blank), null, null, true);
719 if ($disp_add_link) {
720 $link = $this->Html->link(
721 __('Add Column', true),
723 'action' => 'add_milti_profiles',
725 '/profile_id:'.$profile['id']
728 __('If some data have been changed, you should save before click it. OK?', true)
730 if (!empty($profile['CharactersHasProfile'][0]['character_id'])) {
731 $link .= " ".$this->Html->link(
734 'controller' => 'characters_has_profiles',
735 'action' => 'delete',
737 'character_id:'.$profile['CharactersHasProfile'][0]['character_id'],
740 sprintf(__('Are you sure you want to clear the data of %s?', true), $profile['name'])
744 echo $this->Html->div(
751 $options = array_merge(array(
752 'character_id' => $character_id,
755 $this->disp_form4profile($profile, $form_num, $disp_add_link, $disp_public, $options);
758 if (isset($profile['required']) && $profile['required'])
760 echo $this->Html->tag(
762 __(' required', true),
764 'class' => 'required'
770 /* characters_has_profilesの設定に応じてView表示
771 * set_profile_type4view($profile)チェック済み前提。
772 * $profileのkeyはprofilesのkey_name
774 function disp_values4characters_has_profiles($profile, $table_blank = 2, $disp_add_link = false, $character_id = null, $publicOnly = true)
776 if (!isset($profile['CharactersHasProfile']) && !$this->profile_type['is_table']) {
777 $profile['CharactersHasProfile'] = array();
780 if (!$this->profile_type['is_table']) {
782 foreach ($profile['CharactersHasProfile'] as $v) {
783 if (!empty($v['value']) && $this->isPublic($v, $publicOnly)) {
789 if (!$publicOnly && isset($v['public_flag']) && $v['public_flag'] != 'public') {
790 echo $this->Html->tag('span',
791 $this->autoLinkProf($v['value']),
793 'class' => 'publicFlagBg',
797 echo $this->Html->tag('span',
798 __('[Private]', true),
800 'class' => 'publicFlag publicFlagBg',
804 echo $this->Html->tag('span',
805 $this->autoLinkProf($v['value'])
813 if ($this->profile_type['is_multi'] && $disp_add_link) {
814 echo $this->Html->div('editLink', $this->Html->link(
815 __('Add Column', true),
817 'action' => 'add_milti_profiles',
819 '/profile_id:'.$profile['id']
825 $tableId = 'TableProfileId'. $profile['id'];
826 echo '<table id="'.$tableId.'">';
827 if (isset($profile['ProfileTable'])) {
828 $this->disp_th4profile_tables($profile['ProfileTable'], $tableId);
830 if (!empty($profile['CharactersHasProfile'])) {
831 $this->disp_value_td4characters_has_profiles($profile['CharactersHasProfile'], $publicOnly, $profile['profile_type']);
833 if (intval($table_blank) > 0) {
834 $this->disp_blank_td4profile_tables($profile['ProfileTable'], intval($table_blank));
840 if ($disp_add_link) {
841 $link = $this->Html->link(
844 'action' => 'add_milti_profiles',
846 '/profile_id:'.$profile['id']
849 if (isset($profile['CharactersHasProfile'][0]) && !empty($profile['CharactersHasProfile'][0]['character_id'])) {
850 $link .= " ".$this->Html->link(
853 'controller' => 'characters_has_profiles',
854 'action' => 'delete',
856 'character_id:'.$profile['CharactersHasProfile'][0]['character_id'],
859 sprintf(__('Are you sure you want to clear the data of %s?', true), $profile['name'])
862 echo $this->Html->div(
871 function set_form_value($profile_selects, $characters_has_profile, $isProfileDefault = false)
875 if ($this->profile_type['is_select'] || $this->profile_type['is_radio'] || $this->profile_type['is_checkbox']) {
876 return $this->set_form_value_select($profile_selects, $characters_has_profile, $isProfileDefault);
877 } elseif ($this->profile_type['is_table']) {
878 return $this->set_form_value_table($characters_has_profile);
880 // return $profile_selects;
881 return $this->set_form_value_profile($profile_selects, $characters_has_profile);
887 /* profile_select_id->profile_idで抽出 */
888 function set_form_value_select($profile_selects, $characters_has_profile, $isProfileDefault = false)
890 if (isset($characters_has_profile[0]['value'])) {
892 'value' => $characters_has_profile[0]['value'],
894 if (isset($characters_has_profile[0]['public_flag'])) {
895 $selected['public_flag'] = $characters_has_profile[0]['public_flag'];
897 if (isset($characters_has_profile[0]['link_value'])) {
898 $selected['link_value'] = $characters_has_profile[0]['link_value'];
911 function set_form_value_table($profile_selects, $characters_has_profile)
915 /* postからprofile_select_id->profile_idで抽出 */
916 function get_selected_profile($profile_select, $characters_has_profile, $isProfileDefault = false)
919 'profile_select_id' => $profile_select['id'],
920 'profile_id' => $profile_select['profile_id'],
923 if (!empty($isProfileDefault)) {
925 $profile['value'] = $profile_select['value'];
928 foreach ($characters_has_profile as $v) {
929 if (Set::contains($v, $profile)) {
938 function isPublic($profile, $publicOnly = true)
940 if ($publicOnly && !CorePlus::check_public_flag($profile)) {
947 function autoLinkProf($value)
954 $patterns = array("/\&/", "/\%/", "/\+/", "/\-/");
955 $replacements = array("&", "%", "+", "-");
956 $value = preg_replace($patterns, $replacements, $value);
958 return $this->Text->autoLinkUrls(
961 'target' => '_blank',
968 /* ProfileTableを横並びに表示(行単位) */
969 function dispTableBySideways($profile, $key_name = 'title', $option = array())
971 $option = array_merge(array(
978 'add_column' => array(),
979 'form_options' => array(),
980 'tr_options' => array(),
981 'td_options' => array(),
984 if (!isset($profile['ProfileTable']) || empty($profile['ProfileTable'])) {
985 if (isset($option['add_column']) && empty($option['add_column'])) {
990 if (!empty($option['add_column'])) {
991 $add_profile = array(
993 'profile_id' => $profile['Profile']['id'],
995 'tablekey_name' => '',
998 'ProfileTableStatic' => array(),
1000 if (isset($option['add_column']['data']) && isset($add_profile[$key_name])) {
1001 $add_profile[$key_name] = $option['add_column']['data'];
1003 if (isset($option['add_column']['place']) && $option['add_column']['place'] == 'top') {
1004 array_unshift($profile['ProfileTable'], $add_profile);
1006 array_push($profile['ProfileTable'], $add_profile);
1010 $rows = count($profile['ProfileTable']);
1011 if (!empty($option['header'])) {
1012 $tds = $this->Html->tag('th', $option['header'], array('style' => 'width:65px;'));
1017 for ($i=0; $i<$rows;$i++) {
1018 if (!isset($profile['ProfileTable'][$i][$key_name])) {
1019 $profile['ProfileTable'][$i][$key_name] = null;
1022 if ($option['type'] == 'form') {
1023 $tabindex = $option['tabindex']['start'] + $option['tabindex']['gap'] * $i;
1024 $form_options = array_merge(
1027 'value' => $profile['ProfileTable'][$i][$key_name],
1029 'tabindex' => $tabindex,
1031 $option['form_options']
1034 $content = $this->Form->input(
1035 'ProfileTable.'.$profile['ProfileTable'][$i]['id'].'.'.$key_name,
1038 $option['td_options'] = array_merge($option['td_options'], array('escape' => false));
1040 if (isset($option['add_column']['place']) &&
1041 (($option['add_column']['place'] == 'top' && $i == 0) ||
1042 ($option['add_column']['place'] != 'top' && $i == $rows - 1))) {
1043 $content = __('Add', true);
1045 $content = $profile['ProfileTable'][$i][$key_name];
1049 $tds .= $this->Html->tag('td', $content, $option['td_options']);
1052 return $this->Html->tag('tr', $tds, $option['tr_options']);
1056 /* 一定の文字数で複数行に折り返すtruncate
1059 * @param array $options is for truncate()
1061 function multi_truncate($text, $length = 20, $rows = 3, $options = array())
1073 $replace_pairs = array(
1081 $text = strtr($text, $replace_pairs);
1084 $Sanitize = CorePlus::set_behavoir('SanitizePlus');
1085 $text = $Sanitize->restore_html($this->model(), $text);
1087 $text = trim($text);
1089 if (mb_strlen($text) < $length) {
1096 for ($i = 1; $i <= $rows; $i++) {
1103 if (!empty($last_row)) {
1104 $text = substr_replace($text, '', 0, strlen($last_row));
1108 $text_len = mb_strlen($text);
1110 if ($text_len < $length) {
1111 $result[$i] = $text;
1113 $result[$i] = $this->Text->truncate($text, mb_strlen(mb_substr($text, 0, $length)), $options);
1118 $result[$i] = mb_substr($text, 0, $length);
1121 $last_row = $result[$i];
1122 $result[$i] = strip_tags($result[$i]);
1126 $result[$i] = $Sanitize->escapeTags($this->model(), $result[$i]);
1129 $text = implode("<br />\n", $result);