Don't know how much this will help, but here's some code I wrote to add and
delete employees from a tree:

<!--- add someone to the tree --->
        <---passing (name,left,right) values as "form.boss"--->
        <cfset bossright = listlast(form.boss)><cfset
bossleft=listgetat(form.boss,2)>
        <!--- get all users who come after this person's boss --->
        <cfquery name=get datasource=#dsn#>
                select userID, leftno, rightno
                from userroles
                where companyID = #companyID#
        </cfquery>
        <cftransaction>
        <!--- move them all over by 2 --->
        <cfoutput query=get>
                <cfset newright=rightno><cfset newleft=leftno>
                <cfif leftno gt bossleft><!--- if they come after the insert point --->
                        <cfset newleft=leftno+2><cfset newright=rightno+2>
                <cfelseif leftno lte bossleft and rightno gte bossright><!--- if they 
are
one of the bosses --->
                        <cfset newright=rightno+2><cfset newleft=leftno>
                </cfif>
                <cfif newright is rightno and newleft is  leftno><!--- if no change,
skip --->
                <cfelse><!--- otherwise, update database --->
                <cfquery datasource=#dsn#>
                        update userroles
                        set leftno = #newleft#, rightno = #newright#
                        where userID=#get.userID#
                </cfquery>
                </cfif>
        </cfoutput>
        <cfquery datasource=#dsn#><!--- update the boss  --->
                update userroles
                set rightno=#bossright#+2
                where userID = #val(listfirst(form.boss))#
        </cfquery>
        <cfquery datasource=#dsn#><!--- add the new user as leftmost under
boss --->
                update userroles
                set rightno = #bossleft# +2,
                        leftno = #bossleft# +1
                where userID = #val(form.userID)#
        </cfquery>
        </cftransaction>



<!--- delete someone from tree --->
<cfelseif isDefined("delete")>
        <cftransaction>
        <cfquery name=get datasource=#dsn#>
                select userID as dropID, leftno as dropleft, rightno as dropright
                from userroles where userID = #val(form.userID)#
        </cfquery>
        <cfquery datasource=#dsn#>
                updateuserroles
                set rightno =0, leftno =0 where userID =#val(form.userID)#
        </cfquery>
        <!--- get all employees --->
        <cfquery name=getall datasource=#dsn#>
                select rightno,leftno,userID from userroles
                where companyID =#companyID# and leftno <> 0
        </cfquery>
        <!--- fill in the gap --->
        <cfoutput query=getall>
                <cfset newright=rightno><cfset newleft=leftno>
                <cfif leftno gt get.dropleft and leftno lt get.dropright><!--- they are
subs --->
                        <cfset newright=rightno-1><cfset newleft=leftno-1>
                <cfelseif leftno gt get.dropleft and rightno gt get.dropright><!--- if
they are after, but not subs --->
                        <cfset newright=rightno-2><cfset newleft=leftno-2>
                <cfelseif leftno lt get.dropleft and rightno gt get.dropright><!--- if
they are one of the bosses --->
                        <cfset newright=rightno-2><cfset newleft=leftno>
                </cfif>
        <!--- if changed, update the database --->
                <cfif newright is rightno and newleft is leftno><!--- if no change, 
skip
update --->
                <cfelse>
                <cfquery datasource=#dsn#>
                        update userroles set rightno = #newright#, leftno=#newleft#
                        where userID = #getall.userID#
                </cfquery>
                </cfif>
        </cfoutput>
        </cftransaction>

HTH
D
Diana Nichols
Webmistress
http://www.salesthreads.com
Selling...Simplified


-----Original Message-----
From: Matthew W Jones [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 12, 2001 12:11 PM
To: CF-Talk
Subject: RE: Hierarchy


Actually, that tutorial is where this question began. The tutorial deals
with getting the data out.  I had searched the dev exchange looking for
custom tags to simplify some of the work for getting the data in and
manipulating it, to no avail.  So, now my intent is to write a set of custom
tags, that will assist with any of the processes (outside of selecting the
data back out).

I have used some of Joe Celkos columns as references, and plan on using the
database structure from secret agents rather than Joe's design.

-----Original Message-----
From: John Lucas [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 12, 2001 9:55 AM
To: CF-Talk
Subject: Re: Hierarchy


http://www.secretagents.com/tools/freeviewlets/index.cfm?category_id=20&show
viewlets=1

----- Original Message -----
From: "Matthew W Jones" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Wednesday, September 12, 2001 9:53 AM
Subject: RE: Hierarchy


> That should have read:
> Is anyone using the "Nested Set Method" for Hierarchy's?  Do you have any
> implementation tips/tricks etc. (specifically towards insert, update, de
> lete, reordering of an items left/right boundaries)?
>
> -----Original Message-----
> From: Matthew W Jones [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, September 12, 2001 9:47 AM
> To: CF-Talk
> Subject: SOT:Hierarchy
>
> Is anyone using the "Nested Set Method" for Hierarchy's?  Do you have any
> implementation tips/tricks etc. (specifically towards insert, update,
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Your ad could be here. Monies from ads go to support these lists and provide more 
resources for the community. http://www.fusionauthority.com/ads.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to