<commit_before><?php

namespace Croogo\Croogo\Model\Table;

use Cake\ORM\Table;
use Croogo\Croogo\Croogo;
use Croogo\Croogo\PropertyHookTrait;

/**
 * Croogo Base Table class
 *
 * @category Croogo.Model
 * @package  Croogo.Croogo.Model.Table
 * @version  1.5
 * @author   <NAME> <<EMAIL>>
 * @license  http://www.opensource.org/licenses/mit-license.php The MIT License
 * @link     http://www.croogo.org
 */
class CroogoTable extends Table {

	use PropertyHookTrait;

/**
 * use Caching
 *
 * @var string
 */
	public $useCache = true;

/**
 * Default behaviors
 */
	public $actsAs = array(
		'Containable',
	);

	public $hookedBehaviors = [];

/**
 * Display fields for admin_index. Use displayFields()
 *
 * @var array
 * @access protected
 */
	protected $_displayFields = array();

/**
 * Edit fields for admin_edit. Use editFields()
 *
 * @var array
 * @access protected
 */
	protected $_editFields = array();

/**
 * Constructor
 *
 * @param mixed  $id Set this ID for this model on startup, can also be an array of options, see above.
 * @param string $table Name of database table to use.
 * @param string $ds DataSource connection name.
 */
	public function __construct($id = false, $table = null, $ds = null) {
		Croogo::applyHookProperties('Hook.table_properties', $this);

		parent::__construct($id, $table, $ds);
	}

	public function initialize(array $config) {
		parent::initialize($config);

		foreach ($this->hookedBehaviors as $behavior => $config) {
			$this->behaviors()->load($behavior, $config);
		}
	}


	/**
 * Override find function to use caching
 *
 * Caching can be done either by unique names,
 * or prefixes where a hashed value of $options array is appended to the name
 *
 * @param mixed $type Type of find operation (all / first / count / neighbors / list / threaded)
 * @param array $options Option fields (conditions / fields / joins / limit / offset / order / page / group / callbacks)
 * @return array Array of records, or Null of failure
 * @access public
 */
	public function find($type = 'first', $options = array()) {
		if ($this->useCache) {
			$cachedResults = $this->_findCached($type, $options);
			if ($cachedResults) {
				return $cachedResults;
			}
		}

		$args = func_get_args();
		$results = call_user_func_array(array('parent', 'find'), $args);
		if ($this->useCache) {
			if (isset($options['cache']['name']) && isset($options['cache']['config'])) {
				$cacheName = $options['cache']['name'];
			} elseif (isset($options['cache']['prefix']) && isset($options['cache']['config'])) {
				$cacheName = $options['cache']['prefix'] . md5(serialize($options));
			}

			if (isset($cacheName)) {
				$cacheName .= '_' . Configure::read('Config.language');
				Cache::write($cacheName, $results, $options['cache']['config']);
				$this->cacheConfig = $options['cache']['config'];
			}
		}
		return $results;
	}

/**
 * Check if find() was already cached
 *
 * @param mixed $type
 * @param array $options
 * @return array Array of records, or False when no records found in cache
 * @access private
 */
	protected function _findCached($type, $options) {
		if (isset($options['cache']['name']) && isset($options['cache']['config'])) {
			$cacheName = $options['cache']['name'];
		} elseif (isset($options['cache']['prefix']) && isset($options['cache']['config'])) {
			$cacheName = $options['cache']['prefix'] . md5(serialize($options));
		} else {
			return false;
		}

		$cacheName .= '_' . Configure::read('Config.language');
		$results = Cache::read($cacheName, $options['cache']['config']);
		if ($results) {
			return $results;
		}
		return false;
	}

/**
 * Updates multiple model records based on a set of conditions.<commit_msg>Remove not needed methods from CroogoTable<commit_after><?php

namespace Croogo\Croogo\Model\Table;

use Cake\ORM\Table;
use Croogo\Croogo\Croogo;
use Croogo\Croogo\PropertyHookTrait;

/**
 * Croogo Base Table class
 *
 * @category Croogo.Model
 * @package  Croogo.Croogo.Model.Table
 * @version  1.5
 * @author   <NAME> <<EMAIL>>
 * @license  http://www.opensource.org/licenses/mit-license.php The MIT License
 * @link     http://www.croogo.org
 */
class CroogoTable extends Table {

	use PropertyHookTrait;

/**
 * use Caching
 *
 * @var string
 */
	public $useCache = true;

/**
 * Default behaviors
 */
	public $actsAs = array(
		'Containable',
	);

	public $hookedBehaviors = [];

/**
 * Display fields for admin_index. Use displayFields()
 *
 * @var array
 * @access protected
 */
	protected $_displayFields = array();

/**
 * Edit fields for admin_edit. Use editFields()
 *
 * @var array
 * @access protected
 */
	protected $_editFields = array();

/**
 * Constructor
 *
 * @param mixed  $id Set this ID for this model on startup, can also be an array of options, see above.
 * @param string $table Name of database table to use.
 * @param string $ds DataSource connection name.
 */
	public function __construct($id = false, $table = null, $ds = null) {
		Croogo::applyHookProperties('Hook.table_properties', $this);

		parent::__construct($id, $table, $ds);
	}

	public function initialize(array $config) {
		parent::initialize($config);

		foreach ($this->hookedBehaviors as $behavior => $config) {
			$this->behaviors()->load($behavior, $config);
		}
	}

/**
 * Updates multiple model records based on a set of conditions.
{'fraction_non_alphanumeric': 0.1606100546036528, 'fraction_numerical': 0.001129730747505178, 'mean_word_length': 3.969130028063611, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, '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': '4136902', 'n_tokens_mistral': 1741, 'n_tokens_neox': 1637, 'n_words': 465}