<commit_before><?php
/*
 * psx
 * A object oriented and modular based PHP framework for developing
 * dynamic web applications. For the current version and informations
 * visit <http://phpsx.org>
 *
 * Copyright (c) 2010-2013 <NAME> <<EMAIL>>
 *
 * This file is part of psx. psx is free software: you can
 * redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or any later version.
 *
 * psx is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with psx. If not, see <http://www.gnu.org/licenses/>.
 */

namespace PSX\Data;

use BadMethodCallException;
use InvalidArgumentException;
use PSX\Data\ResultSet;
use PSX\Sql;
use PSX\Sql\Condition;
use PSX\Sql\TableInterface;

/**
 * Default abstract class wich implements all necessary methods using an 
 * TableInterface. The TableInterface only simplyfies creating sql queries you
 * could also write an handler wich uses simple sql queries.
 *
 * @author  <NAME> <<EMAIL>>
 * @license http://www.gnu.org/licenses/gpl.html GPLv3
 * @link    http://phpsx.org
 */
abstract class HandlerAbstract implements HandlerInterface
{
	protected $table;

	protected $_select;

	public function __construct(TableInterface $table)
	{
		$this->table = $table;
	}

	public function getAll(array $fields, $startIndex = 0, $count = 16, $sortBy = null, $sortOrder = null, Condition $con = null, $mode = 0, $class = null, array $args = array())
	{
		$startIndex = $startIndex !== null ? (integer) $startIndex : 0;
		$count      = !empty($count)       ? (integer) $count      : 16;
		$sortBy     = $sortBy     !== null ? $sortBy               : $this->table->getPrimaryKey();
		$sortOrder  = $sortOrder  !== null ? (integer) $sortOrder  : Sql::SORT_DESC;

		$select = $this->getSelect();
		$fields = array_intersect($fields, $select->getSupportedFields());

		if(!empty($fields))
		{
			$select->setColumns($fields);
		}
		else
		{
			$select->setColumns(array_keys($select->getAllColumns()));
		}

		$select->orderBy($sortBy, $sortOrder)
			->limit($startIndex, $count);

		if($con !== null && $con->hasCondition())
		{
			$values = $con->toArray();

			foreach($values as $row)
			{
				$select->where($row[Condition::COLUMN], 
					$row[Condition::OPERATOR], 
					$row[Condition::VALUE], 
					$row[Condition::CONJUNCTION], 
					$row[Condition::TYPE]);
			}
		}

		if($mode == Sql::FETCH_OBJECT && $class === null)
		{
			$class = $this->getClassName();
		}

		if($mode == Sql::FETCH_OBJECT && empty($args))
		{
			$args = $this->getClassArgs();
		}

		return $select->getAll($mode, $class, $args);
	}

	public function getBy(Condition $con, array $fields = array(), $mode = 0, $class = null, array $args = array())
	{
		return $this->getAll($fields, null, null, null, null, $con, $mode, $class, $args);
	}

	public function getOneBy(Condition $con, array $fields = array(), $mode = 0, $class = null, array $args = array())
	{
		$select = $this->getSelect();
		$fields = array_intersect($fields, $select->getSupportedFields());

		if(!empty($fields))
		{
			$select->setColumns($fields);
		}
		else
		{
			$select->setColumns(array_keys($select->getAllColumns()));
		}
<commit_msg>set columns only if available<commit_after><?php
/*
 * psx
 * A object oriented and modular based PHP framework for developing
 * dynamic web applications. For the current version and informations
 * visit <http://phpsx.org>
 *
 * Copyright (c) 2010-2013 <NAME> <<EMAIL>>
 *
 * This file is part of psx. psx is free software: you can
 * redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or any later version.
 *
 * psx is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with psx. If not, see <http://www.gnu.org/licenses/>.
 */

namespace PSX\Data;

use BadMethodCallException;
use InvalidArgumentException;
use PSX\Data\ResultSet;
use PSX\Sql;
use PSX\Sql\Condition;
use PSX\Sql\TableInterface;

/**
 * Default abstract class wich implements all necessary methods using an 
 * TableInterface. The TableInterface only simplyfies creating sql queries you
 * could also write an handler wich uses simple sql queries.
 *
 * @author  <NAME> <<EMAIL>>
 * @license http://www.gnu.org/licenses/gpl.html GPLv3
 * @link    http://phpsx.org
 */
abstract class HandlerAbstract implements HandlerInterface
{
	protected $table;

	protected $_select;

	public function __construct(TableInterface $table)
	{
		$this->table = $table;
	}

	public function getAll(array $fields, $startIndex = 0, $count = 16, $sortBy = null, $sortOrder = null, Condition $con = null, $mode = 0, $class = null, array $args = array())
	{
		$startIndex = $startIndex !== null ? (integer) $startIndex : 0;
		$count      = !empty($count)       ? (integer) $count      : 16;
		$sortBy     = $sortBy     !== null ? $sortBy               : $this->table->getPrimaryKey();
		$sortOrder  = $sortOrder  !== null ? (integer) $sortOrder  : Sql::SORT_DESC;

		$select = $this->getSelect();
		$fields = array_intersect($fields, $select->getSupportedFields());

		if(!empty($fields))
		{
			$select->setColumns($fields);
		}

		$select->orderBy($sortBy, $sortOrder)
			->limit($startIndex, $count);

		if($con !== null && $con->hasCondition())
		{
			$values = $con->toArray();

			foreach($values as $row)
			{
				$select->where($row[Condition::COLUMN], 
					$row[Condition::OPERATOR], 
					$row[Condition::VALUE], 
					$row[Condition::CONJUNCTION], 
					$row[Condition::TYPE]);
			}
		}

		if($mode == Sql::FETCH_OBJECT && $class === null)
		{
			$class = $this->getClassName();
		}

		if($mode == Sql::FETCH_OBJECT && empty($args))
		{
			$args = $this->getClassArgs();
		}

		return $select->getAll($mode, $class, $args);
	}

	public function getBy(Condition $con, array $fields = array(), $mode = 0, $class = null, array $args = array())
	{
		return $this->getAll($fields, null, null, null, null, $con, $mode, $class, $args);
	}

	public function getOneBy(Condition $con, array $fields = array(), $mode = 0, $class = null, array $args = array())
	{
		$select = $this->getSelect();
		$fields = array_intersect($fields, $select->getSupportedFields());

		if(!empty($fields))
		{
			$select->setColumns($fields);
		}

{'fraction_non_alphanumeric': 0.1459918080748976, 'fraction_numerical': 0.005558806319485079, 'mean_word_length': 3.831802120141343, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '5378573', 'n_tokens_mistral': 2319, 'n_tokens_neox': 2108, 'n_words': 650}