You are here

function certificate_nodeapi in Certificate 6.2

Same name and namespace in other branches
  1. 6 certificate.module \certificate_nodeapi()

Implements hook_nodeapi.

File

./certificate.module, line 349
Certificate module.

Code

function certificate_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  if (certificate_node_is_certifiable($node)) {
    switch ($op) {
      case 'insert':
      case 'update':
        if (isset($node->certificate)) {
          if (certificate_node_is_certifiable($node)) {

            // Update node mappings from a certifiable activity.
            certificate_update_node_mappings($node->nid, $node->certificate['map']);
          }
        }
        break;
      case 'delete':

        // Clean up the certificate template tables for the deleted node.
        db_query("DELETE FROM {certificate_node} WHERE nid = %d", $node->nid);
        db_query("DELETE FROM {certificate_snapshots} WHERE nid = %d", $node->nid);
        break;
      case 'load':
        return array(
          'certificate' => array(
            'node_settings' => certificate_course_node_template_settings($node->nid),
          ),
        );
      case 'view':
        if (certificate_can_access_certificate($node)) {

          // Add a download certificate link to the node content.
          $node->content['certificate']['#value'] = '<span class="certificate-link">' . l(t('Download certificate'), "node/{$node->nid}/certificate") . '</span>';
        }
        break;
    }
  }
  if ($node->type == 'certificate') {
    switch ($op) {
      case 'insert':
      case 'update':

        // Save the certificate settings.
        if (isset($node->certificate)) {
          $record = $node->certificate;
          $record['nid'] = $node->nid;
          if (db_result(db_query("select 1 from {certificate_node_settings} where nid = %d", $node->nid))) {
            $keys = array(
              'nid',
            );
          }
          drupal_write_record('certificate_node_settings', $record, $keys);
        }
        break;
      case 'load':
        return array(
          'certificate' => db_fetch_array(db_query("select * from {certificate_node_settings} where nid = %d", $node->nid)),
        );
    }
  }
}