//in order to store unit into logs
 //This is the basic content iterator, including even inactive, unpublished or empty units
 if (EfrontUser::isOptionVisible('tests')) {
     $visitableIterator = new EfrontVisitableAndEmptyFilterIterator(new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($currentContent->tree), RecursiveIteratorIterator::SELF_FIRST)));
 } else {
     $visitableIterator = new EfrontNoTestsFilterIterator(new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($currentContent->tree), RecursiveIteratorIterator::SELF_FIRST)));
 }
 $treeOptions = array('truncateNames' => 25, 'selectedNode' => $currentUnit['id']);
 //$_professor_ ? $treeOptions['edit'] = 1 : $treeOptions['edit'] = 0;
 $ruleCheck = true;
 if ($_student_ && $_change_ && $currentLesson->options['tracking']) {
     //$currentUser -> setSeenUnit($currentUnit, $currentLesson, 1);
     //$currentContent -> markSeenNodes($currentUser);
     //$userProgress = EfrontStats :: getUsersLessonStatus($currentLesson, $currentUser -> user['login']);
     //$userProgress = $userProgress[$currentLesson -> lesson['id']][$currentUser -> user['login']];
     $seenContent = EfrontStats::getStudentsSeenContent($currentLesson->lesson['id'], $currentUser->user['login']);
     $seenContent = $seenContent[$currentLesson->lesson['id']][$currentUser->user['login']];
     $userProgress = EfrontStats::lightGetUserStatusInLesson($_SESSION['s_login'], $currentLesson, $seenContent, $visitableIterator);
     $smarty->assign("T_SEEN_UNIT", in_array($currentUnit['id'], array_keys($seenContent)));
     //Notify smarty whether the student has seen the current unit
     if ($currentLesson->options['rules']) {
         $ruleCheck = $currentContent->checkRules($currentUnit['id'], $seenContent);
     }
     if ($ruleCheck !== true) {
         $message = $ruleCheck;
         $message_type = 'failure';
         $smarty->assign("T_RULE_CHECK_FAILED", true);
         $ruleCheck = false;
     }
     $smarty->assign("T_USER_PROGRESS", $userProgress);
 }
