本文整理匯總了PHP中Track::whereIn方法的典型用法代碼示例。如果您正苦於以下問題:PHP Track::whereIn方法的具體用法?PHP Track::whereIn怎麽用?PHP Track::whereIn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Track
的用法示例。
在下文中一共展示了Track::whereIn方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: edit
/**
* Edit a playlist
*/
private function edit()
{
Base::requireLogged();
if (LOGGED !== $this->playlist->user_id) {
Base::requireAdmin();
}
// Set page title
View::set('page_title', 'Edit playlist');
// Set playlist
$playlist = $this->playlist->asArray();
$playlist['tracks'] = $this->playlist->tracks();
$tags = $this->playlist->tags();
if ($tags) {
$playlist['tags'] = implode(', ', $tags);
}
View::set('playlist', $playlist);
// Not submitted
if (!isset($_POST['playlist']) && !isset($_POST['draft'])) {
View::show('playlist/edit');
}
/**
* Add playlist title and playlist description
*/
if (!Validate::len($_POST['title'], 2, 64)) {
$error = 'Playlist title must be between 2 and 64 chars';
} elseif (!Validate::len($_POST['description'], 0, 512)) {
$error = 'Playlist description must be lesser than 512 chars';
}
if ($error) {
View::error('playlist/edit', $error);
}
// Raw HTML may enter the db but it's automatically
// encoded at output by Mustache
$this->playlist->title = $_POST['title'];
$this->playlist->description = $_POST['description'];
/**
* Uploads cover image
*/
if (!empty($_FILES['cover']) && $_FILES['cover']['size'] > 0) {
Base::uploadImage($_FILES['cover'], $cover, $error);
if ($error) {
View::error('playlist/edit', $error);
}
$this->playlist->cover = $cover;
}
/**
* Inserts tags into database
*/
if (!empty($_POST['tags'])) {
// Separates tags by commas
$tags = strtolower($_POST['tags']);
$tags = explode(',', $tags, 6);
// Tag limit
$tags = array_slice($tags, 0, 5);
// Filter tags
foreach ($tags as $k => &$tag) {
if (!ADMIN && $tag === 'staff') {
continue;
}
$tag = preg_replace('/[^a-z]+/', ' ', $tag);
$tag = trim($tag, ' ');
// Tag must have at least 2 chars
// And it must be lesser than 32 chars
if (!Validate::len($tag, 1, 32)) {
unset($tags[$k]);
}
}
if (!empty($tags)) {
// Remove tags from PlaylistTag
PlaylistTag::where('playlist_id', $this->playlist->id)->deleteMany();
// Insert tags
$sql = str_repeat(',(?)', count($tags));
$sql[0] = ' ';
Tag::rawExecute("INSERT IGNORE INTO tag(name) VALUES {$sql}", $tags);
// Get inserted tags ids and point them to the new playlist
$tags = Tag::select('id')->whereIn('name', $tags)->findMany();
foreach ($tags as $tag) {
$link = PlaylistTag::create();
$link->playlist_id = $this->playlist->id;
$link->tag_id = $tag->id;
$link->save();
}
}
}
// Published status
$this->playlist->published = isset($_POST['playlist']);
/**
* Add tracks into db
*/
if (!isset($_POST['tracks'])) {
$error = 'You can\'t publish without any tracks';
$this->playlist->published = 0;
} else {
if (is_array($_POST['tracks'])) {
$max = Base::$g['playlist_max_tracks'];
$min = Base::$g['playlist_min_tracks'];
$tracks = $_POST['tracks'];
//.........這裏部分代碼省略.........