/**
  * 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';
     }
 }
Exemplo n.º 2
0
 protected function getPK()
 {
     if ($this->_pk === null) {
         $this->_pk = $this->_model->getMetaData()->tableSchema->primaryKey;
     }
     return $this->_pk;
 }
Exemplo n.º 3
0
 /**
  * @return CActiveRecordMetaData the meta for this AR class.
  */
 public function getMetaData()
 {
     $md = parent::getMetaData();
     if ($this->getScenario() === 'search') {
         $md->attributeDefaults = array();
     }
     return $md;
 }
Exemplo n.º 4
0
 public function getMetaData()
 {
     if (!($md = parent::getMetaData())) {
         return null;
     }
     $md->relations = array();
     foreach ($this->relations() as $name => $config) {
         $md->addRelation($name, $config);
     }
     return $md;
 }
 /**
  * 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];
 }
Exemplo n.º 6
0
 /**
  * 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;
 }
 /**
  * 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';
     }
 }
 /**
  *
  * @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);
 }
Exemplo n.º 9
0
        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;
        }        
Exemplo n.º 10
0
 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;
 }
Exemplo n.º 11
0
 /**
  * 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);
     }
 }
Exemplo n.º 12
0
 public function getMetaData()
 {
     $data = parent::getMetaData();
     $this->addAdditionalColumns($data);
     return $data;
 }
 /**
  * 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);
 }
 /**
  *
  * @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);
 }