]> git.andy128k.dev Git - ipf.git/commitdiff
fix auth models
authorAndrey Kutejko <andy128k@gmail.com>
Sat, 25 Jan 2014 08:33:53 +0000 (10:33 +0200)
committerAndrey Kutejko <andy128k@gmail.com>
Sat, 25 Jan 2014 08:33:53 +0000 (10:33 +0200)
ipf/auth/models/Role.php
ipf/auth/models/User.php
ipf/form/model.php

index f42ef0a20a40f27beb639123be3b25df7bb7f0ed..b79bd59399b6a8977726e42fce644f7e031c08d2 100644 (file)
@@ -13,14 +13,14 @@ class IPFAdminRoleForm extends IPF_Form_Model
     public function add__Permissions__field()
     {
         if (!IPF_Auth_App::ArePermissionsEnabled())
-            return;
+            return null;
 
         $choices = array();
         foreach (IPF_ORM::getTable('Permission')->findAll() as $o)
             $choices[$o->__toString()] = $o->id;
         ksort($choices);
 
-        $field = new IPF_Form_Field_ModelMultipleChoice(array(
+        return new IPF_Form_Field_ModelMultipleChoice(array(
             'required' => false,
             'label' => 'Permissions',
             'help_text' => '',
@@ -31,8 +31,6 @@ class IPFAdminRoleForm extends IPF_Form_Model
             'choices' => $choices,
             'widget_attrs' => array('class' => 'checkgroup'),
         ));
-
-        $this->fields['Permissions'] = $field;
     }
 }
 
index 18237ff260b9b23aa4a7402382d612db860cdd04..5e5ba9349ef305709387f0b84e94c3448b065dc1 100644 (file)
@@ -4,6 +4,8 @@ class IPFAuthAdminUserForm extends IPF_Form_Model
 {
     function initFields($extra=array())
     {
+        ArrayTools::pushToKey($extra, 'exclude', 'UserRole');
+        ArrayTools::pushToKey($extra, 'exclude', 'UserPermission');
         parent::initFields($extra);
 
         $this->fields['email']->label = 'E-mail';
@@ -78,14 +80,14 @@ class IPFAuthAdminUserForm extends IPF_Form_Model
     public function add__Permissions__field()
     {
         if (!IPF_Auth_App::ArePermissionsEnabled())
-            return;
+            return null;
 
         $choices = array();
         foreach (IPF_ORM::getTable('Permission')->findAll() as $o)
             $choices[$o->__toString()] = $o->id;
         ksort($choices);
 
-        $field = new IPF_Form_Field_ModelMultipleChoice(array(
+        return new IPF_Form_Field_ModelMultipleChoice(array(
             'required' => false,
             'label' => 'Permissions',
             'help_text' => '',
@@ -96,20 +98,18 @@ class IPFAuthAdminUserForm extends IPF_Form_Model
             'choices' => $choices,
             'widget_attrs' => array('class' => 'checkgroup'),
         ));
-
-        $this->fields['Permissions'] = $field;
     }
 
     public function add__Roles__field()
     {
         if (!IPF_Auth_App::ArePermissionsEnabled())
-            return;
+            return null;
 
         $choices = array();
         foreach (IPF_ORM::getTable('Role')->findAll() as $o)
             $choices[$o->__toString()] = $o->id;
 
-        $field = new IPF_Form_Field_ModelMultipleChoice(array(
+        return 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.',
@@ -120,8 +120,6 @@ class IPFAuthAdminUserForm extends IPF_Form_Model
             'choices' => $choices,
             'widget_attrs' => array('class' => 'checkgroup'),
         ));
-
-        $this->fields['Roles'] = $field;
     }
 
     function isValid()
index a63ae3d8839be196aad9ceed44e68b45132cae06..817a2430bac93755c2425f885f4ab71c931ba896 100644 (file)
@@ -36,7 +36,15 @@ class IPF_Form_Model extends IPF_Form
                     continue;
                 if (isset($col['exclude']) && $col['exclude'])
                     continue;
-                $field = self::createDBField($name, $table, $col);
+
+                if ($form && method_exists($form, 'add__'.$name.'__field')) {
+                    $f = call_user_func(array($form, 'add__'.$name.'__field'));
+                    if ($f)
+                        $field = array($name, $f);
+                } else {
+                    $field = self::createDBField($name, $table, $col);
+                }
+
                 if ($field)
                     $result[] = $field;
             }
@@ -46,7 +54,15 @@ class IPF_Form_Model extends IPF_Form
                     continue;
                 if (isset($relation['exclude']) && $relation['exclude'])
                     continue;
-                $field = self::createDBRelation($name, $relation, $db_columns);
+
+                if ($form && method_exists($form, 'add__'.$name.'__field')) {
+                    $f = call_user_func(array($form, 'add__'.$name.'__field'));
+                    if ($f)
+                        $field = array($name, $f);
+                } else {
+                    $field = self::createDBRelation($name, $relation, $db_columns);
+                }
+
                 if ($field)
                     $result[] = $field;
             }
@@ -54,7 +70,9 @@ class IPF_Form_Model extends IPF_Form
             foreach ($fields as $uname) {
                 $field = null;
                 if ($form && method_exists($form, 'add__'.$uname.'__field')) {
-                    $field = array($uname, array($form, 'add__'.$uname.'__field'));
+                    $f = call_user_func(array($form, 'add__'.$uname.'__field'));
+                    if ($f)
+                        $field = array($uname, $f);
                 } elseif (array_key_exists($uname, $db_columns)) {
                     $field = self::createDBField($uname, $table, $db_columns[$uname]);
                 } elseif (array_key_exists($uname, $db_relations)) {
@@ -145,13 +163,6 @@ class IPF_Form_Model extends IPF_Form
         else
             $col = array();
 
-        $defaults = array(
-            'blank'     => !isset($col['notblank']),
-            'help_text' => '',
-            'model'     => $relation->getClass(),
-            'verbose'   => isset($col['verbose']) ? $col['verbose'] : $name,
-        );
-
         $table = IPF_ORM::getTable($relation->getClass());
 
         $params = array(
@@ -159,6 +170,7 @@ class IPF_Form_Model extends IPF_Form
             'label'     => isset($col['verbose']) ? $col['verbose'] : IPF_Utils::humanTitle($name),
             'help_text' => '',
             'table'     => $table,
+            'model'     => $relation->getClass(),
         );
 
         if ($rt === IPF_ORM_Relation::ONE_AGGREGATE) {
@@ -168,7 +180,7 @@ class IPF_Form_Model extends IPF_Form
 
             $pk = $table->getIdentifier();
             $choices = array();
-            foreach ($table->findAll() as $o){
+            foreach ($table->findAll() as $o) {
                 $choices[$o->__toString()] = $o->$pk;
             }