Changeset 6894


Ignore:
Timestamp:
Sep 13, 2010, 8:54:21 PM (14 years ago)
Author:
grum
Message:

Version 3.2.0
Enhance the request builder

Location:
extensions/GrumPluginClasses
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • extensions/GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php

    r6213 r6894  
    22/* -----------------------------------------------------------------------------
    33  class name: GCPRequestBuilder
    4   class version  : 1.0.0
     4  class version  : 1.1.0
    55  plugin version : 3.1.0
    6   date           : 2010-04-29
     6  date           : 2010-09-08
    77
    88  ------------------------------------------------------------------------------
     
    1414    << May the Little SpaceFrog be with you ! >>
    1515  ------------------------------------------------------------------------------
    16 
     16  *
    1717  * theses classes provides base functions to manage search pictures in the
    1818  * database
    1919  *
    20 
    21 
     20  *
     21  * HOW TO USE IT ?
     22  * ===============
     23  *
     24  * when installing the plugin, you have to register the usage of the request
     25  * builder
     26  *
     27  * 1/ Create a RBCallback class
     28  *  - extends the GPCSearchCallback class ; the name of the extended class must
     29  *    be "RBCallBack%" => replace the "%" by the plugin name
     30  *     for example : 'ThePlugin' => 'RBCallBackThePlugin'
     31  *
     32  * 2/ In the plugin 'maintain.inc.php' file :
     33  *  - function plugin_install, add :
     34  *       GPCRequestBuilder::register('plugin name', 'path to the RBCallback classe');
     35  *          for example : GPCRequestBuilder::register('ThePlugin', $piwigo_path.'plugins/ThePlugin/rbcallback_file_name.php');
     36  *
     37  *
     38  *  - function plugin_uninstall, add :
     39  *       GPCRequestBuilder::unregister('plugin name');
     40  *          for example : GPCRequestBuilder::unregister('ThePlugin');
     41  *
     42  * 3/ In the plugin code, put somewhere
     43  *     GPCRequestBuilder::loadJSandCSS();
     44  *     => this will load specific JS and CSS in the page, by adding url in the
     45  *        the header, so try to put this where you're used to prepare the header
     46  *
     47  * 4/ to display the request builder, just add the returned string in the html
     48  *    page
     49  *       $stringForTheTemplate=GPCRequestBuilder::displaySearchPage();
     50  *
     51  *
     52  *
     53  * HOW DOES THE REQUEST BUILDER WORKS ?
     54  * ====================================
     55  *
     56  * the request builder works in 2 steps :
     57  *  - first step  : build a cache, to associate all image id corresponding to
     58  *                  the search criterion
     59  *                  the cache is an association of request ID/image id
     60  *  - second step : use the cache to retrieve images informations
     61  *
    2262  ------------------------------------------------------------------------------
    2363  :: HISTORY
     
    2565| release | date       |
    2666| 1.0.0   | 2010/04/30 | * start coding
     67|         |            |
     68| 1.1.0   | 2010/09/08 | * add functionnalities to manage complex requests
    2769|         |            |
    2870|         |            |
     
    3476|         |            |
    3577|         |            |
    36 |         |            |
    37 |         |            |
    3878
    3979  --------------------------------------------------------------------------- */
     
    4282include_once('GPCTables.class.inc.php');
    4383
    44 
     84/**
     85 *
     86 * Preparing the cache
     87 * -------------------
     88 * To prepare the cache, the request builder use the following functions :
     89 *  - getFrom
     90 *  - getWhere
     91 *  - getJoin
     92 *  - getImageId (used for multirecord requests only)
     93 *
     94 * Retrieving the results
     95 * ----------------------
     96 * To retrieve the image informations, the request builder uses the following
     97 * functions :
     98 *  - getSelect
     99 *  - getFrom
     100 *  - getJoin
     101 *  - getFilter (in fact, the result of this function is stored while the cache
     102 *               is builded, but it is used only when retrieving the results for
     103 *               multirecord tables)
     104 *
     105 *
     106 * Example 1 : single record request
     107 * ---------------------------------
     108 * Consider the table "tableA" like this
     109 *
     110 *  - (*) imageId
     111 *  -     att1
     112 *  -     att2
     113 *  The primary key is the 'imageId' attribute
     114 *    => for one imageId, you can only have ZERO or ONE record
     115 *
     116 *  getSelect returns : "tableA.att1, tableA.att2"
     117 *  getFrom returns   : "tableA"
     118 *  getWhere returns  : "tableA.att1 = zzzz"
     119 *  getJoin returns   : "tableA.imageId = pit.id"
     120 *  getFilter returns : ""
     121 *
     122 *
     123 * Example 2 : multi records request
     124 * ---------------------------------
     125 * Consider the table "tableA" like this
     126 *
     127 *  - (*) imageId
     128 *  - (*) localId
     129 *  -     att1
     130 *  -     att2
     131 *  The primary key is the 'imageId'+'localId' attributes
     132 *    => for one imageId, you can have ZERO or more than ONE record
     133 *       when you register the class, you have to set the $multiRecord parameter
     134 *       to 'y'
     135 *
     136 *  gatImageId returns : "tableA.imageId"
     137 *  getSelect returns  : "tableA.att1, tableA.att2"
     138 *  getFrom returns    : "tableA"
     139 *  getWhere returns   : "tableA.att1 = zzzz AND tableA.att1 = xxxx"
     140 *  getJoin returns    : "tableA.id = pit.id"
     141 *  getFilter returns  : ""
     142 *
     143 */
    45144class GPCSearchCallback {
    46145
    47146  /**
     147   * the getImageId returns the name of the image id attribute
     148   * return String
     149   */
     150  static public function getImageId()
     151  {
     152    return("");
     153  }
     154
     155  /**
    48156   * the getSelect function must return an attribute list separated with a comma
    49157   *
    50158   * "att1, att2, att3, att4"
     159   *
     160   * you can specifie tables names and aliases
     161   *
     162   * "table1.att1 AS alias1, table1.att2 AS alias2, table2.att3 AS alias3"
    51163   */
    52164  static public function getSelect($param="")
     
    76188
    77189  /**
    78    * the getJoin function must return a ready to use where allowing to join the
    79    * IMAGES table (key : pit.id) with given conditions
     190   * the getJoin function must return a ready to use sql statement allowing to
     191   * join the IMAGES table (key : pit.id) with given conditions
    80192   *
    81193   * "att3 = pit.id "
     
    86198  }
    87199
     200
     201  /**
     202   * the getFilter function must return a ready to use where clause
     203   * this where clause is used to filter the cache when the used tables can
     204   * return more than one result
     205   *
     206   * the filter can be empty, can be equal to the where clause, or can be equal
     207   * to a sub part of the where clause
     208   *
     209   */
     210  static public function getFilter($param="")
     211  {
     212    return(self::getWhere($param));
     213  }
    88214
    89215  /**
     
    152278
    153279  static public $pluginName = 'GPCRequestBuilder';
    154   static public $version = '1.0.0';
     280  static public $version = '1.1.0';
    155281
    156282  static private $tables = Array();
     283  static protected $tGlobalId=0;
    157284
    158285  /**
     
    173300        'fileName' => $fileName,
    174301        'date' => date("Y-m-d H:i:s"),
    175         'version' => self::$version,
     302        'version' => self::$version
    176303      );
    177304      return(GPCCore::saveConfig(self::$pluginName, $config));
     
    232359  static public function init($prefixeTable, $pluginNameFile)
    233360  {
    234     $list=Array('request', 'result_cache');
     361    $list=Array('request', 'result_cache', 'temp');
    235362
    236363    for($i=0;$i<count($list);$i++)
     
    253380  `execution_time` float unsigned NOT NULL default '0',
    254381  `connected_plugin` char(255) NOT NULL,
     382  `filter` text NOT NULL,
    255383  PRIMARY KEY  (`id`)
    256384)
     
    263391)
    264392CHARACTER SET utf8 COLLATE utf8_general_ci",
     393
     394"CREATE TABLE `".self::$tables['temp']."` (
     395  `requestId` char(30) NOT NULL,
     396  `imageId` mediumint(8) unsigned NOT NULL,
     397  PRIMARY KEY  (`request`,`id`)
     398)
     399CHARACTER SET utf8 COLLATE utf8_general_ci",
    265400  );
    266401
     
    277412  {
    278413    $tablef= new GPCTables(self::$tables);
    279     $tablef->drop($tables_def);
     414    $tablef->drop();
    280415    return(true);
    281416  }
     
    378513
    379514  /**
     515   * prepare the temporary table used for multirecord requests
     516   *
     517   * @param Integer $requestNumber : id of request
     518   * @return String : name of the request key temporary table
     519   */
     520  static private function prepareTempTable($requestNumber)
     521  {
     522    //$tableName=call_user_func(Array('RBCallBack'.$plugin, 'getFrom'));
     523    //$imageIdName=call_user_func(Array('RBCallBack'.$plugin, 'getImageId'));
     524
     525    $tempWHERE=array();
     526    foreach($_REQUEST['extraData'] as $key => $extraData)
     527    {
     528      $tmpWHERE[$key]=array(
     529        'plugin' => $extraData['owner'],
     530        'where' => call_user_func(Array('RBCallBack'.$extraData['owner'], 'getWhere'), $extraData['param'])
     531      );
     532    }
     533
     534    $sql="INSERT INTO ".self::$tables['temp']." ".self::buildGroupRequest($_REQUEST[$_REQUEST['requestName']], $tmpWHERE, $_REQUEST['operator'], ' AND ', $requestNumber);
     535//echo $sql;
     536    $result=pwg_query($sql);
     537
     538    return($requestNumber);
     539  }
     540
     541  /**
     542   * clear the temporary table used for multirecord requests
     543   *
     544   * @param Array $requestNumber : the requestNumber to delete
     545   */
     546  static private function clearTempTable($requestNumber)
     547  {
     548    $sql="DELETE FROM ".self::$tables['temp']." WHERE requestId = '$requestNumber';";
     549    pwg_query($sql);
     550  }
     551
     552
     553  /**
    380554   * execute a query, and place result in cache
    381555   *
     
    390564
    391565    $registeredPlugin=self::getRegistered();
     566    $requestNumber=self::getNewRequest($user['id']);
    392567
    393568    $build=Array(
     
    396571      'WHERE' => '',
    397572      'GROUPBY' => '',
     573      'FILTER' => '',
    398574    );
    399575    $tmpBuild=Array(
     
    407583      'GROUPBY' => Array(
    408584        'pit.id'
    409       )
     585      ),
     586      'FILTER' => Array(),
    410587    );
    411588
     
    429606    $pluginNeeded=Array();
    430607    $pluginList=Array();
     608    $tempName=Array();
    431609    foreach($_REQUEST['extraData'] as $key => $val)
    432610    {
     
    435613    }
    436614
    437     /* for each needed plugin :
    438      *  - include the file
    439      *  - call the static public function getWhere
    440      */
     615    /* for each plugin, include the rb callback class file */
     616    foreach($pluginList as $val)
     617    {
     618      if(file_exists($registeredPlugin[$val]['fileName']))
     619      {
     620        include_once($registeredPlugin[$val]['fileName']);
     621      }
     622    }
     623
     624    /* prepare the temp table for the request */
     625    self::prepareTempTable($requestNumber);
     626    $tmpBuild['FROM'][]=self::$tables['temp'];
     627    $tmpBuild['JOIN'][]=self::$tables['temp'].".requestId = '".$requestNumber."'
     628                        AND ".self::$tables['temp'].".imageId = pit.id";
     629
     630    /* for each needed plugin, prepare the filter */
    441631    foreach($pluginNeeded as $key => $val)
    442632    {
    443       if(array_key_exists($key, $registeredPlugin))
    444       {
    445         if(file_exists($registeredPlugin[$key]['fileName']))
    446         {
    447           include_once($registeredPlugin[$key]['fileName']);
    448 
    449           $tmpBuild['FROM'][]=call_user_func(Array('RBCallBack'.$key, 'getFrom'));
    450           $tmpBuild['JOIN'][]=call_user_func(Array('RBCallBack'.$key, 'getJoin'));
    451 
    452           foreach($val as $itemNumber => $param)
    453           {
    454             $tmpBuild['WHERE'][$itemNumber]=call_user_func(Array('RBCallBack'.$key, 'getWhere'), $param);
    455           }
    456         }
     633      foreach($val as $itemNumber => $param)
     634      {
     635        $tmpBuild['FILTER'][$key][]='('.call_user_func(Array('RBCallBack'.$key, 'getFilter'), $param).')';
    457636      }
    458637    }
     
    475654
    476655
     656    /* build FILTER
     657     */
     658    self::cleanArray($tmpBuild['FILTER']);
     659    if(count($tmpBuild['FILTER'])>0)
     660    {
     661      $tmp=array();
     662      foreach($tmpBuild['FILTER'] as $key=>$val)
     663      {
     664        $tmp[$key]='('.implode(' OR ', $val).')';
     665      }
     666      $build['FILTER']=' ('.implode(' AND ', $tmp).') ';
     667      // array_flip twice => simply remove identical values...
     668      //$build['FILTER']=' ('.implode(' AND ', array_flip(array_flip($tmpBuild['FILTER']))).') ';
     669    }
     670    unset($tmpBuild['FILTER']);
     671
     672
    477673    /* for each plugin, adds jointure with the IMAGE table
    478674     */
     
    480676    if(count($tmpBuild['JOIN'])>0)
    481677    {
    482       $build['WHERE'].=' AND ('.implode(' AND ', $tmpBuild['JOIN']).') ';
     678      if($build['WHERE']!='') $build['WHERE'].=' AND ';
     679      $build['WHERE'].=' ('.implode(' AND ', $tmpBuild['JOIN']).') ';
    483680    }
    484681    unset($tmpBuild['JOIN']);
     
    505702    $sql.=" ORDER BY pit.id ";
    506703
    507     $requestNumber=self::getNewRequest($user['id']);
    508 
    509704    $sql="INSERT INTO ".self::$tables['result_cache']." (SELECT DISTINCT $requestNumber, ".$build['SELECT']." $sql)";
     705
     706//echo $sql;
     707
     708    $returned="0;0";
    510709
    511710    $result=pwg_query($sql);
     
    513712    {
    514713      $numberItems=pwg_db_changes($result);
    515       self::updateRequest($requestNumber, $numberItems, 0, implode(',', $pluginList));
    516 
    517 
    518       return("$requestNumber;".$numberItems);
    519     }
    520 
    521     return("0;0");
     714      self::updateRequest($requestNumber, $numberItems, 0, implode(',', $pluginList), $build['FILTER']);
     715
     716      $returned="$requestNumber;".$numberItems;
     717    }
     718
     719    self::clearTempTable($requestNumber);
     720
     721    return($returned);
    522722  }
    523723
     
    554754      'SELECT' => Array(
    555755        'RB_PIT' => "pit.id AS imageId, pit.name AS imageName, pit.path AS imagePath", // from the piwigo's image table
    556         'RB_PIC' => "GROUP_CONCAT(pic.category_id SEPARATOR ',') AS imageCategoriesId",     // from the piwigo's image_category table
    557         'RB_PCT' => "GROUP_CONCAT(CASE WHEN pct.name IS NULL THEN '' ELSE pct.name END SEPARATOR '#sep#') AS imageCategoriesNames,
    558                      GROUP_CONCAT(CASE WHEN pct.permalink IS NULL THEN '' ELSE pct.permalink END SEPARATOR '#sep#') AS imageCategoriesPLink,
    559                      GROUP_CONCAT(CASE WHEN pct.dir IS NULL THEN 'V' ELSE 'P' END) AS imageCategoriesDir",   //from the piwigo's categories table
     756        'RB_PIC' => "GROUP_CONCAT(DISTINCT pic.category_id SEPARATOR ',') AS imageCategoriesId",     // from the piwigo's image_category table
     757        'RB_PCT' => "GROUP_CONCAT(DISTINCT CASE WHEN pct.name IS NULL THEN '' ELSE pct.name END SEPARATOR '#sep#') AS imageCategoriesNames,
     758                     GROUP_CONCAT(DISTINCT CASE WHEN pct.permalink IS NULL THEN '' ELSE pct.permalink END SEPARATOR '#sep#') AS imageCategoriesPLink,
     759                     GROUP_CONCAT(DISTINCT CASE WHEN pct.dir IS NULL THEN 'V' ELSE 'P' END) AS imageCategoriesDir",   //from the piwigo's categories table
    560760      ),
    561761      'FROM' => Array(
     
    591791        {
    592792          include_once($registeredPlugin[$val]['fileName']);
    593           $tmpBuild['SELECT'][$val]=call_user_func(Array('RBCallBack'.$val, 'getSelect'));
     793
     794          $tmp=explode(',', call_user_func(Array('RBCallBack'.$val, 'getSelect')));
     795          foreach($tmp as $key2=>$val2)
     796          {
     797            $tmp[$key2]=self::groupConcatAlias($val2, '#sep#');
     798          }
     799          $tmpBuild['SELECT'][$val]=implode(',', $tmp);
    594800          $tmpBuild['FROM'][$val]=call_user_func(Array('RBCallBack'.$val, 'getFrom'));
    595801          $tmpBuild['JOIN'][$val]=call_user_func(Array('RBCallBack'.$val, 'getJoin'));
     
    612818    /* build WHERE
    613819     */
     820    if($request['filter']!='') $tmpBuild['WHERE'][]=$request['filter'];
    614821    $build['WHERE']=implode(' AND ', $tmpBuild['WHERE']);
    615822    unset($tmpBuild['WHERE']);
     
    641848        .' ORDER BY pit.id '
    642849        .' LIMIT '.$limitFrom.', '.$numPerPage;
    643 
     850//echo $sql;
    644851    $result=pwg_query($sql);
    645852    if($result)
     
    737944    foreach($array as $key => $val)
    738945    {
    739       if(trim($val)=='') unset($array[$key]);
     946      if(is_array($val))
     947      {
     948        self::cleanArray($val);
     949        if(count($val)==0) unset($array[$key]);
     950      }
     951      elseif(trim($val)=='') unset($array[$key]);
    740952    }
    741953  }
     
    744956   * returns the alias for an attribute
    745957   *
    746    *  item1                  => returns item1
    747    *  table1.item1           => returns item1
    748    *  table1.item1 AS alias1 => returns alias1
    749    *  item1 AS alias1        => returns alias1
    750    *
    751    * @param String $var : value ti examine
     958   *  item1                          => returns item1
     959   *  table1.item1                   => returns item1
     960   *  table1.item1 AS alias1         => returns alias1
     961   *  item1 AS alias1                => returns alias1
     962   *  GROUP_CONCAT( .... ) AS alias1 => returns alias1
     963   *
     964   * @param String $var : value to examine
    752965   * @return String : the attribute name
    753966   */
    754967  static private function getAttribute($val)
    755968  {
    756     preg_match('/(?:(?:[A-Z0-9_]*)\.)?([A-Z0-9_]*)(?:\s+AS\s+([A-Z0-9_]*))?/i', trim($val), $result);
     969    preg_match('/(?:GROUP_CONCAT\(.*\)|(?:[A-Z0-9_]*)\.)?([A-Z0-9_]*)(?:\s+AS\s+([A-Z0-9_]*))?/i', trim($val), $result);
    757970    if(array_key_exists(2, $result))
    758971    {
     
    766979    {
    767980      return($val);
     981    }
     982  }
     983
     984
     985  /**
     986   * returns a a sql statement GROUP_CONCAT for an alias
     987   *
     988   *  item1                  => returns GROUP_CONCAT(item1 SEPARATOR $sep) AS item1
     989   *  table1.item1           => returns GROUP_CONCAT(table1.item1 SEPARATOR $sep) AS item1
     990   *  table1.item1 AS alias1 => returns GROUP_CONCAT(table1.item1 SEPARATOR $sep) AS alias1
     991   *  item1 AS alias1        => returns GROUP_CONCAT(item1 SEPARATOR $sep) AS alias1
     992   *
     993   * @param String $val : value to examine
     994   * @param String $sep : the separator
     995   * @return String : the attribute name
     996   */
     997  static private function groupConcatAlias($val, $sep=',')
     998  {
     999    /*
     1000     * table1.item1 AS alias1
     1001     *
     1002     * $result[3] = alias1
     1003     * $result[2] = item1
     1004     * $result[1] = table1.item1
     1005     */
     1006    preg_match('/((?:(?:[A-Z0-9_]*)\.)?([A-Z0-9_]*))(?:\s+AS\s+([A-Z0-9_]*))?/i', trim($val), $result);
     1007    if(array_key_exists(3, $result))
     1008    {
     1009      return("GROUP_CONCAT(".$result[1]." SEPARATOR '$sep') AS ".$result[3]);
     1010    }
     1011    elseif(array_key_exists(2, $result))
     1012    {
     1013      return("GROUP_CONCAT(".$result[1]." SEPARATOR '$sep') AS ".$result[2]);
     1014    }
     1015    else
     1016    {
     1017      return("GROUP_CONCAT($val SEPARATOR '$sep') AS ".$val);
    7681018    }
    7691019  }
     
    7781028  static private function getNewRequest($userId)
    7791029  {
    780     $sql="INSERT INTO ".self::$tables['request']." VALUES('', '$userId', '".date('Y-m-d H:i:s')."', 0, 0, '')";
     1030    $sql="INSERT INTO ".self::$tables['request']." VALUES('', '$userId', '".date('Y-m-d H:i:s')."', 0, 0, '', '')";
    7811031    $result=pwg_query($sql);
    7821032    if($result)
     
    7961046   * @return Boolean : true if request was updated, otherwise false
    7971047   */
    798   static private function updateRequest($requestId, $numItems, $executionTime, $pluginList)
     1048  static private function updateRequest($requestId, $numItems, $executionTime, $pluginList, $additionalFilter)
    7991049  {
    8001050    $sql="UPDATE ".self::$tables['request']."
    8011051            SET num_items = $numItems,
    8021052                execution_time = $executionTime,
    803                 connected_plugin = '$pluginList'
     1053                connected_plugin = '$pluginList',
     1054                filter = '".mysql_escape_string($additionalFilter)."'
    8041055            WHERE id = $requestId";
    8051056    $result=pwg_query($sql);
     
    8201071  {
    8211072    $returned=false;
    822     $sql="SELECT user_id, date, num_items, execution_time, connected_plugin
     1073    $sql="SELECT user_id, date, num_items, execution_time, connected_plugin, filter
    8231074          FROM ".self::$tables['request']."
    8241075          WHERE id = $requestId";
     
    8361087
    8371088  /**
    838    * internal function used by the executeRequest function
     1089   * internal function used by the executeRequest function for single record
     1090   * requests
    8391091   *
    8401092   * this function is called recursively
     
    8611113    }
    8621114    return('('.implode($operator, $returned).')');
     1115  }
     1116
     1117
     1118  /**
     1119   * internal function used by the executeRequest function for multi records
     1120   * requests
     1121   *
     1122   * this function is called recursively
     1123   *
     1124   * @param Array $groupContent :
     1125   * @param Array $items :
     1126   * @return String : a SQL request
     1127   */
     1128  static private function buildGroupRequest($groupContent, $whereItems, $groups, $operator, $requestNumber)
     1129  {
     1130    $returnedS='';
     1131    $returned=Array();
     1132    foreach($groupContent as $key => $val)
     1133    {
     1134      if(strpos($val['id'], 'iCbGroup')!==false)
     1135      {
     1136        preg_match('/[0-9]*$/i', $val['id'], $groupNumber);
     1137
     1138        $groupValue=self::buildGroupRequest($val['children'], $whereItems, $groups, $groups[$groupNumber[0]], $requestNumber);
     1139
     1140        if($groupValue!='')
     1141          $returned[]=array(
     1142            'mode'  => 'group',
     1143            'value' => $groupValue
     1144          );
     1145      }
     1146      else
     1147      {
     1148        preg_match('/[0-9]*$/i', $val['id'], $itemNumber);
     1149
     1150        $returned[]=array(
     1151          'mode'  => 'item',
     1152          'plugin' => $whereItems[$itemNumber[0]]['plugin'],
     1153          'value' => " (".$whereItems[$itemNumber[0]]['where'].") "
     1154        );
     1155      }
     1156    }
     1157
     1158    if(count($returned)>0)
     1159    {
     1160      if(strtolower(trim($operator))=='and')
     1161      {
     1162        $tId=0;
     1163        foreach($returned as $key=>$val)
     1164        {
     1165          if($tId>0) $returnedS.=" JOIN ";
     1166
     1167          if($val['mode']=='item')
     1168          {
     1169            $returnedS.="(SELECT ".call_user_func(Array('RBCallBack'.$val['plugin'], 'getImageId'))." AS imageId
     1170                          FROM ".call_user_func(Array('RBCallBack'.$val['plugin'], 'getFrom'))."
     1171                          WHERE ".$val['value'].") t".self::$tGlobalId." ";
     1172          }
     1173          else
     1174          {
     1175            $returnedS.="(".$val['value'].") t".self::$tGlobalId." ";
     1176          }
     1177
     1178          if($tId>0) $returnedS.=" ON t".(self::$tGlobalId-1).".imageId = t".self::$tGlobalId.".imageId ";
     1179          $tId++;
     1180          self::$tGlobalId++;
     1181        }
     1182        $returnedS="SELECT '$requestNumber', t".(self::$tGlobalId-$tId).".imageId FROM ".$returnedS;
     1183      }
     1184      else
     1185      {
     1186        foreach($returned as $key=>$val)
     1187        {
     1188          if($returnedS!='') $returnedS.=" UNION DISTINCT ";
     1189
     1190          if($val['mode']=='item')
     1191          {
     1192            $returnedS.="SELECT '$requestNumber', t".self::$tGlobalId.".imageId
     1193                          FROM (SELECT ".call_user_func(Array('RBCallBack'.$val['plugin'], 'getImageId'))." AS imageId
     1194                                FROM ".call_user_func(Array('RBCallBack'.$val['plugin'], 'getFrom'))."
     1195                                WHERE ".$val['value'].") t".self::$tGlobalId." ";
     1196          }
     1197          else
     1198          {
     1199            $returnedS.="SELECT '$requestNumber', t".self::$tGlobalId.".imageId FROM (".$val['value'].") t".self::$tGlobalId;
     1200          }
     1201
     1202          self::$tGlobalId++;
     1203        }
     1204      }
     1205    }
     1206
     1207    return($returnedS);
    8631208  }
    8641209
     
    9571302  /**
    9581303   * display search page
    959    */
    960   static public function displaySearchPage()
     1304   *
     1305   * @param Array $filter : an array of string ; each item is the name of a
     1306   *                        registered plugin
     1307   *                        if no parameters are given, no filter is applied
     1308   *                        otherwise only plugin wich name is given are
     1309   *                        accessible
     1310   */
     1311  static public function displaySearchPage($filter=array())
    9611312  {
    9621313    global $template, $lang;
    9631314
    9641315    load_language('rbuilder.lang', GPC_PATH);
     1316
     1317    if(is_string($filter)) $filter=array($filter);
     1318    $filter=array_flip($filter);
    9651319
    9661320    $template->set_filename('gpc_search_page',
     
    9711325    foreach($registeredPlugin as $key=>$val)
    9721326    {
    973       if(array_key_exists($key, $registeredPlugin))
     1327      if(array_key_exists($key, $registeredPlugin) and
     1328         (count($filter)==0 or array_key_exists($key, $filter)))
    9741329      {
    9751330        if(file_exists($registeredPlugin[$key]['fileName']))
  • extensions/GrumPluginClasses/css/rbuilder.css

    r6174 r6894  
    112112{
    113113  margin-bottom:3px;
     114  cursor:default;
     115}
     116
     117div#iMenuCaddieBar {
     118  margin-left:8px;
     119  padding-left:8px;
     120  border-left:1px solid;
     121  cursor:default;
     122}
     123
     124
     125div#iMenuCaddieBar div#iMenuCaddieItems {
     126  display:none;
     127  list-style-type:none;
     128  max-height:30px;
     129  position:absolute;
     130  padding:0px;
     131}
     132
     133div#iMenuCaddieBar ul {
     134  margin:4px 0 4px -8px;
     135  padding-bottom:2px;
     136  padding-left:16px;
     137  padding-right:2px;
     138}
     139
     140div#iMenuCaddieBar ul li {
     141  list-style-type:none;
     142  padding:4px;
     143}
     144
     145div#iMenuCaddieBar:hover  div#iMenuCaddieItems
     146{
     147  cursor:pointer;
     148  display:block;
     149}
  • extensions/GrumPluginClasses/language/fr_FR/rbuilder.lang.php

    r6174 r6894  
    1111$lang['gpc_rb_textOR']='Au moins un critère doit être vérifié';
    1212
     13$lang['gpc_manage_caddie'] = 'Gestion du panier';
     14$lang['gpc_add_caddie'] = 'Le résultat viens s\'ajouter au panier';
     15$lang['gpc_replace_caddie'] = 'Le résultat viens remplacer le panier';
     16$lang['gpc_the_caddie_is_updated'] = 'Le panier a été mis à jour';
     17$lang['gpc_something_is_wrong_on_the_server_side'] = 'Une anomalie est survenue lors de la connexion avec le serveur';
     18
     19
    1320?>
  • extensions/GrumPluginClasses/main.inc.php

    r6702 r6894  
    5353|         |            |   included)
    5454|         |            |
    55 | 3.2.0   | 2010/06/20 | * Enhance GPCTabSheet functionnalities
     55| 3.2.0   | 2010/09/12 | * Enhance GPCTabSheet functionnalities
    5656|         |            |   - possibility to choose tab classes
    5757|         |            | * Add the simpleTip.js
    58 |         |            |
    59 |         |            |
     58|         |            | * Enhance GPCRequestBuilder functionnalities
     59|         |            |   - now abble to manage complex request with multi-record
    6060|         |            |
    6161|         |            |
  • extensions/GrumPluginClasses/templates/GPCRequestBuilder_search.tpl

    r6208 r6894  
    6868          }
    6969          break;
     70        case 'fillCaddie':
     71          /* function 'fillCaddie' : allows to fill the caddie with the search result
     72           *
     73           */
     74          if(arguments.length==2)
     75          {
     76            fillCaddie(arguments[1], this.getRequestNumber());
     77          }
     78          break;
    7079      }
    7180    }
     
    132141        //$('#'+options.requestResultContent).html("");
    133142        show('buildQuery');
    134         alert('Something is wrong on the server-side !');
     143        alert('{/literal}{"gpc_something_is_wrong_on_the_server_side"|@translate}{literal}');
    135144      }
    136145    }
     
    160169      else
    161170      {
    162         alert('Something is wrong on the server-side !');
     171        alert('{/literal}{"gpc_something_is_wrong_on_the_server_side"|@translate}{literal}');
    163172      }
    164173    }
     
    203212    }
    204213
     214    /**
     215     * fill the caddie with the search results
     216     * @param String mode : 'add' or 'fill'
     217     */
     218    var fillCaddie = function (mode, requestNumber)
     219    {
     220      $('#iMenuCaddieImg').css('display', 'inline-block');
     221      $('#iMenuCaddieItems ul').css('display', 'none');
     222
     223      $.ajax(
     224        {
     225          type: "POST",
     226          url: "plugins/GrumPluginClasses/gpc_ajax.php",
     227          async: true,
     228          data: { ajaxfct:"admin.rbuilder.fillCaddie", fillMode:mode, requestNumber:requestNumber },
     229          success:
     230            function(msg)
     231            {
     232              $('#iMenuCaddieImg').css('display', 'none');
     233              $('#iMenuCaddieItems ul').css('display', 'block');
     234              alert('{/literal}{"gpc_the_caddie_is_updated"|@translate}{literal}');
     235            },
     236          error:
     237            function(msg)
     238            {
     239              $('#iMenuCaddieImg').css('display', 'none');
     240              $('#iMenuCaddieItems ul').css('display', 'block');
     241              alert('{/literal}{"gpc_something_is_wrong_on_the_server_side"|@translate}{literal}');
     242            },
     243        }
     244      );
     245    }
     246
    205247    init(optionsToSet);
    206248  }
     
    252294  {$dialogBox.content}
    253295{/foreach}
     296<div id='iRBCaddieNfo'></div>
    254297
    255298<form>
     
    264307
    265308      <div id='iMenuCriterions' >
    266         <div id='iMenuCTitle' class='gcLink gcBgInput cbButtons'>{'gpc_rb_add_criterions'|@translate}</div>
     309        <div id='iMenuCTitle' class='gcLink gcBgInput cbButtons'>{'gpc_rb_add_criterions'|@translate}&nbsp;&dArr;</div>
    267310        <div id='iMenuCItems'>
    268311          <ul class='gcBgInput'>
     
    292335    <div class='gcBgInput gcTextInput'>
    293336      <div id='iPagesNavigator' style='float:right;'></div>
    294       <div style='text-align:left;padding:4px;'>{'gpc_rb_number_of_item_found'|@translate}&nbsp;:&nbsp;<span id='iResultQueryNfo'></span></div>
     337      <div style='text-align:left;padding:4px;'>
     338        {'gpc_rb_number_of_item_found'|@translate}&nbsp;:&nbsp;<span id='iResultQueryNfo'></span>
     339        <div id='iMenuCaddie' style='display:inline-block;'>
     340          <div id='iMenuCaddieBar'>
     341            <div id='iMenuCaddieText' class='gcLink gcBgInput'>{'gpc_manage_caddie'|@translate}&dArr;
     342            <div id='iMenuCaddieImg' style='display:none;width:16px;height:16px;background:url(./plugins/GrumPluginClasses/icons/processing.gif) no-repeat 0 0 transparent;'>&nbsp;</div>
     343            <div id='iMenuCaddieItems'>
     344              <ul class='gcBgInput'>
     345                <li class='gcBgInput'><a onclick="im.doAction('fillCaddie', 'add');">{'gpc_add_caddie'|@translate}</a></li>
     346                <li class='gcBgInput'><a onclick="im.doAction('fillCaddie', 'replace');">{'gpc_replace_caddie'|@translate}</a></li>
     347              </ul>
     348            </div>
     349          </div>
     350
     351        </span>
     352      </div>
    295353    </div>
    296354
Note: See TracChangeset for help on using the changeset viewer.