dmBridge PHP API
DMUpdateManager.php
00001 <?php
00002 #
00003 # dmBridge: a data access framework for CONTENTdm(R)
00004 #
00005 # Copyright © 2009, 2010, 2011 Board of Regents of the Nevada System of Higher
00006 # Education, on behalf of the University of Nevada, Las Vegas
00007 #
00008 
00015 class DMUpdateManager {
00016 
00017    const NEWS_RSS_URL = "http://digital.library.unlv.edu/software/dmbridge/feed";
00018    const HTTP_TIMEOUT = 6;
00019 
00021    private $request;
00022 
00027    public function __construct(DMHTTPRequest $req) {
00028       $this->request = $req;
00029    }
00030 
00035    public function getNewsItems($num) {
00036       $items = array();
00037       $this->request->setURI(new DMURI(self::NEWS_RSS_URL));
00038       $client = new DMHTTPClient($this->request);
00039       $response = $client->send();
00040 
00041       if ($response->getRepresentation()->getBody()) {
00042          $dxml = new DOMDocument("1.0", "utf-8");
00043          @$dxml->loadXML($response->getRepresentation()->getBody());
00044          $dxp = new DOMXPath($dxml);
00045 
00046          $i = 0;
00047          foreach ($dxp->query("//channel/item") as $item) {
00048             if ($i >= $num) {
00049                break;
00050             }
00051             $ni = new DMNewsItem();
00052             $ni->setTitle($item->getElementsByTagName("title")->item(0)->nodeValue);
00053             $ni->setURL($item->getElementsByTagName("link")->item(0)->nodeValue);
00054             $ni->setDate(new DMDateTime($item->getElementsByTagName("pubDate")->item(0)->nodeValue));
00055             $ni->setBody($item->getElementsByTagName("description")->item(0)->nodeValue);
00056             $items[] = $ni;
00057             $i++;
00058          }
00059       }
00060 
00061       return $items;
00062    }
00063 
00064 }
 All Data Structures Functions Variables