Пример #1
0
 /** Get whether the rrcID exists in the CORR system
  * @access public
  * @param string $value
  * @return string
  */
 public function getType($rrcID)
 {
     $curl = new Pas_Curl();
     $curl->setUri('http://numismatics.org/ocre/id/' . $rrcID);
     $curl->getRequest();
     if ($curl->getResponseCode() == '200') {
         return true;
     }
 }
Пример #2
0
 /** The lister function of all guardian articles
  * @access public
  */
 public function indexAction()
 {
     $page = $this->getParam('page');
     $key = md5('pas' . self::QUERY);
     if (!$this->getCache()->test($key)) {
         $guardian = self::GUARDIANAPI_URL . 'search?q=' . urlencode(self::QUERY) . '&page-size=50&order-by=newest&format=' . self::FORMAT . '&show-fields=all&show-tags=all&show-factboxes=all&show-references=all&api-key=' . $this->_apikey;
         $this->_curl->setUri($guardian);
         $this->_curl->getRequest();
         $articles = $this->_curl->getJson();
         $this->getCache()->save($articles);
     } else {
         $articles = $this->getCache()->load($key);
     }
     $results = array();
     foreach ($articles->response->results as $article) {
         if (isset($article->fields->thumbnail)) {
             $image = $article->fields->thumbnail;
         } else {
             $image = null;
         }
         if (isset($article->fields->standfirst)) {
             $stand = $article->fields->standfirst;
         } else {
             $stand = null;
         }
         $tags = array();
         foreach ($article->tags as $k => $v) {
             $tags[$k] = $v;
         }
         if (isset($article->fields->byline)) {
             $byline = $article->fields->byline;
         } else {
             $byline = null;
         }
         $results[] = array('id' => $article->id, 'headline' => $article->fields->headline, 'byline' => $byline, 'image' => $image, 'pubDate' => $article->webPublicationDate, 'content' => $article->fields->body, 'trailtext' => $article->fields->trailText, 'publication' => $article->fields->publication, 'sectionName' => $article->sectionName, 'linkText' => $article->webTitle, 'standfirst' => $stand, 'section' => $article->sectionName, 'url' => $article->webUrl, 'shortUrl' => $article->fields->shortUrl, 'publication' => $article->fields->publication, 'tags' => $tags);
     }
     $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($results));
     Zend_Paginator::setCache($this->getCache());
     if (isset($page) && $page != "") {
         $paginator->setCurrentPageNumber((int) $page);
     }
     $paginator->setItemCountPerPage(20)->setPageRange(10);
     if (in_array($this->_helper->contextSwitch()->getCurrentContext(), array('xml', 'json', 'rss', 'atom'))) {
         $paginated = array();
         foreach ($paginator as $k => $v) {
             $paginated[$k] = $v;
         }
         $data = array('pageNumber' => $paginator->getCurrentPageNumber(), 'total' => number_format($paginator->getTotalItemCount(), 0), 'itemsReturned' => $paginator->getCurrentItemCount(), 'totalPages' => number_format($paginator->getTotalItemCount() / $paginator->getItemCountPerPage(), 0));
         $this->view->data = $data;
         $this->view->guardianStories = array('guardianStory' => $paginated);
     } else {
         $this->view->data = $paginator;
     }
 }
Пример #3
0
 /** Call the they work for you api, caches response
  * @access public
  * @param integer $id The MP or Lord's ID number
  * @return array
  */
 public function callApi($id)
 {
     if (!$this->getCache()->test('mptwfy' . $id)) {
         $twfy = 'http://www.theyworkforyou.com/api/getPerson?key=' . $this->getTwfykey() . '&id=' . $id . '&output=js';
         $curl = new Pas_Curl();
         $curl->setUri($twfy);
         $curl->getRequest();
         $data = $curl->getJson();
         $this->getCache()->save($data);
     } else {
         $data = $this->getCache()->load('mptwfy' . $id);
     }
     return $data;
 }
Пример #4
0
 /** Get OS feature data from 1:50K gazetteer
  * @access public
  * @param type $constituency
  * @return null|array
  */
 public function getGazetteerConstituency($constituency)
 {
     $twfy = 'http://www.theyworkforyou.com/api/getGeometry?name=';
     $twfy .= urlencode($constituency);
     $twfy .= '&output=js&key=';
     $twfy .= $this->_config->webservice->twfy->apikey;
     $curl = new Pas_Curl();
     $curl->setUri($twfy);
     $curl->getRequest();
     $data = $curl->getJson();
     if (array_key_exists('min_lat', $data)) {
         $latmin = $data->min_lat;
         $latmax = $data->max_lat;
         $longmin = $data->min_lon;
         $longmax = $data->max_lon;
         $finds = $this->getAdapter();
         $select = $finds->select()->from($this->_name)->where('latitude > ?', $latmin)->where('latitude < ?', $latmax)->where('longitude > ?', $longmin)->where('longitude < ?', $longmax)->where(new Zend_Db_Expr('f_code = "R" OR f_code = "A"'));
         $osdata = $finds->fetchAll($select);
         return $osdata;
     } else {
         return NULL;
     }
 }
Пример #5
0
 /** Get the data with a specific method using Curl
  * @access public
  * @return string
  */
 public function requestWords($method, $data)
 {
     $data['key'] = $this->getApiKey();
     $data['lang'] = $this->getLanguage();
     $curl = new Pas_Curl();
     $curl->setUri(self::WHAT3WORDS_URI . $method . '?' . http_build_query($data));
     Zend_Debug::dump($curl->getRequest());
     $curl->getRequest();
     if ($curl->getResponseCode() == 200) {
         return $curl->getJson();
     } else {
         return false;
     }
 }
Пример #6
0
 /** Get a list of Scheduled monuments within a constituency
  * @access public
  * @param string $constituency
  * @return null
  */
 public function getSmrsConstituency($constituency)
 {
     $twfy = 'http://www.theyworkforyou.com/api/getGeometry?name=';
     $twfy .= urlencode((string) $constituency);
     $twfy .= '&output=js&key=';
     $twfy .= $this->_config->webservice->twfy->apikey;
     $curl = new Pas_Curl();
     $curl->setUri($twfy);
     $curl->getRequest();
     $data = $curl->decodeJson();
     if (array_key_exists('min_lat', $data)) {
         $latmin = $data->min_lat;
         $latmax = $data->max_lat;
         $longmin = $data->min_lon;
         $longmax = $data->max_lon;
         $finds = $this->getAdapter();
         $select = $finds->select()->from($this->_name)->where('lat > ?', (double) $latmin)->where('lat < ?', (double) $latmax)->where('lon > ?', (double) $longmin)->where('lon < ?', (double) $longmax);
         $osdata = $finds->fetchAll($select);
         return $osdata;
     } else {
         return FALSE;
     }
 }