Example #1
0
/**
 * Returns an array of people given an SQL query. This is a private helper
 * method only for this file.
 * @param $sql The sql query.
 * @return Array
 * @private
 */
function getMostPresentInNews($count, $what = NULL, $tstart = NULL, $tend = NULL, $for_ids = NULL, $source = NULL)
{
    if ($tstart == NULL && $tend == NULL) {
        $tend = time() + 60 * 60 * 8;
        // Adjusting for the time zone.
        $tstart = time() - 60 * 60 * 24 * 7;
    }
    $what_filter = "";
    $history_join = "";
    if ($what != NULL) {
        $history_join = "LEFT JOIN people_history AS h\n                     ON h.idperson = p.idperson";
        $what_filter = "AND h.what = '{$what}'";
    }
    $restrict_to_ids = "";
    if ($for_ids != NULL) {
        $restrict_to_ids = "AND p.idperson IN (" . implode(",", $for_ids) . ")";
    }
    $where_source = '';
    if ($source) {
        $where_source = "AND a.source LIKE '{$source}'";
    }
    $query = "\n    SELECT\n      count(*) AS mentions, p.idperson, people.display_name, people.name\n    FROM news_people AS p\n    LEFT JOIN people ON p.idperson = people.id\n    LEFT JOIN news_articles AS a ON a.id = p.idarticle\n    {$history_join}\n    WHERE a.time > {$tstart} AND\n          a.time < {$tend}\n          {$where_source}\n          {$restrict_to_ids}\n          {$what_filter}\n    GROUP BY p.idperson\n    ORDER BY mentions DESC, p.idperson\n    LIMIT 0, {$count}";
    $sql = mysql_query($query);
    $people = array();
    while ($r = mysql_fetch_array($sql)) {
        $guy = $r;
        $guy['name'] = str_replace(' ', '+', $r['name']);
        $guy['tiny_photo'] = getTinyImgUrl($r['idperson']);
        // TODO(vivi) In a different sql, get this guys history and stick it in an
        // array. Based on that, I should display stuff on the summary page.
        $people[] = $guy;
    }
    return $people;
}
Example #2
0
function getPeopleList($startWith, $count)
{
    $s = mysql_query("\n    SELECT id, name, display_name\n    FROM people\n    LIMIT {$startWith}, {$count}\n  ");
    $ret = array();
    while ($r = mysql_fetch_array($s)) {
        $r['tiny_image'] = getTinyImgUrl($r['id']);
        $ret[] = $r;
    }
    return $ret;
}
function getGovernment($prime_minister, $current_person_id)
{
    $sql = "\n    SELECT g.idperson, g.title, g.mintime, g.maxtime, p.display_name\n    FROM govro_people AS g\n    LEFT JOIN people AS p ON p.id = g.idperson\n    WHERE g.idperson != {$current_person_id} AND\n        title != 'Prim-ministru' AND\n        title NOT LIKE 'viceprim%' AND\n        mintime >= {$prime_minister[time_from]} AND\n        ((maxtime = 0 AND {$prime_minister[time_to]} = 0) OR\n        (maxtime != 0 AND maxtime >= {$prime_minister[time_to]}))\n    ORDER BY maxtime, title";
    $government = array();
    $s = mysql_query($sql);
    while ($r = mysql_fetch_array($s)) {
        $gov_person = new Person();
        $gov_person->setId($r['idperson']);
        $member = array('display_name' => $r['display_name'], 'title' => removeUselessPrefix($r['title']), 'idperson' => $r['idperson'], 'time_from' => $r['mintime'], 'time_to' => $r['maxtime'], 'history_snippet' => $gov_person->getHistorySnippet(), 'tiny_img_url' => getTinyImgUrl($r['idperson']));
        array_push($government, $member);
    }
    return $government;
}
Example #4
0
/**
 * Returns an array of people given an SQL query. This is a private helper
 * method only for this file.
 * @param $sql The sql query.
 * @return Array
 * @private
 */
