<?php defined('SYSPATH') or die('No direct access allowed.');

/**
 *
 * @package    PTA
 * @subpackage Activity Log
 * @category   Models
 * @author     Deon George
 * @copyright  (c) 2010 phpTSMadmin Development Team
 * @license    http://phptsmadmin.sf.net/license.html
 */
class Model_ACTLOG extends ORM_TSM {
	protected $_table_name = 'ACTLOG';
	protected $_primary_key = 'DATE_TIME'; // We need a primary key to detect that the object is loaded.
	protected $_sorting = array(
		'DATE_TIME'=>'ASC',
	);

	protected $_display_filters = array(
		'DATE_TIME'=>array(
			array('ORM_TSM::date',array(':value','d-M H:i')),
		),
	);

	private $_msgno_ba_objects = array(4952,4953,4954,4958,4960,4957,4970,4959,4982);
	private $_msgno_ba_bytes = array(4977,4975,4984,4198,4961);
	private $_msgno_ba_transfer = array(4963,4966,4967,4964);
	private $_msgno_ba_reduction = array(4968,4981,4976);

	/**
	 * Return the timestamp of the record in the ACTLOG
	 */
	public function FirstRec() {
		return DB::query(Database::SELECT,'SELECT min(DATE_TIME) as DATE_TIME from ACTLOG')->cached(86400)->execute()->get('DATE_TIME');
	}

	/**
	 * Where class to exclude NODE backup messages
	 */
	public function ExcludeBA() {
		return $this->where('MSGNO','NOT IN',array_merge($this->_msgno_ba_objects,$this->_msgno_ba_bytes,$this->_msgno_ba_transfer,$this->_msgno_ba_reduction));
	}

	/**
	 * Return this ACTIVITY LOG start time in seconds since epoch
	 */
	public function start() {
		return ORM_TSM::date($this->DATE_TIME,'U');
	}
}
?>
