You are here

function casetracker_block in Case Tracker 5

Same name and namespace in other branches
  1. 6 casetracker.module \casetracker_block()

Implementation of hook_block().

File

./casetracker.module, line 1108
Enables the handling of projects and their cases.

Code

function casetracker_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == 'list') {
    $block = array();
    $block[0]['info'] = t('Jump to case number');
    $block[1]['info'] = t('Latest cases');
    return $block;
  }
  else {
    if ($op == 'configure' && $delta == 1) {
      $form['casetracker_block_latest_cases_count'] = array(
        '#type' => 'select',
        '#title' => t('Number of latest cases'),
        '#default_value' => variable_get('casetracker_block_latest_cases_count', 5),
        '#options' => drupal_map_assoc(array(
          2,
          3,
          4,
          5,
          6,
          7,
          8,
          9,
          10,
          11,
          12,
          13,
          14,
          15,
          16,
          17,
          18,
          19,
          20,
        )),
      );
      return $form;
    }
    else {
      if ($op == 'save' && $delta == 1) {
        variable_set('casetracker_block_latest_cases_count', $edit['casetracker_block_latest_cases_count']);
      }
      else {
        if ($op == 'view') {
          $block = array();
          switch ($delta) {
            case 0:
              if (user_access('access case tracker')) {
                drupal_add_css(drupal_get_path('module', 'casetracker') . '/casetracker.css');
                $block['content'] = drupal_get_form('casetracker_block_jump_to_case_number');
                $block['subject'] = t('Jump to case number');
                return $block;
              }
              break;
            case 1:
              $query = db_rewrite_sql("SELECT n.nid, n.*, cs.* FROM {node} n INNER JOIN {casetracker_case} cs ON (n.vid = cs.vid) WHERE n.status = 1 ORDER BY n.created DESC");
              $results = db_query_range($query, 0, variable_get('casetracker_block_latest_cases_count', 5));
              $cases = array();
              while ($case_result = db_fetch_object($results)) {

                // we'll pull up the raw case data and the raw project data and send it right to the theme.
                $project_result = db_fetch_object(db_query("SELECT n.*, cp.* FROM {node} n INNER JOIN {casetracker_project} cp ON (n.vid = cp.vid) WHERE n.nid = %d", $case_result->pid));
                $cases[] = array(
                  'case' => $case_result,
                  'project' => $project_result,
                );
              }
              $block['subject'] = t('Latest cases');
              $block['content'] = theme('casetracker_block_latest_cases', $cases);
              return $block;
          }
        }
      }
    }
  }
}