PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Users

In order to retrieve information for a specific user, the setUser() method is first used to select the user for which data are to be retrieved. Zend_Service_Audioscrobbler provides several methods for retrieving data specific to a single user:

  • userGetProfileInformation(): Returns a SimpleXML object containing the current user's profile information.

  • userGetTopArtists(): Returns a SimpleXML object containing a list of the current user's most listened to artists.

  • userGetTopAlbums(): Returns a SimpleXML object containing a list of the current user's most listened to albums.

  • userGetTopTracks(): Returns a SimpleXML object containing a list of the current user's most listened to tracks.

  • userGetTopTags(): Returns a SimpleXML object containing a list of tags most applied by the current user.

  • userGetTopTagsForArtist(): Requires that an artist be set via setArtist(). Returns a SimpleXML object containing the tags most applied to the current artist by the current user.

  • userGetTopTagsForAlbum(): Requires that an album be set via setAlbum(). Returns a SimpleXML object containing the tags most applied to the current album by the current user.

  • userGetTopTagsForTrack(): Requires that a track be set via setTrack(). Returns a SimpleXML object containing the tags most applied to the current track by the current user.

  • userGetFriends(): Returns a SimpleXML object containing the user names of the current user's friends.

  • userGetNeighbours(): Returns a SimpleXML object containing the user names of people with similar listening habits to the current user.

  • userGetRecentTracks(): Returns a SimpleXML object containing the 10 tracks most recently played by the current user.

  • userGetRecentBannedTracks(): Returns a SimpleXML object containing a list of the 10 tracks most recently banned by the current user.

  • userGetRecentLovedTracks(): Returns a SimpleXML object containing a list of the 10 tracks most recently loved by the current user.

  • userGetRecentJournals(): Returns a SimpleXML object containing a list of the current user's most recent journal entries.

  • userGetWeeklyChartList(): Returns a SimpleXML object containing a list of weeks for which there exist Weekly Charts for the current user.

  • userGetRecentWeeklyArtistChart(): Returns a SimpleXML object containing the most recent Weekly Artist Chart for the current user.

  • userGetRecentWeeklyAlbumChart(): Returns a SimpleXML object containing the most recent Weekly Album Chart for the current user.

  • userGetRecentWeeklyTrackChart(): Returns a SimpleXML object containing the most recent Weekly Track Chart for the current user.

  • userGetPreviousWeeklyArtistChart($fromDate, $toDate): Returns a SimpleXML object containing the Weekly Artist Chart from $fromDate to $toDate for the current user.

  • userGetPreviousWeeklyAlbumChart($fromDate, $toDate): Returns a SimpleXML object containing the Weekly Album Chart from $fromDate to $toDate for the current user.

  • userGetPreviousWeeklyTrackChart($fromDate, $toDate): Returns a SimpleXML object containing the Weekly Track Chart from $fromDate to $toDate for the current user.

Example 783. Retrieving User Profile Information

In this example, we use the setUser() and userGetProfileInformation() methods to retrieve a specific user's profile information:

<?php
$as 
= new Zend_Service_Audioscrobbler();
// Set the user whose profile information we want to retrieve
$as->setUser('BigDaddy71');
// Retrieve BigDaddy71's profile information
$profileInfo $as->userGetProfileInformation();
// Display some of it
print "Information for $profileInfo->realname "
    
"can be found at $profileInfo->url";

Example 784. Retrieving a User's Weekly Artist Chart

<?php
$as 
= new Zend_Service_Audioscrobbler();
// Set the user whose profile weekly artist chart we want to retrieve
$as->setUser('lo_fye');
// Retrieves a list of previous weeks for which there are chart data
$weeks $as->userGetWeeklyChartList();
if (
count($weeks) < 1) {
    echo 
'No data available';
}
sort($weeks); // Order the list of weeks

$as->setFromDate($weeks[0]); // Set the starting date
$as->setToDate($weeks[0]); // Set the ending date

$previousWeeklyArtists $as->userGetPreviousWeeklyArtistChart();

echo 
'Artist Chart For Week Of '
   
date('Y-m-d h:i:s'$as->from_date)
   . 
'<br />';

foreach (
$previousWeeklyArtists as $artist) {
    
// Display the artists' names with links to their profiles
    
print '<a href="' $artist->url '">' $artist->name '</a><br />';
}

Zend Framework