You are here

course_certificate.install in Course 7

Install, update and uninstall functions for the course_certificate module.

File

modules/course_certificate/course_certificate.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the course_certificate module.
 *
 */

/**
 * Implements hook_install().
 */
function course_certificate_install() {
  course_certificate_update_6101();
}

/**
 * Create certificate course objects at the end of a course for courses that had
 * the "certificate" checkbox checked. Drop the old field.
 */
function course_certificate_update_6101() {
  $ret = array();
  drupal_get_schema(NULL, TRUE);
  drupal_load('module', 'uuid');
  if (db_table_exists('course_node') && db_field_exists('course_node', 'certificate')) {
    $idfield = db_field_exists('course_outline', 'snid') ? 'snid' : 'coid';
    $modulefield = $idfield == 'snid' ? 'requirement_type' : 'module';

    // Find courses that had certificate checked, but no course object.
    $sql = "SELECT * FROM {course_node} cn\n      INNER JOIN {course_outline} co ON (cn.nid = co.nid AND co.{$modulefield} = 'course_certificate')\n      where cn.certificate and co.{$idfield} is null";
    $result = db_query($sql);
    while ($row = $result
      ->fetch()) {
      $object = array(
        'module' => 'course_certificate',
        'object_type' => 'certificate',
        'nid' => $row->nid,
        'enabled' => 1,
        'required' => 0,
        'hidden' => 0,
        'title' => 'Certificate',
        'weight' => 999,
        'uuid' => uuid_generate(),
      );
      drupal_write_record('course_outline', $object);
    }
    db_drop_field('course_node', 'certificate');
  }
  return t('Created new certificate objects.');
}

Functions

Namesort descending Description
course_certificate_install Implements hook_install().
course_certificate_update_6101 Create certificate course objects at the end of a course for courses that had the "certificate" checkbox checked. Drop the old field.