Example #1
0
 /**
  * Get XML representation of artist.
  *
  * @return string
  */
 public function asXML()
 {
     $xml = new MBSimpleXMLElement('<artist></artist>');
     $xml->addAttribute("href", $this->getURI());
     $xml->addCData("name", $this->getName());
     $albumXML = $xml->addChild("albums");
     foreach ($this->albums as $album) {
         $albumXML->addXMLElement(new MBSimpleXMLElement($album->asXML()));
     }
     $xml->addChild("popularity", $this->popularity);
     return $xml->asXML();
 }
 /**
  * Generates a XML string from your array or object of artists, albums
  * or tracks.
  *
  * @throws MetaTuneException
  * @param mixed $input
  * @return string
  */
 public function generateXML($input)
 {
     if (!is_array($input) && $input instanceof SpotifyItem) {
         return $input->asXML();
     }
     // Empty array. No need for that.
     if (count($input) < 1) {
         throw new MetaTuneException(1003);
     }
     if ($input[0] instanceof Artist) {
         $xml = new MBSimpleXMLElement('<?xml version = "1.0" encoding = "UTF-8"?><artists></artists>');
     } else {
         if ($input[0] instanceof Track) {
             $xml = new MBSimpleXMLElement('<?xml version = "1.0" encoding = "UTF-8"?><tracks></tracks>');
         } else {
             if ($input[0] instanceof Album) {
                 $xml = new MBSimpleXMLElement('<?xml version = "1.0" encoding = "UTF-8"?><albums></albums>');
             } else {
                 throw new MetaTuneException(1004);
             }
         }
     }
     foreach ($input as $item) {
         $xml->addXMLElement(new MBSimpleXMLElement($item->asXML()));
     }
     return $xml->asXML();
 }
Example #3
0
 /**
  * Get XML representation of track.
  *
  * @return string
  */
 public function asXML()
 {
     $xml = new MBSimpleXMLElement('<track></track>');
     $xml->addAttribute("href", $this->getURI());
     $xml->addCData("name", $this->getTitle());
     // Add artists
     if ($this->artist != null) {
         if (is_array($this->artist)) {
             foreach ($this->artist as $artist) {
                 $xml->addXMLElement(new MBSimpleXMLElement($artist->asXML()));
             }
         } else {
             $xml->addXMLElement(new MBSimpleXMLElement($this->artist->asXML()));
         }
     }
     if ($this->album != null) {
         $xml->addXMLElement(new MBSimpleXMLElement($this->album->asXML()));
     }
     $xml->addChild("length", $this->length);
     $xml->addChild("popularity", $this->popularity);
     $xml->addChild("track-number", $this->trackNr);
     $xml->addChild("disc-number", $this->discNr);
     return $xml->asXML();
 }
Example #4
0
 /**
  * Get XML representation of album.
  *
  * @return string
  */
 public function asXML()
 {
     $xml = new MBSimpleXMLElement('<album></album>');
     $xml->addAttribute("href", $this->getURI());
     $xml->addCData("name", $this->getName());
     $xml->addXMLElement(new MBSimpleXMLElement($this->artist->asXML()));
     $tracksElement = $xml->addChild("tracks");
     foreach ($this->tracks as $track) {
         $tracksElement->addXMLElement(new MBSimpleXMLElement($track->asXML()));
     }
     $xml->addChild("popularity", $this->popularity);
     $xml->addChild("released", $this->release);
     return $xml->asXML();
 }