/** * Displays the alliance search result. * * @return Bengine_Game_Controller_Search */ protected function allianceSearch() { $sr = array(); $select = array("SUM(u.points) as points", "COUNT(u2a.userid) as members", "a.aid", "a.tag", "a.name", "a.homepage", "a.showhomepage", "a.showmember"); $joins = "LEFT JOIN " . PREFIX . "user2ally u2a ON (u2a.aid = a.aid)"; $joins .= "LEFT JOIN " . PREFIX . "user u ON (u.userid = u2a.userid)"; $result = Core::getQuery()->select("alliance a", $select, $joins, Core::getDB()->quoteInto("a.tag LIKE ? OR a.name LIKE ?", $this->searchItem->get()), "a.tag ASC", "25", "u2a.aid"); $AllianceList = new Bengine_Game_Alliance_List($result); Hook::event("SearchResultAlliance", array($AllianceList)); Core::getTPL()->addLoop("result", $AllianceList->getArray()); Core::getTPL()->addLoop("searchSuggestions", $this->getSimilarWords($this->searchItem, "alliance")); $this->setTemplate("search/ally"); return $this; }
/** * If user search for an alliance to apply. * * @return Bengine_Game_Controller_Alliance */ protected function joinAction() { if ($this->isPost()) { $result = null; $searchItem = Str::validateXHTML($this->getParam("searchitem")); $searchObj = new String($searchItem); $searchObj->setMinSearchLenght(1)->trim()->prepareForSearch(); Core::getTPL()->assign("searchitem", $searchItem); if ($searchObj->validSearchString) { $select = array("a.aid", "a.tag", "a.name", "a.showhomepage", "a.homepage", "a.open", "COUNT(u2a.userid) AS members", "SUM(u.points) AS points"); $joins = "LEFT JOIN " . PREFIX . "user2ally u2a ON (a.aid = u2a.aid)"; $joins .= "LEFT JOIN " . PREFIX . "user u ON (u2a.userid = u.userid)"; $result = Core::getQuery()->select("alliance a", $select, $joins, Core::getDB()->quoteInto("a.tag LIKE ? OR a.name LIKE ?", $searchObj->get()), "", "", "a.aid"); } $results = new Bengine_Game_Alliance_List($result); Hook::event("AllianceSearchResult", array(&$results, $searchObj)); Core::getTPL()->addLoop("results", $results->getArray()); } return $this; }
/** * Shows alliance ranking. * * @param integer $type Type of ranking (Fleet, Research, Points) * @param integer $pos Position to start ranking * * @return Bengine_Game_Controller_Ranking */ protected function allianceRanking($type, $pos) { $joins = "LEFT JOIN " . PREFIX . "user2ally u2a ON (u2a.aid = a.aid)"; $joins .= "LEFT JOIN " . PREFIX . "user u ON (u.userid = u2a.userid)"; $result = Core::getQuery()->select("alliance a", "SUM(u." . $type . ") AS points", $joins, "a.aid > '0'", "", "", "a.aid", "HAVING points >= (points)"); $oPos = $result->rowCount(); $oPos = $oPos <= 0 ? 1 : $oPos; $oPos = ceil($oPos / Core::getOptions()->get("USER_PER_PAGE")); $result->closeCursor(); $result = Core::getQuery()->select("alliance", "aid", "", "aid > '0'"); $pages = ceil($result->rowCount() / Core::getOptions()->get("USER_PER_PAGE")); $result->closeCursor(); if (!is_numeric($pos)) { $pos = $oPos; } else { if ($pos > $pages) { $pos = $pages; } else { if ($pos < 1) { $pos = 1; } } } $ranks = ""; for ($i = 0; $i < $pages; $i++) { $n = $i * Core::getOptions()->get("USER_PER_PAGE") + 1; if ($i + 1 == $pos) { $s = 1; } else { $s = 0; } if ($i + 1 == $oPos) { $c = "ownPosition"; } else { $c = ""; } $ranks .= createOption($i + 1, fNumber($n) . " - " . fNumber($n + Core::getOptions()->get("USER_PER_PAGE") - 1), $s, $c); } Core::getTPL()->assign("rankingSel", $ranks); $order = $this->average ? "average" : "points"; $rank = abs(($pos - 1) * Core::getOptions()->get("USER_PER_PAGE")); $max = Core::getOptions()->get("USER_PER_PAGE"); $select = array("a.aid", "a.name", "a.tag", "a.showhomepage", "a.homepage", "a.open", "COUNT(u2a.userid) AS members", "FLOOR(SUM(u." . $type . ")) AS points", "AVG(u." . $type . ") AS average"); $joins = "LEFT JOIN " . PREFIX . "user2ally u2a ON u2a.aid = a.aid "; $joins .= "LEFT JOIN " . PREFIX . "user u ON u2a.userid = u.userid "; $result = Core::getQuery()->select("alliance a", $select, $joins, "a.aid > '0'", $order . " DESC, members DESC, a.tag ASC", $rank . ", " . $max, "a.aid"); $AllianceList = new Bengine_Game_Alliance_List($result, $rank); Hook::event("ShowRankingAlliance", array($AllianceList)); Core::getTPL()->addLoop("ranking", $AllianceList->getArray()); $this->setTemplate("ranking/ally"); return $this; }