| Current Path : /home/smartconb/www/armencom33/administrator/components/com_eyesite/models/ |
| Current File : /home/smartconb/www/armencom33/administrator/components/com_eyesite/models/data.php |
<?php
/********************************************************************
Product : Eyesite
Date : 1 December 2023
Copyright : Les Arbres Design 2010-2023
Contact : https://www.lesarbresdesign.info
Licence : GNU General Public License
*********************************************************************/
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\Pagination\Pagination;
class EyesiteModelData extends LAE_model
{
var $_pagination = null;
//-------------------------------------------------------------------------------
// Get the current state
//
function getInfo()
{
$this->totalCount = 0; // initialise all properties in case of a db error
$this->runningCount = 0;
$this->notOkCount = 0;
$this->latest_date = 0;
// get the total number of rows we have
$this->totalCount = $this->ladb_loadResult("Select Count(*) From #__eye_site ");
if ($this->totalCount === false)
{
$this->app->enqueueMessage($this->ladb_error_text, 'error');
return $this->totalCount;
}
// get the number of rows in state running
$this->runningCount = $this->ladb_loadResult("Select Count(*) From #__eye_site Where state = ".LAE_STATE_RUNNING);
if ($this->runningCount === false)
{
$this->app->enqueueMessage($this->ladb_error_text, 'error');
return $this->totalCount;
}
// get the number of rows in not-OK state
$this->notOkCount = $this->ladb_loadResult("Select Count(*) From #__eye_site Where state != ".LAE_STATE_OK);
if ($this->notOkCount === false)
{
$this->app->enqueueMessage($this->ladb_error_text, 'error');
return $this->totalCount;
}
// get the latest run date
$this->latest_date = $this->ladb_loadResult("Select Max(datetime) From #__eye_site_history
Where `state` IN (".LAE_HISTORY_SCAN_NO_CHANGES.", ".LAE_HISTORY_SCAN_CHANGES.", ".LAE_HISTORY_SCAN_ERROR.")");
if ($this->latest_date === false)
{
$this->app->enqueueMessage($this->ladb_error_text, 'error');
return $this->totalCount;
}
return true;
}
//-------------------------------------------------------------------------------
// Build a list of all the outstanding changes
//
function getList()
{
$filter_state = $this->app->getUserStateFromRequest('com_eyesite.filter_state','filter_state',-1);
$limit = $this->app->get('list_limit');
$limitstart = $this->app->getUserStateFromRequest('com_eyesite.limitstart', 'limitstart', 0, 'int');
$limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0); // In case limit has been changed
// build the queries
$query_count = "Select count(*) ";
$query_cols = "Select `id`, `state`, `filepath`, `datetime`, `filesize`, `new_datetime`, `new_filesize` ";
$query_from = "From `#__eye_site` ";
$query_where = "Where `state` != ".LAE_STATE_OK." And `state` != ".LAE_STATE_RUNNING.' ';
$query_order = "Order By `filepath` ";
// if the state filter is not set to "all", change the where clause
if ($filter_state != -1)
$query_where = 'Where `state` = '.$filter_state.' ';
// get the total row count
$total = $this->ladb_loadResult($query_count.$query_from.$query_where);
if ($total === false)
{
$this->app->enqueueMessage($this->ladb_error_text, 'error');
return array();
}
// setup the pagination object
$this->_pagination = new Pagination($total, $limitstart, $limit);
// get the subset (based on limits) of required records
$main_query = $query_cols.$query_from.$query_where.$query_order;
$rows = $this->ladb_loadObjectList($main_query, $this->_pagination->limitstart, $this->_pagination->limit);
if ($rows === false)
{
$this->app->enqueueMessage($this->ladb_error_text, 'error');
return array();
}
return $rows;
}
//-------------------------------------------------------------------------------
// Accept all changes
//
function accept_all()
{
$query = "update `#__eye_site` set state = ".LAE_STATE_OK." where `state` = ".LAE_STATE_NEW;
LAE_trace::trace($query);
$result = $this->ladb_execute($query);
if ($result === false)
{
$this->app->enqueueMessage($this->ladb_error_text, 'error');
return;
}
$rows_affected = $this->db->getAffectedRows();
LAE_trace::trace(" - affected $rows_affected rows");
$query = "delete from `#__eye_site` where `state` = ".LAE_STATE_DELETED;
LAE_trace::trace($query);
$result = $this->ladb_execute($query);
if ($result === false)
{
$this->app->enqueueMessage($this->ladb_error_text, 'error');
return;
}
$rows_affected = $this->db->getAffectedRows();
LAE_trace::trace(" - affected $rows_affected rows");
$query = "update `#__eye_site` set `state` = ".LAE_STATE_OK.", `md5` = `new_md5`, `datetime` = `new_datetime`, `filesize` = `new_filesize` where `state` = ".LAE_STATE_CHANGED;
LAE_trace::trace($query);
$result = $this->ladb_execute($query);
if ($result === false)
{
$this->app->enqueueMessage($this->ladb_error_text, 'error');
return;
}
$rows_affected = $this->db->getAffectedRows();
LAE_trace::trace(" - affected $rows_affected rows");
}
//-------------------------------------------------------------------------------
// Return a pointer to our pagination object
// - should be called after getList() has created the pagination object
//
function getPagination()
{
if ($this->_pagination == Null)
$this->_pagination = new Pagination(0,0,0);
return $this->_pagination;
}
}