Message from discussion
adding a method to the nested set
Received: by 10.101.71.6 with SMTP id y6mr1470852ank.2.1246663650495;
Fri, 03 Jul 2009 16:27:30 -0700 (PDT)
Return-Path: <jphi...@noatak.com>
Received: from smtprelay.b.hostedemail.com (smtprelay0197.b.hostedemail.com [64.98.42.197])
by gmr-mx.google.com with ESMTP id 21si331439yxe.12.2009.07.03.16.27.30;
Fri, 03 Jul 2009 16:27:30 -0700 (PDT)
Received-SPF: neutral (google.com: 64.98.42.197 is neither permitted nor denied by best guess record for domain of jphi...@noatak.com) client-ip=64.98.42.197;
Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 64.98.42.197 is neither permitted nor denied by best guess record for domain of jphi...@noatak.com) smtp.mail=jphi...@noatak.com
Received: from filter.hostedemail.com (b-bigip1 [10.5.19.254])
by smtprelay01.b.hostedemail.com (Postfix) with SMTP id F372B6599A77
for <doctrine-user@googlegroups.com>; Fri, 3 Jul 2009 23:27:29 +0000 (UTC)
X-Spam-Summary: 30,2,0,a2a106569f9a60da,cbe355ae162f562c,jphi...@noatak.com,doctrine-user@googlegroups.com,RULES_HIT:69:355:379:539:540:541:542:543:599:600:800:945:960:967:973:980:988:989:1155:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1542:1587:1593:1594:1711:1730:1747:1766:1792:2077:2079:2198:2199:2379:2393:2525:2551:2553:2559:2563:2682:2685:2857:2859:2933:2937:2939:2942:2945:2947:2951:2954:3022:3027:3354:3636:3653:3657:3865:3866:3867:3868:3869:3870:3871:3872:3873:3874:3876:3877:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4184:4362:5007:6114:6119:6261:7464:7576:7679:7903:8501:8660:8957:8985:9025:9040:9388:9545:9562,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:none,DNSBL:none
X-Session-Marker: 646F67746563406875676865732E6E6574
X-Filterd-Recvd-Size: 3586
Received: from dogtecass (dpc674564165.direcpc.com [67.45.64.165])
(Authenticated sender: dog...@hughes.net)
by omf02.b.hostedemail.com (Postfix) with ESMTP
for <doctrine-user@googlegroups.com>; Fri, 3 Jul 2009 23:27:26 +0000 (UTC)
From: "J. Philip" <jphi...@noatak.com>
To: <doctrine-user@googlegroups.com>
Subject: RE: [doctrine-user] adding a method to the nested set
Date: Fri, 3 Jul 2009 15:27:19 -0800
Message-ID: <41ECD43C4A0D409F9E789FDF9C0A0597@dogtecass>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook, Build 10.0.4024
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.3959
In-Reply-To: <3ce1e09f-1823-4d64-9743-847729039...@x3g2000yqa.googlegroups.com>
Importance: Normal
You can derive a class MyNestedSet from nested set and add your own
methods in it.
Add a behavior MyNestedSetBehavior derived from
Doctrine_Template_NestedSet and override the setup method and relpace
$this->_table->setOption('treeImpl', 'NestedSet'); with
$this->_table->setOption('treeImpl', 'MyNestedSet');
After, you replace actAs : [NestedSet] with actAs :
[MyNestedSetBehavior]
I have not tried it but it should work.
Note that if you just want to add an orderBy clause, you should be able
to do it by calling the setBaseQuery($q) method of the Tree just before
you call the getDescendants methos. (Where $q contains the orderBy
clause)
-----Original Message-----
From: doctrine-user@googlegroups.com
[mailto:doctrine-user@googlegroups.com] On Behalf Of crash3k
Sent: Friday, July 03, 2009 10:57 AM
To: doctrine-user
Subject: [doctrine-user] adding a method to the nested set
Hi,
I've just started lerning Doctrine and Symfony
and now I want to add a method to the nested
set-class of Doctrine but I really don't know
how to implement it.
So... here's the method a want to add:
(As you can see it's just the "getDescendants"-method
with an option to sort the result by a specified column)
public function getDescendantsSorted($depth = null, $includeNode =
false, $orderBy = '', $orderType = 'ASC') {
$baseAlias = $this->_tree->getBaseAlias();
$q = $this->_tree->getBaseQuery();
$params = array($this->record->get('lft'), $this->record->get
('rgt'));
if ($includeNode) {
$q->addWhere("$baseAlias.lft >= ? AND $baseAlias.rgt <= ?",
$params)->addOrderBy("$baseAlias.lft asc");
} else {
$q->addWhere("$baseAlias.lft > ? AND $baseAlias.rgt < ?", $params)-
>addOrderBy("$baseAlias.lft asc");
}
if ($depth !== null) {
$q->addWhere("$baseAlias.level <= ?", $this->record['level'] +
$depth);
}
if ($orderBy != "")
$q->orderBy("$baseAlias.$orderBy $orderType");
$q = $this->_tree->returnQueryWithRootId($q, $this->getRootValue());
$result = $q->execute();
if (count($result) <= 0) {
return false;
}
return $result;
}
So is there a way of loading this method into the
given nested set class?
Thanks in advance!
Greetings,
CRaSH3k