]> git.andy128k.dev Git - ipf.git/commitdiff
cleanup auth admin forms
authorAndrey Kutejko <andy128k@gmail.com>
Thu, 9 May 2013 11:09:22 +0000 (14:09 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Thu, 9 May 2013 11:09:22 +0000 (14:09 +0300)
21 files changed:
ipf/admin/media/css/forms.css
ipf/admin/templates/admin/base.html
ipf/auth/forms/widget/permissions.php [deleted file]
ipf/auth/models.yml
ipf/auth/models/Permission.php
ipf/auth/models/Role.php
ipf/auth/models/RolePermission.php
ipf/auth/models/User.php
ipf/auth/models/UserPermission.php
ipf/auth/models/UserRole.php
ipf/form/db/boolean.php
ipf/form/db/manytomany.php
ipf/form/extra/addjs.php [deleted file]
ipf/form/extra/checkgroup.php [deleted file]
ipf/form/extra/widget/checkboxgroupinput.php [deleted file]
ipf/form/extra/widget/checkboxinput.php [deleted file]
ipf/form/field/modelmultiplechoice.php
ipf/form/model.php
ipf/form/widget/checkboxinput.php
ipf/form/widget/selectmultipleinput.php
ipf/form/widget/selectmultipleinputcheckbox.php

index adc124905ed1d56e97ff1a0f1ff35751f1be35f7..dc1c469736de0bb956446d0d87a3f4bc8a199205 100644 (file)
@@ -27,6 +27,9 @@ form ul.radiolist label { float:none; display:inline; }
 form ul.inline { margin-left:0; padding:0; }
 form ul.inline li { float:left; padding-right:7px; }
 
+.checkgroup_master li {list-style: none outside none}
+.checkgroup_master li label {width:auto;float:none}
+
 /* ALIGNED FIELDSETS */
 .aligned label { display:block; padding:0 1em 3px 0; float:left; width:8em; }
 .aligned label.inline { display:inline; float:none; }
index 3c8a35e86dddfc9616639833cbe11df1099c8e32..6b4f810e409e5a6e26bf7721e235d637386731b2 100644 (file)
     <div id="footer"></div>
 </div>
 {block commonjs}
-  {if isset($form) && method_exists($form, 'render_commonjs')}
-    {$form.render_commonjs()|safe}
-  {else}
-    <script type="text/javascript" src="{$ADMIN_MEDIA_URL}js/jquery.js"></script>
-    <script type="text/javascript" src="{$ADMIN_MEDIA_URL}js/jquery-ui.custom.js"></script>
-    <script type="text/javascript" src="{$ADMIN_MEDIA_URL}js/admin.js"></script>
-  {/if}
+  <script type="text/javascript" src="{$ADMIN_MEDIA_URL}js/jquery.js"></script>
+  <script type="text/javascript" src="{$ADMIN_MEDIA_URL}js/jquery-ui.custom.js"></script>
+  <script type="text/javascript" src="{$ADMIN_MEDIA_URL}js/admin.js"></script>
 {/block}
 {block scripts}{/block}
 </body>
diff --git a/ipf/auth/forms/widget/permissions.php b/ipf/auth/forms/widget/permissions.php
deleted file mode 100644 (file)
index 736cbf9..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-
-class IPF_Auth_Forms_Widget_Permissions extends IPF_Form_Extra_Widget_CheckboxGroupInput
-{
-    public function __construct($attrs=array())
-    {
-        if (isset($attrs['choices']))
-            ksort($attrs['choices']);
-       
-        parent::__construct($attrs);
-    }
-}
-
index dd4c3531f6a0ceebdf4b9bb1e9befcc331dc5c6b..e13e4d1085ee297554608ced5654ebe0acc94f9c 100644 (file)
@@ -47,6 +47,7 @@ User:
         type: INNODB
         collate: utf8_unicode_ci
         charset: utf8
+---
 Role:
     tableName: auth_role
     columns:
@@ -63,8 +64,7 @@ Role:
         type: INNODB
         collate: utf8_unicode_ci
         charset: utf8
-
-
+---
 Permission:
     tableName: auth_permission
     columns:
@@ -75,7 +75,7 @@ Permission:
         type: INNODB
         collate: utf8_unicode_ci
         charset: utf8
-
+---
 RolePermission:
     tableName: auth_role_permission
     columns:
@@ -96,7 +96,7 @@ RolePermission:
         type: INNODB
         collate: utf8_unicode_ci
         charset: utf8
-
+---
 UserRole:
     tableName: auth_user_role
     columns:
@@ -117,7 +117,7 @@ UserRole:
         type: INNODB
         collate: utf8_unicode_ci
         charset: utf8
-
+---
 UserPermission:
     tableName: auth_user_permission
     columns:
@@ -138,3 +138,5 @@ UserPermission:
         type: INNODB
         collate: utf8_unicode_ci
         charset: utf8
+---
+
index ea82e6ad4d382290b5d40340b645c401818af135..78b2b0073cdab29c9797b0802ebfbeced85ab2ae 100644 (file)
@@ -7,3 +7,4 @@ class Permission extends BasePermission
         return IPF_Auth_App::GetHumanNameOfPermission($this->name);
     }
 }
