From 89c50400de72996b2e7021faad1f8e755c53599e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Nicolaysen=20S=C3=B8rnes?= Date: Mon, 30 Jul 2007 01:22:55 +0000 Subject: [PATCH] Add objectManager support to the monitor class --- include/monitor.php | 121 +++++++++++++++++++++++++++++++--- unit_test/test_om_objects.php | 2 + 2 files changed, 113 insertions(+), 10 deletions(-) diff --git a/include/monitor.php b/include/monitor.php index 0bcf59b..222d1ac 100644 --- a/include/monitor.php +++ b/include/monitor.php @@ -19,22 +19,26 @@ class Monitor { * Constructor. * If $iMonitorId is provided, fetches Monitor. */ - function Monitor($iMonitorId="") + function Monitor($iMonitorId="", $oRow = null) { - if($iMonitorId) + if(!$iMonitorId && !$oRow) + return; + + if(!$oRow) { $sQuery = "SELECT * FROM appMonitors WHERE monitorId = '".$iMonitorId."'"; $hResult = query_appdb($sQuery); $oRow = mysql_fetch_object($hResult); - if($oRow) - { - $this->iMonitorId = $oRow->monitorId; - $this->iAppId = $oRow->appId; - $this->iVersionId = $oRow->versionId; - $this->iUserId = $oRow->userId; - } + } + + if($oRow) + { + $this->iMonitorId = $oRow->monitorId; + $this->iAppId = $oRow->appId; + $this->iVersionId = $oRow->versionId; + $this->iUserId = $oRow->userId; } } @@ -98,8 +102,12 @@ class Monitor { $hResult = query_parameters("DELETE FROM appMonitors WHERE monitorId = '?'", $this->iMonitorId); if(!$bSilent) $this->SendNotificationMail("delete"); - } + if(!$hResult) + return FALSE; + + return TRUE; + } function SendNotificationMail($sAction="add",$sMsg=null) { @@ -139,6 +147,99 @@ class Monitor { mail_appdb($sEmail, $sSubject ,$sMsg); } + function canEdit() + { + if($_SESSION['current']->hasPriv("admin") || + ($this->iUserId == $_SESSION['current']->iUserId)) + return TRUE; + + return FALSE; + } + + function mustBeQueued() + { + return FALSE; + } + + /* Stub */ + function display() + { + return ""; + } + + /* Stub */ + function getOutputEditorValues() + { + return FALSE; + } + + /* Stub */ + function objectGetHeader() + { + return null; + } + + function objectGetId() + { + return $this->iMonitorId; + } + + /* Stub */ + function objectGetTableRow() + { + return null; + } + + /* Stub */ + function objectMakeLink() + { + return ""; + } + + /* Stub */ + function objectMakeUrl() + { + return ""; + } + + /* Stub */ + function outputEditor() + { + return ""; + } + + function objectGetEntries($bQueued, $bRejected) + { + $hResult = query_parameters("SELECT * FROM appMonitors"); + + if(!$hResult) + return FALSE; + + return $hResult; + } + + function objectGetEntriesCount($bQueued, $bRejected) + { + $hResult = query_parameters("SELECT COUNT(DISTINCT monitorId) as count + FROM appMonitors"); + + if(!$hResult) + return FALSE; + + $oRow = mysql_fetch_object($hResult); + + if(!$oRow) + return FALSE; + + return $oRow->count; + } + + function allowAnonymousSubmissions() + { + /* That makes no sense */ + return FALSE; + } + /* Retrieve the user's monitored versions */ function getVersionsMonitored($oUser) { diff --git a/unit_test/test_om_objects.php b/unit_test/test_om_objects.php index b49427e..0655c99 100644 --- a/unit_test/test_om_objects.php +++ b/unit_test/test_om_objects.php @@ -11,6 +11,7 @@ require_once(BASE.'include/testData_queue.php'); require_once(BASE.'include/version_queue.php'); require_once(BASE.'include/application_queue.php'); require_once(BASE.'include/browse_newest_apps.php'); +require_once(BASE.'include/monitor.php'); /* internal function */ function test_class($sClassName, $aTestMethods) @@ -252,6 +253,7 @@ function test_object_methods() "distribution", "downloadurl", "maintainer", + "monitor", "note", "screenshot", "testData",