Ejemplo n.º 1
0
 /**
  * Search Constituencies
  *
  * Given a search term, find constituencies by name or postcode.
  *
  * @param string $searchterm The term to search for.
  *
  * @return array A list of the array of constituencies, then a boolean
  *               saying whether it was a postcode used.
  */
 public static function searchConstituenciesByQuery($searchterm)
 {
     if (validate_postcode($searchterm)) {
         // Looks like a postcode - can we find the constituency?
         $constituency = Postcode::postcodeToConstituency($searchterm);
         if ($constituency) {
             return array(array($constituency), true);
         }
     }
     // No luck so far - let's see if they're searching for a constituency.
     $try = strtolower($searchterm);
     $query = "select distinct\n                (select name from constituency where cons_id = o.cons_id and main_name) as name\n            from constituency AS o where name like :try\n            and from_date <= date(now()) and date(now()) <= to_date";
     $db = new \ParlDB();
     $q = $db->query($query, array(':try' => '%' . $try . '%'));
     $constituencies = array();
     for ($n = 0; $n < $q->rows(); $n++) {
         $constituencies[] = $q->field($n, 'name');
     }
     return array($constituencies, false);
 }