source: extensions/AMetaData/amd_rb_callback.class.inc.php @ 15907

Revision 7399, 7.4 KB checked in by grum, 9 years ago (diff)

Fix many bugs
bug:1894, bug:1898, bug:1911, bug:1863, bug:1955, bug:1956, bug:1925

Line 
1<?php
2/*
3 * -----------------------------------------------------------------------------
4 * Plugin Name: Advanced MetaData
5 * -----------------------------------------------------------------------------
6 * Author     : Grum
7 *   email    : grum@piwigo.org
8 *   website  : http://photos.grum.fr
9 *   PWG user : http://forum.piwigo.org/profile.php?id=3706
10 *
11 *   << May the Little SpaceFrog be with you ! >>
12 *
13 * -----------------------------------------------------------------------------
14 *
15 * See main.inc.php for release information
16 *
17 * RBCallBackAMetadata classe => used for the request builder
18 *
19 * -----------------------------------------------------------------------------
20 */
21  global $user;
22
23  if(!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
24
25  //include_once('')
26  include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php');
27
28  load_language('plugin.lang', AMD_PATH);
29
30
31  if(isset($user['language']))
32  {
33    L10n::setLanguage($user['language']);
34  }
35
36class RBCallBackAMetaData extends GPCSearchCallback {
37
38  /**
39   * the getImageId returns the name of the image id attribute
40   * return String
41   */
42  static public function getImageId()
43  {
44    return("pait.imageId");
45  }
46
47  /**
48   * the getSelect function must return an attribute list separated with a comma
49   *
50   * "att1, att2, att3, att4"
51   */
52  static public function getSelect($param="")
53  {
54    return(" pait.value AS amdValue, paut.name AS amdName ");
55  }
56
57  /**
58   * the getFrom function must return a tables list separated with a comma
59   *
60   * "table1, (table2 left join table3 on table2.key = table3.key), table4"
61   */
62  static public function getFrom($param="")
63  {
64    global $prefixeTable;
65
66    return($prefixeTable."amd_images_tags pait
67                            LEFT JOIN ".$prefixeTable."amd_used_tags paut
68                            ON pait.numId = paut.numId ");
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    switch($param['conditionIf'])
79    {
80      case 'E':
81        $returned="pait.numId = ".$param['metaNumId'];
82        break;
83      case '!E':
84        $returned="pait.numId = ".$param['metaNumId'];
85        break;
86      case '=':
87        $returned="pait.numId = ".$param['metaNumId']." AND ";
88
89        $tmp=array();
90        foreach($param['listValues'] as $key=>$val)
91        {
92          $tmp[]="pait.value = '".$val."'";
93        }
94        $returned.="(".implode(' OR ', $tmp).")";
95        break;
96      case '!=':
97        $returned="pait.numId = ".$param['metaNumId']." AND NOT ";
98
99        $tmp=array();
100        foreach($param['listValues'] as $key=>$val)
101        {
102          $tmp[]="pait.value = '".$val."'";
103        }
104        $returned.="(".implode(' OR ', $tmp).")";
105        break;
106      case '%':
107        $returned="pait.numId = ".$param['metaNumId']." AND ";
108
109        $tmp=array();
110        foreach($param['listValues'] as $key=>$val)
111        {
112          $tmp[]="pait.value LIKE '%".$val."%'";
113        }
114        $returned.="(".implode(' OR ', $tmp).")";
115        break;
116      case '!%':
117        $returned="pait.numId = ".$param['metaNumId']." AND NOT ";
118
119        $tmp=array();
120        foreach($param['listValues'] as $key=>$val)
121        {
122          $tmp[]="pait.value LIKE '%".$val."%'";
123        }
124        $returned.="(".implode(' OR ', $tmp).")";
125        break;
126      case '^%':
127        $returned="pait.numId = ".$param['metaNumId']." AND ";
128
129        $tmp=array();
130        foreach($param['listValues'] as $key=>$val)
131        {
132          $tmp[]="pait.value LIKE '".$val."%'";
133        }
134        $returned.="(".implode(' OR ', $tmp).")";
135        break;
136      case '!^%':
137        $returned="pait.numId = ".$param['metaNumId']." AND NOT ";
138
139        $tmp=array();
140        foreach($param['listValues'] as $key=>$val)
141        {
142          $tmp[]="pait.value LIKE '".$val."%'";
143        }
144        $returned.="(".implode(' OR ', $tmp).")";
145        break;
146      case '$%':
147        $returned="pait.numId = ".$param['metaNumId']." AND ";
148
149        $tmp=array();
150        foreach($param['listValues'] as $key=>$val)
151        {
152          $tmp[]="pait.value LIKE '%".$val."'";
153        }
154        $returned.="(".implode(' OR ', $tmp).")";
155        break;
156      case '!$%':
157        $returned="pait.numId = ".$param['metaNumId']." AND NOT ";
158
159        $tmp=array();
160        foreach($param['listValues'] as $key=>$val)
161        {
162          $tmp[]="pait.value LIKE '%".$val."'";
163        }
164        $returned.="(".implode(' OR ', $tmp).")";
165        break;
166    }
167
168    return($returned);
169  }
170
171  /**
172   * the getJoin function must return a ready to use where allowing to join the
173   * IMAGES table (key : id) with given conditions
174   *
175   * "att3 = pit.id "
176   */
177  static public function getJoin($param="")
178  {
179    return("pit.id = pait.imageId");
180  }
181
182
183  /**
184   * the getFilter function must return a ready to use where clause
185   * this where clause is used to filter the cache when the used tables can
186   * return more than one result
187   *
188   * the filter is equal to the where clause, or is equal to a part of the where
189   * clause
190   *
191   */
192  static public function getFilter($param="")
193  {
194    return("pait.numId = ".$param['metaNumId']);
195  }
196
197
198  /**
199   * this function is called by the request builder, allowing to display plugin
200   * data with a specific format
201   *
202   * @param Array $attributes : array of ('attribute_name' => 'attribute_value')
203   * @return String : HTML formatted value
204   */
205  static public function formatData($attributes)
206  {
207    /* attributes is an array :
208     *    Array(
209     *      'amdValue' => 'value1#sep#value2#...#sep#valueN'
210     *      'amdTagId' => 'tagId1#sep#tagId2#...#sep#tagIdN'
211     *    );
212     */
213    $returned='';
214
215    $values=explode('#sep#', $attributes['amdValue']);
216    $tagIds=explode('#sep#', $attributes['amdName']);
217
218    foreach($tagIds as $key => $val)
219    {
220      if($returned!='') $returned.='<br>';
221
222      $returned.="<span style='font-weight:bold;'>".L10n::get($val)."</span>&nbsp;:&nbsp;".L10n::get($values[$key]);
223    }
224
225    return($returned);
226  }
227
228
229  /**
230   * this function is called by the request builder to make the search page, and
231   * must return the HTML & JS code of the dialogbox used to select criterion
232   *
233   * Notes :
234   *  - the dialogbox is a JS object with a public method 'show'
235   *  - when the method show is called, one parameter is given by the request
236   *    builder ; the parameter is an object defined as this :
237   *      {
238   *        cBuilder: an instance of the criteriaBuilder object used in the page,
239   *        eventOK : a callback function, called when the OK button is pushed
240   *        id:
241   *      }
242   *
243   *
244   *
245   *
246   * @param String $mode : can take 'admin' or 'public' values, allowing to
247   *                       return different interface if needed
248   * @return String : HTML formatted value
249   */
250  static public function getInterfaceContent($mode='admin')
251  {
252    return(AMD_functions::dialogBoxMetadata());
253  }
254
255  /**
256   * this function returns the label displayed in the criterion menu
257   *
258   * @return String : label displayed in the criterions menu
259   */
260  static public function getInterfaceLabel()
261  {
262    return(l10n('g003_add_metadata'));
263  }
264
265  /**
266   * this function returns the name of the dialog box class
267   *
268   * @return String : name of the dialogbox class
269   */
270  static public function getInterfaceDBClass()
271  {
272    return('dialogChooseMetadataBox');
273  }
274
275}
276
277?>
Note: See TracBrowser for help on using the repository browser.