/** * Finds field object from relation notation * @param string $sourceField * @return Field */ protected function fieldLookup($sourceField) { if (preg_match("#^(id|pk)\$#i", $sourceField, $_match)) { if ($this->model->getPrimaryKey() or $this->model->hasField('id')) { return $_match[1] == 'pk' ? $this->model->getField($this->getModel()->getPrimaryKey()) : $this->model->getField($_match[1]); } else { throw new Exception('Model does not have primary key nor id field'); } } elseif (preg_match("#^[a-z0-9]+(__([a-z0-9_]+))+\$#i", $sourceField, $_match)) { return $this->getModel()->pathLookup($sourceField); } elseif (!preg_match("#__#", $sourceField) && $this->getModel()->hasField($sourceField)) { return $this->getModel()->getField($sourceField, true); } else { throw new Exception("Unable to translate field '{$sourceField}'."); } }
/** * Magic method for creating fields and setting it's values * @param string $name * @param mixed $value */ public function __set($name, $value) { $name = strtolower($name); if ($this->hasField($name)) { if (key_exists($name, $this->fields)) { $valid = true; $this->getField($name)->setValue($value); $this->modified = true; } if ($this->isExtended() and $this->extends->hasField($name)) { $this->extends->{$name} = $value; } } else { throw new Exception("Model '" . get_class($this) . "' does not contain field '{$name}'."); } }