<commit_before><?php
/**
 * Extend base CActiveRecord functionality with handy functions.
 *
 * @since 1.0
 * @package Components
 * @author <NAME> <<EMAIL>>
 */
class CBActiveRecord extends CActiveRecord
{
	/**
	 * Variation of CHtml::listData allowing array results.
	 *
	 * @param array $models Array of source models.
	 * @param mixed $keyAttr Attribute to be used as key. If null, an array is returned instead of an assoc.
	 * @param mixed $valueAttr Attribute to be used as value. If null, the model itself is used as is.
	 * @return array
	 */
	static public function listData(array $models, $keyAttr = null, $valueAttr = null)
	{
		$values = array();

		// Go through all models
		foreach ($models as $model) {
			// Retrieve value
			$value = ($valueAttr === null) ? $model : self::value($model, $valueAttr);

			if ($keyAttr === null) {
				// Array mode (no key)
				$values[] = $value;
			} else {
				// Assoc mode
				$values[self::value($model, $keyAttr)] = $value;
			}
		}

		return $values;
	}

	/**
	 * Variation of CHtml::value retrieving model values.
	 *
	 * This variation does not accept default values and optimizes the isset conditions.
	 *
	 * @param mixed $model Source model
	 * @param mixed $valueAttr
	 * @return mixed
	 */
	public static function value($model, $valueAttr)
	{
		if (is_scalar($valueAttr)) {
			foreach (explode('.', $valueAttr) as $valuAttrComponent) {
				if (is_object($model)) {
					if (!isset($model->$valuAttrComponent)) {
						return null;
					}
					$model=$model->$valuAttrComponent;

				} else if(is_array($model)) {
					if (!isset($model[$valuAttrComponent])) {
						return null;
					}
					$model=$model[$valuAttrComponent];
				} else {
					return null;
				}
			}
		} else {
			return call_user_func($valueAttr,$model);
		}

		return $model;
	}

	/**
	 * Utc datetime to datetime stamp.
	 *
	 * @param integer $stamp
	 * @return string
	 */
	public function stampToUdatetime($stamp = null)
	{
		if (!$stamp) {
			$stamp = time();
		}
		return gmdate('Y-m-d H:i:s', $stamp);
	}

	/**
	 * getErrors() as string with newlines.
	 *
	 * @param string $attribute
	 * @return string
	 */
	public function getErrorsAsString($attribute = null)
	{
		$errorString = '';
		foreach (parent::getErrors($attribute) as $errorArray) {
			$errorString .= implode("\n", $errorArray)."\n";
		}
		return $errorString;
	}

	/**
	 * Select specific data.
	 * @param string $select
	 * @return CBActiveRecord
	 */
	public function scopeSelect($select)
	{
		$this->getDbCriteria()->select = $select;

		return $this;
	}

	/**
	 * Limit results.
	 *
	 * Singleton method.
	 *
	 * @param integer $limit Number of results.
	 * @return CBActiveRecord
	 */
	public function scopeLimit($limit)
	{
		$this->getDbCriteria()->limit = intval($limit);

		return $this;
	}

	/**
	 * Zero-based offset of results.
	 *
	 * Singleton method.
	 *
	 * @param integer $offset Offset of results.
	 * @return CBActiveRecord
	 */
	public function scopeOffset($offset)
	{
		$this->getDbCriteria()->offset = intval($offset);

		return $this;
	}

	/**
	 * Limit results.
	 *
	 * Singleton method.
	 *
	 * @param integer $order Order by clause.
	 * @return CBActiveRecord
	 */
	public function scopeOrderBy($order)
	{
		$this->getDbCriteria()->order = $order;

		return $this;
	}

	/**
	 * Finds a single active record that has the specified attribute values.
	 * See {@link find()} for detailed explanation about $condition and $params.
	 * @param array $attributes list of attribute values (indexed by attribute names) that the active records should match.
	 * An attribute value can be an array which will be used to generate an IN condition.
	 * @param mixed $condition query condition or criteria.
	 * @param array $params parameters to be bound to an SQL statement.
	 * @return CBActiveRecord
	 */
	public function scopeByAttributes($attributes,$condition='',$params=array())
	{
		$prefix=$this->getTableAlias(true).'.';
		$criteria=$this->getCommandBuilder()->createColumnCriteria($this->getTableSchema(),$attributes,$condition,$params,$prefix);
		$this->getDbCriteria()->mergeWith($criteria);
		return $this;
	}
}<commit_msg>Introduced findAllBatches<commit_after><?php
/**
 * Extend base CActiveRecord functionality with handy functions.
 *
 * @since 1.0
 * @package Components
 * @author <NAME> <<EMAIL>>
 */
