/**
  * lookup progress for a specific object
  *
  * @access public
  * @param int obj_id
  * @return array of progress data 
  */
 public static function _lookupProgressByObjId($a_obj_id)
 {
     include_once './Services/Tracking/classes/class.ilChangeEvent.php';
     foreach (ilChangeEvent::_lookupReadEvents($a_obj_id) as $row) {
         if (isset($progress[$row['usr_id']])) {
             $progress[$row['usr_id']]['spent_seconds'] += $row['spent_seconds'];
             $progress[$row['usr_id']]['read_count'] += $row['read_count'];
             $progress[$row['usr_id']]['ts'] = max($row['last_access'], $progress[$row['usr_id']]['ts']);
         } else {
             $progress[$row['usr_id']]['spent_seconds'] = $row['spent_seconds'];
             $progress[$row['usr_id']]['read_count'] = $row['read_count'];
             $progress[$row['usr_id']]['ts'] = $row['last_access'];
         }
         $progress[$row['usr_id']]['usr_id'] = $row['usr_id'];
         $progress[$row['usr_id']]['obj_id'] = $row['obj_id'];
     }
     return $progress ? $progress : array();
 }
 /**
  * add standard object section
  */
 function addObjectSections()
 {
     global $lng, $ilCtrl, $ilUser, $ilAccess, $tree, $ilSetting, $ilObjDataCache;
     $this->addSection($lng->txt("additional_info"));
     $a_obj = $this->gui_object->object;
     // links to the object
     if (is_object($a_obj)) {
         // permanent link
         $type = $a_obj->getType();
         $ref_id = $a_obj->getRefId();
         if ($ref_id) {
             include_once './Services/Link/classes/class.ilLink.php';
             $href = ilLink::_getStaticLink($ref_id, $type, true);
             include_once 'Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
             if (ilECSServerSettings::getInstance()->activeServerExists()) {
                 $this->addProperty($lng->txt("object_id"), $a_obj->getId());
             }
             include_once 'Services/PermanentLink/classes/class.ilPermanentLinkGUI.php';
             $pm = new ilPermanentLinkGUI($type, $ref_id);
             $pm->setIncludePermanentLinkText(false);
             $pm->setAlignCenter(false);
             $this->addProperty($lng->txt("perma_link"), $pm->getHTML(), "");
             // bookmarks
             $title = $ilObjDataCache->lookupTitle($a_obj->getId());
             $bms = ilPermanentLinkGUI::_getBookmarksSelectionList($title, $href);
             // links to resource
             if ($ilAccess->checkAccess("write", "", $ref_id) || $ilAccess->checkAccess("edit_permissions", "", $ref_id)) {
                 $obj_id = $a_obj->getId();
                 $rs = ilObject::_getAllReferences($obj_id);
                 $refs = array();
                 foreach ($rs as $r) {
                     if ($tree->isInTree($r)) {
                         $refs[] = $r;
                     }
                 }
                 if (count($refs) > 1) {
                     $links = $sep = "";
                     foreach ($refs as $r) {
                         $cont_loc = new ilLocatorGUI();
                         $cont_loc->addContextItems($r, true);
                         $links .= $sep . $cont_loc->getHTML();
                         $sep = "<br />";
                     }
                     $this->addProperty($lng->txt("res_links"), '<div class="small">' . $links . '</div>');
                 }
             }
         }
     }
     // creation date
     $this->addProperty($lng->txt("create_date"), ilDatePresentation::formatDate(new ilDateTime($a_obj->getCreateDate(), IL_CAL_DATETIME)));
     // owner
     if ($ilUser->getId() != ANONYMOUS_USER_ID and $a_obj->getOwner()) {
         include_once './Services/Object/classes/class.ilObjectFactory.php';
         include_once './Services/User/classes/class.ilObjUser.php';
         if (ilObjUser::userExists(array($a_obj->getOwner()))) {
             $ownerObj = ilObjectFactory::getInstanceByObjId($a_obj->getOwner(), false);
         } else {
             $ownerObj = ilObjectFactory::getInstanceByObjId(6, false);
         }
         if (!is_object($ownerObj) || $ownerObj->getType() != "usr") {
             $this->addProperty($lng->txt("owner"), $lng->txt("no_owner"));
         } else {
             if ($ownerObj->hasPublicProfile()) {
                 $ilCtrl->setParameterByClass("ilpublicuserprofilegui", "user_id", $ownerObj->getId());
                 $this->addProperty($lng->txt("owner"), $ownerObj->getPublicName(), $ilCtrl->getLinkTargetByClass("ilpublicuserprofilegui", "getHTML"));
             } else {
                 $this->addProperty($lng->txt("owner"), $ownerObj->getPublicName());
             }
         }
     }
     // disk usage
     require_once 'Services/WebDAV/classes/class.ilDiskQuotaActivationChecker.php';
     if ($ilUser->getId() != ANONYMOUS_USER_ID && ilDiskQuotaActivationChecker::_isActive()) {
         $size = $a_obj->getDiskUsage();
         if ($size !== null) {
             $this->addProperty($lng->txt("disk_usage"), ilFormat::formatSize($size, 'long'));
         }
     }
     // change event
     require_once 'Services/Tracking/classes/class.ilChangeEvent.php';
     if (ilChangeEvent::_isActive()) {
         if ($ilUser->getId() != ANONYMOUS_USER_ID) {
             $readEvents = ilChangeEvent::_lookupReadEvents($a_obj->getId());
             $count_users = 0;
             $count_members = 0;
             $count_user_reads = 0;
             $count_anonymous_reads = 0;
             foreach ($readEvents as $evt) {
                 if ($evt['usr_id'] == ANONYMOUS_USER_ID) {
                     $count_anonymous_reads += $evt['read_count'];
                 } else {
                     $count_user_reads += $evt['read_count'];
                     $count_users++;
                     /* to do: if ($evt['user_id'] is member of $this->getRefId())
                     			{
                     				$count_members++;
                     			}*/
                 }
             }
             if ($count_anonymous_reads > 0) {
                 $this->addProperty($this->lng->txt("readcount_anonymous_users"), $count_anonymous_reads);
             }
             if ($count_user_reads > 0) {
                 $this->addProperty($this->lng->txt("readcount_users"), $count_user_reads);
             }
             if ($count_users > 0) {
                 $this->addProperty($this->lng->txt("accesscount_registered_users"), $count_users);
             }
         }
     }
     // END ChangeEvent: Display change event info
     // BEGIN WebDAV: Display locking information
     require_once 'Services/WebDAV/classes/class.ilDAVServer.php';
     if (ilDAVServer::_isActive()) {
         global $ilias, $ilUser;
         if ($ilUser->getId() != ANONYMOUS_USER_ID) {
             $davLocks = new ilDAVLocks();
             // Show lock info
             if ($ilias->account->getId() != ANONYMOUS_USER_ID) {
                 $locks =& $davLocks->getLocksOnObjectObj($a_obj->getId());
                 if (count($locks) > 0) {
                     $lockUser = new ilObjUser($locks[0]['ilias_owner']);
                     $this->addProperty($this->lng->txt("in_use_by"), $lockUser->getPublicName(), "./ilias.php?user=" . $locks[0]['ilias_owner'] . '&cmd=showUserProfile&cmdClass=ilpersonaldesktopgui&cmdNode=1&baseClass=ilPersonalDesktopGUI');
                 }
             }
         }
     }
     // END WebDAV: Display locking information
 }
 /**
  * Determine percentage
  *
  * @param	integer		object id
  * @param	integer		user id
  * @param	object		object (optional depends on object type)
  * @return	integer		percentage
  */
 function determinePercentage($a_obj_id, $a_user_id, $a_obj = null)
 {
     include_once 'Services/Tracking/classes/class.ilLPObjSettings.php';
     $reqv = ilLPObjSettings::_lookupVisits($a_obj_id);
     $re = ilChangeEvent::_lookupReadEvents($a_obj_id, $a_user_id);
     $rc = (int) $re[0]["read_count"];
     if ($reqv > 0) {
         $per = min(100, 100 / $reqv * $rc);
     } else {
         $per = 100;
     }
     return $per;
 }
 /**
  * Determine percentage
  *
  * @param	integer		object id
  * @param	integer		user id
  * @param	object		object (optional depends on object type)
  * @return	integer		percentage
  */
 function determinePercentage($a_obj_id, $a_user_id, $a_obj = null)
 {
     $tlt = (int) ilMDEducational::_getTypicalLearningTimeSeconds($a_obj_id);
     $re = ilChangeEvent::_lookupReadEvents($a_obj_id, $a_user_id);
     $spent = (int) $re[0]["spent_seconds"];
     if ($tlt > 0) {
         $per = min(100, 100 / $tlt * $spent);
     } else {
         $per = 100;
     }
     return $per;
 }
 function il2sopSahsUser()
 {
     global $ilDB, $ilUser;
     $package_attempts = 0;
     $module_version = 1;
     //if module_version in sop is different...
     $last_visited = "";
     $first_access = null;
     $last_access = null;
     $last_status_change = null;
     $total_time_sec = null;
     $sco_total_time_sec = 0;
     $status = 0;
     $percentage_completed = 0;
     $user_data = "";
     global $ilDB, $ilUser;
     $res = $ilDB->queryF('SELECT * FROM sahs_user WHERE obj_id=%s AND user_id=%s', array('integer', 'integer'), array($this->obj_id, $ilUser->getID()));
     while ($row = $ilDB->fetchAssoc($res)) {
         $package_attempts = $row['package_attempts'];
         $module_version = $row['module_version'];
         $last_visited = $row['last_visited'];
         if ($row['first_access'] != null) {
             $first_access = strtotime($row['first_access']) * 1000;
             //check Oracle!
         }
         if ($row['last_access'] != null) {
             $last_access = strtotime($row['last_access']) * 1000;
             //check Oracle!
         }
         $total_time_sec = $row['total_time_sec'];
         $sco_total_time_sec = $row['sco_total_time_sec'];
         $status = $row['status'];
         $percentage_completed = $row['percentage_completed'];
     }
     if ($first_access == null) {
         include_once './Services/Tracking/classes/class.ilChangeEvent.php';
         $all = ilChangeEvent::_lookupReadEvents($this->obj_id, $ilUser->getID());
         foreach ($all as $event) {
             $first_access = strtotime($event['first_access']) * 1000;
             //
         }
     }
     return array($package_attempts, $module_version, $last_visited, $first_access, $last_access, $last_status_change, $total_time_sec, $sco_total_time_sec, $status, $percentage_completed, $user_data);
 }