You are here

casetracker_basic.module in Case Tracker 6

Same filename and directory in other branches
  1. 5 casetracker_basic.module
  2. 7 casetracker_basic.module

Enables a basic project node type for use with Case Tracker.

File

casetracker_basic.module
View source
<?php

/**
 * @file
 * Enables a basic project node type for use with Case Tracker.
 */

/**
 * Implementation of hook_perm().
 */
function casetracker_basic_perm() {
  return array(
    'create projects',
    'create cases',
    'edit own projects',
    'edit own cases',
    'edit any project',
    'edit any case',
  );
}

/**
 * Implementation of hook_node_info().
 */
function casetracker_basic_node_info() {
  return array(
    'casetracker_basic_project' => array(
      'name' => t('Project'),
      'module' => 'casetracker_basic_project',
      'description' => t('Create a basic project for use with Case Tracker.'),
      'help' => t('Create a basic project for use with Case Tracker.'),
      'body_label' => t('Description'),
    ),
    'casetracker_basic_case' => array(
      'name' => t('Case'),
      'module' => 'casetracker_basic_case',
      'description' => t('Open a new case assigned to a particular project.'),
      'help' => t('Open a new case assigned to a particular project.'),
      'body_label' => t('Description'),
    ),
  );
}

/**
 * Implementation of hook_form().
 */
function casetracker_basic_project_form(&$node) {
  $form = array();
  if (casetracker_is_project($node->type)) {
    $type = node_get_types('type', $node);
    $form['title'] = array(
      '#type' => 'textfield',
      '#title' => check_plain($type->title_label),
      '#required' => TRUE,
      '#default_value' => !empty($node->title) ? $node->title : NULL,
      '#weight' => -5,
    );
    $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
  }
  return $form;
}

/**
 * Implementation of hook_form().
 */
function casetracker_basic_case_form(&$node) {
  $form = array();
  if (casetracker_is_case($node->type)) {
    $type = node_get_types('type', $node);
    $form['title'] = array(
      '#type' => 'textfield',
      '#title' => check_plain($type->title_label),
      '#required' => TRUE,
      '#default_value' => !empty($node->title) ? $node->title : NULL,
      '#weight' => -5,
    );
    $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
  }
  return $form;
}

/**
 *  Implementation of hook_access().
 */
function casetracker_basic_project_access($op, $node, $account) {
  switch ($op) {
    case 'create':
      return user_access('create projects', $account);
      break;
    case 'update':
    case 'delete':
      if (user_access('edit any project') || user_access('edit own projects', $account) && $account->uid == $node->uid) {
        return TRUE;
      }
      break;
  }
}

/**
 * Implementation of hook_access().
 */
function casetracker_basic_case_access($op, $node) {
  global $user;
  switch ($op) {
    case 'create':
      return user_access('create cases');
    case 'update':
    case 'delete':
      if (user_access('edit any case') || user_access('edit own cases') && $user->uid == $node->uid) {
        return TRUE;
      }
      break;
  }
}

Functions