OSDN Git Service

public_flagの共通設定化と作成/編集画面でプルダウン表示
authorCake <cake_67@users.sourceforge.jp>
Mon, 18 Jan 2010 15:02:53 +0000 (00:02 +0900)
committerCake <cake_67@users.sourceforge.jp>
Mon, 18 Jan 2010 15:04:49 +0000 (00:04 +0900)
app/controllers/app_controller.php
app/controllers/characters_controller.php
app/controllers/systems_controller.php
app/controllers/users_controller.php
app/views/characters/add.ctp
app/views/characters/edit.ctp
app/views/helpers/selectpublic.php [new file with mode: 0644]
app/views/systems/admin_add.ctp
app/views/systems/admin_edit.ctp

index 66c2cd1..c06cad9 100644 (file)
@@ -37,6 +37,7 @@ class AppController extends Controller
                'Html',
                'Form',
                'Javascript',
+               'Selectpublic',
                'Token'
        );
 
@@ -126,6 +127,18 @@ class AppController extends Controller
                }
 
        }
+
+       /* public_flag設定をview用にセット */
+       function set_public_flag4view()
+       {
+               $model_public_flags = $this->get_public_flag();
+
+               $this->set('public_flags', $model_public_flags);
+       }
+       function get_public_flag()
+       {
+               return $this->{$this->modelClass}->public_flag;
+       }
 }
 
 // AppControllerを携帯とPCで振り分け
index e200555..91e304c 100644 (file)
@@ -61,6 +61,8 @@ class CharactersController extends AppController {
                $systems = $this->Character->System->find('list');
                $users = $this->Character->User->find('list');
                $this->set(compact('systems', 'users'));
+
+               $this->set_public_flag4view();
        }
 
        function edit($id = null) {
@@ -82,6 +84,8 @@ class CharactersController extends AppController {
                $systems = $this->Character->System->find('list');
                $users = $this->Character->User->find('list');
                $this->set(compact('systems','users'));
+
+               $this->set_public_flag4view();
        }
 
        function delete($id = null) {
index 49ea6bc..088ed72 100644 (file)
@@ -65,6 +65,8 @@ class SystemsController extends AppController {
                                $this->Session->setFlash(__('The System could not be saved. Please, try again.', true));
                        }
                }
+
+               $this->set_public_flag4view();
        }
 
        function admin_edit($id = null) {
@@ -88,6 +90,8 @@ class SystemsController extends AppController {
 
                        $this->data['System'] = $this->_restore_html_system($this->data['System']);
                }
+
+               $this->set_public_flag4view();
        }
 
        function admin_delete($id = null) {
index 8dc9586..4914c00 100644 (file)
@@ -25,7 +25,6 @@ class UsersController extends ModuleController {
                $this->unsetData('auto', true);
 
                // 認証なしアクセス可
-               $this->AuthPlus->allow('login');
                $this->AuthPlus->allow('add'); //todo:メール認証etc
                $this->AuthPlus->allow('logout');
                $this->AuthPlus->allow('to_login');
index 78c3852..c143cd1 100644 (file)
@@ -25,7 +25,7 @@
                        'label' => __('Status', true)
                )
        );
-       echo $form->input('public_flag', array(
+       echo $selectpublic->create_publicflag_select($public_flags, 'public_flag', array(
                        'label' => __('Public Flag', true)
                )
        );
index 2468025..a3e8231 100644 (file)
@@ -24,7 +24,7 @@
                        'label' => __('Status', true)
                )
        );
-       echo $form->input('public_flag', array(
+       echo $selectpublic->create_publicflag_select($public_flags, 'public_flag', array(
                        'label' => __('Public Flag', true)
                )
        );
diff --git a/app/views/helpers/selectpublic.php b/app/views/helpers/selectpublic.php
new file mode 100644 (file)
index 0000000..cdbd289
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+class SelectpublicHelper extends Helper {
+       var $helpers = array('Form');
+
+       var $default_public_flags = array('public_flag', 'private');
+       /**
+        * public_flagの選択プルダウン出力
+        * i18n対応
+        *
+        * @param array $public_flags
+        * @return String
+        */
+       function create_publicflag_select($public_flags = array(), $fieldName = 'public_flag', $options = array('type' => 'select')) {
+
+               if (empty($public_flags)) {
+                       $public_flags = $this->default_public_flags;
+               }
+
+               if (!isset($options['type'])) {
+                       $options['type'] = 'select';
+               }
+               if (!isset($options['options'])) {
+                       $options['options'] = array();
+               }
+
+               foreach ($public_flags as $k => $v) {
+                       if ($v == 'public') {
+                               $options['options'][$v] = __('Public', true);
+                       } elseif($v == 'private') {
+                               $options['options'][$v] = __('Private', true);
+                       } else {
+                               $options['options'][$v] = $v;
+                       }
+               }
+
+               return $this->Form->input($fieldName, $options);
+       }
+
+}
+
+
index 25c0b54..cea355a 100644 (file)
                                'selected' => true
                        )
                );
-               echo $form->input('public_flag', array(
-                               'type' => 'select',
-                               'label' => __('Public', true),
-                               'options' => array(
-                                       'public' => __('Public', true),
-                                       'private' => __('Private', true),
-                               ),
+               echo $selectpublic->create_publicflag_select($public_flags, 'public_flag', array(
+                               'label' => __('Public Flag', true),
                                'selected' => 'public',
                        )
                );
index 7cf6488..cb0d058 100644 (file)
                                'selected' => true
                        )
                );
-               echo $form->input('public_flag', array(
-                               'type' => 'select',
-                               'label' => __('Public', true),
-                               'options' => array(
-                                       'public' => __('Public', true),
-                                       'private' => __('Private', true),
-                               ),
-                               'selected' => 'public',
+               echo $selectpublic->create_publicflag_select($public_flags, 'public_flag', array(
+                               'label' => __('Public Flag', true)
                        )
                );
                echo $form->input('detail', array(