diff --git a/master/casetracker/casetracker.module b/master/casetracker/casetracker.module index 884de51..9a11a92 100755 --- a/master/casetracker/casetracker.module +++ b/master/casetracker/casetracker.module @@ -130,7 +130,7 @@ function casetracker_menu() { function casetracker_node_delete($node) { if (casetracker_is_case($node->type)) { // delete case and its comments. - $comment_results = db_select('comments', 'c') + $comment_results = db_select('comment', 'c') ->fields('c', array('cid')) ->condition('c.nid', $node->nid) ->execute(); @@ -152,7 +152,7 @@ function casetracker_node_delete($node) { db_delete('casetracker_case') ->condition('nid', $case_result->nid) ->execute(); - $comment_results = db_select('comments', 'c') + $comment_results = db_select('comment', 'c') ->fields('c', array('cid')) ->condition('c.nid', $case_result->nid) ->execute(); @@ -201,9 +201,11 @@ function casetracker_node_load($nodes, $types) { ->fields('c', array('pid', 'case_priority_id', 'case_type_id', 'assign_to', 'case_status_id')) ->condition('c.nid', $node->nid) ->condition('c.vid', $node->vid) - ->execute(); + ->execute() + ->fetchObject(); if ($casetracker) { - return array('casetracker' => $casetracker); + $nodes[$node->nid]->casetracker = $casetracker; + //return array('casetracker' => $casetracker); } } } @@ -213,13 +215,14 @@ function casetracker_node_load($nodes, $types) { * Implements hook_node_update(). */ function casetracker_node_update($node) { + //dpm($node); if (casetracker_is_case($node->type)) { $record = (object) $node->casetracker; $record->assign_to = is_numeric($record->assign_to) ? $record->assign_to : casetracker_get_uid($record->assign_to); $record->nid = $node->nid; $record->vid = $node->vid; - $primary = $node->revision ? array('nid') : array('nid', 'vid'); + $primary = (isset($node->revision) && $node->revision) ? array('nid') : array('nid', 'vid'); drupal_write_record('casetracker_case', $record, $primary); } } @@ -229,6 +232,7 @@ function casetracker_node_update($node) { */ function casetracker_node_view($node, $view_mode, $langcode) { if (casetracker_is_case($node->type)) { + ////dpm($node->casetracker); // On preview the case will be an array, we want an object. if (isset($node->build_mode) && $node->build_mode == NODE_BUILD_PREVIEW) { $node->casetracker = (object) $node->casetracker; @@ -276,24 +280,25 @@ function casetracker_node_view($node, $view_mode, $langcode) { * Implements hook_comment_insert(). */ function casetracker_comment_insert($comment) { - // Load the node here anyway -- it is almost certainly static cached already. - $node = is_array($comment) ? node_load($comment['nid']) : node_load($comment->nid); + // Load the node here -- it is almost certainly static cached already. + $node = is_array($comment) ? node_load($comment['nid']) : node_load($comment->nid); + //dpm($node->casetracker); // Bail if this is not a casetracker node. if (!casetracker_is_case($node->type)) { return; } - $new = (object) $comment['casetracker']; - $new->cid = $comment['cid']; - $new->nid = $comment['nid']; - $new->vid = $comment['revision_id']; + $new = (object) $comment->casetracker; + $new->cid = $comment->cid; + $new->nid = $comment->nid; + $new->vid = $comment->revision_id; $new->state = 1; $new->assign_to = casetracker_get_uid($new->assign_to); // Populate old state values from node $old = $node->casetracker; - $old->cid = $comment['cid']; + $old->cid = $comment->cid; $old->state = 0; drupal_write_record('casetracker_case', $new, array('nid', 'vid')); @@ -314,16 +319,16 @@ function casetracker_comment_update($comment) { return; } - $new = (object) $comment['casetracker']; - $new->cid = $comment['cid']; - $new->nid = $comment['nid']; - $new->vid = $comment['revision_id']; + $new = (object) $comment->casetracker; + $new->cid = $comment->cid; + $new->nid = $comment->nid; + $new->vid = $comment->revision_id; $new->state = 1; $new->assign_to = casetracker_get_uid($new->assign_to); // Populate old state values from node $old = $node->casetracker; - $old->cid = $comment['cid']; + $old->cid = $comment->cid; $old->state = 0; drupal_write_record('casetracker_case', $new, array('nid', 'vid')); @@ -372,7 +377,7 @@ function casetracker_comment_view($comment) { } else { $results = db_select('casetracker_comment_status', 'c') - ->fields('c', array('cid')) + ->fields('c', array('cid', 'pid', 'title', 'case_status_id', 'assign_to', 'case_priority_id', 'case_type_id', 'state')) ->condition('c.cid', $comment->cid) ->execute(); foreach ($results as $result) { @@ -380,7 +385,8 @@ function casetracker_comment_view($comment) { $case_data[$state] = $result; } } - $comment->comment = theme('casetracker_comment_changes', array('old' => $case_data['old'], 'new' => $case_data['new'] . $comment->comment)); + //dpm($comment); + $comment->content['comment_body'][0]['#markup'] = theme('casetracker_comment_changes', array('old' => $case_data['old'], 'new' => $case_data['new'])) . $comment->content['comment_body'][0]['#markup']; } /** @@ -873,10 +879,18 @@ function _casetracker_get_og_query_string(&$project) { */ function casetracker_theme() { return array( - 'casetracker_comment_changes' => array(), - 'casetracker_case_form_common' => array(), - 'casetracker_case_summary' => array(), - 'casetracker_project_summary' => array(), + 'casetracker_comment_changes' => array( + 'variables' => array('old' => NULL, 'new' => NULL), + ), + 'casetracker_case_form_common' => array( + 'render element' => 'form', + ), + 'casetracker_case_summary' => array( + 'variables' => array('case' => NULL, 'project' => NULL), + ), + 'casetracker_project_summary' => array( + 'variables' => array('project' => NULL), + ), ); } @@ -887,7 +901,9 @@ function casetracker_theme() { * An array of both 'old' and 'new' objects that contains * the before and after values this comment has changed. */ -function theme_casetracker_comment_changes($old, $new) { +function theme_casetracker_comment_changes($variables) { + $old = $variables['old']; + $new = $variables['new']; $rows = array(); $fields = array( @@ -946,7 +962,8 @@ function theme_casetracker_comment_changes($old, $new) { * Theme function for cleaning up the casetracker common form. */ function theme_casetracker_case_form_common($form) { - $form = $form[null]; + //dpm($form); + $form = $form['form']; drupal_add_css(drupal_get_path('module', 'casetracker') . '/casetracker.css'); $output = ''; @@ -983,7 +1000,7 @@ function theme_casetracker_case_form_common($form) { $rows = array($row); //$output .= theme('table', array(), $rows); $output .= theme('table', array('header' => array(), 'rows' => $rows)); -dpm($form); +////dpm($form); // TODO commenting the bellow line removes possible infinite // recursion/iteration on add case form. WHY? //$output .= drupal_render($form); @@ -998,12 +1015,13 @@ dpm($form); * @param $project * The node object of the project this case belongs to. */ -function theme_casetracker_case_summary($case, $project) { - $project = $project[null]['#project']; - $case = $case[null]['#project']; +function theme_casetracker_case_summary($variables) { +//print_r($variables); + $project = $variables['project']; + $case = $variables['case']; -dpm($project); -dpm($case); +//print_r($project); +//print_r($case); $last_comment = db_select('node_comment_statistics', 'n') ->fields('n', array('last_comment_timestamp')) @@ -1015,10 +1033,10 @@ dpm($case); // On node preview the form logic can't translate assign_to back to a uid for // us so we need to be able handle it either way. if (is_numeric($case->casetracker->assign_to)) { - $assign_to = user_load(array('uid' => $case->casetracker->assign_to)); + $assign_to = user_load($case->casetracker->assign_to); } else { - $assign_to = user_load(array('name' => $case->casetracker->assign_to)); + $assign_to = reset(user_load_multiple(array(), array('name' => $case->casetracker->assign_to))); } if (empty($assign_to) || $assign_to->uid == 0) { @@ -1074,8 +1092,8 @@ dpm($case); * @param $project * The node object of the project being viewed. */ -function theme_casetracker_project_summary($project) { - $project = $project[null]['#project']; +function theme_casetracker_project_summary($variables) { + $project = $variables['project']; $rows = array(); $rows[] = array(t('Project number:'), $project->nid); @@ -1094,14 +1112,14 @@ function theme_casetracker_project_summary($project) { ); } $operations = implode(' | ', $operations); // ready for printing in our Operations table cell - delimited by a pipe. nonstandard. -//dpm(t('view all project cases'), 'casetracker', array('query' => 'keys=&pid=' . $project->nid)); +////dpm(t('view all project cases'), 'casetracker', array('query' => 'keys=&pid=' . $project->nid)); $rows[] = array(t('Operations:'), $operations . ' | ' . l(t('view all project cases'), 'casetracker', array('query' => array('destination' => 'keys=&pid=' . $project->nid)))); $output = '
'; $output .= theme('table', array('header' => NULL, 'rows' => $rows, 'attributes' => array('class' => 'summary'))); //$output .= theme('table', NULL, $rows, array('class' => 'summary')); $output .= '
'; -//dpm($output); +////dpm($output); return $output; } @@ -1124,7 +1142,7 @@ function casetracker_project_options() { //$projects[$row->nid] = $row->node_title; $projects[1] = $row->node_title; } -dpm($view); +//dpm($view); } return $projects; } @@ -1142,7 +1160,7 @@ function casetracker_user_options() { foreach ($view->result as $row) { $options[$row->uid] = $row->users_name; } -dpm($view); +//dpm($view); } $anon_user = casetracker_default_assign_to(); @@ -1170,7 +1188,7 @@ function casetracker_is_case($node) { else if (is_string($node)) { $type = $node; } - if ($type) { + if (isset($type)) { return in_array($type, variable_get('casetracker_case_node_types', array('casetracker_basic_case')), TRUE); } return FALSE; @@ -1186,7 +1204,7 @@ function casetracker_is_project($node) { else if (is_string($node)) { $type = $node; } - if ($type) { + if (isset($type)) { return in_array($type, variable_get('casetracker_project_node_types', array('casetracker_basic_project')), TRUE); } return FALSE; @@ -1248,9 +1266,9 @@ function casetracker_default_assign_to() { /** * Implements hook_token_values(). */ -function casetracker_tokens($type, $object = NULL) { +function casetracker_tokens($type, $tokens, array $data = array(), array $options = array()) { module_load_include('inc', 'casetracker', 'casetracker.token'); - return _casetracker_tokens($type, $object); + return _casetracker_tokens($type, $data); } /** diff --git a/master/casetracker/casetracker.token.inc b/master/casetracker/casetracker.token.inc index d06787c..39608dc 100755 --- a/master/casetracker/casetracker.token.inc +++ b/master/casetracker/casetracker.token.inc @@ -11,7 +11,8 @@ */ function _casetracker_tokens($type, $object = NULL) { $values = array(); - if (($type == 'node') && (casetracker_is_case($object))) { + if (($type == 'node') && (casetracker_is_case($object['node']->type))) { + $object = $object['node']; $values['case_status'] = casetracker_case_state_load($object->casetracker->case_status_id, 'status'); $values['case_type'] = casetracker_case_state_load($object->casetracker->case_type_id, 'type'); $values['case_priority'] = casetracker_case_state_load($object->casetracker->case_priority_id, 'priority'); diff --git a/master/casetracker/casetracker.views_default.inc b/master/casetracker/casetracker.views_default.inc index e24dc8e..55c2d64 100755 --- a/master/casetracker/casetracker.views_default.inc +++ b/master/casetracker/casetracker.views_default.inc @@ -92,7 +92,7 @@ function _view_casetracker_project_options() { )); $handler->override_option('items_per_page', 0); -dpm($view); +//dpm($view); return $view; }