PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/results/resultsMoreBuilds.php

https://github.com/testlinkjp/testlink-japanese-localization
PHP | 302 lines | 204 code | 50 blank | 48 comment | 18 complexity | 67282f7a8a4a7a98ef7cbed8b5999031 MD5 | raw file
  1. <?php
  2. /**
  3. * TestLink Open Source Project - http://testlink.sourceforge.net/
  4. * This script is distributed under the GNU General Public License 2 or later.
  5. *
  6. * This page will forward the user to a form where they can select
  7. * the builds they would like to query results against.
  8. *
  9. * @filesource resultsMoreBuilds.php
  10. * @package TestLink
  11. * @author Kevin Levy <kevinlevy@users.sourceforge.net>
  12. * @copyright 2009, TestLink community
  13. *
  14. * @internal revisions
  15. * 20101202 - asimon - BUGID 4027: Query metrics start date and end date are not working - getting all results
  16. * 20101026 - Julian - BUGID 3930 - Localized dateformat for datepicker
  17. * 20101022 - asimon - BUGID 3716 - replaced old separated inputs for day/month/year by ext js calendar
  18. * 20101019 - eloff - BUGID 3794 - added contribution by rtessier
  19. *
  20. **/
  21. require_once('../../config.inc.php');
  22. require_once('common.php');
  23. require_once('results.class.php');
  24. require_once('users.inc.php');
  25. require_once('displayMgr.php');
  26. testlinkInitPage($db);
  27. $templateCfg = templateConfiguration();
  28. $date_format_cfg = config_get('date_format');
  29. $args = init_args($db);
  30. checkRights($db,$_SESSION['currentUser'],$args);
  31. $gui = initializeGui($db,$args,$date_format_cfg);
  32. $mailCfg = buildMailCfg($gui);
  33. $smarty = new TLSmarty();
  34. $smarty->assign('gui', $gui);
  35. $smarty->assign('report_type', $args->report_type);
  36. displayReport($templateCfg->template_dir . $templateCfg->default_template, $smarty, $args->report_type,$mailCfg);
  37. /**
  38. * initialize Gui
  39. */
  40. function initializeGui(&$dbHandler,&$argsObj,$dateFormat)
  41. {
  42. $reports_cfg = config_get('reportsCfg');
  43. $gui = new stdClass();
  44. $tplan_mgr = new testplan($dbHandler);
  45. $tproject_mgr = new testproject($dbHandler);
  46. $getOpt = array('outputFormat' => 'map');
  47. $gui->platformSet = $tplan_mgr->getPlatforms($argsObj->tplan_id,$getOpt);
  48. $gui->title = lang_get('query_metrics_report');
  49. $gui->showPlatforms=true;
  50. if( is_null($gui->platformSet) )
  51. {
  52. $gui->platformSet = array('');
  53. $gui->showPlatforms=false;
  54. }
  55. $gui->resultsCfg = config_get('results');
  56. // BUGID 3716, BUGID 3930
  57. // convert starttime to iso format for database usage
  58. if (isset($_REQUEST['selected_start_date']) && $_REQUEST['selected_start_date'] != '') {
  59. $date_array = split_localized_date($_REQUEST['selected_start_date'], $dateFormat);
  60. if ($date_array != null) {
  61. // set date in iso format
  62. $gui->startTime = $date_array['year'] . "-" . $date_array['month'] . "-" . $date_array['day'];
  63. }
  64. }
  65. // convert starttime to iso format for database usage
  66. if (isset($_REQUEST['selected_end_date']) && $_REQUEST['selected_end_date'] != '') {
  67. $date_array = split_localized_date($_REQUEST['selected_end_date'], $dateFormat);
  68. if ($date_array != null) {
  69. // set date in iso format
  70. $gui->endTime = $date_array['year'] . "-" . $date_array['month'] . "-" . $date_array['day'];
  71. }
  72. }
  73. $start_hour = isset($_REQUEST['start_Hour']) ? $_REQUEST['start_Hour'] : "00";
  74. $gui->startTime = $gui->startTime . " " . $start_hour . ":00:00";
  75. $end_hour = isset($_REQUEST['end_Hour']) ? $_REQUEST['end_Hour'] : "00";
  76. $gui->endTime = $gui->endTime . " " . $end_hour . ":59:59";
  77. $gui_open = config_get('gui_separator_open');
  78. $gui_close = config_get('gui_separator_close');
  79. $gui->str_option_any = $gui_open . lang_get('any') . $gui_close;
  80. $gui->str_option_none = $gui_open . lang_get('nobody') . $gui_close;
  81. $gui->search_notes_string = $argsObj->search_notes_string;
  82. $gui->tplan_id = $argsObj->tplan_id;
  83. $gui->tproject_id = $argsObj->tproject_id;
  84. $tplan_info = $tplan_mgr->get_by_id($gui->tplan_id);
  85. $tproject_info = $tproject_mgr->get_by_id($gui->tproject_id);
  86. $gui->tplan_name = $tplan_info['name'];
  87. $gui->tproject_name = $tproject_info['name'];
  88. $testsuiteIds = null;
  89. $testsuiteNames = null;
  90. $tsuites_qty = sizeOf($argsObj->testsuitesSelected);
  91. for ($id = 0; $id < $tsuites_qty ; $id++)
  92. {
  93. list($suiteId, $suiteName) = preg_split("/\,/", $argsObj->testsuitesSelected[$id], 2);
  94. $testsuiteIds[$id] = $suiteId;
  95. $testsuiteNames[$id] = $suiteName;
  96. }
  97. $buildsToQuery = -1;
  98. if (sizeof($argsObj->buildsSelected)) {
  99. $buildsToQuery = implode(",", $argsObj->buildsSelected);
  100. }
  101. // statusForClass is used for results.class.php
  102. // lastStatus is used to be displayed
  103. $statusForClass = 'a';
  104. // amitkhullar - added this parameter to get the latest results.
  105. $latest_resultset = $argsObj->display->latest_results;
  106. // BUGID 2500
  107. // $assignee = $argsObj->ownerSelected ? TL_USER_ANYBODY : null;
  108. // $tester = $argsObj->executorSelected ? TL_USER_ANYBODY : null;
  109. $assignee = $argsObj->ownerSelected > 0 ? $argsObj->ownerSelected : TL_USER_ANYBODY;
  110. $tester = $argsObj->executorSelected > 0 ? $argsObj->executorSelected : TL_USER_ANYBODY ;
  111. // BUGID 4027
  112. $re = new newResults($dbHandler, $tplan_mgr,$tproject_info,$tplan_info,
  113. $testsuiteIds, $buildsToQuery,
  114. $argsObj->platformsSelected, $statusForClass,
  115. $latest_resultset, $argsObj->keywordSelected,
  116. $assignee, $gui->startTime,
  117. $gui->endTime, $tester,
  118. $argsObj->search_notes_string, null);
  119. $gui->suiteList = $re->getSuiteList(); // test executions results
  120. // Filter test cases on selected platforms
  121. foreach ($gui->suiteList as $suiteid => $tcases) {
  122. $filtered = array();
  123. foreach ($tcases as $index => $tcase) {
  124. if ($tcase['platform_id'] == 0 ||
  125. $argsObj->platformsSelected[0] == ALL_PLATFORMS ||
  126. array_search($tcase['platform_id'], $argsObj->platformsSelected) !== false) {
  127. array_push($filtered, $tcase);
  128. }
  129. }
  130. unset($gui->suiteList[$suiteid]);
  131. $gui->suiteList[$suiteid] = $filtered;
  132. }
  133. $gui->flatArray = $re->getFlatArray();
  134. $gui->mapOfSuiteSummary = $re->getAggregateMap();
  135. $gui->totals = new stdClass();
  136. $gui->totals->items = $re->getTotalsForPlan();
  137. $gui->totals->labels = array();
  138. foreach($gui->totals->items as $key => $value)
  139. {
  140. $l18n = $key == 'total' ? 'th_total_cases' : $gui->resultsCfg['status_label'][$key];
  141. $gui->totals->labels[$key] = lang_get($l18n);
  142. }
  143. // BUGID 2012 - franciscom
  144. $gui->keywords = new stdClass();
  145. $gui->keywords->items[0] = $gui->str_option_any;
  146. if(!is_null($tplan_keywords_map = $tplan_mgr->get_keywords_map($gui->tplan_id)))
  147. {
  148. $gui->keywords->items += $tplan_keywords_map;
  149. }
  150. $gui->keywords->qty = count($gui->keywords->items);
  151. $gui->keywordSelected = $gui->keywords->items[$argsObj->keywordSelected];
  152. $gui->builds_html = $tplan_mgr->get_builds_for_html_options($gui->tplan_id);
  153. $gui->users = getUsersForHtmlOptions($dbHandler,ALL_USERS_FILTER,
  154. array(TL_USER_ANYBODY => $gui->str_option_any));
  155. $gui->ownerSelected = $gui->users[$argsObj->ownerSelected];
  156. $gui->executorSelected = $gui->users[$argsObj->executorSelected];
  157. $gui->testsuitesSelected = $testsuiteNames;
  158. $gui->buildsSelected = $argsObj->buildsSelected;
  159. $gui->platformsSelected = $argsObj->platformsSelected;
  160. $gui->display = $argsObj->display;
  161. // init display rows attribute and some status localized labels
  162. $gui->displayResults = array();
  163. $gui->lastStatus = array();
  164. foreach($reports_cfg->exec_status as $verbose => $label)
  165. {
  166. $gui->displayResults[$gui->resultsCfg['status_code'][$verbose]]=false;
  167. }
  168. foreach($gui->resultsCfg['status_label'] as $status_verbose => $label_key)
  169. {
  170. $gui->statusLabels[$gui->resultsCfg['status_code'][$status_verbose]] = lang_get($label_key);
  171. }
  172. $lastStatus_localized = null;
  173. foreach($argsObj->lastStatus as $key => $status_code)
  174. {
  175. $verbose = $gui->resultsCfg['code_status'][$status_code];
  176. $gui->displayResults[$status_code] = true;
  177. $lastStatus_localized[] = lang_get($gui->resultsCfg['status_label'][$verbose]);
  178. }
  179. $gui->lastStatus = $lastStatus_localized;
  180. return $gui;
  181. }
  182. /**
  183. * Initialize input data
  184. */
  185. function init_args(&$dbHandler)
  186. {
  187. $_REQUEST=strings_stripSlashes($_REQUEST);
  188. $iParams = array(
  189. "format" => array(tlInputParameter::INT_N),
  190. "report_type" => array(tlInputParameter::INT_N),
  191. "tplan_id" => array(tlInputParameter::INT_N),
  192. "tproject_id" => array(tlInputParameter::INT_N),
  193. "build" => array(tlInputParameter::ARRAY_INT),
  194. "platform" => array(tlInputParameter::ARRAY_INT),
  195. "keyword" => array(tlInputParameter::INT_N),
  196. "owner" => array(tlInputParameter::INT_N),
  197. "executor" => array(tlInputParameter::INT_N),
  198. "display_totals" => array(tlInputParameter::INT_N,1),
  199. "display_query_params" => array(tlInputParameter::INT_N,1),
  200. "display_test_cases" => array(tlInputParameter::INT_N,1),
  201. "display_latest_results" => array(tlInputParameter::INT_N,1),
  202. "display_suite_summaries" => array(tlInputParameter::INT_N,1),
  203. "lastStatus" => array(tlInputParameter::ARRAY_STRING_N),
  204. "testsuite" => array(tlInputParameter::ARRAY_STRING_N),
  205. "search_notes_string" => array(tlInputParameter::STRING_N),
  206. );
  207. $args = new stdClass();
  208. $pParams = R_PARAMS($iParams);
  209. $args->format = $pParams["format"];
  210. $args->report_type = $pParams["report_type"];
  211. $args->tplan_id = $pParams["tplan_id"];
  212. $args->tproject_id = $pParams["tproject_id"];
  213. $args->display = new stdClass();
  214. $args->display->suite_summaries = $pParams["display_suite_summaries"];
  215. $args->display->totals = $pParams["display_totals"];
  216. $args->display->query_params = $pParams["display_query_params"];
  217. $args->display->test_cases = $pParams["display_test_cases"];
  218. $args->display->latest_results = $pParams["display_latest_results"];
  219. $args->lastStatus = $pParams["lastStatus"] ? $pParams["lastStatus"] : array();
  220. $args->keywordSelected = $pParams["keyword"];
  221. $args->ownerSelected = $pParams["owner"];
  222. $args->executorSelected = $pParams["executor"];
  223. $args->buildsSelected = $pParams["build"] ? $pParams["build"] : array();
  224. $args->platformsSelected = $pParams["platform"] ? $pParams["platform"] : array();
  225. $args->testsuitesSelected = $pParams["testsuite"] ? $pParams["testsuite"] : array();
  226. $args->search_notes_string = $pParams['search_notes_string'];
  227. return $args;
  228. }
  229. /**
  230. * checkRights
  231. *
  232. */
  233. function checkRights(&$db,&$userObj,$argsObj)
  234. {
  235. $env['tproject_id'] = isset($argsObj->tproject_id) ? $argsObj->tproject_id : 0;
  236. $env['tplan_id'] = isset($argsObj->tplan_id) ? $argsObj->tplan_id : 0;
  237. checkSecurityClearance($db,$userObj,$env,array('testplan_metrics'),'and');
  238. }
  239. /**
  240. *
  241. *
  242. */
  243. function buildMailCfg(&$guiObj)
  244. {
  245. $labels = array('testplan' => lang_get('testplan'), 'testproject' => lang_get('testproject'));
  246. $cfg = new stdClass();
  247. $cfg->cc = '';
  248. $cfg->subject = $guiObj->title . ' : ' . $labels['testproject'] . ' : ' . $guiObj->tproject_name .
  249. ' : ' . $labels['testplan'] . ' : ' . $guiObj->tplan_name;
  250. return $cfg;
  251. }
  252. ?>