+++ /dev/null
-<?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);
- }
-}
-
);
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;
}