mike.morgan%oregonstate.edu 57c40e4799 Added rotating features to the front page. These will be controlled using the "reviews manager" of the existing developer tools.
The rotating feature on the front page assumes that:
    a) there is already a feature that exists -- it barfs when there are zero features in the database for a given application
    b) the main preview (preview='yes' in previews):
        i) exists
        ii) is a reasonable size

Some additions to the reviews manager would be:
    a) adding the "feature" screenshot along with the review so admins have control over what the actual feature looks like
    b) possibly requireing screenshots marked as "preview" to be a certain dimension so we can actually rely on the pixel width assumption


git-svn-id: svn://10.0.0.236/trunk@188458 18797224-902f-48f8-a5cc-f745e15eee43
2006-01-30 08:44:02 +00:00

314 lines
7.8 KiB
PHP

<?php
/**
* AMO master class. This class contains global application logic.
* @todo properly separate accessors and mutators.
* @todo don't store data in this superclass -- strip vars except for tpl/db.
*/
class AMO_Object
{
var $db;
var $tpl;
/**
* AMO_Object constructor.
*/
function AMO_Object() {
// Our DB and Smarty objects are global to save cycles.
global $db, $tpl;
// Pass by reference in order to save memory.
$this->db =& $db;
$this->tpl =& $tpl;
}
/**
* Set var.
*
* @param string $key name of object property to set
* @param mixed $val value to assign
*
* @return bool
*/
function setVar($key,$val)
{
$this->$key = $val;
return true;
}
/**
* Set an array of variables based on a $db record.
*
* @param array $data associative array of data.
*
* @return bool
*/
function setVars($data)
{
if (is_array($data)) {
foreach ($data as $key=>$val) {
$this->setVar($key,$val);
}
return true;
} else {
return false;
}
}
/**
* Get all category names.
*
* @return array
*/
function getCats($type=null)
{
if (!empty($type)) {
$typesql = " WHERE cattype='{$type}' ";
} else {
$typesql = '';
}
// Gather categories.
$this->db->query("
SELECT DISTINCT
CategoryID,
CatName
FROM
categories
{$typesql}
GROUP BY
CatName
ORDER BY
CatName
", SQL_INIT, SQL_ASSOC);
do {
$retval[$this->db->record['CategoryID']] = $this->db->record['CatName'];
} while ($this->db->next(SQL_ASSOC));
return $retval;
}
/**
* Get all operating system names (platforms). Used to populate forms.
*
* @return array
*/
function getPlatforms()
{
// Gather platforms..
$this->db->query("
SELECT
OSID,
OSName
FROM
os
ORDER BY
OSName
", SQL_INIT, SQL_ASSOC);
do {
$retval[$this->db->record['OSID']] = $this->db->record['OSName'];
} while ($this->db->next(SQL_ASSOC));
return $retval;
}
/**
* Get all application names. Used to populate forms.
*/
function getApps()
{
// Gather aapplications.
$this->db->query("
SELECT DISTINCT
AppID,
AppName
FROM
applications
WHERE
public_ver = 'YES'
GROUP BY
AppName
", SQL_INIT, SQL_ASSOC);
do {
$retval[$this->db->record['AppID']] = $this->db->record['AppName'];
} while ($this->db->next(SQL_ASSOC));
return $retval;
}
/**
* Get newest addons.
*
* @param string $app
* @param string $type
* @param int $limit
* @return array
*/
function getNewestAddons($app='firefox',$type='E',$limit=10) {
// Get most popular extensions based on application.
$this->db->query("
SELECT DISTINCT
m.ID ID,
m.Name name,
m.downloadcount dc,
v.DateUpdated as dateupdated
FROM
main m
INNER JOIN version v ON m.ID = v.ID
INNER JOIN applications TA ON v.AppID = TA.AppID
INNER JOIN os o ON v.OSID = o.OSID
WHERE
AppName = '{$app}' AND
downloadcount > '0' AND
approved = 'YES' AND
Type = '{$type}'
GROUP BY
m.ID
ORDER BY
v.dateupdated DESC , downloadcount DESC, rating DESC
LIMIT
{$limit}
", SQL_ALL, SQL_ASSOC);
return $this->db->record;
}
/**
* Get most popular addons.
*
* @param string $app
* @param string $type
* @param int $limit
* @return array
*/
function getPopularAddons($app='firefox',$type='E', $limit=10) {
// Return most popular addons.
$this->db->query("
SELECT DISTINCT
m.ID ID,
m.Name name,
m.downloadcount dc,
v.DateUpdated as dateupdated
FROM
main m
INNER JOIN version v ON m.ID = v.ID
INNER JOIN applications TA ON v.AppID = TA.AppID
INNER JOIN os o ON v.OSID = o.OSID
WHERE
AppName = '{$app}' AND
downloadcount > '0' AND
approved = 'YES' AND
Type = '{$type}'
GROUP BY
m.ID
ORDER BY
downloadcount DESC, rating DESC, v.dateupdated DESC
LIMIT
{$limit}
", SQL_ALL, SQL_ASSOC);
return $this->db->record;
}
/**
* Get recommended addons.
*
* @param string $app
* @param string $type
* @param int $limit
* @return array
*/
function getRecommendedAddons($app='firefox',$type='E', $limit=10) {
// Return most popular addons.
$this->db->query("
SELECT DISTINCT
m.id,
m.name,
m.downloadcount,
v.dateupdated,
v.uri,
r.body,
r.title,
v.size,
v.version,
p.previewuri
FROM
main m
INNER JOIN version v ON m.ID = v.ID
INNER JOIN applications TA ON v.AppID = TA.AppID
INNER JOIN os o ON v.OSID = o.OSID
INNER JOIN reviews r ON m.ID = r.ID
INNER JOIN previews p ON p.ID = m.ID
WHERE
AppName = '{$app}' AND
downloadcount > '0' AND
approved = 'YES' AND
Type = '{$type}' AND
r.featured = 'YES' AND
p.preview = 'YES'
GROUP BY
m.ID
ORDER BY
m.Name
LIMIT
{$limit}
", SQL_ALL, SQL_ASSOC);
return $this->db->record;
}
/**
* Get feature for front page.
*
* @param string $app
* @param string $type
* @return array
*/
function getFeature($app='firefox',$type='E') {
// Return a random feature.
// Yes, rand(now()) is a random (hehe) way to do it.
// I'm open to suggestions.
$this->db->query("
SELECT DISTINCT
m.id,
m.name,
m.downloadcount,
v.dateupdated,
v.uri,
r.body,
r.title,
v.size,
v.version,
p.previewuri
FROM
main m
INNER JOIN version v ON m.ID = v.ID
INNER JOIN applications TA ON v.AppID = TA.AppID
INNER JOIN os o ON v.OSID = o.OSID
INNER JOIN reviews r ON m.ID = r.ID
INNER JOIN previews p ON p.ID = m.ID
WHERE
AppName = '{$app}' AND
downloadcount > '0' AND
approved = 'YES' AND
Type = '{$type}' AND
r.featured = 'YES' AND
p.preview = 'YES'
GROUP BY
m.ID
ORDER BY
rand(now())
LIMIT 1
", SQL_INIT, SQL_ASSOC);
return $this->db->record;
}
}
?>