Location: PHPKode > projects > Aukyla Document Management System > adms2/apps/ADMS/History.php
<?php
/*
     History.php, keeps track of the last added documents
     Copyright (C) 2004-2005 Arend van Beelen, Auton Rijnsburg

     This program is free software; you can redistribute it and/or modify it
     under the terms of the GNU General Public License as published by the Free
     Software Foundation; either version 2 of the License, or (at your option)
     any later version.

     This program is distributed in the hope that it will be useful, but WITHOUT
     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
     more details.

     You should have received a copy of the GNU General Public License along
     with this program; if not, write to the Free Software Foundation, Inc.,
     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

     For any questions, comments or whatever, you may mail me at: hide@address.com
*/

require_once('Config.php');
require_once('Database.php');

class ADMS_HistoryEntry
{
	public $document;
	public $timeCreated;
	public $timeModified;
}

class ADMS_History
{
	public static function createdSince($time, $maxEntries = 20)
	{
		self::openDatabase();

		$query = 'SELECT D.uri, M.value '.
		         'FROM Documents D, MetaData M '.
		         "WHERE D.did = M.did AND M.key = 'ctime' AND M.value > '$time' ".
		         'ORDER BY M.value DESC '.
		         "LIMIT $maxEntries;";

		self::$database->query($query);

		$entries = array();
		for($i = 0; $i < ADMS_History::$database->numberOfRows(); $i++)
		{
			$row = ADMS_History::$database->resultArray();

			$entry = $entries[] = new ADMS_HistoryEntry;
			$entry->document = $row[0];
			$entry->timeCreated = $row[1];
		}

		return $entries;
	}

	public static function modifiedSince($time, $maxEntries = 20)
	{
		self::openDatabase();

		$query = 'SELECT D.uri, M.value '.
		         'FROM Documents D, MetaData M '.
		         "WHERE D.did = M.did AND M.key = 'mtime' AND M.value > '$time' ".
		         'ORDER BY M.value '.
		         "LIMIT $maxEntries;";

		ADMS_History::$database->query($query);

		$entries = array();
		for($i = 0; $i < ADMS_History::$database->numberOfRows(); $i++)
		{
			$row = ADMS_History::$database->resultArray();

			$entry = $entries[] = new ADMS_HistoryEntry;
			$entry->document = $row[0];
			$entry->timeModified = $row[1];
		}

		return $entries;
	}

	private static function openDatabase()
	{
		if(self::$database !== null)
		{
			return;
		}

		$databaseType = Config::globals('searchDatabaseType');
		$server =       Config::globals('searchDatabaseServer');
		$database =     Config::globals('searchDatabaseName');
		$username =     Config::globals('searchDatabaseUsername');
		$password =     Config::globals('searchDatabasePassword');

		self::$database = Database::connection($databaseType, $server, $database, $username, $password);
		if(self::$database === false)
		{
			die("Could not connect to search database at $server!\n");
		}
	}

	private static $database = null;
}

?>
Return current item: Aukyla Document Management System