11<?php
2- /**
2+ /**
33 * TestLink Open Source Project - http://testlink.sourceforge.net/
4- * This script is distributed under the GNU General Public License 2 or later.
4+ * This script is distributed under the GNU General Public License 2 or later.
55 *
66 * @filesource reqSearch.php
77 * @package TestLink
8- * @copyright 2005-2020, TestLink community
8+ * @copyright 2005-2020, TestLink community
99 * @link http://www.testlink.org/index.php
1010 *
1111 * Search results for requirements.
4848
4949 // key: req id (db id)
5050 // value: array of versions and revisions
51- //
5251 $ map = (array )$ db ->fetchRowsIntoMap ($ sql ,'id ' ,database::CUMULATIVE );
5352
5453 // dont show requirements from different testprojects than the selected one
7069 if ($ gui ->row_qty <= $ req_cfg ->search ->max_qty_for_display ) {
7170 $ req_set = array_keys ($ map );
7271 $ options = array ('output_format ' => 'path_as_string ' );
73- $ gui ->path_info =
74- $ tproject_mgr ->tree_manager ->get_full_path_verbose ($ req_set ,$ options );
72+ $ gui ->path_info = $ tproject_mgr ->tree_manager ->get_full_path_verbose ($ req_set ,$ options );
7573 } else {
7674 $ gui ->warning_msg = lang_get ('too_wide_search_criteria ' );
7775 }
8583 $ gui ->tableSet [] = $ table ;
8684}
8785
88- $ gui ->pageTitle =
89- $ gui ->main_descr . " - " . lang_get ('match_count ' ) . ": " . $ gui ->row_qty ;
86+ $ gui ->pageTitle = $ gui ->main_descr . " - " . lang_get ('match_count ' ) . ": " . $ gui ->row_qty ;
9087
9188$ smarty ->assign ('gui ' ,$ gui );
9289$ smarty ->display ($ templateCfg ->template_dir . $ tpl );
9390
9491/**
95- *
92+ *
9693 *
9794 */
9895function buildExtTable ($ gui , $ charset ) {
9996 $ table = null ;
100- $ lbl = array ('edit ' => 'requirement ' , 'rev ' => 'revision_short ' ,
101- 'ver ' => 'version_short ' ,
97+ $ lbl = array ('edit ' => 'requirement ' , 'rev ' => 'revision_short ' ,
98+ 'ver ' => 'version_short ' ,
10299 'req_spec ' => 'req_spec ' , 'requirement ' => 'requirement ' ,
103100 'version_revision_tag ' => 'version_revision_tag ' );
104101
105102 $ labels = init_labels ($ lbl );
106103 $ edit_icon = TL_THEME_IMG_DIR . "edit_icon.png " ;
107104
108- // $gui->resultSet -
109- // key: reqspec_id
105+ // $gui->resultSet -
106+ // key: reqspec_id
110107 // value: array of matches
111108 // array
112109 // {
113110 // [4][0]=>{"name" => "QAZ MNNN","id" => "4","req_doc_id" => "QAZ",
114- // "version_id" => 5, "version" => 1,
111+ // "version_id" => 5, "version" => 1,
115112 // "revision_id" => -1, "revision" => 2} -> revisio_id < 0 => lives on REQ VERSIONS TABLE
116113 //
117114 // [1]=>{"name" => "QAZ MNNN","id" => "4","req_doc_id" => "QAZ",
118- // "version_id" => 5, "version" => 1,
119- // "revision_id" => 6, "revision" => 1}
115+ // "version_id" => 5, "version" => 1,
116+ // "revision_id" => 6, "revision" => 1}
120117 // ...
121118 // }
122119 //
123120 //
124-
125121 if (count ($ gui ->resultSet ) > 0 ) {
126122 $ columns = array ();
127123
@@ -134,9 +130,9 @@ function buildExtTable($gui, $charset) {
134130 $ key2loop = array_keys ($ gui ->resultSet );
135131 $ img = "<img title= \"{$ labels ['edit ' ]}\" src= \"{$ edit_icon }\" /> " ;
136132 // req_id, req_version_id
137- $ reqVerHref = '<a href="javascript:openLinkedReqVersionWindow(%s,%s)"> ' . $ labels ['version_revision_tag ' ] . ' </a> ' ;
133+ $ reqVerHref = '<a href="javascript:openLinkedReqVersionWindow(%s,%s)"> ' . $ labels ['version_revision_tag ' ] . ' </a> ' ;
138134 // req_revision_id
139- $ reqRevHref = '<a href="javascript:openReqRevisionWindow(%s)"> ' . $ labels ['version_revision_tag ' ] . ' </a> ' ;
135+ $ reqRevHref = '<a href="javascript:openReqRevisionWindow(%s)"> ' . $ labels ['version_revision_tag ' ] . ' </a> ' ;
140136
141137 foreach ($ key2loop as $ req_id ) {
142138 $ rowData = array ();
@@ -158,7 +154,7 @@ function buildExtTable($gui, $charset) {
158154 } else {
159155 $ dummy = sprintf ($ reqVerHref ,$ req_id ,$ rx ['version_id ' ],$ rx ['version ' ],
160156 $ rx ['revision ' ]);
161- }
157+ }
162158 $ matches .= $ dummy ;
163159 }
164160 $ rowData [] = $ edit_link . $ title . ' ' . $ matches ;
@@ -182,6 +178,7 @@ function buildExtTable($gui, $charset) {
182178 return $ table ;
183179}
184180
181+
185182/*
186183 function:
187184
@@ -194,7 +191,7 @@ function init_args($dateFormat) {
194191 $ args = new stdClass ();
195192 $ _REQUEST = strings_stripSlashes ($ _REQUEST );
196193
197- $ strnull = array ('requirement_document_id ' , 'name ' ,'scope ' ,
194+ $ strnull = array ('requirement_document_id ' , 'name ' ,'scope ' ,
198195 'reqStatus ' ,
199196 'custom_field_value ' , 'targetRequirement ' ,
200197 'creation_date_from ' ,'creation_date_to ' ,
@@ -224,11 +221,11 @@ function init_args($dateFormat) {
224221 foreach ( $ dk as $ tdk => $ hhmmss ) {
225222 if (isset ($ args ->$ tdk ) && trim ($ args ->$ tdk ) != '' ) {
226223 $ l10ndate = split_localized_date ($ args ->$ tdk , $ dateFormat );
227- $ args ->$ tdk = null ;
224+ $ args ->$ tdk = null ;
228225 if ($ l10ndate != null && is_array ($ l10ndate )) {
229226 // set date in iso format
230- $ args ->$ tdk = $ l10ndate ['year ' ] . "- " .
231- $ l10ndate ['month ' ] . "- " .
227+ $ args ->$ tdk = $ l10ndate ['year ' ] . "- " .
228+ $ l10ndate ['month ' ] . "- " .
232229 $ l10ndate ['day ' ] . $ hhmmss ;
233230 }
234231 }
@@ -243,12 +240,12 @@ function init_args($dateFormat) {
243240
244241
245242/**
246- *
243+ *
247244 *
248245 */
249246function build_search_sql (&$ dbHandler ,&$ argsObj ,&$ guiObj ) {
250- $ tables = tlObjectWithDB::getDBTables (array ('cfield_design_values ' ,
251- 'nodes_hierarchy ' , 'req_specs ' , 'req_relations ' , 'req_versions ' ,
247+ $ tables = tlObjectWithDB::getDBTables (array ('cfield_design_values ' ,
248+ 'nodes_hierarchy ' , 'req_specs ' , 'req_relations ' , 'req_versions ' ,
252249 'req_revisions ' ,'requirements ' , 'req_coverage ' , 'tcversions ' ));
253250
254251 // ver => REQ Versions
@@ -261,12 +258,10 @@ function build_search_sql(&$dbHandler,&$argsObj,&$guiObj) {
261258 //
262259 // That's why to certain extent filter seems to work in OR mode.
263260 // May be this is a BUG, that was never reported.
264- //
265261 $ filter = array ();
266262 $ filter ['ver ' ] = null ;
267263 $ filter ['rev ' ] = null ;
268264
269- // -----------------------------------------------------------------------
270265 // date filters can be build using algorithm
271266 // Need to sanitize!!! 2019
272267 $ date_fields = array ('creation_ts ' => 'ts ' ,'modification_ts ' => 'ts ' );
@@ -278,28 +273,26 @@ function build_search_sql(&$dbHandler,&$argsObj,&$guiObj) {
278273 $ filter ['ver ' ][$ fkey ] = " AND REQV. $ fx $ op ' {$ argsObj ->$ fkey }' " ;
279274 $ filter ['rev ' ][$ fkey ] = " AND REQR. $ fx $ op ' {$ argsObj ->$ fkey }' " ;
280275 }
281- }
276+ }
282277 }
283- // -----------------------------------------------------------------------
284278
285279 // key: args key
286280 // value: map
287281 // key: table field
288- // value: map
282+ // value: map
289283 // key: filter scope, will identify with part of SQL affects
290284 // value: table alias
291- //
292- $ likeKeys = array ('name ' =>
293- array ('name ' =>
285+ $ likeKeys = array ('name ' =>
286+ array ('name ' =>
294287 array ('ver ' => "NH_REQ " , 'rev ' => "REQR " )),
295- 'requirement_document_id ' =>
296- array ('req_doc_id ' =>
288+ 'requirement_document_id ' =>
289+ array ('req_doc_id ' =>
297290 array ('ver ' => 'REQ ' , 'rev ' => 'REQR ' )),
298- 'scope ' =>
299- array ('scope ' =>
291+ 'scope ' =>
292+ array ('scope ' =>
300293 array ('ver ' => 'REQV ' , 'rev ' => 'REQR ' )),
301- 'log_message '
302- => array ('log_message ' =>
294+ 'log_message '
295+ => array ('log_message ' =>
303296 array ('ver ' => 'REQV ' ,'rev ' =>'REQR ' )));
304297
305298 foreach ($ likeKeys as $ key => $ fcfg ) {
@@ -310,12 +303,12 @@ function build_search_sql(&$dbHandler,&$argsObj,&$guiObj) {
310303 $ filter [$ table ][$ field ] = " AND {$ alias }. {$ field } like '% {$ value }%' " ;
311304 }
312305 }
313- }
306+ }
314307
315- $ char_keys = array ( 'reqType ' =>
316- array ('type ' =>
308+ $ char_keys = array ( 'reqType ' =>
309+ array ('type ' =>
317310 array ('ver ' => "REQV " , 'rev ' => "REQR " )),
318- 'reqStatus ' =>
311+ 'reqStatus ' =>
319312 array ('status ' => array ('ver ' => 'REQV ' , 'rev ' => 'REQR ' )));
320313
321314 foreach ($ char_keys as $ key => $ fcfg ) {
@@ -326,7 +319,7 @@ function build_search_sql(&$dbHandler,&$argsObj,&$guiObj) {
326319 $ filter [$ table ][$ field ] = " AND {$ alias }. {$ field } = ' {$ value }' " ;
327320 }
328321 }
329- }
322+ }
330323
331324 if ($ argsObj ->version ) {
332325 $ version = $ dbHandler ->prepare_int ($ argsObj ->version );
@@ -344,37 +337,35 @@ function build_search_sql(&$dbHandler,&$argsObj,&$guiObj) {
344337
345338 // Complex processing
346339 if (!is_null ($ argsObj ->relation_type ) && intval ($ argsObj ->relation_type ) >0 ) {
347- // search by relation type
340+ // search by relation type
348341 // $argsObj->relation_type is a string in following form
349342 // e.g. 3_destination or 2_source or only 4
350343 // must be treated different
351344 $ dummy = explode ('_ ' ,$ argsObj ->relation_type );
352345 $ rel_type = $ dummy [0 ];
353- $ side = isset ($ dummy [1 ]) ? " RR. {$ dummy [1 ]}_id = NH_REQ.id " :
346+ $ side = isset ($ dummy [1 ]) ? " RR. {$ dummy [1 ]}_id = NH_REQ.id " :
354347 " RR.source_id = NH_REQ.id OR RR.destination_id = NH_REQ.id " ;
355348
356349 $ from ['ver ' ]['relation_type ' ] = " JOIN {$ tables ['req_relations ' ]} RR " .
357- " ON ( $ side) AND RR.relation_type = {$ rel_type } " ;
350+ " ON ( $ side) AND RR.relation_type = {$ rel_type } " ;
358351 $ from ['rev ' ]['relation_type ' ] = $ from ['ver ' ]['relation_type ' ];
359352
360- }
353+ }
361354
362355 if ($ argsObj ->custom_field_id > 0 ) {
363356 $ cfield_id = $ dbHandler ->prepare_string ($ argsObj ->custom_field_id );
364357 $ cfield_value = $ dbHandler ->prepare_string ($ argsObj ->custom_field_value );
365- $ from ['ver ' ]['custom_field ' ] =
366- " JOIN {$ tables ['cfield_design_values ' ]} CFD " .
367- " ON CFD.node_id = REQV.id " ;
358+ $ from ['ver ' ]['custom_field ' ] = " JOIN {$ tables ['cfield_design_values ' ]} CFD " .
359+ " ON CFD.node_id = REQV.id " ;
368360
369- $ from ['rev ' ]['custom_field ' ] =
370- " JOIN {$ tables ['cfield_design_values ' ]} CFD " .
371- " ON CFD.node_id = REQR.id " ;
361+ $ from ['rev ' ]['custom_field ' ] = " JOIN {$ tables ['cfield_design_values ' ]} CFD " .
362+ " ON CFD.node_id = REQR.id " ;
372363
373364 $ filter ['ver ' ]['custom_field ' ] = " AND CFD.field_id = {$ cfield_id } " .
374365 " AND CFD.value like '% {$ cfield_value }%' " ;
375366
376- $ filter ['rev ' ]['custom_field ' ] = $ filter ['ver ' ]['custom_field ' ];
377- }
367+ $ filter ['rev ' ]['custom_field ' ] = $ filter ['ver ' ]['custom_field ' ];
368+ }
378369
379370 if ($ argsObj ->tcid != "" && strcmp ($ argsObj ->tcid , $ guiObj ->tcasePrefix ) != 0 ) {
380371 // search for reqs linked to this testcase
@@ -384,28 +375,27 @@ function build_search_sql(&$dbHandler,&$argsObj,&$guiObj) {
384375 $ filter ['ver ' ]['tcid ' ] = " AND TCV.tc_external_id = ' $ tcid' " ;
385376 $ filter ['rev ' ]['tcid ' ] = $ filter ['ver ' ]['tcid ' ];
386377
387- $ from ['ver ' ]['tcid ' ] =
388-
378+ $ from ['ver ' ]['tcid ' ] =
389379 " /* 1.9.18 Changed */ " .
390380 " /* Look for Req Coverage info */ " .
391- " JOIN {$ tables ['req_coverage ' ]} RC ON RC.req_version_id = NH_REQV.id " .
381+ " JOIN {$ tables ['req_coverage ' ]} RC ON RC.req_version_id = NH_REQV.id " .
392382
393383 " /* 1.9.18 Changed */ " .
394384 " /* Need Test case children => test case versions */ " .
395- " JOIN {$ tables ['nodes_hierarchy ' ]} NH_TCV
385+ " JOIN {$ tables ['nodes_hierarchy ' ]} NH_TCV
396386 ON NH_TCV.id = RC.tcversion_id " .
397387
398388 " /* Needed to search using External ID */ " .
399389 " JOIN {$ tables ['tcversions ' ]} TCV ON TCV.id = NH_TCV.id " ;
400390
401- $ from ['rev ' ]['tcid ' ] = $ from ['ver ' ]['tcid ' ];
391+ $ from ['rev ' ]['tcid ' ] = $ from ['ver ' ]['tcid ' ];
402392 }
403393
404394 // We will search on two steps
405395 // STEP 1
406396 // Search on REQ Versions
407397 //
408- $ common = " SELECT NH_REQ.name, REQ.id, REQ.req_doc_id, " ;
398+ $ common = " SELECT NH_REQ.name, REQ.id, REQ.req_doc_id, " ;
409399 $ sql = $ common .
410400 " REQV.id as version_id, REQV.version, REQV.revision, -1 AS revision_id " .
411401 " /* */ " .
@@ -414,8 +404,8 @@ function build_search_sql(&$dbHandler,&$argsObj,&$guiObj) {
414404 " JOIN {$ tables ['nodes_hierarchy ' ]} NH_REQ ON NH_REQ.id=REQ.id " .
415405 " /* */ " .
416406 " /* Need to get all REQ children => REQ Versions */ " .
417- " JOIN {$ tables ['nodes_hierarchy ' ]}
418- NH_REQV ON NH_REQV.parent_id = NH_REQ.id " .
407+ " JOIN {$ tables ['nodes_hierarchy ' ]}
408+ NH_REQV ON NH_REQV.parent_id = NH_REQ.id " .
419409 " /* */ " .
420410 " /* Go for REQ REV data */ " .
421411 " JOIN {$ tables ['req_versions ' ]} REQV ON REQV.id=NH_REQV.id " .
@@ -427,8 +417,8 @@ function build_search_sql(&$dbHandler,&$argsObj,&$guiObj) {
427417 if (!is_null ($ ref ['ver ' ])) {
428418 $ sql .= ($ vv == 'filter ' ) ? ' WHERE 1=1 ' : '' ;
429419 $ sql .= implode ("" ,$ ref ['ver ' ]);
430- }
431- }
420+ }
421+ }
432422 $ stm ['ver ' ] = $ sql ;
433423
434424
@@ -443,7 +433,7 @@ function build_search_sql(&$dbHandler,&$argsObj,&$guiObj) {
443433 " JOIN {$ tables ['nodes_hierarchy ' ]} NH_REQ ON NH_REQ.id=REQ.id " .
444434 " /* SQL For Req REVISIONS - */ " .
445435 " /* SQL For Req REVISIONS - Need to get all REQ children => REQ Versions because they are parent of REVISIONS */ " .
446- " JOIN {$ tables ['nodes_hierarchy ' ]} NH_REQV ON NH_REQV.parent_id = NH_REQ.id " .
436+ " JOIN {$ tables ['nodes_hierarchy ' ]} NH_REQV ON NH_REQV.parent_id = NH_REQ.id " .
447437 " /* SQL For Req REVISIONS - */ " .
448438 " /* SQL For Req REVISIONS - Go for REQ REVISION DATA */ " .
449439 " JOIN {$ tables ['req_versions ' ]} REQV ON REQV.id=NH_REQV.id " .
@@ -456,11 +446,11 @@ function build_search_sql(&$dbHandler,&$argsObj,&$guiObj) {
456446 if (!is_null ($ ref ['rev ' ])) {
457447 $ sql4Union .= ($ vv == 'filter ' ) ? ' WHERE 1=1 ' : '' ;
458448 $ sql4Union .= implode ("" ,$ ref ['rev ' ]);
459- }
460- }
449+ }
450+ }
461451
462452
463453 // add additional joins that depends on user search criteria
464454 $ sql = $ stm ['ver ' ] . " UNION ( {$ sql4Union }) ORDER BY id ASC, version DESC, revision DESC " ;
465455 return $ sql ;
466- }
456+ }
0 commit comments