/** * Allows the element to pre-process a rows data before and join merging of rows * occurs. Used in calc element to do calcs on actual row rather than merged row * * @param string $data Elements data for the current row * @param object $row Current row's data * * @since 3.0.5 * * @return string Formatted value */ public function preFormatFormJoins($data, $row) { $params = $this->getParams(); $format = trim($params->get('calc_format_string')); $element_data = $data; if ($params->get('calc_on_save_only', 0)) { if ($format != '') { $element_data = sprintf($format, $element_data); } return parent::preFormatFormJoins($element_data, $row); } else { $element = $this->getElement(); $cal = $params->get('calc_calculation', ''); $listModel = $this->getlistModel(); $formModel = $this->getFormModel(); $data = ArrayHelper::fromObject($row); $data['rowid'] = $data['__pk_val']; $data['fabrik'] = $formModel->getId(); // $$$ Paul - Because this is run on List rows before repeat-group merges, repeat group placeholders are OK. // $$$ hugh - standardizing on $data but need need $d here for backward compat $d = $data; $w = new FabrikWorker(); $cal = $w->parseMessageForPlaceHolder($cal, $data, true, true); if (FabrikHelperHTML::isDebug()) { $res = eval($cal); } else { $res = @eval($cal); } FabrikWorker::logEval($res, 'Eval exception : ' . $element->name . '::preFormatFormJoins() : ' . $cal . ' : %s'); if ($format != '') { $res = sprintf($format, $res); } // $$$ hugh - need to set _raw, might be needed if (say) calc is being used as 'use_as_row_class' // See comments in formatData() in table model, we might could move this to a renderRawListData() method. $raw_name = $this->getFullName(true, false) . '_raw'; $row->{$raw_name} = str_replace(GROUPSPLITTER, ',', $res); return parent::preFormatFormJoins($res, $row); } }