Пример #1
0
 /**
  * Display an HTML5 video
  *
  * @return     void
  */
 public function videoTask()
 {
     //get the request vars
     $parent = Request::getInt('id', 0);
     $child = Request::getVar('resid', '');
     if (!$parent || !$child) {
         App::abort(404, Lang::txt('COM_RESOURCES_RESOURCE_NOT_FOUND'));
     }
     //load resource
     $activechild = new Resource($this->database);
     $activechild->load($child);
     // check to see if we have a manifest
     if (!$this->videoManifestExistsForResource($activechild)) {
         $this->createVideoManifestForResource($activechild);
     }
     //get manifest
     $manifest = $this->getVideoManifestForResource($activechild);
     if (!file_exists(PATH_APP . $manifest)) {
         App::abort(404, Lang::txt('COM_RESOURCES_RESOURCE_NOT_FOUND'));
     }
     $manifest = json_decode(file_get_contents(PATH_APP . $manifest));
     //media tracking object
     require_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'mediatracking.php';
     $mediaTracking = new MediaTracking($this->database);
     //get tracking for this user for this resource
     $tracking = $mediaTracking->getTrackingInformationForUserAndResource(User::get('id'), $activechild->id);
     //check to see if we already have a time query param
     $hasTime = Request::getVar('time', '') != '' ? true : false;
     //do we want to redirect user with time added to url
     if (is_object($tracking) && !$hasTime && $tracking->current_position > 0 && $tracking->current_position != $tracking->object_duration) {
         $redirect = 'index.php?option=com_resources&task=video&id=' . $parent . '&resid=' . $child;
         if (Request::getVar('tmpl', '') == 'component') {
             $redirect .= '&tmpl=component';
         }
         //append current position to redirect
         $redirect .= '&time=' . gmdate("H:i:s", $tracking->current_position);
         //redirect
         App::redirect(Route::url($redirect, false), '', '', false);
     }
     // Instantiate a new view
     $this->view = new \Hubzero\Component\View(array('name' => 'view', 'layout' => 'video'));
     $this->view->option = $this->_option;
     $this->view->config = $this->config;
     $this->view->database = $this->database;
     $this->view->resource = $activechild;
     $this->view->manifest = $manifest;
     // Output HTML
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->display();
 }
Пример #2
0
 /**
  * Track video viewing progress
  *
  * @return     void
  */
 public function trackingTask()
 {
     // Include need media tracking library
     require_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'mediatracking.php';
     require_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'mediatrackingdetailed.php';
     // Instantiate objects
     $database = \App::get('db');
     $session = \App::get('session');
     // Get request vars
     $time = Request::getVar('time', 0);
     $duration = Request::getVar('duration', 0);
     $event = Request::getVar('event', 'update');
     $resourceid = Request::getVar('resourceid', 0);
     $detailedId = Request::getVar('detailedTrackingId', 0);
     $ipAddress = $_SERVER['REMOTE_ADDR'];
     // Check for asset id
     if (!$resourceid) {
         echo 'Unable to find resource identifier.';
         return;
     }
     // Instantiate new media tracking object
     $mediaTracking = new MediaTracking($database);
     $mediaTrackingDetailed = new MediaTrackingDetailed($database);
     // Load tracking information for user for this resource
     $trackingInformation = $mediaTracking->getTrackingInformationForUserAndResource(User::get('id'), $resourceid, 'course');
     $trackingInformationDetailed = $mediaTrackingDetailed->loadByDetailId($detailedId);
     // Are we creating a new tracking record
     if (!is_object($trackingInformation)) {
         $trackingInformation = new stdClass();
         $trackingInformation->user_id = User::get('id');
         $trackingInformation->session_id = $session->getId();
         $trackingInformation->ip_address = $ipAddress;
         $trackingInformation->object_id = $resourceid;
         $trackingInformation->object_type = 'course';
         $trackingInformation->object_duration = $duration;
         $trackingInformation->current_position = $time;
         $trackingInformation->farthest_position = $time;
         $trackingInformation->current_position_timestamp = Date::toSql();
         $trackingInformation->farthest_position_timestamp = Date::toSql();
         $trackingInformation->completed = 0;
         $trackingInformation->total_views = 1;
         $trackingInformation->total_viewing_time = 0;
     } else {
         // Get the amount of video watched from last tracking event
         $time_viewed = (int) $time - (int) $trackingInformation->current_position;
         // If we have a positive value and its less then our ten second threshold,
         // add viewing time to total watched time
         if ($time_viewed < 10 && $time_viewed > 0) {
             $trackingInformation->total_viewing_time += $time_viewed;
         }
         // Set the new current position
         $trackingInformation->current_position = $time;
         $trackingInformation->current_position_timestamp = Date::toSql();
         // Set the object duration
         if ($duration > 0) {
             $trackingInformation->object_duration = $duration;
         }
         // Check to see if we need to set a new farthest position
         if ($trackingInformation->current_position > $trackingInformation->farthest_position) {
             $trackingInformation->farthest_position = $time;
             $trackingInformation->farthest_position_timestamp = Date::toSql();
         }
         // If event type is start, means we need to increment view count
         if ($event == 'start' || $event == 'replay') {
             $trackingInformation->total_views++;
         }
         // If event type is end, we need to increment completed count
         if ($event == 'ended') {
             $trackingInformation->completed++;
         }
     }
     // Save detailed tracking info
     if ($event == 'start' || !$trackingInformationDetailed) {
         $trackingInformationDetailed = new stdClass();
         $trackingInformationDetailed->user_id = User::get('id');
         $trackingInformationDetailed->session_id = $session->getId();
         $trackingInformationDetailed->ip_address = $ipAddress;
         $trackingInformationDetailed->object_id = $resourceid;
         $trackingInformationDetailed->object_type = 'course';
         $trackingInformationDetailed->object_duration = $duration;
         $trackingInformationDetailed->current_position = $time;
         $trackingInformationDetailed->farthest_position = $time;
         $trackingInformationDetailed->current_position_timestamp = Date::toSql();
         $trackingInformationDetailed->farthest_position_timestamp = Date::toSql();
         $trackingInformationDetailed->completed = 0;
     } else {
         // Set the new current position
         $trackingInformationDetailed->current_position = $time;
         $trackingInformationDetailed->current_position_timestamp = Date::toSql();
         // Set the object duration
         if ($duration > 0) {
             $trackingInformationDetailed->object_duration = $duration;
         }
         // Check to see if we need to set a new farthest position
         if (isset($trackingInformationDetailed->farthest_position) && $trackingInformationDetailed->current_position > $trackingInformationDetailed->farthest_position) {
             $trackingInformationDetailed->farthest_position = $time;
             $trackingInformationDetailed->farthest_position_timestamp = Date::toSql();
         }
         // If event type is end, we need to increment completed count
         if ($event == 'ended') {
             $trackingInformationDetailed->completed++;
         }
     }
     // Save detailed
     $mediaTrackingDetailed->save($trackingInformationDetailed);
     // Save tracking information
     if ($mediaTracking->save($trackingInformation)) {
         if (!isset($trackingInformation->id)) {
             $trackingInformation->id = $mediaTracking->id;
         }
         $trackingInformation->detailedId = $mediaTrackingDetailed->id;
         echo json_encode($trackingInformation);
     }
 }
