You are here

function pmticket_token_values in Drupal PM (Project Management) 7

Same name and namespace in other branches
  1. 8 pmticket/pmticket.module \pmticket_token_values()
  2. 7.3 pmticket/pmticket.module \pmticket_token_values()
  3. 7.2 pmticket/pmticket.module \pmticket_token_values()

Implements hook_token_values().

File

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

Code

function pmticket_token_values($type, $object = NULL) {
  $values = array();
  $node = $object;
  if (($type == 'node' || $type == 'all') && $node->type === 'pmticket') {
    $values['pmticket-organization-nid'] = $node->organization_nid;
    $values['pmticket-organization-title'] = $node->organization_title;
    $values['pmticket-project-nid'] = $node->project_nid;
    $values['pmticket-project-title'] = $node->project_title;
    $values['pmticket-ticketstatus'] = $node->ticketstatus;
    $values['pmticket-ticketpriority'] = $node->ticketpriority;
    $values['pmticket-ticketcategory'] = $node->ticketcategory;
    $values['pmticket-durationunit'] = $node->durationunit;
    $values['pmticket-duration'] = $node->duration;
    $values['pmticket-price'] = $node->price;
    $values['pmticket-pricemode'] = $node->pricemode;
    if (module_exists('pmperson')) {

      // Project Assignee(s) e-mail
      if ($node->assigned_nid) {
        $values['pmticket-assigned-title'] = $node->assigned_title;
        $assignees_node = node_load($node->assigned_nid);

        // Assigned to one person
        if ($assignees_node->type === 'pmperson') {
          $values['pmticket-assigned-to-email'] = pmperson_primary_email($assignees_node);
        }
        else {
          $assignees_array = $assignees_node->members_array;
          $assignees = array();
          foreach ($assignees_array as $nid => $name) {
            $assignee = node_load($nid);
            $assignees[] = pmperson_primary_email($assignee);
          }
          $assigned = implode(", ", $assignees);

          // Return comma separated list of emails
          $values['pmticket-assigned-to-email'] = $assigned;
        }
      }
      else {
        $values['pmticket-assigned-to-email'] = NULL;
      }
    }
  }
  return $values;
}