<commit_before><?php namespace Stillat\Database;

use LaravelBook\Ardent\Ardent;

abstract class Model extends Ardent {

	/**
	 * The order by column name and order. The array is setup such
	 * that the first element is the column name and the second column
	 * is the sorting direction (i.e., ASC or DESC).
	 * 
	 * @var array
	 */
	protected $order_by = array(null, null);

	public function scopeOrder($query)
	{
		if ($this->order_by[0] !=== null and $this->order_by[1] !=== null)
		{
			return $query->orderBy($this->order_by[0], $this->order_by[1]);
		}

		// If the order_by values are invalid, let's just return the query for now.
		return $query;
	}

	/**
	 * Returns the next record.
	 *
	 * @return Stillat\Common\Database\Model
	 */
	public function next()
	{
		return static::where($this->getKeyName(), '>', $this->getKey())->min('id');
	}

	/**
	 * Returns the previous record.
	 *
	 * @return Stillat\Common\Database\Model
	 */
	public function previous()
	{
		return static::where($this->getKeyName(), '<', $this->getKey())->max('id');
	}

}<commit_msg>added option to automatically order query results<commit_after><?php namespace Stillat\Database;

use LaravelBook\Ardent\Ardent;

abstract class Model extends Ardent {

	/**
	 * The order by column name and order. The array is setup such
	 * that the first element is the column name and the second column
	 * is the sorting direction (i.e., ASC or DESC).
	 * 
	 * @var array
	 */
	protected $orderBy = array(null, null);

	/**
	 * Determines if the model will automatically order query results.
	 * 
	 * @var boolean
	 */
	protected $automaticallyOrder = false;

	/**
	 * A list of method names that are ignored when determining if the model
	 * should automatically ordery the query.
	 * 
	 * @var array
	 */
	protected $ignoredOrderMethods = array('increment', 'decrement');

	/**
	 * Orders a given query.
	 * 
	 * @param  \Illuminate\Database\Eloquent\Builder $query
	 * @return \Illuminate\Database\Eloquent\Builder
	 */
	public function scopeOrder($query)
	{
		if ($this->orderBy[0] !=== null and $this->orderBy[1] !=== null)
		{
			return $query->orderBy($this->orderBy[0], $this->orderBy[1]);
		}

		// If the orderBy values are invalid, let's just return the query for now.
		return $query;
	}

	/**
	 * Handle dynamic method calls into the method.
	 *
	 * @param  string  $method
	 * @param  array   $parameters
	 * @return mixed
	 */
	public function __call($method, $parameters)
	{
		// Handle the automatic ordering of query results.
		if ($this->automaticallyOrder and !in_array($method, $this->ignoredOrderMethods))
		{
			return $this->scopeOrder($this->newQuery());
		}

		// Handle the default Eloquent model __call
		return parent::__call($method, $parameters);
	}

	/**
	 * Returns the next record.
	 *
	 * @return Stillat\Common\Database\Model
	 */
	public function next()
	{
		return static::where($this->getKeyName(), '>', $this->getKey())->min('id');
	}

	/**
	 * Returns the previous record.
	 *
	 * @return Stillat\Common\Database\Model
	 */
	public function previous()
	{
		return static::where($this->getKeyName(), '<', $this->getKey())->max('id');
	}

}
{'fraction_non_alphanumeric': 0.14693748016502697, 'fraction_numerical': 0.0025388765471278957, 'mean_word_length': 3.5028571428571427, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, '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': '6863298', 'n_tokens_mistral': 1060, 'n_tokens_neox': 966, 'n_words': 293}