casetracker_views_handler_field_case_count.inc in Case Tracker 6
File
includes/casetracker_views_handler_field_case_count.inc
View source
<?php
class casetracker_views_handler_field_case_count extends views_handler_field {
function query() {
}
function option_definition() {
$options = parent::option_definition();
$options['type'] = array(
'default' => 0,
);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$options = array(
0 => t('All cases'),
t('Priority') => array(),
t('Status') => array(),
t('Type') => array(),
);
$realms = array(
'priority' => t('Priority'),
'status' => t('Status'),
'type' => t('Type'),
);
foreach ($realms as $realm => $realm_name) {
foreach (casetracker_realm_load($realm) as $csid => $name) {
$options[$realm_name]["{$realm}-{$csid}"] = t($name);
}
}
$form['type'] = array(
'#type' => 'select',
'#title' => t('Count for type'),
'#options' => $options,
'#default_value' => $this->options['type'],
'#description' => t('Text to put after the number, such as currency symbol.'),
);
}
function pre_render($values) {
$nids = array();
foreach ($values as $row) {
$nids[] = $row->nid;
}
if (!empty($nids)) {
$this->counts = array();
$placeholders = db_placeholders($nids, 'int');
$where = '';
if (!empty($this->options['type'])) {
$filter = explode('-', $this->options['type']);
$where = "AND case_{$filter[0]}_id = %d";
$nids[] = $filter[1];
}
$result = db_query("SELECT count(c.nid) AS count, c.pid FROM {casetracker_case} c JOIN {node} n ON c.nid = n.nid AND c.vid = n.vid WHERE c.pid IN ({$placeholders}) {$where} GROUP BY c.pid", $nids);
while ($row = db_fetch_object($result)) {
$this->counts[$row->pid] = $row->count;
}
}
}
function render($values) {
$count = !empty($this->counts[$values->nid]) ? $this->counts[$values->nid] : 0;
return "<span class='case-count'>{$count}</span>";
}
}