<commit_before><?php

namespace nitm\helpers\alerts;

use Yii;
use yii\helpers\Html;
use nitm\helpers\Cache;
use nitm\models\Alerts;

/**
 * This is the alert dispatcher class.
 */
class Dispatcher extends \yii\base\Component
{
	public $mode;
	public $useFullnames = true;
	public $reportedAction;
	
	protected static $is = 'alerts';
	protected static $_subject;
	protected static $_body;
	
	protected $_criteria = [];
	protected $_originUserId;
	protected $_message;
	
	private $_prepared = false;
	private $_variables = [];
	private $_alerts;
	
	const BATCH = 'batch';
	const SINGLE = 'single';
	const UNDEFINED = '__undefined__';
	
	public static function supportedMethods()
	{
		return [
			'any' => 'Any',
			'email' => 'Email',
			'mobile' => 'Mobile'
		];
	}
	
	public function reset()
	{
		$this->_variables = [];
		$this->_criteria = [];
		$this->reportedAction = '';
		$this->_prepared = false;
	}
	
	public function addVariables(array $variables)
	{
		$this->_variables = array_merge($variables, $this->_variables);
	}
	
	public function resetVariables()
	{
		$this->_variables = [];
	}
	
	public function prepare($isNew, $basedOn)
	{
		$basedOn['action'] = $isNew === true ? 'create' : 'update';
		$this->reportedAction = $basedOn['action'].'d';
		$this->_criteria = $basedOn;
		$this->_prepared = true;
	}
	
	public function usersWhere($where=[])
	{
		Users::$usersWhere = $where;
	}
	
	public function isPrepared()
	{
		return $this->_prepared === true;
	}
	
	public function criteria($_key, $_value='__undefined__')
	{
		$ret_val = [];
		$key = is_array($_key) ? $_key : [$_key];
		$value = is_array($_value) ? $_value : [$_value];
		foreach($key as $idx=>$k)
		{
			switch($value[$idx])
			{
				case self::UNDEFINED:
				$ret_val[$k] = isset($this->_criteria[$k]) ? $this->_criteria[$k] : self::UNDEFINED;
				break;
				
				default:
				$this->_criteria[$k] = $value[$idx];
				break;
			}
		}
		return (is_array($ret_val) && sizeof($ret_val) == 1) ? $ret_val[$_key] : $ret_val;
	}
	
	/**
	 * Find alerts for the specific criteia originally provided
	 * @param int $originUserId Is the ID of the user for the object which triggered this alert sequence<commit_msg>Minor fix to Alerts Dispatcher<commit_after><?php

namespace nitm\helpers\alerts;

use Yii;
use yii\helpers\Html;
use nitm\helpers\Cache;
use nitm\models\Alerts;

/**
 * This is the alert dispatcher class.
 */
class Dispatcher extends \yii\base\Component
{
	public $mode;
	public $useFullnames = true;
	public $reportedAction;
	
	protected static $is = 'alerts';
	protected static $_subject;
	protected static $_body;
	
	protected $_criteria = [];
	protected $_originUserId;
	protected $_message;
	
	private $_prepared = false;
	private $_variables = [];
	private $_alerts;
	
	const BATCH = 'batch';
	const SINGLE = 'single';
	const UNDEFINED = '__undefined__';
	
	public static function supportedMethods()
	{
		return [
			'any' => 'Any',
			'email' => 'Email',
			'mobile' => 'Mobile'
		];
	}
	
	public function reset()
	{
		$this->_variables = [];
		$this->_criteria = [];
		$this->reportedAction = '';
		$this->_prepared = false;
	}
	
	public function addVariables(array $variables)
	{
		$this->_variables = array_merge($variables, $this->_variables);
	}
	
	public function resetVariables()
	{
		$this->_variables = [];
	}
	
	public function prepare($isNew, $basedOn)
	{
		$basedOn['action'] = $isNew === true ? 'create' : 'update';
		$this->reportedAction = $basedOn['action'].'d';
		$this->_criteria = $basedOn;
		$this->_prepared = true;
	}
	
	public function usersWhere($where=[])
	{
		Users::$usersWhere = $where;
	}
	
	public function isPrepared()
	{
		return $this->_prepared === true;
	}
	
	public function criteria($_key, $_value='__undefined__')
	{
		$ret_val = [];
		$key = is_array($_key) ? $_key : [$_key];
		$value = is_array($_value) ? $_value : [$_value];
		foreach($key as $idx=>$k)
		{
			switch($value[$idx])
			{
				case self::UNDEFINED:
				$ret_val[$k] = isset($this->_criteria[$k]) ? $this->_criteria[$k] : self::UNDEFINED;
				break;
				
				default:
				$this->_criteria[$k] = $value[$idx];
				break;
			}
		}
		return (is_array($ret_val) && sizeof($ret_val) == 1) ? array_pop($ret_val) : $ret_val;
	}
	
	/**
	 * Find alerts for the specific criteia originally provided
	 * @param int $originUserId Is the ID of the user for the object which triggered this alert sequence
{'fraction_non_alphanumeric': 0.16351197263397949, 'fraction_numerical': 0.00045610034207525655, 'mean_word_length': 3.900558659217877, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '6788843', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1485, 'n_words': 353}