<commit_before><?php

class SiteFilterBehavior extends ModelBehavior {

	function setup(&$model, $config = array()) {
		$config = Set::merge(array(
			'relationship' => false,
			'joins' => false,
			'enabled' => true,
			'filter' => true,
			), $config);
		$this->settings[$model->alias] = $config;
	}

	function _setupRelationships(&$model, $config = array()) {
		if (!empty($this->settings[$model->alias]['relationship'])) {
			$model->bindModel($config['relationship'], false);
		}
	}

	function enableFilter(&$model) {
		$this->settings[$model->alias]['filter'] = true;
	}

	function disableFilter(&$model) {
		$this->settings[$model->alias]['filter'] = false;
	}

	function beforeFind(&$model, $query) {
		if ($this->settings[$model->alias]['enabled'] === false) {
			return $query;
		}
		$this->_setupRelationships($model, $this->settings[$model->alias]);
		$site = Sites::currentSite();
		$sites = array(Sites::ALL_SITES, $site['Site']['id']);

		$setting = Set::merge(
			array('relationship' => array(), 'joins' => array()),
			$this->settings[$model->alias]
			);
		extract($setting);

		if (!empty($joins)) {
			foreach ($joins as $join => &$joinConfig) {
				if (empty($joinConfig)) continue;

				// link to Site model
				$foreignKey = $joinConfig['alias']. '.site_id';
				if (empty($joinConfig['conditions'][$foreignKey])) {
					$joinConfig['conditions'][$foreignKey] = $sites;
				}

				$foreignKey = $joinConfig['alias']. '.' . Inflector::underscore($model->alias) . '_id';
				$condition = "{$model->alias}.{$model->primaryKey} = {$foreignKey}";
				if (!in_array($condition, $joinConfig['conditions'])) {
					$joinConfig['conditions'][] = $condition;
				}<commit_msg>filter $sites through array_unique()<commit_after><?php

class SiteFilterBehavior extends ModelBehavior {

	function setup(&$model, $config = array()) {
		$config = Set::merge(array(
			'relationship' => false,
			'joins' => false,
			'enabled' => true,
			'filter' => true,
			), $config);
		$this->settings[$model->alias] = $config;
	}

	function _setupRelationships(&$model, $config = array()) {
		if (!empty($this->settings[$model->alias]['relationship'])) {
			$model->bindModel($config['relationship'], false);
		}
	}

	function enableFilter(&$model) {
		$this->settings[$model->alias]['filter'] = true;
	}

	function disableFilter(&$model) {
		$this->settings[$model->alias]['filter'] = false;
	}

	function beforeFind(&$model, $query) {
		if ($this->settings[$model->alias]['enabled'] === false) {
			return $query;
		}
		$this->_setupRelationships($model, $this->settings[$model->alias]);
		$site = Sites::currentSite();
		$sites = array_unique(array(Sites::ALL_SITES, $site['Site']['id']));

		$setting = Set::merge(
			array('relationship' => array(), 'joins' => array()),
			$this->settings[$model->alias]
			);
		extract($setting);

		if (!empty($joins)) {
			foreach ($joins as $join => &$joinConfig) {
				if (empty($joinConfig)) continue;

				// link to Site model
				$foreignKey = $joinConfig['alias']. '.site_id';
				if (empty($joinConfig['conditions'][$foreignKey])) {
					$joinConfig['conditions'][$foreignKey] = $sites;
				}

				$foreignKey = $joinConfig['alias']. '.' . Inflector::underscore($model->alias) . '_id';
				$condition = "{$model->alias}.{$model->primaryKey} = {$foreignKey}";
				if (!in_array($condition, $joinConfig['conditions'])) {
					$joinConfig['conditions'][] = $condition;
				}
{'fraction_non_alphanumeric': 0.21894182987430577, 'fraction_numerical': 0.0, 'mean_word_length': 4.741610738255034, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 55, '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': '1057504', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1081, 'n_words': 191}