<commit_before><?php

class Crunchbutton_Community extends Cana_Table_Trackchange {

	const CUSTOMER_SERVICE_ID_COMMUNITY = 92;
	const CUSTOMER_SERVICE_COMMUNITY_GROUP = 'support';
	const AUTO_SHUTDOWN_COMMUNITY_LOGIN = 'autoshutdowncommunity';

	const TITLE_CLOSE_ALL_RESTAURANTS = 'Close All Restaurants';
	const TITLE_CLOSE_3RD_PARY_RESTAURANTS = 'Close 3rd Party Delivery Restaurants';
	const TITLE_CLOSE_AUTO_CLOSED = 'Auto Closed';

	const DRIVER_OPEN_COMMUNITY_ERROR_COMMUNITY = 1;
	const DRIVER_OPEN_COMMUNITY_ERROR_SHIFT_HOURS = 2;
	const DRIVER_OPEN_COMMUNITY_ERROR_CREATING_SHIFT = 3;
	const DRIVER_OPEN_COMMUNITY_ERROR_ASSIGNING_SHIFT = 4;

	const PREORDER_MINUTES_AFTER_COMMUNITY_OPEN_DEFAULT = 60;

	public static function all($force = null) {
		$ip = preg_replace('/[^0-9\.]+/','',c::getIp());
		$force = preg_replace('/[^a-z\-]+/','',$force);
		$keys = ['ip' => $ip];

		if ($force) {
			$forceq = ' OR (community.permalink=:force) ';
			$keys['force'] = $force;
		}

		$q = '
			select community.* from community
			left join community_ip on community_ip.id_community=community.id_community
			where
				community.active=true
				AND (
					( community.private=false )
					OR
					(community.private=true AND community_ip.ip=:ip)
					'.$forceq.'
				)
			group by community.id_community
			order by name
		';

		return self::q($q, $keys);
	}

	public function driversHelpOut(){
		$list = [];
		$drivers = $this->getDriversOfCommunity();
		foreach( $drivers as $driver ){
			if( $driver->active && !$driver->isWorking() ){
				$info = Cockpit_Driver_Info::byAdmin( $driver->id_admin );
				if( $info->down_to_help_out ){
					$list[] = $driver;
				}
			}
		}
		return $list;
	}

	public function restaurantByLoc() {
		if (!isset($this->_restaurantsByLoc)) {
			$this->_restaurantsByLoc = Restaurant::byRange([
				'lat' => $this->loc_lat,
				'lon' => $this->loc_lon,
				'range' => $this->range,
			]);
		}
		return $this->_restaurantsByLoc;
	}

