<commit_before><?php
	/** 
	 * Loco database
	 * @since Version 3.2
	 * @version 3.8.7
	 * @author <NAME>
	 * @package Railpage
	 */
	
	namespace Railpage\Locos;
	
	use DateTime;
	use Exception;
	use Railpage\Url;
		
	/** 
	 * Locomotive operators
	 * @since Version 3.2
	 * @version 3.8.7
	 * @author <NAME>
	 */
	
	class Operator extends Locos {
		
		/** 
		 * Operator ID
		 * @since Version 3.2
		 * @var int $id
		 */
		
		public $id;
		
		/** 
		 * Operator name
		 * @since Version 3.2
		 * @var string $name
		 */
		
		public $name;
		
		/**
		 * Organistion ID
		 * @since Version 3.2
		 * @var int $organisation_id
		 */
		
		public $organisation_id;
		
		/**
		 * Operator URL
		 * @since Version 3.8.7
		 * @var string $url_operator
		 */
		
		public $url_operator;
		
		/**
		 * Owner URL
		 * @since Version 3.8.7
		 * @var string $url_owner
		 */
		
		public $url_owner;
		
		/**
		 * Constructor
		 * @since Version 3.2
		 * @version 3.2
		 * @param int $operator_id
		 */
		
		public function __construct($operator_id = false) {
			parent::__construct(); 
			
			if (filter_var($operator_id, FILTER_VALIDATE_INT)) {
				try {
					$this->fetch($operator_id); 
				} catch (Exception $e) {
					throw new Exception($e->getMessage()); 
				}
			}
		}
		
		/**
		 * Populate the operator object
		 * @since Version 3.2
		 * @version 3.2
		 * @param int $operator_id
		 */
		
		public function fetch($operator_id = false) {
			if (!$operator_id) {
				throw new Exception("No operator ID provided"); 
				return false;
			}
			
			// Fetch the data
			if ($this->db instanceof \sql_db) {
				$query = "SELECT * FROM operators WHERE operator_id = ".$this->db->real_escape_string($operator_id); 
				
				if ($rs = $this->db->query($query)) {
					$row = $rs->fetch_assoc(); 
					
					$this->id 		= $operator_id; 
					$this->name		= $row['operator_name']; 
					$this->organisation_id = $row['organisation_id']; 
					
					return true;
				} else {
					throw new Exception($this->db->error."\n".$query);
					return false;
				}
			} else {
				$query = "SELECT * FROM operators WHERE operator_id = ?";
				
				$row = $this->db->fetchRow($query, $operator_id);
				$this->id 		= $operator_id; 
				$this->name		= $row['operator_name']; 
				$this->organisation_id = $row['organisation_id']; 
				$this->url_operator = "/locos/browse/operator/" . $this->id;
				$this->url_owner = "/locos/browse/owner/" . $this->id;
				
				$this->url = new Url(sprintf("/locos/browse/operator/%d", $this->id));
				$this->url->operator = sprintf("/locos/browse/operator/%d", $this->id);
				$this->url->owner = sprintf("/locos/browse/owner/%d", $this->id);
				
				return true;
			}
		}
		
		/**
		 * Verify the changes before committing them
		 * @since Version 3.2
		 * @return boolean
		 */
		
		public function verify() {
			if (empty($this->name)) {
				return false;
			} else {
				return true;
			}
		}
		
		/**
		 * Commit the changes
		 * @since Version 3.2
		 * @version 3.2
		 * @return boolean
		 */
		
		public function commit() {
			if (!$this->verify()) {
				return false;
			}
			
			if ($this->db instanceof \sql_db) {
				$dataArray = array(); 
				$dataArray['operator_name'] 	= $this->db->real_escape_string($this->name); 
				$dataArray['organisation_id']	= $this->db->real_escape_string($this->organisation_id); 
				
				if (!empty($this->id)) {
					$where = array("operator_id" => $this->id);
					
					$query = $this->db->buildQuery($dataArray, "operators", $where); 
				} else {
					$query = $this->db->buildQuery($dataArray, "operators"); 
				}
				
				if ($rs = $this->db->query($query)) {<commit_msg>Bugfix<commit_after><?php
	/** 
	 * Loco database
	 * @since Version 3.2
	 * @version 3.8.7
	 * @author <NAME>
	 * @package Railpage
	 */
	
	namespace Railpage\Locos;
	
	use DateTime;
	use Exception;
	use Railpage\Url;
		
	/** 
	 * Locomotive operators
	 * @since Version 3.2
	 * @version 3.8.7
	 * @author <NAME>
	 */
	
	class Operator extends Locos {
		
		/** 
		 * Operator ID
		 * @since Version 3.2
		 * @var int $id
		 */
		
		public $id;
		
		/** 
		 * Operator name
		 * @since Version 3.2
		 * @var string $name
		 */
		
		public $name;
		
		/**
		 * Organistion ID
		 * @since Version 3.2
		 * @var int $organisation_id
		 */
		
		public $organisation_id;
		
		/**
		 * Operator URL
		 * @since Version 3.8.7
		 * @var string $url_operator
		 */
		
		public $url_operator;
		
		/**
		 * Owner URL
		 * @since Version 3.8.7
		 * @var string $url_owner
		 */
		
		public $url_owner;
		
		/**
		 * Constructor
		 * @since Version 3.2
		 * @version 3.2
		 * @param int $operator_id
		 */
		
		public function __construct($operator_id = false) {
			parent::__construct(); 
			
			if (filter_var($operator_id, FILTER_VALIDATE_INT)) {
				try {
					$this->fetch($operator_id); 
				} catch (Exception $e) {
					throw new Exception($e->getMessage()); 
				}
			}
		}
		
		/**
		 * Populate the operator object
		 * @since Version 3.2
		 * @version 3.2
		 * @param int $operator_id
		 */
		
		public function fetch($operator_id = false) {
			if (!$operator_id) {
				throw new Exception("No operator ID provided"); 
				return false;
			}
			
			// Fetch the data
			if ($this->db instanceof \sql_db) {
				$query = "SELECT * FROM operators WHERE operator_id = ".$this->db->real_escape_string($operator_id); 
				
				if ($rs = $this->db->query($query)) {
					$row = $rs->fetch_assoc(); 
					
					$this->id 		= $operator_id; 
					$this->name		= $row['operator_name']; 
					$this->organisation_id = $row['organisation_id']; 
					
					return true;
				} else {
					throw new Exception($this->db->error."\n".$query);
					return false;
				}
			} else {
				$query = "SELECT * FROM operators WHERE operator_id = ?";
				
				$row = $this->db->fetchRow($query, $operator_id);
				$this->id 		= $operator_id; 
				$this->name		= $row['operator_name']; 
				$this->organisation_id = $row['organisation_id']; 
				$this->url_operator = "/locos/browse/operator/" . $this->id;
				$this->url_owner = "/locos/browse/owner/" . $this->id;
				
				$this->url = new Url(sprintf("/locos/browse/operator/%d", $this->id));
				$this->url->operator = sprintf("/locos/browse/operator/%d", $this->id);
				$this->url->owner = sprintf("/locos/browse/owner/%d", $this->id);
				
				return true;
			}
		}
		
		/**
		 * Verify the changes before committing them
		 * @since Version 3.2
		 * @return boolean
		 */
		
		public function validate() {
			if (empty($this->name)) {
				throw new Exception("Cannot validate Operator: the operator name cannot be empty");
			}
			
			if (!filter_var($this->organisation_id)) {
				$this->organisation_id = 0;
			}
			
			return true;
		}
		
		/**
		 * Commit the changes
		 * @since Version 3.2
		 * @version 3.2
		 * @return boolean
		 */
		
		public function commit() {
			
			$this->validate();
			
			if ($this->db instanceof \sql_db) {
				$dataArray = array(); 
				$dataArray['operator_name'] 	= $this->db->real_escape_string($this->name); 
				$dataArray['organisation_id']	= $this->db->real_escape_string($this->organisation_id); 
				
				if (!empty($this->id)) {
					$where = array("operator_id" => $this->id);
					
					$query = $this->db->buildQuery($dataArray, "operators", $where); 
				} else {
					$query = $this->db->buildQuery($dataArray, "operators"); 
				}
				
				if ($rs = $this->db->query($query)) {
{'fraction_non_alphanumeric': 0.16664414110014866, 'fraction_numerical': 0.009866198134883092, 'mean_word_length': 2.391384051329056, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 105, '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': '4701761', 'n_tokens_mistral': 3298, 'n_tokens_neox': 2459, 'n_words': 540}