fullName = $fullName; // sets $this->name and $this->relation $this->addRelation($fullName); $this->value = $value; } /** * Called by constructor to convert a string pathname into * a well defined relationship sequence. * * @param string $name */ protected function addRelation($name) { if (strstr($name, '.')) { $parts = explode('.', $name); $this->name = array_pop($parts); $this->relation = $parts; } else { $this->name = $name; } } /** * Set the root model class to be selected by this * search query. * * @param string $className */ public function setModel($className) { $this->model = $className; } /** * Set the current value to be filtered on. * * @param string $value */ public function setValue($value) { $this->value = $value; } /** * Accessor for the current value to be filtered on. * Caution: Data is not escaped. * * @return string */ public function getValue() { return $this->value; } /** * The original name of the field. * * @return string */ public function getName() { return $this->name; } /** * The full name passed to the constructor, * including any (optional) relations in dot notation. * * @return string */ public function getFullName() { return $this->fullName; } /** * Normalizes the field name to table mapping. * * @return string */ function getDbName() { // Special handler for "NULL" relations if($this->name == "NULL") return $this->name; // SRM: This code finds the table where the field named $this->name lives // Todo: move to somewhere more appropriate, such as DataMapper, the magical class-to-be? $candidateClass = $this->model; while($candidateClass != 'DataObject') { if(singleton($candidateClass)->hasOwnTableDatabaseField($this->name)) break; $candidateClass = get_parent_class($candidateClass); } if($candidateClass == 'DataObject') user_error("Couldn't find field $this->name in any of $this->model's tables.", E_USER_ERROR); return "\"$candidateClass\".\"$this->name\""; } /** * Return the value of the field as processed by the DBField class * * @return string */ function getDbFormattedValue() { // SRM: This code finds the table where the field named $this->name lives // Todo: move to somewhere more appropriate, such as DataMapper, the magical class-to-be? $candidateClass = $this->model; $dbField = singleton($this->model)->dbObject($this->name); $dbField->setValue($this->value); return $dbField->RAW(); } /** * Apply filter criteria to a SQL query. * * @param SQLQuery $query * @return SQLQuery */ abstract public function apply(DataQuery $query); /** * Determines if a field has a value, * and that the filter should be applied. * Relies on the field being populated with * {@link setValue()} * * @return boolean */ public function isEmpty() { return false; } } ?>