<commit_before><?php
/*
 *@author <NAME> <<EMAIL>>
 */

require_once 'CC_Model.php';
require_once 'CC_SQL.php'; 

class CC_DAO extends CC_Model
{
	protected static $table = '';
	
	protected $data = array();
	
	protected static function createSQL($alias = '')
	{
		return CC_SQL::create(static::$table . ($alias? ' '.$alias : ''));
	}
	
	public static function getTable()
	{
		return static::$table;
	}
	
	protected function get_field($field, $default = '')
	{
		return self::searchIn($this->data, $field, $default);
	}
	
	public function get()
	{
		return (object) $this->data;
	}
	
	protected function validateAndSet($field, $value, $regex, $min = 0, $max = '')
	{
		if($this->validate($value, $regex, $min, $max))
		{
			$this->data[$field] = $value;
			return true;
		}
		else
		{
			$this->setError('Preencha corretamente o campo "'.$field.'"!');
			return false;
		}
	}
	
	protected static function getSelect($fields = '*')
	{
		return self::createSQL()->select($fields);
	}
	
	public function selectAll($fields = '*')
	{
		return $this->getError()? array() : $this->getSelect()->fetchAll();
	}
	
	public function select($fields = '*')
	{
		return $this->getError()? null : $this->getSelect()->whereData($this->data)->fetch();
	}
	
	protected function insert()
	{
		return count($this->data) && $this->getError() == ''? self::createSQL()->insert($this->data)->execute() : false;
	}
	
	protected function delete($filter)
	{
		return self::createSQL()->delete()->whereData($filter)->execute();
	}
	
	protected function update($data, $filter = array())
	{
		return $this->getError()? false : self::createSQL()->update($data)->whereData($filter)->execute();
	}
	
	public function loadByData()
	{
		foreach ($this->select() as $field => $value)
		{
			$this->data[$field] = $value;
		}
	}
	
	public static function countRows()
	{
		return self::createSQL()->getCount();
	}
	
	public static function countPages($amountPerPage)
	{
		return ceil(self::countRows() / $amountPerPage);
	}
}
?><commit_msg>Métodos de CRUD utilizando diretamente os dados do Model.<commit_after><?php
/*
 *@author <NAME> <<EMAIL>>
 */

require_once 'CC_Model.php';
require_once 'CC_SQL.php'; 

class CC_DAO extends CC_Model
{
	protected static $table = '';
	
	protected $data = array();
	
	protected static function createSQL($alias = '')
	{
		return CC_SQL::useTable(static::$table . ($alias? ' '.$alias : ''));
	}
	
	public static function getTable()
	{
		return static::$table;
	}
	
	protected function get_field($field, $default = '')
	{
		return self::searchIn($this->data, $field, $default);
	}
	
	public function get()
	{
		return (object) $this->data;
	}
	
	protected function validateAndSet($field, $value, $regex, $min = 0, $max = '', $html = false)
	{
		if($this->validate($value, $regex, $min, $max))
		{
			$this->data[$field] = $html? $value : strip_tags($value);
			return true;
		}
		else
		{
			$this->setError('Preencha corretamente o campo "'.$field.'"!');
			return false;
		}
	}
	
	private function checkData()
	{
		return count($this->data) && $this->getError() == '';
	}
	
	protected static function getSelect($fields = '*')
	{
		return self::createSQL()->select($fields);
	}
	
	public function selectAll($fields = '*')
	{
		return $this->getSelect($fields)->whereData($this->data)->fetchAll();
	}
	
	public function select($fields = '*')
	{
		return $this->getSelect()->whereData($this->data)->fetch();
	}
	
	protected function insert()
	{
		return $this->checkData()? self::createSQL()->insert($this->data)->execute() : false;
	}
	
	protected function delete()
	{
		return $this->checkData()? self::createSQL()->delete()->whereData($this->data)->execute() : false;
	}
	
	protected function update()
	{
		$data = $this->data;
		$filter = count($data) > 1? array_shift($data) : array();
		
		return $this->checkData()? self::createSQL()->update($data)->whereData($filter)->execute() : false;
	}
	
	public function loadByData()
	{
		foreach ($this->select() as $field => $value)
		{
			$this->data[$field] = $value;
		}
	}
	
	public static function countRows()
	{
		return self::createSQL()->selectCount();
	}
	
	public static function countPages($amountPerPage)
	{
		return ceil(self::countRows() / $amountPerPage);
	}
}
?>
{'fraction_non_alphanumeric': 0.19710968964700307, 'fraction_numerical': 0.0007107320540156361, 'mean_word_length': 4.251243781094527, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 76, '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': '7602158', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1401, 'n_words': 290}