source: extensions/ASearchEngine/ase_rb_callback_keyword.class.inc.php @ 26055

Last change on this file since 26055 was 7318, checked in by grum, 14 years ago

fix some bugs and implement public interface

  • Property svn:executable set to *
File size: 6.1 KB
Line 
1<?php
2/* -----------------------------------------------------------------------------
3  Plugin     : Advanced Search Engine
4  Author     : Grum
5    email    : grum@piwigo.org
6    website  : http://photos.grum.fr
7
8    << May the Little SpaceFrog be with you ! >>
9  ------------------------------------------------------------------------------
10  See main.inc.php for release information
11
12
13  --------------------------------------------------------------------------- */
14
15  if(!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
16
17  include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php');
18
19load_language('plugin.lang', ASE_PATH);
20
21class RBCallBackASEKeyword extends GPCSearchCallback {
22
23  /**
24   * the getImageId returns the name of the image id attribute
25   * return String
26   */
27  static public function getImageId()
28  {
29    return("ase_pitk.id");
30  }
31
32  /**
33   * the getSelect function must return an attribute list separated with a comma
34   *
35   * "att1, att2, att3, att4"
36   */
37  static public function getSelect($param="")
38  {
39    $returned="";
40
41    if($param['searchName']=='y')
42    {
43      $returned=" ase_pitk.name AS optName";
44    };
45
46    if($param['searchDesc']=='y')
47    {
48      $returned.=($returned==''?'':',')." ase_pitk.comment AS optDesc";
49    };
50
51    if($param['searchFileName']=='y')
52    {
53      $returned.=($returned==''?'':',')." ase_pitk.file AS optFileName";
54    };
55
56    return($returned);
57  }
58
59  /**
60   * the getFrom function must return a tables list separated with a comma
61   *
62   * "table1, (table2 left join table3 on table2.key = table3.key), table4"
63   */
64  static public function getFrom($param="")
65  {
66    global $prefixeTable;
67
68    return(IMAGES_TABLE." ase_pitk ");
69  }
70
71  /**
72   * the getWhere function must return a ready to use where clause
73   *
74   * "(att1 = value0 OR att2 = value1) AND att4 LIKE value2 "
75   */
76  static public function getWhere($param="")
77  {
78    global $user;
79
80    $clauses=array();
81
82    if($param['searchName']=='y')
83    {
84      $clauses[]=self::getWhereClause('name', $param['keyword'], $param['optIgnoreCase'], $param['optWholeWords']);
85    }
86
87    if($param['searchDesc']=='y')
88    {
89      $clauses[]=self::getWhereClause('comment', $param['keyword'], $param['optIgnoreCase'], $param['optWholeWords']);
90    }
91
92    if($param['searchFileName']=='y')
93    {
94      $clauses[]=self::getWhereClause('file', $param['keyword'], $param['optIgnoreCase'], $param['optWholeWords']);
95    }
96
97    $returned=implode(' OR ', $clauses);
98
99    return($returned);
100  }
101
102  static private function getWhereClause($target, $keyword, $case, $wwords)
103  {
104    if($target=='file' and $case=='y')
105    {
106      $returned="LOWER(ase_pitk.$target) REGEXP ";
107      $keyword=strtolower($keyword);
108    }
109    else
110    {
111      $returned="ase_pitk.$target REGEXP ";
112    }
113
114    if($case=='n') $returned.=" BINARY ";
115
116    if($wwords=='n')
117    {
118      $returned.=" '$keyword'";
119    }
120    else
121    {
122      $returned.=" '[[:<:]]".$keyword."[[:>:]]'";
123    }
124    return($returned);
125  }
126
127  /**
128   * the getJoin function must return a ready to use where allowing to join the
129   * IMAGES table (key : id) with given conditions
130   *
131   * "att3 = pit.id "
132   */
133  static public function getJoin($param="")
134  {
135    return("ase_pitk.id = pit.id");
136  }
137
138
139  /**
140   * the getFilter function must return a ready to use where clause
141   * this where clause is used to filter the cache when the used tables can
142   * return more than one result
143   *
144   * the filter can be empty, can be equal to the where clause, or can be equal
145   * to a sub part of the where clause
146   *
147   */
148  static public function getFilter($param="")
149  {
150    return("");
151  }
152
153  /**
154   * this function is called by the request builder, allowing to display plugin
155   * data with a specific format
156   *
157   * @param Array $attributes : array of ('attribute_name' => 'attribute_value')
158   * @return String : HTML formatted value
159   */
160  static public function formatData($attributes)
161  {
162    /* attributes is an array :
163     *    Array(
164     *      'csColors' => 'color1,color2,color3,...,colorN',
165     *      'csColorsPct' => 'pct1,pct2,pct3,...,pctN'
166     *    );
167     */
168    $returned="";
169    if(array_key_exists('optName', $attributes))
170    {
171      $returned.="<span style='font-weight:bold;'>".l10n('ase_optName')."</span>&nbsp;:&nbsp;".$attributes['optName'];
172    }
173    if(array_key_exists('optDesc', $attributes))
174    {
175      $returned.=($returned==''?'':'<br>')."<span style='font-weight:bold;'>".l10n('ase_optDesc')."</span>&nbsp;:&nbsp;".$attributes['optDesc'];
176    }
177    if(array_key_exists('optFileName', $attributes))
178    {
179      $returned.=($returned==''?'':'<br>')."<span style='font-weight:bold;'>".l10n('ase_optFileName')."</span>&nbsp;:&nbsp;".$attributes['optFileName'];
180    }
181
182    return($returned);
183  }
184
185
186
187  /**
188   * this function is called by the request builder to make the search page, and
189   * must return the HTML & JS code of the dialogbox used to select criterion
190   *
191   * Notes :
192   *  - the dialogbox is a JS object with a public method 'show'
193   *  - when the method show is called, one parameter is given by the request
194   *    builder ; the parameter is an object defined as this :
195   *      {
196   *        cBuilder: an instance of the criteriaBuilder object used in the page,
197   *        eventOK : a callback function, called when the OK button is pushed
198   *        id:
199   *      }
200   *
201   *
202   *
203   *
204   * @param String $mode : can take 'admin' or 'public' values, allowing to
205   *                       return different interface if needed
206   * @return String : HTML formatted value
207   */
208  static public function getInterfaceContent($mode='admin')
209  {
210    return(ASE_functions::dialogBoxASEKeyword());
211  }
212
213  /**
214   * this function returns the label displayed in the criterion menu
215   *
216   * @return String : label displayed in the criterions menu
217   */
218  static public function getInterfaceLabel()
219  {
220    return(l10n('ase_add_keyword'));
221  }
222
223  /**
224   * this function returns the name of the dialog box class
225   *
226   * @return String : name of the dialogbox class
227   */
228  static public function getInterfaceDBClass()
229  {
230    return('dialogChooseASEKeywordBox');
231  }
232
233}
234
235?>
Note: See TracBrowser for help on using the repository browser.