예제 #1
0
 /** Check if user is active in this lesson
  *
  * This function will return true if the user can normally access this lesson, or
  * false if he/she needs registration confirmation by the admin or supervisor
  *
  * @param mixed $login Either the user login, or an EfrontLessonUser object
  * @since 3.6.7
  * @access public
  */
 public function isUserActiveInLesson($login)
 {
     $login = EfrontUser::convertArgumentToUserLogin($login);
     $result = eF_getTableData("users_to_lessons", "from_timestamp", "archive = 0 and users_LOGIN='******' and lessons_ID=" . $this->lesson['id']);
     if (empty($result)) {
         throw new EfrontUserException(_THEUSERDOESNOTHAVETHISLESSON . ': ' . $this->lesson['id'], EfrontUserException::USER_NOT_HAVE_LESSON);
     } else {
         if ($result[0]['from_timestamp'] > 0) {
             return true;
         } else {
             return false;
         }
     }
 }
예제 #2
0
 /**
  * Check succession rules for user
  *
  * This function checks the user's eligibility for the course lessons,
  * based on the course rules and the user's completed lessons, as well as
  * the dates that each lesson is available on.
  * <br/>Eaample:
  * <code>
  * $course = new EfrontCourse(23);
  * $eligibility = $course -> checkRules('jdoe');
  * </code>
  * In the above example, let's suppose that the course 23 has 3 lessons, with ids 1,2 and 3. Let's suppose that in order to access
  * lesson 2, the user must have completed lesson 1, and for accessing lesson 3, the user must have completed both lessons 1 and 2.
  * Then, if the user has completed lesson 1, the above example will return:
  * <code>array(2 => 1, 3 => 0);</code>
  * where if he has completed both 2 and 3 it will return:
  * <code>array(2 => 1, 3 => 1);</code>
  *
  * @param mixed $user A user login or an EfrontUser object
  * @return array The eligibility array, holding lessons ids as keys and true/false (or 0/1) as values
  * @since 3.5.0
  * @access public
  */
 public function checkRules($user, $courseLessons = false)
 {
     if ($courseLessons == false) {
         if (!$user instanceof EfrontUser) {
             $user = EfrontUserFactory::factory($user);
         }
         $courseLessons = $user->getUserStatusInCourseLessons($this);
     }
     $user = EfrontUser::convertArgumentToUserLogin($user);
     $roles = EfrontLessonUser::getLessonsRoles();
     $courseLessons = EfrontCourse::convertLessonObjectsToArrays($courseLessons);
     if (!empty($courseLessons)) {
         $allowed = array_combine(array_keys($courseLessons), array_fill(0, sizeof($courseLessons), 1));
         //By default, all lessons are accessible
     } else {
         $allowed = array();
     }
     if ($this->course['depends_on']) {
         try {
             $dependsOn = new EfrontCourse($this->course['depends_on']);
             if ($dependsOn->course['active'] && !$dependsOn->course['archive']) {
                 $result = eF_getTableData("users_to_courses", "completed, user_type", "users_LOGIN='******' and courses_ID=" . $dependsOn->course['id']);
                 if (!$result[0]['completed'] && $roles[$result[0]['user_type']] == 'student') {
                     foreach ($allowed as $key => $value) {
                         $allowed[$key] = 0;
                     }
                     return $allowed;
                 }
             }
         } catch (Exception $e) {
         }
     }
     $completedLessons = array();
     foreach ($courseLessons as $key => $value) {
         !isset($value['start_date']) or $dates[$key]['from_timestamp'] = $value['start_date'];
         !isset($value['end_date']) or $dates[$key]['to_timestamp'] = $value['end_date'];
         if (isset($value['start_period']) && isset($value['end_period'])) {
             //$dates[$key]['from_timestamp'] 	= $this -> course['start_date'] + 24 * 60 * 60 * $value['start_period'];
             //$dates[$key]['to_timestamp'] 	= $dates[$key]['from_timestamp'] + 24 * 60 * 60 * $value['end_period'];
             $dates[$key]['from_timestamp'] = $value['active_in_lesson'] + 24 * 60 * 60 * $value['start_period'];
             $dates[$key]['to_timestamp'] = $dates[$key]['from_timestamp'] + 24 * 60 * 60 * $value['end_period'];
         } elseif (isset($value['start_date']) && isset($value['end_date'])) {
             $dates[$key]['from_timestamp'] = $value['start_date'];
             $dates[$key]['to_timestamp'] = $value['end_date'];
         }
         if ($roles[$value['user_type']] == 'student') {
             $completedLessons[$key] = $value['completed'];
         }
     }
     foreach ($this->rules as $lessonId => $lessonRules) {
         if (eF_checkParameter($lessonId, 'id')) {
             $evalString = '';
             for ($i = 1; $i < sizeof($lessonRules['lesson']); $i++) {
                 $evalString .= $completedLessons[$lessonRules['lesson'][$i]] . ' ' . ($lessonRules['condition'][$i + 1] == 'and' ? '&' : '|');
             }
             $evalString = $evalString . ' ' . $completedLessons[$lessonRules['lesson'][$i]];
             if (!empty($completedLessons) && isset($completedLessons[$lessonRules['lesson'][$i]])) {
                 if (trim($evalString) == '') {
                     $evalString = 'false';
                 }
                 eval("\$allowed[{$lessonId}] = {$evalString};");
             }
         }
     }
     foreach ($allowed as $id => $allow) {
         if (isset($dates[$id]['from_timestamp']) && $dates[$id]['from_timestamp'] > time()) {
             $allowed[$id] = 0;
         }
         if (isset($dates[$id]['to_timestamp']) && $dates[$id]['to_timestamp'] < time()) {
             $allowed[$id] = 0;
         }
     }
     return $allowed;
 }
