Add the ability to browse applications by rating and a unit test for the added Application::getWithRating()
This commit is contained in:
182
browse_by_rating.php
Normal file
182
browse_by_rating.php
Normal file
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
/**
|
||||
* Browse Applications by their respective ratings
|
||||
*
|
||||
*/
|
||||
|
||||
// application environment
|
||||
require("path.php");
|
||||
require(BASE."include/incl.php");
|
||||
require(BASE."include/filter.php");
|
||||
require_once(BASE."include/application.php");
|
||||
|
||||
apidb_header("Browse Applications by Rating");
|
||||
|
||||
$sPathtrail = "<a href=\"browse_by_rating.php\">Main</a>";
|
||||
|
||||
echo html_frame_start("", '98%', '', 2);
|
||||
|
||||
if (empty($aClean['sRating']))
|
||||
{
|
||||
echo "<b>Rating: $sPathtrail</b>";
|
||||
echo html_frame_end();
|
||||
echo html_frame_start("", '98%', '', 2);
|
||||
echo "<table width=100% border=0 cellspacing=1 cellpadding=3\n";
|
||||
echo " <tr class=color4>\n";
|
||||
echo " <td><b>Rating</b></td>\n";
|
||||
echo " <td><b>Description</b></td>\n";
|
||||
echo " <td><b>No. Apps</b></td>\n";
|
||||
echo " </tr>\n";
|
||||
html_tr_highlight_clickable("browse_by_rating.php?sRating=".PLATINUM_RATING, "platinum", "platinum", "platinum");
|
||||
echo " <td><a href=\"browse_by_rating.php?sRating=".PLATINUM_RATING."\">Platinum</a></td>";
|
||||
echo " <td>Applications that install and run out of the box</td>\n";
|
||||
echo " <td>".Application::countWithRating(PLATINUM_RATING)."</td>\n";
|
||||
echo " </tr>\n";
|
||||
html_tr_highlight_clickable("browse_by_rating.php?sRating=".GOLD_RATING, "gold", "gold", "gold");
|
||||
echo " <td><a href=\"browse_by_rating.php?sRating=".GOLD_RATING."\">Gold</a></td>";
|
||||
echo " <td>Applications that work flawlessly with some DLL overrides or other settings, crack etc.</td>\n";
|
||||
echo " <td>".Application::countWithRating(GOLD_RATING)."</td>\n";
|
||||
echo " </tr>\n";
|
||||
html_tr_highlight_clickable("browse_by_rating.php?sRating=".SILVER_RATING, "silver", "silver", "silver");
|
||||
echo " <td><a href=\"browse_by_rating.php?sRating=".SILVER_RATING."\">Silver</a></td>";
|
||||
echo " <td>Applications that work excellently for 'normal use'</td>\n";
|
||||
echo " <td>".Application::countWithRating(SILVER_RATING)."</td>\n";
|
||||
echo " </tr>\n";
|
||||
html_tr_highlight_clickable("browse_by_rating.php?sRating=".BRONZE_RATING, "bronze", "bronze", "bronze");
|
||||
echo " <td><a href=\"browse_by_rating.php?sRating=".BRONZE_RATING."\">Bronze</a></td>";
|
||||
echo " <td>Applications that work but have some issues, even for 'normal use'</td>\n";
|
||||
echo " <td>".Application::countWithRating(BRONZE_RATING)."</td>\n";
|
||||
echo " </tr>\n";
|
||||
html_tr_highlight_clickable("browse_by_rating.php?sRating=".GARBAGE_RATING, "garbage", "garbage", "garbage");
|
||||
echo " <td><a href=\"browse_by_rating.php?sRating=".GARBAGE_RATING."\">Garbage</a></td>";
|
||||
echo " <td>Applications that don't work as intended, there should be at least one bug report if an app gets this rating</td>\n";
|
||||
echo " <td>".Application::countWithRating(GARBAGE_RATING)."</td>\n";
|
||||
echo " </tr>\n";
|
||||
echo "</table>\n";
|
||||
|
||||
echo html_frame_end();
|
||||
} else
|
||||
{
|
||||
/* display a range of 10 pages */
|
||||
$iPageRange = 10;
|
||||
$iItemsPerPage = 50;
|
||||
$iCurrentPage = 1;
|
||||
|
||||
if($aClean['iItemsPerPage'])
|
||||
$iItemsPerPage = $aClean['iItemsPerPage'];
|
||||
if($aClean['iPage'])
|
||||
$iCurrentPage = $aClean['iPage'];
|
||||
|
||||
$iItemsPerPage = min($iItemsPerPage,500);
|
||||
|
||||
switch($aClean['sRating'])
|
||||
{
|
||||
case PLATINUM_RATING:
|
||||
$sPathtrail.=" > <a href=\"browse_by_rating.php?sRating=".PLATINUM_RATING."\">Platinum</a>";
|
||||
$iTotalPages = ceil(Application::countWithRating(PLATINUM_RATING)/$iItemsPerPage);
|
||||
$sRating = PLATINUM_RATING;
|
||||
break;
|
||||
|
||||
case GOLD_RATING:
|
||||
$sPathtrail.=" > <a href=\"browse_by_rating.php?sRating=".GOLD_RATING."\">Gold</a>";
|
||||
$iTotalPages = ceil(Application::countWithRating(GOLD_RATING)/$iItemsPerPage);
|
||||
$sRating = GOLD_RATING;
|
||||
break;
|
||||
|
||||
case SILVER_RATING:
|
||||
$sPathtrail.=" > <a href=\"browse_by_rating.php?sRating=".SILVER_RATING."\">Silver</a>";
|
||||
$iTotalPages = ceil(Application::countWithRating(SILVER_RATING)/$iItemsPerPage);
|
||||
$sRating = SILVER_RATING;
|
||||
break;
|
||||
case BRONZE_RATING:
|
||||
$sPathtrail.=" > <a href=\"browse_by_rating.php?sRating=".BRONZE_RATING."\">Bronze</a>";
|
||||
$iTotalPages = ceil(Application::countWithRating(BRONZE_RATING)/$iItemsPerPage);
|
||||
$sRating = BRONZE_RATING;
|
||||
break;
|
||||
case GARBAGE_RATING:
|
||||
$sPathtrail.=" > <a href=\"browse_by_rating.php?sRating=".GARBAGE_RATING."\">Garbage</a>";
|
||||
$iTotalPages = ceil(Application::countWithRating(GARBAGE_RATING)/$iItemsPerPage);
|
||||
$sRating=GARBAGE_RATING;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$iCurrentPage = min($iCurrentPage,$iTotalPages);
|
||||
$iOffset = (($iCurrentPage-1) * $iItemsPerPage);
|
||||
$apps=Application::getWithRating($sRating, $iOffset, $iItemsPerPage);
|
||||
|
||||
echo "<b>Rating: $sPathtrail</b><p>";
|
||||
echo html_frame_end();
|
||||
|
||||
|
||||
|
||||
|
||||
/* display page selection links */
|
||||
echo "<center>";
|
||||
echo "<b>Page $iCurrentPage of $iTotalPages</b><br />";
|
||||
display_page_range($iCurrentPage, $iPageRange, $iTotalPages,
|
||||
$_SERVER['PHP_SELF']."?sRating=".$aClean['sRating']."&iItemsPerPage=".$iItemsPerPage);
|
||||
echo "<br />";
|
||||
echo "<br />";
|
||||
|
||||
/* display the option to choose how many applications per-page to display */
|
||||
echo '<form method="get" name="message" action="'.$_SERVER['PHP_SELF'].'">';
|
||||
echo '<b>Number of Applications per page:</b>';
|
||||
echo " <select name='iItemsPerPage'>";
|
||||
|
||||
$iItemsPerPageArray = array(50, 100, 150, 200, 250, 300, 350, 400, 450, 500);
|
||||
foreach($iItemsPerPageArray as $i => $value)
|
||||
{
|
||||
if($iItemsPerPageArray[$i] == $iItemsPerPage)
|
||||
echo "<option value='$iItemsPerPageArray[$i]' SELECTED>$iItemsPerPageArray[$i]";
|
||||
else
|
||||
echo "<option value='$iItemsPerPageArray[$i]'>$iItemsPerPageArray[$i]";
|
||||
}
|
||||
echo "</select>";
|
||||
|
||||
echo "<input type=hidden name=iPage value=$iCurrentPage>";
|
||||
echo "<input type=hidden name=sRating value=".$aClean['sRating'].">";
|
||||
echo " <input type=submit value='Refresh'>";
|
||||
echo "</form>";
|
||||
echo "</center>";
|
||||
|
||||
echo html_frame_start("","98%","",0);
|
||||
echo "<table width='100%' border=0 cellpadding=3 cellspacing=1>\n\n";
|
||||
|
||||
echo "<tr class=color4>\n";
|
||||
echo " <td><b>Application Name</b></td>\n";
|
||||
echo " <td><b>Description</b></td>\n";
|
||||
echo " <td><b>No. Versions</b></td>\n";
|
||||
echo "</tr>\n\n";
|
||||
|
||||
while(list($i, $iAppId) = each($apps))
|
||||
{
|
||||
$oApp = new Application($iAppId);
|
||||
|
||||
//set row color
|
||||
$bgcolor = ($i % 2) ? "color0" : "color1";
|
||||
|
||||
//format desc
|
||||
$desc = util_trim_description($oApp->sDescription);
|
||||
|
||||
//display row
|
||||
echo "<tr class=$bgcolor>\n";
|
||||
echo " <td><a href='appview.php?iAppId=$iAppId&sRating=".$aClean['sRating']."'>".$oApp->sName."</a></td>\n";
|
||||
echo " <td>$desc </td>\n";
|
||||
echo " <td>".sizeof($oApp->aVersionsIds)."</td>\n";
|
||||
echo "</tr>\n\n";
|
||||
}
|
||||
|
||||
echo "</table>\n\n";
|
||||
|
||||
echo html_frame_end();
|
||||
echo "<center>";
|
||||
display_page_range($iCurrentPage, $iPageRange, $iTotalPages,
|
||||
$_SERVER['PHP_SELF']."?sRating=".$aClean['sRating']."&iItemsPerPage=".$iItemsPerPage);
|
||||
echo "</center>";
|
||||
}
|
||||
|
||||
|
||||
apidb_footer();
|
||||
|
||||
?>
|
||||
@@ -9,6 +9,14 @@ require_once(BASE."include/category.php");
|
||||
require_once(BASE."include/url.php");
|
||||
require_once(BASE."include/util.php");
|
||||
require_once(BASE."include/mail.php");
|
||||
|
||||
define("PLATINUM_RATING", "Platinum");
|
||||
define("GOLD_RATING", "Gold");
|
||||
define("SILVER_RATING", "Silver");
|
||||
define("BRONZE_RATING", "Bronze");
|
||||
define("GARBAGE_RATING", "Garbage");
|
||||
|
||||
|
||||
/**
|
||||
* Application class for handling applications.
|
||||
*/
|
||||
@@ -358,6 +366,38 @@ class Application {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function countWithRating($sRating)
|
||||
{
|
||||
$sQuery = "SELECT DISTINCT count(appId) as total
|
||||
FROM appVersion
|
||||
WHERE maintainer_rating = '?'";
|
||||
|
||||
if($hResult = query_parameters($sQuery, $sRating))
|
||||
{
|
||||
$oRow = mysql_fetch_object($hResult);
|
||||
}
|
||||
return $oRow->total;
|
||||
}
|
||||
|
||||
function getWithRating($sRating, $iOffset, $iItemsPerPage)
|
||||
{
|
||||
$aApps = array();
|
||||
$sQuery = "SELECT DISTINCT appId
|
||||
FROM appVersion
|
||||
WHERE maintainer_rating = '?'
|
||||
ORDER BY appId ASC LIMIT ?, ?";
|
||||
|
||||
if($hResult = query_parameters($sQuery, $sRating, $iOffset, $iItemsPerPage))
|
||||
{
|
||||
while($aRow = mysql_fetch_row($hResult))
|
||||
{
|
||||
array_push($aApps, $aRow[0]);
|
||||
}
|
||||
}
|
||||
return $aApps;
|
||||
}
|
||||
|
||||
function SendNotificationMail($sAction="add",$sMsg=null)
|
||||
{
|
||||
$aClean = array(); //array of filtered user input
|
||||
|
||||
@@ -23,6 +23,7 @@ function global_sidebar_menu() {
|
||||
$g->add("AppDB Home", BASE);
|
||||
$g->add("Screenshots", BASE."viewScreenshots.php");
|
||||
$g->add("Browse Apps", BASE."appbrowse.php");
|
||||
$g->add("Browse Apps by Rating", BASE."browse_by_rating.php");
|
||||
$g->add("Top 25", BASE."votestats.php");
|
||||
$g->add("Submit Application", BASE."appsubmit.php?sSub=view&sAppType=application");
|
||||
$g->add("Help & Documentation", BASE."help/");
|
||||
|
||||
@@ -88,7 +88,7 @@ If you have screenshots or links to contribute, please browse the database and u
|
||||
|
||||
<p>This is a list of applications that are known to be working well and for which many AppDB users voted.</p>
|
||||
|
||||
<h3>The top-10 Platinum List</h3>
|
||||
<h3>The top-10 <a href="browse_by_rating.php?sRating=Platinum">Platinum</a> List</h3>
|
||||
<p>Only Applications which install and run flawless on a out-of-the-box Wine installation make it to the Platinum list: </p>
|
||||
<table class="platinum">
|
||||
<tr class="rowtitle">
|
||||
@@ -100,7 +100,7 @@ If you have screenshots or links to contribute, please browse the database and u
|
||||
</table>
|
||||
<br />
|
||||
|
||||
<h3>The top-10 Gold List</h3>
|
||||
<h3>The top-10 <a href="browse_by_rating.php?sRating=Gold">Gold</a> List</h3>
|
||||
<p>Applications that work flawlessly with some DLL overrides or other settings, crack etc make it to the Gold list: </p>
|
||||
<table class="gold">
|
||||
<tr class="rowtitle">
|
||||
@@ -112,7 +112,7 @@ If you have screenshots or links to contribute, please browse the database and u
|
||||
</table>
|
||||
<br />
|
||||
|
||||
<h3>The top-10 Silver List</h3>
|
||||
<h3>The top-10 <a href="browse_by_rating.php?sRating=Silver">Silver List</a></h3>
|
||||
<p>The Silver list contains apps which we hope we can easily fix so they make it to Gold status:</p>
|
||||
<table class=silver>
|
||||
<tr class=rowtitle>
|
||||
|
||||
@@ -17,38 +17,8 @@ function test_application_delete()
|
||||
{
|
||||
test_start(__FUNCTION__);
|
||||
|
||||
global $test_email, $test_password;
|
||||
|
||||
$oUser = new User();
|
||||
|
||||
/* delete the user if they already exist */
|
||||
if($oUser->login($test_email, $test_password) == SUCCESS)
|
||||
{
|
||||
$oUser->delete();
|
||||
$oUser = new User();
|
||||
}
|
||||
|
||||
/* create the user */
|
||||
$retval = $oUser->create("testemail@somesite.com", "password", "Test user", "20051020");
|
||||
if($retval != SUCCESS)
|
||||
{
|
||||
if($retval == USER_CREATE_EXISTS)
|
||||
echo "The user already exists!\n";
|
||||
else if($retval == USER_LOGIN_FAILED)
|
||||
echo "User login failed!\n";
|
||||
else
|
||||
echo "ERROR: UNKNOWN ERROR!!\n";
|
||||
|
||||
if(!$oUser = create_and_login_user())
|
||||
return false;
|
||||
}
|
||||
|
||||
/* login the user */
|
||||
$retval = $oUser->login($test_email, $test_password);
|
||||
if($retval != SUCCESS)
|
||||
{
|
||||
echo "Got '".$retval."' instead of SUCCESS(".SUCCESS.")\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
/* make this user an admin so we can create applications without having them queued */
|
||||
$hResult = query_parameters("INSERT into user_privs values ('?', '?')",
|
||||
@@ -67,16 +37,12 @@ function test_application_delete()
|
||||
|
||||
$iAppId = $oApp->iAppId; /* use the iAppId of the application we just created */
|
||||
|
||||
$iVersionIdBase = 400000;
|
||||
for($iVersionIdIndex = 0; $iVersionIdIndex < 10; $iVersionIdIndex++)
|
||||
{
|
||||
$iVersionId = $iVersionIdBase + $iVersionIdIndex;
|
||||
|
||||
$oVersion = new Version();
|
||||
$oVersion->versionName = "Some Version".$iVersionId;
|
||||
$oVersion->description = "Some Version description".$iVersionId;
|
||||
$oVersion->versionName = "Some Version".$iVersionIdIndex;
|
||||
$oVersion->description = "Some Version description".$iVersionIdIndex;
|
||||
$oVersion->iAppId = $oApp->iAppId;
|
||||
$oVersion->iVersionId = $iVersionId;
|
||||
|
||||
if(!$oVersion->create())
|
||||
{
|
||||
@@ -107,16 +73,145 @@ function test_application_delete()
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_application_getWithRating()
|
||||
{
|
||||
test_start(__FUNCTION__);
|
||||
|
||||
if(!$oUser = create_and_login_user())
|
||||
return false;
|
||||
|
||||
/* make this user an admin so we can create applications without having them queued */
|
||||
$hResult = query_parameters("INSERT into user_privs values ('?', '?')",
|
||||
$oUser->iUserId, "admin");
|
||||
|
||||
$oApp = new Application();
|
||||
$oApp->sName = "Some application";
|
||||
$oApp->sDescription = "some description";
|
||||
$oApp->submitterId = $oUser->iUserId;
|
||||
if(!$oApp->create())
|
||||
{
|
||||
$oUser->delete();
|
||||
echo "Failed to create application!\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
$iAppId = $oApp->iAppId; /* use the iAppId of the application we just created */
|
||||
|
||||
|
||||
/* Create several versions of the new application to test uniqueness of getWithRating() results */
|
||||
|
||||
for($iVersionIdIndex = 0; $iVersionIdIndex < 10; $iVersionIdIndex++)
|
||||
{
|
||||
$oVersion = new Version();
|
||||
$oVersion->versionName = "Some Version".$iVersionIdIndex;
|
||||
$oVersion->description = "Some Version description".$iVersionIdIndex;
|
||||
$oVersion->iAppId = $oApp->iAppId;
|
||||
|
||||
|
||||
/* Create Several Ratings, some duplicate */
|
||||
if ($iVersionIdIndex < 4)
|
||||
{
|
||||
$oVersion->sTestedRating = "Platinum";
|
||||
}
|
||||
elseif ($iVersionIdIndex < 8)
|
||||
{
|
||||
$oVersion->sTestedRating = "Gold";
|
||||
}
|
||||
else
|
||||
{
|
||||
$oVersion->sTestedRating = "Bronze";
|
||||
}
|
||||
|
||||
if(!$oVersion->create())
|
||||
{
|
||||
delete_app_and_user($oApp, $oUser);
|
||||
echo "Failed to create version!\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$iItemsPerPage = 50;
|
||||
$iOffset = 0;
|
||||
$sRating = 'Bronze';
|
||||
$aApps=Application::getWithRating($sRating, $iOffset, $iItemsPerPage);
|
||||
$aTest = array();//array to test the uniqueness our query results
|
||||
while(list($i, $iId) = each($aApps)) //cycle through results returned by getWithRating
|
||||
{
|
||||
if ( in_array($iId, $aTest) ) //if the appId is already in our test results fail unique test
|
||||
{
|
||||
delete_app_and_user($oApp, $oUser);
|
||||
echo "getWithRating failed to return a unique result set\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
array_push($aTest, $iId); //push the appId on to our test array
|
||||
|
||||
}
|
||||
|
||||
|
||||
delete_app_and_user($oApp, $oUser);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function delete_app_and_user($oApp, $oUser)
|
||||
{
|
||||
$oApp->delete();
|
||||
$oUser->delete();
|
||||
}
|
||||
|
||||
function create_and_login_user()
|
||||
{
|
||||
global $test_email, $test_password;
|
||||
|
||||
$oUser = new User();
|
||||
|
||||
/* delete the user if they already exist */
|
||||
if($oUser->login($test_email, $test_password) == SUCCESS)
|
||||
{
|
||||
$oUser->delete();
|
||||
$oUser = new User();
|
||||
}
|
||||
|
||||
/* create the user */
|
||||
$retval = $oUser->create("$test_email", "$test_password", "Test user", "20051020");
|
||||
if($retval != SUCCESS)
|
||||
{
|
||||
if($retval == USER_CREATE_EXISTS)
|
||||
echo "The user already exists!\n";
|
||||
else if($retval == USER_LOGIN_FAILED)
|
||||
echo "User login failed!\n";
|
||||
else
|
||||
echo "ERROR: UNKNOWN ERROR!!\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* login the user */
|
||||
$retval = $oUser->login($test_email, $test_password);
|
||||
if($retval != SUCCESS)
|
||||
{
|
||||
echo "Got '".$retval."' instead of SUCCESS(".SUCCESS.")\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
return $oUser;
|
||||
|
||||
}
|
||||
|
||||
if(!test_application_delete())
|
||||
echo "test_application_delete() failed!\n";
|
||||
else
|
||||
echo "test_application_delete() passed!\n";
|
||||
|
||||
|
||||
if(!test_application_getWithRating())
|
||||
echo "test_application_getWithRating() failed!\n";
|
||||
else
|
||||
echo "test_application_getWithRating() passed!\n";
|
||||
|
||||
?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user