本文整理匯總了PHP中Playlist::findOne方法的典型用法代碼示例。如果您正苦於以下問題:PHP Playlist::findOne方法的具體用法?PHP Playlist::findOne怎麽用?PHP Playlist::findOne使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Playlist
的用法示例。
在下文中一共展示了Playlist::findOne方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: listened
/**
* Adds a playlists to user history
* increments playlist play count
* @return [type] [description]
*/
private function listened()
{
Base::requireLogged();
$ret = array('status' => 0);
if (empty($_GET['id']) || !Validate::int($_GET['id'])) {
return $ret;
}
$id = (int) $_GET['id'];
// Checks if the play is unique
$play = UserListened::where('playlist_id', $id)->where('user_id', LOGGED)->findOne();
if ($play) {
return $ret;
}
// Adds playlist to user listening history
$history = UserListened::create();
$history->user_id = LOGGED;
$history->playlist_id = $id;
$history->save();
// Increment play count
$playlist = Playlist::findOne($id);
if (!$playlist) {
return $ret;
}
$playlist->played_count++;
$playlist->save();
// Everything went right
$ret['status'] = 1;
return $ret;
}
示例2: __construct
function __construct()
{
if (FIRST_PARAMETER === 'playlist' && SECOND_PARAMETER === 'new') {
$this->newPlaylist();
}
if (!FIRST_PARAMETER || !Validate::id(FIRST_PARAMETER)) {
Base::redirect('/oops');
}
$this->playlist = Playlist::findOne((int) FIRST_PARAMETER);
if (!$this->playlist) {
Base::redirect('/oops');
}
// Title
View::set('page_title', $this->playlist->title);
// Playlist not published
if (!$this->playlist->published) {
if (!LOGGED) {
// Not logged
Base::requireLogged();
} else {
if (LOGGED !== $this->playlist->user_id) {
// User not author
Base::requireAdmin();
}
}
}
if (!SECOND_PARAMETER) {
$this->playlist();
} else {
if (ctype_lower(SECOND_PARAMETER) && method_exists($this, SECOND_PARAMETER)) {
$func = SECOND_PARAMETER;
$this->{$func}();
} else {
Base::redirect('/oops');
}
}
}