You are here

function pmtimetracking_node_presave in Drupal PM (Project Management) 7.2

Same name and namespace in other branches
  1. 8 pmtimetracking/pmtimetracking.module \pmtimetracking_node_presave()
  2. 7.3 pmtimetracking/pmtimetracking.module \pmtimetracking_node_presave()

Implements hook_node_presave().

File

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

Code

function pmtimetracking_node_presave($node) {

  // Only act on pmtimetracking nodes.
  if ($node->type == 'pmtimetracking') {

    // Set duration based on start and end times.
    if ((bool) variable_get('pmtimetracking_auto_duration', TRUE)) {
      $start_datetime = strtotime($node->pm_date[LANGUAGE_NONE][0]['value']);
      $end_datetime = strtotime($node->pm_date[LANGUAGE_NONE][0]['value2']);
      $duration_seconds = $end_datetime - $start_datetime;
      $duration_hours = $duration_seconds / (60 * 60);
      $node->pm_duration[LANGUAGE_NONE][0]['value'] = $duration_hours;
      $node->pm_durationunit[LANGUAGE_NONE][0]['value'] = 'hour';
    }

    // Set billing duration based on duration.
    if ((bool) variable_get('pmtimetracking_auto_billing_duration', TRUE)) {
      $node->pm_billing_duration[LANGUAGE_NONE][0]['value'] = $node->pm_duration[LANGUAGE_NONE][0]['value'];
    }
  }
}