/** * 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; }
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'); } } }