<commit_before><?php 

/**
 * Notification module class
 *
 * @package munkireport
 * @author 
 **/
class Notification_controller extends Module_controller
{
	// For development set debug to true,
	// this will prevent the last_run to be updated.
	private $debug = false;
	
	/*** Protect methods with auth! ****/
	function __construct()
	{
		// Store module path
		$this->module_path = dirname(__FILE__);
	}

	/**
	 * Default method
	 *
	 * @author AvB
	 **/
	function index()
	{
		echo "You've loaded the notification module!";
	}

	/**
	 * REST interface, returns json with notification objects
	 **/
	function get_list()
	{
		
        $obj = new View();
		if( ! $this->authorized())
		{
			$obj->view('json', array('msg' => array('error' => 'Not authorized')));
		}
		else
		{
			$notify_obj = new Notification_model();
			$obj->view('json', array('msg' => $notify_obj->get_list()));
		}

	}
	
	/**
	 * Run notification check
	 *
	 * Check notifications, notify if necessary
	 *
	 **/
	public function runCheck()
	{
		$obj = new View();
		if( ! $this->authorized())
		{
			$obj->view('json', array('msg' => array('error' => 'Not authorized')));
			return;
		}
				
		$now = time();
		$stats = array('errors' => 0, 'email' => 0, 'desktop' => 0);
		
		// Load notifications
		$notifyObj = new Notification_model();
		$notificationList = $notifyObj->getDueNotifications();
		
		// No due notifications?
		if( ! $notificationList){
			// Return JSON with results
			$obj->view('json', array('msg' => $stats));
			return;
		}
		
		// Get Machine Groups per Business Unit
		$buMgList = array();
		$buObj = new Business_unit();
		foreach($buObj->retrieve_many('property=?', array('machine_group')) AS $obj)
		{
			$buId = intval($obj->unitid);
			$buMgList[$buId][] = intval($obj->value);
		}
		
		$allEvents = array(); // $allEvents is used for email
		$eventObj = new Event_model();
		foreach ($notificationList as $notificationObj)
		{
			$events = array();
			$buId = $notificationObj->business_unit;
			
			// Match notification with event todo: move to event model
			$sql = sprintf("SELECT event.*, machine.computer_name 
				FROM event
				LEFT JOIN reportdata USING (serial_number)
				LEFT JOIN machine USING (serial_number)
				WHERE event.serial_number LIKE '%s'<commit_msg>Replace left join with straight joins to cater for max join size<commit_after><?php 

/**
 * Notification module class
 *
 * @package munkireport
 * @author 
 **/
class Notification_controller extends Module_controller
{
	// For development set debug to true,
	// this will prevent the last_run to be updated.
	private $debug = false;
	
	/*** Protect methods with auth! ****/
	function __construct()
	{
		// Store module path
		$this->module_path = dirname(__FILE__);
	}

	/**
	 * Default method
	 *
	 * @author AvB
	 **/
	function index()
	{
		echo "You've loaded the notification module!";
	}

	/**
	 * REST interface, returns json with notification objects
	 **/
	function get_list()
	{
		
        $obj = new View();
		if( ! $this->authorized())
		{
			$obj->view('json', array('msg' => array('error' => 'Not authorized')));
		}
		else
		{
			$notify_obj = new Notification_model();
			$obj->view('json', array('msg' => $notify_obj->get_list()));
		}

	}
	
	/**
	 * Run notification check
	 *
	 * Check notifications, notify if necessary
	 *
	 **/
	public function runCheck()
	{
		$obj = new View();
		if( ! $this->authorized())
		{
			$obj->view('json', array('msg' => array('error' => 'Not authorized')));
			return;
		}
				
		$now = time();
		$stats = array('errors' => 0, 'email' => 0, 'desktop' => 0);
		
		// Load notifications
		$notifyObj = new Notification_model();
		$notificationList = $notifyObj->getDueNotifications();
		
		// No due notifications?
		if( ! $notificationList){
			// Return JSON with results
			$obj->view('json', array('msg' => $stats));
			return;
		}
		
		// Get Machine Groups per Business Unit
		$buMgList = array();
		$buObj = new Business_unit();
		foreach($buObj->retrieve_many('property=?', array('machine_group')) AS $obj)
		{
			$buId = intval($obj->unitid);
			$buMgList[$buId][] = intval($obj->value);
		}
		
		$allEvents = array(); // $allEvents is used for email
		$eventObj = new Event_model();
		foreach ($notificationList as $notificationObj)
		{
			$events = array();
			$buId = $notificationObj->business_unit;
			
			// Match notification with event todo: move to event model
			$sql = sprintf("SELECT event.*, machine.computer_name 
				FROM event
				JOIN reportdata USING (serial_number)
				JOIN machine USING (serial_number)
				WHERE event.serial_number LIKE '%s'
{'fraction_non_alphanumeric': 0.15895765472312703, 'fraction_numerical': 0.0013029315960912053, 'mean_word_length': 3.3452830188679243, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '4664551', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1427, 'n_words': 396}