/** * return an array with current issues, followups and their attached files * matching the chosen set of projects, categories, priorities and states * If a criterium is not specified, all values are included for that criterium * Author Frederic G. MARAND * License GPL 2.0 */ function local_get_issues($us_arProjects = array(), $us_arCategories = array(), $us_arPriorities = array(), $us_arStates = array()) { // only numeric project ids $arProjects = array(); foreach ($us_arProjects as $us_project) { if (!is_numeric($us_project)) { continue; } $arProjects[] = $us_project; } $whereProjects = implode(',', $arProjects); // only numeric priorities $arPriorities = array(); foreach ($us_arPriorities as $us_priority) { if (!is_numeric($us_priority)) { continue; } $arPriorities[] = $us_priority; } $wherePriorities = implode(',', $arPriorities); // only categories actually used on the site $arValidCategories = array(); $sq = 'SELECT DISTINCT pi.category FROM {project_issues} pi '; $q = db_query($sq); while ($o = db_fetch_object($q)) { $arValidCategories[] = $o->category; } $arCategories = array(); foreach ($us_arCategories as $us_category) { if (!in_array($us_category, $arValidCategories)) { continue; } $arCategories[] = $us_category; } $whereCategories = implode(',', $arCategories); // only numeric states $arStates = array(); foreach ($us_arStates as $us_state) { if (!is_numeric($us_priority)) { continue; } $arStates[] = $us_state; } $whereStates = implode(',', $arStates); $sq = 'SELECT ' . ' pc.file_path, pc.file_mime, pc.file_size, ' . ' pc.body, pc.data, ' . ' pc.cid, ' . ' n.title AS n_title, ' . ' nr.body AS nr_body ' . 'FROM ' . ' {project_comments} pc ' . ' INNER JOIN {project_issues} pi ON pc.nid = pi.nid ' . ' INNER JOIN {project_projects} pp ON pi.pid = pp.nid ' . ' INNER JOIN {node} n ON pi.nid = n.nid ' . ' INNER JOIN {node_revisions} nr ON n.nid = nr.nid AND n.vid = nr.vid ' . 'WHERE TRUE '; $args = array(); if (!empty($whereProjects)) { $sq .= ' AND pp.pid IN (%s) '; $args[] = $whereProjects; } if (!empty($whereCategories)) { $sq .= ' AND pi.category IN (%s) '; $args[] = $whereCategories; } if (!empty($wherePriorities)) { $sq .= ' AND pi.priority IN (%s) '; $args[] = $wherePriorities; } if (!empty($whereStates)) { $sq .= ' AND pi.sid IN (%s) '; $args[] = $whereStates; } $ret = array(); $q = db_query($sq, $args); while ($o = db_fetch_object($q)) { $data = unserialize($o->data); unset($ o->data); $o->data = $data; if (!empty($o->file_path)) { $o->file_data = file_get_contents($o->file_path); } $ret[] = $o; } drupal_set_header('Content-type: application/json'); drupal_set_header ('Content-Disposition: attachement; filename= issues.js"'); echo json_encode($ret); exit();