/* * This file is part of the Eventum (Issue Tracking System) package. * * @copyright (c) Eventum Team * @license GNU General Public License, version 2 or later (GPL-2+) * * For the full copyright and license information, * please see the COPYING and AUTHORS files * that were distributed with this source code. */ require_once __DIR__ . '/../../init.php'; Auth::checkAuthentication(); if (!empty($_REQUEST['iss_id'])) { $fields = Custom_Field::getListByIssue(Auth::getCurrentProject(), $_REQUEST['iss_id']); } else { $fields = Custom_Field::getListByProject(Auth::getCurrentProject(), $_REQUEST['form_type']); } $data = array(); foreach ($fields as $field) { $backend = Custom_Field::getBackend($field['fld_id']); if (is_object($backend) && is_subclass_of($backend, 'Dynamic_Custom_Field_Backend')) { $field['structured_data'] = $backend->getStructuredData(); $data[] = $field; } } header('Content-Type: text/javascript; charset=UTF-8'); $tpl = new Template_Helper(); $tpl->setTemplate('js/dynamic_custom_field.tpl.js'); $tpl->assign('fields', $data); $tpl->displayTemplate();
/** * Returns data for the custom fields report, based on the field and options passed in. * * @access public * @param integer $fld_id The id of the custom field. * @param array $cfo_ids An array of option ids. * @param string $group_by How the data should be grouped. * @param boolean $list If the values should be listed out instead of just counted. * @return array An array of data. */ function getCustomFieldReport($fld_id, $cfo_ids, $group_by = "issue", $list = false) { $prj_id = Auth::getCurrentProject(); $fld_id = Misc::escapeInteger($fld_id); $cfo_ids = array_map(array('Misc', 'escapeString'), $cfo_ids); $backend = Custom_Field::getBackend($fld_id); if (is_object($backend)) { $options = array(); foreach ($cfo_ids as $cfo_id) { $options[$cfo_id] = Custom_Field::getOptionValue($fld_id, $cfo_id); } $in_field = 'icf_value'; } else { // get field values $stmt = "SELECT\n cfo_id,\n cfo_value\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_field_option\n WHERE\n cfo_fld_id = {$fld_id} AND\n cfo_id IN('" . join("','", $cfo_ids) . "')\n ORDER BY\n cfo_id"; $options = $GLOBALS["db_api"]->dbh->getAssoc($stmt); if (PEAR::isError($options)) { Error_Handler::logError(array($options->getMessage(), $options->getDebugInfo()), __FILE__, __LINE__); return array(); } $in_field = 'cfo_id'; } if ($group_by == "customer") { $group_by_field = "iss_customer_id"; } else { $group_by_field = "iss_id"; } if ($list == true) { $sql = "SELECT\n DISTINCT({$group_by_field}),\n iss_id,\n iss_summary,\n iss_customer_id,\n count(DISTINCT(iss_id)) as row_count\n FROM\n"; if (!is_object($backend)) { $sql .= APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_field_option,\n"; } $sql .= APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_custom_field,\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n WHERE\n"; if (!is_object($backend)) { $sql .= "cfo_id = icf_value AND"; } $sql .= "\nicf_iss_id = iss_id AND\n icf_fld_id = {$fld_id} AND\n {$in_field} IN('" . join("','", array_keys($options)) . "')\n GROUP BY\n {$group_by_field}\n ORDER BY\n row_count DESC"; $res = $GLOBALS["db_api"]->dbh->getAll($sql, DB_FETCHMODE_ASSOC); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return array(); } if (Customer::hasCustomerIntegration($prj_id)) { Customer::getCustomerTitlesByIssues($prj_id, $res); if ($group_by == "issue") { usort($res, create_function('$a,$b', 'if ($a["customer_title"] < $b["customer_title"]) { return -1; } elseif ($a["customer_title"] > $b["customer_title"]) { return 1; } else { return 0; }')); } } return $res; } $data = array(); foreach ($options as $cfo_id => $value) { $stmt = "SELECT\n COUNT(DISTINCT {$group_by_field})\n FROM\n"; if (!is_object($backend)) { $stmt .= APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_field_option,\n"; } $stmt .= APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_custom_field,\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n WHERE\n"; if (!is_object($backend)) { $stmt .= "cfo_id = icf_value AND"; } $stmt .= "\nicf_iss_id = iss_id AND\n icf_fld_id = {$fld_id} AND\n {$in_field} = '" . Misc::escapeString($cfo_id) . "'"; $count = $GLOBALS["db_api"]->dbh->getOne($stmt); if (PEAR::isError($count)) { Error_Handler::logError(array($count->getMessage(), $count->getDebugInfo()), __FILE__, __LINE__); return array(); } $data[$value] = $count; } // include count of all other values (used in pie chart) $stmt = "SELECT\n COUNT(DISTINCT {$group_by_field})\n FROM\n"; if (!is_object($backend)) { $stmt .= APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_field_option,\n"; } $stmt .= APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_custom_field,\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n WHERE\n"; if (!is_object($backend)) { $stmt .= "cfo_id = icf_value AND"; } $stmt .= "\nicf_iss_id = iss_id AND\n icf_fld_id = {$fld_id} AND\n {$in_field} NOT IN('" . join("','", $cfo_ids) . "')"; $res = $GLOBALS["db_api"]->dbh->getOne($stmt); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return array(); } $data["All Others"] = $res; return $data; }
<?php /* * This file is part of the Eventum (Issue Tracking System) package. * * @copyright (c) Eventum Team * @license GNU General Public License, version 2 or later (GPL-2+) * * For the full copyright and license information, * please see the COPYING and AUTHORS files * that were distributed with this source code. */ require_once __DIR__ . '/../../init.php'; // if there is no field ID, return false if (empty($_GET['fld_id'])) { exit(0); } $backend = Custom_Field::getBackend($_GET['fld_id']); if (is_object($backend) && is_subclass_of($backend, 'Dynamic_Custom_Field_Backend')) { header('Content-Type: application/json; charset=UTF-8'); echo json_encode($backend->getDynamicOptions($_GET)); }
/** * Formats the return value * * @access public * @param mixed $value The value to format * @param integer $fld_id The ID of the field * @param integer $issue_id The ID of the issue * @return mixed the formatted value. */ function formatValue($value, $fld_id, $issue_id, $functional = false) { $backend = Custom_Field::getBackend($fld_id); if (is_object($backend) && method_exists($backend, 'formatValue')) { return $backend->formatValue($value, $fld_id, $issue_id, $functional); } else { return Link_Filter::processText(Auth::getCurrentProject(), htmlspecialchars($value)); } }