6 class ProfiledispHelper extends Helper {
12 var $i18n_profile_types = array();
14 var $profile_type = array();
16 var $character_has_profile_num = 0;
17 var $character_has_profile_cols = 0;
22 * profile_typeの設定をview表示形式に変換
24 function get_i18n_profile_type($profile_type, $profile_types)
26 if (empty($profile_type)) {
30 if (empty($this->i18n_profile_types)) {
31 $this->i18n_profile_types = $this->set_profile_type($profile_types);
34 return $this->i18n_profile_types[$profile_type];
37 * profile_typeの選択プルダウン出力
40 function create_profile_type_select($profile_types = array(), $fieldName = 'profile_type', $options = array('type' => 'select'))
42 if (!isset($options['type'])) {
43 $options['type'] = 'select';
45 if (!isset($options['options'])) {
46 $options['options'] = array();
48 $options['options'] = $this->set_profile_type($profile_types, $options['options']);
50 return $this->Form->input($fieldName, $options);
52 /* profile_typeの設定を、key->value(多言語化対応)に変換 */
53 function set_profile_type($profile_types = array(), $options = array())
55 if (!empty($options)) {
56 $this->i18n_profile_types = $options;
59 if (empty($profile_types)) {
60 App::import('Model', 'Profile');
61 $Profile = new ProfileModel;
62 $profile_types = $Profile->profile_type;
65 foreach ($profile_types as $k => $v) {
67 $this->i18n_profile_types[$v] = __('input', true);
68 } elseif($v == 'textarea') {
69 $this->i18n_profile_types[$v] = __('textarea', true);
70 } elseif($v == 'select') {
71 $this->i18n_profile_types[$v] = __('select', true);
72 } elseif($v == 'radio') {
73 $this->i18n_profile_types[$v] = __('radio', true);
74 } elseif($v == 'checkbox') {
75 $this->i18n_profile_types[$v] = __('checkbox', true);
76 } elseif($v == 'm-input') {
77 $this->i18n_profile_types[$v] = __('multi input', true);
78 } elseif($v == 'table') {
79 $this->i18n_profile_types[$v] = __('table', true);
80 } elseif($v == 's-table') {
81 $this->i18n_profile_types[$v] = __('static table', true);
83 $this->i18n_profile_types[$v] = $v;
87 return $this->i18n_profile_types;
90 /* profileの設定をフォームで出力 */
91 function disp_form4profile($profile, $label = false, $option = array())
93 if ($profile['profile_type'] == 'textarea') {
94 $option['type'] = 'textarea';
96 $option['type'] = 'text';
99 if (!CorePlus::is_valid($profile, 'CharactersHasProfile.0.value')) {
100 $profile['CharactersHasProfile'][0]['value'] = null;
103 foreach ($profile['CharactersHasProfile'] as $v) {
104 echo $this->_get_profile_tag($profile['id'], $v['value'], $label, $option);
105 $this->character_has_profile_num++;
108 if ($this->profile_type['is_multi']) {
109 for ($i=0;$i<2;$i++) {
110 echo $this->_get_profile_tag($profile['id'], null, false, $option);
111 $this->character_has_profile_num++;
115 function _get_profile_tag($profile_id, $value = null, $label = false, $option = array())
117 if (empty($profile_id)) {
121 $name1 = sprintf('CharactersHasProfile.%s.value', $this->character_has_profile_num);
122 $name2 = sprintf('CharactersHasProfile.%s.profile_id', $this->character_has_profile_num);
123 $option = array_merge(array(
130 $this->Form->input($name1, $option).
131 $this->Form->input($name2, array(
133 'value' => $profile_id,
135 if ($option['type'] == 'textarea') {
136 $name3 = sprintf('CharactersHasProfile.%s.is_textarea', $this->character_has_profile_num);
137 $profile_tag .= $this->Form->input($name3, array(
146 /* profile_selectsの設定を出力 */
147 function disp4profile_selects($profile_selects, $option = array())
149 foreach ($profile_selects as $k => $v) {
150 $options[stripcslashes($v['value'])] = stripcslashes($v['value']);
152 $option = array_merge(
155 'options' => $options,
160 $profile_select_tag =
161 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.value', $option).
162 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_id', array(
164 'value' => $profile_selects[0]['profile_id'],
166 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_select_id', array(
168 'value' => $profile_selects[0]['id'],
170 echo $profile_select_tag;
171 $this->character_has_profile_num++;
175 /* profile_selectsの設定をプルダウンで出力 */
176 function disp_select4profile_selects($profile_selects, $characters_has_profile = array(), $option = array(), $label = false, $legend = false)
178 if (empty($profile_selects)) {
182 $selected = $this->set_form_value($profile_selects, $characters_has_profile);
184 $option = array_merge(
189 'selected' => $selected['value'],
194 $this->disp4profile_selects($profile_selects, $option);
197 /* profile_selectsの設定をラジオボタンで出力 */
198 function disp_radio4profile_selects($profile_selects, $characters_has_profile = array(), $label = false, $legend = false)
200 if (empty($profile_selects)) {
204 $selected = $this->set_form_value($profile_selects, $characters_has_profile);
205 if ($selected['value']) {
206 $selected_value = $selected['value'];
208 $first = reset($profile_selects);
209 $selected_value = $first['value'];
214 'value' => $selected_value,
218 'class' => 'input radio inline'
222 return $this->disp4profile_selects($profile_selects, $option);
226 /* profile_selectsの設定をチェックボックスで出力 */
227 function disp_checkbox4profile_selects($profile_selects, $characters_has_profile = array(), $label = false, $legend = false)
229 if (empty($profile_selects)) {
233 foreach($profile_selects as $k => $v) {
238 $profile_select[0] = $v;
239 $has_profile[0] = $this->get_selected_profile($v, $characters_has_profile);
240 $this->disp_select4profile_selects(
244 'multiple' => 'checkbox',
248 'class' => 'input checkbox inline'
255 /* profile_tablesの設定からtableHeadersを出力 */
256 function disp_th4profile_tables($profile_tables, $tableId = null, $tr_options = array(), $th_options = array())
258 if (empty($profile_tables)) {
263 $style_options = array();
265 foreach ($profile_tables as $k => $v) {
266 $values[$k] = $v['title'];
269 $key = '#'.$tableId.' td.column-' . $i;
270 $style_options[$key] = array('width' => $v['width']."px");
271 $key = '#'.$tableId.' td.column-' . $i. ' input';
272 $style_options[$key] = array('width' => $v['width']."px");
277 if (!empty($style_options)) {
278 echo '<style type="text/css"><!--'."\n";
279 foreach($style_options as $k => $v) {
281 echo $this->Html->style($v);
287 $table_header = $this->Html->tableHeaders(
293 $table_header = '<thead>'.$table_header.'</thead>';
298 /* characters_has_profilesの設定からtableCellsを出力 */
299 function disp_td4characters_has_profiles($characters_has_profiles, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
301 if (empty($characters_has_profiles)) {
304 if (isset($characters_has_profiles[0]['ProfileTableStatic'])) {
305 $statics = $characters_has_profiles[0]['ProfileTableStatic'];
309 foreach ($characters_has_profiles as $k => $v) {
313 $values[$k] = $v['value'];
317 $table_cells = $this->Html->tableCells($values, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
322 /* characters_has_profileからtable td出力 */
323 function disp_tds4characters_has_profiles($characters_has_profile, $type = 'view', $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
327 $profiles[$i] = array();
329 foreach($characters_has_profile as $k => $v) {
330 if (is_null($profile_id) && CorePlus::is_valid($v, 'profile_id')) {
331 $profile_id = $v['profile_id'];
333 if (!CorePlus::is_valid($v, 'profile_id')) {
334 if (!is_null($profile_id) && !CorePlus::is_valid($v, 'profile_id')) {
335 $v['profile_id'] = $profile_id;
341 if (!CorePlus::is_valid($v, 'profile_table_id')) {
342 if (!isset($ProfileTable)) {
343 App::import('Model', 'ProfileTable');
344 $ProfileTable = new ProfileTable;
346 $prof_table_ids = $ProfileTable->find('list', array(
347 'ProfileTable.profile_id' => $profile_id,
348 'fields' => array('ProfileTable.id'),
349 'order' => 'ProfileTable.sort_order'
352 if (!empty($prof_table_ids)) {
353 $v['profile_table_id'] = current(array_slice($prof_table_ids, $profile_num+1, 1));
356 $v['profile_table_id'] = null;
362 $v['id'] = $v['profile_table_id'];
364 if (isset($profiles[$i][$v['profile_table_id']])) {
367 $profiles[$i][$v['profile_table_id']] = $v;
373 foreach($profiles as $k => $v) {
374 if ($type == 'form') {
375 $tds = $this->disp_form4profile_tables($v, null, null, true);
377 $tds = $this->disp_value4profile_tables($v, null, null, true);
380 $this->character_has_profile_cols = 0;
382 $this->disp_td4characters_has_profiles($tds, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
386 /* characters_has_profileからvalue出力 */
387 function disp_value_td4characters_has_profiles($characters_has_profile)
389 $this->disp_tds4characters_has_profiles($characters_has_profile, 'view', null, null, true);
392 /* characters_has_profileからtdフォーム出力 */
393 function disp_form_td4characters_has_profiles($characters_has_profile)
395 $this->disp_tds4characters_has_profiles($characters_has_profile, 'form', null, null, true);
398 /* profile_tablesの設定からView表示を出力 */
399 function disp_value4profile_tables($profile_tables, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
401 if (empty($profile_tables)) {
406 foreach ($profile_tables as $k => $v) {
407 if (!Set::check($v, 'value')) {
410 $tds[] = $v['value'];
412 $this->disp_td4characters_has_profiles($tds, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
415 /* profile_tablesの設定から入力フォームを出力 */
416 function disp_form4profile_tables($profile_tables, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
418 if (empty($profile_tables)) {
421 $first = reset($profile_tables);
422 if (isset($first['ProfileTableStatic'])) {
423 $statics = $first['ProfileTableStatic'];
428 foreach ($profile_tables as $k => $v) {
429 if (!Set::check($v, 'profile_id')) {
432 if (!Set::check($v, 'id')) {
433 if (Set::check($v, 'profile_table_id')) {
434 $v['id'] = $v['profile_table_id'];
440 if (!Set::check($v, 'value')) {
444 if ($i == 0 && (isset($statics[$this->character_has_profile_cols]) || isset($v['profile_table_static_id']))) {
445 $value = isset($v['profile_table_static_id']) ? $v['value']: $statics[$this->character_has_profile_cols]['title'];
446 $form = '<span class="staticHead">'.$value.'</span>'.
447 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.value', array(
452 $form = $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.value', array(
455 'value' => $v['value'],
459 if (isset($v['profile_table_static_id'])) {
460 $profile_table_static_id = $v['profile_table_static_id'];
461 } elseif (isset($profile_tables[0]['ProfileTableStatic'][$this->character_has_profile_cols]['id'])) {
462 $profile_table_static_id = $profile_tables[0]['ProfileTableStatic'][$this->character_has_profile_cols]['id'];
464 $profile_table_static_id = null;
469 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_id', array(
471 'value' => $v['profile_id'],
473 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_table_id', array(
477 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_table_static_id', array(
479 'value' => $profile_table_static_id,
481 $this->character_has_profile_num++;
484 $this->character_has_profile_cols++;
486 $this->disp_td4characters_has_profiles($forms, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
489 /* profile_tablesの設定からブランクのtableCellsを出力 */
490 function disp_blank_td4profile_tables($profile_tables, $num = 2, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
492 if (empty($profile_tables)) {
496 $blank = array_fill(0, count($profile_tables), $this->Html->div('blank', " "));
497 for ($i=0; $i<$num; $i++) {
498 $this->disp_td4characters_has_profiles($blank, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
503 function set_profile_type4view($profile)
505 $this->profile_type = array(
506 'is_subsetting' => false,
507 'is_select' => false,
509 'is_checkbox' => false,
514 if ($profile['profile_type'] == 'select' || $profile['profile_type'] == 'radio' || $profile['profile_type'] == 'checkbox' || $profile['profile_type'] == 'table' ) {
515 $this->profile_type['is_subsetting'] = true;
517 if ($profile['profile_type'] == 'select') {
518 $this->profile_type['is_select'] = true;
520 if ($profile['profile_type'] == 'radio') {
521 $this->profile_type['is_radio'] = true;
523 if ($profile['profile_type'] == 'checkbox') {
524 $this->profile_type['is_checkbox'] = true;
526 if ($profile['profile_type'] == 'table' || $profile['profile_type'] == 's-table') {
527 $this->profile_type['is_table'] = true;
529 if ($profile['profile_type'] == 'm-input') {
530 $this->profile_type['is_multi'] = true;
534 /* profile_typeの設定に応じてフォーム表示
535 * set_profile_type4view($profile)チェック済み前提。
537 function disp_forms4profile_type($profile, $form_num = 2, $table_blank = 2, $disp_add_link = false, $character_id = null)
539 if (!isset($profile['CharactersHasProfile'])) {
540 $profile['CharactersHasProfile'] = array();
543 if ($this->profile_type['is_select'] || $this->profile_type['is_radio'] || $this->profile_type['is_checkbox']) {
544 if ($this->profile_type['is_select']) {
545 $this->disp_select4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile']);
546 } elseif ($this->profile_type['is_radio']) {
547 $this->disp_radio4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile']);
548 } elseif ($this->profile_type['is_checkbox']) {
549 $this->disp_checkbox4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile']);
551 } elseif ($this->profile_type['is_table']) {
552 if (isset($profile['id'])) {
553 $tableId = 'TableProfileId'. $profile['id'];
555 $tableId = 'TableProfileId'. $profile['Profile']['id'];
557 echo '<table id="'.$tableId.'">';
558 $this->disp_th4profile_tables($profile['ProfileTable'], $tableId);
560 if (!empty($profile['CharactersHasProfile'])) {
561 $this->disp_form_td4characters_has_profiles($profile['CharactersHasProfile']);
564 if (intval($form_num) > 0
565 && ((isset ($profile['Profile']['profile_type']) && $profile['Profile']['profile_type'] != 's-table') || (isset($profile['profile_type']) && $profile['profile_type'] != 's-table'))
566 || empty($profile['CharactersHasProfile'])) {
567 for ($i=0; $i<$form_num; $i++) {
568 $this->disp_form4profile_tables($profile['ProfileTable'], null, null, true);
570 $this->character_has_profile_cols = 0;
572 if (intval($table_blank) > 0 && $profile['profile_type'] != 's-table') {
573 $this->disp_blank_td4profile_tables($profile['ProfileTable'], intval($table_blank));
577 if ($disp_add_link) {
578 $link = $this->Html->link(
579 __('Edit Data', true),
581 'action' => 'add_milti_profiles',
583 '/profile_id:'.$profile['id']
586 __('If some data have been changed, you should save before click it. OK?', true)
588 if (!empty($profile['CharactersHasProfile'][0]['character_id'])) {
589 $link .= " ".$this->Html->link(
592 'controller' => 'characters_has_profiles',
593 'action' => 'delete',
595 'character_id:'.$profile['CharactersHasProfile'][0]['character_id'],
598 sprintf(__('Are you sure you want to clear the data of %s?', true), $profile['name'])
601 echo $this->Html->div(
607 $this->disp_form4profile($profile);
611 /* characters_has_profilesの設定に応じてView表示
612 * set_profile_type4view($profile)チェック済み前提。
613 * $profileのkeyはprofilesのkey_name
615 function disp_values4characters_has_profiles($profile, $table_blank = 2, $disp_add_link = false, $character_id = null)
617 if (!isset($profile['CharactersHasProfile']) && !$this->profile_type['is_table']) {
618 $profile['CharactersHasProfile'] = array();
621 if (!$this->profile_type['is_table']) {
623 foreach ($profile['CharactersHasProfile'] as $v) {
624 if (!empty($v['value'])) {
629 echo $this->Html->tag('span', $v['value']);
634 $tableId = 'TableProfileId'. $profile['id'];
635 echo '<table id="'.$tableId.'">';
636 if (isset($profile['ProfileTable'])) {
637 $this->disp_th4profile_tables($profile['ProfileTable'], $tableId);
639 if (!empty($profile['CharactersHasProfile'])) {
640 $this->disp_value_td4characters_has_profiles($profile['CharactersHasProfile']);
642 if (intval($table_blank) > 0) {
643 $this->disp_blank_td4profile_tables($profile['ProfileTable'], intval($table_blank));
649 if ($disp_add_link) {
650 $link = $this->Html->link(
651 __('Edit Data', true),
653 'action' => 'add_milti_profiles',
655 '/profile_id:'.$profile['id']
658 if (!empty($profile['CharactersHasProfile'][0]['character_id'])) {
659 $link .= " ".$this->Html->link(
662 'controller' => 'characters_has_profiles',
663 'action' => 'delete',
665 'character_id:'.$profile['CharactersHasProfile'][0]['character_id'],
668 sprintf(__('Are you sure you want to clear the data of %s?', true), $profile['name'])
671 echo $this->Html->div(
680 function set_form_value($profile_selects, $characters_has_profile)
684 if ($this->profile_type['is_select'] || $this->profile_type['is_radio'] || $this->profile_type['is_checkbox']) {
685 return $this->set_form_value_select($profile_selects, $characters_has_profile);
686 } elseif ($this->profile_type['is_table']) {
687 return $this->set_form_value_table($characters_has_profile);
689 return $this->set_form_value_profile($profile_selects, $characters_has_profile);
695 /* profile_select_id->profile_idで抽出 */
696 function set_form_value_select($profile_selects, $characters_has_profile)
698 if (isset($characters_has_profile[0]['id'])) {
700 'value' => $characters_has_profile[0]['value'],
701 'public_flag' => $characters_has_profile[0]['public_flag'],
702 'link_value' => $characters_has_profile[0]['link_value'],
715 function set_form_value_table($profile_selects, $characters_has_profile)
719 /* postからprofile_select_id->profile_idで抽出 */
720 function get_selected_profile($profile_select, $characters_has_profile)
723 'profile_select_id' => $profile_select['id'],
724 'profile_id' => $profile_select['profile_id'],
725 'value' => $profile_select['value'],
728 foreach ($characters_has_profile as $v) {
729 if (Set::contains($v, $profile)) {