class CourseObjectAccessConditional in Course 6
Same name and namespace in other branches
- 7.2 plugins/course_object_access/conditional.inc \CourseObjectAccessConditional
- 7 plugins/course_object_access/conditional.inc \CourseObjectAccessConditional
Hierarchy
- class \CourseHandler- class \CourseObjectAccess
 
Expanded class hierarchy of CourseObjectAccessConditional
1 string reference to 'CourseObjectAccessConditional'
- conditional.inc in plugins/course/ access/ conditional.inc 
File
- plugins/course/ access/ conditional.inc, line 11 
View source
class CourseObjectAccessConditional extends CourseObjectAccess {
  function view() {
    return $this
      ->take();
  }
  function see() {
    if ($this
      ->getOption('conditional_hidden')) {
      return $this
        ->view();
    }
  }
  function take() {
    $type = $this
      ->getOption('conditional_type');
    $offset = $this
      ->getOption('conditional_time');
    $time = time();
    $access = TRUE;
    if ($type) {
      foreach ($this
        ->getCourseObject()
        ->getCourse()
        ->getObjects() as $courseObject) {
        if ($courseObject
          ->getId() == $this
          ->getOption('conditional_object')) {
          switch ($type) {
            case 'completed':
              $completed = $courseObject
                ->getFulfillment()
                ->getOption('date_completed');
              if (!$completed) {
                $access = FALSE;
              }
              else {
                $access = $time >= $completed + $offset;
              }
              break;
            case 'started':
              $started = $courseObject
                ->getFulfillment()
                ->getOption('date_started');
              if (!$started) {
                $access = FALSE;
              }
              else {
                $access = $time >= $started + $offset;
              }
              break;
          }
        }
      }
    }
    return $access;
  }
  function optionsDefinition() {
    $defaults = parent::optionsDefinition();
    $defaults += array(
      'conditional_type' => NULL,
      'conditional_time' => NULL,
      'conditional_object' => NULL,
      'conditional_hidden' => NULL,
    );
    return $defaults;
  }
  function optionsValidate(&$form, &$values) {
    if (module_exists('duration_element')) {
      $values['conditional_time'] = $values['conditional_time']
        ->to_single_metric('seconds');
    }
  }
  function optionsForm() {
    $form = array();
    $config = $this
      ->getOptions();
    ctools_include('dependent');
    $form['conditional_type'] = array(
      '#title' => t('Event'),
      '#type' => 'select',
      '#options' => array(
        '',
        'started' => t('User started course object.'),
        'completed' => t('User completed course object.'),
      ),
      '#description' => t('This sets the conditional behavior.'),
    );
    $options = array(
      '',
    );
    foreach ($this
      ->getCourseObject()
      ->getCourse()
      ->getObjects() as $courseObject) {
      $options[$courseObject
        ->getId()] = $courseObject
        ->getTitle();
    }
    if (module_exists('duration_element')) {
      $conditional_time = duration_create();
      $conditional_time
        ->set_seconds($config['conditional_time']);
      $conditional_time
        ->normalize();
      $form['conditional_time'] = array(
        '#title' => t('Time'),
        '#type' => 'duration_combo',
        '#description' => t('Length of time after the event happens when this course object should be accessible.'),
        '#largest_metric' => 'days',
        '#smallest_metric' => 'minutes',
        '#default_value' => $conditional_time,
      );
    }
    else {
      $form['conditional_time'] = array(
        '#title' => t('Time'),
        '#type' => 'textfield',
        '#size' => 8,
        '#description' => t('Length of time in seconds after the event happens when this course object should be accessible.'),
        '#default_value' => $config['conditional_time'],
      );
    }
    $form['conditional_object'] = array(
      '#title' => t('Course object'),
      '#type' => 'select',
      '#options' => $options,
      '#description' => t('The course object to check for the type and time of conditional display.'),
    );
    $form['conditional_hidden'] = array(
      '#title' => t('Hide object until ready'),
      '#type' => 'checkbox',
      '#description' => t('This will prevent the course object from appearing in the course outline until it is ready.'),
    );
    $conditional_dependent = array(
      '#process' => array(
        'ctools_dependent_process',
      ),
      '#dependency' => array(
        'edit-plugins-access-conditional-conditional-type' => array(
          'completed',
          'started',
        ),
      ),
    );
    foreach (element_children($form) as $key) {
      if ($key != 'conditional_time') {
        $form[$key]['#default_value'] = $config[$key];
      }
      if ($key != 'conditional_type' && $key != 'conditional_time') {
        $form[$key] += $conditional_dependent;
      }
    }
    return $form;
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| CourseHandler:: | private | property | ||
| CourseHandler:: | protected | property | ||
| CourseHandler:: | public | property | ||
| CourseHandler:: | public | property | ||
| CourseHandler:: | public | property | ||
| CourseHandler:: | public | property | ||
| CourseHandler:: | final public | function | Merge an array of options onto the existing options. | |
| CourseHandler:: | public | function | Get an array of access messages. | |
| CourseHandler:: | protected | function | Return an array of database fields. This determines what fields should be serialized instead of stored. | |
| CourseHandler:: | function | |||
| CourseHandler:: | final public | function | Get an option stored in this CourseObject. | |
| CourseHandler:: | public | function | Get an object's configuration. | 1 | 
| CourseHandler:: | public | function | Stub. Get the summary of an object's options. | 1 | 
| CourseHandler:: | public | function | Return a list of warning strings about this handler. | 1 | 
| CourseHandler:: | private | function | Merge arrays with replace, not append. | |
| CourseHandler:: | public | function | Save data somewhere. | 1 | 
| CourseHandler:: | public | function | 2 | |
| CourseHandler:: | public | function | Set an access message to be displayed along with the course object when it is in the outline. For example, "This activity will open on XYZ" or "Please complete Step 1 to take this activity." | |
| CourseHandler:: | final public | function | Set an option for this handler. | |
| CourseHandler:: | final public | function | Set this entire handler's options. | |
| CourseObjectAccess:: | private | property | ||
| CourseObjectAccess:: | public | function | ||
| CourseObjectAccess:: | public | function | ||
| CourseObjectAccess:: | function | Overrides CourseHandler:: | ||
| CourseObjectAccessConditional:: | function | Handlers need to declare their defaults if they have a configuration form. Overrides CourseHandler:: | ||
| CourseObjectAccessConditional:: | function | Handlers can declare a form. Overrides CourseHandler:: | ||
| CourseObjectAccessConditional:: | function | Validate? Overrides CourseHandler:: | ||
| CourseObjectAccessConditional:: | function | Overrides CourseObjectAccess:: | ||
| CourseObjectAccessConditional:: | function | Overrides CourseObjectAccess:: | ||
| CourseObjectAccessConditional:: | function | Overrides CourseObjectAccess:: | 
