本文整理汇总了PHP中Track::structureData方法的典型用法代码示例。如果您正苦于以下问题:PHP Track::structureData方法的具体用法?PHP Track::structureData怎么用?PHP Track::structureData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Track
的用法示例。
在下文中一共展示了Track::structureData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* Returns a specific user's track by it sequence number.
*
* @return mixed|bool track on success, or false on error.
*/
public function get()
{
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Track.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/DatabaseConnection.php';
$connection = new DatabaseConnection();
$query = $connection->prepare('SELECT `track`.`id`, `track`.`title`, `track`.`artist`, `artist`.`name` AS `artistName`, `track`.`album`, `album`.`name` AS `albumName`, `track`.`id` AS `file`, `playlist`.`userId` , `playlist`.`sequence`, `cover`.`albumId` AS `coverId` FROM `track`, `artist`, `playlist`, `album` LEFT JOIN `cover` ON `album`.`id`=`cover`.`albumId` AND `cover`.`status` = 1 WHERE `track`.`artist`=`artist`.`id` AND `track`.`album`=`album`.`id` AND `track`.`id`=`playlist`.`id` AND `playlist`.`userId`=:userId AND `playlist`.`sequence`=:sequence LIMIT 1;');
$query->bindValue(':userId', $this->userId, PDO::PARAM_INT);
$query->bindValue(':sequence', $this->sequence, PDO::PARAM_INT);
$query->execute();
$query->setFetchMode(PDO::FETCH_INTO, $this);
if ($query->fetch()) {
$trackStructured = new Track();
//returns structured track
return $trackStructured->structureData($this);
}
//returns false to indicate there is no such a track for this user
return false;
}
示例2: addFiles
/**
* Scan the specified folder and subfolders, insert in the library the files found.
*
* @param string $folder Root folder to scan
*
* @return array Tracks inserted
*/
public function addFiles($folder)
{
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Artist.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Album.php';
$result = array();
$this->scanFolders($folder, $this->folders);
foreach ($this->files as $file) {
//reset timeout for 20 seconds before processing each file
set_time_limit(20);
$track = new Track();
$track->file = $file;
$trackInfo = $track->readId3();
if (key_exists('comments_html', $trackInfo)) {
//ID3 has been found, we can use it
if (key_exists('title', $trackInfo['comments_html'])) {
$track->title = $trackInfo['comments_html']['title'][0];
}
if (key_exists('album', $trackInfo['comments_html'])) {
$track->albumName = $trackInfo['comments_html']['album'][0];
}
if (key_exists('artist', $trackInfo['comments_html'])) {
$track->artistName = $trackInfo['comments_html']['artist'][0];
}
if (key_exists('track_number', $trackInfo['comments_html'])) {
$track->track = intval($trackInfo['comments_html']['track_number'][0]);
}
if (key_exists('year', $trackInfo['comments_html'])) {
$track->year = intval($trackInfo['comments_html']['year'][0]);
}
if (key_exists('audio', $trackInfo) && key_exists('bitrate_mode', $trackInfo['audio'])) {
$track->mode = $trackInfo['audio']['bitrate_mode'];
}
if (key_exists('audio', $trackInfo) && key_exists('bitrate', $trackInfo['audio'])) {
$track->bitrate = intval($trackInfo['audio']['bitrate']);
}
if (key_exists('playtime_seconds', $trackInfo)) {
$track->time = intval($trackInfo['playtime_seconds']);
}
if (key_exists('filesize', $trackInfo)) {
$track->size = intval($trackInfo['filesize']);
}
}
if (!isset($track->title, $track->albumName, $track->artistName)) {
//We use the filesystem pattern /path/artistName/albumName/title.ext
$elements = explode('/', $file);
$title = str_replace('-', ' ', str_replace('_', ' ', end($elements)));
$albumName = str_replace('-', ' ', str_replace('_', ' ', prev($elements)));
$artistName = str_replace('-', ' ', str_replace('_', ' ', prev($elements)));
if (!isset($track->title)) {
$track->title = $title;
}
if (!isset($track->albumName)) {
$track->albumName = $albumName;
}
if (!isset($track->artistName)) {
$track->artistName = $artistName;
}
}
//insert/update artist
$artist = new Artist();
$track->artist = $artist->insertIfRequired($track->artistName, null);
//insert/update album
$album = new Album();
$track->album = $album->insertIfRequired($track->albumName, null, $track->artist);
//insert track
if ($track->insert()) {
//add to the returned array
array_push($result, $track->structureData($track));
}
}
//return inserted files
return $result;
}
示例3: getTracks
/**
* Get album tracks.
*
* @return mixed Array of album tracks or false on failure
*/
public function getTracks()
{
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Track.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/DatabaseConnection.php';
$connection = new DatabaseConnection();
$query = $connection->prepare('SELECT `track`.`id`, `track`.`track`, `track`.`title`, `track`.`time`, `track`.`artist`, `artist`.`name` AS `artistName` FROM `track` INNER JOIN `artist` ON `artist`.`id` = `track`.`artist` WHERE `track`.`album` = :albumId ORDER BY `track`.`track` ASC;');
$query->bindValue(':albumId', $this->id, PDO::PARAM_INT);
if ($query->execute()) {
$this->tracks = $query->fetchAll(PDO::FETCH_CLASS);
foreach ($this->tracks as $track) {
$trackStructured = new Track();
$track = $trackStructured->structureData($track);
}
//return album tracks
return $this->tracks;
}
//returns database was not reachable
return false;
}