config = array_merge($this->config, $config); $this->label = $label; $this->ismulti = (bool) $ismulti; $this->tid = $tid; } /** * Returns data as associative array * * @return array */ public function getAsEntry() { return array( 'config' => json_encode($this->config), 'label' => $this->label, 'ismulti' => $this->ismulti, 'class' => $this->getClass() ); } /** * The class name of this type (no namespace) * @return string */ public function getClass() { return substr(get_class($this), 20); } /** * Return the current configuration for this type * * @return array */ public function getConfig() { return $this->config; } /** * @return boolean */ public function isMulti() { return $this->ismulti; } /** * @return string */ public function getLabel() { return $this->label; } /** * @return int */ public function getTid() { return $this->tid; } /** * Split a single value into multiple values * * This function is called on saving data when only a single value instead of an array * was submitted. * * Types implementing their own @see multiValueEditor() will probably want to override this * * @param string $value * @return array */ public function splitValues($value) { return array_map('trim', explode(',', $value)); } /** * Return the editor to edit multiple values * * Types can override this to provide a better alternative than multiple entry fields * * @param string $name the form base name where this has to be stored * @param string[] $values the current values * @return string html */ public function multiValueEditor($name, $values) { $html = ''; foreach($values as $value) { $html .= $this->valueEditor($name . '[]', $value); } // empty field to add $html .= $this->valueEditor($name . '[]', ''); return $html; } /** * Return the editor to edit a single value * * @param string $name the form name where this has to be stored * @param string $value the current value * @return string html */ abstract public function valueEditor($name, $value); /** * Output the stored data * * @param string|int $value the value stored in the database * @return string the HTML to represent this data */ abstract public function getDisplayData($value); /** * This function builds a where clause for this column, comparing * the current value stored in $column with $value. Types can use it to do * clever things with the comparison. * * This default implementation is probably good enough for most basic types * * @param string $column The column name to us in the SQL * @param string $comp The comparator @see Search::$COMPARATORS * @param string $value * @return array Tuple with the SQL and parameter array */ public function compare($column, $comp, $value) { if($comp == '~') { $sql = "$column LIKE ?"; $opt = array('%' . $value . '%'); } else if($comp == '!~') { $sql = "$column NOT LIKE ?"; $opt = array('%' . $value . '%'); } else { $sql = "$column $comp ?"; $opt = array($value); } return array($sql, $opt); } }