Exemple #1
0
 /**
  * get_missing_albums
  * Get list of library's missing albums from MusicBrainz
  * @param Artist|null $artist
  * @param string $mbid
  * @return array
  */
 public static function get_missing_albums($artist, $mbid = '')
 {
     $mb = new MusicBrainz(new RequestsHttpAdapter());
     $includes = array('release-groups');
     $types = explode(',', AmpConfig::get('wanted_types'));
     try {
         $martist = $mb->lookup('artist', $artist ? $artist->mbid : $mbid, $includes);
     } catch (Exception $e) {
         return null;
     }
     $owngroups = array();
     $wartist = array();
     if ($artist) {
         $albums = $artist->get_albums();
         foreach ($albums as $id) {
             $album = new Album($id);
             if (trim($album->mbid_group)) {
                 $owngroups[] = $album->mbid_group;
             } else {
                 if (trim($album->mbid)) {
                     $malbum = $mb->lookup('release', $album->mbid, array('release-groups'));
                     if ($malbum->{'release-group'}) {
                         if (!in_array($malbum->{'release-group'}->id, $owngroups)) {
                             $owngroups[] = $malbum->{'release-group'}->id;
                         }
                     }
                 }
             }
         }
     } else {
         $wartist['mbid'] = $mbid;
         $wartist['name'] = $martist->name;
         parent::add_to_cache('missing_artist', $mbid, $wartist);
         $wartist = self::get_missing_artist($mbid);
     }
     $results = array();
     foreach ($martist->{'release-groups'} as $group) {
         if (in_array(strtolower($group->{'primary-type'}), $types)) {
             $add = true;
             for ($i = 0; $i < count($group->{'secondary-types'}) && $add; ++$i) {
                 $add = in_array(strtolower($group->{'secondary-types'}[$i]), $types);
             }
             if ($add) {
                 if (!in_array($group->id, $owngroups)) {
                     $wantedid = self::get_wanted($group->id);
                     $wanted = new Wanted($wantedid);
                     if ($wanted->id) {
                         $wanted->format();
                     } else {
                         $wanted->mbid = $group->id;
                         if ($artist) {
                             $wanted->artist = $artist->id;
                         } else {
                             $wanted->artist_mbid = $mbid;
                         }
                         $wanted->name = $group->title;
                         if (!empty($group->{'first-release-date'})) {
                             if (strlen($group->{'first-release-date'}) == 4) {
                                 $wanted->year = $group->{'first-release-date'};
                             } else {
                                 $wanted->year = date("Y", strtotime($group->{'first-release-date'}));
                             }
                         }
                         $wanted->accepted = false;
                         $wanted->link = AmpConfig::get('web_path') . "/albums.php?action=show_missing&mbid=" . $group->id;
                         if ($artist) {
                             $wanted->link .= "&artist=" . $wanted->artist;
                         } else {
                             $wanted->link .= "&artist_mbid=" . $mbid;
                         }
                         $wanted->f_link = "<a href=\"" . $wanted->link . "\" title=\"" . $wanted->name . "\">" . $wanted->name . "</a>";
                         $wanted->f_artist_link = $artist ? $artist->f_link : $wartist['link'];
                         $wanted->f_user = $GLOBALS['user']->f_name;
                     }
                     $results[] = $wanted;
                 }
             }
         }
     }
     return $results;
 }
</th>
            <th class="cel_user optional"><?php 
echo Ajax::text('?page=browse&action=set_sort&browse_id=' . $browse->id . '&type=wanted&sort=user', T_('User'), 'sort_wanted_user');
?>
</th>
            <th class="cel_action essential"><?php 
echo T_('Actions');
?>
</th>
        </tr>
    </thead>
    <tbody>
        <?php 
foreach ($object_ids as $wanted_id) {
    $libitem = new Wanted($wanted_id);
    $libitem->format();
    ?>
        <tr id="walbum_<?php 
    echo $libitem->mbid;
    ?>
" class="<?php 
    echo UI::flip_class();
    ?>
">
            <?php 
    require AmpConfig::get('prefix') . UI::find_template('show_wanted_album_row.inc.php');
    ?>
        </tr>
        <?php 
}
?>
</th>
            <th class="cel_user optional"><?php 
echo Ajax::text('?page=browse&action=set_sort&browse_id=' . $browse->id . '&type=wanted&sort=user', T_('User'), 'sort_wanted_user');
?>
</th>
            <th class="cel_action essential"><?php 
echo T_('Actions');
?>
</th>
        </tr>
    </thead>
    <tbody>
        <?php 
foreach ($object_ids as $wanted_id) {
    $walbum = new Wanted($wanted_id);
    $walbum->format();
    ?>
        <tr id="walbum_<?php 
    echo $walbum->mbid;
    ?>
" class="<?php 
    echo UI::flip_class();
    ?>
">
            <?php 
    require AmpConfig::get('prefix') . '/templates/show_wanted_album_row.inc.php';
    ?>
        </tr>
        <?php 
}
?>