Пример #3
0
 /**
  * Display an HTML5 video
  *
  * @return  void
  */
 public function videoTask()
 {
     //get the request vars
     $parent = Request::getInt('id', 0);
     $child = Request::getVar('resid', '');
     if (!$parent || !$child) {
         App::abort(404, Lang::txt('COM_RESOURCES_RESOURCE_NOT_FOUND'));
     }
     // Load the resource
     include_once dirname(dirname(__DIR__)) . DS . 'models' . DS . 'resource.php';
     $this->model = Models\Resource::getInstance($parent);
     // Make sure we got a result from the database
     if (!$this->model->exists() || $this->model->deleted()) {
         App::abort(404, Lang::txt('COM_RESOURCES_RESOURCE_NOT_FOUND'));
     }
     // Make sure the resource is published and standalone
     if (!$this->model->resource->standalone) {
         App::abort(403, Lang::txt('COM_RESOURCES_ALERTNOTAUTH'));
     }
     // Is the visitor authorized to view this resource?
     if (User::isGuest() && ($this->model->resource->access == 1 || $this->model->resource->access == 4)) {
         $return = base64_encode(Request::getVar('REQUEST_URI', Route::url('index.php?option=' . $this->_option . ($this->model->resource->alias ? '&alias=' . $this->model->resource->alias : '&id=' . $this->model->resource->id), false, true), 'server'));
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . $return, false), Lang::txt('COM_RESOURCES_ALERTLOGIN_REQUIRED'), 'warning');
     }
     if ($this->model->resource->group_owner && !$this->model->access('view-all')) {
         App::abort(403, Lang::txt('COM_RESOURCES_ALERTNOTAUTH_GROUP', $this->model->resource->group_owner, Route::url('index.php?option=com_groups&cn=' . $this->model->resource->group_owner)));
     }
     if (!$this->model->access('view')) {
         App::abort(403, Lang::txt('COM_RESOURCES_ALERTNOTAUTH'));
     }
     //load resource
     $activechild = new Resource($this->database);
     $activechild->load($child);
     // check to see if we have a manifest
     if (!$this->videoManifestExistsForResource($activechild)) {
         $this->createVideoManifestForResource($activechild);
     }
     //get manifest
     $manifest = $this->getVideoManifestForResource($activechild);
     if (!file_exists(PATH_APP . $manifest)) {
         App::abort(404, Lang::txt('COM_RESOURCES_RESOURCE_NOT_FOUND'));
     }
     $manifest = json_decode(file_get_contents(PATH_APP . $manifest));
     //media tracking object
     require_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'mediatracking.php';
     $mediaTracking = new MediaTracking($this->database);
     //get tracking for this user for this resource
     $tracking = $mediaTracking->getTrackingInformationForUserAndResource(User::get('id'), $activechild->id);
     //check to see if we already have a time query param
     $hasTime = Request::getVar('time', '') != '' ? true : false;
     //do we want to redirect user with time added to url
     if (is_object($tracking) && !$hasTime && $tracking->current_position > 0 && $tracking->current_position != $tracking->object_duration) {
         $redirect = 'index.php?option=com_resources&task=video&id=' . $parent . '&resid=' . $child;
         if (Request::getVar('tmpl', '') == 'component') {
             $redirect .= '&tmpl=component';
         }
         //append current position to redirect
         $redirect .= '&time=' . gmdate("H:i:s", $tracking->current_position);
         //redirect
         App::redirect(Route::url($redirect, false), '', '', false);
     }
     // Instantiate a new view
     $this->view = new \Hubzero\Component\View(array('name' => 'view', 'layout' => 'video'));
     $this->view->option = $this->_option;
     $this->view->config = $this->config;
     $this->view->database = $this->database;
     $this->view->resource = $activechild;
     $this->view->manifest = $manifest;
     // Output HTML
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->display();
 }