You are here

function CourseObjectAccessGrade::take in Course 7

Same name and namespace in other branches
  1. 6 plugins/course/access/grade.inc \CourseObjectAccessGrade::take()
  2. 7.2 plugins/course_object_access/grade.inc \CourseObjectAccessGrade::take()

Overrides CourseObjectAccess::take

2 calls to CourseObjectAccessGrade::take()
CourseObjectAccessGrade::see in plugins/course_object_access/grade.inc
CourseObjectAccessGrade::view in plugins/course_object_access/grade.inc

File

plugins/course_object_access/grade.inc, line 41

Class

CourseObjectAccessGrade

Code

function take() {
  $config = $this
    ->getOptions();
  if (!empty($config['course_grade_range']) && is_numeric($config['course_grade_range']['low']) && is_numeric($config['course_grade_range']['high'])) {
    $grade = NULL;
    $conditional_object = NULL;
    if ($this
      ->getOption('conditional_object')) {

      // Check object grade.
      $conditional_object = course_object_load($config['conditional_object']);
      $grade = $conditional_object
        ->getFulfillment()
        ->getOption('grade_result');
    }
    else {
      $grade = $this
        ->getCourseObject()
        ->getCourse()
        ->getTracker()
        ->getOption('grade_result');
    }
    $low_range = $grade >= $config['course_grade_range']['low'];
    $high_range = $grade <= $config['course_grade_range']['high'];
    if ($low_range && $high_range) {
      return TRUE;
    }
    else {
      if (isset($conditional_object)) {
        $this
          ->getCourseObject()
          ->setAccessMessage('grade', t('%title requires a grade between @grade_low% and @grade_high% to continue.', array(
          '@grade_low' => $config['course_grade_range']['low'],
          '@grade_high' => $config['course_grade_range']['high'],
          '%title' => $conditional_object
            ->getTitle(),
        )));
        return FALSE;
      }
      else {
        $this
          ->getCourseObject()
          ->setAccessMessage('grade', t('You must have a grade between @grade_low% and @grade_high% to continue.', array(
          '@grade_low' => $config['course_grade_range']['low'],
          '@grade_high' => $config['course_grade_range']['high'],
        )));
        return FALSE;
      }
    }
  }
}