Source for file Tasteometer.php

Documentation is available at Tasteometer.php

  1. <?
  2.  
  3. /** Provides a method for comparing music tastes.
  4.  *
  5.  * @package    php-lastfm-api
  6.  * @author  Felix Bruns <felixbruns@web.de>
  7.  * @version    1.0
  8.  */
  9. class Tasteometer {
  10.     /** Possible comparison types.
  11.      *
  12.      * @var integer 
  13.      * @access    public
  14.      */
  15.     const COMPARE_USER    'user';
  16.     const COMPARE_ARTIST  'artists';
  17.     const COMPARE_MYSPACE 'myspace';
  18.  
  19.     /** Get a Tasteometer score from two inputs, along with a list of shared artists. If the input is a User or a Myspace URL, some additional information is returned.
  20.      *
  21.      * @param    integer    $type1    A Tasteometer comparison type. (Required)
  22.      * @param    integer    $type2    A Tasteometer comparison type. (Required)
  23.      * @param    mixed    $value1    A last.fm username, an array of artist names or a myspace profile URL. (Required)
  24.      * @param    mixed    $value2    A last.fm username, an array of artist names or a myspace profile URL. (Required)
  25.      * @param    integer    $limit    How many shared artists to display (default = 5). (Optional)
  26.      * @return    array            An array containing comparison results, input information and shared artists.
  27.      *
  28.      * @static
  29.      * @access    public
  30.      * @throws    Error
  31.      */
  32.     public static function compare($type1$type2$value1$value2$limit null){
  33.         /* Handle arrays of artist names. */
  34.         if(is_array($value1)){
  35.             $value1 implode(','$value1);
  36.         }
  37.  
  38.         if(is_array($value2)){
  39.             $value2 implode(','$value2);
  40.         }
  41.  
  42.         /* API call. */
  43.         $xml CallerFactory::getDefaultCaller()->call('tasteometer.compare'array(
  44.             'type1'  => $type1,
  45.             'type2'  => $type2,
  46.             'value1' => $value1,
  47.             'value2' => $value2,
  48.             'limit'  => $limit
  49.         ));
  50.  
  51.         /* Get shared artists. */
  52.         $artists array();
  53.  
  54.         foreach($xml->result->artists->children(as $artist){
  55.             $artists[Artist::fromSimpleXMLElement($artist);
  56.         }
  57.  
  58.         /* Get input information. */
  59.         $inputs array();
  60.  
  61.         foreach($xml->input->children(as $input){
  62.             $inputs[User::fromSimpleXMLElement($input);
  63.         }
  64.  
  65.         return array(
  66.             'score'   => Util::toFloat($xml->result->score),
  67.             'input'   => $inputs,
  68.             'artists' => $artists
  69.         );
  70.     }
  71. }
  72.  
  73. ?>

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