本文整理汇总了PHP中Artist::insertIfRequired方法的典型用法代码示例。如果您正苦于以下问题:PHP Artist::insertIfRequired方法的具体用法?PHP Artist::insertIfRequired怎么用?PHP Artist::insertIfRequired使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Artist
的用法示例。
在下文中一共展示了Artist::insertIfRequired方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInsertIfRequired
/**
* @covers Artist::insert
* @covers Artist::insertIfRequired
*/
public function testInsertIfRequired()
{
$artistDummy = $this->dummyArtistProvider();
$this->object->mbid = $artistDummy->mbid;
$result = $this->object->insertIfRequired($artistDummy->name, $artistDummy->mbid);
$this->assertEquals(1, $result, 'Artist should be inserted with id #1 but returned: ' . $result);
$artistDummy->name .= '2';
$result = $this->object->insertIfRequired($artistDummy->name, $artistDummy->mbid);
$this->assertEquals(2, $result, 'Artist should be inserted with id #2 but returned: ' . $result);
$result = $this->object->insertIfRequired($artistDummy->name, $artistDummy->mbid);
$this->assertEquals(2, $result, 'Artist should be retrieved with id #2 but returned: ' . $result);
}
示例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;
}