pmproject.module in Drupal PM (Project Management) 7.3
Same filename and directory in other branches
Main module file for the PM Project module.
File
pmproject/pmproject.moduleView source
<?php
/**
* @file
* Main module file for the PM Project module.
*/
/**
* Implements hook_help().
*/
function pmproject_help($path, $arg) {
$o = '';
switch ($path) {
case "admin/help#pmproject":
$o = '<p>' . t("Provides project support for Project Management") . '</p>';
break;
}
return $o;
}
/**
* Implements hook_permission().
*/
function pmproject_permission() {
$name = 'Project Management Project';
return array(
"Project Management Project: access" => array(
'title' => t('Access %type_name.', array(
'%type_name' => $name,
)),
'description' => t('Allows the user to see pages and blocks associated with the %type_name, but does not control specific item that is shown within them.', array(
'%type_name' => $name,
)),
),
);
}
/**
* Implements hook_node_info().
*/
function pmproject_node_info() {
return array(
'pmproject' => array(
'name' => t('Project'),
'base' => 'pmproject',
'description' => t('Use <em>projects</em> for recording high level work requirements within <em>Project Management</em>.'),
'title_label' => t('Title'),
),
);
}
/**
* Implements hook_form().
*/
function pmproject_form(&$node, &$form_state) {
$breadcrumb = array(
array(
'text' => t('Projects'),
'path' => 'pm/projects',
),
);
pm_set_breadcrumb($breadcrumb);
return node_content_form($node, $form_state);
}
/**
* Implements hook_view().
*/
function pmproject_view($node, $view_mode) {
if ($view_mode == 'full' && node_is_page($node)) {
$breadcrumb = array(
array(
'text' => t('Projects'),
'path' => 'pm/projects',
),
);
pm_set_breadcrumb($breadcrumb);
}
return $node;
}
/**
* Implements hook_pm_contextual_links().
*/
function pmproject_pm_contextual_links($entity, $type, $view_mode, $langcode) {
$links = array();
list($id, $vid, $bundle) = entity_extract_ids($type, $entity);
if ($type == 'node') {
$field_info = field_info_field('pmproject_parent');
if (isset($field_info['settings']['handler_settings']['target_bundles'])) {
$target_bundles = $field_info['settings']['handler_settings']['target_bundles'];
}
else {
$target_bundles = array(
'pmorganization',
);
}
if (in_array($bundle, $target_bundles)) {
$links[t('Add Project')] = array(
'title' => t('Add Project'),
'href' => 'node/add/pmproject',
'query' => array(
'pmproject_parent' => $id,
),
);
}
}
return $links;
}
/**
* Implements hook_views_api().
*/
function pmproject_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'pmproject'),
);
}
/**
* Implements hook_token_list().
*/
function pmproject_token_list($type = 'all') {
$tokens = array();
if ($type == 'node' || $type == 'all') {
$tokens['node']['pmproject-projectstatus'] = t('Project Management Project: Project Status.');
$tokens['node']['pmproject-projectcategory'] = t('Project Management Project: Project Category.');
$tokens['node']['pmproject-projectpriority'] = t('Project Management Project: Project Priority.');
$tokens['node']['pmproject-durationunit'] = t('Project Management Project: Project Duration Unit.');
$tokens['node']['pmproject-duration'] = t('Project Management Project: Project Duration.');
$tokens['node']['pmproject-price'] = t('Project Management Project: Project Price.');
$tokens['node']['pmproject-pricemode'] = t('Project Management Project: Project Price Mode.');
if (module_exists('pmorganization')) {
$tokens['node']['pmproject-organization-nid'] = t('Project Management Project: Organization Node ID.');
$tokens['node']['pmproject-organization-title'] = t('Project Management Project: Organization Title.');
}
if (module_exists('pmperson')) {
// Project Manager.
$tokens['node']['pmproject-manager-title'] = t('Project Management Project: Project Manager Title.');
$tokens['node']['pmproject-manager-uid'] = t('Project Management Project: Project Manager User ID.');
$tokens['node']['pmproject-manager-name'] = t('Project Management Project: Project Manager Name.');
$tokens['node']['pmproject-manager-fullname'] = t('Project Management Project: Project Manager Full Name.');
$tokens['node']['pmproject-manager-email'] = t('Project Management Project: Project Manager Email Address.');
// Assignee(s).
$tokens['node']['pmproject-assigned-to-email'] = t('Project Management Project: Project Assignee(s) Email Address(s).');
$tokens['node']['pmproject-assigned-title'] = t('Project Management Project: Project Assignee(s) Title(s).');
}
}
return $tokens;
}
/**
* Implements hook_token_values().
*/
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;
}
/**
* Implements hook_pm_dashboard_links().
*/
function pmproject_pm_dashboard_links($type) {
$links = array();
if ($type == 'page' || $type == 'block') {
$links[] = array(
'theme' => 'pm_dashboard_link',
'title' => t('Projects'),
'icon' => 'pmprojects',
'path' => 'pm/projects',
'params' => array(),
'node_type' => 'pmproject',
'add_type' => 'pmproject',
'map' => array(),
'weight' => 4,
);
}
return $links;
}
/**
* @defgroup pmproject_index pmproject indexing
* @{
* Functions to maintain pmproject indexing.
*/
/**
* Implements hook_node_insert().
*/
function pmproject_node_insert($node) {
// Add pmproject index entries for the node.
pmproject_build_node_index($node);
}
/**
* Builds and inserts pmproject index entries for a given node.
*
* The index lists all terms that are related to a given node entity, and is
* therefore maintained at the entity level.
*
* @param object $node
* The node object.
*/
function pmproject_build_node_index($node) {
// We maintain a denormalized table of term/node relationships, containing
// only data for current, published nodes.
$status = NULL;
if (variable_get('pmproject_maintain_index_table', TRUE)) {
// If a node property is not set in the node object when node_save() is
// called, the old value from $node->original is used.
if (!empty($node->original)) {
$status = (int) (!empty($node->status) || !isset($node->status) && !empty($node->original->status));
}
else {
$status = (int) (!empty($node->status));
}
}
// We only maintain the pmproject index for published nodes.
if ($status) {
// Hunt for PM Organization.
$pmproject_nid = pm_permission_get_parent_nid_of_node($node, 'pmproject');
// Insert index entries for all the node's terms.
if (!empty($pmproject_nid)) {
$query = db_insert('pmproject_index')
->fields(array(
'nid',
'pmproject_nid',
'created',
));
$query
->values(array(
'nid' => $node->nid,
'pmproject_nid' => $pmproject_nid,
'created' => $node->created,
));
$query
->execute();
}
}
}
/**
* Implements hook_node_update().
*/
function pmproject_node_update($node) {
// Always rebuild the node's pmproject index entries on node save.
pmproject_delete_node_index($node);
pmproject_build_node_index($node);
}
/**
* Implements hook_node_delete().
*/
function pmproject_node_delete($node) {
// Clean up the {pmproject_index} table when nodes are deleted.
pmproject_delete_node_index($node);
if (variable_get('pmproject_maintain_index_table', TRUE) and $node->type == 'pmproject') {
// Clean up the {pmproject_index} table when pmproject are deleted.
db_delete('pmproject_index')
->condition('pmproject_nid', $node->nid)
->execute();
}
}
/**
* Deletes pmproject index entries for a given node.
*
* @param object $node
* The node object.
*/
function pmproject_delete_node_index($node) {
if (variable_get('pmproject_maintain_index_table', TRUE)) {
db_delete('pmproject_index')
->condition('nid', $node->nid)
->execute();
}
}
/**
* @} End of "defgroup pmproject_index".
*/
Functions
Name | Description |
---|---|
pmproject_build_node_index | Builds and inserts pmproject index entries for a given node. |
pmproject_delete_node_index | Deletes pmproject index entries for a given node. |
pmproject_form | Implements hook_form(). |
pmproject_help | Implements hook_help(). |
pmproject_node_delete | Implements hook_node_delete(). |
pmproject_node_info | Implements hook_node_info(). |
pmproject_node_insert | Implements hook_node_insert(). |
pmproject_node_update | Implements hook_node_update(). |
pmproject_permission | Implements hook_permission(). |
pmproject_pm_contextual_links | Implements hook_pm_contextual_links(). |
pmproject_pm_dashboard_links | Implements hook_pm_dashboard_links(). |
pmproject_token_list | Implements hook_token_list(). |
pmproject_token_values | Implements hook_token_values(). |
pmproject_view | Implements hook_view(). |
pmproject_views_api | Implements hook_views_api(). |