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,
139 /* profile_selectsの設定を出力 */
140 function disp4profile_selects($profile_selects, $option = array())
142 foreach ($profile_selects as $k => $v) {
143 $options[stripcslashes($v['value'])] = stripcslashes($v['value']);
145 $option = array_merge(
148 'options' => $options,
153 $profile_select_tag =
154 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.value', $option).
155 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_id', array(
157 'value' => $profile_selects[0]['profile_id'],
159 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_select_id', array(
161 'value' => $profile_selects[0]['id'],
163 echo $profile_select_tag;
164 $this->character_has_profile_num++;
168 /* profile_selectsの設定をプルダウンで出力 */
169 function disp_select4profile_selects($profile_selects, $characters_has_profile = array(), $option = array(), $label = false, $legend = false)
171 if (empty($profile_selects)) {
175 $selected = $this->set_form_value($profile_selects, $characters_has_profile);
177 $option = array_merge(
182 'selected' => $selected['value'],
187 $this->disp4profile_selects($profile_selects, $option);
190 /* profile_selectsの設定をラジオボタンで出力 */
191 function disp_radio4profile_selects($profile_selects, $characters_has_profile = array(), $label = false, $legend = false)
193 if (empty($profile_selects)) {
197 $selected = $this->set_form_value($profile_selects, $characters_has_profile);
198 if ($selected['value']) {
199 $selected_value = $selected['value'];
201 $first = reset($profile_selects);
202 $selected_value = $first['value'];
207 'value' => $selected_value,
211 'class' => 'input radio inline'
215 return $this->disp4profile_selects($profile_selects, $option);
219 /* profile_selectsの設定をチェックボックスで出力 */
220 function disp_checkbox4profile_selects($profile_selects, $characters_has_profile = array(), $label = false, $legend = false)
222 if (empty($profile_selects)) {
226 foreach($profile_selects as $k => $v) {
231 $profile_select[0] = $v;
232 $has_profile[0] = $this->get_selected_profile($v, $characters_has_profile);
233 $this->disp_select4profile_selects(
237 'multiple' => 'checkbox',
241 'class' => 'input checkbox inline'
248 /* profile_tablesの設定からtableHeadersを出力 */
249 function disp_th4profile_tables($profile_tables, $tableId = null, $tr_options = array(), $th_options = array())
251 if (empty($profile_tables)) {
256 $style_options = array();
258 foreach ($profile_tables as $k => $v) {
259 $values[$k] = $v['title'];
262 $key = '#'.$tableId.' td.column-' . $i;
263 $style_options[$key] = array('width' => $v['width']."px");
264 $key = '#'.$tableId.' td.column-' . $i. ' input';
265 $style_options[$key] = array('width' => $v['width']."px");
270 if (!empty($style_options)) {
271 echo '<style type="text/css"><!--'."\n";
272 foreach($style_options as $k => $v) {
274 echo $this->Html->style($v);
280 $table_header = $this->Html->tableHeaders(
286 $table_header = '<thead>'.$table_header.'</thead>';
291 /* characters_has_profilesの設定からtableCellsを出力 */
292 function disp_td4characters_has_profiles($characters_has_profiles, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
294 if (empty($characters_has_profiles)) {
297 if (isset($characters_has_profiles[0]['ProfileTableStatic'])) {
298 $statics = $characters_has_profiles[0]['ProfileTableStatic'];
302 foreach ($characters_has_profiles as $k => $v) {
306 $values[$k] = $v['value'];
310 $table_cells = $this->Html->tableCells($values, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
315 /* characters_has_profileからtable td出力 */
316 function disp_tds4characters_has_profiles($characters_has_profile, $type = 'view', $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
320 $profiles[$i] = array();
322 foreach($characters_has_profile as $k => $v) {
323 if (is_null($profile_id) && CorePlus::is_valid($v, 'profile_id')) {
324 $profile_id = $v['profile_id'];
326 if (!CorePlus::is_valid($v, 'profile_id')) {
327 if (!is_null($profile_id) && !CorePlus::is_valid($v, 'profile_id')) {
328 $v['profile_id'] = $profile_id;
334 if (!CorePlus::is_valid($v, 'profile_table_id')) {
335 if (!isset($ProfileTable)) {
336 App::import('Model', 'ProfileTable');
337 $ProfileTable = new ProfileTable;
339 $prof_table_ids = $ProfileTable->find('list', array(
340 'ProfileTable.profile_id' => $profile_id,
341 'fields' => array('ProfileTable.id'),
342 'order' => 'ProfileTable.sort_order'
345 if (!empty($prof_table_ids)) {
346 $v['profile_table_id'] = current(array_slice($prof_table_ids, $profile_num+1, 1));
354 $v['id'] = $v['profile_table_id'];
356 if (isset($profiles[$i][$v['profile_table_id']])) {
359 $profiles[$i][$v['profile_table_id']] = $v;
365 foreach($profiles as $k => $v) {
366 if ($type == 'form') {
367 $tds = $this->disp_form4profile_tables($v, null, null, true);
369 $tds = $this->disp_value4profile_tables($v, null, null, true);
373 $this->disp_td4characters_has_profiles($tds, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
377 /* characters_has_profileからvalue出力 */
378 function disp_value_td4characters_has_profiles($characters_has_profile)
380 $this->disp_tds4characters_has_profiles($characters_has_profile, 'view', null, null, true);
383 /* characters_has_profileからtdフォーム出力 */
384 function disp_form_td4characters_has_profiles($characters_has_profile)
386 $this->disp_tds4characters_has_profiles($characters_has_profile, 'form', null, null, true);
389 /* profile_tablesの設定からView表示を出力 */
390 function disp_value4profile_tables($profile_tables, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
392 if (empty($profile_tables)) {
397 foreach ($profile_tables as $k => $v) {
398 if (!Set::check($v, 'value')) {
401 $tds[] = $v['value'];
403 $this->disp_td4characters_has_profiles($tds, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
406 /* profile_tablesの設定から入力フォームを出力 */
407 function disp_form4profile_tables($profile_tables, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
409 if (empty($profile_tables)) {
412 $first = reset($profile_tables);
413 if (isset($first['ProfileTableStatic'])) {
414 $statics = $first['ProfileTableStatic'];
419 foreach ($profile_tables as $k => $v) {
420 if (!Set::check($v, 'profile_id')) {
423 if (!Set::check($v, 'id')) {
424 if (Set::check($v, 'profile_table_id')) {
425 $v['id'] = $v['profile_table_id'];
431 if (!Set::check($v, 'value')) {
435 if ($i == 0 && (isset($statics[$this->character_has_profile_cols]) || isset($v['profile_table_static_id']))) {
436 $value = isset($v['profile_table_static_id']) ? $v['value']: $statics[$this->character_has_profile_cols]['title'];
437 $form = '<span class="staticHead">'.$value.'</span>'.
438 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.value', array(
443 $form = $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.value', array(
446 'value' => $v['value'],
450 if (isset($v['profile_table_static_id'])) {
451 $profile_table_static_id = $v['profile_table_static_id'];
452 } elseif (isset($profile_tables[0]['ProfileTableStatic'][$this->character_has_profile_cols]['id'])) {
453 $profile_table_static_id = $profile_tables[0]['ProfileTableStatic'][$this->character_has_profile_cols]['id'];
455 $profile_table_static_id = null;
460 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_id', array(
462 'value' => $v['profile_id'],
464 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_table_id', array(
468 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_table_static_id', array(
470 'value' => $profile_table_static_id,
472 $this->character_has_profile_num++;
475 $this->character_has_profile_cols++;
477 $this->disp_td4characters_has_profiles($forms, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
480 /* profile_tablesの設定からブランクのtableCellsを出力 */
481 function disp_blank_td4profile_tables($profile_tables, $num = 2, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
483 if (empty($profile_tables)) {
487 $blank = array_fill(0, count($profile_tables), $this->Html->div('blank', " "));
489 for ($i=0; $i<$num; $i++) {
490 $this->disp_td4characters_has_profiles($blank, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
495 function set_profile_type4view($profile)
497 $this->profile_type = array(
498 'is_subsetting' => false,
499 'is_select' => false,
501 'is_checkbox' => false,
506 if ($profile['profile_type'] == 'select' || $profile['profile_type'] == 'radio' || $profile['profile_type'] == 'checkbox' || $profile['profile_type'] == 'table' ) {
507 $this->profile_type['is_subsetting'] = true;
509 if ($profile['profile_type'] == 'select') {
510 $this->profile_type['is_select'] = true;
512 if ($profile['profile_type'] == 'radio') {
513 $this->profile_type['is_radio'] = true;
515 if ($profile['profile_type'] == 'checkbox') {
516 $this->profile_type['is_checkbox'] = true;
518 if ($profile['profile_type'] == 'table' || $profile['profile_type'] == 's-table') {
519 $this->profile_type['is_table'] = true;
521 if ($profile['profile_type'] == 'm-input') {
522 $this->profile_type['is_multi'] = true;
526 /* profile_typeの設定に応じてフォーム表示
527 * set_profile_type4view($profile)チェック済み前提。
529 function disp_forms4profile_type($profile, $form_num = 2, $table_blank = 2, $disp_add_link = false, $character_id = null)
531 if (!isset($profile['CharactersHasProfile'])) {
532 $profile['CharactersHasProfile'] = array();
535 if ($this->profile_type['is_select'] || $this->profile_type['is_radio'] || $this->profile_type['is_checkbox']) {
536 if ($this->profile_type['is_select']) {
537 $this->disp_select4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile']);
538 } elseif ($this->profile_type['is_radio']) {
539 $this->disp_radio4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile']);
540 } elseif ($this->profile_type['is_checkbox']) {
541 $this->disp_checkbox4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile']);
543 } elseif ($this->profile_type['is_table']) {
544 if (isset($profile['id'])) {
545 $tableId = 'TableProfileId'. $profile['id'];
547 $tableId = 'TableProfileId'. $profile['Profile']['id'];
549 echo '<table id="'.$tableId.'">';
550 $this->disp_th4profile_tables($profile['ProfileTable'], $tableId);
552 if (!empty($profile['CharactersHasProfile'])) {
553 $this->disp_form_td4characters_has_profiles($profile['CharactersHasProfile']);
556 if (intval($form_num) > 0
557 && ((isset ($profile['Profile']['profile_type']) && $profile['Profile']['profile_type'] != 's-table') || (isset($profile['profile_type']) && $profile['profile_type'] != 's-table'))
558 || empty($profile['CharactersHasProfile'])) {
559 for ($i=0; $i<$form_num; $i++) {
560 $this->disp_form4profile_tables($profile['ProfileTable'], null, null, true);
563 if (intval($table_blank) > 0 && $profile['profile_type'] != 's-table') {
564 $this->disp_blank_td4profile_tables($profile['ProfileTable'], intval($table_blank));
568 if ($disp_add_link) {
569 echo $this->Html->div(
572 __('Edit Data', true),
574 'action' => 'add_milti_profiles',
576 '/profile_id:'.$profile['id']
579 __('If some data have been changed, you should save before click it. OK?', true)
584 $this->disp_form4profile($profile);
588 /* characters_has_profilesの設定に応じてView表示
589 * set_profile_type4view($profile)チェック済み前提。
590 * $profileのkeyはprofilesのkey_name
592 function disp_values4characters_has_profiles($profile, $table_blank = 2, $disp_add_link = false, $character_id = null)
594 if (!isset($profile['CharactersHasProfile']) && !$this->profile_type['is_table']) {
595 $profile['CharactersHasProfile'] = array();
598 if (!$this->profile_type['is_table']) {
600 foreach ($profile['CharactersHasProfile'] as $v) {
601 if (!empty($v['value'])) {
606 echo $this->Html->tag('span', $v['value']);
611 $tableId = 'TableProfileId'. $profile['id'];
612 echo '<table id="'.$tableId.'">';
613 if (isset($profile['ProfileTable'])) {
614 $this->disp_th4profile_tables($profile['ProfileTable'], $tableId);
616 if (!empty($profile['CharactersHasProfile'])) {
617 $this->disp_value_td4characters_has_profiles($profile['CharactersHasProfile']);
619 if (intval($table_blank) > 0) {
620 $this->disp_blank_td4profile_tables($profile['ProfileTable'], intval($table_blank));
626 if ($disp_add_link) {
627 echo $this->Html->div(
630 __('Edit Data', true),
632 'action' => 'add_milti_profiles',
634 '/profile_id:'.$profile['id'],
643 function set_form_value($profile_selects, $characters_has_profile)
647 if ($this->profile_type['is_select'] || $this->profile_type['is_radio'] || $this->profile_type['is_checkbox']) {
648 return $this->set_form_value_select($profile_selects, $characters_has_profile);
649 } elseif ($this->profile_type['is_table']) {
650 return $this->set_form_value_table($characters_has_profile);
652 return $this->set_form_value_profile($profile_selects, $characters_has_profile);
658 /* profile_select_id->profile_idで抽出 */
659 function set_form_value_select($profile_selects, $characters_has_profile)
661 if (isset($characters_has_profile[0]['id'])) {
663 'value' => $characters_has_profile[0]['value'],
664 'public_flag' => $characters_has_profile[0]['public_flag'],
665 'link_value' => $characters_has_profile[0]['link_value'],
678 function set_form_value_table($profile_selects, $characters_has_profile)
682 /* postからprofile_select_id->profile_idで抽出 */
683 function get_selected_profile($profile_select, $characters_has_profile)
686 'profile_select_id' => $profile_select['id'],
687 'profile_id' => $profile_select['profile_id'],
688 'value' => $profile_select['value'],
691 foreach ($characters_has_profile as $v) {
692 if (Set::contains($v, $profile)) {