. */ require_once('HistogramTransform.php'); class CountInField extends HistogramTransform { var $delimiter = ','; function __construct($valueField, $groupByField = null, $delimiter = null) { parent::__construct($valueField, $groupByField); if ($delimiter) { $this->delimiter = $delimiter; } } public function addEntry(&$entry) { if (array_key_exists($this->valueField, $entry)) { $value = $entry[$this->valueField]; $valueList = explode($this->delimiter, $value); foreach ($valueList as $aValue) { $groupByName = $aValue; if ($value !== null && $value !== '') { if (array_key_exists($groupByName, $this->values)) { $this->values[$groupByName]++; } else { $this->values[$groupByName] = 1; } } } } } public function getTransformedData() { $data = array(); foreach ($this->values as $name => $value) { if (empty($this->groupByField)) { $data[] = array($this->valueField => $value); } else { $data[] = array($this->valueField => $name, $this->groupByField => $value); } } return $data; } }