Exemplo n.º 2
0
 public function getUserLessonStatus($lesson, $user, $options)
 {
     $times = new EfrontTimes();
     $usersTimesInLessonContent = array();
     if ($lesson instanceof EfrontLesson) {
         $lessonId = $lesson->lesson['id'];
     } else {
         $lessonId = $lesson;
     }
     //$usersTimesInLessonContent[$user] = $times->getUserSessionTimeInLessonContent($user, $lessonId);
     $usersTimesInLessonContent[$user] = EfrontLesson::getUserActiveTimeInLesson($user, $lessonId);
     $usersDoneContent = EfrontStats::getStudentsSeenContent($lesson, $user, $options);
     //Calculate the done content for users in this lesson
     $usersAssignedProjects = array();
     if (!isset($options['noprojects']) || !$options['noprojects']) {
         $usersAssignedProjects = EfrontStats::getStudentsAssignedProjects($lesson, $user);
     }
     $usersDoneTests = array();
     if (!isset($options['notests']) || !$options['notests']) {
         $usersDoneTests = EfrontStats::getStudentsDoneTests($lesson, $user);
     }
     $roles = EfrontLessonUser::getLessonsRoles();
     //transpose projects array, from (login => array(project id => project)) to array(lesson id => array(login => array(project id => project)))
     $temp = array();
     foreach ($usersAssignedProjects as $login => $userProjects) {
         foreach ($userProjects as $projectId => $project) {
             $temp[$project['lessons_ID']][$login][$projectId] = $project;
         }
     }
     $usersAssignedProjects = $temp;
     //transpose tests array, from (login => array(test id => test)) to array(lesson id => array(login => array(test id => test)))
     $temp0 = eF_getTableData("content", "id,ctg_type");
     //filter feedbacks
     foreach ($temp0 as $value) {
         $checkctg[$value['id']] = $value['ctg_type'];
     }
     $temp = array();
     foreach ($usersDoneTests as $login => $userTests) {
         foreach ($userTests as $contentID => $test) {
             if ($checkctg[$contentID] != 'feedback') {
                 $temp[$test['lessons_ID']][$login][$contentID] = $test;
             }
         }
     }
     $usersDoneTests = $temp;
     if (!$user instanceof EfrontUser) {
         $user = EfrontUserFactory::factory($user);
         $user = $user->user;
     }
     if (!$lesson instanceof EfrontLesson) {
         $lesson = new EfrontLesson($lesson);
     }
     $result = eF_getTableData("users_to_lessons", "*", "users_LOGIN ='******'login'] . "' and lessons_ID = " . $lesson->lesson['id']);
     if (sizeof($result[0]['users_LOGIN']) > 0) {
         if ($lesson->lesson['duration'] && $result[0]['from_timestamp']) {
             $result[0]['remaining'] = $result[0]['from_timestamp'] + $lesson->lesson['duration'] * 3600 * 24 - time();
         } else {
             $result[0]['remaining'] = null;
         }
         //Check whether the lesson registration is expired. If so, set $result[0]['from_timestamp'] to false, so that the effect is to appear disabled
         if ($lesson->lesson['duration'] && $result[0]['from_timestamp'] && $lesson->lesson['duration'] * 3600 * 24 + $result[0]['from_timestamp'] < time()) {
             $lesson->removeUsers($result[0]['users_LOGIN']);
         } else {
             $usersLessons[$result[0]['lessons_ID']][$result[0]['users_LOGIN']] = $result[0];
             $usersLessonsTypes[$result[0]['lessons_ID']][$result[0]['users_LOGIN']] = $roles[$result[0]['user_type']];
             //Handy since we need to know whether a lesson has any students
         }
     }
     //Build a caching set for conditions, so that we avoid looping queries inside $lesson -> getConditions();
     $result = eF_getTableData("lesson_conditions", "*", "lessons_ID=" . $lesson->lesson['id']);
     $conditions = array();
     foreach ($result as $value) {
         $conditions[$value['lessons_ID']][] = $value;
     }
     $lessonStatus = array();
     if (in_array('student', $usersLessonsTypes[$lesson->lesson['id']])) {
         //Calculate these statistics only if the lesson has students
         !isset($conditions[$lesson->lesson['id']]) ? $conditions[$lesson->lesson['id']] = array() : null;
         $lessonConditions = $lesson->getConditions($conditions[$lesson->lesson['id']]);
         $lessonContent = new EfrontContentTree($lesson);
         $doneContent = isset($usersDoneContent[$lesson->lesson['id']]) ? $usersDoneContent[$lesson->lesson['id']] : array();
         $doneTests = isset($usersDoneTests[$lesson->lesson['id']]) ? $usersDoneTests[$lesson->lesson['id']] : array();
         $assignedProjects = isset($usersAssignedProjects[$lesson->lesson['id']]) ? $usersAssignedProjects[$lesson->lesson['id']] : array();
         $visitableContentIds = array();
         $visitableExampleIds = array();
         $visitableTestIds = array();
         $testIds = array();
         foreach ($iterator = new EfrontVisitableFilterIterator(new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($lessonContent->tree), RecursiveIteratorIterator::SELF_FIRST))) as $key => $value) {
             if ($value['active']) {
                 switch ($value->offsetGet('ctg_type')) {
                     case 'theory':
                     case 'scorm':
                     case 'feedback':
                         $visitableContentIds[$key] = $key;
                         //Get the not-test unit ids for this content
                         break;
                     case 'examples':
                         $visitableExampleIds[$key] = $key;
                         //Get the not-test unit ids for this content
                         break;
                     case 'tests':
                     case 'scorm_test':
                         $visitableTestIds[$key] = $key;
                         //Get the scorm test unit ids for this content
                         $testIds[$key] = $key;
                         //Get the test unit ids for this content
                         break;
                 }
             }
         }
         $visitableUnits = $visitableContentIds + $visitableExampleIds + $visitableTestIds;
     }
     foreach ($usersLessons[$lesson->lesson['id']] as $login => $value) {
         $lessonStatus = array('login' => $login, 'name' => $user['name'], 'surname' => $user['surname'], 'basic_user_type' => $user['user_type'], 'user_type' => $value['user_type'], 'user_types_ID' => $user['user_types_ID'], 'different_role' => $value['user_type'] != $user['user_type'] && $value['user_type'] != $user['user_types_ID'], 'different_role' => !$users[$login]['user_types_ID'] && $value['user_type'] != $users[$login]['user_type'] || $users[$login]['user_types_ID'] && $value['user_type'] != $users[$login]['user_types_ID'], 'active' => $user['active'], 'lesson_name' => $lesson->lesson['name'], 'from_timestamp' => $value['from_timestamp'], 'remaining' => $value['remaining']);
         //Student - specific information
         if ($roles[$value['user_type']] == 'student') {
             !isset($doneContent[$login]) ? $doneContent[$login] = array() : null;
             !isset($assignedProjects[$login]) ? $assignedProjects[$login] = array() : null;
             list($conditionsMet, $lessonPassed) = self::checkConditions($doneContent[$login], $lessonConditions, $visitableUnits, $visitableTestIds, $usersTimesInLessonContent[$login]);
             //Content progress is theory and examples units seen
             $contentProgress = 0;
             if (isset($doneContent[$login]) && sizeof($doneContent[$login]) > 0 && (sizeof($visitableContentIds) > 0 || sizeof($visitableExampleIds) > 0)) {
                 $contentProgress = round(100 * sizeof(array_diff_key($doneContent[$login], $visitableTestIds)) / (sizeof($visitableContentIds) + sizeof($visitableExampleIds)), 2);
             }
             //Calculate tests average score and progress
             $testsProgress = 0;
             $numCompletedTests = 0;
             $testsAvgScore = array();
             if (sizeof($testIds) > 0 && isset($doneTests[$login]) && sizeof($doneTests[$login]) > 0) {
                 foreach ($doneTests[$login] as $doneTest) {
                     $testsAvgScore[] = $doneTest['active_score'];
                 }
                 $testsAvgScore = array_sum($testsAvgScore) / sizeof($testsAvgScore);
                 $numCompletedTests = 0;
                 if (!isset($doneTest[$login['lesson_status']]) || $doneTest[$login['lesson_status']] == 'passed' || $doneTest[$login['lesson_status']] == 'completed') {
                     $numCompletedTests++;
                 }
                 $testsProgress = round(100 * $numCompletedTests / sizeof($visitableTestIds), 2);
             } else {
                 $testsAvgScore = 0;
             }
             //Calculate projects average score and build done projects list, since we don't have this automatically
             $doneProjects = array();
             $projectsAvgScore = array();
             $projectsProgress = 0;
             if (sizeof($assignedProjects[$login]) > 0) {
                 foreach ($assignedProjects[$login] as $id => $project) {
                     if ($project['grade'] !== '' || $project['upload_timestamp']) {
                         $doneProjects[$id] = $project;
                         $projectsAvgScore[] = $project['grade'];
                     }
                 }
                 sizeof($doneProjects) > 0 ? $projectsAvgScore = array_sum($projectsAvgScore) / sizeof($projectsAvgScore) : ($projectsAvgScore = 0);
                 $projectsProgress = round(100 * sizeof($doneProjects) / sizeof($assignedProjects[$login]), 2);
             } else {
                 $projectsAvgScore = 0;
             }
             //Calculate overall progress, the number of done content + done (passed for SCORM) tests divided with the total units number
             $overallProgress = 0;
             if (sizeof($visitableUnits) > 0) {
                 $overallProgress = round(100 * sizeof(array_intersect(array_keys($visitableUnits), array_keys($doneContent[$login]))) / sizeof($visitableUnits), 2);
             }
             $lessonStatus['assigned_projects'] = $assignedProjects[$login];
             //the total assigned projects to the user, with information for each one.
             $lessonStatus['projects_progress'] = $projectsProgress;
             //the projects percentage done
             $lessonStatus['projects_avg_score'] = $projectsAvgScore;
             //the projects average score
             $lessonStatus['tests_progress'] = $testsProgress;
             //the tests percentage done
             $lessonStatus['tests_avg_score'] = $testsAvgScore;
             //the tests average score
             $lessonStatus['content_progress'] = $contentProgress;
             //the content (theory_examples) percentage done
             $lessonStatus['overall_progress'] = $overallProgress;
             //the total percentage done, including content and tests
             $lessonStatus['lesson_passed'] = $lessonPassed;
             $lessonStatus['total_conditions'] = sizeof($lessonConditions);
             $lessonStatus['conditions_passed'] = array_sum($conditionsMet);
             $lessonStatus['completed'] = $value['completed'];
             $lessonStatus['score'] = $value['score'];
             $lessonStatus['comments'] = $value['comments'] ? $value['comments'] : 0;
         }
     }
     return $lessonStatus;
 }
