You are here

course_poll.module in Course 8.2

File

modules/course_poll/course_poll.module
View source
<?php

/**
 * Implements hook_course_handlers().
 */
function course_poll_course_handlers() {
  return array(
    'object' => array(
      'poll' => array(
        'name' => t('Poll'),
        'class' => 'Drupal\\course_poll\\Course\\Object\\CourseObjectPoll',
        'fulfillment class' => 'Drupal\\course_poll\\Course\\Object\\CourseObjectPollFulfillment',
        'description' => t('A poll to be used in a course workflow.'),
      ),
    ),
  );
}

/**
 * Implements hook_form_FORMID_alter().
 */
function course_poll_form_poll_view_voting_alter(&$form, &$form_state) {
  $form['vote']['#submit'][] = 'course_poll_fulfill';
}

/**
 * Fulfill the voting object.
 */
function course_poll_fulfill(&$form, &$form_state) {
  global $user;
  $nid = $form['#node']->nid;
  $chid = $form_state['values']['choice'];

  // Find the course object associated with this poll.
  if ($courseObject = course_get_course_object('course_poll', 'poll', $nid)) {
    $courseObject
      ->getFulfillment($user)
      ->setOption('instance', $chid)
      ->setComplete()
      ->save();
  }
}

Functions

Namesort descending Description
course_poll_course_handlers Implements hook_course_handlers().
course_poll_form_poll_view_voting_alter Implements hook_form_FORMID_alter().
course_poll_fulfill Fulfill the voting object.