/**
  * function to get artifacts in specified preference order
  *
  * 	@return null
  *
  */
 function getArtifactsInOrder()
 {
     $ar = new ArtifactReport($this->report_id, $this->atid);
     $ar->getResultQueryElements($this->prefs, $this->morder, $this->advsrch, $aids = false, &$select, &$from, &$where, &$order_by);
     //artifact permissions
     $sql_group_id = "SELECT group_id FROM artifact_group_list WHERE group_artifact_id=" . db_ei($this->atid);
     $result_group_id = db_query($sql_group_id);
     if (db_numrows($result_group_id) > 0) {
         $row = db_fetch_array($result_group_id);
         $group_id = $row['group_id'];
     }
     $user = UserManager::instance()->getCurrentUser();
     $ugroups = $user->getUgroups($group_id, array('artifact_type' => $this->atid));
     $from .= " LEFT JOIN permissions \n                         ON (permissions.object_id = CONVERT(a.artifact_id USING utf8)\n                             AND \n                             permissions.permission_type = 'TRACKER_ARTIFACT_ACCESS') ";
     $where .= " AND (a.use_artifact_permissions = 0\n                         OR \n                         (\n                             permissions.ugroup_id IN (" . implode(',', $ugroups) . ")\n                         )\n                   ) ";
     if ($order_by == "") {
         $sql = "SELECT DISTINCT art.artifact_id FROM (SELECT STRAIGHT_JOIN a.artifact_id {$from} {$where} {$order_by}) AS art";
     } else {
         $sql = "SELECT DISTINCT art.artifact_id FROM (SELECT STRAIGHT_JOIN a.artifact_id {$from} {$where} {$order_by},a.artifact_id ASC) AS art";
     }
     return $ar->_ExecuteQueryForSelectReportItems($sql);
 }
