<commit_before><?php
/**
 * timeModel model class
 * 
 * @author <NAME> <<EMAIL>>
 * @since 0.0.4
 */

/**
 * timeModel
 *
 * Access-Start is a k/v pair stored in the radcheck table. k is Access-Start, v is int of UNIX timestamp
 * Access-Period is a k/v pair stored in the radcheck table. k is Access-Period, v is int of UNIX timestamp
 *
 * @author <NAME> <<EMAIL>>
 * @since 0.0.1
 */
require_once (__DIR__.'/base_model.php');



class timeModel extends baseModel {

	private $datetime;

	public function __construct() {
		parent::__construct();

		$this->datetime = new Datetime;
	}

	/**
	 * Add a session-start entry to the RADIUS server TBO
	 *
	 *@author <NAME> <<EMAIL>>
	 *@date 2014-01-22
	 *@param object $param_data [required]
	 *@return boolean
	 */
	public function createTime($param_data) {

		try {
			# New Session-Start & #Session-Expire rows
			$query = "			
				INSERT INTO `".DB_NAME."`.`".DB_RAD_TABL."`
						( `username`, `attribute`, `op`, `value`)
				VALUES 	( :username, 'Access-Expire', ':=', :value_expire)
			";

			$pstmt = $this->conn->prepare($query);

		    $pstmt->bindParam(':username'		, $username);
		    $pstmt->bindParam(':value_expire'	, $value_expire);

		    $username 		= $param_data->username;
		    $value_expire	= ($this->datetime->getTimestamp() + $param_data->serviceduration);

		    return $pstmt->execute();

		} catch (Exception $e) {
			$this->logger->AddError("timeModel->createTime() error: ". $e);
			return false;
		}
	}

	/**
	 * Read the expiration date of the users access time
	 */
	public function readTime($username) {
		$return_data = null;
		
		$query = "
			SELECT `username`,`attribute`,`value` FROM `".DB_NAME."`.`".DB_RAD_TABL."`
			WHERE  `username` = '".$username."' AND `attribute` = 'Access-Expire'
		";

	    $qdata = $this->conn->prepare($query);

	    $qdata->execute();
			 
		# Get array containing all of the result rows (should be two)
		$return_data = $qdata->fetchAll(PDO::FETCH_OBJ);

		if (isset($return_data[0]->value)){

			return $return_data[0]->value;
		} else {

			return false;
		}
	}

	/**<commit_msg>Changed FreeRadius attribute to 'Expiration' as per doc's to properly state when a session should end.<commit_after><?php
/**
 * timeModel model class
 * 
 * @author <NAME> <<EMAIL>>
 * @since 0.0.4
 */

/**
 * timeModel
 *
 * Access-Start is a k/v pair stored in the radcheck table. k is Access-Start, v is int of UNIX timestamp
 * Access-Period is a k/v pair stored in the radcheck table. k is Access-Period, v is int of UNIX timestamp
 *
 * @author <NAME> <<EMAIL>>
 * @since 0.0.1
 */
require_once (__DIR__.'/base_model.php');



class timeModel extends baseModel {

	private $datetime;

	public function __construct() {
		parent::__construct();

		$this->datetime = new Datetime;
	}

	/**
	 * Add a session-start entry to the RADIUS server TBO
	 *
	 *@author <NAME> <<EMAIL>>
	 *@date 2014-01-22
	 *@param object $param_data [required]
	 *@return boolean
	 */
	public function createTime($param_data) {

		try {
			# New Session-Start & #Session-Expire rows
			$query = "			
				INSERT INTO `".DB_NAME."`.`".DB_RAD_TABL."`
						( `username`, `attribute`, `op`, `value`)
				VALUES 	( :username, 'Access-Expire', ':=', :value_expire)
			";

			$pstmt = $this->conn->prepare($query);

		    $pstmt->bindParam(':username'		, $username);
		    $pstmt->bindParam(':value_expire'	, $value_expire);

		    $username 		= $param_data->username;
		    $value_expire	= ($this->datetime->getTimestamp() + $param_data->serviceduration);

		    return $pstmt->execute();

		} catch (Exception $e) {
			$this->logger->AddError("timeModel->createTime() error: ". $e);
			return false;
		}
	}

	/**
	 * Read the expiration date of the users access time
	 */
	public function readTime($username) {
		$return_data = null;
		
		$query = "
			SELECT `username`,`attribute`,`value` FROM `".DB_NAME."`.`".DB_RAD_TABL."`
			WHERE  `username` = '".$username."' AND `attribute` = 'Expiration'
		";

	    $qdata = $this->conn->prepare($query);

	    $qdata->execute();
			 
		# Get array containing all of the result rows (should be two)
		$return_data = $qdata->fetchAll(PDO::FETCH_OBJ);

		if (isset($return_data[0]->value)){

			return $return_data[0]->value;
		} else {

			return false;
		}
	}

	/**
{'fraction_non_alphanumeric': 0.16799065420560746, 'fraction_numerical': 0.007476635514018692, 'mean_word_length': 3.2981927710843375, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 59, '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': '1739516', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1438, 'n_words': 369}