You are here

function course_edit_enrollment_action_form in Course 6

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

Edit enrollment action form.

File

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

Code

function course_edit_enrollment_action_form($context) {
  $form = array();
  $node = node_load(arg(1));
  if (!$node) {
    return array();
  }
  $num_users = count($context['selection']);
  $form['header'] = array(
    '#value' => format_plural($num_users, 'Use this form to edit course enrollment and completion data for 1 user', 'Use this form to edit course enrollment and completion data for @count users'),
  );

  // Check if this action is being performed on a single user, and set the
  // account accordingly.
  $account = NULL;
  $enroll = NULL;
  $course_report = NULL;
  if ($num_users == 1) {

    // Only one user, so let's prefill values.
    $selection = reset($context['selection']);
    $enroll = course_enrolment_load($selection->eid);
    $account = user_load($enroll->uid);
    $course_report = course_report_load($node, $account);
  }

  // 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) {

      // Find required course objects the user has not yet completed.

      //if ($courseObject->getOption('required') && !$courseObject->getOption('complete')) {
      $fulfillments[$courseObject
        ->getId()] = $courseObject
        ->getFulfillment();

      //}
    }
  }
  $form['status'] = array(
    '#title' => t('Set enrollment status to'),
    '#type' => 'select',
    '#options' => array(
      '' => '',
      1 => 'Active',
      0 => 'Inactive',
    ),
    '#default_value' => $enroll->status,
    '#description' => t('Setting an enrollment to "inactive" will prevent a user from accessing the course.'),
  );
  $form['enrol_end'] = array(
    '#title' => t('Extend course enrollment until'),
    '#type' => module_exists('date_popup') ? 'date_popup' : 'date_text',
    '#date_format' => 'm/d/Y H:i',
    '#description' => t('The date when the user will not be able to access the course.'),
    '#default_value' => $enroll->enrol_end ? date('Y-m-d H:i:s', $enroll->enrol_end) : '',
  );
  $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 to incomplete this to re-evaluate all requirements. Course will never be automatically un-completed once they have been marked completed."),
    '#default_value' => $course_report->complete,
  );
  $form['date_completed'] = array(
    '#title' => t('Set completion date to'),
    '#type' => module_exists('date_popup') ? 'date_popup' : 'date_text',
    '#date_format' => 'm/d/Y H:i',
    '#description' => t('The date of completion.'),
    '#default_value' => !empty($course_report->date_completed) ? date('Y-m-d H:i:s', $course_report->date_completed) : NULL,
  );
  $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;
}