+
index 6f6c3e9ee1f571e7669f96402c417a52f58a43c1..e600af9068f548d7a576d3c20daa006b78d35b28 100644 (file)
@@ -8,6 +8,42 @@ class Role extends BaseRole
     }
 }
 
+class IPFAdminRoleForm extends IPF_Form_Model
+{
+    public function add__Permissions__field()
+    {
+        if (!IPF_Auth_App::ArePermissionsEnabled())
+            return;
+
+        $choices = array();
+        foreach (IPF_ORM::getTable('Permission')->findAll() as $o)
+            $choices[$o->__toString()] = $o->id;
+        ksort($choices);
+
+        $field = new IPF_Form_Field_ModelMultipleChoice(array(
+            'required' => false,
+            'label' => 'Permissions',
+            'help_text' => '',
+            'type' => 'manytomany',
+            'editable' => true,
+            'model' => 'Permission',
+            'widget' => 'IPF_Form_Widget_SelectMultipleInputCheckbox',
+            'choices' => $choices,
+            'widget_attrs' => array('class' => 'checkgroup'),
+        ));
+
+        $this->fields['Permissions'] = $field;
+    }
+
+    public function extra_js()
+    {
+        $extra_js = parent::extra_js();
+        if (IPF_Auth_App::ArePermissionsEnabled())
+            $extra_js[] = '<script type="text/javascript" src="'.IPF::get('admin_media_url').'js/extra/checkall.js"></script>';
+        return array_unique($extra_js);
+    }
+}
+
 class AdminRole extends IPF_Admin_Model
 {
     public function list_display()
@@ -35,19 +71,12 @@ class AdminRole extends IPF_Admin_Model
     protected function _getForm($model_obj, $data, $extra)
     {
         $extra['model'] = $model_obj;
-        $extra['checkgroup_fields'] = array(
-            'Permissions' => array('widget'=>'IPF_Auth_Forms_Widget_Permissions'),
-        );
-        return new IPF_Form_Extra_CheckGroup($data, $extra);
-    }
-    
-    protected function _setupForm($form)
-    {
-        IPF_Form_Extra_CheckGroup::SetupForm($form);
+        return new IPFAdminRoleForm($data, $extra);
     }
 
     public function page_title()   { return 'Group'; }
     public function verbose_name() { return 'Group'; }
 }
 
-IPF_Admin_Model::register('Role','AdminRole');
+IPF_Admin_Model::register('Role', 'AdminRole');
+
index 9707d3e39f6e0277b61034f16d870ad3813c4d10..c407a8ceeb39b1ad97b370c2077abca1fce8fe2c 100644 (file)
@@ -1,9 +1,6 @@
 <?php
 
-/**
- * This class has been auto-generated by the IPF ORM Framework
- */
 class RolePermission extends BaseRolePermission
 {
+}
 
-}
\ No newline at end of file
index a09afc4df815e0b64733f6e694afca8ea69b6549..ec2d95ea8d0d9bef087efc2e601b53fdf4c96dbb 100644 (file)
@@ -1,13 +1,13 @@
 <?php
 
