/**
  * check condition
  * @param type $a_svy_id
  * @param type $a_operator
  * @param type $a_value
  * @param type $a_usr_id
  * @return boolean
  */
 public static function checkCondition($a_trigger_obj_id, $a_operator, $a_value, $a_usr_id)
 {
     switch ($a_operator) {
         case ilConditionHandler::OPERATOR_FAILED:
             include_once './Services/Tracking/classes/class.ilLPStatus.php';
             ilLPStatus::_lookupStatus($a_trigger_obj_id, $a_usr_id) == ilLPStatus::LP_STATUS_FAILED_NUM;
             break;
         case ilConditionHandler::OPERATOR_FINISHED:
         default:
             include_once './Services/Tracking/classes/class.ilLPStatus.php';
             return ilLPStatus::_hasUserCompleted($a_trigger_obj_id, $a_usr_id);
     }
     return true;
 }
 function _showWarning($a_ref_id, $a_usr_id)
 {
     global $objDefinition;
     include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
     include_once './Services/Tracking/classes/class.ilLPStatus.php';
     include_once './Services/Tracking/classes/class.ilLPObjSettings.php';
     global $ilObjDataCache;
     $obj_id = $ilObjDataCache->lookupObjId($a_ref_id);
     // if completed no warning
     if (ilLPStatus::_lookupStatus($obj_id, $a_usr_id) == LP_STATUS_COMPLETED_NUM) {
         return false;
     }
     // if editing time reached => show warning
     $timings =& ilTimingCache::_getTimings($a_ref_id);
     if ($timings['item']['timing_type'] == ilObjectActivation::TIMINGS_PRESETTING) {
         if ($timings['item']['changeable'] and $timings['user'][$a_usr_id]['end']) {
             $end = $timings['user'][$a_usr_id]['end'];
         } else {
             $end = $timings['item']['suggestion_end'];
         }
         if ($end < time()) {
             return true;
         }
     }
     // objective_ids would get confused with ref_ids !
     if (ilLPObjSettings::_lookupMode($obj_id) != LP_MODE_OBJECTIVES && $objDefinition->isContainer(ilObject::_lookupType($obj_id))) {
         // No check subitems
         foreach (ilLPCollectionCache::_getItems($obj_id) as $item) {
             if (ilTimingCache::_showWarning($item, $a_usr_id)) {
                 return true;
             }
         }
     }
     // Really ???
     return false;
 }
 /**
  * sync course status from lp 
  * 
  * as lp data is not deleted on course exit new members may already have lp completed
  * 
  * @param int $a_member_id
  */
 public function checkLPStatusSync($a_member_id)
 {
     // #11113
     include_once "Services/Tracking/classes/class.ilObjUserTracking.php";
     if (ilObjUserTracking::_enabledLearningProgress() && $this->getStatusDetermination() == ilObjCourse::STATUS_DETERMINATION_LP) {
         include_once "Services/Tracking/classes/class.ilLPStatus.php";
         // #13811 - we need to suppress creation if status entry
         $has_completed = ilLPStatus::_lookupStatus($this->getId(), $a_member_id, false) == ilLPStatus::LP_STATUS_COMPLETED_NUM;
         $this->getMembersObject()->updatePassed($a_member_id, $has_completed, false, true);
     }
 }
 function getStatus($a_packageId, $a_user_id, $auto_last_visited, $scormType = "1.2")
 {
     global $ilDB;
     include_once './Services/Tracking/classes/class.ilLPStatus.php';
     $oldStatus = ilLPStatus::_lookupStatus($a_packageId, $a_user_id);
     $status['saved_global_status'] = (int) $oldStatus;
     include_once './Services/Object/classes/class.ilObjectLP.php';
     $olp = ilObjectLP::getInstance($a_packageId);
     $status['lp_mode'] = $olp->getCurrentMode();
     $collection = $olp->getCollectionInstance();
     if ($collection) {
         $status['scos'] = $collection->getItems();
     } else {
         $status['scos'] = array();
     }
     $status['hash'] = ilObjSCORMInitData::setHash($a_packageId, $a_user_id);
     $status['p'] = $a_user_id;
     $status['last_visited'] = null;
     $status['total_time_sec'] = 0;
     $val_set = $ilDB->queryF('SELECT last_visited, sco_total_time_sec, total_time_sec FROM sahs_user WHERE obj_id = %s AND user_id = %s', array('integer', 'integer'), array($a_packageId, $a_user_id));
     $val_rec = $ilDB->fetchAssoc($val_set);
     if ($auto_last_visited) {
         $status['last_visited'] = $val_rec["last_visited"];
     }
     if ($val_rec["total_time_sec"] == null) {
         if ($val_rec["sco_total_time_sec"] == null) {
             //fall back for old ILIAS-Versions
             if ($scormType == "2004") {
                 include_once './Modules/Scorm2004/classes/class.ilSCORM2004Tracking.php';
                 $status['total_time_sec'] = (int) ilSCORM2004Tracking::getSumTotalTimeSecondsFromScos($a_packageId, $a_user_id, true);
             }
         } else {
             $status['total_time_sec'] = (int) $val_rec["sco_total_time_sec"];
         }
     } else {
         $status['total_time_sec'] = (int) $val_rec["total_time_sec"];
     }
     return $status;
 }
 /**
  * Prepare For a Regrade of a Rubric
  * @param $obj_id
  * @param $usr_id
  * @return bool
  */
 public static function _prepareForRegrade($obj_id, $usr_id)
 {
     global $ilDB, $ilUser;
     $delete_date = date("Y-m-d H:i:s");
     //try and set deleted on any criteria in rubric_data table where deleted is not null.
     $affected_rows = $ilDB->manipulate("UPDATE rubric_data d INNER JOIN rubric r on d.rubric_id = r.rubric_id SET d.deleted =\r\n                                            " . $ilDB->quote($delete_date, "timestamp") . " WHERE d.deleted IS NULL AND d.usr_id = " . $ilDB->quote($usr_id, "integer") . " AND r.obj_id = " . $ilDB->quote($obj_id, "integer"));
     if ($affected_rows > 0) {
         //there was a mark prior, we should proceed with preparing things for a regrade.
         include_once 'Services/Tracking/classes/class.ilLPMarks.php';
         include_once "./Modules/Exercise/classes/class.ilExAssignment.php";
         include_once "./Services/Tracking/classes/class.ilLPStatus.php";
         //grab everything from ut_lp_marks for the users obj_id and usr_id, that way we can save it for our own use.
         $marks = new ilLPMarks($obj_id, $usr_id);
         $status = ilLPStatus::_lookupStatus($obj_id, $usr_id);
         $completed = $marks->getCompleted();
         $mark = $marks->getMark();
         $comments = $marks->getComment();
         //Save the UT LP marks for this object. We're using Delete Date for the Create Date so we can inner join to the delete up above so we have a
         //record of all marks.
         $id = $ilDB->nextID('rubric_grade_hist');
         $ilDB->manipulateF("INSERT INTO rubric_grade_hist(rubric_history_id,rubric_id,obj_id,usr_id,status,mark,completed,comments,owner,create_date,last_update) VALUES " . " (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", array("integer", "integer", "integer", "integer", "integer", "float", "integer", "text", "integer", "date", "date"), array($id, self::_lookupRubricId($obj_id), $obj_id, $usr_id, $status, $mark, $completed, $comments, $ilUser->getId(), $delete_date, $delete_date));
         //now that a record is saved delete it from marks, status and exercise.
         $marks->_deleteForUsers($obj_id, array($usr_id));
         ilLPStatus::writeStatus($obj_id, $usr_id, ilLPStatus::LP_STATUS_IN_PROGRESS_NUM);
         //Remove from Ex Assignment
         $ass_id = array_shift(ilExAssignment::getAssignmentDataOfExercise($obj_id));
         $assignment = new ilExAssignment($ass_id['id']);
         $assignment->updateMarkOfUser($ass_id['id'], $usr_id, '');
         $assignment->updateStatusOfUser($ass_id['id'], $usr_id, 'notgraded');
         return true;
     } else {
         //there were no marks to begin with OR this was already marked for regrade, so go no further.
         return false;
     }
 }
 protected function initEditUserForm($a_user_id, $a_obj_id, $a_cancel = null)
 {
     global $lng, $ilCtrl;
     include_once 'Services/Object/classes/class.ilObjectLP.php';
     $olp = ilObjectLP::getInstance($a_obj_id);
     $lp_mode = $olp->getCurrentMode();
     include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
     $form = new ilPropertyFormGUI();
     $form->setFormAction($ilCtrl->getFormAction($this, "updateUser"));
     $form->setTitle($lng->txt("edit") . ": " . ilObject::_lookupTitle($a_obj_id));
     $form->setDescription($lng->txt('trac_mode') . ": " . $olp->getModeText($lp_mode));
     include_once "Services/User/classes/class.ilUserUtil.php";
     $user = new ilNonEditableValueGUI($lng->txt("user"), null, true);
     $user->setValue(ilUserUtil::getNamePresentation($a_user_id, true));
     $form->addItem($user);
     include_once 'Services/Tracking/classes/class.ilLPMarks.php';
     $marks = new ilLPMarks($a_obj_id, $a_user_id);
     $type = ilObject::_lookupType($a_obj_id);
     if ($type != 'lm') {
         $mark = new ilTextInputGUI($lng->txt("trac_mark"), "mark");
         $mark->setValue($marks->getMark());
         $mark->setMaxLength(32);
         $form->addItem($mark);
     }
     $comm = new ilTextInputGUI($lng->txt("trac_comment"), "comment");
     $comm->setValue($marks->getComment());
     $form->addItem($comm);
     if ($lp_mode == ilLPObjSettings::LP_MODE_MANUAL || $lp_mode == ilLPObjSettings::LP_MODE_MANUAL_BY_TUTOR) {
         include_once "./Services/Tracking/classes/class.ilLPStatus.php";
         $completed = ilLPStatus::_lookupStatus($a_obj_id, $a_user_id);
         $status = new ilCheckboxInputGUI($lng->txt('trac_completed'), "completed");
         $status->setChecked($completed == ilLPStatus::LP_STATUS_COMPLETED_NUM);
         $form->addItem($status);
     }
     $form->addCommandButton("updateUser", $lng->txt('save'));
     if ($a_cancel) {
         $form->addCommandButton($a_cancel, $lng->txt('cancel'));
     }
     return $form;
 }
 public function getSCORMCompletionStatus($sid, $a_usr_id, $a_ref_id)
 {
     $this->initAuth($sid);
     $this->initIlias();
     if (!$this->__checkSession($sid)) {
         return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
     }
     if (!strlen($a_ref_id)) {
         return $this->__raiseError('No ref_id given. Aborting!', 'Client');
     }
     include_once 'include/inc.header.php';
     // get obj_id
     if (!($obj_id = ilObject::_lookupObjectId($a_ref_id))) {
         return $this->__raiseError('No scorm module found for id: ' . $a_ref_id, 'Client');
     }
     include_once 'Services/Tracking/classes/class.ilLPStatus.php';
     include_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
     if (!ilObjUserTracking::_enabledLearningProgress()) {
         return $this->__raiseError('Learning progress not enabled in this installation. Aborting!', 'Server');
     }
     $status = ilLPStatus::_lookupStatus($obj_id, $a_usr_id);
     if ($status == ilLPStatus::LP_STATUS_COMPLETED_NUM) {
         return 'completed';
     } else {
         if ($status == ilLPStatus::LP_STATUS_FAILED_NUM) {
             return 'failed';
         } else {
             if ($status == ilLPStatus::LP_STATUS_IN_PROGRESS_NUM) {
                 return 'in_progress';
             } else {
                 return 'not_attempted';
             }
         }
     }
 }
 /**
  * sync course status from lp 
  * 
  * as lp data is not deleted on course exit new members may already have lp completed
  * 
  * @param int $a_member_id
  */
 public function checkLPStatusSync($a_member_id)
 {
     // #11113
     include_once "Services/Tracking/classes/class.ilObjUserTracking.php";
     if (ilObjUserTracking::_enabledLearningProgress() && $this->getStatusDetermination() == ilObjCourse::STATUS_DETERMINATION_LP) {
         include_once "Services/Tracking/classes/class.ilLPStatus.php";
         $lp_status = ilLPStatus::_lookupStatus($this->getId(), $a_member_id);
         if ($lp_status == LP_STATUS_COMPLETED_NUM) {
             $this->getMembersObject()->updatePassed($a_member_id, true, -1);
         }
     }
 }
 /**
  *    Fill a table row.
  *
  *    This method is called internally by ilias to
  *    fill a table row according to the row template.
  *
  * @param array $row
  * @internal param \ilObjTestOverview $overview
  */
 protected function fillRow($row)
 {
     $overview = $this->getParentObject()->object;
     $results = array();
     foreach ($overview->getUniqueTests() as $obj_id => $refs) {
         $test = $overview->getTest($obj_id);
         $activeId = $test->getActiveIdOfUser($row['member_id']);
         $result = $progress = null;
         if ($this->accessIndex[$obj_id]) {
             $result = $test->getTestResult($activeId);
             $lpStatus = new ilLPStatus($test->getId());
             $progress = $lpStatus->_lookupStatus($test->getId(), $row['member_id']);
             if ((bool) $progress) {
                 $result = sprintf("%.2f %%", (double) $result['pass']['percent'] * 100);
                 $results[] = $result;
             } else {
                 $result = $this->lng->txt("rep_robj_xtov_overview_test_not_passed");
                 $results[] = 0;
             }
             if ($activeId > 0) {
                 $resultLink = $this->buildMemberResultLinkTarget($this->accessIndex[$obj_id], $activeId);
                 $this->populateLinkedCell($resultLink, $result, $this->getCSSByProgress($progress));
             } else {
                 $this->populateNoLinkCell($result, $this->getCSSByProgress($progress));
             }
         } else {
             $this->populateNoLinkCell($this->lng->txt("rep_robj_xtov_overview_test_no_permission"), $this->getCSSByProgress($progress));
         }
     }
     if (count($results)) {
         $average = sprintf("%.2f", array_sum($results) / count($results));
     } else {
         $average = "";
     }
     $this->tpl->setVariable("AVERAGE_CLASS", "");
     $this->tpl->setVariable("AVERAGE_VALUE", $average . (is_numeric($average) ? "%" : ""));
     $this->tpl->setVariable('TEST_PARTICIPANT', $row['member_fullname']);
 }
 function __showEditUser($a_user_id, $a_ref_id, $a_cancel, $a_sub_id = false)
 {
     global $ilObjDataCache, $lng, $ilCtrl;
     include_once 'Services/Tracking/classes/class.ilLPMarks.php';
     if (!$a_sub_id) {
         $obj_id = $ilObjDataCache->lookupObjId($a_ref_id);
     } else {
         $ilCtrl->setParameter($this, 'userdetails_id', $a_sub_id);
         $obj_id = $ilObjDataCache->lookupObjId($a_sub_id);
     }
     $marks = new ilLPMarks($obj_id, $a_user_id);
     $tpl = new ilTemplate('tpl.lp_edit_user.html', true, true, 'Services/Tracking');
     $tpl->setVariable("OBJ_TITLE", $lng->txt("edit") . ": " . $ilObjDataCache->lookupTitle($obj_id));
     $tpl->setVariable("OBJ_SUBTITLE", $this->lng->txt('trac_mode') . ": " . ilLPObjSettings::_mode2Text(ilLPObjSettings::_lookupMode($obj_id)));
     $ilCtrl->setParameter($this, 'user_id', $a_user_id);
     $ilCtrl->setParameter($this, 'details_id', $a_ref_id);
     $tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
     $tpl->setVariable("TYPE_IMG", ilObjUser::_getPersonalPicturePath($a_user_id, 'xxsmall'));
     $tpl->setVariable("ALT_IMG", $ilObjDataCache->lookupTitle($a_user_id));
     $tpl->setVariable("TXT_LP", $lng->txt('trac_learning_progress_tbl_header'));
     $tpl->setVariable("COMMENT", ilUtil::prepareFormOutput($marks->getComment(), false));
     $type = $ilObjDataCache->lookupType($obj_id);
     if ($type != 'lm') {
         $tpl->setVariable("TXT_MARK", $lng->txt('trac_mark'));
         $tpl->setVariable("MARK", ilUtil::prepareFormOutput($marks->getMark(), false));
     }
     $tpl->setVariable("TXT_COMMENT", $lng->txt('trac_comment'));
     $mode = ilLPObjSettings::_lookupMode($obj_id);
     if ($mode == LP_MODE_MANUAL or $mode == LP_MODE_MANUAL_BY_TUTOR) {
         include_once "./Services/Tracking/classes/class.ilLPStatus.php";
         $completed = ilLPStatus::_lookupStatus($obj_id, $a_user_id);
         $tpl->setVariable("mode_manual");
         $tpl->setVariable("TXT_COMPLETED", $lng->txt('trac_completed'));
         $tpl->setVariable("CHECK_COMPLETED", ilUtil::formCheckbox($completed == LP_STATUS_COMPLETED_NUM, 'completed', '1'));
     }
     $tpl->setVariable("TXT_CANCEL", $lng->txt('cancel'));
     $tpl->setVariable("TXT_SAVE", $lng->txt('save'));
     $tpl->setVariable("CMD_CANCEL", $a_cancel);
     return $tpl->get();
 }
 function getStatus($a_packageId, $a_user_id)
 {
     include_once './Services/Tracking/classes/class.ilLPStatus.php';
     $oldStatus = ilLPStatus::_lookupStatus($a_packageId, $a_user_id);
     $status['saved_global_status'] = (int) $oldStatus;
     include_once './Services/Object/classes/class.ilObjectLP.php';
     $olp = ilObjectLP::getInstance($a_packageId);
     $status['lp_mode'] = $olp->getCurrentMode();
     $collection = $olp->getCollectionInstance();
     if ($collection) {
         $status['scos'] = $collection->getItems();
     } else {
         $status['scos'] = array();
     }
     $status['hash'] = ilObjSCORMInitData::setHash($a_packageId, $a_user_id);
     $status['p'] = $a_user_id;
     return $status;
 }
 /**
  * Checks whether a certificate exists for the active user or not
  * @param int obj_id Object ID of the SCORM Learning Module
  * @param int usr_id Object ID of the user. If not given, the active user will be taken
  * @return true/false
  */
 public static function _lookupUserCertificate($obj_id, $usr_id = 0)
 {
     global $ilUser;
     $uid = $usr_id ? $usr_id : $ilUser->getId();
     $completed = false;
     // check for certificates
     include_once "./Services/Certificate/classes/class.ilCertificate.php";
     if (ilCertificate::isActive() && ilCertificate::isObjectActive($obj_id)) {
         $lpdata = false;
         include_once "./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php";
         $type = ilObjSAHSLearningModule::_lookupSubType($obj_id);
         include_once "Services/Tracking/classes/class.ilObjUserTracking.php";
         if (ilObjUserTracking::_enabledLearningProgress()) {
             include_once "./Services/Tracking/classes/class.ilLPStatus.php";
             $completed = ilLPStatus::_lookupStatus($obj_id, $uid);
             $completed = $completed == LP_STATUS_COMPLETED_NUM;
             $lpdata = true;
         }
         switch ($type) {
             case "scorm":
                 if (!$lpdata) {
                     include_once "./Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php";
                     $completed = ilObjSCORMLearningModule::_getCourseCompletionForUser($obj_id, $uid);
                 }
                 break;
             case "scorm2004":
                 if (!$lpdata) {
                     include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php";
                     $completed = ilObjSCORM2004LearningModule::_getCourseCompletionForUser($obj_id, $uid);
                 }
                 break;
             default:
                 break;
         }
     }
     return $completed;
 }
 function isFullfilled($user_id, $item_id)
 {
     global $ilObjDataCache;
     include_once './Modules/Course/classes/class.ilCourseLMHistory.php';
     $lm_continue =& new ilCourseLMHistory($this->getRefId(), $user_id);
     $continue_data = $lm_continue->getLMHistory();
     $obj_id = $ilObjDataCache->lookupObjId($item_id);
     $type = $ilObjDataCache->lookupType($obj_id);
     switch ($type) {
         case 'tst':
             include_once './Modules/Test/classes/class.ilObjTestAccess.php';
             if (!ilObjTestAccess::_checkCondition($obj_id, 'finished', '')) {
                 return false;
             }
             break;
         case 'svy':
             include_once './Modules/Survey/classes/class.ilObjSurveyAccess.php';
             if (!ilObjSurveyAccess::_lookupFinished($obj_id, $user_id)) {
                 return false;
             }
             break;
         case 'sahs':
             include_once 'Services/Tracking/classes/class.ilLPStatus.php';
             $completed = ilLPStatus::_lookupStatus($obj_id, $user_id);
             if ($completed == LP_STATUS_COMPLETED_NUM) {
                 return false;
             }
             break;
         default:
             if (!isset($continue_data[$item_id])) {
                 return false;
             }
     }
     return true;
 }
 /**
  * checks wether a single condition is fulfilled
  * every trigger object type must implement a static method
  * _checkCondition($a_operator, $a_value)
  */
 function _checkCondition($a_id, $a_usr_id = 0)
 {
     global $ilUser;
     $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
     $condition = ilConditionHandler::_getCondition($a_id);
     switch ($condition['trigger_type']) {
         case "tst":
             include_once './Modules/Test/classes/class.ilObjTestAccess.php';
             return ilObjTestAccess::_checkCondition($condition['trigger_obj_id'], $condition['operator'], $condition['value'], $a_usr_id);
         case "crs":
             include_once './Modules/Course/classes/class.ilObjCourse.php';
             return ilObjCourse::_checkCondition($condition['trigger_obj_id'], $condition['operator'], $condition['value'], $a_usr_id);
         case 'exc':
             include_once './Modules/Exercise/classes/class.ilObjExercise.php';
             return ilObjExercise::_checkCondition($condition['trigger_obj_id'], $condition['operator'], $condition['value'], $a_usr_id);
         case 'crsg':
             include_once './Modules/Course/classes/class.ilObjCourseGrouping.php';
             return ilObjCourseGrouping::_checkCondition($condition['trigger_obj_id'], $condition['operator'], $condition['value'], $a_usr_id);
         case 'sahs':
             include_once './Services/Tracking/classes/class.ilLPStatus.php';
             return ilLPStatus::_lookupStatus($condition['trigger_obj_id'], $a_usr_id) == LP_STATUS_COMPLETED_NUM;
         case 'svy':
             include_once './Modules/Survey/classes/class.ilObjSurvey.php';
             return ilObjSurvey::_checkCondition($condition['trigger_obj_id'], $condition['operator'], $condition['value'], $a_usr_id);
         default:
             return false;
     }
 }