You are here

public function CourseObject::optionsForm in Course 7

Same name and namespace in other branches
  1. 6 includes/course_object.core.inc \CourseObject::optionsForm()
  2. 7.2 includes/CourseObject.inc \CourseObject::optionsForm()

Default options form for all course objects.

Overrides CourseHandler::optionsForm

3 calls to CourseObject::optionsForm()
CourseObjectCertificate::optionsForm in modules/course_certificate/course_certificate.classes.inc
Default options form for all course objects.
CourseObjectManual::optionsForm in modules/course_object_manual/course_object_manual.classes.inc
Default options form for all course objects.
CourseObjectNode::optionsForm in includes/CourseObjectNode.inc
Default options form for all course objects.
3 methods override CourseObject::optionsForm()
CourseObjectCertificate::optionsForm in modules/course_certificate/course_certificate.classes.inc
Default options form for all course objects.
CourseObjectManual::optionsForm in modules/course_object_manual/course_object_manual.classes.inc
Default options form for all course objects.
CourseObjectNode::optionsForm in includes/CourseObjectNode.inc
Default options form for all course objects.

File

includes/CourseObject.inc, line 209

Class

CourseObject
Parent abstract base class of all course objects.

Code

public function optionsForm(&$form, &$form_state) {
  ctools_include('plugins');
  parent::optionsForm($form, $form_state);
  $config = $this
    ->getOptions();
  $form['header']['#markup'] = t("<h2>Settings for %t</h2>", array(
    '%t' => $this
      ->getTitle(),
  ));
  $form['uniqid'] = array(
    '#type' => 'value',
    '#value' => $this
      ->getId(),
  );
  $form['nid'] = array(
    '#type' => 'value',
    '#value' => $this
      ->getCourseNid(),
  );
  $form['course_tabs']['#type'] = 'vertical_tabs';
  $form['title'] = array(
    '#title' => t('Title & description'),
    '#type' => 'fieldset',
    '#group' => 'course_tabs',
    '#weight' => 0,
  );
  $form['outline'] = array(
    '#type' => 'fieldset',
    '#title' => t('Settings'),
    '#group' => 'course_tabs',
    '#weight' => 1,
  );
  $form['plugins']['access'] = array(
    '#type' => 'fieldset',
    '#title' => 'Access',
    '#group' => 'course_tabs',
    '#weight' => 4,
  );
  $form['delete'] = array(
    '#type' => 'fieldset',
    '#title' => 'Delete',
    '#group' => 'course_tabs',
    '#weight' => 5,
  );
  $form['title']['title'] = array(
    '#title' => t('Title'),
    '#type' => 'textfield',
    '#description' => t('The title of this course object as it will appear to users in the course outline.'),
    '#size' => 100,
    '#default_value' => $config['title'],
    '#group' => 'description',
    '#required' => TRUE,
  );
  $form['outline']['enabled'] = array(
    '#title' => t('Enabled'),
    '#type' => 'checkbox',
    '#description' => t('Enabled course objects will become part of the course. Uncheck this box if you are not using this course object.'),
    '#default_value' => $config['enabled'],
  );
  $form['outline']['hidden'] = array(
    '#title' => t('Visible in outline'),
    '#type' => 'checkbox',
    '#description' => t('Objects that are not visible will not be seen by the learner. Uncheck this box for course objects that you do not want the learner to see.'),
    '#default_value' => !$config['hidden'],
    '#group' => 'course',
  );
  $form['outline']['required'] = array(
    '#title' => t('Completion required'),
    '#type' => 'checkbox',
    '#description' => t('Users must complete required objects. Uncheck this box if this is an optional course object.'),
    '#default_value' => $config['required'],
  );
  $form['outline']['skippable'] = array(
    '#title' => t('Skippable'),
    '#type' => 'checkbox',
    '#default_value' => $config['skippable'],
    '#states' => array(
      'visible' => array(
        '#edit-required' => array(
          'checked' => TRUE,
        ),
      ),
    ),
    '#description' => t('Users can proceed past this object but it will still be required for course completion.'),
  );

  // Delete object
  $form['delete']['delete_button'] = array(
    '#value' => t('Delete'),
    '#weight' => 999,
    '#type' => 'submit',
    '#submit' => array(
      array(
        $this,
        'setDelete',
      ),
      array(
        $this,
        'optionsSubmit',
      ),
    ),
    '#limit_validation_errors' => array(),
  );

  // Only allow deletion of existing instances.
  if (!empty($config['instance'])) {
    $form['delete']['delete_instance'] = array(
      '#title' => t('Also delete the referenced content.'),
      '#type' => 'checkbox',
      '#default_value' => $config['delete_instance'],
      '#stats' => array(
        'visible' => array(
          '#edit-delete' => array(
            'checked' => TRUE,
          ),
        ),
      ),
      '#group' => 'delete',
    );

    // Check for multiple instances.
    if (db_query("SELECT count(coid) FROM {course_outline} WHERE module = :module AND object_type = :object_type AND instance = :instance", array(
      ':module' => $config['module'],
      ':object_type' => $config['object_type'],
      ':instance' => $config['instance'],
    ))
      ->fetchField() > 1) {
      $form['delete']['delete_instance']['#description'] = t('<span class="error"><strong>WARNING</strong></span>: multiple course objects link to this instance. Deleting the instance might break the other course objects that use it.');
    }
  }
  if ($this
    ->isGraded()) {
    $form['grading'] = array(
      '#title' => t('Grading'),
      '#type' => 'fieldset',
      '#description' => t('Settings for graded objects.'),
      '#group' => 'course_tabs',
      '#weight' => 2,
    );
    $form['grading']['grade_include'] = array(
      '#title' => t('Include in final course grade'),
      '#description' => t('Include this grade result for calculation of the final course grade.<br/>Currently, only the last grade result per Course will be used.'),
      '#default_value' => $config['grade_include'],
      '#type' => 'checkbox',
    );
  }

  // Bring in access plugin configuration.
  $form['plugins']['#tree'] = TRUE;
  $form['plugins']['access']['#title'] = t('Access');
  $form['plugins']['access']['#description'] = t('By default, all required objects appearing before this object in the course outline must be completed before the user may access this object. Conditional access allows for additional conditions to be applied.');
  $form['plugins']['access']['#type'] = 'fieldset';
  foreach (ctools_get_plugins('course', 'course_object_access') as $key => $plugin) {
    $form['plugins']['access']['#tree'] = TRUE;
    $form['plugins']['access'][$key] = array(
      '#title' => $plugin['title'],
      '#type' => 'fieldset',
      '#tree' => TRUE,
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );

    // Initialize access class.
    $class = ctools_plugin_get_class($plugin, 'handler');
    $courseAccess = new $class();
    $courseAccess
      ->setCourseObject($this);
    $courseAccess
      ->setType($key);

    // Add access plugin form to our form.
    $access_form = $access_form_state = array();
    $form['plugins']['access'][$key] += $courseAccess
      ->optionsForm($access_form, $access_form_state);
  }

  // Update settings
  $form['actions']['update'] = array(
    '#value' => t('Update'),
    '#weight' => 999,
    '#type' => 'submit',
    '#validate' => array(
      array(
        $this,
        'optionsValidate',
      ),
    ),
    '#submit' => array(
      array(
        $this,
        'optionsSubmit',
      ),
    ),
  );
}