- Timestamp:
- Oct 24, 2010, 11:29:20 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php
r7327 r7370 86 86 /** 87 87 * 88 * Preparing the cache89 * ------------------- 88 * Preparing the temporary table => doCache() 89 * ------------------------------------------ 90 90 * To prepare the cache, the request builder use the following functions : 91 * - getImageId 91 92 * - getFrom 92 93 * - getWhere 93 * - getJoin 94 * - getImageId 94 * - getHaving 95 95 * 96 * Retrieving the results 97 * ---------------------- 96 * Preparing the cache table => doCache() 97 * -------------------------------------- 98 * To prepare the cache, the request builder use the following functions : 99 * => the getFilter function is used to prepare the filter for the getPage() 100 * function ; not used to build the cache 101 * 102 * Retrieving the results => getPage() 103 * ----------------------------------- 98 104 * To retrieve the image informations, the request builder uses the following 99 105 * functions : … … 101 107 * - getFrom 102 108 * - getJoin 103 * - getFilter (in fact, the result of this function is stored while the cache104 * is builded, but it is used only when retrieving the results for105 * multirecord tables)109 * - getFilter (in fact, the result of this function is stored by the doCache() 110 * function while the cache is builded, but it is used only when 111 * retrieving the results for multirecord tables) 106 112 * - formatData 107 113 * … … 120 126 * to 'y' 121 127 * 122 * gatImageId returns : "tableA.imageId"123 * getSelect returns : "tableA.att1, tableA.att2"124 * getFrom returns : "tableA"125 * getWhere returns : "tableA.localId= xxxx AND tableA.att1 = zzzz"126 * getJoin returns : "tableA.imageId = pit.id"127 * getFilter returns : "tableA.localId= xxxx"128 * gatImageId returns : "tableA.imageId" 129 * getSelect returns : "tableA.att1, tableA.att2" 130 * getFrom returns : "tableA" 131 * getWhere returns : "tableA.localId= xxxx AND tableA.att1 = zzzz" 132 * getJoin returns : "tableA.imageId = pit.id" 133 * getFilter returns : "tableA.localId= xxxx" 128 134 * 135 * Examples : 136 * - plugin AdvancedMetadata use getFilter 137 * - plugin AdvancedSearchEngine, module ASETag use getHaving and getWhere 129 138 */ 130 139 class GPCSearchCallback { … … 172 181 return(""); 173 182 } 183 184 185 /** 186 * the getHaving function return a ready to user HAVING clause 187 * 188 * " FIND_IN_SET(value0, GROUP_CONCAT(DISTINCT att1 SEPARATOR ',')) AND 189 * FIND_IN_SET(value0, GROUP_CONCAT(DISTINCT att1 SEPARATOR ',')) " 190 * 191 */ 192 static public function getHaving($param="") 193 { 194 return(""); 195 } 196 174 197 175 198 /** … … 201 224 return(""); 202 225 } 226 203 227 204 228 /** … … 487 511 $baseName=basename(dirname(dirname(__FILE__))).'/css/'; 488 512 $template->append('head_elements', '<link href="plugins/'.$baseName.'rbuilder.css" type="text/css" rel="stylesheet"/>'); 513 if(defined('IN_ADMIN')) $template->append('head_elements', '<link href="plugins/'.$baseName.'rbuilder_'.$template->get_themeconf('name').'.css" type="text/css" rel="stylesheet"/>'); 514 489 515 490 516 $baseName=basename(dirname(dirname(__FILE__))).'/js/'; … … 492 518 GPCCore::addHeaderJS('gpc.interface', 'plugins/'.$baseName.'external/interface/interface.js'); 493 519 GPCCore::addHeaderJS('gpc.inestedsortable', 'plugins/'.$baseName.'external/inestedsortable.pack.js'); 494 GPCCore::addHeaderJS('gpc. criteriaBuilder', 'plugins/'.$baseName.'criteriaBuilder.packed.js');520 GPCCore::addHeaderJS('gpc.rbCriteriaBuilder', 'plugins/'.$baseName.'rbCriteriaBuilder.packed.js'); 495 521 496 522 $template->append('head_elements', 497 523 "<script type=\"text/javascript\"> 498 524 requestBuilderOptions = { 499 textAND:'".l10n('gpc_rb_textAND')."', 500 textOR:'".l10n('gpc_rb_textOR')."', 501 textNoCriteria:\"".l10n('There is no criteria ! At least, one criteria is required to do search...')."\", 502 imgEditUrl:'', 503 imgDeleteUrl:'', 504 ajaxUrl:'plugins/GrumPluginClasses/gpc_ajax.php', 525 textAND:\"".l10n('gpc_rb_textAND')."\", 526 textOR:\"".l10n('gpc_rb_textOR')."\", 527 textNoCriteria:\"".l10n('There is no criteria ! At least, one criteria is required to do search...')."\", 528 textSomethingWrong:\"".l10n('gpc_something_is_wrong_on_the_server_side')."\", 529 textCaddieUpdated:\"".l10n('gpc_the_caddie_is_updated')."\", 530 helpEdit:\"".l10n('gpc_help_edit_criteria')."\", 531 helpDelete:\"".l10n('gpc_help_delete_criteria')."\", 532 helpMove:\"".l10n('gpc_help_move_criteria')."\", 533 helpSwitchCondition:\"".l10n('gpc_help_switch_condition')."\", 534 ajaxUrl:'plugins/GrumPluginClasses/gpc_ajax.php', 505 535 } 506 536 </script>"); … … 562 592 //$imageIdName=call_user_func(Array('RBCallBack'.$plugin, 'getImageId')); 563 593 564 $temp WHERE=array();594 $tempClauses=array(); 565 595 foreach($_REQUEST['extraData'] as $key => $extraData) 566 596 { 567 $t mpWHERE[$key]=array(597 $tempClauses[$key]=array( 568 598 'plugin' => $extraData['owner'], 569 'where' => call_user_func(Array('RBCallBack'.$extraData['owner'], 'getWhere'), $extraData['param']) 599 'where' => call_user_func(Array('RBCallBack'.$extraData['owner'], 'getWhere'), $extraData['param']), 600 'having' => call_user_func(Array('RBCallBack'.$extraData['owner'], 'getHaving'), $extraData['param']), 570 601 ); 571 602 } 572 603 573 $sql="INSERT INTO ".self::$tables['temp']." ".self::buildGroupRequest($_REQUEST[$_REQUEST['requestName']], $t mpWHERE, $_REQUEST['operator'], ' AND ', $requestNumber);574 604 $sql="INSERT INTO ".self::$tables['temp']." ".self::buildGroupRequest($_REQUEST[$_REQUEST['requestName']], $tempClauses, $_REQUEST['operator'], ' AND ', $requestNumber); 605 //echo $sql; 575 606 $result=pwg_query($sql); 576 607 … … 610 641 'WHERE' => 'pit.level <= '.$user['level'], 611 642 'GROUPBY' => '', 612 'FILTER' => '' ,643 'FILTER' => '' 613 644 ); 614 645 $tmpBuild=Array( … … 706 737 } 707 738 $build['FILTER']=' ('.implode(' AND ', $tmp).') '; 708 // array_flip twice => simply remove identical values...709 //$build['FILTER']=' ('.implode(' AND ', array_flip(array_flip($tmpBuild['FILTER']))).') ';710 739 } 711 740 unset($tmpBuild['FILTER']); … … 745 774 $sql="INSERT INTO ".self::$tables['result_cache']." (SELECT DISTINCT $requestNumber, ".$build['SELECT']." $sql)"; 746 775 747 776 //echo $sql; 748 777 $returned="0;0"; 749 778 … … 768 797 * @param Integer $pageNumber : the page to be returned 769 798 * @param Integer $numPerPage : the number of items returned on a page 799 * @param String $mode : if mode = 'count', the function returns the number of 800 * rows ; otherwise, returns rows in a html string 770 801 * @return String : formatted HTML code 771 802 */ … … 869 900 unset($tmpBuild['WHERE']); 870 901 871 872 902 /* for each plugin, adds jointure with the IMAGE table 873 903 */ … … 889 919 $imagesList=Array(); 890 920 891 $sql='SELECT '.$build['SELECT']921 $sql='SELECT DISTINCT '.$build['SELECT'] 892 922 .' FROM '.$build['FROM'] 893 923 .' WHERE '.$build['WHERE'] 894 .' GROUP BY '.$build['GROUPBY'] 895 .' ORDER BY pit.id ' 896 .' LIMIT '.$limitFrom.', '.$numPerPage; 924 .' GROUP BY '.$build['GROUPBY']; 925 926 $sql.=' ORDER BY pit.id ' 927 .' LIMIT '.$limitFrom.', '.$numPerPage; 928 897 929 //echo $sql; 898 930 $result=pwg_query($sql); … … 1056 1088 if(array_key_exists(3, $result)) 1057 1089 { 1058 return("GROUP_CONCAT( ".$result[1]." SEPARATOR '$sep') AS ".$result[3]);1090 return("GROUP_CONCAT(DISTINCT ".$result[1]." SEPARATOR '$sep') AS ".$result[3]); 1059 1091 } 1060 1092 elseif(array_key_exists(2, $result)) 1061 1093 { 1062 return("GROUP_CONCAT( ".$result[1]." SEPARATOR '$sep') AS ".$result[2]);1094 return("GROUP_CONCAT(DISTINCT ".$result[1]." SEPARATOR '$sep') AS ".$result[2]); 1063 1095 } 1064 1096 else 1065 1097 { 1066 return("GROUP_CONCAT( $val SEPARATOR '$sep') AS ".$val);1098 return("GROUP_CONCAT(DISTINCT $val SEPARATOR '$sep') AS ".$val); 1067 1099 } 1068 1100 } … … 1175 1207 * 1176 1208 * @param Array $groupContent : 1177 * @param Array $items : 1178 * @return String : a SQL request 1179 */ 1180 static private function buildGroupRequest($groupContent, $whereItems, $groups, $operator, $requestNumber) 1209 * @param Array $clausesItems : array with 'where' and 'having' conditions (and 'plugin' for the plugin) 1210 * @param Array $groups : operators of each group 1211 * @param String $operator : 'OR' or 'AND', according with the current group operator 1212 * @param String $requestNumber : the request number 1213 * @return String : part of a SQL request 1214 */ 1215 static private function buildGroupRequest($groupContent, $clausesItems, $groups, $operator, $requestNumber) 1181 1216 { 1182 1217 $returnedS=''; … … 1188 1223 preg_match('/[0-9]*$/i', $val['id'], $groupNumber); 1189 1224 1190 $groupValue=self::buildGroupRequest($val['children'], $ whereItems, $groups, $groups[$groupNumber[0]], $requestNumber);1225 $groupValue=self::buildGroupRequest($val['children'], $clausesItems, $groups, $groups[$groupNumber[0]], $requestNumber); 1191 1226 1192 1227 if($groupValue!='') … … 1202 1237 $returned[]=array( 1203 1238 'mode' => 'item', 1204 'plugin' => $whereItems[$itemNumber[0]]['plugin'], 1205 'value' => " (".$whereItems[$itemNumber[0]]['where'].") " 1239 'plugin' => $clausesItems[$itemNumber[0]]['plugin'], 1240 'valueWhere' => ($clausesItems[$itemNumber[0]]['where']!='')?" (".$clausesItems[$itemNumber[0]]['where'].") ":'', 1241 'valueHaving' => ($clausesItems[$itemNumber[0]]['having'])?" (".$clausesItems[$itemNumber[0]]['having'].") ":'', 1206 1242 ); 1207 1243 } … … 1220 1256 { 1221 1257 $returnedS.="(SELECT DISTINCT ".call_user_func(Array('RBCallBack'.$val['plugin'], 'getImageId'))." AS imageId 1222 FROM ".call_user_func(Array('RBCallBack'.$val['plugin'], 'getFrom'))." 1223 WHERE ".$val['value'].") t".self::$tGlobalId." "; 1258 FROM ".call_user_func(Array('RBCallBack'.$val['plugin'], 'getFrom')); 1259 if($val['valueWhere']!='') $returnedS.=" WHERE ".$val['valueWhere']; 1260 if($val['valueHaving']!='') 1261 $returnedS.=" GROUP BY imageId 1262 HAVING ".$val['valueHaving']; 1263 $returnedS.=") t".self::$tGlobalId." "; 1224 1264 } 1225 1265 else … … 1232 1272 self::$tGlobalId++; 1233 1273 } 1234 $returnedS="SELECT '$requestNumber', t".(self::$tGlobalId-$tId).".imageId FROM ".$returnedS;1274 $returnedS="SELECT DISTINCT '$requestNumber', t".(self::$tGlobalId-$tId).".imageId FROM ".$returnedS; 1235 1275 } 1236 1276 else … … 1244 1284 $returnedS.="SELECT DISTINCT '$requestNumber', t".self::$tGlobalId.".imageId 1245 1285 FROM (SELECT ".call_user_func(Array('RBCallBack'.$val['plugin'], 'getImageId'))." AS imageId 1246 FROM ".call_user_func(Array('RBCallBack'.$val['plugin'], 'getFrom'))." 1247 WHERE ".$val['value'].") t".self::$tGlobalId." "; 1286 FROM ".call_user_func(Array('RBCallBack'.$val['plugin'], 'getFrom')); 1287 if($val['valueWhere']!='') $returnedS.=" WHERE ".$val['valueWhere']; 1288 if($val['valueHaving']!='') 1289 $returnedS.=" GROUP BY imageId 1290 HAVING ".$val['valueHaving']; 1291 $returnedS.=") t".self::$tGlobalId." "; 1248 1292 } 1249 1293 else 1250 1294 { 1251 $returnedS.="SELECT '$requestNumber', t".self::$tGlobalId.".imageId FROM (".$val['value'].") t".self::$tGlobalId;1295 $returnedS.="SELECT DISTINCT '$requestNumber', t".self::$tGlobalId.".imageId FROM (".$val['value'].") t".self::$tGlobalId; 1252 1296 } 1253 1297
Note: See TracChangeset
for help on using the changeset viewer.