38 require_once realpath(dirname(__FILE__)).
"/../field_renderers.inc";
72 if ($form->data->hasField(
$field))
85 $this->width = $width;
86 $this->height = $height;
92 $this->groupByFormat = $format;
108 $pks = $obj->getPrimaryKeyList();
114 throw new DataItemException(
"No matching foreign key in related table {$relatedClass->table}");
119 if (count($this->options) == 0)
return;
125 $obj = $this->parent->data;
129 $keys = array_keys($this->options);
133 $related_pk = $this->options[0]->getPrimaryKey();
134 $selected = $this->
getSelected($obj, $itempk, $related_pk);
136 if ($this->width && $this->height)
138 echo
"<div id='{$this->parent->id}_{$field}_container' class='selectbox scrollbox{$resizable}{$dropdown}' style='width: {$this->width}px; height: {$this->height}px; overflow: auto'>\n";
142 echo
"<div class='selectbox'>\n";
144 $countOptions = count($this->options);
148 $gpk = $this->
groupBy[0]->getPrimaryKey();
150 foreach($this->
groupBy as $group)
152 if (array_key_exists($group->get($gpk), $this->options))
154 echo $group->format($this->groupByFormat);
155 $this->
renderCheckboxes($field, $this->options[$group->get($gpk)], $related_pk, $selected);
159 else if (is_string($this->
groupBy))
163 foreach($options as $group => $choices)
165 echo
"<br/><h4>$group</h4>";
171 $this->renderCheckBoxes(
$field, $this->options, $related_pk, $selected);
177 echo
"<input type=\"hidden\" name=\"count_{$field}\" value=\"$countOptions\">";
184 return Query::create($this->relatedClass, $this->constraint)->execute();
197 ->bind(
"{$itempk}", $obj->get($itempk))
203 foreach($items as $item)
205 $item_id = $item->$pk;
207 echo
"<input type='checkbox' class='checkbox' name='{$field}[$item_id]' id='checkbox_{$field}_$item_id' value='1'";
208 if (array_key_exists($item_id, $selected))
214 echo
"<label for='checkbox_{$field}_$item_id'>".$this->formatName($item, $this->nameField).
"</label>";
221 if (count($this->options) == 0)
return;
223 $obj = $this->parent->data;
225 $related_pk = $this->options[0]->getPrimaryKey();
226 $selected = $this->
getSelected($obj, $itempk, $related_pk);
231 foreach($this->options as $item)
233 if (array_key_exists($item->$related_pk, $selected))
235 echo $this->
formatName($item, $this->nameField).
"<br/>";
244 if (count($this->options) == 0)
return;
246 $option_pk = $this->options[0]->getPrimaryKey();
247 $obj_pk = $this->parent->data->getPrimaryKey();
248 $obj_id = $this->parent->data->$obj_pk;
258 foreach($selected as $selected_pk => $value)
260 if(!array_key_exists($selected_pk, $items))
continue;
262 $item = $items[$selected_pk];
264 $item->$obj_pk= $obj_id;
272 foreach($items as $item_id => $item)
274 if($item->$obj_pk == $obj_id && !array_key_exists($item->$option_pk, $selected))
FieldRenderer is the abstract base class for all FieldRenderers.
_startField($field, $styles="")
Internal method to generate the starting HTML for the field (including the label)
formatName($item, $name)
Formats the given DataItem based on the supplied format string.
_endField($field)
Internal method to generate the closing HTML for the field.
FieldRenderer($parent)
Constructor.
Used to place a filter on the contents of a DataItem-derived object.
static create($class, $constraints="", $indexBy="")
static create($class, $constraints="")
Static factory method to create a new Query.
reindexList($list, $field, $autoPromote=true)
Reindex an indexed or grouped query result by a different field.
regroupList($list, $field)
Regroup an indexed or grouped query result by a different field.