Listing 2720
Submitted by anonymous user, 3 March 2010
public function ranksAction()
{
$model = Zend_Registry::get('orm');
$consts = Zend_Registry::get('consts');
$consts['categories'][] = false;
foreach($consts['categories'] as $key => $value)
{
$file = $model->cron('ranks/rank'.($value ? '_'.$key : ''));
if($value)
$model->where('s.cid = '.$key);
$songs = $model->setTable('votes v')->select('s.id,aid,s.bid,name,title,b.cid,count(v.value) as c, sum(v.value) as s')->where('v.date > DATE_SUB(NOW(), INTERVAL 7 DAY)', 'subQuery')->innerJoin('songs s', 's.id=v.sid')->innerJoin('bands b', 'b.id=s.bid')->order('s')->group('s.id')->limit(6)->findAll();
foreach($songs as $key2 => $obj)
{
if(!count($file))
$songs[$key2]->rank = 1;
else
{
foreach($file as $key3 => $obj2)
if($obj->id == $obj2->id)
{
if($key2 != $key3)
$songs[$key2]->rank = ($key2 < $key3 ? 'up' : 'down');
$songs[$key2]->is = 1;
}
}
if(!$songs[$key2]->is) $songs[$key2]->rank = 'up';
}
$model->putcron('ranks/rank'.($value ? '_'.$key : ''), false, $songs);
}
}


