You are here

function certificate_nodeapi in Certificate 6

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

Implements hook_nodeapi.

File

./certificate.module, line 534
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 (certificate_node_is_certifiable($node)) {
          certificate_update_node_mappings($node);
        }
        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),
          ),
        );
        break;
      case 'view':
        if (certificate_can_access_certificate($node)) {
          $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':
        $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)),
        );
    }
  }
}