예제 #3
0
 /**
  * Return a list of all calendar events that should be presented to a user
  * that is not an administrator
  *
  * @param mixed $user A user login or an EfrontUser object
  * @return array A list of calendar events
  * @since 3.6.7
  * @access public
  * @static
  */
 public static function getCalendarEventsForNonAdministrator($user)
 {
     $user = EfrontUser::convertArgumentToUserLogin($user);
     $personalEvents = $globalEvents = $lessonEvents = $courseEvents = $groupEvents = $branchEvents = $subbranchEvents = array();
     $result = eF_getTableData("calendar c", "c.*", "type = 'global' and foreign_ID=0");
     foreach ($result as $value) {
         $globalEvents[$value['id']] = $value;
     }
     $result = eF_getTableData("lessons l, calendar ca, users_to_lessons ul", "ca.*, l.name", "ul.users_LOGIN='******' and ca.foreign_ID=ul.lessons_ID and ul.lessons_ID=l.id and l.archive=0 and ul.archive=0 and ca.type = 'lesson'");
     foreach ($result as $value) {
         $lessonEvents[$value['id']] = $value;
     }
     $result = eF_getTableData("courses c, calendar ca, users_to_courses uc", "ca.*, c.name", "uc.users_LOGIN='******' and ca.foreign_ID=uc.courses_ID and uc.courses_ID=c.id and c.archive=0 and uc.archive=0 and ca.type = 'course'");
     foreach ($result as $value) {
         $courseEvents[$value['id']] = $value;
     }
     $result = eF_getTableData("groups g, calendar ca, users_to_groups ug", "ca.*, g.name", "ug.users_LOGIN='******' and ca.foreign_ID=ug.groups_ID and ug.groups_ID=g.id and ca.type = 'group'");
     foreach ($result as $value) {
         $groupEvents[$value['id']] = $value;
     }
     if (G_VERSIONTYPE == 'enterprise') {
         #cpp#ifdef ENTERPRISE
         $result = eF_getTableData("module_hcd_branch b, calendar ca, module_hcd_employee_works_at_branch wb", "ca.*, b.name", "wb.users_LOGIN='******' and ca.foreign_ID=wb.branch_ID and b.branch_ID=wb.branch_ID and ca.type = 'branch'");
         foreach ($result as $value) {
             $branchEvents[$value['id']] = $value;
         }
         $userParentBranches = array();
         $branchesTree = new EfrontBranchesTree();
         $result = eF_getTableData("module_hcd_employee_works_at_branch", "branch_ID", "users_login='******' and assigned=1");
         foreach ($result as $value) {
             foreach ($branchesTree->getNodeAncestors($value['branch_ID']) as $node) {
                 $userParentBranches[] = $node['branch_ID'];
             }
         }
         $userParentBranches = array_unique($userParentBranches);
         if (!empty($userParentBranches)) {
             $result = eF_getTableData("module_hcd_branch b, calendar ca", "ca.*, b.name", "ca.foreign_ID=b.branch_ID and b.branch_ID in (" . implode(",", $userParentBranches) . ") and ca.type = 'sub_branch'");
             foreach ($result as $value) {
                 $subbranchEvents[$value['id']] = $value;
             }
         }
     }
     #cpp#endif
     $personalEvents = self::getUserCalendarEvents($user);
     $userEvents = $personalEvents + $globalEvents + $lessonEvents + $courseEvents + $groupEvents + $branchEvents + $subbranchEvents;
     return $userEvents;
 }