<commit_before><?php

class Crunchbutton_Phone extends Cana_Table {

	const DAYS_THRESHOLD = '2';

	public function __construct($id = null) {
		parent::__construct();
		$this
			->table('phone')
			->idVar('id_phone')
			->load($id);
	}

	public static function numbers() {
		return explode(',',c::config()->site->config('twilio-number')->value);
	}

	public static function phoneNumberBelongsToDriver($phone){
		return self::phoneNumberBelongsTo($phone, 'driver');
	}

	public static function phoneNumberBelongsToSupport($phone){
		return self::phoneNumberBelongsTo($phone, 'support');
	}

	public static function phoneNumberBelongsTo($phone, $type){
		$admins = self::adminsWithPhoneNumber($phone);
		if($admins && $admins->count() > 0){
			foreach($admins as $admin){
				switch ($type) {
					case 'driver':
						if($admin->isDriver()){
							return $admin;
						}
						break;
					case 'support':
						if($admin->isSupport()){
							return $admin;
						}
						break;
				}

			}
		}
		return false;
	}

	public static function adminsWithPhoneNumber($phone){
		$phone = Phone::byPhone($phone);
		if($phone->id_phone){
			return Admin::q('SELECT * FROM admin WHERE id_phone = ? ORDER BY id_admin ASC',[$phone->id_phone]);
		}
		return false;
	}

	// return a number specific from number based on our numbers in the last 30 days
	public function from() {
		$phone = Phone::q('
			select phone.*, phone_log.date
			from phone_log
			left join phone on phone.id_phone=phone_log.id_phone_from
			where
				phone.id_phone is not null
				and phone_log.direction="outgoing"
				and phone_log.id_phone_to="'.$this->id_phone.'"
				and datediff(now(), date) < '.self::DAYS_THRESHOLD.'
				group by phone.id_phone

			union

			select phone.*, phone_log.date<commit_msg>texting with @ doesn't work #8168<commit_after><?php

class Crunchbutton_Phone extends Cana_Table {

	const DAYS_THRESHOLD = '2';

	public function __construct($id = null) {
		parent::__construct();
		$this
			->table('phone')
			->idVar('id_phone')
			->load($id);
	}

	public static function numbers() {
		return explode(',',c::config()->site->config('twilio-number')->value);
	}

	public static function phoneNumberBelongsToDriver($phone){
		return self::phoneNumberBelongsTo($phone, 'driver');
	}

	public static function phoneNumberBelongsToSupport($phone){
		return self::phoneNumberBelongsTo($phone, 'support');
	}

	public static function phoneNumberBelongsTo($phone, $type){
		$admins = self::adminsWithPhoneNumber($phone);
		if($admins && $admins->count() > 0){
			foreach($admins as $admin){
				switch ($type) {
					case 'driver':
						if($admin->isDriver()){
							return $admin;
						}
						break;
					case 'support':
						if($admin->isSupport()){
							return $admin;
						}
						break;
				}

			}
		}
		return false;
	}

	public static function adminsWithPhoneNumber($phone){
		$phone = Phone::byPhone($phone);
		if($phone->id_phone){
			return Admin::q('SELECT * FROM admin WHERE id_phone = ? AND active = 1 ORDER BY id_admin ASC',[$phone->id_phone]);
		}
		return false;
	}

	// return a number specific from number based on our numbers in the last 30 days
	public function from() {
		$phone = Phone::q('
			select phone.*, phone_log.date
			from phone_log
			left join phone on phone.id_phone=phone_log.id_phone_from
			where
				phone.id_phone is not null
				and phone_log.direction="outgoing"
				and phone_log.id_phone_to="'.$this->id_phone.'"
				and datediff(now(), date) < '.self::DAYS_THRESHOLD.'
				group by phone.id_phone

			union

			select phone.*, phone_log.date
{'fraction_non_alphanumeric': 0.1419390891310422, 'fraction_numerical': 0.0036322995250069852, 'mean_word_length': 3.7606382978723403, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, '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': '235110', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1143, 'n_words': 276}