/** * Init property form * * @return ilPropertyFormGUI $form */ protected function initFormSettings() { include_once './Services/Form/classes/class.ilPropertyFormGUI.php'; $form = new ilPropertyFormGUI(); $form->setTitle($this->lng->txt('tracking_settings')); $form->setFormAction($this->ctrl->getFormAction($this)); // Mode $mod = new ilRadioGroupInputGUI($this->lng->txt('trac_mode'), 'modus'); $mod->setRequired(true); $mod->setValue($this->obj_lp->getCurrentMode()); $form->addItem($mod); foreach ($this->obj_lp->getValidModes() as $mode_key) { $opt = new ilRadioOption($this->obj_lp->getModeText($mode_key), $mode_key, $this->obj_lp->getModeInfoText($mode_key)); $opt->setValue($mode_key); $mod->addOption($opt); // :TODO: Subitem for visits ?! if ($mode_key == ilLPObjSettings::LP_MODE_VISITS) { $vis = new ilNumberInputGUI($this->lng->txt('trac_visits'), 'visits'); $vis->setSize(3); $vis->setMaxLength(4); $vis->setInfo(sprintf($this->lng->txt('trac_visits_info'), ilObjUserTracking::_getValidTimeSpan())); $vis->setRequired(true); $vis->setValue($this->obj_settings->getVisits()); $opt->addSubItem($vis); } } $form->addCommandButton('saveSettings', $this->lng->txt('save')); return $form; }
/** * Init property form * * @return ilPropertyFormGUI $form */ protected function initFormSettings() { include_once './Services/Form/classes/class.ilPropertyFormGUI.php'; $form = new ilPropertyFormGUI(); $form->setTitle($this->lng->txt('tracking_settings')); $form->setFormAction($this->ctrl->getFormAction($this)); // Mode $mod = new ilRadioGroupInputGUI($this->lng->txt('trac_mode'), 'modus'); $mod->setRequired(true); $mod->setValue($this->obj_settings->getMode()); $form->addItem($mod); foreach ($this->obj_settings->getValidModes() as $mode_key => $mode_name) { $opt = new ilRadioOption($mode_name, $mode_key, ilLPObjSettings::_mode2InfoText($mode_key)); $opt->setValue($mode_key); $mod->addOption($opt); // Subitem for vistits if ($mode_key == LP_MODE_VISITS) { $vis = new ilNumberInputGUI($this->lng->txt('trac_visits'), 'visits'); $vis->setSize(3); $vis->setMaxLength(4); $vis->setInfo(sprintf($this->lng->txt('trac_visits_info'), ilObjUserTracking::_getValidTimeSpan())); $vis->setRequired(true); $vis->setValue($this->obj_settings->getVisits()); $opt->addSubItem($vis); } } /* // Info Active $act = new ilCustomInputGUI($this->lng->txt('trac_activated'), ''); $img = new ilTemplate('tpl.obj_settings_img_row.html',true,true,'Services/Tracking'); $img->setVariable("IMG_SRC", $activated = ilObjUserTracking::_enabledLearningProgress() ? ilUtil::getImagePath('icon_ok.png') : ilUtil::getImagePath('icon_not_ok.png') ); $act->setHTML($img->get()); $form->addItem($act); // Info Anonymized $ano = new ilCustomInputGUI($this->lng->txt('trac_anonymized'), ''); $img = new ilTemplate('tpl.obj_settings_img_row.html',true,true,'Services/Tracking'); $img->setVariable("IMG_SRC", $anonymized = !ilObjUserTracking::_enabledUserRelatedData() ? ilUtil::getImagePath('icon_ok.png') : ilUtil::getImagePath('icon_not_ok.png') ); $ano->setHTML($img->get()); $form->addItem($ano); */ $form->addCommandButton('saveSettings', $this->lng->txt('save')); return $form; }
protected function trackChapterAccess() { global $ilDB, $ilUser; // get last accessed page $set = $ilDB->query("SELECT * FROM lo_access WHERE " . "usr_id = " . $ilDB->quote($ilUser->getId(), "integer") . " AND " . "lm_id = " . $ilDB->quote($this->lm->getRefId(), "integer")); $res = $ilDB->fetchAssoc($set); if ($res["obj_id"]) { include_once 'Services/Tracking/classes/class.ilObjUserTracking.php'; $valid_timespan = ilObjUserTracking::_getValidTimeSpan(); $pg_ts = new ilDateTime($res["timestamp"], IL_CAL_DATETIME); $pg_ts = $pg_ts->get(IL_CAL_UNIX); $pg_id = $res["obj_id"]; if (!$this->lm_tree->isInTree($pg_id)) { return; } $now = time(); $time_diff = $read_diff = 0; // spent_seconds or read_count ? if ($now - $pg_ts <= $valid_timespan) { $time_diff = $now - $pg_ts; } else { $read_diff = 1; } // find parent chapter(s) for that page $parent_st_ids = array(); foreach ($this->lm_tree->getPathFull($pg_id) as $item) { if ($item["type"] == "st") { $parent_st_ids[] = $item["obj_id"]; } } if ($parent_st_ids && ($time_diff || $read_diff)) { // get existing chapter entries $ex_st = array(); $set = $ilDB->query("SELECT obj_id FROM lm_read_event" . " WHERE " . $ilDB->in("obj_id", $parent_st_ids, "", "integer") . " AND usr_id = " . $ilDB->quote($ilUser->getId(), "integer")); while ($row = $ilDB->fetchAssoc($set)) { $ex_st[] = $row["obj_id"]; } // add missing chapter entries $missing_st = array_diff($parent_st_ids, $ex_st); if (sizeof($missing_st)) { foreach ($missing_st as $st_id) { $fields = array("obj_id" => array("integer", $st_id), "usr_id" => array("integer", $ilUser->getId())); $ilDB->insert("lm_read_event", $fields); } } // update all parent chapters $ilDB->manipulate("UPDATE lm_read_event SET" . " read_count = read_count + " . $ilDB->quote($read_diff, "integer") . " , spent_seconds = spent_seconds + " . $ilDB->quote($time_diff, "integer") . " , last_access = " . $ilDB->quote($now, "integer") . " WHERE " . $ilDB->in("obj_id", $parent_st_ids, "", "integer") . " AND usr_id = " . $ilDB->quote($ilUser->getId(), "integer")); } } }
/** * get mode info text * * @access public * @static * * @param int $mode */ public static function _mode2InfoText($a_mode) { global $lng; switch ($a_mode) { case LP_MODE_DEACTIVATED: return $lng->txt('trac_mode_deactivated_info_new'); case LP_MODE_TLT: return sprintf($lng->txt('trac_mode_tlt_info'), ilObjUserTracking::_getValidTimeSpan()); case LP_MODE_VISITS: return $lng->txt('trac_mode_visits_info'); case LP_MODE_MANUAL: return $lng->txt('trac_mode_manual_info'); case LP_MODE_MANUAL_BY_TUTOR: return $lng->txt('trac_mode_manual_by_tutor_info'); case LP_MODE_OBJECTIVES: return $lng->txt('trac_mode_objectives_info'); case LP_MODE_COLLECTION: return $lng->txt('trac_mode_collection_info'); case LP_MODE_SCORM: return $lng->txt('trac_mode_scorm_info'); case LP_MODE_TEST_FINISHED: return $lng->txt('trac_mode_test_finished_info'); case LP_MODE_TEST_PASSED: return $lng->txt('trac_mode_test_passed_info'); case LP_MODE_EXERCISE_RETURNED: return $lng->txt('trac_mode_exercise_returned_info'); case LP_MODE_SCORM_PACKAGE: return $lng->txt('trac_mode_scorm_package_info'); case LP_MODE_EVENT: return $lng->txt('trac_mode_event_info'); } }
/** * Records a read event and catches up with write events. * * @param $obj_id int The object which was read. * @param $usr_id int The user who performed a read action. * @param $catchupWriteEvents boolean If true, this function catches up with * write events. */ function _recordReadEvent($a_type, $a_ref_id, $obj_id, $usr_id, $isCatchupWriteEvents = true, $a_ext_rc = false, $a_ext_time = false) { global $ilDB, $tree; /* read_event data is now used for several features, so we are always keeping track if (!ilChangeEvent::_isActive()) { return; } */ include_once 'Services/Tracking/classes/class.ilObjUserTracking.php'; $validTimeSpan = ilObjUserTracking::_getValidTimeSpan(); $query = sprintf('SELECT * FROM read_event ' . 'WHERE obj_id = %s ' . 'AND usr_id = %s ', $ilDB->quote($obj_id, 'integer'), $ilDB->quote($usr_id, 'integer')); $res = $ilDB->query($query); $row = $ilDB->fetchObject($res); // read counter if ($a_ext_rc !== false) { $read_count = 'read_count = ' . $ilDB->quote($a_ext_rc, "integer") . ", "; $read_count_init = max(1, (int) $a_ext_rc); $read_count_diff = max(1, (int) $a_ext_rc) - $row->read_count; } else { $read_count = 'read_count = read_count + 1, '; $read_count_init = 1; $read_count_diff = 1; } if ($row) { if ($a_ext_time !== false) { $time = (int) $a_ext_time; } else { $time = $ilDB->quote(time() - $row->last_access <= $validTimeSpan ? $row->spent_seconds + time() - $row->last_access : $row->spent_seconds, 'integer'); // if we are in the valid interval, we do not // add anything to the read_count, since this is the // same access for us if (time() - $row->last_access <= $validTimeSpan) { $read_count = ''; $read_count_init = 1; $read_count_diff = 0; } } $time_diff = $time - (int) $row->spent_seconds; // Update $query = sprintf('UPDATE read_event SET ' . $read_count . 'spent_seconds = %s, ' . 'last_access = %s ' . 'WHERE obj_id = %s ' . 'AND usr_id = %s ', $time, $ilDB->quote(time(), 'integer'), $ilDB->quote($obj_id, 'integer'), $ilDB->quote($usr_id, 'integer')); $aff = $ilDB->manipulate($query); self::_recordObjStats($obj_id, $time_diff, $read_count_diff); } else { if ($a_ext_time !== false) { $time = (int) $a_ext_time; } else { $time = 0; } $time_diff = $time - (int) $row->spent_seconds; /* $query = sprintf('INSERT INTO read_event (obj_id,usr_id,last_access,read_count,spent_seconds,first_access) '. 'VALUES (%s,%s,%s,%s,%s,'.$ilDB->now().') ', $ilDB->quote($obj_id,'integer'), $ilDB->quote($usr_id,'integer'), $ilDB->quote(time(),'integer'), $ilDB->quote($read_count_init,'integer'), $ilDB->quote($time,'integer')); $ilDB->manipulate($query); */ // #10407 $ilDB->replace('read_event', array('obj_id' => array('integer', $obj_id), 'usr_id' => array('integer', $usr_id)), array('read_count' => array('integer', $read_count_init), 'spent_seconds' => array('integer', $time), 'first_access' => array('timestamp', date("Y-m-d H:i:s")), 'last_access' => array('integer', time()))); self::$has_accessed[$obj_id][$usr_id] = true; self::_recordObjStats($obj_id, $time_diff, $read_count_diff); } if ($isCatchupWriteEvents) { ilChangeEvent::_catchupWriteEvents($obj_id, $usr_id); } // update parents (no categories or root) if (!in_array($a_type, array("cat", "root", "crs"))) { if ($tree->isInTree($a_ref_id)) { $path = $tree->getPathId($a_ref_id); foreach ($path as $p) { $obj2_id = ilObject::_lookupObjId($p); $obj2_type = ilObject::_lookupType($obj2_id); //echo "<br>1-$obj2_type-$p-$obj2_id-"; if ($p != $a_ref_id && in_array($obj2_type, array("crs", "fold", "grp"))) { $query = sprintf('SELECT * FROM read_event ' . 'WHERE obj_id = %s ' . 'AND usr_id = %s ', $ilDB->quote($obj2_id, 'integer'), $ilDB->quote($usr_id, 'integer')); $res2 = $ilDB->query($query); if ($row2 = $ilDB->fetchAssoc($res2)) { //echo "<br>2"; // update read count and spent seconds $query = sprintf('UPDATE read_event SET ' . 'childs_read_count = childs_read_count + %s ,' . 'childs_spent_seconds = childs_spent_seconds + %s ' . 'WHERE obj_id = %s ' . 'AND usr_id = %s ', $ilDB->quote((int) $read_count_diff, 'integer'), $ilDB->quote((int) $time_diff, 'integer'), $ilDB->quote($obj2_id, 'integer'), $ilDB->quote($usr_id, 'integer')); $aff = $ilDB->manipulate($query); self::_recordObjStats($obj2_id, null, null, (int) $time_diff, (int) $read_count_diff); } else { //echo "<br>3"; //$ilLog->write("insert read event for obj_id -".$obj2_id."-".$usr_id."-"); /* $query = sprintf('INSERT INTO read_event (obj_id,usr_id,last_access,read_count,spent_seconds,first_access,'. 'childs_read_count, childs_spent_seconds) '. 'VALUES (%s,%s,%s,%s,%s,'.$ilDB->now().', %s, %s) ', $ilDB->quote($obj2_id,'integer'), $ilDB->quote($usr_id,'integer'), $ilDB->quote(time(),'integer'), $ilDB->quote(1,'integer'), $ilDB->quote($time,'integer'), $ilDB->quote((int) $read_count_diff,'integer'), $ilDB->quote((int) $time_diff,'integer') ); $aff = $ilDB->manipulate($query); */ // #10407 $ilDB->replace('read_event', array('obj_id' => array('integer', $obj2_id), 'usr_id' => array('integer', $usr_id)), array('read_count' => array('integer', 1), 'spent_seconds' => array('integer', $time), 'first_access' => array('timestamp', date("Y-m-d H:i:s")), 'last_access' => array('integer', time()), 'childs_read_count' => array('integer', (int) $read_count_diff), 'childs_spent_seconds' => array('integer', (int) $time_diff))); self::$has_accessed[$obj2_id][$usr_id] = true; self::_recordObjStats($obj2_id, $time, 1, (int) $time_diff, (int) $read_count_diff); } } } } } // @todo: // - calculate diff of spent_seconds and read_count // - use ref id to get parents of types grp, crs, fold // - add diffs to childs_spent_seconds and childs_read_count }
public static function _mode2InfoText($a_mode) { global $lng; switch ($a_mode) { case self::LP_MODE_DEACTIVATED: return $lng->txt('trac_mode_deactivated_info_new'); case self::LP_MODE_TLT: include_once 'Services/Tracking/classes/class.ilObjUserTracking.php'; return sprintf($lng->txt('trac_mode_tlt_info'), ilObjUserTracking::_getValidTimeSpan()); case self::LP_MODE_VISITS: return $lng->txt('trac_mode_visits_info'); case self::LP_MODE_MANUAL: return $lng->txt('trac_mode_manual_info'); case self::LP_MODE_MANUAL_BY_TUTOR: return $lng->txt('trac_mode_manual_by_tutor_info'); case self::LP_MODE_OBJECTIVES: return $lng->txt('trac_mode_objectives_info'); case self::LP_MODE_COLLECTION: return $lng->txt('trac_mode_collection_info'); case self::LP_MODE_SCORM: return $lng->txt('trac_mode_scorm_info'); case self::LP_MODE_TEST_FINISHED: return $lng->txt('trac_mode_test_finished_info'); case self::LP_MODE_TEST_PASSED: return $lng->txt('trac_mode_test_passed_info'); case self::LP_MODE_EXERCISE_RETURNED: return $lng->txt('trac_mode_exercise_returned_info'); case self::LP_MODE_SCORM_PACKAGE: return $lng->txt('trac_mode_scorm_package_info'); case self::LP_MODE_EVENT: return $lng->txt('trac_mode_event_info'); case self::LP_MODE_COLLECTION_MANUAL: return $lng->txt('trac_mode_collection_manual_info'); case self::LP_MODE_COLLECTION_TLT: return $lng->txt('trac_mode_collection_tlt_info'); case self::LP_MODE_QUESTIONS: return $lng->txt('trac_mode_questions_info'); // START PATCH RUBRIC CPKN 2015 // START PATCH RUBRIC CPKN 2015 case self::LP_MODE_RUBRIC: return $lng->txt('trac_mode_rubric_info'); // END PATCH RUBRIC CPKN 2015 } }