当前位置: 首页>>代码示例>>PHP>>正文


PHP Track::setName方法代码示例

本文整理汇总了PHP中Track::setName方法的典型用法代码示例。如果您正苦于以下问题:PHP Track::setName方法的具体用法?PHP Track::setName怎么用?PHP Track::setName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Track的用法示例。


在下文中一共展示了Track::setName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: fromXML

 /**
  * @param SimpleXMLElement $xml
  * @return Track
  */
 public static function fromXML(SimpleXMLElement $xml)
 {
     $track = new Track();
     if (!empty($xml->name)) {
         $track->setName((string) $xml->name[0]);
     }
     if (!empty($xml->cmt)) {
         $track->setComment((string) $xml->cmt[0]);
     }
     if (!empty($xml->desc)) {
         $track->setDescription((string) $xml->desc[0]);
     }
     if (!empty($xml->src)) {
         $track->setSource((string) $xml->src[0]);
     }
     if (!empty($xml->link)) {
         $links = [];
         foreach ($xml->link as $link) {
             array_push($links, Link::fromXML($link));
         }
         $track->setLinks($links);
     }
     if (!empty($xml->number)) {
         $track->setNumber((int) $xml->number[0]);
     }
     if (!empty($xml->type)) {
         $track->setType((string) $xml->type[0]);
     }
     if (!empty($xml->extensions)) {
         $track->setExtensions(Extensions::fromXML($xml->extensions[0]));
     }
     if (!empty($xml->trkseg)) {
         $trackSegments = [];
         foreach ($xml->trkseg as $trackSegment) {
             array_push($trackSegments, TrackSegment::fromXML($trackSegment));
         }
         $track->setTrackSegments($trackSegments);
     }
     return $track;
 }
开发者ID:Crayg,项目名称:PHPGPX,代码行数:44,代码来源:Track.php

示例2: findArtistTracks

 public static function findArtistTracks($entityManager)
 {
     #get the configuration file for the app
     $file = file_get_contents(__DIR__ . "/../../etc/config.json");
     $config = json_decode($file, true);
     $artistRepository = $entityManager->getRepository('Artist');
     $artists = $artistRepository->findBy(array('hasTracks' => NULL), array('name' => 'ASC'), 30, 0);
     if (count($artists) == 0) {
         error_log("no trackless artists. Exit");
         return;
     } else {
         error_log(count($artists) . "artist(s) to process.");
     }
     foreach ($artists as $artist) {
         $name = $artist->getName();
         if (!$name) {
             continue;
         }
         #ignore artists that already have tracks
         if ($artist->getTracks()->count()) {
             $entityManager->persist($artist);
             continue;
         }
         error_log("processing {$name}");
         $spotifyId = $artist->getSpotifyId();
         $parameters = array('bucket' => array('id:spotify-WW', 'tracks'), 'limit' => "true", "results" => 10);
         if ($spotifyId) {
             $parameters['artist_id'] = $spotifyId;
         } else {
             $parameters['artist'] = $name;
         }
         $query = http_build_query($parameters);
         $query = preg_replace("/\\%5B\\d+\\%5D/im", "", $query);
         \Echonest\Service\Echonest::configure($config['echonest']['key']);
         $response = \Echonest\Service\Echonest::query('song', 'search', $query);
         $response = $response->response;
         if ($response && $response->status->code == 0) {
             $songs = $response->songs;
             $entityManager->persist($artist);
             #no songs, move on to next artist
             if (!count($songs)) {
                 $artist->setHasTracks(false);
                 continue;
             } else {
                 $artist->setHasTracks(true);
             }
             foreach ($songs as $song) {
                 $track = new \Track();
                 $title = $song->title;
                 $track->setName($title);
                 $foreign = array_shift($song->tracks);
                 if ($foreign) {
                     $spotifyId = $foreign->foreign_id;
                     $track->setSpotifyId($spotifyId);
                 }
                 $artist->addTrack($track);
                 $track->assignToArtist($artist);
                 $entityManager->persist($track);
             }
         } else {
             error_log("error: " . $response->status->message);
             break;
         }
     }
     $entityManager->flush();
 }
开发者ID:andreiamlm,项目名称:ThisDayInMusic,代码行数:66,代码来源:ThisDayInMusic.php


注:本文中的Track::setName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。