Ignore:
Timestamp:
Oct 24, 2010, 11:29:20 AM (13 years ago)
Author:
grum
Message:

externalise and pack some js ; rename criteriaBuilder.js files ; improve templates & css theming ; fix bug and add functionnalities for request builder ; update key languages

File:
1 edited

Legend:

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

    r7327 r7370  
    8686/**
    8787 *
    88  * Preparing the cache
    89  * -------------------
     88 * Preparing the temporary table => doCache()
     89 * ------------------------------------------
    9090 * To prepare the cache, the request builder use the following functions :
     91 *  - getImageId
    9192 *  - getFrom
    9293 *  - getWhere
    93  *  - getJoin
    94  *  - getImageId
     94 *  - getHaving
    9595 *
    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 * -----------------------------------
    98104 * To retrieve the image informations, the request builder uses the following
    99105 * functions :
     
    101107 *  - getFrom
    102108 *  - getJoin
    103  *  - getFilter (in fact, the result of this function is stored while the cache
    104  *               is builded, but it is used only when retrieving the results for
    105  *               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)
    106112 *  - formatData
    107113 *
     
    120126 *       to 'y'
    121127 *
    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"
    128134 *
     135 *  Examples :
     136 *   - plugin AdvancedMetadata use getFilter
     137 *   - plugin AdvancedSearchEngine, module ASETag use getHaving and getWhere
    129138 */
    130139class GPCSearchCallback {
     
    172181    return("");
    173182  }
     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
    174197
    175198  /**
     
    201224    return("");
    202225  }
     226
    203227
    204228  /**
     
    487511    $baseName=basename(dirname(dirname(__FILE__))).'/css/';
    488512    $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
    489515
    490516    $baseName=basename(dirname(dirname(__FILE__))).'/js/';
     
    492518    GPCCore::addHeaderJS('gpc.interface', 'plugins/'.$baseName.'external/interface/interface.js');
    493519    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');
    495521
    496522    $template->append('head_elements',
    497523"<script type=\"text/javascript\">
    498524  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',
    505535  }
    506536</script>");
     
    562592    //$imageIdName=call_user_func(Array('RBCallBack'.$plugin, 'getImageId'));
    563593
    564     $tempWHERE=array();
     594    $tempClauses=array();
    565595    foreach($_REQUEST['extraData'] as $key => $extraData)
    566596    {
    567       $tmpWHERE[$key]=array(
     597      $tempClauses[$key]=array(
    568598        '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']),
    570601      );
    571602    }
    572603
    573     $sql="INSERT INTO ".self::$tables['temp']." ".self::buildGroupRequest($_REQUEST[$_REQUEST['requestName']], $tmpWHERE, $_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;
    575606    $result=pwg_query($sql);
    576607
     
    610641      'WHERE' => 'pit.level <= '.$user['level'],
    611642      'GROUPBY' => '',
    612       'FILTER' => '',
     643      'FILTER' => ''
    613644    );
    614645    $tmpBuild=Array(
     
    706737      }
    707738      $build['FILTER']=' ('.implode(' AND ', $tmp).') ';
    708       // array_flip twice => simply remove identical values...
    709       //$build['FILTER']=' ('.implode(' AND ', array_flip(array_flip($tmpBuild['FILTER']))).') ';
    710739    }
    711740    unset($tmpBuild['FILTER']);
     
    745774    $sql="INSERT INTO ".self::$tables['result_cache']." (SELECT DISTINCT $requestNumber, ".$build['SELECT']." $sql)";
    746775
    747 
     776//echo $sql;
    748777    $returned="0;0";
    749778
     
    768797   * @param Integer $pageNumber : the page to be returned
    769798   * @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
    770801   * @return String : formatted HTML code
    771802   */
     
    869900    unset($tmpBuild['WHERE']);
    870901
    871 
    872902    /* for each plugin, adds jointure with the IMAGE table
    873903     */
     
    889919    $imagesList=Array();
    890920
    891     $sql='SELECT '.$build['SELECT']
     921    $sql='SELECT DISTINCT '.$build['SELECT']
    892922        .' FROM '.$build['FROM']
    893923        .' 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
    897929//echo $sql;
    898930    $result=pwg_query($sql);
     
    10561088    if(array_key_exists(3, $result))
    10571089    {
    1058       return("GROUP_CONCAT(".$result[1]." SEPARATOR '$sep') AS ".$result[3]);
     1090      return("GROUP_CONCAT(DISTINCT ".$result[1]." SEPARATOR '$sep') AS ".$result[3]);
    10591091    }
    10601092    elseif(array_key_exists(2, $result))
    10611093    {
    1062       return("GROUP_CONCAT(".$result[1]." SEPARATOR '$sep') AS ".$result[2]);
     1094      return("GROUP_CONCAT(DISTINCT ".$result[1]." SEPARATOR '$sep') AS ".$result[2]);
    10631095    }
    10641096    else
    10651097    {
    1066       return("GROUP_CONCAT($val SEPARATOR '$sep') AS ".$val);
     1098      return("GROUP_CONCAT(DISTINCT $val SEPARATOR '$sep') AS ".$val);
    10671099    }
    10681100  }
     
    11751207   *
    11761208   * @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)
    11811216  {
    11821217    $returnedS='';
     
    11881223        preg_match('/[0-9]*$/i', $val['id'], $groupNumber);
    11891224
    1190         $groupValue=self::buildGroupRequest($val['children'], $whereItems, $groups, $groups[$groupNumber[0]], $requestNumber);
     1225        $groupValue=self::buildGroupRequest($val['children'], $clausesItems, $groups, $groups[$groupNumber[0]], $requestNumber);
    11911226
    11921227        if($groupValue!='')
     
    12021237        $returned[]=array(
    12031238          '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'].") ":'',
    12061242        );
    12071243      }
     
    12201256          {
    12211257            $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." ";
    12241264          }
    12251265          else
     
    12321272          self::$tGlobalId++;
    12331273        }
    1234         $returnedS="SELECT '$requestNumber', t".(self::$tGlobalId-$tId).".imageId FROM ".$returnedS;
     1274        $returnedS="SELECT DISTINCT '$requestNumber', t".(self::$tGlobalId-$tId).".imageId FROM ".$returnedS;
    12351275      }
    12361276      else
     
    12441284            $returnedS.="SELECT DISTINCT '$requestNumber', t".self::$tGlobalId.".imageId
    12451285                          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." ";
    12481292          }
    12491293          else
    12501294          {
    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;
    12521296          }
    12531297
Note: See TracChangeset for help on using the changeset viewer.