You are here

function _pmticket_beforesave in Drupal PM (Project Management) 7

Prepares pmticket for saving.

2 calls to _pmticket_beforesave()
pmticket_insert in pmticket/pmticket.module
Implements hook_insert().
pmticket_update in pmticket/pmticket.module
Implements hook_update().

File

pmticket/pmticket.module, line 578
1: Hooks 2: Access functions

Code

function _pmticket_beforesave(&$node) {
  $org_query = db_select('node', 'n');
  $org_query
    ->join('pmorganization', 'sor', 'n.vid = sor.vid');
  $org_result = $org_query
    ->fields('n', array(
    'title',
  ))
    ->condition('n.type', 'pmorganization')
    ->condition('n.nid', $node->organization_nid)
    ->execute();
  $o = $org_result
    ->fetchObject();
  $node->organization_title = $o->title;
  $pro_query = db_select('node', 'n');
  $pro_query
    ->join('pmproject', 'spr', 'n.vid = spr.vid');
  $pro_result = $pro_query
    ->fields('n', array(
    'title',
  ))
    ->condition('n.type', 'pmproject')
    ->condition('n.nid', $node->project_nid)
    ->execute();
  $p = $pro_result
    ->fetchObject();
  $node->project_title = isset($p->title) ? $p->title : '';
  $task_query = db_select('node', 'n');
  $task_query
    ->join('pmtask', 'sta', 'n.vid = sta.vid');
  $task_result = $task_query
    ->fields('n', array(
    'title',
  ))
    ->fields('sta', array(
    'stepno',
  ))
    ->condition('n.type', 'pmtask')
    ->condition('n.nid', $node->task_nid)
    ->execute();
  $ta = $task_result
    ->fetchObject();
  $node->task_title = isset($ta->title) ? $ta->title : '';
  $node->task_stepno = isset($ta->stepno) ? $ta->stepno : '';
  $assigned = node_load($node->assigned_nid);
  $node->assigned_title = isset($assigned->title) ? $assigned->title : '';

  // Allow use of comma when inputting numerical values - str_replace with period decimal
  $node->duration = str_replace(',', '.', $node->duration);
  $node->price = str_replace(',', '.', $node->price);
  if (!is_numeric($node->duration)) {
    $node->duration = 0;
  }
  if (!is_numeric($node->price)) {
    $node->price = 0;
  }
}