> ------------------------------------------------------------------------------ See main.inc.php for release information --------------------------------------------------------------------------- */ if(!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php'); load_language('plugin.lang', CSTAT_PATH); class RBCallBackColorStat extends GPCSearchCallback { /** * the getSelect function must return an attribute list separated with a comma * * "att1, att2, att3, att4" */ static public function getSelect($param="") { return("pci.colors AS csColors, pci.colors_pct AS csColorsPct"); } /** * the getFrom function must return a tables list separated with a comma * * "table1, (table2 left join table3 on table2.key = table3.key), table4" */ static public function getFrom($param="") { global $prefixeTable; return($prefixeTable."cstat_images pci"); } /** * the getWhere function must return a ready to use where clause * * "(att1 = value0 OR att2 = value1) AND att4 LIKE value2 " */ static public function getWhere($param="") { $returned=''; $not=false; if($param['mode']=='not') { $param['mode']='or'; $not=true; } $colors=split(',', $param['colors']); if(count($colors)>0) { foreach($colors as $key=>$val) { if($returned!='') $returned.=" ".$param['mode']." "; $returned.=" pci.colors LIKE '%".trim($val)."%'"; } } if($not) $returned=' NOT('.$returned.') '; return($returned); } /** * the getJoin function must return a ready to use where allowing to join the * IMAGES table (key : id) with given conditions * * "att3 = pit.id " */ static public function getJoin($param="") { return("pci.image_id = pit.id"); } /** * this function is called by the request builder, allowing to display plugin * data with a specific format * * @param Array $attributes : array of ('attribute_name' => 'attribute_value') * @return String : HTML formatted value */ static public function formatData($attributes) { /* attributes is an array : * Array( * 'csColors' => 'color1,color2,color3,...,colorN', * 'csColorsPct' => 'pct1,pct2,pct3,...,pctN' * ); */ $colors=explode(',', $attributes['csColors']); $pct=explode(',', $attributes['csColorsPct']); $colorList=Array(); $i=0; foreach($colors as $key => $val) { $colorList[$val]=$pct[$i]; $i++; } return(self::htmlColorList($colorList, 16, 15,"","color1px")); } /** * return HTML code for a given colors list * * ==> this is the same function than the CStat_root::htmlColorList() function * make a copy here only top optimize performance (don't load the * CStat_root file for one function) * * @param Array $colors : list of colors * @param Int $size : size for colorbox in the HTML table * @return String : HTML code */ static private function htmlColorList($colorList, $split=8, $size=5, $id="", $class="") { global $template; $template->set_filename('color_table_page', dirname(__FILE__).'/templates/cstat_color_table.tpl'); $colors=Array(); $row=0; $num=0; foreach($colorList as $key => $val) { $colors[$row][]=Array('color' => $key, 'pct' => $val, 'num' => ""); $num++; if($num==$split) { $num=0; $row++; } } $data=array( 'colorTable' => $colors, 'size' => $size, 'id' => $id, 'class' => $class, 'br' => ' / ', ); $template->assign('data', $data); unset($data); return($template->parse('color_table_page', true)); } } ?>