	public function save($new = false){

		// close logs
		if( $this->id_community ){
			$current = Community::q( 'SELECT * FROM community WHERE id_community = ? ', [ $this->id_community ] )->get( 0 );
			$keys = [ Cockpit_Community_Status_Log::TYPE_ALL_RESTAURANTS, Cockpit_Community_Status_Log::TYPE_3RD_PARY_DELIRERY_RESTAURANTS, Cockpit_Community_Status_Log::TYPE_AUTO_CLOSED ];
			$newKeys = $this->properties();
			$oldKeys = $current->properties();

			foreach ( $keys as $key ) {
				$newKeys[ $key ] = strval( $newKeys[ $key ] ) ? true : false;
				$oldKeys[ $key ] = strval( $oldKeys[ $key ] ) ? true : false;
				if( $newKeys[ $key ] != $oldKeys[ $key ] ){
					$close = $newKeys[ $key ];
					$params = [ 'type' => $key, 'close' => $close, 'properties' => $newKeys ];
					Cockpit_Community_Status_Log::register( $params );
				}
			}

			$note_keys = [ Cockpit_Community_Status_Log::NOTE_ALL_RESTAURANTS, Cockpit_Community_Status_Log::NOTE_3RD_PARY_DELIRERY_RESTAURANTS, Cockpit_Community_Status_Log::NOTE_AUTO_CLOSED ];
			foreach ( $keys as $key ) {
				// if it is close, check if the message was changed
				$newKeys[ $key ] = strval( $newKeys[ $key ] ) ? true : false;
				$oldKeys[ $key ] = strval( $oldKeys[ $key ] ) ? true : false;
				if( $oldKeys[ $key ] && !$newKeys[ $key ] ){
					foreach ( $note_keys as $note_key ) {
						if( $newKeys[ $note_key ] != $oldKeys[ $note_key ] ){
							$close = $newKeys[ $key ];
							$params = [ 'type' => $key, 'note' => $newKeys[ $note_key ], 'properties' => $newKeys ];
							Cockpit_Community_Status_Log::registerNote( $params );
						}
					}<commit_msg>missing closing logs #7615<commit_after><?php

class Crunchbutton_Community extends Cana_Table_Trackchange {

	const CUSTOMER_SERVICE_ID_COMMUNITY = 92;
	const CUSTOMER_SERVICE_COMMUNITY_GROUP = 'support';
	const AUTO_SHUTDOWN_COMMUNITY_LOGIN = 'autoshutdowncommunity';

	const TITLE_CLOSE_ALL_RESTAURANTS = 'Close All Restaurants';
	const TITLE_CLOSE_3RD_PARY_RESTAURANTS = 'Close 3rd Party Delivery Restaurants';
	const TITLE_CLOSE_AUTO_CLOSED = 'Auto Closed';

	const DRIVER_OPEN_COMMUNITY_ERROR_COMMUNITY = 1;
	const DRIVER_OPEN_COMMUNITY_ERROR_SHIFT_HOURS = 2;
	const DRIVER_OPEN_COMMUNITY_ERROR_CREATING_SHIFT = 3;
	const DRIVER_OPEN_COMMUNITY_ERROR_ASSIGNING_SHIFT = 4;

	const PREORDER_MINUTES_AFTER_COMMUNITY_OPEN_DEFAULT = 60;

	public static function all($force = null) {
		$ip = preg_replace('/[^0-9\.]+/','',c::getIp());
		$force = preg_replace('/[^a-z\-]+/','',$force);
		$keys = ['ip' => $ip];

		if ($force) {
			$forceq = ' OR (community.permalink=:force) ';
			$keys['force'] = $force;
		}

		$q = '
			select community.* from community
			left join community_ip on community_ip.id_community=community.id_community
			where
				community.active=true
				AND (
					( community.private=false )
					OR
					(community.private=true AND community_ip.ip=:ip)
					'.$forceq.'
				)
			group by community.id_community
			order by name
		';

		return self::q($q, $keys);
	}

	public function driversHelpOut(){
		$list = [];
		$drivers = $this->getDriversOfCommunity();
		foreach( $drivers as $driver ){
			if( $driver->active && !$driver->isWorking() ){
				$info = Cockpit_Driver_Info::byAdmin( $driver->id_admin );
				if( $info->down_to_help_out ){
					$list[] = $driver;
				}
			}
		}
		return $list;
	}

	public function restaurantByLoc() {
		if (!isset($this->_restaurantsByLoc)) {
			$this->_restaurantsByLoc = Restaurant::byRange([
				'lat' => $this->loc_lat,
				'lon' => $this->loc_lon,
				'range' => $this->range,
			]);
		}
		return $this->_restaurantsByLoc;
	}

	public function save($new = false){

		// close logs
		if( $this->id_community ){
			$current = Community::q( 'SELECT * FROM community WHERE id_community = ? ', [ $this->id_community ] )->get( 0 );
			$keys = [ Cockpit_Community_Status_Log::TYPE_ALL_RESTAURANTS, Cockpit_Community_Status_Log::TYPE_3RD_PARY_DELIRERY_RESTAURANTS, Cockpit_Community_Status_Log::TYPE_AUTO_CLOSED ];
			$newKeys = $this->properties();
			$oldKeys = $current->properties();
Log::debug( [ 'old' => $oldKeys, 'new' => $newKeys ] );
			foreach ( $keys as $key ) {
				$newKeys[ $key ] = strval( $newKeys[ $key ] ) ? true : false;
				$oldKeys[ $key ] = strval( $oldKeys[ $key ] ) ? true : false;
				if( $newKeys[ $key ] != $oldKeys[ $key ] ){
					$close = $newKeys[ $key ];
					$params = [ 'type' => $key, 'close' => $close, 'properties' => $newKeys ];
					Cockpit_Community_Status_Log::register( $params );
				}
			}

			$note_keys = [ Cockpit_Community_Status_Log::NOTE_ALL_RESTAURANTS, Cockpit_Community_Status_Log::NOTE_3RD_PARY_DELIRERY_RESTAURANTS, Cockpit_Community_Status_Log::NOTE_AUTO_CLOSED ];
			foreach ( $keys as $key ) {
				// if it is close, check if the message was changed
				$newKeys[ $key ] = strval( $newKeys[ $key ] ) ? true : false;
				$oldKeys[ $key ] = strval( $oldKeys[ $key ] ) ? true : false;
				if( $oldKeys[ $key ] && !$newKeys[ $key ] ){
					foreach ( $note_keys as $note_key ) {
						if( $newKeys[ $note_key ] != $oldKeys[ $note_key ] ){
							$close = $newKeys[ $key ];
							$params = [ 'type' => $key, 'note' => $newKeys[ $note_key ], 'properties' => $newKeys ];
							Cockpit_Community_Status_Log::registerNote( $params );
						}
					}
{'fraction_non_alphanumeric': 0.1531767955801105, 'fraction_numerical': 0.004696132596685083, 'mean_word_length': 4.06009783368274, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, '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': '2754780', 'n_tokens_mistral': 3116, 'n_tokens_neox': 2625, 'n_words': 506}