本文整理汇总了PHP中CActiveRecord::getMetaData方法的典型用法代码示例。如果您正苦于以下问题:PHP CActiveRecord::getMetaData方法的具体用法?PHP CActiveRecord::getMetaData怎么用?PHP CActiveRecord::getMetaData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CActiveRecord
的用法示例。
在下文中一共展示了CActiveRecord::getMetaData方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Builds a new COrderedIterator object. This object will iterate over the
* given $model records found in table. The found records will be filtered
* accordingly to the params in given $criteria object. If no criteria is
* provided, no filtering will be done. This method clones the criteria for
* its inner purposes, so the given criteria can be used for other things
* elsewhere.
*
* This iterator takes over the control of the $criteria->offset and the
* $criteria->order values. If such values are provided, they will be
* ignored for the iterations. If the $criteria->limit is provided, it will
* be used as a one-row fetch limit each time it will be needed until the
* end of the set is reached. If this is not provided, this object will try
* to find a value that is not too big and not too small to have good
* performances without exploding the memory.
*
* @param CActiveRecord $model
* @param CDbCriteria $criteria
*/
public function __construct(CActiveRecord $model, CDbCriteria $criteria = null)
{
$this->_model = $model;
if ($criteria === null) {
$this->_criteria = new CDbCriteria();
} else {
$this->_criteria = clone $criteria;
}
if (empty($this->_criteria->limit) || $this->_criteria->limit <= 0) {
$this->_criteria->limit = 500;
}
// TODO dynamical evaluation
$this->_criteria->offset = null;
$this->_current_offset = 0;
/* @var $schema CDbSchema */
$schema = $this->_model->getDbConnection()->getSchema();
/* @var $md CActiveRecordMetaData */
$md = $this->_model->getMetaData();
$pk = $md->tableSchema->primaryKey;
if ($pk === null) {
throw new CException(Yii::t('orderediterator', "You cannot use this iterator over {mname} models, since they have no primary keys.", array('{mname}' => get_class($this->_model))));
}
if (is_array($pk)) {
$orders = array();
foreach ($pk as $upk) {
$orders[] = $schema->quoteColumnName($upk) . ' ASC';
}
$this->_criteria->order = implode(', ', $orders);
} else {
$this->_criteria->order = $schema->quoteColumnName($pk) . ' ASC';
}
}
示例2: getPK
protected function getPK()
{
if ($this->_pk === null) {
$this->_pk = $this->_model->getMetaData()->tableSchema->primaryKey;
}
return $this->_pk;
}
示例3: getMetaData
/**
* @return CActiveRecordMetaData the meta for this AR class.
*/
public function getMetaData()
{
$md = parent::getMetaData();
if ($this->getScenario() === 'search') {
$md->attributeDefaults = array();
}
return $md;
}
示例4: getMetaData
public function getMetaData()
{
if (!($md = parent::getMetaData())) {
return null;
}
$md->relations = array();
foreach ($this->relations() as $name => $config) {
$md->addRelation($name, $config);
}
return $md;
}
示例5: getMetaData
/**
* Returns the meta-data for this AR
* @return CActiveRecordMetaData the meta for this AR class.
*/
public function getMetaData()
{
$metaData = parent::getMetaData();
if ($metaData) {
return $metaData;
}
$className = get_class($this);
if (empty(self::$_md[$className])) {
// override this from the parent to force it to get the new MetaData
self::$_md[$className] = null;
self::$_md[$className] = new CActiveRecordMetaData($this);
}
return self::$_md[$className];
}
示例6: getMetaData
/**
* respect dynamic relation depending on commentableType
* @see CActiveRecord::getMetaData()
*/
public function getMetaData()
{
if (isset(self::$_mdByType[self::$commentableType])) {
return self::$_mdByType[self::$commentableType];
}
if (!($md = parent::getMetaData())) {
return null;
}
$md->relations = array();
foreach ($this->relations() as $name => $config) {
$md->addRelation($name, $config);
}
self::$_mdByType[self::$commentableType] = $md;
return $md;
}
示例7: __construct
/**
* Builds a new CTimedOrderedIterator object. This object will iterate over
* the given $model records found in table. The found records will be
* filtered accordingly to the params in given $criteria object. The found
* records will also be filtered by the given $dateValue that given
* $dateField is supposed to have. If no criteria is provided, only the date
* related field will be filtered. This method clones the criteria for its
* inner purposes, so the given criteria can be used for other things
* elsewhere.
*
* This iterator takes over the control of the $criteria->offset and the
* $criteria->order values. If such values are provided, they will be
* ignored for the iterations. If the $criteria->limit is provided, it will
* be used as a one-row fetch limit each time it will be needed until the
* end of the set is reached. If this is not provided, this object will try
* to find a value that is not too big and not too small to have good
* performances without exploding the memory.
*
* @param CActiveRecord $model
* @param string $dateField
* @param string|DateTime $dateValue
* @param CDbCriteria $criteria
*/
public function __construct(CActiveRecord $model, $dateField, $dateValue, CDbCriteria $criteria = null)
{
$this->_model = $model;
if ($criteria === null) {
$this->_criteria = new CDbCriteria();
} else {
$this->_criteria = clone $criteria;
}
if (empty($this->_criteria->limit) || $this->_criteria->limit <= 0) {
$this->_criteria->limit = 500;
}
// TODO dynamical evaluation
if (!is_string($dateField)) {
throw new CException(Yii::t('timedorderediterator', "The date field should be a string, {type} given.", array('{type}' => gettype($dateField) === 'object' ? get_class($dateField) : gettype($dateField))));
}
$this->_date_field = $dateField;
if (is_string($dateValue)) {
$this->_date_value = $dateValue;
} else {
if ($dateValue instanceof \DateTime) {
$this->_date_value = $dateValue->format('Y-m-d');
} else {
throw new CException(Yii::t('timedorderediterator', "The date value field should be a string or an instance of \\DateTime, {type} given.", array('{type}' => gettype($dateField) === 'object' ? get_class($dateField) : gettype($dateField))));
}
}
$this->_criteria->offset = null;
$this->_current_offset = 0;
/* @var $schema CDbSchema */
$schema = $this->_model->getDbConnection()->getSchema();
/* @var $md CActiveRecordMetaData */
$md = $this->_model->getMetaData();
$pk = $md->tableSchema->primaryKey;
if ($pk === null) {
throw new CException(Yii::t('timedorderediterator', "You cannot use this iterator over {mname} models, since they have no primary keys.", array('{mname}' => get_class($this->_model))));
}
if (is_array($pk)) {
$orders = array();
foreach ($pk as $upk) {
$orders[] = $schema->quoteColumnName($upk) . ' ASC';
}
$this->_criteria->order = implode(', ', $orders);
} else {
$this->_criteria->order = $schema->quoteColumnName($pk) . ' ASC';
}
}
示例8: convertModel
/**
*
* @param CActiveRecord $model
* @param mixed $attributes If is set to null all attributes of the model will be added. If a string is given, only this attribute will added. If an array of strings is given, all elements will be retrieved.
* @param mixed $relations If is set to true, all relations will be retrieved. If a string is given, only one relation will be added. For array see the class definition of relations.
*/
protected function convertModel($model, $attributes = null, $relations = null)
{
$relationArray = array();
if ($attributes === null) {
$attributes = array();
foreach ($model->attributes as $attr => $type) {
$attributes[] = $attr;
}
}
if ($relations === true || is_array($relations) || is_string($relations)) {
if ($relations === true) {
//include all relations
$relations = array();
foreach ($model->getMetaData()->relations as $name => $relation) {
$relations[] = $name;
}
}
if (is_string($relations)) {
$relations = array($relations);
}
foreach ($relations as $key => $relation) {
$relAttributes = null;
$relRelations = null;
/**
* @var array|mixed array or CDbCriteria object with additional parameters that customize the query
* conditions as specified in the relation declaration. See more at http://www.yiiframework.com/doc/api/1.1/CActiveRecord#getRelated-detail
*/
$relParams = array();
/**
* @var boolean whether to reload the related objects from database. See more at
* http://www.yiiframework.com/doc/api/1.1/CActiveRecord#getRelated-detail
*/
$relRefresh = false;
$relationName = $relation;
if (is_array($relation)) {
$relationName = $key;
if (!isset($relation['attributes']) && !isset($relation['relations']) && !isset($relation['refresh']) && !isset($relation['params'])) {
// for convenient configuration
$relAttributes = $relation;
} else {
$relAttributes = isset($relation['attributes']) ? $relation['attributes'] : null;
$relRelations = isset($relation['relations']) ? $relation['relations'] : null;
$relParams = isset($relation['params']) ? $relation['params'] : array();
$relRefresh = isset($relation['refresh']) ? $relation['refresh'] : false;
}
}
$relatedModels = $model->getRelated($relationName, $relRefresh, $relParams);
if (is_array($relatedModels)) {
foreach ($relatedModels as $relatedModel) {
$relationArray[$relationName][] = $this->convertModel($relatedModel, $relAttributes, $relRelations);
}
} else {
if ($relatedModels) {
$relationArray[$relationName] = $this->convertModel($relatedModels, $relAttributes, $relRelations);
}
}
}
}
if (is_string($attributes)) {
$attributes = array($attributes);
}
if ($attributes === null) {
$attributes = true;
}
foreach ($attributes as $attribute) {
$attributeArray[$attribute] = $model->{$attribute};
}
if ($this->attributeAliases) {
$tempArray = array();
foreach ($attributeArray as $attributeName => $value) {
if (isset($this->attributeAliases[$attributeName])) {
$tempArray[$this->attributeAliases[$attributeName]] = $value;
} else {
$tempArray[$attributeName] = $value;
}
}
$attributeArray = $tempArray;
}
if ($this->onAfterModelToArray) {
call_user_func_array($this->onAfterModelToArray, array($model, &$attributeArray, &$relationArray));
}
return array_merge($attributeArray, $relationArray);
}
示例9: getMetaData
public function getMetaData()
{
$data = parent::getMetaData();
$data->columns['category_id'] = array('name' => 'category_id');
// $data->columns['adjusted_stock'] = array('name' => 'adjusted_stock');
// $data->columns['display'] = array('name' => 'display');
// $data->columns['idCombined'] = array('name' => 'idCombined');
// $data->columns['spminusdisc'] = array('name' => 'spminusdisc');
// $data->columns['value'] = array('name' => 'value');
// $data->columns['label'] = array('name' => 'label');
return $data;
}
示例10: getMetaData
public function getMetaData(){
$data = parent::getMetaData();
$data->columns['role_id'] = array('name' => 'role_id');
$data->columns['rolename'] = array('name' => 'rolename');
$data->columns['editpassword'] = array('name' => 'editpassword');
$data->columns['login'] = array('name' => 'login');
$data->columns['addresstype'] = array('name' => 'addresstype');
$data->columns['address'] = array('name' => 'address');
$data->columns['lookupDisplay'] = array('name' => 'lookupDisplay');
$data->columns['selected_date'] = array('name' => 'selected_date');
return $data;
}
示例11: _resolvePrimaryAttributes
/**
* Resolves primary key attributes (name => value).
*
* @param CActiveRecord $record record to resolve primary key
*
* @return array primary key attributes
*/
private static function _resolvePrimaryAttributes($record)
{
$key = $record->getMetaData()->tableSchema->primaryKey;
$primaryAttributes = $record->getPrimaryKey();
if (is_array($key)) {
return $primaryAttributes;
} else {
return array($key => $primaryAttributes);
}
}
示例12: getMetaData
public function getMetaData()
{
$data = parent::getMetaData();
$this->addAdditionalColumns($data);
return $data;
}
示例13: getMetadata
/**
* Generates a new additional metadata information from a given active
* record model.
*
* @param CActiveRecord $record
* @return IDbMetadata
*/
public static function getMetadata(CActiveRecord $record)
{
$factory = new CDbMetadataFactory();
return $factory->createDbMetadata($record->getMetaData()->tableSchema);
}
示例14: convertModel
/**
*
* @param CActiveRecord $model
* @param mixed $attributes If is set to null all attributes of the model will be added. If a string is given, only this attribute will added. If an array of strings is given, all elements will be retrieved.
* @param mixed $relations If is set to true, all relations will be retrieved. If a string is given, only one relation will be added. For array see the class definition of relations.
*/
protected function convertModel($model, $attributes = null, $relations = null)
{
$relationArray = array();
if ($attributes === null) {
$attributes = array();
foreach ($model->attributes as $attr => $type) {
$attributes[] = $attr;
}
}
if ($relations === true || is_array($relations) || is_string($relations)) {
if ($relations === true) {
//include all relations
$relations = array();
foreach ($model->getMetaData()->relations as $name => $relation) {
$relations[] = $name;
}
}
if (is_string($relations)) {
$relations = array($relations);
}
foreach ($relations as $key => $relation) {
$relAttributes = null;
$relRelations = null;
$relationName = $relation;
if (is_array($relation)) {
$relationName = $key;
if (!isset($relation['attributes']) && !isset($relation['relations'])) {
// for convenient configuration
$relAttributes = $relation;
} else {
$relAttributes = isset($relation['attributes']) ? $relation['attributes'] : null;
$relRelations = isset($relation['relations']) ? $relation['relations'] : null;
}
}
$relatedModels = $model->getRelated($relationName);
if (is_array($relatedModels)) {
foreach ($relatedModels as $relatedModel) {
$relationArray[$relationName][] = $this->convertModel($relatedModel, $relAttributes, $relRelations);
}
} else {
if ($relatedModels) {
$relationArray[$relationName] = $this->convertModel($relatedModels, $relAttributes, $relRelations);
}
}
}
}
if (is_string($attributes)) {
$attributes = array($attributes);
}
if ($attributes === null) {
$attributes = true;
}
foreach ($attributes as $attribute) {
$attributeArray[$attribute] = $model->{$attribute};
}
if ($this->attributeAliases) {
$tempArray = array();
foreach ($attributeArray as $attributeName => $value) {
if (isset($this->attributeAliases[$attributeName])) {
$tempArray[$this->attributeAliases[$attributeName]] = $value;
} else {
$tempArray[$attributeName] = $value;
}
}
$attributeArray = $tempArray;
}
if ($this->onAfterModelToArray) {
call_user_func_array($this->onAfterModelToArray, array($model, &$attributeArray, &$relationArray));
}
return array_merge($attributeArray, $relationArray);
}