Source for file Group.php

Documentation is available at Group.php

  1. <?
  2.  
  3. /** Provides different methods to query group information.
  4.  *
  5.  * @package    php-lastfm-api
  6.  * @author  Felix Bruns <felixbruns@web.de>
  7.  * @version    1.0
  8.  */
  9. class Group {
  10.     /** Get a list of members for this group.
  11.      *
  12.      * @param    string    $group    The group name to fetch the members of. (Required)
  13.       * @return    array            An array of User objects.
  14.      *
  15.      * @static
  16.      * @access    public
  17.      * @throws    Error
  18.      */
  19.     public static function getMembers($group){
  20.         $xml CallerFactory::getDefaultCaller()->call('group.getMembers'array(
  21.             'group' => $group
  22.         ));
  23.  
  24.         $users array();
  25.  
  26.         foreach($xml->children(as $user){
  27.             $users[User::fromSimpleXMLElement($user);
  28.         }
  29.  
  30.         $perPage Util::toInteger($xml['perPage']);
  31.  
  32.         return new PaginatedResult(
  33.             Util::toInteger($xml['totalPages']$perPage,
  34.             Util::toInteger($xml['page']$perPage,
  35.             $perPage,
  36.             $users
  37.         );
  38.     }
  39.  
  40.     /** Get an album chart for a group, for a given date range. If no date range is supplied, it will return the most recent album chart for this group.
  41.      *
  42.      * @param    string    $group    The last.fm group name to fetch the charts of. (Required)
  43.       * @param    integer    $from    The date at which the chart should start from. See {@link de.felixbruns.lastfm.Group#getWeeklyChartList Group::getWeeklyChartList} for more. (Optional)
  44.      * @param    integer    $to        The date at which the chart should end on. See {@link de.felixbruns.lastfm.Group#getWeeklyChartList Group::getWeeklyChartList} for more. (Optional)
  45.      * @return    array            An array of Album objects.
  46.      *
  47.      * @static
  48.      * @access    public
  49.      * @throws    Error
  50.      */
  51.     public static function getWeeklyAlbumChart($group$from null$to null){
  52.         $xml CallerFactory::getDefaultCaller()->call('group.getWeeklyAlbumChart'array(
  53.             'group' => $group,
  54.             'from'  => $from,
  55.             'to'    => $to
  56.         ));
  57.  
  58.         $albums array();
  59.  
  60.         foreach($xml->children(as $album){
  61.             $albums[Album::fromSimpleXMLElement($album);
  62.         }
  63.  
  64.         return $albums;
  65.     }
  66.  
  67.     /** Get an artist chart for a group, for a given date range. If no date range is supplied, it will return the most recent album chart for this group.
  68.      *
  69.      * @param    string    $group    The last.fm group name to fetch the charts of. (Required)
  70.       * @param    integer    $from    The date at which the chart should start from. See {@link de.felixbruns.lastfm.Group#getWeeklyChartList Group::getWeeklyChartList} for more. (Optional)
  71.      * @param    integer    $to        The date at which the chart should end on. See {@link de.felixbruns.lastfm.Group#getWeeklyChartList Group::getWeeklyChartList} for more. (Optional)
  72.      * @return    array            An array of Artist objects.
  73.      *
  74.      * @static
  75.      * @access    public
  76.      * @throws    Error
  77.      */
  78.     public static function getWeeklyArtistChart($group$from null$to null){
  79.         $xml CallerFactory::getDefaultCaller()->call('group.getWeeklyArtistChart'array(
  80.             'group' => $group,
  81.             'from'  => $from,
  82.             'to'    => $to
  83.         ));
  84.  
  85.         $artists array();
  86.  
  87.         foreach($xml->children(as $artist){
  88.             $artists[Artist::fromSimpleXMLElement($artist);
  89.         }
  90.  
  91.         return $artists;
  92.     }
  93.  
  94.     /** Get a list of available charts for this group, expressed as date ranges which can be sent to the chart services.
  95.      *
  96.      * @param    string    $group    The last.fm group name to fetch the charts list for. (Required)
  97.      * @return    array            An array of from/to unix timestamp pairs.
  98.      *
  99.      * @static
  100.      * @access    public
  101.      * @throws    Error
  102.      */
  103.     public static function getWeeklyChartList($group){
  104.         $xml CallerFactory::getDefaultCaller()->call('group.getWeeklyChartList'array(
  105.             'group' => $group
  106.         ));
  107.  
  108.         $chartList array();
  109.  
  110.         foreach($xml->children(as $chart){
  111.             $chartList[array(
  112.                 'from' => Util::toInteger($chart['from']),
  113.                 'to'   => Util::toInteger($chart['to']),
  114.             );
  115.         }
  116.  
  117.         return $chartList;
  118.     }
  119.  
  120.     /** Get a track chart for a group, for a given date range. If no date range is supplied, it will return the most recent album chart for this group.
  121.      *
  122.      * @param    string    $group    The last.fm group name to fetch the charts of. (Required)
  123.       * @param    integer    $from    The date at which the chart should start from. See {@link de.felixbruns.lastfm.Group#getWeeklyChartList Group::getWeeklyChartList} for more. (Optional)
  124.      * @param    integer    $to        The date at which the chart should end on. See {@link de.felixbruns.lastfm.Group#getWeeklyChartList Group::getWeeklyChartList} for more. (Optional)
  125.      * @return    array            An array of Track objects.
  126.      *
  127.      * @static
  128.      * @access    public
  129.      * @throws    Error
  130.      */
  131.     public static function getWeeklyTrackChart($group$from null$to null){
  132.         $xml CallerFactory::getDefaultCaller()->call('group.getWeeklyTrackChart'array(
  133.             'group' => $group,
  134.             'from'  => $from,
  135.             'to'    => $to
  136.         ));
  137.  
  138.         $tracks array();
  139.  
  140.         foreach($xml->children(as $track){
  141.             $tracks[Track::fromSimpleXMLElement($track);
  142.         }
  143.  
  144.         return $tracks;
  145.     }
  146. }
  147.  
  148. ?>

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