From: Ivo Jansch <ivo dot
Reply-To: achievo dot
To: achievo dot
Subject: Re: [achievo] group, count, any one?
Date: Mon, 05 May 2003 11:26:42 +0200
MIME-Version: 1.0
Received: from s2.ibuildings.nl ([213.133.42.35]) by
mc10-f34.bay6.hotmail.com with Microsoft SMTPSVC(5.0.2195.5600); Mon, 5 May
2003 02:27:38 -0700
Received: (qmail 17571 invoked by uid 87); 5 May 2003 09:27:10 -0000
Received: (qmail 17567 invoked from network); 5 May 2003 09:27:09 -0000
X-Message-Info: JGTYoYF78jEHjJx36Oi8+Q1OJDRSDidP
Mailing-List: contact achievo-help dot
Precedence: bulk
X-No-Archive: yes
List-Post: <
X-Accept-Language: nl, en-us, en
References: <Law8-F26IEAOeIiGXix0002120d dot
In-Reply-To: <Law8-F26IEAOeIiGXix0002120d dot
Return-Path: achievo-return-1683-elran70=hotmail.com dot
X-OriginalArrivalTime: 05 May 2003 09:27:39.0113 (UTC)
FILETIME=[92347590:01C312E8]
Hi,
e r wrote:
I need to use grouping with count function netween two nodes, is there any
"nice" way to do that or I'll need to make a dirty hack for it?
10x,
Eldad Ran.
Now the easy way. This is a lot easier to understand and implement.
However, it does a new query for each record that's being displayed.
class myCountAttribute extends atkAttribute
{
function load($db, $rec, $mode="")
{
$childnode = &getNode("mymodule.childnode");
if (is_object($childnode))
{
// $rec is the 'master' record, we can use it's id-field to
// count records in another node.
return $childnode->countDb("parent_id='".$rec["id"]."'",
"","",$mode);
}
else
{
// node not found.
return 0;
}
}
function store($db, $rec, $mode="")
{
// dummy impl, we don't have anything to store
}
}
This approach has several advantages. First of all, it's a lot less code.
Second, it's very easy to generalize this to a generic attribute
that you can use in any situation (by passing the nodename and where clause
as parameters). And you don't use the (somewhat difficult) database
abstraction layer. The last advantage is that you use $childnode to access
the count. Any filters that might have been set in
$childnode will be applied.
Greetings,
Ivo
[ Achievo mailing list - http://www.achievo.org/ ]
[ to unsubscribe send an e-mail to achievo-unsubscribe dot