-class IPFAuthAdminUserForm extends IPF_Form_Extra_CheckGroup
+class IPFAuthAdminUserForm extends IPF_Form_Model
 {
     function initFields($extra=array())
     {
         parent::initFields($extra);
-        
+
         $this->fields['email']->label = 'E-mail';
-        
+
         $this->fields['is_active']->label    = 'Active';
         $this->fields['is_staff']->label     = 'Staff status';
         $this->fields['is_superuser']->label = 'Superuser status';
@@ -15,20 +15,19 @@ class IPFAuthAdminUserForm extends IPF_Form_Extra_CheckGroup
         $this->fields['is_active']->help_text    = 'Designates whether this user should be treated as active. Unselect this instead of deleting accounts.';
         $this->fields['is_staff']->help_text     = 'Designates whether the user can log into this admin site.';
         $this->fields['is_superuser']->help_text = 'Designates that this user has all permissions without explicitly assigning them.';
-        
+
         $this->fields['username']->help_text = 'Required. 32 characters or less. Alphanumeric characters only (letters, digits and underscores).';        
-        
-        if (!$this->model->id)
-        {
+
+        if (!$this->model->id) {
             unset($this->fields['password']);
-            
+
             $this->fields['password1'] = new IPF_Form_Field_Varchar(array(
                 'label' => 'Password',
                 'required' => true,
                 'max_length' => 32,
                 'widget' => 'IPF_Form_Widget_PasswordInput'
             ));
-            
+
             $this->fields['password2'] = new IPF_Form_Field_Varchar(array(
                 'label' => 'Password (again)',
                 'required' => true,
@@ -36,13 +35,11 @@ class IPFAuthAdminUserForm extends IPF_Form_Extra_CheckGroup
                 'widget' => 'IPF_Form_Widget_PasswordInput',
                 'help_text' => 'Enter the same password as above, for verification.'
             ));
-            
+
             $account = array('username', 'password1', 'password2');
-        }
-        else
-        {
+        } else {
             $this->fields['password']->help_text = "Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."; 
-            
+
             $account = array('username', 'password');
         }
 
@@ -50,14 +47,6 @@ class IPFAuthAdminUserForm extends IPF_Form_Extra_CheckGroup
         if (IPF_Auth_App::ArePermissionsEnabled()) {
             $permissions[] = 'Permissions';
             $permissions[] = 'Roles';
-
-            $this->fields['Roles']->label = 'Groups';
-            $this->fields['Roles']->help_text = 'In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in.';
-
-            parent::SetupForm($this);            
-        } else {
-            unset($this->fields['Permissions']);
-            unset($this->fields['Roles']);
         }
 
         $this->field_groups = array(
@@ -66,24 +55,79 @@ class IPFAuthAdminUserForm extends IPF_Form_Extra_CheckGroup
             array('fields' => $permissions, 'label' => 'Permissions'),
         );
     }
-    
+
+    public function add__Permissions__field()
+    {
+        if (!IPF_Auth_App::ArePermissionsEnabled())
+            return;
+
+        $choices = array();
+        foreach (IPF_ORM::getTable('Permission')->findAll() as $o)
+            $choices[$o->__toString()] = $o->id;
+        ksort($choices);
+
+        $field = new IPF_Form_Field_ModelMultipleChoice(array(
+            'required' => false,
+            'label' => 'Permissions',
+            'help_text' => '',
+            'type' => 'manytomany',
+            'editable' => true,
+            'model' => 'Permission',
+            'widget' => 'IPF_Form_Widget_SelectMultipleInputCheckbox',
+            'choices' => $choices,
+            'widget_attrs' => array('class' => 'checkgroup'),
+        ));
+
+        $this->fields['Permissions'] = $field;
+    }
+
+    public function add__Roles__field()
+    {
+        if (!IPF_Auth_App::ArePermissionsEnabled())
+            return;
+
+        $choices = array();
+        foreach (IPF_ORM::getTable('Role')->findAll() as $o)
+            $choices[$o->__toString()] = $o->id;
+
+        $field = new IPF_Form_Field_ModelMultipleChoice(array(
+            'required' => false,
+            'label' => 'Groups',
+            'help_text' => 'In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in.',
+            'type' => 'manytomany',
+            'editable' => true,
+            'model' => 'Role',
+            'widget' => 'IPF_Form_Widget_SelectMultipleInputCheckbox',
+            'choices' => $choices,
+            'widget_attrs' => array('class' => 'checkgroup'),
+        ));
+
+        $this->fields['Roles'] = $field;
+    }
+
+    public function extra_js()
+    {
+        $extra_js = parent::extra_js();
+        if (IPF_Auth_App::ArePermissionsEnabled())
+            $extra_js[] = '<script type="text/javascript" src="'.IPF::get('admin_media_url').'js/extra/checkall.js"></script>';
+        return array_unique($extra_js);
+    }
+
     function isValid()
     {
         $ok = parent::isValid();
         
-        if ($ok===true && !$this->model->id)
-        {
-            if ($this->cleaned_data['password1'] != $this->cleaned_data['password2'])
-            {
+        if ($ok===true && !$this->model->id) {
+            if ($this->cleaned_data['password1'] != $this->cleaned_data['password2']) {
                 $this->is_valid = false;
                 $this->errors['password2'][] = "The two password fields didn't match.";
-                
+
                 return false;
             }
-            
+
             $this->cleaned_data['password'] = User::SetPassword2($this->cleaned_data['password1']);
         }
-        
+
         return $ok;
     }
 }
@@ -104,7 +148,7 @@ class AdminUser extends IPF_Admin_Model
     
     public function fields()
     {
-        return array(
+        $fields = array(
             'username',
             'password',
             'email',
@@ -113,9 +157,12 @@ class AdminUser extends IPF_Admin_Model
             'is_active',
             'is_staff',
             'is_superuser',
-            'Permissions',
-            'Roles',
         );
+        if (IPF_Auth_App::ArePermissionsEnabled()) {
+            $fields[] = 'Permissions';
+            $fields[] = 'Roles';
+        }
+        return $fields;
     }
 
     function _searchFields()
@@ -129,10 +176,6 @@ class AdminUser extends IPF_Admin_Model
     protected function _getForm($model_obj, $data, $extra)
     {
         $extra['model'] = $model_obj;
-        $extra['checkgroup_fields'] = array(
-            'Permissions' => array('widget'=>'IPF_Auth_Forms_Widget_Permissions'),
-            'Roles' => array(),
-        );
         return new IPFAuthAdminUserForm($data, $extra);
     }
 }
@@ -142,14 +185,16 @@ class User extends BaseUser
     const UNUSABLE_PASSWORD = '!';
     public $session_key = 'IPF_User_auth';
 
-    public function __toString() {
+    public function __toString()
+    {
         $s = $this->username;
         if ($s===null)
             return 'Anonymous';
         return $s;
     }
 
-    public function smartName() {
+    public function smartName()
+    {
         $username = $this->username;
         if ($username===null)
             return __('Anonymous');
@@ -197,20 +242,24 @@ class User extends BaseUser
         return $user;
     }
 
-    function setUnusablePassword(){
+    function setUnusablePassword()
+    {
         $this->password = UNUSABLE_PASSWORD;
     }
 
-    static function SetPassword2($raw_password){
+    static function SetPassword2($raw_password)
+    {
         $salt = IPF_Utils::randomString(5);
         return 'sha1:'.$salt.':'.sha1($salt.$raw_password);
     }
     
-    function setPassword($raw_password){
+    function setPassword($raw_password)
+    {
         $this->password = self::SetPassword2($raw_password);
     }
 
-    function checkPassword($password){
+    function checkPassword($password)
+    {
         if ( ($this->password=='') || ($this->password==User::UNUSABLE_PASSWORD) )
             return false;
         list($algo, $salt, $hash) = explode(':', $this->password);
@@ -222,9 +271,7 @@ class User extends BaseUser
 
     function isAnonymous()
     {
-        if (0===(int)$this->id)
-            return true;
-        return false;
+        return 0 === (int)$this->id;
     }
 
     function checkCreditentials($username, $password)
@@ -240,4 +287,5 @@ class User extends BaseUser
     }
 }
 
-IPF_Admin_Model::register('User','AdminUser');
+IPF_Admin_Model::register('User', 'AdminUser');
+
index 58111ccd499c6180f6ab3a21fde305d6a4c97dbd..7af37b9c6f6d482687333242d2607d29f7e64780 100644 (file)
@@ -1,9 +1,6 @@
 <?php
 
-/**
- * This class has been auto-generated by the IPF ORM Framework
- */
 class UserPermission extends BaseUserPermission
 {
+}
 
-}
\ No newline at end of file
index be3f5d8079c374540a08b946d8ac91b2bfa51ee6..35126ddb313c6741f13c224639a34d5b2dee1112 100644 (file)
@@ -1,9 +1,6 @@
 <?php
 
-/**
- * This class has been auto-generated by the IPF ORM Framework
- */
 class UserRole extends BaseUserRole
 {
+}
 
-}
\ No newline at end of file
index 94fdea918f3dc96ece9268f375f53fc1d9c6a505..c526265a6bb0565a9bb898ec9af5d524bc5f1744 100644 (file)
@@ -1,8 +1,12 @@
 <?php
 
-class IPF_Form_DB_Boolean extends IPF_Form_DB{
+class IPF_Form_DB_Boolean extends IPF_Form_DB
+{
     public $type = 'boolean';
-    function formField($def, $form_field='IPF_Form_Field_Boolean'){
+
+    function formField($def, $form_field='IPF_Form_Field_Boolean')
+    {
         return parent::formField($def, $form_field);
     }
 }
+
index d035e0d6c1ba653388646866ca0b4f6fab903c84..6a90a70736d88591360337546ec1086058abe1ce 100644 (file)
@@ -19,3 +19,4 @@ class IPF_Form_DB_Manytomany extends IPF_Form_DB
         return parent::formField($def, $form_field);
     }
 }
+
diff --git a/ipf/form/extra/addjs.php b/ipf/form/extra/addjs.php
deleted file mode 100644 (file)
index d00bb74..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-
-class IPF_Form_Extra_AddJs extends IPF_Form_Model
-{
-    protected $add_js = array();
-
-    function initFields($extra=array())
-    {
-        parent::initFields($extra);
-
-        $this->add_js[] = '<script language="javascript" type="text/javascript" src="'.IPF::get('admin_media_url').'js/extra/jquery.js"></script>';
-
-        if (array_key_exists('add_js', $extra) && is_array($extra['add_js']))
-            $this->add_js = array_merge($this->add_js, $extra['add_js']);
-    }
-
-    public function render_commonjs()
-    {
-        return implode('', $this->add_js);
-    }
-}
\ No newline at end of file
diff --git a/ipf/form/extra/checkgroup.php b/ipf/form/extra/checkgroup.php
deleted file mode 100644 (file)
index e9b0d26..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-<?php
-
-class IPF_Form_Extra_Checkgroup extends IPF_Form_Extra_AddJs
-{
-    public $checkgroup_fields = array();
-
-    function initFields($extra=array())
-    {
-        parent::initFields($extra);
-
-        if (array_key_exists('checkgroup_fields', $extra) && is_array($extra['checkgroup_fields']))
-            $this->checkgroup_fields = $extra['checkgroup_fields'];
-    }
-
-    static function SetupForm($form, $checkgroup_fields=null)
-    {
-        if (!$checkgroup_fields)
-            $checkgroup_fields = &$form->checkgroup_fields;
-
-        foreach ($checkgroup_fields as $fieldName=>&$params)
-        {
-           $field = $form->fields[$fieldName];
-           
-            if (array_key_exists('label', $params))
-                $field->label = $params['label'];
-                
-            $widget = null;
-            if (array_key_exists('widget', $params))
-                $widget = $params['widget'];
-            if (!$widget)
-                $widget = 'IPF_Form_Extra_Widget_CheckboxGroupInput';
-
-            $field->widget = new $widget(array(
-                'choices' => $field->widget->choices,
-            ));
-
-            if (array_key_exists('class', $field->widget->attrs) && $field->widget->attrs['class'])
-                 $field->widget->attrs['class'] .= ' checkgroup';
-            else $field->widget->attrs['class']  = 'checkgroup';
-        }
-    }
-
-    public function render_commonjs()
-    {
-        if (count($this->checkgroup_fields))
-             $result = '<script language="javascript" type="text/javascript" src="'.IPF::get('admin_media_url').'js/extra/checkall.js"></script>';
-        else $result = '';
-
-        return implode('', $this->add_js).$result;
-    }
-}
diff --git a/ipf/form/extra/widget/checkboxgroupinput.php b/ipf/form/extra/widget/checkboxgroupinput.php
deleted file mode 100644 (file)
index cca37f1..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-
-class IPF_Form_Extra_Widget_CheckboxGroupInput extends IPF_Form_Widget_SelectMultipleInputCheckbox
-{
-    public function render($name, $value, $extra_attrs=array(), $choices=array())
-    {
-        $output = array();
-        if ($value === null || $value == '')
-            $value = array();
-        $final_attrs = $this->buildAttrs($extra_attrs);
-        $output[] = '<div><ul style="float:left;">';
-        $choices = array_merge($this->choices, $choices);
-        $i=0;
-        $base_id = $final_attrs['id'];
-        foreach ($choices as $option_label=>$option_value)
-        {
-            $final_attrs['id'] = $base_id.'_'.$i;
-            $final_attrs['value'] = htmlspecialchars($option_value, ENT_COMPAT, 'UTF-8');
-            $field = new IPF_Form_Extra_Widget_CheckboxInput($final_attrs);
-            $rendered = $field->render($name.'[]', in_array($option_value, $value), array('value'=>$option_value));
-            $output[] = sprintf(
-                '<li style="list-style-type:none;"><label style="width:600px;">%s %s</label></li><br/>',
-                $rendered, htmlspecialchars($option_label, ENT_COMPAT, 'UTF-8')
-            );
-            $i++;
-        }
-        $output[] = '</ul><div style="clear:both; height:0px;"></div></div>';
-        return new IPF_Template_SafeString(implode("\n", $output), true);
-    }
-}
diff --git a/ipf/form/extra/widget/checkboxinput.php b/ipf/form/extra/widget/checkboxinput.php
deleted file mode 100644 (file)
index 7ecd19f..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-
-class IPF_Form_Extra_Widget_CheckboxInput extends IPF_Form_Widget_Input
-{
-    public $input_type = 'checkbox';
-
-    public function render($name, $checked, $extra_attrs=array())
-    {
-        if ($checked)
-            $extra_attrs['checked'] = 'checked';
-        return parent::render($name, '', $extra_attrs);
-    }
-
-    public function valueFromFormData($name, &$data)
-    {
-        return (!isset($data[$name]) || false === $data[$name] || (string)$data[$name] === '0' || (string)$data[$name] === 'off') ? false : true;
-    }
-}
index 644ac1da8c8b56cf57e6da7a259dc1645b808700..3a631a98f3225bd2224b68eb42c60cfab4f32570 100644 (file)
@@ -1,10 +1,13 @@
 <?php
 
-class IPF_Form_Field_ModelMultipleChoice extends IPF_Form_Field_MultipleChoice{
+class IPF_Form_Field_ModelMultipleChoice extends IPF_Form_Field_MultipleChoice
+{
     public $widget = 'IPF_Form_Widget_SelectMultipleInput';
+
     protected $_model;
 
-    function __construct($params=array()){
+    function __construct($params=array())
+    {
         parent::__construct($params);
         $this->_model = $params['model'];
     }
index 80e1ee68dd9764dd5f243efec7cfe2214e6ad2a0..cf3a32aeb5b5998ace3e5f3c923c92a05a33504a 100644 (file)
@@ -25,20 +25,20 @@ class IPF_Form_Model extends IPF_Form
             else
                 $exclude = array();
 
-            foreach($db_columns as $name=>$col) {
-                if (array_search($name,$exclude)!==false)
+            foreach ($db_columns as $name => $col) {
+                if (array_search($name, $exclude) !== false)
                     continue;
-                $this->addDBField($name,$col);
+                $this->addDBField($name, $col);
             }
-            foreach($db_relations as $name => $relation) {
-                if (array_search($name,$exclude)!==false)
+            foreach ($db_relations as $name => $relation) {
+                if (array_search($name, $exclude) !== false)
                     continue;
-                $this->addDBRelation($name,$relation,$col);
+                $this->addDBRelation($name, $relation, $col);
             }
         } else {
-            foreach($user_fields as $uname) {
+            foreach ($user_fields as $uname) {
                 $add_method = 'add__'.$uname.'__field';
-                if (method_exists($this,$add_method)) {
+                if (method_exists($this, $add_method)) {
                     $this->$add_method();
                     continue;
                 }
index 4b55f2c134510333568226b88b7a2aa315d34b92..f147a76a3ec342c15dfe8ba2bb32aebb88875a14 100644 (file)
@@ -6,18 +6,16 @@ class IPF_Form_Widget_CheckboxInput extends IPF_Form_Widget_Input
 
     public function render($name, $value, $extra_attrs=array())
     {
-        if ((bool)$value) {
+        if ($value)
             $extra_attrs['checked'] = 'checked';
-        }
-        $extra_attrs['value'] = '1';
+        if (!array_key_exists('value', $extra_attrs))
+            $extra_attrs['value'] = '1';
         return parent::render($name, '', $extra_attrs);
     }
 
     public function valueFromFormData($name, &$data)
     {
-        if (!isset($data[$name]) or false === $data[$name] or (string)$data[$name] === '0' or (string)$data[$name] === 'off') {
-            return false;
-        }
-        return true;
+        return isset($data[$name]) && false !== $data[$name] && (string)$data[$name] !== '0' && (string)$data[$name] !== 'off';
     }
 }
+
index 86b39b01b546dbb272cc6933bd502900e2ea9f23..43133c20873ce9803b1bfcf48c4cf25efbdb3177 100644 (file)
@@ -6,10 +6,10 @@ class IPF_Form_Widget_SelectMultipleInput extends IPF_Form_Widget
 
     public function __construct($attrs=array())
     {
-       if (isset($attrs['choices'])){
-               $this->choices = $attrs['choices'];
-               unset($attrs['choices']);
-       }
+        if (isset($attrs['choices'])) {
+            $this->choices = $attrs['choices'];
+            unset($attrs['choices']);
+        }
         parent::__construct($attrs);
     }
 
@@ -45,5 +45,5 @@ class IPF_Form_Widget_SelectMultipleInput extends IPF_Form_Widget
         }
         return null;
     }
-
 }
+
index d2b18f643053192a431e419bec998217dd294fce..3f4e614516ead760aa9a2c4b5c7bbd9ddf8b2af6 100644 (file)
@@ -2,26 +2,23 @@
 
 class IPF_Form_Widget_SelectMultipleInputCheckbox extends IPF_Form_Widget_SelectMultipleInput
 {
-    public function render($name, $value, $extra_attrs=array(), 
-                           $choices=array())
+    public function render($name, $value, $extra_attrs=array(), $choices=array())
     {
         $output = array();
-        if ($value === null or $value == '') {
+        if ($value === null || $value == '')
             $value = array();
-        }
         $final_attrs = $this->buildAttrs($extra_attrs);
         $output[] = '<ul>';
         $choices = array_merge($this->choices, $choices);
         $i=0;
         $base_id = $final_attrs['id'];
         foreach ($choices as $option_label=>$option_value) {
-
             $final_attrs['id'] = $base_id.'_'.$i;
             $final_attrs['value'] = htmlspecialchars($option_value, ENT_COMPAT, 'UTF-8');
             $checkbox = new IPF_Form_Widget_CheckboxInput($final_attrs);
-            $rendered = $checkbox->render($name.'[]', in_array($option_value, $value));
-            
-            $output[] = sprintf('<li><label>%s %s</label></li>', $rendered,
+            $rendered = $checkbox->render($name.'[]', in_array($option_value, $value), array('value'=>$option_value));
+            $output[] = sprintf('<li><label>%s %s</label></li>',
+                                $rendered,
                                 htmlspecialchars($option_label, ENT_COMPAT, 'UTF-8'));
             $i++;
         }
@@ -36,6 +33,5 @@ class IPF_Form_Widget_SelectMultipleInputCheckbox extends IPF_Form_Widget_Select
         }
         return $id;
     }
+}
 
-
-}
\ No newline at end of file