/** * fetch data */ protected function fetchData() { $criteria = $this->_criteria; $criteria->offset = $this->_offset; $criteria->limit = $this->batchSize; $this->_batch = $this->_model->findAll($criteria); $this->_offset += $this->batchSize; }
public function getValidParents() { $result = array(); $criteria = new CDbCriteria(); if (!$this->_model->getIsNewRecord()) { $criteria->addNotInCondition($this->getPK(), $this->getDescendantsIds($this->_model)); } foreach ($this->_model->findAll($criteria) as $model) { $result[$model->{$this->getPK()}] = $model->getCaption(); } return $result; }
public function findAll($condition = '', $params = array()) { $stores = parent::findAll($condition, $params); // add default store $default = self::getDefaultStore(); array_unshift($stores, $default); return $stores; }
/** * {@inheritDoc} * @see Iterator::rewind() */ public function rewind() { $this->_current_index = 0; $this->_criteria->offset = 0; $this->_max_count = (int) $this->_model->count($this->_criteria); $this->_current_records = $this->_model->findAll($this->_criteria); $this->_current_records_size = count($this->_current_records); }
/** * {@inheritDoc} * @see Iterator::rewind() */ public function rewind() { $this->_current_index = 0; $this->_current_offset = 0; $this->_max_count = $this->_model->count($this->_criteria); $newcriteria = clone $this->_criteria; $this->_current_records = $this->_model->findAll($newcriteria); $this->_current_records_size = count($this->_current_records); }
/** * {@inheritDoc} * @see Iterator::rewind() */ public function rewind() { $this->_current_index = 0; $this->_current_offset = 0; $timedCriteria = clone $this->_criteria; $timedCriteria->compare($this->_date_field, $this->_date_value); $this->_max_count = $this->_model->count($timedCriteria); $this->_current_records = $this->_model->findAll($timedCriteria); $this->_current_records_size = count($this->_current_records); }
/** * @param CActiveRecord $model * @param string $valueField defaults to primary key field * @param string $textField defaults to primary key field * @return array */ public static function listData($model, $valueField = '', $textField = '') { $pk = $model->metaData->tableSchema->primaryKey; if ($valueField === '') { $valueField = $pk; } if ($textField === '') { $textField = $valueField; } return CHtml::listData($model->findAll(array('select' => $valueField == $textField ? $valueField : $valueField . ',' . $textField)), $valueField, $textField); }
/** * @param CActiveRecord $model * @param string|array $inValues * @param string $column * @return CActiveRecord */ public static function GET_DATA_IN($model, $column = 'id', $inValues) { $criteria = new CDbCriteria(); if (is_string($inValues)) { $inValues = explode(',', $inValues); } $criteria->addInCondition($column, $inValues); return $model->findAll($criteria); }
/** * @param CActiveRecord $model * @param CDbCriteria $criteria * @param int $length * @return CDbCriteria */ public static function GET_RANDOM_CRITERIA_OFFSET($model, $criteria, $length = NULL) { $criteriaTmp = $criteria; $criteriaTmp->select = 't.id'; $randomMax = count($model->findAll($criteriaTmp)); if ($randomMax > $length) { if ($length == NULL) { $random = rand(0, $randomMax - 1); } else { $random = rand(0, $randomMax - $length); } $criteria->offset = $random; } return $criteria; }
/** * Finds all active records satisfying the specified condition, selecting only the requested * attributes and, if specified, the primary keys. * See {@link CActiveRecord::find} for detailed explanation about $condition and $params. * #MethodTracker * This method is based on {@link CActiveRecord::findAll}, from version 1.1.7 (r3135). Changes: * <ul> * <li>Selects only the specified attributes.</li> * <li>Detects and selects the representing column.</li> * <li>Detects and selects the PK attribute.</li> * </ul> * @param string|array $attributes The names of the attributes to be selected. * Optional. If not specified, the {@link representingColumn} will be used. * @param boolean $withPk Specifies if the primary keys will be selected. * @param mixed $condition Query condition or criteria. * @param array $params Parameters to be bound to an SQL statement. * @return array List of active records satisfying the specified condition. An empty array is returned if none is found. * @uses representingColumn */ public function findAllAttributes($attributes = null, $withPk = false, $condition = '', $params = array()) { Yii::trace(get_class($this) . '.findAllAttributes()', 'giix.components.GxActiveRecord'); $criteria = $this->getCommandBuilder()->createCriteria($condition, $params); if ($attributes === null) { $attributes = $this->representingColumn(); } if ($withPk) { $pks = self::model(get_class($this))->getTableSchema()->primaryKey; if (!is_array($pks)) { $pks = array($pks); } if (!is_array($attributes)) { $attributes = array($attributes); } $attributes = array_merge($pks, $attributes); } $criteria->select = $attributes; return parent::findAll($criteria); }
/** * * @param string $condition * @param array $params * @return array */ public function findAll($condition = '', $params = array()) { if (CStubActiveRecord::isUnittests()) { return CallFactory::call($this, 'findAll'); } return parent::findAll($condition, $params); }
public function findAll($condition = '', $params = array()) { return $this->prepareRecords(parent::findAll($this->prepareCondition($condition), $params)); }
/** * Don't use now. * * @param \CActiveRecord $model - model class name. * @param array $params - params list. * @param int $page - current page. * @param int $min - left border * @param int $max - right border * @return int page number */ private function countTotalPages($model, $params, $page, $min = 0, $max = 0) { if (!empty($model->findAll(array('limit' => 1, 'offset' => $params['limit'] * ($page - 1))))) { if (empty($model->findAll(array('limit' => 1, 'offset' => $params['limit'] * $page)))) { return $page; } $min = $page; $page = $max == 0 ? ceil($page * 1.5) : ceil($page + ($max - $page) / 2); } else { $max = $page; $page = $min == 0 ? ceil($page / 2) : ceil(($page - $min) * 1.5); } return $this->countTotalPages($model, $params, $page, $min, $max); }