/**
  * Get user items
  */
 function getItems()
 {
     global $lng, $tree;
     $this->determineOffsetAndOrder();
     $additional_fields = $this->getSelectedColumns();
     include_once "./Services/Tracking/classes/class.ilTrQuery.php";
     $tr_data = ilTrQuery::getObjectsDataForUser($this->user_id, $this->obj_id, $this->ref_id, ilUtil::stripSlashes($this->getOrderField()), ilUtil::stripSlashes($this->getOrderDirection()), ilUtil::stripSlashes($this->getOffset()), ilUtil::stripSlashes($this->getLimit()), $this->filter, $additional_fields, $this->filter["view_mode"]);
     if (count($tr_data["set"]) == 0 && $this->getOffset() > 0) {
         $this->resetOffset();
         $tr_data = ilTrQuery::getObjectsDataForUser($this->user_id, $this->obj_id, $this->ref_id, ilUtil::stripSlashes($this->getOrderField()), ilUtil::stripSlashes($this->getOrderDirection()), ilUtil::stripSlashes($this->getOffset()), ilUtil::stripSlashes($this->getLimit()), $this->filter, $additional_fields, $this->filter["view_mode"]);
     }
     $this->setMaxCount($tr_data["cnt"]);
     if ($this->getOrderField() == "title") {
         // sort alphabetically, move parent object to 1st position
         $set = array();
         $parent = false;
         foreach ($tr_data["set"] as $idx => $row) {
             if ($row['obj_id'] == $this->obj_id) {
                 $parent = $row;
             } else {
                 if (isset($row["sort_title"])) {
                     $set[strtolower($row["sort_title"]) . "__" . $idx] = $row;
                 } else {
                     $set[strtolower($row["title"]) . "__" . $idx] = $row;
                 }
             }
         }
         unset($tr_data["set"]);
         if ($this->getOrderDirection() == "asc") {
             ksort($set);
         } else {
             krsort($set);
         }
         $set = array_values($set);
         if ($parent) {
             array_unshift($set, $parent);
         }
         $this->setData($set);
     } else {
         $this->setData($tr_data["set"]);
     }
 }
 /**
  * Return all Placeholders of Learning Progress data
  *
  * @param ilObjCourse $course
  * @param ilObjUser $user
  * @return array
  */
 protected function parseLearningProgressPlaceholders(ilObjCourse $course, ilObjUser $user)
 {
     $passed_datetime = ilCourseParticipants::getDateTimeOfPassed($course->getId(), $user->getId());
     $lp_fields = array('first_access', 'last_access', 'percentage', 'status', 'read_count', 'childs_spent_seconds');
     $lp_data = ilTrQuery::getObjectsDataForUser($user->getId(), $course->getId(), $course->getRefId(), '', '', 0, 9999, null, $lp_fields);
     $lp_avg = $this->buildAvgPercentageOfCourseObjects($lp_data);
     $lp_crs = array();
     $max_last_access = 0;
     foreach ($lp_data['set'] as $v) {
         if ($v['type'] == 'crs') {
             $lp_crs = $v;
             $lp_crs['first_access'] = strtotime($v['first_access']);
             // First access is not stored as UNIX timestamp...
         }
         if ($v['last_access'] > $max_last_access) {
             $max_last_access = $v['last_access'];
         }
     }
     $lp_crs['last_access'] = $max_last_access;
     // calculates spent time different for scorm modules if enabled in config
     /** @var $cert_def srCertificateDefinition */
     $cert_definition = $this->certificate->getDefinition();
     if ($cert_definition->getScormTiming()) {
         $spent_seconds = 0;
         require_once './Services/Object/classes/class.ilObjectLP.php';
         $ilScormLP = ilObjectLP::getInstance($course->getId());
         /**
          * @var $ilLPCollection ilLPCollection
          */
         $ilLPCollection = $ilScormLP->getCollectionInstance();
         if ($ilLPCollection instanceof ilLPCollection) {
             foreach ($ilLPCollection->getItems() as $item) {
                 $spent_seconds += $this->getSpentSeconds(ilObject::_lookupObjectId($item), $user->getId());
             }
         }
         $lp_crs['childs_spent_seconds'] = $spent_seconds;
     }
     $lp_spent_time = $this->buildLpSpentTime($lp_crs);
     return array('DATE_COMPLETED' => $this->formatDate('DATE_COMPLETED', strtotime($passed_datetime)), 'DATETIME_COMPLETED' => $this->formatDateTime('DATETIME_COMPLETED', strtotime($passed_datetime)), 'LP_FIRST_ACCESS' => $this->formatDateTime('LP_FIRST_ACCESS', (int) $lp_crs['first_access']), 'LP_LAST_ACCESS' => $this->formatDateTime('LP_LAST_ACCESS', (int) $lp_crs['last_access']), 'LP_SPENT_TIME' => $lp_spent_time, 'LP_SPENT_SECONDS' => $lp_crs['childs_spent_seconds'], 'LP_READ_COUNT' => $lp_crs['read_count'], 'LP_STATUS' => $lp_crs['status'], 'LP_AVG_PERCENTAGE' => $lp_avg);
 }
 /**
  * Get user items
  */
 function getItems()
 {
     global $rbacsystem;
     $this->determineOffsetAndOrder();
     $additional_fields = $this->getSelectedColumns();
     include_once "./Services/Tracking/classes/class.ilTrQuery.php";
     $tr_data = ilTrQuery::getObjectsDataForUser($this->user_id, $this->obj_id, $this->ref_id, ilUtil::stripSlashes($this->getOrderField()), ilUtil::stripSlashes($this->getOrderDirection()), ilUtil::stripSlashes($this->getOffset()), ilUtil::stripSlashes($this->getLimit()), $this->filter, $additional_fields, $this->filter["view_mode"]);
     if (count($tr_data["set"]) == 0 && $this->getOffset() > 0) {
         $this->resetOffset();
         $tr_data = ilTrQuery::getObjectsDataForUser($this->user_id, $this->obj_id, $this->ref_id, ilUtil::stripSlashes($this->getOrderField()), ilUtil::stripSlashes($this->getOrderDirection()), ilUtil::stripSlashes($this->getOffset()), ilUtil::stripSlashes($this->getLimit()), $this->filter, $additional_fields, $this->filter["view_mode"]);
     }
     // #13807
     foreach ($tr_data["set"] as $idx => $row) {
         if ($row["ref_id"] && !$rbacsystem->checkAccess("read_learning_progress", $row["ref_id"])) {
             foreach (array_keys($row) as $col_id) {
                 if (!in_array($col_id, array("type", "obj_id", "ref_id", "title", "sort_title"))) {
                     $tr_data["set"][$idx][$col_id] = null;
                 }
             }
             $tr_data["set"][$idx]["privacy_conflict"] = true;
         }
     }
     $this->setMaxCount($tr_data["cnt"]);
     if ($this->getOrderField() == "title") {
         // sort alphabetically, move parent object to 1st position
         $set = array();
         $parent = false;
         foreach ($tr_data["set"] as $idx => $row) {
             if ($row['obj_id'] == $this->obj_id) {
                 $parent = $row;
             } else {
                 if (isset($row["sort_title"])) {
                     $set[strtolower($row["sort_title"]) . "__" . $idx] = $row;
                 } else {
                     $set[strtolower($row["title"]) . "__" . $idx] = $row;
                 }
             }
         }
         unset($tr_data["set"]);
         if ($this->getOrderDirection() == "asc") {
             ksort($set);
         } else {
             krsort($set);
         }
         $set = array_values($set);
         if ($parent) {
             array_unshift($set, $parent);
         }
         $this->setData($set);
     } else {
         $this->setData($tr_data["set"]);
     }
 }
 /**
  * Get timestamp of the last_status according to LP
  *
  * @param srCertificate $cert
  * @return int|null
  */
 protected function getLastLPStatus(srCertificate $cert)
 {
     $ref_id = $cert->getDefinition()->getRefId();
     $obj_id = ilObject::_lookupObjectId($ref_id);
     $lp_data = ilTrQuery::getObjectsDataForUser($cert->getUserId(), $obj_id, $ref_id, '', '', 0, 9999, null, array('last_access'));
     $last_status = null;
     foreach ($lp_data['set'] as $data) {
         if ($data['type'] == 'crs') {
             $last_status = $data['last_access'];
             break;
         }
     }
     return (int) $last_status;
 }