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