[HTML_DataObject_Browse] Calculate sum Fields

From: Date: Wed, 23 Jun 2004 16:46:23 +0000
Subject: [HTML_DataObject_Browse] Calculate sum Fields
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-13274@lists.php.net to get a copy of this message
Hi! This is my hack to calculating sum(filed)'s in HTML_DataObject_Browse: First, create new $options value in descend class $options['sumRows'] = Array('importe','pagado'); //Numeric field's Second, hack HTML/DataObject/Browse.php the function BuildTotal function buildTotal() { $count = $this->_object->__clone(); $count->find(); $this->N = $count->count(); // NEW CODE ****************************** if(count( $this->options['sumRows'])>0){ $sumquery = $this->_object->__clone(); $sumquery->selectAdd(); foreach ($this->options['sumRows'] as $dat ){ $sumquery->selectAdd("sum($dat) as sum$dat"); } $sumquery->find(true); foreach ($this->options['sumRows'] as $dat ){ $this->{'sum_'.$dat} = $sumquery->{sum.$dat}; } } // END NEW CODE *************************** } In this sample, 2 news object var are created: $this->sum_imprte and $this->sum_pagado, you can call this at Flexy_Template usually.... {sum_importe} .... Have fun!

« previous php.pear.general (#13274) next »