You are here

function course_edit_enrollment_action_form in Course 7

Same name and namespace in other branches
  1. 6 course.module \course_edit_enrollment_action_form()
  2. 7.2 course.module \course_edit_enrollment_action_form()

Edit enrollment action form.

File

./course.module, line 1998
course.module Core functionality for Courses.

Code

function course_edit_enrollment_action_form($a1, $context) {
  $form = array();

  // Load the first enrollment.
  $selection = reset($context['selection']);
  $check_enrollment = course_enrollment_load($selection);
  $node = node_load($check_enrollment->nid);

  // Check if this action is being performed on a single user, and set the
  // account accordingly.
  $account = NULL;
  $course_report = NULL;
  if (count($context['selection']) === 1) {

    // Only one user and course, so let's prefill values.
    $enrollment = $check_enrollment;
    $account = user_load($enrollment->uid);
    $course_report = course_report_load($node, $account);
  }
  $form['timestamp'] = array(
    '#title' => t('Set started date to'),
    '#type' => module_exists('date_popup') ? 'date_popup' : 'date_text',
    '#date_format' => 'Y-m-d H:i',
    '#description' => t('The date the user started the course.'),
    '#default_value' => !empty($enrollment->timestamp) ? format_date($enrollment->timestamp, 'custom', 'Y-m-d H:i') : NULL,
  );
  $form['enroll_end'] = array(
    '#title' => t('Extend course enrollment until'),
    '#type' => module_exists('date_popup') ? 'date_popup' : 'date_text',
    '#date_format' => 'Y-m-d H:i',
    '#description' => t('The date when the user will not be able to access the course.'),
    '#default_value' => !empty($enrollment->enroll_end) ? format_date($enrollment->enroll_end, 'custom', 'Y-m-d H:i') : NULL,
  );
  $form['status'] = array(
    '#title' => t('Set enrollment status to'),
    '#type' => 'select',
    '#options' => array(
      '' => '',
      1 => 'Active',
      0 => 'Inactive',
    ),
    '#default_value' => !empty($enrollment->status) ? $enrollment->status : NULL,
    '#description' => t('Setting an enrollment to "inactive" will prevent a user from accessing the course.'),
  );
  $form['complete'] = array(
    '#title' => t('Set completion status to'),
    '#type' => 'select',
    '#options' => array(
      '' => '',
      1 => t('Complete'),
      0 => t('Incomplete'),
    ),
    '#description' => t("This will change a user's course completion. Set this to incomplete to re-evaluate all requirements. Courses will never be automatically un-completed once they have been marked completed."),
    '#default_value' => !empty($course_report->complete) ? $course_report->complete : NULL,
  );
  $form['date_completed'] = array(
    '#title' => t('Set completion date to'),
    '#type' => module_exists('date_popup') ? 'date_popup' : 'date_text',
    '#date_format' => 'Y-m-d H:i',
    '#description' => t('The date of completion.'),
    '#default_value' => !empty($course_report->date_completed) ? format_date($course_report->date_completed, 'custom', 'Y-m-d H:i') : NULL,
  );
  if (isset($node)) {

    // Get course objects, with or without a single user account information.
    $course = course_get_course($node, $account);
    $objects = $course
      ->getObjects();

    // Build a list of a single user's fulfillments.
    $fulfillments = NULL;
    if ($account) {
      $fulfillments = array();
      foreach ($objects as $courseObject) {
        $fulfillments[$courseObject
          ->getId()] = $courseObject
          ->getFulfillment($account);
      }
    }
    $form['course_objects'] = array(
      '#title' => t('Set completion status'),
      '#description' => t('Set the status of a course object to be applied to selected users.'),
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#tree' => TRUE,
      '#prefix' => '<span id="course-objects-wrapper">',
      '#suffix' => '</span>',
    );
    foreach ($objects as $courseObject) {
      $form['course_objects'][$courseObject
        ->getId()] = array(
        '#type' => 'select',
        '#title' => check_plain($courseObject
          ->getTitle()),
        '#options' => array(
          '' => '- no change - ',
          1 => t('Complete'),
          -1 => t('Incomplete'),
          0 => t('Failed'),
        ),
        '#default_value' => $fulfillments ? $fulfillments[$courseObject
          ->getId()]
          ->isComplete() : NULL,
      );
    }
  }
  return $form;
}