class CBActiveRecord extends CActiveRecord
{
	/**
	 * Variation of CHtml::listData allowing array results.
	 *
	 * @param array $models Array of source models.
	 * @param mixed $keyAttr Attribute to be used as key. If null, an array is returned instead of an assoc.
	 * @param mixed $valueAttr Attribute to be used as value. If null, the model itself is used as is.
	 * @return array
	 */
	static public function listData(array $models, $keyAttr = null, $valueAttr = null)
	{
		$values = array();

		// Go through all models
		foreach ($models as $model) {
			// Retrieve value
			$value = ($valueAttr === null) ? $model : self::value($model, $valueAttr);

			if ($keyAttr === null) {
				// Array mode (no key)
				$values[] = $value;
			} else {
				// Assoc mode
				$values[self::value($model, $keyAttr)] = $value;
			}
		}

		return $values;
	}

	/**
	 * Variation of CHtml::value retrieving model values.
	 *
	 * This variation does not accept default values and optimizes the isset conditions.
	 *
	 * @param mixed $model Source model
	 * @param mixed $valueAttr
	 * @return mixed
	 */
	public static function value($model, $valueAttr)
	{
		if (is_scalar($valueAttr)) {
			foreach (explode('.', $valueAttr) as $valuAttrComponent) {
				if (is_object($model)) {
					if (!isset($model->$valuAttrComponent)) {
						return null;
					}
					$model=$model->$valuAttrComponent;

				} else if(is_array($model)) {
					if (!isset($model[$valuAttrComponent])) {
						return null;
					}
					$model=$model[$valuAttrComponent];
				} else {
					return null;
				}
			}
		} else {
			return call_user_func($valueAttr,$model);
		}

		return $model;
	}

	/**
	 * Utc datetime to datetime stamp.
	 *
	 * @param integer $stamp
	 * @return string
	 */
	public function stampToUdatetime($stamp = null)
	{
		if (!$stamp) {
			$stamp = time();
		}
		return gmdate('Y-m-d H:i:s', $stamp);
	}

	/**
	 * getErrors() as string with newlines.
	 *
	 * @param string $attribute
	 * @return string
	 */
	public function getErrorsAsString($attribute = null)
	{
		$errorString = '';
		foreach (parent::getErrors($attribute) as $errorArray) {
			$errorString .= implode("\n", $errorArray)."\n";
		}
		return $errorString;
	}

	/**
	 * Select specific data.
	 * @param string $select
	 * @return CBActiveRecord
	 */
	public function scopeSelect($select)
	{
		$this->getDbCriteria()->select = $select;

		return $this;
	}

	/**
	 * Limit results.
	 *
	 * Singleton method.
	 *
	 * @param integer $limit Number of results.
	 * @return CBActiveRecord
	 */
	public function scopeLimit($limit)
	{
		$this->getDbCriteria()->limit = intval($limit);

		return $this;
	}

	/**
	 * Zero-based offset of results.
	 *
	 * Singleton method.
	 *
	 * @param integer $offset Offset of results.
	 * @return CBActiveRecord
	 */
	public function scopeOffset($offset)
	{
		$this->getDbCriteria()->offset = intval($offset);

		return $this;
	}

	/**
	 * Limit results.
	 *
	 * Singleton method.
	 *
	 * @param integer $order Order by clause.
	 * @return CBActiveRecord
	 */
	public function scopeOrderBy($order)
	{
		$this->getDbCriteria()->order = $order;

		return $this;
	}

	/**
	 * Finds a single active record that has the specified attribute values.
	 * See {@link find()} for detailed explanation about $condition and $params.
	 * @param array $attributes list of attribute values (indexed by attribute names) that the active records should match.
	 * An attribute value can be an array which will be used to generate an IN condition.
	 * @param mixed $condition query condition or criteria.
	 * @param array $params parameters to be bound to an SQL statement.
	 * @return CBActiveRecord
	 */
	public function scopeByAttributes($attributes,$condition='',$params=array())
	{
		$prefix=$this->getTableAlias(true).'.';
		$criteria=$this->getCommandBuilder()->createColumnCriteria($this->getTableSchema(),$attributes,$condition,$params,$prefix);
		$this->getDbCriteria()->mergeWith($criteria);
		return $this;
	}

	/**
	 * Execute current criteria in batches of given size.
	 *
	 * @param integer $batchSize
	 * @param string $orderBy
	 * @return CBActiveRecordBatchIterator
	 */
	public function findAllBatches($batchSize, $orderBy = null)
	{
		if ($orderBy !== null) {
			$this->scopeOrderBy($orderBy);
		}

		return new CBActiveRecordBatchIterator($this, $batchSize);
	}
}
{'fraction_non_alphanumeric': 0.13864238792209288, 'fraction_numerical': 0.00046098882102109026, 'mean_word_length': 3.420784513499745, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '97040', 'n_tokens_mistral': 3006, 'n_tokens_neox': 2618, 'n_words': 788}