OSDN Git Service

Merge branch 'master' of cake_67@git.sourceforge.jp:/gitroot/trpgtools-onweb/cake...
[trpgtools-onweb/cake-frame.git] / app / views / helpers / profiledisp.php
1 <?php
2 /* 
3  * プロフィール表示用Helper
4  * i18n対応
5  */
6 class ProfiledispHelper extends Helper {
7         var $helpers = array(
8                 'Html',
9                 'Form',
10         );
11
12         var $i18n_profile_types = array();
13
14         var $profile_type = array();
15
16         var $character_has_profile_num = 0;
17         var $character_has_profile_cols = 0;
18
19         var $form_id = 0;
20
21         /**
22          * profile_typeの設定をview表示形式に変換
23          */
24         function get_i18n_profile_type($profile_type, $profile_types)
25         {
26                 if (empty($profile_type)) {
27                         return null;
28                 }
29
30                 if (empty($this->i18n_profile_types)) {
31                         $this->i18n_profile_types = $this->set_profile_type($profile_types);
32                 }
33
34                 return $this->i18n_profile_types[$profile_type];
35         }
36         /**
37          * profile_typeの選択プルダウン出力
38          * i18n対応
39          */
40         function create_profile_type_select($profile_types = array(), $fieldName = 'profile_type', $options = array('type' => 'select'))
41         {
42                 if (!isset($options['type'])) {
43                         $options['type'] = 'select';
44                 }
45                 if (!isset($options['options'])) {
46                         $options['options'] = array();
47                 }
48                 $options['options'] = $this->set_profile_type($profile_types, $options['options']);
49
50                 return $this->Form->input($fieldName, $options);
51         }
52         /* profile_typeの設定を、key->value(多言語化対応)に変換 */
53         function set_profile_type($profile_types = array(), $options = array())
54         {
55                 if (!empty($options)) {
56                         $this->i18n_profile_types = $options;
57                 }
58
59                 if (empty($profile_types)) {
60                         App::import('Model', 'Profile');
61                         $Profile = new ProfileModel;
62                         $profile_types = $Profile->profile_type;
63                 }
64
65                 foreach ($profile_types as $k => $v) {
66                         if ($v == 'input') {
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);
82                         } else {
83                                 $this->i18n_profile_types[$v] = $v;
84                         }
85                 }
86
87                 return $this->i18n_profile_types;
88         }
89
90         /* profileの設定をフォームで出力 */
91         function disp_form4profile($profile, $label = false, $option = array())
92         {
93                 if ($profile['profile_type'] == 'textarea') {
94                         $option['type'] = 'textarea';
95                 } else {
96                         $option['type'] = 'text';
97                 }
98
99                 if (!CorePlus::is_valid($profile, 'CharactersHasProfile.0.value')) {
100                         $profile['CharactersHasProfile'][0]['value'] = null;
101                 }
102
103                 foreach ($profile['CharactersHasProfile'] as $v) {
104                         echo $this->_get_profile_tag($profile['id'], $v['value'], $label, $option);
105                         $this->character_has_profile_num++;
106                 }
107
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++;
112                         }
113                 }
114         }
115         function _get_profile_tag($profile_id, $value = null, $label = false, $option = array())
116         {
117                 if (empty($profile_id)) {
118                         return null;
119                 }
120
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(
124                         'label' => $label,
125                         'value' => $value,
126                         ), $option
127                 );
128
129                 $profile_tag = 
130                         $this->Form->input($name1, $option).
131                         $this->Form->input($name2, array(
132                                 'type' => 'hidden',
133                                 'value' => $profile_id,
134                         ));
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(
138                                 'type' => 'hidden',
139                                 'value' => 1,
140                         ));
141                 }
142
143                 return $profile_tag;
144         }
145
146         /* profile_selectsの設定を出力 */
147         function disp4profile_selects($profile_selects, $option = array())
148         {
149                 foreach ($profile_selects as $k => $v) {
150                         $options[stripcslashes($v['value'])] = stripcslashes($v['value']);
151                 }
152                 $option = array_merge(
153                         array(
154                         'type' => 'select',
155                         'options' => $options,
156                         ),
157                         $option
158                 );
159
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(
163                                 'type' => 'hidden',
164                                 'value' => $profile_selects[0]['profile_id'],
165                         )).
166                          $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_select_id', array(
167                                 'type' => 'hidden',
168                                 'value' => $profile_selects[0]['id'],
169                         ));
170                 echo $profile_select_tag;
171                 $this->character_has_profile_num++;
172         }
173
174
175         /* profile_selectsの設定をプルダウンで出力 */
176         function disp_select4profile_selects($profile_selects, $characters_has_profile = array(), $option = array(), $label = false, $legend = false)
177         {
178                 if (empty($profile_selects)) {
179                         return null;
180                 }
181
182                 $selected = $this->set_form_value($profile_selects, $characters_has_profile);
183
184                 $option = array_merge(
185                         array(
186                                 'type' => 'select',
187                                 'label' => $label,
188                                 'legend' => $legend,
189                                 'selected' => $selected['value'],
190                         ),
191                         $option
192                 );
193
194                 $this->disp4profile_selects($profile_selects, $option);
195         }
196
197         /* profile_selectsの設定をラジオボタンで出力 */
198         function disp_radio4profile_selects($profile_selects, $characters_has_profile = array(), $label = false, $legend = false)
199         {
200                 if (empty($profile_selects)) {
201                         return null;
202                 }
203
204                 $selected = $this->set_form_value($profile_selects, $characters_has_profile);
205                 if ($selected['value']) {
206                         $selected_value = $selected['value'];
207                 } else {
208                         $first = reset($profile_selects);
209                         $selected_value = $first['value'];
210                 }
211
212                 $option = array(
213                         'type' => 'radio',
214                         'value' => $selected_value,
215                         'label' => $label,
216                         'legend' => $legend,
217                         'div' => array(
218                                 'class' => 'input radio inline'
219                         ),
220                 );
221
222                 return $this->disp4profile_selects($profile_selects, $option);
223
224         }
225
226         /* profile_selectsの設定をチェックボックスで出力 */
227         function disp_checkbox4profile_selects($profile_selects, $characters_has_profile = array(), $label = false, $legend = false)
228         {
229                 if (empty($profile_selects)) {
230                         return null;
231                 }
232
233                 foreach($profile_selects as $k => $v) {
234                         if (empty($v)) {
235                                 continue;
236                         }
237
238                         $profile_select[0] = $v;
239                         $has_profile[0] = $this->get_selected_profile($v, $characters_has_profile);
240                         $this->disp_select4profile_selects(
241                                 $profile_select, 
242                                 $has_profile,
243                                 array(
244                                         'multiple' => 'checkbox',
245                                         'label' => $label,
246                                         'legend' => $legend,
247                                         'div' => array(
248                                                 'class' => 'input checkbox inline'
249                                         ),
250                                 )
251                         );
252                 }
253         }
254
255         /* profile_tablesの設定からtableHeadersを出力 */
256         function disp_th4profile_tables($profile_tables, $tableId = null, $tr_options = array(), $th_options = array())
257         {
258                 if (empty($profile_tables)) {
259                         return null;
260                 }
261
262                 $values = array();
263                 $style_options = array();
264                 $i = 1;
265                 foreach ($profile_tables as $k => $v) {
266                         $values[$k] = $v['title'];
267
268                         if ($v['width']) {
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");
273                         }
274                         $i++;
275                 }
276
277                 if (!empty($style_options)) {
278                         echo '<style type="text/css"><!--'."\n";
279                         foreach($style_options as $k => $v) {
280                                 echo $k. " {\n";
281                                 echo $this->Html->style($v);
282                                 echo "}\n";
283                         }
284                         echo '--></style>';
285                 }
286
287                 $table_header = $this->Html->tableHeaders(
288                         $values,
289                         $tr_options,
290                         $th_options
291                 );
292
293                 $table_header = '<thead>'.$table_header.'</thead>';
294
295                 echo $table_header;
296         }
297
298         /* characters_has_profilesの設定からtableCellsを出力 */
299         function disp_td4characters_has_profiles($characters_has_profiles, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
300         {
301                 if (empty($characters_has_profiles)) {
302                         return null;
303                 }
304                 if (isset($characters_has_profiles[0]['ProfileTableStatic'])) {
305                         $statics = $characters_has_profiles[0]['ProfileTableStatic'];
306                 }
307
308                 $values = array();
309                 foreach ($characters_has_profiles as $k => $v) {
310                         if (is_string($v)) {
311                                 $values[$k] = $v;
312                         } else {
313                                 $values[$k] = $v['value'];
314                         }
315                 }
316
317                 $table_cells = $this->Html->tableCells($values, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
318
319                 echo $table_cells;
320         }
321
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)
324         {
325                 $i = 1;
326                 $profile_num = 0;
327                 $profiles[$i] = array();
328                 $profile_id = null;
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'];
332                         }
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;
336                                 } else {
337                                         continue;
338                                 }
339                         }
340
341                         if (!CorePlus::is_valid($v, 'profile_table_id')) {
342                                 if (!isset($ProfileTable)) {
343                                         App::import('Model', 'ProfileTable');
344                                         $ProfileTable = new ProfileTable;
345                                 }
346                                 $prof_table_ids = $ProfileTable->find('list', array(
347                                         'ProfileTable.profile_id' => $profile_id,
348                                         'fields' => array('ProfileTable.id'),
349                                         'order' => 'ProfileTable.sort_order'
350                                 ));
351
352                                 if (!empty($prof_table_ids)) {
353                                         $v['profile_table_id'] = current(array_slice($prof_table_ids, $profile_num+1, 1));
354                                         $v['value'] = null;
355                                 } else {
356                                         $v['profile_table_id'] = null;
357                                         $v['value'] = null;
358                                         continue;
359                                 }
360                         }
361
362                         $v['id'] = $v['profile_table_id'];
363
364                         if (isset($profiles[$i][$v['profile_table_id']])) {
365                                 $i++;
366                         }
367                         $profiles[$i][$v['profile_table_id']] = $v;
368
369                         $profile_num++;
370                 }
371                 $forms = array();
372
373                 foreach($profiles as $k => $v) {
374                         if ($type == 'form') {
375                                 $tds = $this->disp_form4profile_tables($v, null, null, true);
376                         } else {
377                                 $tds = $this->disp_value4profile_tables($v, null, null, true);
378                         }
379                 }
380                 $this->character_has_profile_cols = 0;
381
382                 $this->disp_td4characters_has_profiles($tds, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
383         }
384
385
386         /* characters_has_profileからvalue出力 */
387         function disp_value_td4characters_has_profiles($characters_has_profile)
388         {
389                 $this->disp_tds4characters_has_profiles($characters_has_profile, 'view', null, null, true);
390         }
391
392         /* characters_has_profileからtdフォーム出力 */
393         function disp_form_td4characters_has_profiles($characters_has_profile)
394         {
395                 $this->disp_tds4characters_has_profiles($characters_has_profile, 'form', null, null, true);
396         }
397
398         /* profile_tablesの設定からView表示を出力 */
399         function disp_value4profile_tables($profile_tables, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
400         {
401                 if (empty($profile_tables)) {
402                         return null;
403                 }
404
405                 $tds = array();
406                 foreach ($profile_tables as $k => $v) {
407                         if (!Set::check($v, 'value')) {
408                                 $v['value'] = null;
409                         }
410                         $tds[] = $v['value'];
411                 }
412                 $this->disp_td4characters_has_profiles($tds, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
413         }
414
415         /* profile_tablesの設定から入力フォームを出力 */
416         function disp_form4profile_tables($profile_tables, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
417         {
418                 if (empty($profile_tables)) {
419                         return null;
420                 }
421                 $first = reset($profile_tables);
422                 if (isset($first['ProfileTableStatic'])) {
423                         $statics = $first['ProfileTableStatic'];
424                 }
425
426                 $forms = array();
427                 $i = 0;
428                 foreach ($profile_tables as $k => $v) {
429                         if (!Set::check($v, 'profile_id')) {
430                                 continue;
431                         }
432                         if (!Set::check($v, 'id')) {
433                                 if (Set::check($v, 'profile_table_id')) {
434                                         $v['id'] = $v['profile_table_id'];
435                                 } else {
436                                         continue;
437                                 }
438                         }
439
440                         if (!Set::check($v, 'value')) {
441                                 $v['value'] = null;
442                         }
443
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(
448                                                 'type' => 'hidden',
449                                                 'value' => $value,
450                                         ));
451                         } else {
452                                 $form = $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.value', array(
453                                         'type' => 'text',
454                                         'label' => false,
455                                         'value' => $v['value'],
456                                 ));
457                         }
458
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'];
463                         } else {
464                                 $profile_table_static_id = null;
465                         }
466
467                         $forms[] = 
468                                 $form.
469                                 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_id', array(
470                                         'type' => 'hidden',
471                                         'value' => $v['profile_id'],
472                                 )).
473                                 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_table_id', array(
474                                         'type' => 'hidden',
475                                         'value' => $v['id'],
476                                 )).
477                                 $this->Form->input('CharactersHasProfile.'.$this->character_has_profile_num.'.profile_table_static_id', array(
478                                         'type' => 'hidden',
479                                         'value' => $profile_table_static_id,
480                                 ));
481                         $this->character_has_profile_num++;
482                         $i++;
483                 }
484                 $this->character_has_profile_cols++;
485
486                 $this->disp_td4characters_has_profiles($forms, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
487         }
488
489         /* profile_tablesの設定からブランクのtableCellsを出力 */
490         function disp_blank_td4profile_tables($profile_tables, $num = 2, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true)
491         {
492                 if (empty($profile_tables)) {
493                         return null;
494                 }
495
496                 $blank = array_fill(0, count($profile_tables), $this->Html->div('blank', "&nbsp;"));
497                 for ($i=0; $i<$num; $i++) {
498                         $this->disp_td4characters_has_profiles($blank, $oddTrOptions, $evenTrOptions, $useCount, $continueOddEven);
499                 }
500         }
501
502         /* Profile種類を判断 */
503         function set_profile_type4view($profile)
504         {
505                 $this->profile_type = array(
506                         'is_subsetting' => false,
507                         'is_select' => false,
508                         'is_radio' => false,
509                         'is_checkbox' => false,
510                         'is_table' => false,
511                         'is_multi' => false,
512                 );
513
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;
516                 }
517                 if ($profile['profile_type'] == 'select') {
518                         $this->profile_type['is_select'] = true;
519                 }
520                 if ($profile['profile_type'] == 'radio') {
521                         $this->profile_type['is_radio'] = true;
522                 }
523                 if ($profile['profile_type'] == 'checkbox') {
524                         $this->profile_type['is_checkbox'] = true;
525                 }
526                 if ($profile['profile_type'] == 'table' || $profile['profile_type'] == 's-table') {
527                         $this->profile_type['is_table'] = true;
528                 }
529                 if ($profile['profile_type'] == 'm-input') {
530                         $this->profile_type['is_multi'] = true;
531                 }
532         }
533
534         /* profile_typeの設定に応じてフォーム表示
535          * set_profile_type4view($profile)チェック済み前提。
536          */
537         function disp_forms4profile_type($profile, $form_num = 2, $table_blank = 2, $disp_add_link = false, $character_id = null)
538         {
539                 if (!isset($profile['CharactersHasProfile'])) {
540                         $profile['CharactersHasProfile'] = array();
541                 }
542
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']);
550                         }
551                 } elseif ($this->profile_type['is_table']) {
552                         if (isset($profile['id'])) {
553                                 $tableId = 'TableProfileId'. $profile['id'];
554                         } else {
555                                 $tableId = 'TableProfileId'. $profile['Profile']['id'];
556                         }
557                         echo '<table id="'.$tableId.'">';
558                         $this->disp_th4profile_tables($profile['ProfileTable'], $tableId);
559                         echo '<tbody>';
560                         if (!empty($profile['CharactersHasProfile'])) {
561                                 $this->disp_form_td4characters_has_profiles($profile['CharactersHasProfile']);
562
563                         }
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);
569                                 }
570                                 $this->character_has_profile_cols = 0;
571                         }
572                         if (intval($table_blank) > 0 && $profile['profile_type'] != 's-table') {
573                                 $this->disp_blank_td4profile_tables($profile['ProfileTable'], intval($table_blank));
574                         }
575                         echo '</tbody>';
576                         echo '</table>';
577                         if ($disp_add_link) {
578                                 $link = $this->Html->link(
579                                         __('Edit Data', true),
580                                         array(
581                                                 'action' => 'add_milti_profiles',
582                                                 $character_id.
583                                                 '/profile_id:'.$profile['id']
584                                         ),
585                                         null,
586                                         __('If some data have been changed, you should save before click it. OK?', true)
587                                 );
588                                 if (!empty($profile['CharactersHasProfile'][0]['character_id'])) {
589                                         $link .= " ".$this->Html->link(
590                                                 __('Clear', true),
591                                                 array(
592                                                         'controller' => 'characters_has_profiles',
593                                                         'action' => 'delete',
594                                                         $profile['id'],
595                                                         'character_id:'.$profile['CharactersHasProfile'][0]['character_id'],
596                                                 ),
597                                                 null,
598                                                 sprintf(__('Are you sure you want to clear the data of %s?', true), $profile['name'])
599                                         );
600                                 }
601                                 echo $this->Html->div(
602                                         'editLink text', 
603                                         $link
604                                 );
605                         }
606                 } else {
607                         $this->disp_form4profile($profile);
608                 }
609         }
610
611         /* characters_has_profilesの設定に応じてView表示
612          * set_profile_type4view($profile)チェック済み前提。
613          * $profileのkeyはprofilesのkey_name
614          */
615         function disp_values4characters_has_profiles($profile, $table_blank = 2, $disp_add_link = false, $character_id = null)
616         {
617                 if (!isset($profile['CharactersHasProfile']) && !$this->profile_type['is_table']) {
618                         $profile['CharactersHasProfile'] = array();
619                 }
620
621                 if (!$this->profile_type['is_table']) {
622                         $num = 0;
623                         foreach ($profile['CharactersHasProfile'] as $v) {
624                                 if (!empty($v['value'])) {
625                                         if ($num > 0) {
626                                                 echo "&nbsp;";
627                                         }
628
629                                         echo $this->Html->tag('span', $v['value']);
630                                         $num++;
631                                 }
632                         }
633                 } else {
634                         $tableId = 'TableProfileId'. $profile['id'];
635                         echo '<table id="'.$tableId.'">';
636                         if (isset($profile['ProfileTable'])) {
637                                 $this->disp_th4profile_tables($profile['ProfileTable'], $tableId);
638                                 echo '<tbody>';
639                                 if (!empty($profile['CharactersHasProfile'])) {
640                                         $this->disp_value_td4characters_has_profiles($profile['CharactersHasProfile']);
641                                 } else {
642                                         if (intval($table_blank) > 0) {
643                                                 $this->disp_blank_td4profile_tables($profile['ProfileTable'], intval($table_blank));
644                                         }
645                                 }
646                                 echo '</tbody>';
647                         }
648                         echo '</table>';
649                         if ($disp_add_link) {
650                                 $link = $this->Html->link(
651                                         __('Edit Data', true),
652                                         array(
653                                                 'action' => 'add_milti_profiles',
654                                                 $character_id.
655                                                 '/profile_id:'.$profile['id']
656                                         )
657                                 );
658                                 if (!empty($profile['CharactersHasProfile'][0]['character_id'])) {
659                                         $link .= " ".$this->Html->link(
660                                                 __('Clear', true),
661                                                 array(
662                                                         'controller' => 'characters_has_profiles',
663                                                         'action' => 'delete',
664                                                         $profile['id'],
665                                                         'character_id:'.$profile['CharactersHasProfile'][0]['character_id'],
666                                                 ),
667                                                 null,
668                                                 sprintf(__('Are you sure you want to clear the data of %s?', true), $profile['name'])
669                                         );
670                                 }
671                                 echo $this->Html->div(
672                                         'editLink text', 
673                                         $link
674                                 );
675                         }
676                 }
677         }
678
679         /* フォームに値入力 */
680         function set_form_value($profile_selects, $characters_has_profile)
681         {
682                 $this->form_id++;
683
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);
688                 } else {
689                         return $this->set_form_value_profile($profile_selects, $characters_has_profile);
690                 }
691
692         }
693
694         /* profile_select */
695         /* profile_select_id->profile_idで抽出 */
696         function set_form_value_select($profile_selects, $characters_has_profile)
697         {
698                 if (isset($characters_has_profile[0]['id'])) {
699                         $selected = array(
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'],
703                         );
704                 } else {
705                         $selected = array(
706                                 'value' => '',
707                                 'public_flag' => '',
708                                 'link_value' => '',
709                         );
710                 }
711
712                 return $selected;
713         }
714         /* profile_table */
715         function set_form_value_table($profile_selects, $characters_has_profile)
716         {
717         }
718
719         /* postからprofile_select_id->profile_idで抽出 */
720         function get_selected_profile($profile_select, $characters_has_profile)
721         {
722                 $profile = array(
723                         'profile_select_id' => $profile_select['id'],
724                         'profile_id' => $profile_select['profile_id'],
725                         'value' => $profile_select['value'],
726                 );
727
728                 foreach ($characters_has_profile as $v) {
729                         if (Set::contains($v, $profile)) {
730                                 return $v;
731                         }
732                 }
733
734                 return array();
735
736         }
737
738 }
739