/**
  * Private function getting results for the HOF
  *
  * @param  null $action
  * @param  null $limit
  * @return string
  */
 private function _getHof($action = null, $limit = null)
 {
     $connection = Phalcon_Db_Pool::getConnection();
     $sql = 'SELECT COUNT(a.id) AS total, p.name AS playerName, a.award ' . 'FROM awards a ' . 'INNER JOIN players p ON a.playerId = p.id ' . 'WHERE a.award = %s ';
     if (!empty($action)) {
         $sql .= 'AND a.userId = ' . (int) $action . ' ';
     }
     $sql .= 'GROUP BY a.award, a.playerId ' . 'ORDER BY a.award ASC, total DESC, p.name ';
     if (!empty($limit)) {
         $sql .= 'LIMIT ' . (int) $limit;
     }
     // Kicks
     $query = sprintf($sql, -1);
     $result = $connection->query($query);
     $result->setFetchMode(Phalcon_Db::DB_ASSOC);
     $kicks = array();
     $kicksMax = 0;
     while ($item = $result->fetchArray()) {
         $kicksMax = 0 == $kicksMax ? $item['total'] : $kicksMax;
         $name = $item['playerName'];
         $kicks[] = array('total' => (int) $item['total'], 'name' => $name, 'percent' => (int) ($item['total'] * 100 / $kicksMax));
     }
     // Game balls
     $query = sprintf($sql, 1);
     $result = $connection->query($query);
     $result->setFetchMode(Phalcon_Db::DB_ASSOC);
     $gameballs = array();
     $gameballsMax = 0;
     while ($item = $result->fetchArray()) {
         $gameballsMax = 0 == $gameballsMax ? $item['total'] : $gameballsMax;
         $name = $item['playerName'];
         $gameballs[] = array('total' => (int) $item['total'], 'name' => $name, 'percent' => (int) ($item['total'] * 100 / $gameballsMax));
     }
     $result = array('gameballs' => $gameballs, 'kicks' => $kicks);
     return json_encode($result);
 }
예제 #2
0
    $list = $entry->getElementsByTagName("content");
    $domContent = new DOMDocument();
    $domContent->loadXML("<div></div>");
    $node = $domContent->importNode($list->item(0), true);
    $domContent->documentElement->appendChild($node);
    $dataEntry["content"] = str_replace('default:', '', $domContent->saveHTML());
    $dataEntry["categories"] = array();
    $categories = $entry->getElementsByTagName("category");
    foreach ($categories as $category) {
        $dataEntry["categories"][$category->getAttribute("term")] = $category->getAttribute("label");
    }
    $entries[] = $dataEntry;
}
$modelManager = new Phalcon_Model_Manager();
$modelManager->setModelsDir(__DIR__ . '/' . $config->phalcon->modelsDir);
Phalcon_Db_Pool::setDefaultDescriptor($config->database);
foreach ($entries as $entry) {
    $shortTitle = preg_replace('/[ ]+/', '-', $entry['title']);
    $shortTitle = strtolower(preg_replace('/[^a-zA-Z0-9\\-]/', '', $shortTitle));
    $shortTitle = preg_replace('/[\\-]+/', '-', $shortTitle);
    $news = News::findFirst("short_title='{$shortTitle}'");
    if ($news == false) {
        $news = new News($modelManager);
        $news->language = 'en';
        $news->short_title = $shortTitle;
        $news->title = $entry['title'];
        $published = date_parse($entry['published']);
        $news->published = mktime($published['hour'], $published['minute'], $published['second'], $published['month'], $published['day'], $published['year']);
        $news->year = $published['year'];
        $updated = date_parse($entry['updated']);
        $news->updated = mktime($updated['hour'], $updated['minute'], $updated['second'], $updated['month'], $updated['day'], $updated['year']);