<commit_before><?php

class Crunchbutton_Admin_Notification extends Cana_Table {

	const TYPE_SMS   = 'sms';
	const TYPE_EMAIL = 'email';
	const TYPE_PHONE = 'phone';
	const TYPE_URL   = 'url';
	const TYPE_FAX   = 'fax';
	const REPS_COCKPIT = 'http://cbtn.io/';

	const IS_ENABLE_KEY = 'notification-admin-is-enable';
	const IS_ENABLE_TO_TAKEOUT_KEY = 'notification-admin-is-enable-takeout';

	const IS_ENABLE_DEFAULT = true;
	const IS_ENABLE_TO_TAKEOUT_DEFAULT = false;

	public function resendNotification(){

		// Get orders with active admin notifications from the last 24 hours
		$query = 'SELECT DISTINCT( o.id_order ), o.*
							FROM `order` o
							INNER JOIN `restaurant` r ON o.id_restaurant = o.id_restaurant
							INNER JOIN `notification` n ON n.id_restaurant = o.id_restaurant AND n.active = 1 AND n.type = "' . Crunchbutton_Notification::TYPE_ADMIN . '" 
							INNER JOIN `admin_notification` an ON an.id_admin = n.id_admin AND an.active = 1

							WHERE o.date > DATE_SUB( NOW(), INTERVAL 24 HOUR )
							ORDER BY o.id_order ASC';

		$orders = Crunchbutton_Order::q( $query );
		if( $orders->count() > 0 ){
			foreach ( $orders as $order ) {
				if( !$order->wasAcceptedByRep() ){
					Log::debug( [ 'order' => $order->id_order, 'action' => 'resend admin notification', 'type' => 'admin_notification' ]);
					foreach ( $order->restaurant()->notifications() as $n ) {
						Log::debug([ 'order' => $order->id_order, 'action' => 'starting resend notification', 'notification_type' => $n->type, 'notification_value' => $n->value, 'notification_id_admin' => $n->id_admin, 'type' => 'notification']);
						if( $n->type == Crunchbutton_Notification::TYPE_ADMIN ){
							foreach( $n->admin()->activeNotifications() as $adminNotification ){
								$adminNotification->send( $order );
							}
						} 
					}
				}
			}
		}
	}

