本文整理汇总了PHP中Playlist::addTrack方法的典型用法代码示例。如果您正苦于以下问题:PHP Playlist::addTrack方法的具体用法?PHP Playlist::addTrack怎么用?PHP Playlist::addTrack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Playlist
的用法示例。
在下文中一共展示了Playlist::addTrack方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getNextTrack
}
public function getNextTrack()
{
if ($this->hasNextElement()) {
return $this->_list->getSongById(++$this->_currentTrack);
}
return false;
}
public function getCurrentTrack()
{
return $this->_list->getSongById($this->_currentTrack);
}
public function hasNextElement()
{
if ($this->_list->getSongById($this->_currentTrack + 1)) {
return true;
}
return false;
}
}
$song1 = new Song('title1', 'author1');
$song2 = new Song('title2', 'author2');
$song3 = new Song('title3', 'author3');
$playlist = new Playlist();
$playlist->addTrack($song1);
$playlist->addTrack($song2);
$playlist->addTrack($song3);
$playlistItterator = new PlaylistItterator($playlist);
while ($playlistItterator->hasNextElement()) {
echo $playlistItterator->getNextTrack()->getTitle() . "<br />";
}
示例2: set
protected function set()
{
#find all the events for this day, as well as the event artists and tracks
$query = $this->entityManager->createQuery('SELECT e,a FROM Event e JOIN e.artist a WHERE e.date LIKE :date');
$query->setParameter("date", "%" . $this->date->format('m-d'));
$events = $query->getResult();
$artistRepository = $this->entityManager->getRepository('Artist');
$artists = $artistRepository->findBy(array("hasTracks" => NULL));
#do not show playlist while the cron hasn't set all artist tracks
if (count($artists)) {
return array("code" => 3, "status" => "No tracks for playlist found. Please try again later.");
}
#find tracks for each event artist and create a playlist with a track for each one of the artists
foreach ($events as $event) {
$artist = $event->getArtist() || next;
#ignores events without artist
#trackless artist will not enter the playlist
if (!$artist->getTracks()->count()) {
error_log("trackless: " . $artist->getName() . ". Not adding to playlist");
continue;
}
$tracks = $artist->getUnPublishedTracks();
#ignore artists with all the tracks already published
if (!count($tracks)) {
continue;
}
$track = array_shift($tracks);
$event->setTrack($track);
$track->assignToEvent($event);
$this->entityManager->persist($track);
$this->entityManager->persist($event);
#add to playlist tracks
array_push($this->tracks, $track);
}
#create new playlist from the tracks found
if (count($this->tracks)) {
$playlist = new \Playlist();
$playlist->setDate($this->date);
foreach ($this->tracks as $track) {
$playlist->addTrack($track);
}
$this->entityManager->persist($playlist);
//update db
$this->entityManager->flush();
//set the total tracks in the attribute
$this->total = $this->total();
}
return 1;
}