function getPresidentialCandidates($what, $year, $count)
{
    $sql = mysql_query("\n    SELECT\n        p.display_name,\n        parties.name AS party_name,\n        candidates.idperson\n    FROM pres_2009_people AS candidates\n    LEFT JOIN people AS p ON p.id = candidates.idperson\n    LEFT JOIN parties ON parties.id = candidates.idparty\n    LEFT JOIN people_history AS h\n      ON h.idperson = candidates.idperson AND what = 'catavencu/2008'\n    WHERE candidates.retras = 0\n    ORDER BY p.display_name LIMIT 0, {$count}");
    $people = array();
    while ($r = mysql_fetch_array($sql)) {
        $guy = $r;
        $guy['name'] = $r['display_name'];
        $guy['tiny_photo'] = getTinyImgUrl($r['idperson']);
        // TODO(vivi) In a different sql, get this guys history and stick it in an
        // array. Based on that, I should display stuff on the summary page.
        $people[] = $guy;
    }
    return $people;
}
/**
 * Returns the list of candidates and their results for this college. For now
 * this method is not generic at all, hence the very specific name.
 *
 * TODO(vivi): Refactor and generalize this.
 *
 * @param {string} $college The college name needs to be in the form of
 *     "S1 Alba" or "D3 Prahova". Capitalization is important.
 */
function getCollegeCandidates($college, $year)
{
    $sql = "SELECT people.id, people.display_name, people.name, " . "parties.name AS party, history.url as source " . "FROM results_{$year} AS results " . "LEFT JOIN people ON people.id = results.idperson " . "LEFT JOIN parties " . "ON parties.id = results.idpartid " . "LEFT JOIN people_history AS history " . "ON people.id = history.idperson AND history.what = 'results/2012' " . "WHERE colegiu = '{$college}' " . "ORDER BY people.display_name ASC";
    $s = mysql_query($sql);
    $candidates = array();
    while ($r = mysql_fetch_array($s)) {
        $person = new Person();
        $person->id = $r['id'];
        $person_object = $r;
        $person_object['tiny_img_url'] = getTinyImgUrl($r['id']);
        $person_object['history_snippet'] = $person->getHistorySnippet(array('results/2012'));
        // HACK to show the USL/ARD alliance for parties.
        $displayed_party_name = $r["party"];
        $logo = $r["party"];
        if ($year == "2012") {
            switch ($r["party"]) {
                case "PSD":
                    $displayed_party_name = "PSD (USL)";
                    $logo = "usl";
                    break;
                case "PNL":
                    $displayed_party_name = "PNL (USL)";
                    $logo = "usl";
                    break;
                case "PC":
                    $displayed_party_name = "PC (USL)";
                    $logo = "usl";
                    break;
                case "PD-L":
                    $displayed_party_name = "PD-L (ARD)";
                    $logo = "ard";
                    break;
                case "FC":
                    $displayed_party_name = "FC (ARD)";
                    $logo = "ard";
                    break;
                case "PNTCD":
                    $displayed_party_name = "PNTCD (ARD)";
                    $logo = "ard";
                    break;
            }
        }
        $person_object["displayed_party_name"] = $displayed_party_name;
        $person_object["party_logo"] = $logo;
        $candidates[] = $person_object;
    }
    return $candidates;
}
Example #6
0
/**
 * Returns an array of people given an SQL query. This is a private helper
 * method only for this file.
 * @param $sql The sql query.
 * @return Array
 * @private
 */
