function _pm_number_of_items in Drupal PM (Project Management) 7
Helper function to count nodes of type destination module with parent nid of type source module.
Parameters
string $source_module: A string of module where the request is coming from
string $destination_module: A string with name of targeted module
int $nid: Node id of source module
Return value
''|int empty string if can't be counted or the count of destination nodes in source node
See also
1 call to _pm_number_of_items()
- theme_pm_link in ./
pm.theme.inc - Provides HTML for a Project Management link.
File
- ./
pm.module, line 1061 - Main module file for the Project Management module.
Code
function _pm_number_of_items($source_module, $destination_module, $nid) {
global $user;
$nmb_of_items = '';
$valid_destination_modules = array();
switch ($source_module) {
case "pmorganization":
$column_name = 'organization_nid';
$valid_destination_modules = array(
'pmproject',
'pmtask',
'pmticket',
'pmtimetracking',
'pmnote',
'pmperson',
'pmexpense',
'pminvoice',
);
break;
case "pmproject":
$column_name = 'project_nid';
$valid_destination_modules = array(
'pmtask',
'pmticket',
'pmtimetracking',
'pmnote',
'pmexpense',
'pminvoice',
);
break;
case "pmtask":
$column_name = 'task_nid';
$valid_destination_modules = array(
'pmticket',
'pmtimetracking',
'pmnote',
'pmexpense',
);
break;
case "pmticket":
$column_name = 'ticket_nid';
$valid_destination_modules = array(
'pmtimetracking',
'pmexpense',
);
break;
}
if (in_array($destination_module, $valid_destination_modules)) {
switch ($destination_module) {
case 'pmproject':
$sql = "SELECT COUNT(*) FROM {node} AS n INNER JOIN {pmproject} AS spr ON n.vid=spr.vid WHERE n.status=1 AND\n n.type='pmproject' and spr." . $column_name . " = %d";
break;
case 'pmtask':
$sql = "SELECT COUNT(*) FROM {node} AS n INNER JOIN {pmtask} AS sta ON n.vid=sta.vid WHERE n.status=1 AND\n n.type='pmtask' and sta." . $column_name . " = %d";
break;
case 'pmticket':
$sql = "SELECT COUNT(*) FROM {node} AS n INNER JOIN {pmticket} AS sti ON n.vid=sti.vid WHERE n.status=1 AND\n n.type='pmticket' and sti." . $column_name . " = %d";
break;
case 'pmtimetracking':
$sql = "SELECT COUNT(*) FROM {node} AS n INNER JOIN {pmtimetracking} AS stt ON n.vid=stt.vid WHERE n.status=1 AND\n n.type='pmtimetracking' and stt." . $column_name . " = %d";
break;
case 'pmperson':
$sql = "SELECT COUNT(*) FROM {node} AS n INNER JOIN {pmperson} AS spe ON n.vid=spe.vid WHERE n.status=1 AND\n n.type='pmperson' and spe." . $column_name . " = %d";
break;
case 'pmnote':
$sql = "SELECT COUNT(*) FROM {node} AS n INNER JOIN {pmnote} AS sno ON n.vid=sno.vid WHERE n.status=1 AND\n n.type='pmnote' and sno." . $column_name . " = %d";
break;
case 'pmexpense':
$sql = "SELECT COUNT(*) FROM {node} AS n INNER JOIN {pmexpense} AS sex ON n.vid=sex.vid WHERE n.status=1 AND\n n.type='pmexpense' and sex." . $column_name . " = %d";
break;
case 'pminvoice':
$sql = "SELECT COUNT(*) FROM {node} AS n INNER JOIN {pminvoice} AS sin ON n.vid=sin.vid WHERE n.status=1 AND\n n.type='pminvoice' and sin." . $column_name . " = %d";
break;
}
// @todo Convert to DBTNG
// ->addTag('node_access')
$nmb_of_items = db_result(db_query($sql, $nid));
}
return $nmb_of_items;
}