	public function send( Crunchbutton_Order $order ) {

		$is_enable = ( !is_null( $this->getSetting( Crunchbutton_Admin_Notification::IS_ENABLE_KEY ) ) ? ( $this->getSetting( Crunchbutton_Admin_Notification::IS_ENABLE_KEY ) == '1' ) : Crunchbutton_Admin_Notification::IS_ENABLE_DEFAULT );
		if( !$is_enable ){
			Log::debug( [ 'order' => $order->id_order, 'action' => 'notification to admin is disabled', 'notification_type' => $this->type, 'value'=> $this->value, 'type' => 'admin_notification' ]);
			return;
		}

		$is_enable_takeout = ( !is_null( $this->getSetting( Crunchbutton_Admin_Notification::IS_ENABLE_TO_TAKEOUT_KEY ) ) ? ( $this->getSetting( Crunchbutton_Admin_Notification::IS_ENABLE_TO_TAKEOUT_KEY ) == '1' ) : Crunchbutton_Admin_Notification::IS_ENABLE_TO_TAKEOUT_DEFAULT );
		if( $order->delivery_type == Crunchbutton_Order::SHIPPING_TAKEOUT && $this->getSetting( Crunchbutton_Admin_Notification::IS_ENABLE_TO_TAKEOUT_KEY ) != '1' ){
			Log::debug( [ 'order' => $order->id_order, 'action' => 'notification to admin to TAKEOUT is disabled', 'notification_type' => $this->type, 'value'=> $this->value, 'type' => 'admin_notification' ]);
			return;
		}

		Log::debug( [ 'order' => $order->id_order, 'action' => 'notification to admin starting', 'notification_type' => $this->type, 'value'=> $this->value, 'type' => 'admin_notification' ]);

		switch ( $this->type ) {
			case Crunchbutton_Admin_Notification::TYPE_FAX :
				$this->sendFax( $order );
				break;<commit_msg>partial #2143 - cron to renotivy reps if no one accepts - changed the log to see the env<commit_after><?php

class Crunchbutton_Admin_Notification extends Cana_Table {

	const TYPE_SMS   = 'sms';
	const TYPE_EMAIL = 'email';
	const TYPE_PHONE = 'phone';
	const TYPE_URL   = 'url';
	const TYPE_FAX   = 'fax';
	const REPS_COCKPIT = 'http://cbtn.io/';

	const IS_ENABLE_KEY = 'notification-admin-is-enable';
	const IS_ENABLE_TO_TAKEOUT_KEY = 'notification-admin-is-enable-takeout';

	const IS_ENABLE_DEFAULT = true;
	const IS_ENABLE_TO_TAKEOUT_DEFAULT = false;

	public function resendNotification(){

		// Get orders with active admin notifications from the last 24 hours
		$query = 'SELECT DISTINCT( o.id_order ), o.*
							FROM `order` o
							INNER JOIN `restaurant` r ON o.id_restaurant = o.id_restaurant
							INNER JOIN `notification` n ON n.id_restaurant = o.id_restaurant AND n.active = 1 AND n.type = "' . Crunchbutton_Notification::TYPE_ADMIN . '" 
							INNER JOIN `admin_notification` an ON an.id_admin = n.id_admin AND an.active = 1

							WHERE o.date > DATE_SUB( NOW(), INTERVAL 24 HOUR )
							ORDER BY o.id_order ASC';

		$orders = Crunchbutton_Order::q( $query );
		if( $orders->count() > 0 ){
			foreach ( $orders as $order ) {
				if( !$order->wasAcceptedByRep() ){
					Log::debug( [ 'order' => $order->id_order, 'action' => 'resend admin notification', 'type' => 'admin_notification' ]);
					foreach ( $order->restaurant()->notifications() as $n ) {
						Log::debug([ 'order' => $order->id_order, 'action' => 'starting resend notification', 'notification_type' => $n->type, 'env' => c::getEnv();, 'notification_id_admin' => $n->id_admin, 'type' => 'notification']);
						if( $n->type == Crunchbutton_Notification::TYPE_ADMIN ){
							foreach( $n->admin()->activeNotifications() as $adminNotification ){
								$adminNotification->send( $order );
							}
						} 
					}
				}
			}
		}
	}

	public function send( Crunchbutton_Order $order ) {

		$is_enable = ( !is_null( $this->getSetting( Crunchbutton_Admin_Notification::IS_ENABLE_KEY ) ) ? ( $this->getSetting( Crunchbutton_Admin_Notification::IS_ENABLE_KEY ) == '1' ) : Crunchbutton_Admin_Notification::IS_ENABLE_DEFAULT );
		if( !$is_enable ){
			Log::debug( [ 'order' => $order->id_order, 'action' => 'notification to admin is disabled', 'notification_type' => $this->type, 'value'=> $this->value, 'type' => 'admin_notification' ]);
			return;
		}

		$is_enable_takeout = ( !is_null( $this->getSetting( Crunchbutton_Admin_Notification::IS_ENABLE_TO_TAKEOUT_KEY ) ) ? ( $this->getSetting( Crunchbutton_Admin_Notification::IS_ENABLE_TO_TAKEOUT_KEY ) == '1' ) : Crunchbutton_Admin_Notification::IS_ENABLE_TO_TAKEOUT_DEFAULT );
		if( $order->delivery_type == Crunchbutton_Order::SHIPPING_TAKEOUT && $this->getSetting( Crunchbutton_Admin_Notification::IS_ENABLE_TO_TAKEOUT_KEY ) != '1' ){
			Log::debug( [ 'order' => $order->id_order, 'action' => 'notification to admin to TAKEOUT is disabled', 'notification_type' => $this->type, 'value'=> $this->value, 'type' => 'admin_notification' ]);
			return;
		}

		Log::debug( [ 'order' => $order->id_order, 'action' => 'notification to admin starting', 'notification_type' => $this->type, 'value'=> $this->value, 'type' => 'admin_notification' ]);

		switch ( $this->type ) {
			case Crunchbutton_Admin_Notification::TYPE_FAX :
				$this->sendFax( $order );
				break;
{'fraction_non_alphanumeric': 0.15509293680297398, 'fraction_numerical': 0.0035687732342007433, 'mean_word_length': 4.5495049504950495, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 114, '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': '410030', 'n_tokens_mistral': 2547, 'n_tokens_neox': 2225, 'n_words': 477}