source: extensions/ColorStat/cstat_rb_callback.class.inc.php @ 32729

Last change on this file since 32729 was 6893, checked in by grum, 14 years ago

Update plugin version to 1.0.2
bug:1796, bug:1854 + update CStat for GPC 3.2.0

File size: 5.8 KB
Line 
1<?php
2/* -----------------------------------------------------------------------------
3  Plugin     : ColorStat
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('')
18  include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php');
19
20load_language('plugin.lang', CSTAT_PATH);
21
22class RBCallBackColorStat extends GPCSearchCallback {
23
24  /**
25   * the getImageId returns the name of the image id attribute
26   * return String
27   */
28  static public function getImageId()
29  {
30    return("pci.image_id");
31  }
32
33  /**
34   * the getSelect function must return an attribute list separated with a comma
35   *
36   * "att1, att2, att3, att4"
37   */
38  static public function getSelect($param="")
39  {
40    return("pci.colors AS csColors, pci.colors_pct AS csColorsPct");
41  }
42
43  /**
44   * the getFrom function must return a tables list separated with a comma
45   *
46   * "table1, (table2 left join table3 on table2.key = table3.key), table4"
47   */
48  static public function getFrom($param="")
49  {
50    global $prefixeTable;
51
52    return($prefixeTable."cstat_images pci");
53  }
54
55  /**
56   * the getWhere function must return a ready to use where clause
57   *
58   * "(att1 = value0 OR att2 = value1) AND att4 LIKE value2 "
59   */
60  static public function getWhere($param="")
61  {
62    $returned='';
63
64    $not=false;
65    if($param['mode']=='not')
66    {
67      $param['mode']='or';
68      $not=true;
69    }
70
71    $colors=explode(',', $param['colors']);
72    if(count($colors)>0)
73    {
74      foreach($colors as $key=>$val)
75      {
76        if($returned!='') $returned.=" ".$param['mode']." ";
77        $returned.=" pci.analyzed='y' AND pci.colors LIKE '%".trim($val)."%'";
78      }
79    }
80
81    if($not) $returned=' NOT('.$returned.') ';
82
83    return($returned);
84  }
85
86  /**
87   * the getJoin function must return a ready to use where allowing to join the
88   * IMAGES table (key : id) with given conditions
89   *
90   * "att3 = pit.id "
91   */
92  static public function getJoin($param="")
93  {
94    return("pci.image_id = pit.id");
95  }
96
97
98  /**
99   * the getFilter function must return a ready to use where clause
100   * this where clause is used to filter the cache when the used tables can
101   * return more than one result
102   *
103   * the filter can be empty, can be equal to the where clause, or can be equal
104   * to a sub part of the where clause
105   *
106   */
107  static public function getFilter($param="")
108  {
109    return(self::getWhere($param));
110  }
111
112  /**
113   * this function is called by the request builder, allowing to display plugin
114   * data with a specific format
115   *
116   * @param Array $attributes : array of ('attribute_name' => 'attribute_value')
117   * @return String : HTML formatted value
118   */
119  static public function formatData($attributes)
120  {
121    /* attributes is an array :
122     *    Array(
123     *      'csColors' => 'color1,color2,color3,...,colorN',
124     *      'csColorsPct' => 'pct1,pct2,pct3,...,pctN'
125     *    );
126     */
127    $colors=explode(',', $attributes['csColors']);
128    $pct=explode(',', $attributes['csColorsPct']);
129
130    $colorList=Array();
131    $i=0;
132    foreach($colors as $key => $val)
133    {
134      $colorList[$val]=$pct[$i];
135      $i++;
136    }
137    return(self::htmlColorList($colorList, 16, 15,"","color1px"));
138  }
139
140
141  /**
142   * return HTML code for a given colors list
143   *
144   *
145   * @param Array $colors : list of colors
146   * @param Int $size     : size for colorbox in the HTML table
147   * @return String : HTML code
148   */
149  static private function htmlColorList($colorList, $split=8, $size=5, $id="", $class="")
150  {
151    global $template;
152
153    $template->set_filename('color_table_page',
154                  dirname(__FILE__).'/templates/cstat_color_table.tpl');
155
156    $colors=Array();
157
158    $row=0;
159    $num=0;
160    foreach($colorList as $key => $val)
161    {
162      $colors[$row][]=Array('color' => $key, 'pct' => $val, 'num' => "");
163      $num++;
164      if($num==$split)
165      {
166        $num=0;
167        $row++;
168      }
169    }
170
171    $data=array(
172      'colorTable' => $colors,
173      'size' => $size,
174      'id' => $id,
175      'class' => $class,
176      'br' => '<br>',
177    );
178
179    $template->assign('data', $data);
180    unset($data);
181
182    return($template->parse('color_table_page', true));
183  }
184
185
186  /**
187   * this function is called by the request builder to make the search page, and
188   * must return the HTML & JS code of the dialogbox used to select criterion
189   *
190   * Notes :
191   *  - the dialogbox is a JS object with a public method 'show'
192   *  - when the method show is called, one parameter is given by the request
193   *    builder ; the parameter is an object defined as this :
194   *      {
195   *        cBuilder: an instance of the criteriaBuilder object used in the page,
196   *        eventOK : a callback function, called when the OK button is pushed
197   *        id:
198   *      }
199   *
200   *
201   *
202   *
203   * @param String $mode : can take 'admin' or 'public' values, allowing to
204   *                       return different interface if needed
205   * @return String : HTML formatted value
206   */
207  static public function getInterfaceContent($mode='admin')
208  {
209    return(CStat_functions::dialogBoxColor());
210  }
211
212  /**
213   * this function returns the label displayed in the criterion menu
214   *
215   * @return String : label displayed in the criterions menu
216   */
217  static public function getInterfaceLabel()
218  {
219    return(l10n('cstat_add_colors'));
220  }
221
222  /**
223   * this function returns the name of the dialog box class
224   *
225   * @return String : name of the dialogbox class
226   */
227  static public function getInterfaceDBClass()
228  {
229    return('dialogChooseColorBox');
230  }
231
232}
233
234?>
Note: See TracBrowser for help on using the repository browser.