/** * Loads a single DbObject from the database. * @access private */ private function loadUnique() { $ret = ArrayUtility::firstElement($this->loadMultiple()); return $ret; }
/** * Print some data to the standard output * @param string - the string to be outed to the output * @access public */ public function out($string) { if (is_array($string)) { $string = ArrayUtility::firstElement($string); } Display::outToStandardOutput($string); }
/** * Set the array 'selected' array of this ButtonGroup * * The 'selected' array is an array of buttons that will be * checked, or selected for radio groups. Only one button * can actually be selected if this ButtonGroup will be used * to display a radio group * @param selected - the array of selected items (corresponding * to the 'value' of each of the selected * buttons, ie. the key of the each element * of the 'values' array passed into the * constructor */ function setSelected($selected) { if ($selected instanceof FormOption) { $selected = $selected->standardValue(); } else { if (is_array($selected) && ArrayUtility::firstElement($selected) instanceof FormOption) { $newsel = array(); foreach ($selected as $opt) { $newsel[] = $opt->standardValue(); } $selected = $newsel; } } if (is_array($selected) && $this->type == ButtonGroup::RADIO) { $selected = ArrayUtility::firstElement($selected); } if (is_array($selected) && $this->type == ButtonGroup::CHECK || !is_array($selected) && $this->type == ButtonGroup::RADIO || $selected === '' && $this->type == ButtonGroup::RADIO) { $this->selected = $selected; } else { if (!is_array($selected) && trim($selected) === '' && $this->type == ButtonGroup::CHECK) { $this->selected = array(); } else { if ($this->type != ButtonGroup::NONE && trim($selected) !== '') { throw new Exception('Invalid selected passed ' . $selected); } } } }
function setSelected($key) { if ($key instanceof FormOption) { $key = strval($key->completeKey()); } else { if (is_array($key) && ArrayUtility::firstElement($key) instanceof FormOption) { $newsel = array(); foreach ($key as $opt) { $newsel[] = strval($opt->completeKey()); } $key = $newsel; } else { if (is_array($key)) { $newsel = array(); foreach ($key as $val) { $newsel[] = strval($val); } $key = $newsel; } } } if (is_array($key) && !$this->multiple) { $key = ArrayUtility::firstElement($key); } $this->selected = $key; }