| 1 |
/* from Community Tags quicktags form */
|
| 2 |
|
| 3 |
$destination = drupal_get_destination();
|
| 4 |
$form['login'] = array(
|
| 5 |
'#type' => 'markup',
|
| 6 |
'#value' => '<div>'. t('<a href="@login">Login</a> or <a href="@register">register</a> to tag items', array('@login' => url('user/login', $destination), '@register' => url('user/register', $destination))) .'</div>',
|
| 7 |
);
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
/* from hook_help */
|
| 13 |
|
| 14 |
// case 'cmt':
|
| 15 |
// case 'cmt/my':
|
| 16 |
// return '<p>'.t('Hypothetical listing pages or something.').'</p>';
|
| 17 |
|
| 18 |
// case 'casetracker/cases':
|
| 19 |
// case 'casetracker/cases/'.arg(2):
|
| 20 |
// case 'casetracker/cases/'.arg(2).'/'.arg(3):
|
| 21 |
// return '<p>'.t('A list of cases created within Case Tracker, per your filter criteria.').'</p>';
|
| 22 |
|
| 23 |
// case 'user/'.arg(1).'/cases':
|
| 24 |
// return '<p>'.t('A list of cases you\'ve created or which have been assigned to you.').'</p>';
|
| 25 |
|
| 26 |
|
| 27 |
/* I'm not a fan of the separate settings page approach, e.g.:
|
| 28 |
case 'admin/settings/casetracker':
|
| 29 |
return '<p>'.t('Configure the various Case Tracker options with these settings.').'</p>';
|
| 30 |
*/
|
| 31 |
// case 'admin/content/casetracker/state/edit/'.arg(4):
|
| 32 |
// return '<p>'.t('You may edit an existing case state below.').'</p>';
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
/* from hook_menu may_cache */
|
| 37 |
|
| 38 |
|
| 39 |
/* -- user accessible menu items ---------------------------------------- */
|
| 40 |
/*
|
| 41 |
$items[] = array(
|
| 42 |
'access' => user_access('access case tracker'),
|
| 43 |
'callback' => 'cmt_admin',
|
| 44 |
'path' => 'cmt',
|
| 45 |
'title' => t('Community Categories'),
|
| 46 |
);
|
| 47 |
*/
|
| 48 |
|
| 49 |
|
| 50 |
/*
|
| 51 |
$items[] = array(
|
| 52 |
'access' => user_access('administer case tracker'),
|
| 53 |
'path' => 'admin/content/casetracker/state/list',
|
| 54 |
'callback' => 'casetracker_case_state_overview',
|
| 55 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 56 |
'title' => t('List'),
|
| 57 |
'weight' => -10,
|
| 58 |
);
|
| 59 |
$items[] = array(
|
| 60 |
'access' => user_access('administer case tracker'),
|
| 61 |
'callback' => 'drupal_get_form',
|
| 62 |
'callback arguments' => array('casetracker_case_state_edit'),
|
| 63 |
'path' => 'admin/content/casetracker/state/add',
|
| 64 |
'title' => t('Add case state'),
|
| 65 |
'type' => MENU_LOCAL_TASK,
|
| 66 |
);
|
| 67 |
*/
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
// no cache
|
| 72 |
|
| 73 |
/* ADD later from community_tags
|
| 74 |
// Add tagging tab, if necessary and supported for this node.
|
| 75 |
if (arg(0) == 'node' && is_numeric(arg(1))) {
|
| 76 |
$node = node_load(arg(1));
|
| 77 |
if ($node) {
|
| 78 |
$tab = variable_get('community_tags_display_'. $node->type, COMMUNITY_TAGS_MODE_TAB) == COMMUNITY_TAGS_MODE_TAB;
|
| 79 |
$vids = community_tags_for_node($node);
|
| 80 |
$items[] = array(
|
| 81 |
'path' => 'node/'. arg(1) .'/tag',
|
| 82 |
'title' => t('Tags'),
|
| 83 |
'callback' => 'community_tags_node_view',
|
| 84 |
'callback arguments' => array(arg(1), FALSE),
|
| 85 |
'access' => (user_access('access content') && user_access('tag content') && count($vids)),
|
| 86 |
'type' => $tab ? MENU_LOCAL_TASK : MENU_CALLBACK,
|
| 87 |
'weight' => 2,
|
| 88 |
);
|
| 89 |
}
|
| 90 |
LATER */
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
hook_nodeapi case view
|
| 95 |
|
| 96 |
// cases: summary data to beginning of body.
|
| 97 |
if (in_array($node->type, variable_get('casetracker_case_node_types', array('casetracker_basic_case')), TRUE)) {
|
| 98 |
$project = node_load($node->pid); // used in the breadcrumb and our theme function, mostly for nid and project number display.
|
| 99 |
$node->content['casetracker_case_summary'] = array('#value' => theme('casetracker_case_summary', $node, $project), '#weight' => -10);
|
| 100 |
if ($page) { drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('Case Tracker projects'), 'casetracker/projects'), l($project->title, 'node/'.$node->pid), l(t('All cases'), 'casetracker/cases/'.$node->pid.'/all'))); }
|
| 101 |
}
|
| 102 |
|
| 103 |
// projects: summary data to beginning of body.
|
| 104 |
if (in_array($node->type, variable_get('casetracker_project_node_types', array('casetracker_basic_project')), TRUE)) {
|
| 105 |
$node->content['casetracker_project_summary'] = array('#value' => theme('casetracker_project_summary', $node), '#weight' => -10);
|
| 106 |
}
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
FROM: function community_tags_node_view($node, $inline = TRUE) {
|
| 111 |
|
| 112 |
// there's no separate "all terms" view for CMT, and that's what this provides for community_tags
|
| 113 |
$cloud = theme('community_tags', 'node', NULL, $node->nid);
|
| 114 |
|
| 115 |
$vid = array_shift(community_tags_for_node($node));
|
| 116 |
/**
|
| 117 |
* Check whether a given node has one or more community tagged vocabulary associated with its type.
|
| 118 |
*/
|
| 119 |
// that's what the above calls
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
/**
|
| 124 |
* Theme the quick tag form.
|
| 125 |
* @ingroup themeable
|
| 126 |
*/
|
| 127 |
function theme_community_tags_form($form) {
|
| 128 |
$output .= theme('form_element', array('#title' => t('All tags')), drupal_render($form['cloud']));
|
| 129 |
|
| 130 |
$output .= drupal_render($form);
|
| 131 |
|
| 132 |
// We add the JS file this late, to ensure it comes after autocomplete.js.
|
| 133 |
drupal_add_css(drupal_get_path('module', 'community_tags') .'/community_tags.css', 'module');
|
| 134 |
drupal_add_js(drupal_get_path('module', 'community_tags') .'/community_tags.js');
|
| 135 |
|
| 136 |
return $output;
|
| 137 |
}
|
| 138 |
|
| 139 |
/**
|
| 140 |
* Helper function for the JS tagger.
|
| 141 |
*/
|
| 142 |
function community_tags_flatten($tags) {
|
| 143 |
$names = array();
|
| 144 |
foreach ($tags as $tag) {
|
| 145 |
$names[] = $tag->name;
|
| 146 |
}
|
| 147 |
return $names;
|
| 148 |
}
|
| 149 |
|
| 150 |
/**
|
| 151 |
* Callback for the JS tagger.
|
| 152 |
*/
|
| 153 |
function community_tags_from_js($nid) {
|
| 154 |
global $user;
|
| 155 |
if (!is_numeric($nid) || !($node = node_load($nid))) {
|
| 156 |
return;
|
| 157 |
}
|
| 158 |
|
| 159 |
$tags = is_array($_POST['tags']) ? $_POST['tags'] : array();
|
| 160 |
|
| 161 |
// Merge in new tag and save
|
| 162 |
$tags = array_unique(array_merge($tags, taxonomy_explode_tags($_POST['add'])));
|
| 163 |
$vid = array_shift(community_tags_for_node($node));
|
| 164 |
community_tags_taxonomy_node_save($node->nid, array('tags' => array($vid => $tags)), FALSE, $user->uid);
|
| 165 |
|
| 166 |
// Fetch updated list
|
| 167 |
$tags = community_tags_flatten(community_tags_get_user_node_tags($user->uid, $node->nid));
|
| 168 |
|
| 169 |
// Output JSON
|
| 170 |
print drupal_to_js(array('status' => TRUE, 'tags' => $tags, 'sequence' => $_POST['sequence']));
|
| 171 |
drupal_set_header('Content-Type: text/javascript; charset=utf-8');
|
| 172 |
}
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
/**
|
| 178 |
* Common form elements for cases, generic enough for use either in
|
| 179 |
* a full node display, or in comment displays and updating. Default
|
| 180 |
* values are calculated based on an existing $form['nid']['#value'].
|
| 181 |
*
|
| 182 |
* @param $form
|
| 183 |
* A Forms API $form, as received from a hook_form_alter().
|
| 184 |
* @param $default_project
|
| 185 |
* The project ID that should be pre-selected (ie., no select box).
|
| 186 |
* @return $form
|
| 187 |
* A modified Forms API $form.
|
| 188 |
*/
|
| 189 |
function casetracker_case_form_common(&$form, $default_project = NULL) {
|
| 190 |
// we use CSS to make an inline display of the case states.
|
| 191 |
drupal_add_css(drupal_get_path('module', 'casetracker') .'/casetracker.css');
|
| 192 |
$node = isset($form['nid']['#value']) ? node_load($form['nid']['#value']) : NULL;
|
| 193 |
|
| 194 |
// project to set as the default is based on how the user got here.
|
| 195 |
$default_project = isset($default_project) ? $default_project : $node->pid;
|
| 196 |
|
| 197 |
// get a list of all nodes that have been assigned as projects. we first
|
| 198 |
// check our settings for all node types assigned as projects, count them,
|
| 199 |
// and add that many %s's to our SQL so as to grab all nodes of those types.
|
| 200 |
$project_options = array(); // stores all found projects from set node types.
|
| 201 |
$results = db_query(db_rewrite_sql("SELECT n.nid, n.title FROM {node} n WHERE n.type IN (".str_pad('', count(array_filter(variable_get('casetracker_project_node_types', array('casetracker_basic_project')))) * 5 - 1, "'%s',").") ORDER BY n.title"), array_filter(variable_get('casetracker_project_node_types', array('casetracker_basic_project'))));
|
| 202 |
while ($result = db_fetch_array($results)) {
|
| 203 |
$project_options[$result['nid']] = $result['title'];
|
| 204 |
}
|
| 205 |
|
| 206 |
// if there's no project ID from the URL, or more than one project,
|
| 207 |
// we'll create a select menu for the user; otherwise, we'll save
|
| 208 |
// the passed (or only) project ID into a hidden field.
|
| 209 |
if (count($project_options) > 1) {
|
| 210 |
$form['casetracker_project_information'] = array(
|
| 211 |
'#type' => 'fieldset',
|
| 212 |
'#title' => t('Project information'),
|
| 213 |
'#weight' => -10,
|
| 214 |
'#collapsible' => TRUE,
|
| 215 |
'#collapsed' => isset($default_project) ? TRUE : FALSE,
|
| 216 |
'#prefix' => '<div id="project-information">',
|
| 217 |
'#suffix' => '</div>', // no particular reason.
|
| 218 |
);
|
| 219 |
$form['casetracker_project_information']['pid'] = array(
|
| 220 |
'#title' => t('Project'),
|
| 221 |
'#type' => 'select',
|
| 222 |
'#default_value' => $default_project,
|
| 223 |
'#options' => $project_options,
|
| 224 |
);
|
| 225 |
}
|
| 226 |
else {
|
| 227 |
$form['casetracker_project_information']['pid'] = array(
|
| 228 |
'#type' => 'hidden', // default value, or the only the project ID in the project_options array.
|
| 229 |
'#default_value' => isset($default_project) ? $default_project : array_shift(array_keys($project_options)),
|
| 230 |
'#options' => $project_options,
|
| 231 |
);
|
| 232 |
}
|
| 233 |
|
| 234 |
$form['casetracker_case_information'] = array(
|
| 235 |
'#type' => 'fieldset',
|
| 236 |
'#title' => t('Case information'),
|
| 237 |
'#collapsible' => TRUE,
|
| 238 |
'#collapsed' => FALSE,
|
| 239 |
'#weight' => -9,
|
| 240 |
'#prefix' => '<div id="case-information">',
|
| 241 |
'#suffix' => '</div>', // inline display.
|
| 242 |
);
|
| 243 |
$form['casetracker_case_information']['assign_to'] = array(
|
| 244 |
'#type' => user_access('assign case to user') ? 'textfield' : 'hidden',
|
| 245 |
'#title' => t('Assign to'),
|
| 246 |
'#autocomplete_path' => 'casetracker/autocomplete',
|
| 247 |
'#size' => 25,
|
| 248 |
'#default_value' => user_access('assign case to user')
|
| 249 |
? isset($node->assign_to) ? casetracker_get_name($node->assign_to) : $node->name
|
| 250 |
: isset($node->assign_to) ? casetracker_get_name($node->assign_to)
|
| 251 |
: variable_get('casetracker_default_assign_to', variable_get('anonymous', t('Anonymous'))),
|
| 252 |
);
|
| 253 |
|
| 254 |
$case_status_options = casetracker_case_state_load('status');
|
| 255 |
$form['casetracker_case_information']['case_status_id'] = array(
|
| 256 |
'#type' => user_access('set case status') ? 'select' : 'hidden',
|
| 257 |
'#title' => t('Status'),
|
| 258 |
'#options' => $case_status_options,
|
| 259 |
'#default_value' => user_access('set case status')
|
| 260 |
? isset($node->case_status_id) ? $node->case_status_id : NULL
|
| 261 |
: isset($node->case_status_id) ? $node->case_status_id
|
| 262 |
: variable_get('casetracker_default_case_status', array_shift(array_keys($case_status_options))),
|
| 263 |
);
|
| 264 |
|
| 265 |
$case_priority_options = casetracker_case_state_load('priority');
|
| 266 |
$form['casetracker_case_information']['case_priority_id'] = array(
|
| 267 |
'#type' => 'select',
|
| 268 |
'#title' => t('Priority'),
|
| 269 |
'#options' => $case_priority_options,
|
| 270 |
'#default_value' => isset($node->case_priority_id) ? $node->case_priority_id
|
| 271 |
: variable_get('casetracker_default_case_priority', array_shift(array_keys($case_priority_options))),
|
| 272 |
);
|
| 273 |
|
| 274 |
$case_type_options = casetracker_case_state_load('type');
|
| 275 |
$form['casetracker_case_information']['case_type_id'] = array(
|
| 276 |
'#type' => 'select',
|
| 277 |
'#title' => t('Type'),
|
| 278 |
'#options' => $case_type_options,
|
| 279 |
'#default_value' => isset($node->case_type_id) ? $node->case_type_id
|
| 280 |
: variable_get('casetracker_default_case_type', array_shift(array_keys($case_type_options))),
|
| 281 |
);
|
| 282 |
|
| 283 |
return $form;
|
| 284 |
}
|
| 285 |
|
| 286 |
/**
|
| 287 |
* Displays an administrative overview of all case states available.
|
| 288 |
*/
|
| 289 |
function casetracker_case_state_overview() {
|
| 290 |
$rows = array(); $headers = array(t('Name'), t('Realm'), array('data' => t('Operations'), 'colspan' => 2));
|
| 291 |
foreach (array('priority', 'status', 'type') as $realm) {
|
| 292 |
foreach (casetracker_case_state_load($realm) as $csid => $name) {
|
| 293 |
$rows[] = array(l($name, 'casetracker/cases/all/state/'.$csid), $realm,
|
| 294 |
l(t('edit'), 'admin/content/casetracker/state/edit/'.$csid),
|
| 295 |
l(t('delete'), 'admin/content/casetracker/state/delete/'.$csid), );
|
| 296 |
}
|
| 297 |
}
|
| 298 |
|
| 299 |
return theme('table', $headers, $rows);
|
| 300 |
}
|
| 301 |
|
| 302 |
/**
|
| 303 |
* Deletes a case state.
|
| 304 |
*
|
| 305 |
* @todo There is currently no attempt to do anything with cases which
|
| 306 |
* have been assigned the $csid that is about to be deleted. We should
|
| 307 |
* reset them to the default per our settings (and warn the user on our
|
| 308 |
* confirmation page), or something else entirely.
|
| 309 |
*
|
| 310 |
* @param $csid
|
| 311 |
* The case state ID to delete.
|
| 312 |
*/
|
| 313 |
function casetracker_case_state_delete($csid = NULL) {
|
| 314 |
if (!$csid) { return NULL; } // I SHALL NOT DELETE NOTHING! NOTHING AT ALL!
|
| 315 |
db_query('DELETE FROM {casetracker_case_states} WHERE csid = %d', $csid);
|
| 316 |
}
|
| 317 |
|
| 318 |
/**
|
| 319 |
* Returns information about the various case states and their options.
|
| 320 |
* The number of parameters passed will determine the return value.
|
| 321 |
*
|
| 322 |
* @param $realm
|
| 323 |
* Optional; the name of the realm ('status', 'priority', or 'type').
|
| 324 |
* @param $csid
|
| 325 |
* Optional; the state ID to return from the passed $realm.
|
| 326 |
* @return $values
|
| 327 |
* If only $realm is passed, you'll receive an array with the keys
|
| 328 |
* being the state ID and the values being their names. If a $csid
|
| 329 |
* is also passed, you'll receive just a string of the state name.
|
| 330 |
* If ONLY a $csid is passed, we'll return a list of 'name', 'realm'.
|
| 331 |
*/
|
| 332 |
function casetracker_case_state_load($realm = NULL, $csid = NULL) {
|
| 333 |
static $states_lookup = array();
|
| 334 |
|
| 335 |
if (!$states_lookup) {
|
| 336 |
$results = db_query("SELECT csid, case_state_name, case_state_realm FROM {casetracker_case_states}");
|
| 337 |
while ($result = db_fetch_object($results)) { // offer cached csid and realm lookups from a one-time query.
|
| 338 |
$states_lookup[$result->case_state_realm][$result->csid] = array('name' => $result->case_state_name, 'realm' => $result->case_state_realm, 'csid' => $result->csid);
|
| 339 |
$states_lookup[$result->csid] = $states_lookup[$result->case_state_realm][$result->csid];
|
| 340 |
}
|
| 341 |
}
|
| 342 |
|
| 343 |
if ($csid && $realm) {
|
| 344 |
return $states_lookup[$csid]['name'];
|
| 345 |
}
|
| 346 |
elseif ($csid && !$realm) {
|
| 347 |
return $states_lookup[$csid];
|
| 348 |
}
|
| 349 |
elseif (!$csid && $realm) {
|
| 350 |
$options = array(); // suitable for form api.
|
| 351 |
foreach ($states_lookup[$realm] as $state) {
|
| 352 |
$options[$state['csid']] = $state['name'];
|
| 353 |
} return $options;
|
| 354 |
}
|
| 355 |
}
|
| 356 |
|
| 357 |
/**
|
| 358 |
* Saves a case state.
|
| 359 |
*
|
| 360 |
* @param $case_state
|
| 361 |
* An array containing 'name' and 'realm' keys. If no 'csid'
|
| 362 |
* is passed, a new state is created, otherwise, we'll update
|
| 363 |
* the record that corresponds to that ID.
|
| 364 |
*/
|
| 365 |
function casetracker_case_state_save($case_state = NULL) {
|
| 366 |
if (!$case_state['name'] || !$case_state['realm']) { return NULL; }
|
| 367 |
$result = isset($case_state['csid']) // @todo we should probably do some error checking on the result and return it.
|
| 368 |
? db_query("UPDATE {casetracker_case_states} SET case_state_name = '%s', case_state_realm = '%s' WHERE csid = %d", $case_state['name'], $case_state['realm'], $case_state['csid'])
|
| 369 |
: db_query("INSERT INTO {casetracker_case_states} SET case_state_name = '%s', case_state_realm = '%s'", $case_state['name'], $case_state['realm']);
|
| 370 |
}
|
| 371 |
|
| 372 |
/**
|
| 373 |
* Displays a form for adding or editing a case state.
|
| 374 |
*/
|
| 375 |
function casetracker_case_state_edit($csid = NULL) {
|
| 376 |
$case_state = isset($csid) ? casetracker_case_state_load(NULL, $csid) : NULL;
|
| 377 |
|
| 378 |
$form = array();
|
| 379 |
$form['case_state'] = array(
|
| 380 |
'#type' => 'fieldset',
|
| 381 |
'#title' => t('Case state'),
|
| 382 |
'#collapsible' => TRUE,
|
| 383 |
'#collapsed' => FALSE,
|
| 384 |
);
|
| 385 |
$form['case_state']['name'] = array(
|
| 386 |
'#type' => 'textfield',
|
| 387 |
'#title' => t('State name'),
|
| 388 |
'#required' => TRUE,
|
| 389 |
'#default_value' => isset($case_state) ? $case_state['name'] : NULL,
|
| 390 |
'#description' => t('The name for this case state. Example: "Resolved".'),
|
| 391 |
);
|
| 392 |
$form['case_state']['realm'] = array(
|
| 393 |
'#type' => 'select',
|
| 394 |
'#title' => t('State realm'),
|
| 395 |
'#required' => TRUE,
|
| 396 |
'#default_value' => isset($case_state) ? $case_state['realm'] : NULL,
|
| 397 |
'#description' => t('The realm in which this case state will appear.'),
|
| 398 |
'#options' => array('priority' => t('priority'), 'status' => t('status'), 'type' => t('type')),
|
| 399 |
);
|
| 400 |
|
| 401 |
if ($case_state) { $form['csid'] = array('#type' => 'hidden', '#default_value' => $csid, ); }
|
| 402 |
$form['submit'] = array('#type' => 'submit', '#value' => t('Submit')); // this text is an easter egg.
|
| 403 |
|
| 404 |
return $form;
|
| 405 |
}
|
| 406 |
|
| 407 |
/**
|
| 408 |
* Processes the submitted results of our case state addition or editing.
|
| 409 |
*/
|
| 410 |
function casetracker_case_state_edit_submit($form_id, $form_values) {
|
| 411 |
$case_state = array('name' => $form_values['name'], 'realm' => $form_values['realm']);
|
| 412 |
$case_state['csid'] = $form_values['csid'] ? $form_values['csid'] : NULL; // add or edit, eh?
|
| 413 |
drupal_set_message(t('The case state %name has been updated.', array('%name' => $form_values['name'])));
|
| 414 |
casetracker_case_state_save($case_state);
|
| 415 |
return 'admin/content/casetracker';
|
| 416 |
}
|
| 417 |
|
| 418 |
/**
|
| 419 |
* If the user has asked to delete a case state, we'll double-check.
|
| 420 |
*/
|
| 421 |
function casetracker_case_state_confirm_delete($csid = NULL) {
|
| 422 |
$case_state = casetracker_case_state_load(NULL, $csid);
|
| 423 |
$form['csid'] = array('#type' => 'hidden', '#default_value' => $csid, );
|
| 424 |
$form['name'] = array('#type' => 'hidden', '#default_value' => $case_state['name'], );
|
| 425 |
return confirm_form($form, // NP: 'Eruyt Village' from 'Final Fantasy XII: Original Soundtrack Limited Edition'.
|
| 426 |
t('Are you sure you want to delete the case state %name?', array('%name' => $case_state['name'])),
|
| 427 |
'admin/content/casetracker', t('This action can not be undone.'), t('Delete'), t('Cancel'));
|
| 428 |
}
|
| 429 |
|
| 430 |
/**
|
| 431 |
* Ayup, the user definitely wants to delete this case state.
|
| 432 |
*/
|
| 433 |
function casetracker_case_state_confirm_delete_submit($form_id, $form_values) {
|
| 434 |
drupal_set_message(t('Deleted case state %name.', array('%name' => $form_values['name'])));
|
| 435 |
casetracker_case_state_delete($form_values['csid']);
|
| 436 |
return 'admin/content/casetracker';
|
| 437 |
}
|
| 438 |
|
| 439 |
/**
|
| 440 |
* Menu callback; displays a list of all cases in a table.
|
| 441 |
* See the README.txt for the various URLs we support.
|
| 442 |
*
|
| 443 |
* The "design" behind $project_filters and $case_filters has been inspired
|
| 444 |
* by the search.module, and we hope to eventually use this function as a
|
| 445 |
* frontend to that feature, once we actually recode it over again.
|
| 446 |
*
|
| 447 |
* @param $project_filters
|
| 448 |
* Whether 'all' or only 'my' (current user) project cases are shown.
|
| 449 |
* Any numbers passed are considered project node IDs. Multiple filters
|
| 450 |
* can be passed through by space-separating them.
|
| 451 |
* @param $case_filters
|
| 452 |
* 'all', 'my', or 'assigned' cases from the project filter and/or
|
| 453 |
* various keyed filters that are explained in the README.txt.
|
| 454 |
*/
|
| 455 |
function casetracker_cases_overview($project_filters = 'all', $case_filters = 'all') {
|
| 456 |
drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('Case Tracker'), 'casetracker'), l(t('All cases'), 'casetracker/cases')));
|
| 457 |
drupal_add_css(drupal_get_path('module', 'casetracker') .'/casetracker.css');
|
| 458 |
|
| 459 |
$output = NULL;
|
| 460 |
$headers = array(
|
| 461 |
array('data' => t('#'), 'field' => 'cc.case_number'),
|
| 462 |
array('data' => t('Title'), 'field' => 'n.title'),
|
| 463 |
array('data' => t('Last updated'), 'field' => 'ncs.last_comment_timestamp', 'sort' => 'desc'),
|
| 464 |
array('data' => t('Priority'), 'field' => 'cc.case_priority_id'),
|
| 465 |
array('data' => t('Status'), 'field' => 'cc.case_status_id'),
|
| 466 |
array('data' => t('Type'), 'field' => 'cc.case_type_id'),
|
| 467 |
array('data' => t('Assigned to'), 'field' => 'cc.assign_to')
|
| 468 |
);
|
| 469 |
|
| 470 |
// ah, the joys of filtering data based upon URL arguments. we try to base
|
| 471 |
// everything around one "master" SQL query, and add in filterable WHERE
|
| 472 |
// clauses ($case_filter_sql) and arguments ($case_filter_args) when needed.
|
| 473 |
global $user; // I DON'T LIKE HOW YOU MAKE ME FEEL! PLEASE STOP IT! AAHHhHHHHHHh!
|
| 474 |
$case_filter_args = strpos($case_filters, 'type') !== FALSE ? array() : array_filter(variable_get('casetracker_case_node_types', array('casetracker_basic_case')));
|
| 475 |
$case_filter_sql = strpos($case_filters, 'type') !== FALSE ? NULL : array('n.type IN ('.str_pad('', count(array_filter(variable_get('casetracker_case_node_types', array('casetracker_basic_case')))) * 5 - 1, "'%s',").')');
|
| 476 |
$case_filter_explanation = array(); // human readable explanation of filters.
|
| 477 |
|
| 478 |
// first up is the project_filter. see README.txt about URLs.
|
| 479 |
// rather simple here - just "all", "my", and/or project nid(s).
|
| 480 |
if (strpos('all', $project_filters) === FALSE) { // no filtering on 'all'
|
| 481 |
$project_filter_nids = array(); // merged into case_filter_args and _sql.
|
| 482 |
$project_filter_parts = preg_split('/\s+/', $project_filters);
|
| 483 |
foreach ($project_filter_parts as $project_filter) {
|
| 484 |
if ($project_filter == 'my') {
|
| 485 |
$project_filter_args = array_filter(variable_get('casetracker_project_node_types', array('casetracker_basic_project'))); $project_filter_args[] = $user->uid;
|
| 486 |
$results = db_query('SELECT n.nid FROM {node} n LEFT JOIN {casetracker_project} cp ON (n.vid = cp.vid) WHERE n.type IN ('.str_pad('', count(array_filter(variable_get('casetracker_project_node_types', array('casetracker_basic_project')))) * 5 - 1, "'%s',").') AND n.uid = %d AND n.status = 1', $project_filter_args);
|
| 487 |
while ($result = db_fetch_object($results)) { $project_filter_nids[] = $result->nid; }
|
| 488 |
$case_filter_explanation[] = t('my projects');
|
| 489 |
}
|
| 490 |
else { // probably project node ID(s).
|
| 491 |
$project_filter_values = explode(',', $project_filter);
|
| 492 |
foreach ($project_filter_values as $project_filter_value) {
|
| 493 |
if (!is_numeric($project_filter_value)) { continue; }
|
| 494 |
$project_filter_nids[] = $project_filter_value;
|
| 495 |
$case_filter_explanation[] = t('project %title', array('%title' =>
|
| 496 |
db_result(db_query('SELECT title FROM {node} n WHERE n.nid = %d', $project_filter_value))));
|
| 497 |
}
|
| 498 |
}
|
| 499 |
} // project filtering is finished, so merge into mastah...
|
| 500 |
if (count($project_filter_nids) >= 1) { // ... but only if values.
|
| 501 |
$case_filter_args = array_merge($case_filter_args, $project_filter_nids);
|
| 502 |
$case_filter_sql[] = 'cc.pid IN ('.str_pad('', count($project_filter_nids) * 5 - 1, "'%s',").')';
|
| 503 |
}
|
| 504 |
} else { $case_filter_explanation[] = t('all projects'); }
|
| 505 |
|
| 506 |
// determine the projects part of the page title based on our criteria.
|
| 507 |
$title_project_filters = t('filtered projects'); // just a generic default if we can't think of anything better.
|
| 508 |
if (is_numeric($project_filters)) { $title_project_filters = db_result(db_query('SELECT title FROM {node} n WHERE n.nid = %d', $project_filters)); }
|
| 509 |
elseif ($project_filters == 'all' || $project_filters == 'my') { $title_project_filters = t('!project_filters projects', array('!project_filters' => $project_filters)); }
|
| 510 |
|
| 511 |
// case filters are up next - we support keyed and unkeyed filters
|
| 512 |
// here, so have to loop a few more times to get it right and uber.
|
| 513 |
// EXAMPLE: "type:casetracker_basic_case my author:4"
|
| 514 |
// UNKEYED FILTERS: all, my, assigned
|
| 515 |
// KEYED FILTERS: assigned author state type
|
| 516 |
if (strpos($case_filters, 'all') === FALSE) { // no filtering on 'all'.
|
| 517 |
$case_filter_parts = preg_split('/\s+/', $case_filters); asort($case_filter_parts);
|
| 518 |
|
| 519 |
foreach ($case_filter_parts as $case_filter_part) {
|
| 520 |
$case_filter = explode(':', $case_filter_part);
|
| 521 |
|
| 522 |
// if value exists, this is a keyed filter
|
| 523 |
// like state:15,16 or similar. README.txt.
|
| 524 |
if ($case_filter[1]) {
|
| 525 |
$case_filter_values = explode(',', $case_filter[1]);
|
| 526 |
|
| 527 |
if ($case_filter[0] == 'assigned') {
|
| 528 |
$assigned_uids = array(); // numbers from input only.
|
| 529 |
foreach ($case_filter_values as $case_filter_value) {
|
| 530 |
if (!is_numeric($case_filter_value)) { continue; }
|
| 531 |
$assigned_uids[] = $case_filter_value;
|
| 532 |
$case_filter_args[] = $case_filter_value;
|
| 533 |
$case_filter_explanation[] = t('assigned to %user', array('%user' =>
|
| 534 |
db_result(db_query('SELECT name FROM {users} u WHERE u.uid = %d', $case_filter_value))));
|
| 535 |
} // we do this out here with assigned_uids to make sure they're all numeric.
|
| 536 |
$case_filter_sql[] = 'cc.assign_to IN ('.str_pad('', count($assigned_uids) * 5 - 1, "'%s',").')';
|
| 537 |
}
|
| 538 |
|
| 539 |
if ($case_filter[0] == 'author') {
|
| 540 |
$author_uids = array(); // numbers from input only.
|
| 541 |
foreach ($case_filter_values as $case_filter_value) {
|
| 542 |
if (!is_numeric($case_filter_value)) { continue; }
|
| 543 |
$author_uids[] = $case_filter_value;
|
| 544 |
$case_filter_args[] = $case_filter_value;
|
| 545 |
$case_filter_explanation[] = t('created by %user', array('%user' =>
|
| 546 |
db_result(db_query('SELECT name FROM {users} u WHERE u.uid = %d', $case_filter_value))));
|
| 547 |
} // we do this out here with author_uids to make sure they're all numeric.
|
| 548 |
$case_filter_sql[] = 'n.uid IN ('.str_pad('', count($author_uids) * 5 - 1, "'%s',").')';
|
| 549 |
}
|
| 550 |
|
| 551 |
// what follows is an edge case where the more sensible thing is to OR the queries,
|
| 552 |
// not AND. it's more useful to find (all items by a certain uid OR assigned to a
|
| 553 |
// certain uid) as opposed to (all items by a certain uid AND assigned to a certain
|
| 554 |
// uid). we'll sniff for these sorts of requests and mutilate our SQL array to OR
|
| 555 |
// instead of AND. A similar edge case is required for "my" and "assigned" in the
|
| 556 |
// unkeyed filters below. NOTE: we check against "author" first so that we know
|
| 557 |
// we've processed all relevant (and alphabetically stored) case filters.
|
| 558 |
if ($case_filter[0] == 'author' && strpos($case_filters, 'author:') !== FALSE && strpos($case_filters, 'assigned:') !== FALSE) {
|
| 559 |
$sql_2 = array_pop($case_filter_sql); $sql_1 = array_pop($case_filter_sql);
|
| 560 |
$case_filter_sql[] = '('.$sql_1.' OR '.$sql_2.')'; // and make a new one.
|
| 561 |
}
|
| 562 |
|
| 563 |
if ($case_filter[0] == 'state') {
|
| 564 |
$state_ids_by_realm = array();
|
| 565 |
$state_sql = array(); $state_args = array();
|
| 566 |
foreach ($case_filter_values as $case_filter_value) {
|
| 567 |
if (!is_numeric($case_filter_value)) { continue; }
|
| 568 |
$state = casetracker_case_state_load(NULL, $case_filter_value);
|
| 569 |
$state_ids_by_realm[$state['realm']][] = $case_filter_value;
|
| 570 |
$case_filter_explanation[] = t('case %realm %name', array('%realm' => $state['realm'], '%name' => $state['name']));
|
| 571 |
} // turn our IDs into a happy OR query. laborious.
|
| 572 |
foreach ($state_ids_by_realm as $realm => $state_ids) {
|
| 573 |
$state_sql[] = 'cc.case_'.$realm.'_id IN ('.str_pad('', count($state_ids) * 5 - 1, "'%s',").')';
|
| 574 |
$state_args = array_merge($state_args, $state_ids);
|
| 575 |
} // and finally add them to our master query, so...
|
| 576 |
if ($state_sql) { // make sure there's something there.
|
| 577 |
$case_filter_sql[] = '('.implode(' AND ', $state_sql).')';
|
| 578 |
$case_filter_args = array_merge($case_filter_args, $state_args);
|
| 579 |
}
|
| 580 |
}
|
| 581 |
|
| 582 |
if ($case_filter[0] == 'type') {
|
| 583 |
$valid_node_types = array();
|
| 584 |
$all_node_types = node_get_types('names'); // for human readable names.
|
| 585 |
$supported_node_types = array_filter(variable_get('casetracker_case_node_types', array('casetracker_basic_case')));
|
| 586 |
foreach ($case_filter_values as $case_filter_value) {
|
| 587 |
if (isset($supported_node_types[$case_filter_value])) {
|
| 588 |
$valid_node_types[] = $case_filter_value;
|
| 589 |
$case_filter_args[] = $case_filter_value;
|
| 590 |
$case_filter_explanation[] = t('node type %type', array('%type' => $all_node_types[$case_filter_value]));
|
| 591 |
} // we only want to search through node types that are valid casetracker case value-adds.
|
| 592 |
} $case_filter_sql[] = 'n.type IN ('.str_pad('', count($valid_node_types) * 5 - 1, "'%s',").')';
|
| 593 |
}
|
| 594 |
}
|
| 595 |
else { // unkeyed, currently only my or assigned.
|
| 596 |
$case_filter_values = explode(',', $case_filter[0]);
|
| 597 |
foreach ($case_filter_values as $case_filter_value) {
|
| 598 |
if ($case_filter_value == 'assigned') {
|
| 599 |
$case_filter_args[] = $user->uid;
|
| 600 |
$case_filter_sql[] = 'cc.assign_to = %d';
|
| 601 |
$case_filter_explanation[] = t('my assigned cases');
|
| 602 |
}
|
| 603 |
|
| 604 |
if ($case_filter_value == 'my') {
|
| 605 |
$case_filter_args[] = $user->uid;
|
| 606 |
$case_filter_sql[] = 'n.uid = %d';
|
| 607 |
$case_filter_explanation[] = t('my opened cases');
|
| 608 |
}
|
| 609 |
|
| 610 |
// see the discussion about edge cases above under key filters. we can use the
|
| 611 |
// in_array here instead of strpos since unkeyed filters are their own index.
|
| 612 |
if ($case_filter_value == 'my' && in_array('assigned', $case_filter_parts) && in_array('my', $case_filter_parts)) {
|
| 613 |
$sql_2 = array_pop($case_filter_sql); $sql_1 = array_pop($case_filter_sql);
|
| 614 |
$case_filter_sql[] = '('.$sql_1.' OR '.$sql_2.')'; // and make a new one.
|
| 615 |
}
|
| 616 |
}
|
| 617 |
}
|
| 618 |
}
|
| 619 |
} else { $case_filter_explanation[] = t('all cases'); }
|
| 620 |
|
| 621 |
// determine the cases part of the page title.
|
| 622 |
$title_case_filters = t('filtered cases'); // a generic default.
|
| 623 |
if ($case_filters == 'all') { $title_case_filters = t('all cases'); }
|
| 624 |
elseif ($case_filters == 'my') { $title_case_filters = t('my opened cases'); }
|
| 625 |
elseif ($case_filters == 'assigned') { $title_case_filters = t('my assigned cases'); }
|
| 626 |
|
| 627 |
// and set the page title now that all filteres are handled.
|
| 628 |
drupal_set_title(t('%case_filter in %project_filter', array('%case_filter' => $title_case_filters, '%project_filter' => $title_project_filters)));
|
| 629 |
|
| 630 |
// now, with our filter arguments out of the way, actually run the query and go nutty.
|
| 631 |
$case_filter_sql = count($case_filter_sql) ? 'AND '.implode(' AND ', $case_filter_sql) : NULL; // make a final string of WHERE clauses.
|
| 632 |
$sql = db_rewrite_sql('SELECT n.nid, n.title, ncs.last_comment_timestamp, cc.case_number, cc.case_priority_id, cc.case_status_id, cc.case_type_id, cc.assign_to, cp.project_number FROM {node} n LEFT JOIN {casetracker_case} cc ON (n.vid = cc.vid) LEFT JOIN {casetracker_project} cp ON (cp.nid = cc.pid) LEFT JOIN {node_comment_statistics} ncs ON (n.nid = ncs.nid) WHERE n.status = 1 '.$case_filter_sql);
|
| 633 |
$results = pager_query($sql . tablesort_sql($headers), 15, 0, NULL, $case_filter_args);
|
| 634 |
$rows = array(); while ($result = db_fetch_object($results)) {
|
| 635 |
$state_classes = ''; $state_links = array();
|
| 636 |
foreach (array('priority', 'status', 'type') as $state) {
|
| 637 |
$state_classes .= $state.'-'.preg_replace('/[^\w\-]/', '-', drupal_strtolower(casetracker_case_state_load($state, $result->{'case_'.$state.'_id'}))).' ';
|
| 638 |
$state_links[$state] = strpos($case_filters, 'state') !== FALSE ? str_replace('state:', 'state:'.$result->{'case_'.$state.'_id'}.',', $case_filters) : $case_filters .' state:'.$result->{'case_'.$state.'_id'};
|
| 639 |
$state_links[$state] = "casetracker/cases/$project_filters/".str_replace('all ', '', $state_links[$state]);
|
| 640 |
} $state_classes = rtrim($state_classes); // pedant: remove final space from the classes.
|
| 641 |
$rows[] = array('data' => array(
|
| 642 |
array('data' => $result->project_number.'-'.$result->case_number, 'class' => 'case-number'),
|
| 643 |
array('data' => l($result->title, 'node/'.$result->nid), 'class' => 'title'),
|
| 644 |
array('data' => format_date($result->last_comment_timestamp, 'small'), 'class' => 'last-updated'),
|
| 645 |
array('data' => l(casetracker_case_state_load('priority', $result->case_priority_id), $state_links['priority']), 'class' => 'priority'),
|
| 646 |
array('data' => l(casetracker_case_state_load('status', $result->case_status_id), $state_links['status']), 'class' => 'status'),
|
| 647 |
array('data' => l(casetracker_case_state_load('type', $result->case_type_id), $state_links['type']), 'class' => 'type'),
|
| 648 |
array('data' => theme('username', user_load(array('uid' => $result->assign_to))), 'class' => 'assign-to'),
|
| 649 |
), 'class' => $state_classes);
|
| 650 |
} if (count($rows) == 0) { $rows[] = array(array('data' => t('No cases found.'), 'colspan' => 7)); }
|
| 651 |
|
| 652 |
// turn the filter explanations into a comma-spliced list for human readout. we use a filter
|
| 653 |
// criteria AND a page title, because sometimes the criteria is too big to fit nicely into both.
|
| 654 |
$output .= '<div id="case-filter-criteria"><span class="case-filter-title">'.t('Case filter criteria:').'</span> ';
|
| 655 |
if (count($case_filter_explanation) < 1) { $output .= t("Do you think you're being naughty?"); }
|
| 656 |
else { $output .= implode(', ', $case_filter_explanation).'.'; } $output .= '</div>';
|
| 657 |
|
| 658 |
$output .= theme('table', $headers, $rows, array('id' => 'casetracker-cases-overview'));
|
| 659 |
$output .= theme('pager', NULL, 15, 0);
|
| 660 |
return $output;
|
| 661 |
}
|
| 662 |
|
| 663 |
/**
|
| 664 |
* Menu callback; displays a list of all projects in a table.
|
| 665 |
* See the README.txt for the various URLs we support.
|
| 666 |
*
|
| 667 |
* @param $project_filter
|
| 668 |
* Whether 'all' or only 'my' (current user) projects are shown.
|
| 669 |
*/
|
| 670 |
function casetracker_projects_overview($project_filter = 'all') {
|
| 671 |
drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('Case Tracker'), 'casetracker'), l(t('All projects'), 'casetracker/projects')));
|
| 672 |
|
| 673 |
// we'll count how many node types can be cases so that we know how many
|
| 674 |
// columns our Operations will span. array_filter will, in the absence of a
|
| 675 |
// callback, return only indexes whose values do not evaluate to FALSE.
|
| 676 |
$case_types = array_filter(variable_get('casetracker_case_node_types', array('casetracker_basic_case')));
|
| 677 |
$colspan_count = count($case_types) + 1; // one more for the 'view all cases' link.
|
| 678 |
|
| 679 |
$headers = array(
|
| 680 |
array('data' => t('#'), 'field' => 'cp.project_number'),
|
| 681 |
array('data' => t('Title'), 'field' => 'n.title', 'sort' => 'asc'),
|
| 682 |
array('data' => t('Operations'), 'colspan' => $colspan_count),
|
| 683 |
);
|
| 684 |
|
| 685 |
$filter_sql = NULL;
|
| 686 |
$filter_args = array_filter(variable_get('casetracker_project_node_types', array('casetracker_basic_project')));
|
| 687 |
if ($project_filter == 'my') { global $user; $filter_sql = 'AND n.uid = %d'; $filter_args[] = $user->uid; }
|
| 688 |
$sql = db_rewrite_sql('SELECT n.nid, n.title, cp.project_number FROM {node} n LEFT JOIN {casetracker_project} cp ON (n.vid = cp.vid) WHERE n.type IN ('.str_pad('', count(array_filter(variable_get('casetracker_project_node_types', array('casetracker_basic_project')))) * 5 - 1, "'%s',").') AND n.status = 1 '.$filter_sql);
|
| 689 |
$results = pager_query($sql . tablesort_sql($headers), 15, 0, NULL, $filter_args);
|
| 690 |
|
| 691 |
$node_types = node_get_types('names');
|
| 692 |
$rows = array(); while ($result = db_fetch_object($results)) {
|
| 693 |
$operations = array(array('data' => l(t('view cases'), 'casetracker/cases/'.$result->nid.'/all'), 'class' => 'operation'));
|
| 694 |
foreach ($case_types as $case_type) { $operations[] = array('data' => l(t('add !name', array('!name' => $node_types[$case_type])), 'node/add/'.$case_type.'/'.$result->nid), 'class' => 'operation'); }
|
| 695 |
$rows[] = array_merge(array(array('data' => $result->project_number, 'class' => 'project-number'), array('data' => l($result->title, 'node/'.$result->nid), 'class' => 'title')), $operations);
|
| 696 |
} if (count($rows) == 0) { $rows[] = array(array('data' => t('No projects found.'), 'colspan' => 3 + $colspan_count)); }
|
| 697 |
|
| 698 |
// set a sensible page title.
|
| 699 |
if ($project_filter == 'all') { drupal_set_title(t('all projects')); }
|
| 700 |
if ($project_filter == 'my') { drupal_set_title(t('my projects')); }
|
| 701 |
|
| 702 |
$output .= theme('table', $headers, $rows, array('id' => 'casetracker-projects-overview'));
|
| 703 |
$output .= theme('pager', NULL, 15, 0);
|
| 704 |
return $output;
|
| 705 |
}
|
| 706 |
|
| 707 |
/**
|
| 708 |
* Theme the case summary shown at the beginning of a case's node.
|
| 709 |
*
|
| 710 |
* @param $case
|
| 711 |
* The node object of the case being viewed.
|
| 712 |
* @param $project
|
| 713 |
* The node object of the project this case belongs to.
|
| 714 |
*/
|
| 715 |
function theme_casetracker_case_summary($case, $project) {
|
| 716 |
$rows = array();
|
| 717 |
$rows[] = array(t('Case number:'), $project->project_number.'-'.$case->case_number);
|
| 718 |
$rows[] = array(t('Project:'), l($project->title, 'node/'.$case->pid));
|
| 719 |
$rows[] = array(t('Opened by:'), theme('username', $case));
|
| 720 |
$rows[] = array(t('Status:'), casetracker_case_state_load('status', $case->case_status_id));
|
| 721 |
$rows[] = array(t('Assigned:'), theme('username', user_load(array('uid' => $case->assign_to))));
|
| 722 |
$rows[] = array(t('Priority:'), casetracker_case_state_load('priority', $case->case_priority_id));
|
| 723 |
$rows[] = array(t('Type:'), casetracker_case_state_load('type', $case->case_type_id));
|
| 724 |
$rows[] = array(t('Opened on:'), format_date($case->created, 'large'));
|
| 725 |
|
| 726 |
$last_comment = db_result(db_query('SELECT last_comment_timestamp FROM {node_comment_statistics} WHERE nid = %d', $case->nid));
|
| 727 |
$rows[] = array(t('Last modified:'), format_date($last_comment, 'large')); // @bug fails if comments are disabled.
|
| 728 |
|
| 729 |
$output = '<div class="case">';
|
| 730 |
$output .= theme('table', NULL, $rows, array('class' => 'summary'));
|
| 731 |
$output .= '</div>';
|
| 732 |
return $output;
|
| 733 |
}
|
| 734 |
|
| 735 |
/**
|
| 736 |
* Theme the project summary shown at the beginning of a project's node.
|
| 737 |
*
|
| 738 |
* @param $project
|
| 739 |
* The node object of the project being viewed.
|
| 740 |
*/
|
| 741 |
function theme_casetracker_project_summary($project) {
|
| 742 |
$rows = array();
|
| 743 |
$rows[] = array(t('Project number:'), $project->project_number);
|
| 744 |
$rows[] = array(t('Opened by:'), theme('username', $project));
|
| 745 |
$rows[] = array(t('Opened on:'), format_date($project->created, 'large'));
|
| 746 |
$rows[] = array(t('Last modified:'), format_date($project->changed, 'large'));
|
| 747 |
|
| 748 |
$operations = array(); $node_types = node_get_types('names');
|
| 749 |
foreach (array_filter(variable_get('casetracker_case_node_types', array('casetracker_basic_case'))) as $type) {
|
| 750 |
$operations[] = l(t('add !name', array('!name' => $node_types[$type])), 'node/add/'.$type.'/'.$project->nid);
|
| 751 |
} $operations = implode(' | ', $operations); // ready for printing in our Operations table cell - delimited by a pipe. nonstandard.
|
| 752 |
$rows[] = array(t('Operations:'), $operations.' | '.l(t('view all project cases'), 'casetracker/cases/'.$project->nid.'/all'));
|
| 753 |
|
| 754 |
$output = '<div class="project">';
|
| 755 |
$output .= theme('table', NULL, $rows, array('class' => 'summary'));
|
| 756 |
$output .= '</div>';
|
| 757 |
return $output;
|
| 758 |
}
|
| 759 |
|
| 760 |
/**
|
| 761 |
* Implementation of hook_block().
|
| 762 |
*/
|
| 763 |
function casetracker_block($op = 'list', $delta = 0, $edit = array()) {
|
| 764 |
if ($op == 'list') {
|
| 765 |
$block = array();
|
| 766 |
$block[0]['info'] = t('Jump to case number');
|
| 767 |
$block[1]['info'] = t('Latest cases');
|
| 768 |
return $block;
|
| 769 |
}
|
| 770 |
else if ($op == 'configure' && $delta == 1) {
|
| 771 |
$form['casetracker_block_latest_cases_count'] = array(
|
| 772 |
'#type' => 'select',
|
| 773 |
'#title' => t('Number of latest cases'),
|
| 774 |
'#default_value' => variable_get('casetracker_block_latest_cases_count', 5),
|
| 775 |
'#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)),
|
| 776 |
);
|
| 777 |
return $form;
|
| 778 |
}
|
| 779 |
else if ($op == 'save' && $delta == 1) {
|
| 780 |
variable_set('casetracker_block_latest_cases_count', $edit['casetracker_block_latest_cases_count']);
|
| 781 |
}
|
| 782 |
else if ($op == 'view') {
|
| 783 |
$block = array();
|
| 784 |
switch ($delta) {
|
| 785 |
case 0:
|
| 786 |
if (user_access('access case tracker')) {
|
| 787 |
drupal_add_css(drupal_get_path('module', 'casetracker') .'/casetracker.css');
|
| 788 |
$block['content'] = drupal_get_form('casetracker_block_jump_to_case_number');
|
| 789 |
$block['subject'] = t('Jump to case number');
|
| 790 |
return $block;
|
| 791 |
} break;
|
| 792 |
case 1:
|
| 793 |
$results = db_query_range(db_rewrite_sql("SELECT n.*, cs.* FROM {node} n INNER JOIN {casetracker_case} cs ON (n.vid = cs.vid) WHERE n.status = 1 ORDER BY n.created DESC"), 0, variable_get('casetracker_block_latest_cases_count', 5));
|
| 794 |
$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.
|
| 795 |
$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));
|
| 796 |
$cases[] = array('case' => $case_result, 'project' => $project_result);
|
| 797 |
}
|
| 798 |
$block['subject'] = t('Latest cases');
|
| 799 |
$block['content'] = theme('casetracker_block_latest_cases', $cases);
|
| 800 |
return $block;
|
| 801 |
}
|
| 802 |
}
|
| 803 |
}
|
| 804 |
|
| 805 |
/**
|
| 806 |
* Form builder for "Jump to case number" block.
|
| 807 |
*/
|
| 808 |
function casetracker_block_jump_to_case_number() {
|
| 809 |
$form = array();
|
| 810 |
$form['case_number'] = array(
|
| 811 |
'#maxlength' => 60, // class makes it all one line.
|
| 812 |
'#prefix' => '<div class="container-inline">',
|
| 813 |
'#required' => TRUE,
|
| 814 |
'#size' => 15,
|
| 815 |
'#title' => t('Case number'),
|
| 816 |
'#type' => 'textfield',
|
| 817 |
);
|
| 818 |
$form['submit'] = array(
|
| 819 |
'#suffix' => '</div>',
|
| 820 |
'#type' => 'submit',
|
| 821 |
'#value' => t('Go'),
|
| 822 |
);
|
| 823 |
return $form;
|
| 824 |
}
|
| 825 |
|
| 826 |
/**
|
| 827 |
* Submit function for our "Jump to case number" block.
|
| 828 |
*/
|
| 829 |
function casetracker_block_jump_to_case_number_submit($form_id, $form_values) {
|
| 830 |
$case_parts = explode('-', $form_values['case_number']);
|
| 831 |
$result = db_fetch_object(db_query("SELECT cc.nid FROM {casetracker_case} cc LEFT JOIN {casetracker_project} cp ON (cc.pid = cp.nid) WHERE cp.project_number = %d AND cc.case_number = %d", $case_parts[0], $case_parts[1]));
|
| 832 |
if (!$result->nid) { drupal_set_message(t('Your case number was not found.'), 'error'); return NULL; }
|
| 833 |
return 'node/'.$result->nid;
|
| 834 |
}
|
| 835 |
|
| 836 |
/**
|
| 837 |
* Theme the "Latest cases" block.
|
| 838 |
*
|
| 839 |
* @param $cases
|
| 840 |
* An array of arrays containing 'case' and 'project'
|
| 841 |
* objects of the latest cases and info to be displayed.
|
| 842 |
*/
|
| 843 |
function theme_casetracker_block_latest_cases($cases) {
|
| 844 |
$item_list = array();
|
| 845 |
foreach ($cases as $case) {
|
| 846 |
$case_link = l('['.$case['project']->project_number.'-'.$case['case']->case_number.'] '.$case['case']->title, 'node/'.$case['case']->nid);
|
| 847 |
$project_link = '('.l($case['project']->title, 'node/'.$case['project']->nid).')';
|
| 848 |
$item_list[] = $case_link.' '.$project_link;
|
| 849 |
} // spit only if spittle.
|
| 850 |
if (count($item_list) > 0) {
|
| 851 |
return theme('item_list', $item_list);
|
| 852 |
}
|
| 853 |
}
|
| 854 |
|
| 855 |
/**
|
| 856 |
* Implementation of hook_comment().
|
| 857 |
*/
|
| 858 |
function casetracker_comment(&$comment, $op) {
|
| 859 |
$case_data = array(); // stores old and new values for comparison.
|
| 860 |
$case_fields = array('case_priority_id', 'case_type_id', 'case_status_id', 'assign_to');
|
| 861 |
|
| 862 |
if ($op == 'insert' || $op == 'update') {
|
| 863 |
$node = node_load($comment['nid']); // only care about nodes on insert and update.
|
| 864 |
if (!in_array($node->type, variable_get('casetracker_case_node_types', array('casetracker_basic_case')), TRUE)) {
|
| 865 |
return; // if this isn't a casetracker case node type, return without sullying our beautiful code. BEAUTY!
|
| 866 |
} // this will also short circuit the other insert/updates in our switch below.
|
| 867 |
// note: we're using 'prid' here for our project ID because the comment forms
|
| 868 |
// already use 'pid' to represent the parent comment of a reply. be friendly!
|
| 869 |
$case_data['old']->prid = $node->pid;
|
| 870 |
$case_data['new']->prid = $comment['prid'];
|
| 871 |
|
| 872 |
foreach ($case_fields as $case_field) {
|
| 873 |
$case_data['old']->$case_field = $node->$case_field;
|
| 874 |
$case_data['new']->$case_field = $comment[$case_field];
|
| 875 |
if ($case_field == 'assign_to') { $case_data['new']->assign_to = casetracker_get_uid($comment['assign_to']); }
|
| 876 |
} $case_data['old']->case_title = $node->title; $case_data['new']->case_title = $comment['case_title'];
|
| 877 |
db_query("UPDATE {node} SET title = '%s' WHERE nid = %d AND vid = %d", $case_data['new']->case_title, $comment['nid'], $comment['revision_id']);
|
| 878 |
db_query("UPDATE {node_revisions} SET title = '%s' WHERE nid = %d AND vid = %d", $case_data['new']->case_title, $comment['nid'], $comment['revision_id']);
|
| 879 |
db_query("UPDATE {casetracker_case} SET assign_to = %d, case_status_id = %d, case_priority_id = %d, case_type_id = %d, pid = %d WHERE nid = %d AND vid = %d ", $case_data['new']->assign_to, $case_data['new']->case_status_id, $case_data['new']->case_priority_id, $case_data['new']->case_type_id, $case_data['new']->prid, $comment['nid'], $comment['revision_id']);
|
| 880 |
}
|
| 881 |
|
| 882 |
switch($op) {
|
| 883 |
case 'insert':
|
| 884 |
db_query("INSERT INTO {casetracker_comment_status} (cid, pid, assign_to, case_priority_id, case_type_id, case_status_id, state, title) VALUES (%d, %d, '%d', %d, %d, '%d', %d, '%s')", $comment['cid'], $case_data['old']->prid, $case_data['old']->assign_to, $case_data['old']->case_priority_id, $case_data['old']->case_type_id, $case_data['old']->case_status_id, 0, $case_data['old']->case_title);
|
| 885 |
db_query("INSERT INTO {casetracker_comment_status} (cid, pid, assign_to, case_priority_id, case_type_id, case_status_id, state, title) VALUES (%d, %d, '%d', %d, %d, '%d', %d, '%s')", $comment['cid'], $case_data['new']->prid, $case_data['new']->assign_to, $case_data['new']->case_priority_id, $case_data['new']->case_type_id, $case_data['new']->case_status_id, 1, $case_data['new']->case_title);
|
| 886 |
break;
|
| 887 |
case 'update':
|
| 888 |
db_query("UPDATE {casetracker_comment_status} SET pid = %d, assign_to = %d, case_priority_id = %d, case_type_id = %d, case_status_id = %d, title = '%s' WHERE cid = %d AND state = %d", $case_data['old']->prid, $case_data['old']->assign_to, $case_data['old']->case_priority_id, $case_data['old']->case_type_id, $case_data['old']->case_status_id, $case_data['old']->case_title, $comment['cid'], 0);
|
| 889 |
db_query("UPDATE {casetracker_comment_status} SET pid = %d, assign_to = %d, case_priority_id = %d, case_type_id = %d, case_status_id = %d, title = '%s' WHERE cid = %d AND state = %d", $case_data['new']->prid, $case_data['new']->assign_to, $case_data['new']->case_priority_id, $case_data['new']->case_type_id, $case_data['new']->case_status_id, $case_data['new']->case_title, $comment['cid'], 1);
|
| 890 |
break;
|
| 891 |
case 'delete':
|
| 892 |
// @todo theoretically, if you delete a comment, we should reset all the values
|
| 893 |
// to what they were before the comment was submitted. this doesn't happen yet.
|
| 894 |
db_query("DELETE FROM {casetracker_comment_status} WHERE cid = %d", $comment->cid);
|
| 895 |
break;
|
| 896 |
case 'view':
|
| 897 |
$node = node_load($comment->nid); // only care about nodes that are casetracker related.
|
| 898 |
if (in_array($node->type, variable_get('casetracker_case_node_types', array('casetracker_basic_case')), TRUE)) {
|
| 899 |
$results = db_query("SELECT * FROM {casetracker_comment_status} WHERE cid = %d", $comment->cid); // hoo-hah. HOO-HAHAHAH!
|
| 900 |
while ($result = db_fetch_object($results)) { $state = $result->state ? 'new' : 'old'; $case_data[$state] = $result; }
|
| 901 |
$comment->comment = casetracker_comment_changes($case_data) . $comment->comment;
|
| 902 |
}
|
| 903 |
break;
|
| 904 |
}
|
| 905 |
}
|
| 906 |
|
| 907 |
/**
|
| 908 |
* Displays the changes a comment has made to the case fields.
|
| 909 |
*
|
| 910 |
* @param $case_data
|
| 911 |
* An array of both 'old' and 'new' objects that contains
|
| 912 |
* the before and after values this comment has changed.
|
| 913 |
*/
|
| 914 |
function casetracker_comment_changes($case_data) {
|
| 915 |
$rows = array();
|
| 916 |
|
| 917 |
if ($case_data['new']->pid != $case_data['old']->pid) {
|
| 918 |
$old_project_title = db_result(db_query("SELECT title FROM {node} WHERE nid = %d", $case_data['old']->pid));
|
| 919 |
$new_project_title = db_result(db_query("SELECT title FROM {node} WHERE nid = %d", $case_data['new']->pid));
|
| 920 |
$rows[] = array(t('Project:'), $old_project_title.' '.t('»').' '.$new_project_title);
|
| 921 |
}
|
| 922 |
|
| 923 |
if ($case_data['new']->title != $case_data['old']->title) {
|
| 924 |
$rows[] = array(t('Title:'), $case_data['old']->title.' '.t('»').' '.$case_data['new']->title);
|
| 925 |
}
|
| 926 |
|
| 927 |
if ($case_data['new']->case_status_id != $case_data['old']->case_status_id) {
|
| 928 |
$rows[] = array(t('Status:'), casetracker_case_state_load('status', $case_data['old']->case_status_id).' '.t('»').' '.casetracker_case_state_load('status', $case_data['new']->case_status_id));
|
| 929 |
}
|
| 930 |
|
| 931 |
if ($case_data['new']->assign_to != $case_data['old']->assign_to) {
|
| 932 |
$rows[] = array(t('Assigned:'), theme('username', user_load(array('uid' => $case_data['old']->assign_to))).' '.t('»').' '.theme('username', user_load(array('uid' => $case_data['new']->assign_to))));
|
| 933 |
}
|
| 934 |
|
| 935 |
if ($case_data['new']->case_priority_id != $case_data['old']->case_priority_id) {
|
| 936 |
$rows[] = array(t('Priority:'), casetracker_case_state_load('priority', $case_data['old']->case_priority_id).' '.t('»').' '.casetracker_case_state_load('priority', $case_data['new']->case_priority_id));
|
| 937 |
}
|
| 938 |
|
| 939 |
if ($case_data['new']->case_type_id != $case_data['old']->case_type_id) {
|
| 940 |
$rows[] = array(t('Type:'), casetracker_case_state_load('type', $case_data['old']->case_type_id).' '.t('»').' '.casetracker_case_state_load('type', $case_data['new']->case_type_id));
|
| 941 |
}
|
| 942 |
|
| 943 |
return theme('table', NULL, $rows, array('class' => 'case_changes'));
|
| 944 |
}
|
| 945 |
|
| 946 |
/**
|
| 947 |
* Implementation of hook_form_alter().
|
| 948 |
*/
|
| 949 |
function casetracker_form_alter($form_id, &$form) {
|
| 950 |
$node = isset($form['nid']['#value']) ? node_load($form['nid']['#value']) : NULL;
|
| 951 |
|
| 952 |
// add case options to our basic case type.
|
| 953 |
if (in_array(str_replace('_node_form', '', $form_id), variable_get('casetracker_case_node_types', array('casetracker_basic_case')), TRUE)) {
|
| 954 |
$count = db_result(db_query(db_rewrite_sql("SELECT COUNT(*) AS count FROM {node} n WHERE n.type IN (".str_pad('', count(array_filter(variable_get('casetracker_project_node_types', array('casetracker_basic_project')))) * 5 - 1, "'%s',").")"), array_filter(variable_get('casetracker_project_node_types', array('casetracker_basic_project')))));
|
| 955 |
if ($count == 0) { drupal_set_message(t('You must create a project before adding cases.'), 'error'); return; } // we can't make a link to a project here because the admin may have assigned more than one node type as project usable.
|
| 956 |
$form = casetracker_case_form_common($form, arg(3)); // proceed as normal with modifications.
|
| 957 |
}
|
| 958 |
|
| 959 |
// add case options to the comment form.
|
| 960 |
if ($form_id == 'comment_form' && in_array($node->type, variable_get('casetracker_case_node_types', array('casetracker_basic_case')), TRUE)) {
|
| 961 |
$form = casetracker_case_form_common($form);
|
| 962 |
$form['casetracker_case_information']['case_title'] = array(
|
| 963 |
'#type' => 'textfield',
|
| 964 |
'#title' => t('Title'),
|
| 965 |
'#required' => TRUE,
|
| 966 |
'#weight' => -10,
|
| 967 |
'#default_value' => isset($node->title) ? $node->title : NULL,
|
| 968 |
'#prefix' => '<div id="comment-case-title">',
|
| 969 |
'#suffix' => '</div>', // escapes the inlining.
|
| 970 |
);
|
| 971 |
|
| 972 |
// we use 'pid' for a project ID, but the comment form uses 'pid' for
|
| 973 |
// the parent comment (in a reply). we'll change ours to 'prid'. sigh.
|
| 974 |
$form['casetracker_project_information']['prid'] = $form['casetracker_project_information']['pid'];
|
| 975 |
unset($form['casetracker_project_information']['pid']); // cater to this in casetracker_comment().
|
| 976 |
|
| 977 |
// necessary for our casetracker_comment() callback.
|
| 978 |
$form['nid'] = array('#type' => 'hidden', '#value' => $node->nid, );
|
| 979 |
$form['case_number'] = array('#type' => 'hidden', '#value' => $node->case_number, );
|
| 980 |
$form['revision_id'] = array('#type' => 'hidden', '#value' => $node->vid, );
|
| 981 |
}
|
| 982 |
}
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
/**
|
| 988 |
* Retrieve a pipe delimited string of autocomplete suggestions for existing
|
| 989 |
* users. Stolen from user_autocomplete. Eventually this will be expanded to
|
| 990 |
* include OG specific users subscribed to a project.
|
| 991 |
*/
|
| 992 |
function casetracker_autocomplete($string) {
|
| 993 |
$matches = array();
|
| 994 |
$result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER('%s%%')", $string, 0, 10);
|
| 995 |
while ($user = db_fetch_object($result)) {
|
| 996 |
$matches[$user->name] = check_plain($user->name);
|
| 997 |
}
|
| 998 |
print drupal_to_js($matches);
|
| 999 |
exit();
|
| 1000 |
}
|
| 1001 |
|
| 1002 |
/**
|
| 1003 |
* Given a uid, returns the name of that account. If the passed uid is
|
| 1004 |
* 0, we'll skip the database lookup and return the anonymous user name.
|
| 1005 |
* See also casetracker_get_uid().
|
| 1006 |
*/
|
| 1007 |
function casetracker_get_name($uid) {
|
| 1008 |
return ($uid != 0)
|
| 1009 |
? db_result(db_query("SELECT name FROM {users} WHERE uid = %d", $uid))
|
| 1010 |
: variable_get('anonymous', t('Anonymous'));
|
| 1011 |
}
|
| 1012 |
|
| 1013 |
/**
|
| 1014 |
* Given a user name, returns the uid of that account.
|
| 1015 |
* If the passed name is not found, returns 0.
|
| 1016 |
* See also casetracker_get_name().
|
| 1017 |
*/
|
| 1018 |
function casetracker_get_uid($name = NULL) {
|
| 1019 |
$uid = db_result(db_query("SELECT uid FROM {users} WHERE name = '%s'", $name));
|
| 1020 |
return $uid ? $uid : 0;
|
| 1021 |
}
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
/**
|
| 1026 |
* Configures the various Community Managed Taxonomy options; system_settings_form().
|
| 1027 |
*/
|
| 1028 |
function cmt_settings() {
|
| 1029 |
$form = array();
|
| 1030 |
|
| 1031 |
$form['cmt_general'] = array(
|
| 1032 |
'#type' => 'fieldset',
|
| 1033 |
'#title' => t('General settings'),
|
| 1034 |
'#collapsible' => TRUE,
|
| 1035 |
'#collapsed' => FALSE,
|
| 1036 |
);
|
| 1037 |
$form['casetracker_general']['casetracker_default_assign_to'] = array(
|
| 1038 |
'#type' => 'textfield',
|
| 1039 |
'#title' => t('Default assigned user'),
|
| 1040 |
'#autocomplete_path' => 'casetracker/autocomplete',
|
| 1041 |
'#required' => TRUE,
|
| 1042 |
'#default_value' => variable_get('casetracker_default_assign_to', variable_get('anonymous', t('Anonymous'))),
|
| 1043 |
'#description' => t('This user will be prefilled in the "Assign To" field on case creation.'),
|
| 1044 |
);
|
| 1045 |
|
| 1046 |
|
| 1047 |
$node_types = node_get_types('names');
|
| 1048 |
|
| 1049 |
$project_types = $node_types; unset($project_types['casetracker_basic_case']);
|
| 1050 |
$form['casetracker_general']['casetracker_project_node_types'] = array(
|
| 1051 |
'#type' => 'checkboxes',
|
| 1052 |
'#title' => t('Project node types'),
|
| 1053 |
'#options' => $project_types,
|
| 1054 |
'#default_value' => variable_get('casetracker_project_node_types', array('casetracker_basic_project')),
|
| 1055 |
'#description' => t('Select the node types to be Case Tracker projects. If there are existing nodes of this type, you must edit and resave them.'),
|
| 1056 |
);
|
| 1057 |
|
| 1058 |
return system_settings_form($form);
|
| 1059 |
}
|
| 1060 |
|
| 1061 |
|
| 1062 |
|