]> git.andy128k.dev Git - ipf.git/commitdiff
cleanup forms
authorAndrey Kutejko <andy128k@gmail.com>
Mon, 25 Aug 2014 14:56:50 +0000 (17:56 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Tue, 26 Aug 2014 15:45:34 +0000 (18:45 +0300)
ipf/form/field/modelchoice.php [deleted file]
ipf/form/field/modelmultiplechoice.php [deleted file]
ipf/legacy_orm/modelform.php

diff --git a/ipf/form/field/modelchoice.php b/ipf/form/field/modelchoice.php
deleted file mode 100644 (file)
index 91c1ee8..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-
-class IPF_Form_Field_ModelChoice extends IPF_Form_Field_Choice
-{
-    protected $table;
-
-    function __construct($params=array())
-    {
-        parent::__construct($params);
-        $this->table = $params['table'];
-        if (isset($params['queryset'])) {
-            $choices = array('--------' => '');
-            foreach ($params['queryset'] as $item) {
-                $choices[(string)$item] = $item->id;
-            }
-            $this->setChoices($choices);
-        }
-    }
-
-    public function clean($value)
-    {
-        parent::clean($value);
-        if (in_array($value, $this->empty_values))
-            return null;
-        return $this->table->find($value);
-    }
-}
-
diff --git a/ipf/form/field/modelmultiplechoice.php b/ipf/form/field/modelmultiplechoice.php
deleted file mode 100644 (file)
index f6844d7..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<?php
-
-class IPF_Form_Field_ModelMultipleChoice extends IPF_Form_Field_MultipleChoice
-{
-}
-
index 89ffed1e25283dc549f85dc2999490b6715f4a54..fe9cb9344bf3d387d07dfa448ecbb71aeeab4830 100644 (file)
@@ -174,19 +174,23 @@ class IPF_Form_Model extends IPF_Form
         );
 
         if ($rt === IPF_ORM_Relation::ONE_AGGREGATE) {
-            $params['queryset'] = $table->findAll();
-            return array($name.'_id', new IPF_Form_Field_ModelChoice($params));
-        } elseif ($rt === IPF_ORM_Relation::MANY_AGGREGATE) {
-
+            $choices = array('--------' => '');
             $pk = $table->getIdentifier();
+            foreach ($table->findAll() as $o) {
+                $choices[$o->__toString()] = $o->$pk;
+            }
+
+            $params['choices'] = $choices;
+            return array($name.'_id', new IPF_Form_Field_Choice($params));
+        } elseif ($rt === IPF_ORM_Relation::MANY_AGGREGATE) {
             $choices = array();
+            $pk = $table->getIdentifier();
             foreach ($table->findAll() as $o) {
                 $choices[$o->__toString()] = $o->$pk;
             }
 
             $params['choices'] = $choices;
-            $params['widget']  = 'IPF_Form_Widget_SelectMultipleInput';
-            return array($name, new IPF_Form_Field_ModelMultipleChoice($params));
+            return array($name, new IPF_Form_Field_MultipleChoice($params));
         } else {
             return null;
         }