You are here

public function CourseObject::optionsForm in Course 6

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

Default options form for all course objects.

Overrides CourseHandler::optionsForm

4 calls to CourseObject::optionsForm()
CourseObject::getOptionsSummary in includes/course_object.core.inc
Get core options summary.
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/course_object.core.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/course_object.core.inc
Default options form for all course objects.

File

includes/course_object.core.inc, line 235

Class

CourseObject
Parent abstract base class of all course objects.

Code

public function optionsForm(&$form, &$form_state) {
  ctools_include('dependent');
  ctools_include('plugins');
  parent::optionsForm($form, $form_state);
  $config = $this
    ->getOptions();
  $form['header']['#value'] = t("<h2>Settings for %t</h2>", array(
    '%t' => $this
      ->getTitle(),
  ));
  $form['uniqid'] = array(
    '#type' => 'hidden',
    '#value' => arg(4),
  );
  $form['nid'] = array(
    '#type' => 'hidden',
    '#value' => arg(1),
  );
  $form['title'] = array(
    '#title' => 'Title',
    '#type' => 'textfield',
    '#size' => 100,
    '#default_value' => check_plain($config['title']),
  );
  $form['enabled'] = array(
    '#title' => 'Enabled',
    '#type' => 'checkbox',
    '#default_value' => $config['enabled'],
  );
  $form['hidden'] = array(
    '#title' => t('Visible in outline'),
    '#type' => 'checkbox',
    //'#description' => t('Hide this course object in the course outline. If this object is required, progress through the course will be blocked until this object is complete.'),
    '#default_value' => !$config['hidden'],
  );
  $form['required'] = array(
    '#title' => t('Completion required'),
    '#type' => 'checkbox',
    '#default_value' => $config['required'],
  );
  $form['delete'] = array(
    '#title' => t('Delete'),
    '#type' => 'checkbox',
    '#default_value' => $config['delete'],
  );

  // Only allow deletion of existing instances.
  if (!empty($config['instance'])) {
    $form['delete_instance'] = array(
      '#title' => t('Also delete related object instance(s)'),
      '#type' => 'checkbox',
      '#default_value' => $config['delete_instance'],
      '#process' => array(
        'ctools_dependent_process',
      ),
      '#dependency' => array(
        'edit-delete' => array(
          1,
        ),
      ),
    );

    // Check for multiple instances.
    $sql = "SELECT count(coid) FROM {course_outline} WHERE module = '%s' AND object_type = '%s' AND instance = '%s'";
    if (db_result(db_query($sql, $config['module'], $config['object_type'], $config['instance'])) > 1) {
      $form['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' => 'Grading',
      '#type' => 'fieldset',
      '#description' => t('Settings for graded objects.'),
    );
    $form['grading']['grade_include'] = array(
      '#title' => 'Include in final course grade',
      '#description' => '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']['#weight'] = 998;
  $form['plugins']['access']['#title'] = 'Access plugins';
  $form['plugins']['access']['#type'] = 'fieldset';
  foreach (ctools_get_plugins('course', 'access') as $key => $plugin) {
    $form['plugins']['access']['#tree'] = TRUE;
    $form['plugins']['access'][$key] = array(
      '#title' => $plugin['title'],
      '#type' => 'fieldset',
      '#tree' => TRUE,
      '#collapsible' => TRUE,
    );

    // Initialize access class.
    $class = ctools_plugin_get_class($plugin, 'handler');
    $courseAccess = new $class();
    if (!empty($config['plugins']['access'][$key])) {
      $courseAccess
        ->setOptions($config['plugins']['access'][$key]);
    }
    $courseAccess
      ->setCourseObject($this);

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

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