course_webform.module in Course 8.2
File
modules/course_webform/course_webform.module
View source
<?php
function course_webform_webform_results_download_submission_information_info() {
$out = array();
$out['course_id'] = 'Course ID';
$out['course_title'] = 'Course title';
return $out;
}
function course_webform_webform_results_download_submission_information_data($token, $submission, array $options, $serial_start, $row_count) {
if (in_array($token, array(
'course_id',
'course_title',
))) {
$query = \Drupal::database()
->select('course_outline_fulfillment', 'cof')
->fields('n', array(
'nid',
'title',
))
->condition('cof.instance', strval($submission->sid))
->condition('co.object_type', 'webform');
$query
->join('course_outline', 'co', 'co.coid = cof.coid');
$query
->join('node', 'n', 'co.nid = n.nid');
if ($row = $query
->execute()
->fetch()) {
if ($token == 'course_id') {
return $row->nid;
}
if ($token == 'course_title') {
return $row->title;
}
}
}
}
function course_webform_webform_submission_insert(Drupal\webform\Entity\WebformSubmission $webform_submission) {
if (!$webform_submission
->isDraft()) {
if ($courseObject = course_get_course_object('webform', $webform_submission
->getWebform()
->id())) {
$fulfillment = $courseObject
->getFulfillment($webform_submission
->getOwner());
$sids = (array) $fulfillment
->getOption('sids');
$sids[] = $webform_submission
->id();
$fulfillment
->setOption('instance', $webform_submission
->id())
->setOption('sids', $sids)
->setComplete()
->save();
}
}
}
function course_webform_webform_submission_update(Drupal\webform\Entity\WebformSubmission $webform_submission) {
course_webform_webform_submission_insert($webform_submission);
}