function alterDisplay(&$rows) { parent::alterDisplay($rows); //THis is all generic functionality which can hopefully go into the parent class // it introduces the option of defining an alter display function as part of the column definition // @tod tidy up the iteration so it happens in this function list($firstRow) = $rows; // no result to alter if (empty($firstRow)) { return; } $selectedFields = array_keys($firstRow); $alterfunctions = $altermap = array(); foreach ($this->_columns as $tablename => $table) { if (array_key_exists('fields', $table)) { foreach ($table['fields'] as $field => $specs) { if (in_array($tablename . '_' . $field, $selectedFields) && array_key_exists('alter_display', $specs)) { $alterfunctions[$tablename . '_' . $field] = $specs['alter_display']; $altermap[$tablename . '_' . $field] = $field; } } } } if (empty($alterfunctions)) { // - no manipulation to be done return; } foreach ($rows as $index => &$row) { foreach ($row as $selectedfield => $value) { if (array_key_exists($selectedfield, $alterfunctions)) { $rows[$index][$selectedfield] = $this->{$alterfunctions}[$selectedfield]($value, $row, $selectedfield, $altermap[$selectedfield]); } } } }
/** * @param $rows */ function alterDisplay(&$rows) { parent::alterDisplay($rows); //THis is all generic functionality which can hopefully go into the parent class // it introduces the option of defining an alter display function as part of the column definition // @todo tidy up the iteration so it happens in this function if (!empty($this->_rollup) && !empty($this->_groupBysArray)) { $this->assignSubTotalLines($rows); } if (empty($rows)) { return; } list($firstRow) = $rows; // no result to alter if (empty($firstRow)) { return; } $selectedFields = array_keys($firstRow); $alterFunctions = $alterMap = array(); foreach ($this->_columns as $tableName => $table) { if (array_key_exists('fields', $table)) { foreach ($table['fields'] as $field => $specs) { if (in_array($tableName . '_' . $field, $selectedFields)) { if (array_key_exists('alter_display', $specs)) { $alterFunctions[$tableName . '_' . $field] = $specs['alter_display']; $alterMap[$tableName . '_' . $field] = $field; $alterSpecs[$tableName . '_' . $field] = NULL; } if ($this->_editableFields && array_key_exists('crm_editable', $specs)) { //id key array is what the array would look like if the ONLY group by field is our id field // in which case it should be editable - in any other group by scenario it shouldn't be $idKeyArray = array($this->_aliases[$specs['crm_editable']['id_table']] . "." . $specs['crm_editable']['id_field']); if (empty($this->_groupByArray) || $this->_groupByArray == $idKeyArray) { $alterFunctions[$tableName . '_' . $field] = 'alterCrmEditable'; $alterMap[$tableName . '_' . $field] = $field; $alterSpecs[$tableName . '_' . $field] = $specs['crm_editable']; $alterSpecs[$tableName . '_' . $field]['field_name'] = $specs['name']; } } } } } } if (empty($alterFunctions)) { // - no manipulation to be done return; } foreach ($rows as $index => & $row) { foreach ($row as $selectedField => $value) { if (array_key_exists($selectedField, $alterFunctions)) { $rows[$index][$selectedField] = $this->$alterFunctions[$selectedField]($value, $row, $selectedField, $alterMap[$selectedField], $alterSpecs[$selectedField]); } } } if ($this->_rollup) { //we want to be able to unset rows so here $this->alterRollupRows($rows); } }