6 class ProfiledispHelper extends Helper {
12 var $i18n_profile_types = array();
14 var $profile_type = array();
16 var $character_has_profile_num = 0;
21 * profile_typeの設定をview表示形式に変換
23 function get_i18n_profile_type($profile_type, $profile_types)
25 if (empty($profile_type)) {
29 if (empty($this->i18n_profile_types)) {
30 $this->i18n_profile_types = $this->set_profile_type($profile_types);
33 return $this->i18n_profile_types[$profile_type];
36 * profile_typeの選択プルダウン出力
39 function create_profile_type_select($profile_types = array(), $fieldName = 'profile_type', $options = array('type' => 'select'))
41 if (!isset($options['type'])) {
42 $options['type'] = 'select';
44 if (!isset($options['options'])) {
45 $options['options'] = array();
47 $options['options'] = $this->set_profile_type($profile_types, $options['options']);
49 return $this->Form->input($fieldName, $options);
51 /* profile_typeの設定を、key->value(多言語化対応)に変換 */
52 function set_profile_type($profile_types = array(), $options = array())
54 if (!empty($options)) {
55 $this->i18n_profile_types = $options;
58 if (empty($profile_types)) {
59 App::import('Model', 'Profile');
60 $Profile = new ProfileModel;
61 $profile_types = $Profile->profile_type;
64 foreach ($profile_types as $k => $v) {
66 $this->i18n_profile_types[$v] = __('input', true);
67 } elseif($v == 'textarea') {
68 $this->i18n_profile_types[$v] = __('textarea', true);
69 } elseif($v == 'select') {
70 $this->i18n_profile_types[$v] = __('select', true);
71 } elseif($v == 'radio') {
72 $this->i18n_profile_types[$v] = __('radio', true);
73 } elseif($v == 'checkbox') {
74 $this->i18n_profile_types[$v] = __('checkbox', true);
75 } elseif($v == 'm-input') {
76 $this->i18n_profile_types[$v] = __('multi input', true);
77 } elseif($v == 'm-select') {
78 $this->i18n_profile_types[$v] = __('multi select', true);
79 } elseif($v == 'm-radio') {
80 $this->i18n_profile_types[$v] = __('multi radio', true);
81 } elseif($v == 'table') {
82 $this->i18n_profile_types[$v] = __('table', true);
84 $this->i18n_profile_types[$v] = $v;
88 return $this->i18n_profile_types;
91 /* profileの設定をフォームで出力 */
92 function disp_form4profile($profile, $label = false, $option = array())
94 if ($profile['profile_type'] == 'textarea') {
95 $option['type'] = 'textarea';
97 $option['type'] = 'text';
100 if (!CorePlus::is_valid($profile, 'CharactersHasProfile.0.value')) {
101 $profile['CharactersHasProfile'][0]['value'] = null;
104 foreach ($profile['CharactersHasProfile'] as $v) {
105 $option = array_merge(array(
107 'value' => $v['value'],
112 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.value', $option).
113 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_id', array(
115 'value' => $profile['id'],
119 $this->character_has_profile_num++;
120 if (!$this->profile_type['is_multi']) {
126 /* profile_selectsの設定を出力 */
127 function disp4profile_selects($profile_selects, $option = array())
129 foreach ($profile_selects as $k => $v) {
130 $options[stripcslashes($v['value'])] = stripcslashes($v['value']);
132 $option = array_merge(
135 'options' => $options,
140 $profile_select_tag =
141 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.value', $option).
142 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_id', array(
144 'value' => $profile_selects[0]['profile_id'],
146 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_select_id', array(
148 'value' => $profile_selects[0]['id'],
150 echo $profile_select_tag;
151 $this->character_has_profile_num++;
155 /* profile_selectsの設定をプルダウンで出力 */
156 function disp_select4profile_selects($profile_selects, $characters_has_profile = array(), $option = array(), $label = false, $legend = false)
158 if (empty($profile_selects)) {
162 $selected = $this->set_form_value($profile_selects, $characters_has_profile);
164 $option = array_merge(
169 'selected' => $selected['value'],
174 $this->disp4profile_selects($profile_selects, $option);
177 /* profile_selectsの設定をラジオボタンで出力 */
178 function disp_radio4profile_selects($profile_selects, $characters_has_profile = array(), $label = false, $legend = false)
180 if (empty($profile_selects)) {
184 $selected = $this->set_form_value($profile_selects, $characters_has_profile);
185 if ($selected['value']) {
186 $selected_value = $selected['value'];
188 $first = reset($profile_selects);
189 $selected_value = $first['value'];
194 'value' => $selected_value,
198 'class' => 'input radio inline'
202 return $this->disp4profile_selects($profile_selects, $option);
206 /* profile_selectsの設定をチェックボックスで出力 */
207 function disp_checkbox4profile_selects($profile_selects, $characters_has_profile = array(), $label = false, $legend = false)
209 if (empty($profile_selects)) {
213 foreach($profile_selects as $k => $v) {
218 $profile_select[0] = $v;
219 $has_profile[0] = $this->get_selected_profile($v, $characters_has_profile);
220 $this->disp_select4profile_selects(
224 'multiple' => 'checkbox',
228 'class' => 'input checkbox inline'
235 /* profile_tablesの設定からtableHeadersを出力 */
236 function disp_th4profile_tables($profile_tables, $tableId = null, $tr_options = array(), $th_options = array())
238 if (empty($profile_tables)) {
243 $style_options = array();
245 foreach ($profile_tables as $k => $v) {
246 $values[$k] = $v['title'];
249 $key = '#'.$tableId.' td.column-' . $i;
250 $style_options[$key] = array('width' => $v['width']."px");
251 $key = '#'.$tableId.' td.column-' . $i. ' input';
252 $input_width = $v['width']-8;
253 $style_options[$key] = array('width' => $input_width."px");
258 if (!empty($style_options)) {
259 echo '<style type="text/css"><!--';
260 foreach($style_options as $k => $v) {
262 echo $this->Html->style($v);
268 $table_header = $this->Html->tableHeaders(
274 $table_header = '<thead>'.$table_header.'</thead>';
279 /* characters_has_profilesの設定からtableCellsを出力 */
280 function disp_td4characters_has_profiles($characters_has_profiles, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
282 if (empty($characters_has_profiles)) {
287 foreach ($characters_has_profiles as $k => $v) {
291 $values[$k] = $v['value'];
295 $table_cells = $this->Html->tableCells($values, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
300 /* characters_has_profileからtable td出力 */
301 function disp_tds4characters_has_profiles($characters_has_profile, $type = 'view', $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
305 $profiles[$i] = array();
307 foreach($characters_has_profile as $k => $v) {
308 if (is_null($profile_id) && CorePlus::is_valid($v, 'profile_id')) {
309 $profile_id = $v['profile_id'];
312 if (!CorePlus::is_valid($v, 'profile_id')) {
313 if (!is_null($profile_id) && !CorePlus::is_valid($v, 'profile_id')) {
314 $v['profile_id'] = $profile_id;
321 if (!CorePlus::is_valid($v, 'profile_table_id')) {
322 if (!isset($ProfileTable)) {
323 App::import('Model', 'ProfileTable');
324 $ProfileTable = new ProfileTable;
326 $prof_table_ids = $ProfileTable->find('list', array(
327 'ProfileTable.profile_id' => $profile_id,
328 'fields' => array('ProfileTable.id'),
329 'order' => 'ProfileTable.sort_order'
332 if (!empty($prof_table_ids)) {
333 $v['profile_table_id'] = current(array_slice($prof_table_ids, $profile_num+1, 1));
341 $v['id'] = $v['profile_table_id'];
343 if (isset($profiles[$i][$v['profile_table_id']])) {
346 $profiles[$i][$v['profile_table_id']] = $v;
352 foreach($profiles as $k => $v) {
353 if ($type == 'form') {
354 $tds = $this->disp_form4profile_tables($v, null, null, true);
356 $tds = $this->disp_value4profile_tables($v, null, null, true);
360 $this->disp_td4characters_has_profiles($tds, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
364 /* characters_has_profileからvalue出力 */
365 function disp_value_td4characters_has_profiles($characters_has_profile)
367 $this->disp_tds4characters_has_profiles($characters_has_profile, 'view', null, null, true);
370 /* characters_has_profileからtdフォーム出力 */
371 function disp_form_td4characters_has_profiles($characters_has_profile)
373 $this->disp_tds4characters_has_profiles($characters_has_profile, 'form', null, null, true);
376 /* profile_tablesの設定からView表示を出力 */
377 function disp_value4profile_tables($profile_tables, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
379 if (empty($profile_tables)) {
384 foreach ($profile_tables as $k => $v) {
385 if (!Set::check($v, 'value')) {
388 $tds[] = $v['value'];
390 $this->disp_td4characters_has_profiles($tds, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
393 /* profile_tablesの設定から入力フォームを出力 */
394 function disp_form4profile_tables($profile_tables, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
396 if (empty($profile_tables)) {
402 foreach ($profile_tables as $k => $v) {
403 if (!Set::check($v, 'profile_id')) {
406 if (!Set::check($v, 'id')) {
407 if (Set::check($v, 'profile_table_id')) {
408 $v['id'] = $v['profile_table_id'];
414 if (!Set::check($v, 'value')) {
419 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.value', array(
422 'value' => $v['value'],
424 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_id', array(
426 'value' => $v['profile_id'],
428 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_table_id', array(
432 $this->character_has_profile_num++;
435 $this->disp_td4characters_has_profiles($forms, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
438 /* profile_tablesの設定からブランクのtableCellsを出力 */
439 function disp_blank_td4profile_tables($profile_tables, $num = 2, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
441 if (empty($profile_tables)) {
445 $blank = array_fill(0, count($profile_tables), $this->Html->div('blank', " "));
447 for ($i=0; $i<$num; $i++) {
448 $this->disp_td4characters_has_profiles($blank, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
453 function set_profile_type4view($profile)
455 $this->profile_type = array(
456 'is_subsetting' => false,
457 'is_select' => false,
459 'is_checkbox' => false,
464 if ($profile['profile_type'] == 'select' || $profile['profile_type'] == 'm-select' || $profile['profile_type'] == 'radio' || $profile['profile_type'] == 'm-radio' || $profile['profile_type'] == 'checkbox' || $profile['profile_type'] == 'table' ) {
465 $this->profile_type['is_subsetting'] = true;
467 if ($profile['profile_type'] == 'select' || $profile['profile_type'] == 'm-select') {
468 $this->profile_type['is_select'] = true;
470 if ($profile['profile_type'] == 'radio' || $profile['profile_type'] == 'm-radio') {
471 $this->profile_type['is_radio'] = true;
473 if ($profile['profile_type'] == 'checkbox') {
474 $this->profile_type['is_checkbox'] = true;
476 if ($profile['profile_type'] == 'table') {
477 $this->profile_type['is_table'] = true;
479 if ($profile['profile_type'] == 'm-select' || $profile['profile_type'] == 'm-input') {
480 $this->profile_type['is_multi'] = true;
484 /* profile_typeの設定に応じてフォーム表示
485 * set_profile_type4view($profile)チェック済み前提。
487 function disp_forms4profile_type($profile, $form_num = 2, $table_blank = 2)
489 if (!isset($profile['CharactersHasProfile'])) {
490 $profile['CharactersHasProfile'] = array();
493 if ($this->profile_type['is_select'] || $this->profile_type['is_radio'] || $this->profile_type['is_checkbox']) {
494 if ($this->profile_type['is_select']) {
495 $this->disp_select4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile']);
496 } elseif ($this->profile_type['is_radio']) {
497 $this->disp_radio4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile']);
498 } elseif ($this->profile_type['is_checkbox']) {
499 $this->disp_checkbox4profile_selects($profile['ProfileSelect'], $profile['CharactersHasProfile']);
501 } elseif ($this->profile_type['is_table']) {
502 if (isset($profile['id'])) {
503 $tableId = 'TableProfileId'. $profile['id'];
505 $tableId = 'TableProfileId'. $profile['Profile']['id'];
507 echo '<table id="'.$tableId.'">';
508 $this->disp_th4profile_tables($profile['ProfileTable'], $tableId);
511 if (!empty($profile['CharactersHasProfile'])) {
512 $this->disp_form_td4characters_has_profiles($profile['CharactersHasProfile']);
515 if (empty($profile['CharacterHasProfile'])) {
516 if (intval($form_num) > 0) {
517 for ($i=0; $i<$form_num; $i++) {
518 $this->disp_form4profile_tables($profile['ProfileTable'], null, null, true);
521 if (intval($table_blank) > 0) {
522 $this->disp_blank_td4profile_tables($profile['ProfileTable'], intval($table_blank));
528 $this->disp_form4profile($profile);
532 /* characters_has_profilesの設定に応じてView表示
533 * set_profile_type4view($profile)チェック済み前提。
534 * $profileのkeyはprofilesのkey_name
536 function disp_values4characters_has_profiles($profile, $table_blank = 2, $disp_add_link = false, $character_id = null)
538 if (!isset($profile['CharactersHasProfile']) && !$this->profile_type['is_table']) {
539 $profile['CharactersHasProfile'] = array();
542 if (!$this->profile_type['is_table']) {
544 foreach ($profile['CharactersHasProfile'] as $v) {
548 if (!empty($v['value'])) {
554 $tableId = 'TableProfileId'. $profile['id'];
555 echo '<table id="'.$tableId.'">';
556 $this->disp_th4profile_tables($profile['ProfileTable'], $tableId);
558 if (!empty($profile['CharactersHasProfile'])) {
559 $this->disp_value_td4characters_has_profiles($profile['CharactersHasProfile']);
561 if (intval($table_blank) > 0) {
562 $this->disp_blank_td4profile_tables($profile['ProfileTable'], intval($table_blank));
567 if ($disp_add_link) {
568 echo $this->Html->div(
571 __('Add Data', true),
573 'action' => 'add_milti_profiles',
575 '/profile_id:'.$profile['id'],
584 function set_form_value($profile_selects, $characters_has_profile)
588 if ($this->profile_type['is_select'] || $this->profile_type['is_radio'] || $this->profile_type['is_checkbox']) {
589 return $this->set_form_value_select($profile_selects, $characters_has_profile);
590 } elseif ($this->profile_type['is_table']) {
591 return $this->set_form_value_table($characters_has_profile);
593 return $this->set_form_value_profile($profile_selects, $characters_has_profile);
599 /* profile_select_id->profile_idで抽出 */
600 function set_form_value_select($profile_selects, $characters_has_profile)
602 if (isset($characters_has_profile[0]['id'])) {
604 'value' => $characters_has_profile[0]['value'],
605 'public_flag' => $characters_has_profile[0]['public_flag'],
606 'link_value' => $characters_has_profile[0]['link_value'],
619 function set_form_value_table($profile_selects, $characters_has_profile)
623 /* postからprofile_select_id->profile_idで抽出 */
624 function get_selected_profile($profile_select, $characters_has_profile)
627 'profile_select_id' => $profile_select['id'],
628 'profile_id' => $profile_select['profile_id'],
629 'value' => $profile_select['value'],
632 foreach ($characters_has_profile as $v) {
633 if (Set::contains($v, $profile)) {