示例#1
0
 public static function fromXml(\SimpleXMLElement $dayguide)
 {
     $model = new Dayguide();
     $model->setDate($dayguide['date']);
     $type = 'phpOpenNOS\\Model\\' . ucfirst($dayguide['type']);
     foreach ($dayguide->item as $item) {
         $model->addItem($type::fromXML($item));
     }
     return $model;
 }
示例#2
0
 public function testFromXml()
 {
     $dayguide = Dayguide::fromXml(simplexml_load_string('<dayguide type="tv" date="2010-12-29"><item>
                                     <id>182884239</id>
                                     <type><![CDATA[tv]]></type>
                                     <channel_icon><![CDATA[http://open.nos.nl/img/icons/tv/nl2.png]]></channel_icon>
                                     <channel_code><![CDATA[NL2]]></channel_code>
                                     <channel_name><![CDATA[Nederland 2]]></channel_name>
                                     <starttime><![CDATA[2010-12-29 02:00:00]]></starttime>
                                     <endtime><![CDATA[2010-12-29 06:00:00]]></endtime>
                                     <genre><![CDATA[Informatief]]></genre>
                                     <title><![CDATA[NOS Tekst tv]]></title>
                                     <description><![CDATA[Informatie uit Teletekst.]]></description>
                                     </item>
                                     <item>
                                     <id>182342528</id>
                                     <type><![CDATA[tv]]></type>
                                     <channel_icon><![CDATA[http://open.nos.nl/img/icons/tv/nl1.png]]></channel_icon>
                                     <channel_code><![CDATA[NL1]]></channel_code>
                                     <channel_name><![CDATA[Nederland 1]]></channel_name>
                                     <starttime><![CDATA[2010-12-29 03:41:00]]></starttime>
                                     <endtime><![CDATA[2010-12-29 06:00:00]]></endtime>
                                     <genre><![CDATA[Informatief]]></genre>
                                     <title><![CDATA[NOS Tekst tv]]></title>
                                     <description><![CDATA[Informatie uit Teletekst.]]></description>
                                     </item>
                                     <item>
                                     <id>183724239</id>
                                     <type><![CDATA[tv]]></type>
                                     <channel_icon><![CDATA[http://open.nos.nl/img/icons/tv/nl1.png]]></channel_icon>
                                     <channel_code><![CDATA[NL1]]></channel_code>
                                     <channel_name><![CDATA[Nederland 1]]></channel_name>
                                     <starttime><![CDATA[2010-12-29 06:00:00]]></starttime>
                                     <endtime><![CDATA[2010-12-29 06:25:00]]></endtime>
                                     <genre><![CDATA[Informatief]]></genre>
                                     <title><![CDATA[NOS Tekst tv]]></title>
                                     <description><![CDATA[Informatie uit Teletekst.]]></description>
                                     </item>
                                     </dayguide>'));
     $this->assertEquals($dayguide->getDate('d-m-Y'), '29-12-2010');
     $items = $dayguide->getItems();
     $this->assertEquals(count($items), 3);
 }
示例#3
0
 /**
  * Get the Radio broadcasts for the specified period and channel (optional)
  *
  * @param string $startdate
  * @param string $enddate
  * @param string $channel
  * @return array
  */
 public function getRadioBroadcast($startdate = '', $enddate = '', $channel = '')
 {
     $dayguides = array();
     $url = 'http://open.nos.nl/v2/guide/radio/key/' . $this->apikey . '/output/xml/';
     if (!empty($startdate) && !empty($enddate)) {
         $startdate = new \DateTime($startdate);
         $enddate = new \Datetime($enddate);
         if ($this->validateDaterange($startdate, $enddate)) {
             $url .= 'start/' . $startdate->format('Y-m-d') . '/end/' . $enddate->format('Y-m-d') . '/';
         }
     }
     if (!empty($channel)) {
         $url .= 'channel/' . $channel . '/';
     }
     $xml = $this->request($url);
     foreach ($xml->dayguide as $day) {
         $dayguides[] = Dayguide::fromXml($day);
     }
     return $dayguides;
 }