本文整理汇总了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');
}
}
}