function getSenatSorted($sortBy, $order, $count, $party = -1)
{
    switch ($sortBy) {
        case 0:
            $sort = 'display_name';
            break;
        case 1:
            $sort = 'college';
            break;
        case 2:
            $sort = 'party_name, percent';
            break;
        case 3:
            $sort = 'percent';
            break;
        case 4:
            $sort = 'maverick';
            break;
        default:
            $sort = 'percent';
            break;
    }
    $partyFilter = $party > 0 ? "WHERE parties.id = {$party}" : "";
    $sql = mysql_query("\n    SELECT\n        p.name, p.display_name, agg.percent, agg.maverick, agg.idperson,\n        parties.name AS party_name, agg.possible, parties.id AS party_id,\n        r.college\n    FROM senat_2008_votes_agg AS agg\n    LEFT JOIN people AS p ON p.id = agg.idperson\n    LEFT JOIN senat_2008_belong_agg AS party ON party.idperson = agg.idperson\n    LEFT JOIN parties ON parties.id = party.idparty\n    LEFT JOIN people_history AS h\n      ON h.idperson = agg.idperson AND what = 'catavencu/2008'\n    LEFT JOIN results_2008_candidates AS r\n      ON r.idperson = agg.idperson\n    {$partyFilter}\n    ORDER BY {$sort} {$order} LIMIT 0, {$count}");
    $people = array();
    while ($r = mysql_fetch_array($sql)) {
        $guy = $r;
        $guy['name'] = str_replace(' ', '+', $r['name']);
        $guy['percent'] = 100 * $r['percent'];
        $guy['maverick'] = 100 * $r['maverick'];
        $guy['anti_maverick'] = 100 - 100 * $r['maverick'];
        $guy['left_percent'] = 99 - 100 * $r['percent'];
        $guy['tiny_photo'] = getTinyImgUrl($r['idperson']);
        // TODO(vivi) In a different sql, get this guys history and stick it in an
        // array. Based on that, I should display stuff on the summary page.
        $people[] = $guy;
    }
    return $people;
}
Example #7
0
<?php

include_once 'pages/functions_common.php';
$s = mysql_query("\n    SELECT q.id, qualifier, idperson, p.display_name, n.time, n.source, n.link\n    FROM news_qualifiers AS q\n    LEFT JOIN news_articles AS n ON n.id = q.idarticle\n    LEFT JOIN people AS p ON p.id = q.idperson\n    WHERE q.approved = 1 AND q.idperson > 0\n    GROUP BY qualifier\n    ORDER BY n.time DESC\n    LIMIT 0, 50");
$facts = array();
while ($r = mysql_fetch_array($s)) {
    $guy = $r;
    $guy['tiny_photo'] = getTinyImgUrl($r['idperson']);
    $facts[] = $guy;
}
$t = new Smarty();
$t->assign('facts', $facts);
$t->display('pres_2009_learned_facts.tpl');
Example #8
0
$t = new Smarty();
$t->assign('tag', getTagNameForId($tagid));
$t->assign('description', getTagDescriptionForId($tagid));
$votes = getVotesForTag($room, $year, $tagid, $uid);
$possible = sizeof($votes);
$t->assign('votes', $votes);
$people = getPeopleList($room, $year);
$non_zero_people = array();
$zero_people = array();
for ($i = 0; $i < sizeof($people); $i++) {
    $context = getBeliefContext($room, $year, $uid, $people[$i]['id'], $tagid, $possible, 200);
    foreach ($context as $key => $value) {
        $people[$i][$key] = $value;
    }
    // Since I'm here, fix a few things. A little hacky.
    $people[$i]['link'] = "?cid=9&id=" . $people[$i]['id'];
    $people[$i]['tiny_photo'] = getTinyImgUrl($people[$i]['id']);
    if ($context['yes_cnt'] + $context['no_cnt'] > 0) {
        array_push($non_zero_people, $people[$i]);
    } else {
        array_push($zero_people, $people[$i]);
    }
}
usort($non_zero_people, "beliefCmp");
$t->assign('people', $non_zero_people);
$t->assign('absentees', $zero_people);
$t->assign('room', $room);
$t->assign('year', $year);
$t->assign('tagid', $tagid);
$t->assign('user_login', getUserLogin($uid));
$t->display('compass_show_tag.tpl');