Page 1 of 1

PostPosted: Tue Apr 17, 2007 5:21 am
by neku
hello dataface workers

i am brand-new here. i find dataface fantastic and want build one app thereby. but i find not all information which i need. for example:

a) how can i sum collons and display it in tablefooter (listfooter)?
b) how can i display this in detail-can someone help me?

is somewhere an example?

much thanks in advance

ps:
(my english is poor. but i hope, with a little help from aunt google, (much thanks steve) i am gona make it: http://translate.google.com/translate_t)

PostPosted: Tue Apr 17, 2007 9:16 am
by shannah

Hi Nestor,

This is a bit tricky, but possible.Ê It involves a few concepts:

1. You can insert content after the list view using the block__after_result_list() method in the delegate class.

2. You can calculate whatever totals you want in that method.


For calculating your totals, you will probably need to know what the current query is that dataface is using.Ê You can build portions of the query using the Dataface_QueryBuilder class and passing the query array to it:

e.g.

function block__after_result_list(){
ÊÊÊ $app =& Dataface_Application::getInstance();
ÊÊÊ $query =& $app->getQuery();
ÊÊÊ $queryBuilder = new Dataface_QueryBuilder($query['-table'], $query);
ÊÊÊ $where = $queryBuilder->_where();Ê // the where clause
ÊÊÊ $from = $queryBuilder->_from();Ê // the from clause
ÊÊÊÊÊÊÊ
ÊÊÊ $sql = "select sum(income) as total_income, sum(expense) as total_expense $from $where";
ÊÊÊ $res = mysql_query($sql, df_db());
ÊÊÊ list($total_income, $total_expense) = msyql_fetch_row($res);
ÊÊÊ echo "

Totals:


ÊÊÊÊÊÊÊÊÊÊÊÊ

ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ
Income
$total_income

ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ
Expense
$total_expense

ÊÊÊÊÊÊÊÊÊÊÊÊ
";
}

This will make the total income and expense show up in the footer of list view. (Note I haven't tested this, so there may be bugs in this code.. but it is pretty much right.
-Steve






PostPosted: Wed Apr 18, 2007 2:20 am
by neku
hi steve

much thanks, i will try it in such a way.

neku