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

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

Plugin is now in a usable state (color analysis is not yet tuned)

File size: 4.0 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(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php');
18
19load_language('plugin.lang', CSTAT_PATH);
20
21class RBCallBackColorStat extends GPCSearchCallback {
22
23  /**
24   * the getSelect function must return an attribute list separated with a comma
25   *
26   * "att1, att2, att3, att4"
27   */
28  static public function getSelect($param="")
29  {
30    return("pci.colors AS csColors, pci.colors_pct AS csColorsPct");
31  }
32
33  /**
34   * the getFrom function must return a tables list separated with a comma
35   *
36   * "table1, (table2 left join table3 on table2.key = table3.key), table4"
37   */
38  static public function getFrom($param="")
39  {
40    global $prefixeTable;
41
42    return($prefixeTable."cstat_images pci");
43  }
44
45  /**
46   * the getWhere function must return a ready to use where clause
47   *
48   * "(att1 = value0 OR att2 = value1) AND att4 LIKE value2 "
49   */
50  static public function getWhere($param="")
51  {
52    $returned='';
53
54    $not=false;
55    if($param['mode']=='not')
56    {
57      $param['mode']='or';
58      $not=true;
59    }
60
61    $colors=split(',', $param['colors']);
62    if(count($colors)>0)
63    {
64      foreach($colors as $key=>$val)
65      {
66        if($returned!='') $returned.=" ".$param['mode']." ";
67        $returned.=" pci.colors LIKE '%".trim($val)."%'";
68      }
69    }
70
71    if($not) $returned=' NOT('.$returned.') ';
72
73    return($returned);
74  }
75
76  /**
77   * the getJoin function must return a ready to use where allowing to join the
78   * IMAGES table (key : id) with given conditions
79   *
80   * "att3 = pit.id "
81   */
82  static public function getJoin($param="")
83  {
84    return("pci.image_id = pit.id");
85  }
86
87
88
89  /**
90   * this function is called by the request builder, allowing to display plugin
91   * data with a specific format
92   *
93   * @param Array $attributes : array of ('attribute_name' => 'attribute_value')
94   * @return String : HTML formatted value
95   */
96  static public function formatData($attributes)
97  {
98    /* attributes is an array :
99     *    Array(
100     *      'csColors' => 'color1,color2,color3,...,colorN',
101     *      'csColorsPct' => 'pct1,pct2,pct3,...,pctN'
102     *    );
103     */
104    $colors=explode(',', $attributes['csColors']);
105    $pct=explode(',', $attributes['csColorsPct']);
106
107    $colorList=Array();
108    $i=0;
109    foreach($colors as $key => $val)
110    {
111      $colorList[$val]=$pct[$i];
112      $i++;
113    }
114    return(self::htmlColorList($colorList, 16, 15,"","color1px"));
115  }
116
117
118  /**
119   * return HTML code for a given colors list
120   *
121   * ==> this is the same function than the CStat_root::htmlColorList() function
122   *     make a copy here only top optimize performance (don't load the
123   *     CStat_root file for one function)
124   *
125   * @param Array $colors : list of colors
126   * @param Int $size     : size for colorbox in the HTML table
127   * @return String : HTML code
128   */
129  static private function htmlColorList($colorList, $split=8, $size=5, $id="", $class="")
130  {
131    global $template;
132
133    $template->set_filename('color_table_page',
134                  dirname(__FILE__).'/templates/cstat_color_table.tpl');
135
136    $colors=Array();
137
138    $row=0;
139    $num=0;
140    foreach($colorList as $key => $val)
141    {
142      $colors[$row][]=Array('color' => $key, 'pct' => $val, 'num' => "");
143      $num++;
144      if($num==$split)
145      {
146        $num=0;
147        $row++;
148      }
149    }
150
151    $data=array(
152      'colorTable' => $colors,
153      'size' => $size,
154      'id' => $id,
155      'class' => $class,
156      'br' => ' / ',
157    );
158
159    $template->assign('data', $data);
160    unset($data);
161
162    return($template->parse('color_table_page', true));
163  }
164
165}
166
167?>
Note: See TracBrowser for help on using the repository browser.