Exemplo n.º 3
0
 /**
  * Mark seen nodes
  *
  * This function gets the units that the user has seen
  * and sets the 'seen' property either to 1 or to 0.
  * <br/>Example:
  * <code>
  * $currentContent = new EfrontContentTree(5);           //Initialize content for lesson with id 5
  * $currentContent -> markSeenNodes($currentUser);       //Mark the seen content for user in object $currentUser
  * </cod>
  *
  * @param mixed $user Either a user login or an EfrontUser object
  * @since 3.5.0
  * @access public
  */
 public function markSeenNodes($user)
 {
     $user instanceof EfrontUser ? $login = $user->user['login'] : ($login = $user);
     $seenContent = EfrontStats::getStudentsSeenContent($this->lessonId, $login);
     $seenNodes = array_keys($seenContent[$this->lessonId][$login]);
     $resultScorm = eF_getTabledataFlat("scorm_data", "content_ID, lesson_status", "users_LOGIN='******'");
     $resultScorm = array_combine($resultScorm['content_ID'], $resultScorm['lesson_status']);
     $result = eF_getTableData("content c, completed_tests ct, tests t", "t.content_ID, ct.status, ct.timestamp, ct.archive, t.keep_best", "ct.status != 'deleted' and c.id = t.content_ID and c.lessons_ID = " . $this->lessonId . " and ct.tests_ID = t.id and ct.users_LOGIN='******'");
     foreach ($result as $value) {
         if ($value['keep_best'] && $value['status'] == 'passed') {
             $resultTests[$value['content_ID']] = $value['status'];
         } else {
             if (!$value['archive'] && !isset($resultTests[$value['content_ID']])) {
                 $resultTests[$value['content_ID']] = $value['status'];
             }
         }
         if (!$value['archive']) {
             $resultTestsTimes[$value['content_ID']] = $value['timestamp'];
         }
     }
     $iterator = new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($this->tree), RecursiveIteratorIterator::SELF_FIRST));
     foreach ($iterator as $key => $value) {
         in_array($key, $seenNodes) || $resultScorm[$key] == 'completed' || $resultScorm[$key] == 'passed' ? $value['seen'] = 1 : ($value['seen'] = 0);
         if ($resultScorm[$key]) {
             $resultScorm[$key] == 'incomplete' ? $value['incomplete'] = 1 : ($value['incomplete'] = 0);
             $resultScorm[$key] == 'failed' ? $value['failed'] = 1 : ($value['failed'] = 0);
         } else {
             if ($resultTests[$key]) {
                 $resultTests[$key] == 'incomplete' ? $value['incomplete'] = $resultTestsTimes[$key] : ($value['incomplete'] = 0);
                 $resultTests[$key] == 'failed' ? $value['failed'] = 1 : ($value['failed'] = 0);
             }
         }
     }
     //Empty top level unit should be marked as complete if all sub units are marked as complete
     foreach ($iterator as $key => $value) {
         if (!$value['has_data'] && $value['ctg_type'] == 'theory') {
             $childIterator = new EfrontVisitableFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($value), RecursiveIteratorIterator::SELF_FIRST));
             $seenChildNodes = true;
             $has_child = false;
             foreach ($childIterator as $key2 => $value2) {
                 $has_child = true;
                 if (!$value2['seen'] && $value2['has_data']) {
                     $seenChildNodes = false;
                 }
             }
             $seenChildNodes && $has_child ? $value['seen'] = 1 : ($value['seen'] = 0);
         }
     }
 }
     $firstNodeIterator = new EfrontNoTestsFilterIterator(new EfrontVisitableFilterIterator(new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($currentContent->tree), RecursiveIteratorIterator::SELF_FIRST), array('active' => 1))));
 }
 /*	$hideFeedback = false;
 			foreach (new EfrontNoFeedbackFilterIterator(new EfrontVisitableFilterIterator(new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($currentContent -> tree), RecursiveIteratorIterator :: SELF_FIRST), array('active' => 1)))) as $key => $value) {
 				if (!$value['seen']) {
 					$hideFeedback = true;
 				}
 			} */
 if ($currentLesson->options['content_tree']) {
     $smarty->assign("T_CONTENT_TREE", $currentContent->toHTML($iterator, false, array('truncateNames' => 60, 'hideFeedback' => $hideFeedback)));
 }
 //Progress, status and start/continue block
 if (!$currentLesson->options['tracking'] || $currentUser->coreAccess['content'] == 'hidden') {
     $currentLesson->options['lesson_info'] ? $controlPanelOptions[] = array('text' => _LESSONINFORMATION, 'image' => '32x32/information.png', 'href' => basename($_SERVER['PHP_SELF']) . '?ctg=lesson_information', 'onClick' => "eF_js_showDivPopup(event, '" . _LESSONINFORMATION . "', 2)", 'target' => 'POPUP_FRAME') : null;
 } else {
     $seenContent = EfrontStats::getStudentsSeenContent($currentLesson, $currentUser);
     $seenContent = $seenContent[$currentLesson->lesson['id']][$currentUser->user['login']];
     $userProgress = EfrontStats::lightGetUserStatusInLesson($_SESSION['s_login'], $currentLesson, $seenContent, $iterator);
     $result = eF_getTableData("users_to_lessons", "current_unit", "users_LOGIN = '******'login'] . "' and lessons_ID = " . $currentLesson->lesson['id']);
     sizeof($result) > 0 ? $userProgress['current_unit'] = $result[0]['current_unit'] : ($userProgress['current_unit'] = false);
     if ($userProgress['lesson_passed'] && !$userProgress['completed']) {
         if (!$userProgress['completed'] && $currentLesson->options['auto_complete']) {
             $userProgress = EfrontStats::getUsersLessonStatus($currentLesson, $currentUser->user['login']);
             $userProgress = $userProgress[$currentLesson->lesson['id']][$currentUser->user['login']];
             $userProgress['tests_avg_score'] ? $avgScore = $userProgress['tests_avg_score'] : ($avgScore = 100);
             $timestamp = _AUTOCOMPLETEDAT . ': ' . date("Y/m/d, H:i:s");
             $currentUser->completeLesson($currentLesson, $avgScore, $timestamp);
             $userProgress['completed'] = 1;
             $userProgress['score'] = $avgScore;
             $userProgress['comments'] = $timestamp;
         } else {