You are here

function _pmtimetracking_beforesave in Drupal PM (Project Management) 7

Prepares pmtimetracking nodes for save operations.

2 calls to _pmtimetracking_beforesave()
pmtimetracking_insert in pmtimetracking/pmtimetracking.module
Implments hook_insert().
pmtimetracking_update in pmtimetracking/pmtimetracking.module
Implements hook_update().

File

pmtimetracking/pmtimetracking.module, line 525
Main module functions for PM Timetracking.

Code

function _pmtimetracking_beforesave(&$node) {

  // Set duration field based on start and end dates.
  $duration_in_seconds = strtotime($node->pm_date['und'][0]['value2']) - strtotime($node->pm_date['und'][0]['value']);

  // Convert to hours
  $node->duration = $duration_in_seconds / 60 / 60;
  if (variable_get('pmtimetracking_auto_duration', TRUE)) {
    $node->billing_duration = $node->duration;
  }
  $s = "SELECT n.title FROM {node} n INNER JOIN {pmorganization} o ON n.nid=o.nid WHERE type='pmorganization' AND n.nid=:oid";
  $r = db_query($s, array(
    ':oid' => $node->organization_nid,
  ));
  $o = $r
    ->fetchObject();
  $node->organization_title = $o->title;
  $s = "SELECT n.title, p.organization_title FROM {node} n INNER JOIN {pmproject} p ON n.nid=p.nid WHERE type='pmproject' AND n.nid=:pid";
  $r = db_query($s, array(
    ':pid' => $node->project_nid,
  ));
  $p = $r
    ->fetchObject();
  $node->project_title = isset($p->title) ? $p->title : '';
  $s = "SELECT title, stepno FROM {node} n INNER JOIN {pmtask} t ON n.nid=t.nid WHERE n.type='pmtask' AND n.nid=:tid";
  $r = db_query($s, array(
    ':tid' => $node->task_nid,
  ));
  $ta = $r
    ->fetchObject();
  $node->task_title = isset($ta->title) ? $ta->title : '';
  $node->task_stepno = isset($ta->stepno) ? $ta->stepno : '';
  $s = "SELECT title FROM {node} n INNER JOIN {pmticket} t ON n.nid=t.nid WHERE n.type='pmticket' AND n.nid=:tktid";
  $r = db_query($s, array(
    ':tktid' => $node->ticket_nid,
  ));
  $ti = $r
    ->fetchObject();
  $node->ticket_title = isset($ti->title) ? $ti->title : '';
}