You are here

function pmproject_token_values in Drupal PM (Project Management) 7.2

Same name and namespace in other branches
  1. 8 pmproject/pmproject.module \pmproject_token_values()
  2. 7.3 pmproject/pmproject.module \pmproject_token_values()
  3. 7 pmproject/pmproject.module \pmproject_token_values()

Implements hook_token_values().

File

pmproject/pmproject.module, line 120
Main module file for the PM Project module.

Code

function pmproject_token_values($type, $object = NULL) {
  $values = array();
  $node = $object;
  if (($type == 'node' || $type == 'all') && $node->type === 'pmproject') {
    $values['pmproject-projectstatus'] = $node->projectstatus;
    $values['pmproject-projectpriority'] = $node->projectpriority;
    $values['pmproject-projectcategory'] = $node->projectcategory;
    $values['pmproject-durationunit'] = $node->durationunit;
    $values['pmproject-duration'] = $node->duration;
    $values['pmproject-price'] = $node->price;
    $values['pmproject-pricemode'] = $node->pricemode;
    if (module_exists('pmorganization')) {
      $values['pmproject-organization-nid'] = $node->organization_nid;
      $values['pmproject-organization-title'] = $node->organization_title;
    }
    if (module_exists('pmperson')) {

      // Project Manager.
      if ($node->manager_nid) {
        $manager = node_load($node->manager_nid);
        $values['pmproject-manager-uid'] = $manager->user_uid;
        $values['pmproject-manager-name'] = $manager->title;
        $values['pmproject-manager-fullname'] = $manager->fullname;
        $values['pmproject-manager-email'] = pmperson_primary_email($manager);
        $values['pmproject-manager-title'] = $node->manager_title;
      }
      else {
        $values['pmproject-manager-email'] = NULL;
      }

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

        // Assigned to one person.
        if ($assignees_node->type === 'pmperson') {
          $values['pmproject-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['pmproject-assigned-to-email'] = $assigned;
        }
      }
      else {
        $values['pmproject-assigned-to-email'] = NULL;
      }
    }
  }
  return $values;
}