示例#1
0
 /**
  * @param \Lertify\Lastfm\Api\Data\Tasteometer\Comparison $Comparison
  * @return void
  */
 private function assertComparison(\Lertify\Lastfm\Api\Data\Tasteometer\Comparison $Comparison)
 {
     $Input = $Comparison->getInput();
     $this->assertInstanceOf('Lertify\\Lastfm\\Api\\Data\\ArrayCollection', $Input, 'Input is not an instance of Data\\ArrayCollection!');
     /** @var $User \Lertify\Lastfm\Api\Data\Tasteometer\User */
     foreach ($Input as $User) {
         $this->assertInstanceOf('Lertify\\Lastfm\\Api\\Data\\Tasteometer\\User', $User, 'User is not an instance of Data\\Tasteometer\\User!');
         $UserImages = $User->getImages();
         $this->assertInstanceOf('Lertify\\Lastfm\\Api\\Data\\ArrayCollection', $UserImages, 'UserImages are not an instance of Data\\ArrayCollection!');
     }
     $MatchedArtists = $Comparison->getArtists();
     $this->assertInstanceOf('Lertify\\Lastfm\\Api\\Data\\ArrayCollection', $MatchedArtists, 'MatchedArtists are not an instance of Data\\ArrayCollection!');
     /** @var $Artist \Lertify\Lastfm\Api\Data\Tasteometer\Artist */
     foreach ($MatchedArtists as $Artist) {
         $this->assertInstanceOf('Lertify\\Lastfm\\Api\\Data\\Tasteometer\\Artist', $Artist, 'Artist is not an instance of Data\\Tasteometer\\User!');
         $ArtistImages = $Artist->getImages();
         $this->assertInstanceOf('Lertify\\Lastfm\\Api\\Data\\ArrayCollection', $ArtistImages, 'ArtistImages are not an instance of Data\\ArrayCollection!');
     }
 }
示例#2
0
 /**
  * @link http://www.last.fm/api/show/tasteometer.compare
  *
  * @param string $typeOne
  * @param string $typeTwo
  * @param string|array $valueOne
  * @param string|array $valueTwo
  * @param int $limit
  * @throws InvalidArgumentException
  * @return \Lertify\Lastfm\Api\Data\Tasteometer\Comparison
  */
 public function compare($typeOne, $typeTwo, $valueOne, $valueTwo, $limit = 5)
 {
     if (is_array($valueOne)) {
         if (count($valueOne) > 100) {
             throw new InvalidArgumentException('Number of artists is higher then allowed!');
         } else {
             $valueOne = implode(',', $valueOne);
         }
     }
     if (is_array($valueTwo)) {
         if (count($valueTwo) > 100) {
             throw new InvalidArgumentException('Number of artists is higher then allowed!');
         } else {
             $valueTwo = implode(',', $valueTwo);
         }
     }
     $params = array('type1' => $typeOne, 'type2' => $typeTwo, 'value1' => $valueOne, 'value2' => $valueTwo, 'limit' => $limit);
     $result = $this->get(self::PREFIX . 'compare', $params);
     $resultComparison = $result['comparison'];
     $Comparison = new Data\Tasteometer\Comparison();
     $UsersList = new ArrayCollection();
     if (isset($resultComparison['input']['user'][0])) {
         $users = $resultComparison['input']['user'];
     } else {
         $users = array($resultComparison['input']['user']);
     }
     foreach ($users as $userRow) {
         $User = new Data\Tasteometer\User();
         $User->setName(Util::toSting($userRow['name']));
         $User->setUrl(Util::toSting($userRow['url']));
         $Images = new ArrayCollection();
         if (isset($userRow['image'])) {
             foreach ($userRow['image'] as $image) {
                 $Images->set(Util::toSting($image['size']), Util::toSting($image['#text']));
             }
         }
         $User->setImages($Images);
         $UsersList->add($User);
     }
     $Comparison->setInput($UsersList);
     $Comparison->setScore((double) $resultComparison['result']['score']);
     $Artists = $resultComparison['result']['artists'];
     $Comparison->setMatches((int) $Artists['@attr']['matches']);
     $ArtistList = new ArrayCollection();
     if (isset($Artists['artist'][0])) {
         $artistsList = $Artists['artist'];
     } else {
         $artistsList = array($Artists['artist']);
     }
     foreach ($artistsList as $artistRow) {
         $Artist = new Data\Tasteometer\Artist();
         $Artist->setName(Util::toSting($artistRow['name']));
         $Artist->setUrl(Util::toSting($artistRow['url']));
         $Images = new ArrayCollection();
         if (isset($artistRow['image'])) {
             foreach ($artistRow['image'] as $image) {
                 $Images->set(Util::toSting($image['size']), Util::toSting($image['#text']));
             }
         }
         $Artist->setImages($Images);
         $ArtistList->add($Artist);
     }
     $Comparison->setArtists($ArtistList);
     return $Comparison;
 }