/** * Destroys the test data at the end of the test */ public function tearDown() { foreach ($this->fixtureData() as $attributes) { $doc = ASolrDocument::model()->findByAttributes($attributes); if (is_object($doc)) { $this->assertTrue($doc->delete()); } } $this->getConnection()->commit(); }
/** * Constructor. * @param mixed $modelClass the model class (e.g. 'Post') or the model finder instance * (e.g. <code>Post::model()</code>, <code>Post::model()->published()</code>). * @param array $config configuration (name=>value) to be applied as the initial property values of this class. */ public function __construct($modelClass, $config = array()) { if ($modelClass instanceof IASolrDocument || $modelClass instanceof CActiveRecord) { $this->modelClass = get_class($modelClass); $this->model = $modelClass; } else { $this->modelClass = $modelClass; $this->model = ASolrDocument::model($this->modelClass); } $this->setId($this->modelClass); foreach ($config as $key => $value) { $this->{$key} = $value; } }
/** * Returns the real definition of an attribute given its name. * * The resolution is based on {@link attributes} and {@link CActiveRecord::attributeNames}. * <ul> * <li>When {@link attributes} is an empty array, if the name refers to an attribute of {@link modelClass}, * then the name is returned back.</li> * <li>When {@link attributes} is not empty, if the name refers to an attribute declared in {@link attributes}, * then the corresponding virtual attribute definition is returned. Starting from version 1.1.3, if {@link attributes} * contains a star ('*') element, the name will also be used to match against all model attributes.</li> * <li>In all other cases, false is returned, meaning the name does not refer to a valid attribute.</li> * </ul> * @param string $attribute the attribute name that the user requests to sort on * @return mixed the attribute name or the virtual attribute definition. False if the attribute cannot be sorted. */ public function resolveAttribute($attribute) { if ($this->attributes !== array()) { $attributes = $this->attributes; } else { if ($this->modelClass !== null) { $attributes = ASolrDocument::model($this->modelClass)->attributeNames(); } else { return false; } } foreach ($attributes as $name => $definition) { if (is_string($name)) { if ($name === $attribute) { return $definition; } } else { if ($definition === '*') { if ($this->modelClass !== null && ASolrDocument::model($this->modelClass)->hasAttribute($attribute)) { return $attribute; } } else { if ($definition === $attribute) { return $attribute; } } } } return false; }
/** * Gets the static model * @param string $className the model class to instantiate * @return ExampleExtendedSolrDocument the nidek */ public static function model($className = __CLASS__) { return parent::model($className); }