/** * Get asset views/completions * * @param (int) $member_id * @return (array) **/ public function views($member_id) { $filters = array('section_id' => $this->course->offering()->section()->get('id'), 'member_id' => $member_id); // Get the asset views $database = \App::get('db'); $assetViews = new Tables\AssetViews($database); $results = $assetViews->find($filters); $views = array(); if ($results && count($results) > 0) { foreach ($results as $result) { $views[$result->member_id][] = $result->asset_id; } } return $views; }
/** * Track asset views * * @param object $course \Components\Courses\Models\Course * @return mixed */ public function logView($course = null) { require_once dirname(__DIR__) . DS . 'tables' . DS . 'asset.views.php'; if (!$course || !is_object($course)) { $gid = Request::getVar('gid'); $offering = Request::getVar('offering'); $section = Request::getVar('section'); $course = new Course($gid); $course->offering($offering); $course->offering()->section($section); } $member = $course->offering()->section()->member(User::get('id')); if (!$member->get('id')) { $member = $course->offering()->member(User::get('id')); } if (!$member || !is_object($member) || !$member->get('id')) { return false; } $view = new Tables\AssetViews($this->_db); $view->asset_id = $this->_tbl->id; $view->course_id = $this->get('course_id'); $view->viewed = Date::toSql(); $view->viewed_by = $member->get('id'); $view->ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $view->url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; $view->referrer = isset($_SERVER['HTTP_REFERRER']) ? $_SERVER['HTTP_REFERRER'] : ''; $view->user_agent_string = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $view->session_id = App::get('session')->getId(); if (!$view->store()) { $this->setError($view->getError()); } }