/**
  * Get lesson users
  *
  * This function returns an array with the lesson users.
  * <br/>Example:
  * <code>
  * $lesson = new EfrontLesson(32);                      //32 is a lesson id
  * $lessonUsers    = $lesson -> getUsers();             //Get the lesson users
  * $nonLessonUsers = $lesson -> getNonUsers();          //Get the users that don't have the lesson, but are eligible to
  * </code>
  * The returned array keys match the users logins
  *
  * @param string $basicType The user's basic type in the lesson
  * @param boolean $refresh Whether to explicitly refresh the object cached data set
  * @return array A 2-dimensional array with lesson users per type, or a 1-dimensional array with lesson users of the specified type
  * @since 3.5.0
  * @access public
  */
 public function getUsers($basicType = false, $refresh = false)
 {
     if ($this->users === false || $refresh || $basicType) {
         //Make a database query only if the variable is not initialized, or it is explicitly asked
         $users = array();
         if ($basicType && eF_checkParameter($basicType, 'alnum_general')) {
             $users = array();
             if ($basicType == 'professor') {
                 $roles = EfrontLessonUser::getProfessorRoles();
                 $roles = array_keys($roles);
             } else {
                 if ($basicType == 'student') {
                     $roles = EfrontLessonUser::getStudentRoles();
                     $roles = array_keys($roles);
                 } else {
                     $roles = $basicType;
                 }
             }
             $result = eF_getTableData("users u, users_to_lessons ul", "u.*, ul.user_type as role, ul.from_timestamp, ul.completed, ul.to_timestamp as timestamp_completed", "u.user_type != 'administrator' and ul.archive = 0 and u.archive = 0 and ul.users_LOGIN = login and lessons_ID=" . $this->lesson['id'] . " and ul.user_type in ('" . implode("','", $roles) . "')");
         } else {
             $result = eF_getTableData("users u, users_to_lessons ul", "u.*, ul.user_type as role, ul.from_timestamp, ul.completed, ul.to_timestamp as timestamp_completed", "u.user_type != 'administrator' and ul.archive = 0 and u.archive = 0 and ul.users_LOGIN = login and lessons_ID=" . $this->lesson['id']);
         }
         foreach ($result as $value) {
             $users[$value['login']] = array('login' => $value['login'], 'email' => $value['email'], 'name' => $value['name'], 'surname' => $value['surname'], 'basic_user_type' => $value['user_type'], 'user_type' => $value['user_type'], 'user_types_ID' => $value['user_types_ID'], 'role' => $value['role'], 'from_timestamp' => $value['from_timestamp'], 'active' => $value['active'], 'avatar' => $value['avatar'], 'completed' => $value['completed'], 'timestamp_completed' => $value['timestamp_completed'], 'partof' => 1);
         }
         if (!$basicType) {
             $this->users = $users;
         }
     }
     if ($basicType) {
         return $users;
     } else {
         return $this->users;
     }
 }
 /**
  * Get lesson users
  *
  * This function returns a list with the students of all the lessons in which the current user has a professor role
  * <br/>Example:
  * <code>
  *	  $user = EfrontUserFactory :: factory('professor');
  *	  $students = $user -> getProfessorStudents();
  * </code>
  *
  * @return array A list of user logins
  * @since 3.5.0
  * @access public
  */
 public function getProfessorStudents()
 {
     $users = array();
     $result = eF_getTableDataFlat("users_to_lessons", "lessons_ID", "archive=0 and users_LOGIN='******'login'] . "' and user_type in ('" . implode("','", array_keys(EfrontLessonUser::getProfessorRoles())) . "')");
     if (!empty($result['lessons_ID'])) {
         $result = eF_getTableDataFlat("users_to_lessons as ul, users as u", "distinct ul.users_LOGIN", "ul.users_LOGIN=u.login and u.active=1 and ul.archive=0 and ul.user_type in ('" . implode("','", array_keys(EfrontLessonUser::getStudentRoles())) . "') and ul.lessons_ID in (" . implode(",", $result['lessons_ID']) . ")");
         $users = array_unique($result['users_LOGIN']);
     }
     return $users;
 }
 $smarty->assign("T_STATS_ENTITY_ID", $_GET['sel_course']);
 try {
     $result = eF_getTableData("user_times ut join users_to_courses uc on ut.users_LOGIN=uc.users_LOGIN and ut.courses_ID=uc.courses_ID", "sum(time) as sum, count(distinct uc.users_LOGIN) as count", "completed=1 and uc.archive=0 and ut.courses_ID=" . $infoCourse->course['id'], "", "");
     if ($result[0]['sum']) {
         $smarty->assign("T_AVERAGE_COMPLETION_TIME", EfrontTimes::formatTimeForReporting($result[0]['sum'] / $result[0]['count']));
     }
     $roles = EfrontLessonUser::getLessonsRoles(true);
     $smarty->assign("T_ROLES_ARRAY", $roles);
     $rolesBasic = EfrontLessonUser::getLessonsRoles();
     $smarty->assign("T_BASIC_ROLES_ARRAY", $rolesBasic);
     $constraints = array('archive' => false, 'table_filters' => $stats_filters, 'condition' => 'r.course_user_type IN ("' . implode('","', array_keys(EfrontLessonUser::getStudentRoles())) . '")');
     $numUsers = $infoCourse->countCourseUsersAggregatingResults($constraints);
     if ($numUsers) {
         $usersPerRole['student'] = $numUsers;
     }
     $constraints = array('archive' => false, 'table_filters' => $stats_filters, 'condition' => 'r.course_user_type IN ("' . implode('","', array_keys(EfrontLessonUser::getProfessorRoles())) . '")');
     $numUsers = $infoCourse->countCourseUsersAggregatingResults($constraints);
     if ($numUsers) {
         $usersPerRole['professor'] = $numUsers;
     }
     $infoCourse->course['users_per_role'] = $usersPerRole;
     $infoCourse->course['num_users'] = array_sum($usersPerRole);
     $courseInstances = $infoCourse->getInstances();
     $smarty->assign("T_COURSE_INSTANCES", $courseInstances);
     $smarty->assign("T_COURSE_HAS_INSTANCES", sizeof($courseInstances) > 1);
     $smarty->assign("T_DATASOURCE_SORT_BY", 0);
     if (isset($_GET['ajax']) && $_GET['ajax'] == 'courseUsersTable') {
         $smarty->assign("T_DATASOURCE_COLUMNS", array('login', 'user_type', 'lesson_percentage', 'completed', 'score', 'operations', 'to_timestamp', 'enrolled_on'));
         $smarty->assign("T_DATASOURCE_OPERATIONS", array('statistics'));
         $constraints = createConstraintsFromSortedTable() + array('return_objects' => false, 'table_filters' => $stats_filters);
         $users = $infoCourse->getCourseUsersAggregatingResults($constraints);