Example #1
0
 /**
  * Records media tracking info
  *
  * @apiMethod POST
  * @apiUri    /system/media/tracking
  * @return    void
  */
 public function trackingTask()
 {
     // 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');
     $entityId = Request::getVar('entity_id', 0);
     $entityType = Request::getVar('entity_type', 'resource');
     $detailedId = Request::getVar('detailed_tracking_id', 0);
     $ipAddress = $_SERVER['REMOTE_ADDR'];
     // Check for entity id
     if (!$entityId) {
         echo 'Unable to find entity identifier.';
         return;
     }
     // Instantiate new media tracking object
     $mediaTracking = new \Components\System\Tables\MediaTracking($database);
     $mediaTrackingDetailed = new \Components\System\Tables\MediaTrackingDetailed($database);
     // Load tracking information for user for this entity
     $trackingInformation = $mediaTracking->getTrackingInformationForUserAndResource(User::get('id'), $entityId, $entityType);
     $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 = $entityId;
         $trackingInformation->object_type = $entityType;
         $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 = $entityId;
         $trackingInformationDetailed->object_type = $entityType;
         $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;
         $this->send($trackingInformation);
     }
 }
Example #2
0
    // Make sure we don't already have this file
    if (!in_array($subtitle->source, $subFiles)) {
        $subs[] = $subtitle;
    }
}
// Add the HUBpresenter stylesheet and scripts
$this->css('hubpresenter');
$this->js('hubpresenter');
$this->js('hubpresenter.plugins');
$this->js('jquery.colpick.js', 'system');
$this->css('jquery.colpick.css', 'system');
// Include media tracking
if (isset($this->entityId) && isset($this->entityType)) {
    require_once PATH_CORE . DS . 'components' . DS . 'com_system' . DS . 'tables' . DS . 'mediatracking.php';
    $dbo = \App::get('db');
    $mediaTracking = new \Components\System\Tables\MediaTracking($dbo);
    // Get tracking for this user for this resource
    $tracking = $mediaTracking->getTrackingInformationForUserAndResource(User::get('id'), $this->entityId, $this->entityType);
    // 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 && !Request::getInt('no_html', 0)) {
        $redirect = Request::current(true);
        // do we have tmpl=componet in url?
        $delimeter = strpos($redirect, '?') === false ? '?' : '&';
        if (Request::getVar('tmpl', '') == 'component') {
            $redirect .= $delimeter . 'tmpl=component';
        }
        $delimeter = strpos($redirect, '?') === false ? '?' : '&';
        // Append current position to redirect
        $redirect .= $delimeter . 'time=' . gmdate("H:i:s", $tracking->current_position);