/** * Show keywords starting with letter */ function showAction($letter) { if (!Config::get('keywordsEnabled') || !preg_match("#^[A-Z0-9]\$#", $letter)) { return $this->return404(); } //set adPage for display Display::set("adPage", "letter{$letter}"); $keywordGroups = array(); //retrieve keywors which start with $letter $keywords = $this->keyword->getKeywordsWithPrefix($letter); $keywordIds = array(); foreach ($keywords as $keyword) { $keywordIds[] = $keyword['keywordId']; } //Count validated sites which contain keyword $c = new Criteria(); $c->add("keywordId", $keywordIds, "IN"); $c->addGroup("keywordId"); $c->addInnerJoin("sites", "sites.siteId", "keywordsofsites.siteId"); $c->add("status", "validated"); $sitesCountsForKeyword = $this->keywordsOfSite->getArray($c, "count(*)", "keywordId"); //foreach keyword on this page check have many sites include it and push it to prefix group foreach ($keywords as $keyword) { //if some site have this keyword if (isset($sitesCountsForKeyword[$keyword['keywordId']])) { $keyword['count'] = $sitesCountsForKeyword[$keyword['keywordId']]; } else { //if no set counter to default 0 $keyword['count'] = 0; } //if group for this prefix doesn't exists so far if (!isset($keywordGroups[$keyword['prefix']]['keywords'])) { //create group for this prefix $keywordGroups[$keyword['prefix']]['keywords'] = array(); } //add keyword to prefix group $keywordGroups[$keyword['prefix']]['keywords'][] = $keyword; } $this->set("letter", $letter); $this->set("keywordGroups", $keywordGroups); }
function getLetterIndex() { $c = new Criteria(); $c->addGroup("letter"); return $this->findAll($c, "UPPER(LEFT(keyword, 1)) as letter, COUNT(*) as keywordsCount"); }
function getModeratorsStats() { $stats = array(); $c = new Criteria(); $c->addGroup("moderatorId"); $c->add("status", "banned"); $stats['banned'] = $this->site->getArray($c, "moderatorId, COUNT(*) as bannedSitesCount", "moderatorId", true); $c = new Criteria(); $c->addGroup("moderatorId"); $c->add("status", "validated"); $stats['validated'] = $this->site->getArray($c, "moderatorId, COUNT(*) as validatedSitesCount", "moderatorId", true); $c = new Criteria(); $stats['refused'] = $this->refusal->getArray($c, "moderatorId, refusedSitesCount", "moderatorId", true); return $stats; }