Source for file Event.php

Documentation is available at Event.php

  1. <?
  2.  
  3. /** Represents an event and provides different methods to query event information.
  4.  *
  5.  * @package    php-lastfm-api
  6.  * @author  Felix Bruns <felixbruns@web.de>
  7.  * @version    1.0
  8.  */
  9. class Event {
  10.     /** Event id.
  11.      *
  12.      * @var integer 
  13.      * @access    private
  14.      */
  15.     private $id;
  16.  
  17.     /** Event title.
  18.      *
  19.      * @var string 
  20.      * @access    private
  21.      */
  22.     private $title;
  23.  
  24.     /** Event artists.
  25.      *
  26.      * @var array 
  27.      * @access    private
  28.      */
  29.     private $artists;
  30.  
  31.     /** Event venue.
  32.      *
  33.      * @var Venue 
  34.      * @access    private
  35.      */
  36.     private $venue;
  37.  
  38.     /** Event start date (unix timestamp).
  39.      *
  40.      * @var integer 
  41.      * @access    private
  42.      */
  43.     private $startDate;
  44.  
  45.     /** Event description.
  46.      *
  47.      * @var string 
  48.      * @access    private
  49.      */
  50.     private $description;
  51.  
  52.     /** An array of images of this event.
  53.      *
  54.      * @var array 
  55.      * @access    private
  56.      */
  57.     private $images;
  58.  
  59.     /** Event last.fm URL.
  60.      *
  61.      * @var string 
  62.      * @access    private
  63.      */
  64.     private $url;
  65.  
  66.     /** Number of users attending this event.
  67.      *
  68.      * @var integer 
  69.      * @access    private
  70.      */
  71.     private $attendance;
  72.  
  73.     /** Number of reviews of this event.
  74.      *
  75.      * @var integer 
  76.      * @access    private
  77.      */
  78.     private $reviews;
  79.  
  80.     /** Tag of this event (e.g. lastfm:event=<id>).
  81.      *
  82.      * @var string 
  83.      * @access    private
  84.      */
  85.     private $tag;
  86.  
  87.     /** Possible attendance statuses.
  88.      *
  89.      * @var integer 
  90.      * @access    public
  91.      */
  92.     const ATTENDING       0;
  93.     const MAYBE_ATTENDING 1;
  94.     const NOT_ATTENDING   2;
  95.  
  96.     /** Create an event object.
  97.      *
  98.      * @param integer    $id                Event ID.
  99.      * @param string    $title            Event title.
  100.      * @param array        $artists        An array of Artist objects.
  101.      * @param Venue        $venue            A Venue object.
  102.      * @param integer    $startDate        A start date (unix timestamp).
  103.      * @param string    $description    An event description.
  104.      * @param array        $images            An array of cover art images of different sizes.
  105.      * @param string    $url            A last.fm event URL.
  106.      * @param integer    $attendance        The Number of users attending this event.
  107.      * @param integer    $reviews        The Number of reviews of this event.
  108.      * @param string    $tag            Tag of this event.
  109.      *
  110.      * @access    public
  111.      */
  112.     public function __construct($id$titlearray $artistsVenue $venue,
  113.                                 $startDate$description$images$url,
  114.                                 $attendance$reviews$tag){
  115.         $this->id          $id;
  116.         $this->title       $title;
  117.         $this->artists     $artists;
  118.         $this->venue       $venue;
  119.         $this->startDate   $startDate;
  120.         $this->description $description;
  121.         $this->images      $images;
  122.         $this->url         $url;
  123.         $this->attendance  $attendance;
  124.         $this->reviews     $reviews;
  125.         $this->tag         $tag;
  126.     }
  127.  
  128.     /** Returns the ID of this event.
  129. /** Returns the ID of this event.
  130.      *
  131.      * @return    integer    ID of this event.
  132.      * @access    public
  133.      */
  134.     public function getId(){
  135.         return $this->id;
  136.     }
  137.  
  138.     /** Returns the title of this event.
  139.      *
  140.      * @return    string    Title of this event.
  141.      * @access    public
  142.      */
  143.     public function getTitle(){
  144.         return $this->title;
  145.     }
  146.  
  147.     /** Returns the artists of this event.
  148.      *
  149.      * @return    array    An array of Artist objects.
  150.      * @access    public
  151.      */
  152.     public function getArtists(){
  153.         return $this->artists;
  154.     }
  155.  
  156.     /** Returns the venue of this event.
  157.      *
  158.      * @return    Venue    A Venue object.
  159.      * @access    public
  160.      */
  161.     public function getVenue(){
  162.         return $this->venue;
  163.     }
  164.  
  165.     /** Returns the start date of this event.
  166.      *
  167.      * @return    integer    A unix timestamp.
  168.      * @access    public
  169.      */
  170.     public function getStartDate(){
  171.         return $this->startDate;
  172.     }
  173.  
  174.     /** Returns the description of this event.
  175.      *
  176.      * @return    string    A description string.
  177.      * @access    public
  178.      */
  179.     public function getDescription(){
  180.         return $this->description;
  181.     }
  182.  
  183.     /** Returns an image URL of the specified size.
  184.      *
  185.      * @param    integer    $size    Image size constant.
  186.      * @return    string            An image URL.
  187.      * @access    public
  188.      */
  189.     public function getImage($size){
  190.         return $this->images[$size];
  191.     }
  192.  
  193.     /** Returns the last.fm URL of this event.
  194.      *
  195.      * @return    string    A last.fm URL.
  196.      * @access    public
  197.      */
  198.     public function getUrl(){
  199.         return $this->url;
  200.     }
  201.  
  202.     /** Returns number of users attending this event.
  203.      *
  204.      * @return    integer    Number of users attending.
  205.      * @access    public
  206.      */
  207.     public function getAttendance(){
  208.         return $this->attendance;
  209.     }
  210.  
  211.     /** Returns number of reviews of this event.
  212.      *
  213.      * @return    integer    Number of reviews.
  214.      * @access    public
  215.      */
  216.     public function getReviews(){
  217.         return $this->reviews;
  218.     }
  219.  
  220.     /** Returns the tag of this event.
  221.      *
  222.      * @return    Tag    A Tag object.
  223.      * @access    public
  224.      */
  225.     public function getTag(){
  226.         return $this->tag;
  227.     }
  228.  
  229.     /** Set a user's attendance status for an event.
  230.      *
  231.      * @param    integer    $event        The numeric last.fm event ID. (Required)
  232.      * @param    integer    $status        The attendance status (ATTENDING, MAYBE_ATTENDING, NOT_ATTENDING). (Required)
  233.      * @param    Session    $session    A session obtained by {@link de.felixbruns.lastfm.Auth#getSession Auth::getSession} or {@link de.felixbruns.lastfm.Auth#getMobileSession Auth::getMobileSession}. (Required)
  234.      *
  235.      * @static
  236.      * @access    public
  237.      * @throws    Error
  238.      */
  239.     public static function attend($event$status$session){
  240.         CallerFactory::getDefaultCaller()->signedCall('event.attend'array(
  241.             'event'  => $event,
  242.             'status' => $status
  243.         )$session'POST');
  244.     }
  245.  
  246.     /** Get the metadata for an event on last.fm. Includes attendance and lineup information.
  247.      *
  248.      * @param    integer    $event    The numeric last.fm event ID. (Required)
  249.      * @return    mixed            An Event object.
  250.      *
  251.      * @static
  252.      * @access    public
  253.      * @throws    Error
  254.      */
  255.     public static function getInfo($event){
  256.         $xml CallerFactory::getDefaultCaller()->call('event.getInfo'array(
  257.             'event' => $event
  258.         ));
  259.  
  260.         return Event::fromSimpleXMLElement($xml);
  261.     }
  262.  
  263.     /** Get shouts for this event.
  264.      *
  265.      * @param    integer    $event    The numeric last.fm event id (Required)
  266.      * @return    array            An array of Shout objects.
  267.      *
  268.      * @static
  269.      * @access    public
  270.      * @throws    Error
  271.      */
  272.     public static function getShouts($event){
  273.         $xml CallerFactory::getDefaultCaller()->call('event.getShouts'array(
  274.             'event' => $event
  275.         ));
  276.  
  277.         $shouts array();
  278.  
  279.         foreach($xml->children(as $shout){
  280.             $shouts[Shout::fromSimpleXMLElement($shout);
  281.         }
  282.  
  283.         return $shouts;
  284.     }
  285.  
  286.     /** Share an event with one or more last.fm users or other friends.
  287.      *
  288.      * @param    integer    $event        An event ID. (Required)
  289.      * @param    array    $recipients    An array of email addresses or last.fm usernames. Maximum is 10. (Required)
  290.      * @param    string    $message    An optional message to send with the recommendation. If not supplied a default message will be used. (Optional)
  291.      * @param    Session    $session    A session obtained by {@link de.felixbruns.lastfm.Auth#getSession Auth::getSession} or {@link de.felixbruns.lastfm.Auth#getMobileSession Auth::getMobileSession}. (Required)
  292.      *
  293.      * @static
  294.      * @access    public
  295.      * @throws    Error
  296.      */
  297.     public static function share($eventarray $recipients$message null$session){
  298.         CallerFactory::getDefaultCaller()->signedCall('event.share'array(
  299.             'event'     => $event,
  300.             'recipient' => implode(','$recipients),
  301.             'message'   => $message
  302.         )$session'POST');
  303.     }
  304.  
  305.     /** Get an event playlist for streaming.. INOFFICIAL.
  306.      *
  307.      * @param    integer    $event    An event ID. (Required)
  308.      * @return    mixed            A Playlist object.
  309.      *
  310.      * @static
  311.      * @access    public
  312.      * @throws    Error
  313.      */
  314.     public static function getPlaylist($event){
  315.         $xml CallerFactory::getDefaultCaller()->call('event.getPlayerMenu'array(
  316.             'event' => $event
  317.         ));
  318.  
  319.         return Playlist::fetch(Util::toString($xml->playlist->url)truetrue);
  320.     }
  321.  
  322.     /** Create a Event object from a SimpleXMLElement.
  323.      *
  324.      * @param    SimpleXMLElement    $xml    A SimpleXMLElement.
  325.      * @return    Event                        A Event object.
  326.      *
  327.      * @static
  328.      * @access    public
  329.      * @internal
  330.      */
  331.     public static function fromSimpleXMLElement(SimpleXMLElement $xml){
  332.         $artists array();
  333.         $images  array();
  334.  
  335.         if($xml->artists){
  336.             foreach($xml->artists->artist as $artist){
  337.                 $artists[Util::toString($artist);
  338.             }
  339.  
  340.             $artists['headliner'Util::toString($xml->artists->headliner);
  341.         }
  342.  
  343.         if($xml->image){
  344.             foreach($xml->image as $image){
  345.                 $images[Util::toImageType($image['size'])=
  346.                     Util::toString($image);
  347.             }
  348.         }
  349.  
  350.         return new Event(
  351.             Util::toInteger($xml->id),
  352.             Util::toString($xml->title),
  353.             $artists,
  354.             ($xml->venue)?Venue::fromSimpleXMLElement($xml->venue):null,
  355.             Util::toTimestamp($xml->startDate),
  356.             Util::toString($xml->description),
  357.             $images,
  358.             Util::toString($xml->url),
  359.             Util::toInteger($xml->attendance),
  360.             Util::toInteger($xml->reviews),
  361.             Util::toString($xml->tag)
  362.         );
  363.     }
  364. }
  365.  
  366. ?>

Documentation generated on Mon, 22 Dec 2008 16:57:36 +0100 by phpDocumentor 1.4.1