Ejemplo n.º 2
0
$dsc_list['is_dependent_on'] = $Language->getText('project_export_artifact_export', 'depend_on_list');
$dsc_list['cc'] = $Language->getText('project_export_artifact_export', 'add_cc_dsc');
// Add the 2 fields that we build ourselves for user convenience
// - All follow-up comments
// - Dependencies
// - CC List
$col_list[] = 'follow_ups';
$col_list[] = 'is_dependent_on';
$col_list[] = 'cc';
$eol = "\n";
// If user asked to export only displayed fields (fields displayed in the current report)
// The export is based on the arrays col_list and lbl_list, that contain the fields to export.
// Basically, these arrays contain all the fields of the tracker,
// so we simply remove the non-displayed fields from these arrays.
if ($request->get('only_displayed_fields') == 'on') {
    $artifact_report = new ArtifactReport($request->get('report_id'), $atid);
    $displayed_fields = $artifact_report->getResultFields();
    // array_intersect_key is a PHP 5 function (implemented here in src/www/include/utils.php)
    $col_list = array_intersect_key($col_list, $displayed_fields);
    $lbl_list = array_intersect_key($lbl_list, $displayed_fields);
}
//$sql = $export_select." ".$export_from." ".$export_where." AND a.artifact_id IN ($export_aids) group by a.artifact_id";
if ($multiple_queries) {
    $all_results = array();
    foreach ($all_queries as $q) {
        $result = db_query($q);
        $all_results[] = $result;
        $rows = db_numrows($result);
    }
} else {
    $result = db_query($sql);
Ejemplo n.º 3
0
 function getArtifactsFromReport($group_id, $group_artifact_id, $report_id, $criteria, $offset, $max_rows, $sort_criteria, &$total_artifacts)
 {
     global $ath, $art_field_fact, $Language;
     $GLOBALS['group_id'] = $group_id;
     $chunksz = $max_rows;
     $advsrch = 0;
     // ?
     $prefs = array();
     $report = new ArtifactReport($report_id, $group_artifact_id);
     if (!$report || !is_object($report)) {
         $this->setError('Cannot Get ArtifactReport From ID : ' . $report_id);
         return false;
     } elseif ($report->isError()) {
         $this->setError($report->getErrorMessage());
         return false;
     }
     $query_fields = $report->getQueryFields();
     $result_fields = $report->getResultFields();
     // Filter part
     if (is_array($criteria)) {
         foreach ($criteria as $cr) {
             $af = $art_field_fact->getFieldFromName($cr->field_name);
             if (!$af || !is_object($af)) {
                 $this->setError('Cannot Get ArtifactField From Name : ' . $cr->field_name);
                 return false;
             } elseif ($art_field_fact->isError()) {
                 $this->setError($art_field_fact->getErrorMessage());
                 return false;
             }
             if (!array_key_exists($cr->field_name, $query_fields)) {
                 $this->setError('You cannot filter on field ' . $cr->field_name . ': it is not a query field for report ' . $report_id);
                 return false;
             }
             if ($af->isSelectBox() || $af->isMultiSelectBox()) {
                 $prefs[$cr->field_name] = explode(",", $cr->field_value);
             } else {
                 $prefs[$cr->field_name] = array($cr->field_value);
                 if (isset($cr->operator)) {
                     $prefs[$cr->field_name][] = $cr->operator;
                 }
             }
         }
     }
     // Sort part
     $morder = '';
     $array_morder = array();
     if (is_array($sort_criteria)) {
         foreach ($sort_criteria as $sort_cr) {
             $field_name = $sort_cr->field_name;
             // check if fieldname is ok
             $af = $art_field_fact->getFieldFromName($sort_cr->field_name);
             if (!$af || !is_object($af)) {
                 $this->setError('Cannot Get ArtifactField From Name : ' . $sort_cr->field_name);
                 return false;
             } elseif ($art_field_fact->isError()) {
                 $this->setError($art_field_fact->getErrorMessage());
                 return false;
             }
             if (!array_key_exists($sort_cr->field_name, $result_fields)) {
                 $this->setError('You cannot sort on field ' . $sort_cr->field_name . ': it is not a result field for report ' . $report_id);
                 return false;
             }
             // check if direction is ok
             $sort_direction = '>';
             // by default, direction is ASC
             if (isset($sort_cr->sort_direction) && $sort_cr->sort_direction == 'DESC') {
                 $sort_direction = '<';
             }
             $array_morder[] = $field_name . $sort_direction;
         }
     }
     $morder = implode(',', $array_morder);
     $pm = ProjectManager::instance();
     $group = $pm->getProject($group_id);
     $ath = new ArtifactTypeHtml($group);
     $artifact_report = new ArtifactReport($report_id, $group_artifact_id);
     // get the total number of artifact that answer the query, and the corresponding IDs
     $total_artifacts = $artifact_report->selectReportItems($prefs, $morder, $advsrch, $aids);
     // get the SQL query corresponding to the query
     $sql = $artifact_report->createQueryReport($prefs, $morder, $advsrch, $offset, $chunksz, $aids);
     $result = $artifact_report->getResultQueryReport($sql);
     $result_fields = $artifact_report->getResultFields();
     //we get from result only fields that we need to display in the report (we add at the begining id and severity only to identify the artifact and for the severity color)
     $artifacts = array();
     $i = 0;
     foreach ($result as $art) {
         $artifact_id = $art['artifact_id'];
         $severity_id = $art['severity_id'];
         $artifact = new Artifact($this->ArtifactType, $art['artifact_id'], true);
         if ($artifact->userCanView()) {
             $fields = array();
             reset($result_fields);
             $fields['severity_id'] = $severity_id;
             $fields['id'] = $artifact_id;
             while (list($key, $field) = each($result_fields)) {
                 $value = $result[$i][$key];
                 $fields[$key] = $value;
             }
             $artifacts[$artifact_id] = $fields;
         }
         $i++;
     }
     return $artifacts;
 }