예제 #1
0
function person_recent_appearances($member)
{
    global $DATA, $SEARCHENGINE, $this_page;
    $out = array();
    $out['appearances'] = array();
    //$this->block_start(array('id'=>'hansard', 'title'=>$title));
    // This is really far from ideal - I don't really want $PAGE to know
    // anything about HANSARDLIST / DEBATELIST / WRANSLIST.
    // But doing this any other way is going to be a lot more work for little
    // benefit unfortunately.
    twfy_debug_timestamp();
    $person_id = $member->person_id();
    $memcache = new MySociety\TheyWorkForYou\Memcache();
    $recent = $memcache->get('recent_appear:' . $person_id);
    if (!$recent) {
        // Initialise the search engine
        $searchstring = "speaker:{$person_id}";
        $SEARCHENGINE = new \SEARCHENGINE($searchstring);
        $hansard = new MySociety\TheyWorkForYou\Hansard();
        $args = array('s' => $searchstring, 'p' => 1, 'num' => 3, 'pop' => 1, 'o' => 'd');
        $results = $hansard->search($searchstring, $args);
        $recent = serialize($results['rows']);
        $memcache->set('recent_appear:' . $person_id, $recent);
    }
    $out['appearances'] = unserialize($recent);
    twfy_debug_timestamp();
    $MOREURL = new \URL('search');
    $MOREURL->insert(array('pid' => $person_id, 'pop' => 1));
    $out['more_href'] = $MOREURL->generate() . '#n4';
    $out['more_text'] = 'More of ' . ucfirst($member->full_name()) . '’s recent appearances';
    if ($rssurl = $DATA->page_metadata($this_page, 'rss')) {
        // If we set an RSS feed for this page.
        $HELPURL = new \URL('help');
        $out['additional_links'] = '<a href="' . WEBPATH . $rssurl . '" title="XML version of this person&rsquo;s recent appearances">RSS feed</a> (<a href="' . $HELPURL->generate() . '#rss" title="An explanation of what RSS feeds are for">?</a>)';
    }
    return $out;
}
예제 #2
0
 public function load_extra_info($display = false)
 {
     $memcache = new MySociety\TheyWorkForYou\Memcache();
     $memcache_key = 'extra_info:' . $this->person_id . ($display ? '' : ':plain');
     $this->extra_info = $memcache->get($memcache_key);
     if (!DEVSITE && $this->extra_info) {
         return;
     }
     $this->extra_info = array();
     $q = $this->db->query('SELECT * FROM moffice WHERE person=:person_id ORDER BY from_date DESC', array(':person_id' => $this->person_id));
     for ($row = 0; $row < $q->rows(); $row++) {
         $this->extra_info['office'][] = $q->row($row);
     }
     // Info specific to member id (e.g. attendance during that period of office)
     $q = $this->db->query("SELECT data_key, data_value\n                        FROM \tmemberinfo\n                        WHERE\tmember_id = :member_id", array(':member_id' => $this->member_id));
     for ($row = 0; $row < $q->rows(); $row++) {
         $this->extra_info[$q->field($row, 'data_key')] = $q->field($row, 'data_value');
         #		if ($q->field($row, 'joint') > 1)
         #			$this->extra_info[$q->field($row, 'data_key').'_joint'] = true;
     }
     // Info specific to person id (e.g. their permanent page on the Guardian website)
     $q = $this->db->query("SELECT data_key, data_value\n                        FROM \tpersoninfo\n                        WHERE\tperson_id = :person_id", array(':person_id' => $this->person_id));
     for ($row = 0; $row < $q->rows(); $row++) {
         $this->extra_info[$q->field($row, 'data_key')] = $q->field($row, 'data_value');
         #	    if ($q->field($row, 'count') > 1)
         #	    	$this->extra_info[$q->field($row, 'data_key').'_joint'] = true;
     }
     // Info specific to constituency (e.g. election results page on Guardian website)
     if ($this->house(HOUSE_TYPE_COMMONS)) {
         $q = $this->db->query("SELECT data_key, data_value FROM consinfo\n            WHERE constituency = :constituency", array(':constituency' => $this->constituency));
         for ($row = 0; $row < $q->rows(); $row++) {
             $this->extra_info[$q->field($row, 'data_key')] = $q->field($row, 'data_value');
         }
     }
     if (array_key_exists('public_whip_rebellions', $this->extra_info)) {
         $rebellions = $this->extra_info['public_whip_rebellions'];
         $rebel_desc = "<unknown>";
         if ($rebellions == 0) {
             $rebel_desc = "never";
         } elseif ($rebellions <= 1) {
             $rebel_desc = "hardly ever";
         } elseif ($rebellions <= 3) {
             $rebel_desc = "occasionally";
         } elseif ($rebellions <= 5) {
             $rebel_desc = "sometimes";
         } elseif ($rebellions > 5) {
             $rebel_desc = "quite often";
         }
         $this->extra_info['public_whip_rebel_description'] = $rebel_desc;
     }
     if (isset($this->extra_info['public_whip_attendrank'])) {
         $prefix = $this->house(HOUSE_TYPE_LORDS) ? 'L' : '';
         $this->extra_info[$prefix . 'public_whip_division_attendance_rank'] = $this->extra_info['public_whip_attendrank'];
         $this->extra_info[$prefix . 'public_whip_division_attendance_rank_outof'] = $this->extra_info['public_whip_attendrank_outof'];
         $this->extra_info[$prefix . 'public_whip_division_attendance_quintile'] = floor($this->extra_info['public_whip_attendrank'] / ($this->extra_info['public_whip_attendrank_outof'] + 1) * 5);
     }
     if ($this->house(HOUSE_TYPE_LORDS) && isset($this->extra_info['public_whip_division_attendance'])) {
         $this->extra_info['Lpublic_whip_division_attendance'] = $this->extra_info['public_whip_division_attendance'];
         unset($this->extra_info['public_whip_division_attendance']);
     }
     if ($display && array_key_exists('register_member_interests_html', $this->extra_info) && $this->extra_info['register_member_interests_html'] != '') {
         $args = array("sort" => "regexp_replace");
         $GLOSSARY = new GLOSSARY($args);
         $this->extra_info['register_member_interests_html'] = $GLOSSARY->glossarise($this->extra_info['register_member_interests_html']);
     }
     $q = $this->db->query('select count(*) as c from alerts where criteria like "%speaker:' . $this->person_id . '%" and confirmed and not deleted');
     $this->extra_info['number_of_alerts'] = $q->field(0, 'c');
     if (isset($this->extra_info['reading_ease'])) {
         $this->extra_info['reading_ease'] = round($this->extra_info['reading_ease'], 2);
         $this->extra_info['reading_year'] = round($this->extra_info['reading_year'], 0);
         $this->extra_info['reading_age'] = $this->extra_info['reading_year'] + 4;
         $this->extra_info['reading_age'] .= '&ndash;' . ($this->extra_info['reading_year'] + 5);
     }
     # Public Bill Committees
     $q = $this->db->query('select bill_id,session,title,sum(attending) as a,sum(chairman) as c
         from pbc_members, bills
         where bill_id = bills.id and person_id = ' . $this->person_id() . ' group by bill_id order by session desc');
     $this->extra_info['pbc'] = array();
     for ($i = 0; $i < $q->rows(); $i++) {
         $bill_id = $q->field($i, 'bill_id');
         $c = $this->db->query('select count(*) as c from hansard where major=6 and minor=' . $bill_id . ' and htype=10');
         $c = $c->field(0, 'c');
         $title = $q->field($i, 'title');
         $attending = $q->field($i, 'a');
         $chairman = $q->field($i, 'c');
         $this->extra_info['pbc'][$bill_id] = array('title' => $title, 'session' => $q->field($i, 'session'), 'attending' => $attending, 'chairman' => $chairman > 0, 'outof' => $c);
     }
     $memcache->set($memcache_key, $this->extra_info);
 }