From 970cbca7f3df553e44971726c96817e3b98a3e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Nicolaysen=20S=C3=B8rnes?= Date: Wed, 4 Apr 2007 00:30:42 +0000 Subject: [PATCH] Add and use version::objectGetEntriesCount(). Only display the user menu's 'view rejected apps' link for non-admins --- include/sidebar_admin.php | 4 +- include/sidebar_login.php | 8 ++-- include/sidebar_maintainer_admin.php | 2 +- include/user.php | 57 ----------------------- include/version.php | 68 ++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 62 deletions(-) diff --git a/include/sidebar_admin.php b/include/sidebar_admin.php index b56dc9b..91aa720 100644 --- a/include/sidebar_admin.php +++ b/include/sidebar_admin.php @@ -12,7 +12,7 @@ function global_admin_menu() { $g->add("View App Queue (".application::objectGetEntriesCount(true, false).")", BASE."objectManager.php?sClass=application&bIsQueue=true&sTitle=". "Application%20Queue"); - $g->add("View Version Queue (".$_SESSION['current']->getQueuedVersionCount().")", + $g->add("View Version Queue (".version::objectGetEntriesCount(true, false).")", BASE."admin/adminAppQueue.php"); $g->add("View Screenshot Queue (".appData::objectGetEntriesCount("true", false, "screenshot").")", @@ -45,6 +45,8 @@ function global_admin_menu() { true).")", BASE."objectManager.php?sClass=application&bIsQueue=true&bIsRejected=true&". "sTitle=Rejected%20Applications"); + $g->add("View Rejected Versions (".version::objectGetEntriesCount(true, true).")", + BASE."appsubmit.php"); $g->add("View Rejected Test Results (".testData::objectGetEntriesCount(true, true).")", BASE."objectManager.php?sClass=testData&bIsQueue=true&bIsRejected=true&". diff --git a/include/sidebar_login.php b/include/sidebar_login.php index 57aa9cd..6d2cb94 100644 --- a/include/sidebar_login.php +++ b/include/sidebar_login.php @@ -34,9 +34,11 @@ function global_sidebar_login() { $g->addmisc(version::fullNameLink($versionId), "center"); } } - $appsRejected = $_SESSION['current']->getAllRejectedApps(); - if($appsRejected) - $g->addmisc("Review Rejected Apps", "center"); + $iAppsRejected = application::objectGetEntriesCount(true, true) + + version::objectGetEntriesCount(true, true); + if($iAppsRejected && !$_SESSION['current']->hasPriv("admin")) + $g->addmisc("Review Rejected Apps ". + "($iAppsRejected)", "center"); $aMonitored = Monitor::getVersionsMonitored($_SESSION['current']); if($aMonitored) diff --git a/include/sidebar_maintainer_admin.php b/include/sidebar_maintainer_admin.php index 074c69c..af45d4e 100644 --- a/include/sidebar_maintainer_admin.php +++ b/include/sidebar_maintainer_admin.php @@ -7,7 +7,7 @@ function global_maintainer_admin_menu() { $g = new htmlmenu("Maintainer Admin"); - $g->add("View Version Queue (".$_SESSION['current']->getQueuedVersionCount().")", + $g->add("View Version Queue (".version::objectGetEntriesCount(true, false).")", BASE."admin/adminAppQueue.php"); $g->add("View Screenshot Queue (".appData::objectGetEntriesCount("true", false, "screenshot").")", diff --git a/include/user.php b/include/user.php index f4936d0..8a91bb1 100644 --- a/include/user.php +++ b/include/user.php @@ -265,40 +265,6 @@ class User { return Maintainer::isUserSuperMaintainer($this, $iAppId); } - /* get the number of queued applications */ - function getQueuedAppCount() - { - /* return 0 because non-admins have no way to process new apps */ - if(!$this->hasPriv("admin")) - return 0; - - $sQuery = "SELECT count(*) as queued_apps FROM appFamily WHERE queued='true'"; - $hResult = query_parameters($sQuery); - $oRow = mysql_fetch_object($hResult); - return $oRow->queued_apps; - } - - function getQueuedVersionCount() - { - if($this->hasPriv("admin")) - { - $hResult = query_parameters("SELECT count(*) as queued_versions FROM appVersion WHERE queued='true'"); - } else - { - /* find all queued versions of applications that the user is a super maintainer of */ - $hResult = query_parameters("SELECT count(*) as queued_versions FROM appVersion, appMaintainers - WHERE appVersion.queued='true' AND appMaintainers.superMaintainer ='1' - AND appVersion.appId = appMaintainers.appId - AND appMaintainers.userId ='?'", $this->iUserId); - } - - $oRow = mysql_fetch_object($hResult); - - /* we don't want to count the versions that are implicit in the applications */ - /* that are in the queue */ - return $oRow->queued_versions - $this->getQueuedAppCount(); - } - function addPriv($sPriv) { if(!$this->isLoggedIn() || !$sPriv) @@ -500,29 +466,6 @@ class User { return query_appdb($sQuery); } - function getAllRejectedApps() - { - $hResult = query_parameters("SELECT appVersion.versionId, appFamily.appId - FROM appVersion, appFamily - WHERE appFamily.appId = appVersion.appId - AND (appFamily.queued = 'rejected' OR appVersion.queued = 'rejected') - AND appVersion.submitterId = '?'", - $this->iUserId); - - if(!$hResult || mysql_num_rows($hResult) == 0) - return; - - $retval = array(); - $c = 0; - while($oRow = mysql_fetch_object($hResult)) - { - $retval[$c] = array($oRow->appId, $oRow->versionId); - $c++; - } - - return $retval; - } - function isAppSubmitter($iAppId) { $hResult = query_parameters("SELECT appId FROM appFamily diff --git a/include/version.php b/include/version.php index 4295b0b..f5d0de4 100644 --- a/include/version.php +++ b/include/version.php @@ -1152,6 +1152,74 @@ class Version { $this->sName.""; return $sLink; } + + function objectGetEntriesCount($bQueued, $bRejected) + { + $sQueued = objectManager::getQueueString($bQueued, $bRejected); + + if($bQueued && !version::canEdit()) + { + /* Users should see their own rejected entries */ + if($bRejected) + $sIncludeUserSubmissions = "OR appVersion.submitterId = '". + $_SESSION['current']->iUserId."'"; + + $sQuery = "SELECT COUNT(DISTINCT appVersion.versionId) as count FROM + appVersion, appMaintainers, appFamily WHERE + appFamily.appId = appVersion.appId + AND + appFamily.queued = 'false' + AND + ( + ( + ( + ( + appMaintainers.appId = appVersion.appId + AND + superMaintainer = '1' + ) + OR + ( + appMaintainers.versionId = appVersion.versionId + AND + superMaintainer = '0' + ) + ) + AND + appMaintainers.userId = '?' + AND + appMaintainers.queued = 'false' + ) + $sIncludeUserSubmissions + ) + AND + appVersion.queued = '?'"; + $hResult = query_parameters($sQuery, $_SESSION['current']->iUserId, $sQueued); + } else + { + $sQuery = "SELECT COUNT(DISTINCT versionId) as count + FROM appVersion, appFamily WHERE + appFamily.appId = appVersion.appId + AND + appFamily.queued = 'false' + AND + appVersion.queued = '?'"; + $hResult = query_parameters($sQuery, $sQueued); + } + + if(!$hResult) + return FALSE; + + if(!$oRow = mysql_fetch_object($hResult)) + return FALSE; + + return $oRow->count; + } + + function canEdit() + { + return $_SESSION['current']->hasPriv("admin"); + } } ?>