forgot the attachment

and the warning: dont use it on your valuable data !!

it certainly has some bugs still

regards,
--
Jens
//get the source parentid aSQL=arrayNew(1); //this is just an array to hold a record of all sql statements - gonna keep it in till this move tree bizo is all gud stReturn = structNew(); q = getParentID(objectID=arguments.objectID, dsn=arguments.dsn); source_parentid = q.parentID; // check for orphan - JPS sql = "select objectID from nested_tree_objects where objectID = '#source_parentid#'"; q = query(sql=sql,dsn=arguments.dsn); isOrphan = 1; if (q.recordCount GT 0) { isOrphan = 0; } sql = "select objectID from nested_tree_objects where parentid = '#arguments.parentid#'"; q = query(sql=sql,dsn=arguments.dsn); destChildrenCount = q.recordCount; qDestDescendants = getDescendants(objectid=arguments.parentid,dsn=application.dsn); // we dont want to expand the dest node, if the souce node is a descendant - just flagging this status here sql = "select objectid from qDestDescendants where objectid = '#arguments.objectid#'"; q = queryOfQuery(sql); bExpandDest = 1; if (q.recordCount) bExpandDest = 0; //prevent calling of getDescendants, if parentid is orphan - JPS if (isOrphan EQ 0) { //also checking to see if destination is a descendant of sources parent, if so, we wont want to expand parentid of source qSourceParentDesc = getDescendants(objectid=source_parentid,dsn=arguments.dsn); q = queryOfQuery2('select objectid',qSourceParentDesc,"where objectid = '#arguments.parentid#'"); if (q.recordCount) bExpandDest = 0; } // get the left and right of the object. this span defines the branch (object including its descendants). Also get typename, //to differentiate between trees (there may be more than one tree, and we don't want to change the values of the other trees) sql = "select nleft, nright, typename from nested_tree_objects where objectid = '#arguments.objectid#'"; q = query(sql=sql, dsn=arguments.dsn); nleft = q.nleft; nright = q.nright; typename = q.typename; //-- keep the branch (object and descendants of the object) ids safe in a temp table sql = " select objectid from nested_tree_objects where nleft between #nleft# and #nright# and typename = '#typename#'"; qBranchIDs = query(sql=sql, dsn=arguments.dsn); //prevent calling, if parentid is orphan - JPS if (isOrphan EQ 0) { //check destination is not a descendant of the source node q = queryofquery2("select count(*) AS ObjCount",qBranchIDs,"where objectid = '#arguments.parentid#'"); if (q.objCount GT 0) { throwerror(detail = 'The destination is part of the branch you are trying to move. This move is impossible.', errorcode='Move Branch'); } } //-- get the number of branch members. Each one has 2 positions: left and right, so times it by 2 count = qBranchIds.recordCount * 2; if (NOT source_parentid IS arguments.parentid) { sql = " update nested_tree_objects set parentid = '#arguments.parentid#' where objectid = '#arguments.objectid#'"; query(sql=sql, dsn=arguments.dsn); arrayAppend(aSQL,sql); //check the level of the new parent. if its level is different than that of the original parent, change levels of //object and all its descendants sql = " select nlevel from nested_tree_objects where objectid = '#arguments.parentid#'"; q = query(sql=sql, dsn=arguments.dsn); dest_parent_level = q.nlevel; //modified calling, if parentid is orphan - JPS if (isOrphan EQ 1) { sql = " select nlevel from nested_tree_objects where objectid = '#arguments.objectid#'"; q = query(sql=sql, dsn=arguments.dsn); source_parent_level = q.nlevel - 1; } if (isOrphan EQ 0) { sql = " select nlevel from nested_tree_objects where objectid = '#source_parentid#'"; q = query(sql=sql, dsn=arguments.dsn); source_parent_level = q.nlevel; } //fix the levels of the branch that is moving leveldiff = dest_parent_level - source_parent_level; sql = " update nested_tree_objects set nlevel = (nlevel + #leveldiff#) where nleft between #nleft# and #nright# and typename = '#typename#'"; query(sql=sql, dsn=arguments.dsn); arrayAppend(aSQL,sql); } //contract the old parent and greater by this number, excluding the branch. sql = " update nested_tree_objects set nleft = (nleft - #count#) where nleft > #nleft# and typename = '#typename#'"; //to deal with scenarios where there are no children if(qBranchIds.recordCount) sql = sql & "and objectid not in (#quotedValueList(qBranchIds.objectid)#)"; query(sql=sql, dsn=arguments.dsn); arrayAppend(aSQL,sql); sql = " update nested_tree_objects set nright = (nright - #count#) where nright > #nleft# and typename = '#typename#'"; //to deal with scenarios where there are no children if(qBranchIds.recordCount) sql = sql & "and objectid not in (#quotedValueList(qBranchIds.objectid)#)"; query(sql=sql, dsn=arguments.dsn); arrayAppend(aSQL,sql); // if pos is 1 or less, assume it is 1. This means we move the branch to the top position amongst the siblings // of the specified destination parent. if (arguments.pos LT 2) { sql = "select nleft + 1 AS nleft from nested_tree_objects where objectid = '#arguments.parentid#'"; q = query(sql=sql, dsn=arguments.dsn); dest_left = q.nleft; } else { //work out the left hand value of the new child, by getting the right of the next older sibling, and adding one to it //make a temp table, put the right hand value of the first child of the parent into it rowindex = 1; sql = " select #rowindex# AS seq, min(nright) AS nright FROM nested_tree_objects where parentID = '#arguments.parentid#' AND objectID <> '#arguments.objectid#'"; qTemp = query(sql=sql, dsn=arguments.dsn); //smoke up some sequence numbers for the latter for (i = 1;i LTE qTemp.recordCount;i=i+1) { querySetCell(qTemp,'seq',i,i); } minr = 1; while (minr GT 0) { sql = "select nright from qTemp"; q = queryofquery2("select nright",qTemp); sql = " select min(nright) AS minr from nested_tree_objects where parentid = '#arguments.parentID#' and objectid <> '#arguments.objectid#' and nright not in (#quotedValueList(qTemp.nright)#)"; q = query(sql=sql, dsn=arguments.dsn); if (q.recordcount AND len(q.minr)) { rowindex = qTemp.recordCount + 1; minr = q.minr; queryAddRow(qTemp); querySetCell(qTemp,'nright',minr); querySetCell(qTemp,'seq',rowindex); } else minr = -1; }//end while // now get the nright hand value from the temp table that is directly before the position we want to insert the new // child at, and assign it (+1)to the var @dest_left q = queryofquery2("select nright + 1 AS destLeft",qTemp,"where seq = #arguments.pos# - 1"); dest_left = q.destLeft; }//end if // expand the new parent and lower siblings if they exist, and greater by the same number as we contracted the old parent // by, excluding the branch. sql = " update nested_tree_objects set nright = nright + #count# where nright > #dest_left# and typename = '#typename#'"; //to deal with scenarios where there are no children if(qBranchIds.recordCount) sql = sql & "and objectid not in (#quotedValueList(qBranchIds.objectid)#)"; //dump(sql); query(sql=sql, dsn=arguments.dsn); arrayAppend(aSQL,sql); //sql = "select objectid,objectname,nlevel,nleft,nright from nested_tree_objects where objectid = '#arguments.parentID#'"; //qpar = query(sql=sql, dsn=arguments.dsn); //dump(qpar); // deal with the parent's right hand value if it is a new parent, and has a different level if (NOT source_parentid IS arguments.parentid) { //get children count for dest node - if no children, we need to expand parent if ((NOT source_parent_level IS dest_parent_level OR NOT destChildrenCount) AND bExpandDest) { sql = " update nested_tree_objects set nright = nright + #count# where objectid = '#arguments.parentid#'"; query(sql=sql, dsn=arguments.dsn); arrayAppend(aSQL,sql); } } sql = " update nested_tree_objects set nleft = nleft + #count# where nleft >= #dest_left# and typename = '#typename#'"; //to deal with scenarios where there are no children if(qBranchIds.recordCount) sql = sql & "and objectid not in (#quotedValueList(qBranchIds.objectid)#)"; query(sql=sql, dsn=arguments.dsn); arrayAppend(aSQL,sql); // change the nlefts and nrights of the branch itself diff = dest_left - nleft; //to deal with scenarios where there are no children if(qBranchIds.recordCount) { sql = " update nested_tree_objects set nleft = (nleft + #diff#), nright = (nright + #diff#) where objectid in (#quotedValueList(qBranchIds.objectid)#)"; query(sql=sql, dsn=arguments.dsn); arrayAppend(aSQL,sql); } //Fixing a problem where when moving to bottom, the parent node nright value does not get correctly updated if (source_parentid IS arguments.parentid) { sql = "select objectid, objectname from nested_tree_objects where parentid = '#arguments.parentid#' order by nleft"; qChildren = query(sql=sql,dsn=arguments.dsn); if(arguments.pos EQ qChildren.recordCount) { sql = " update nested_tree_objects set nright = nright + #count# where objectid = '#arguments.parentid#'"; query(sql=sql, dsn=arguments.dsn); arrayAppend(aSQL,sql); } } stTmp.aSQL = aSQL; --->
---
You are currently subscribed to farcry-dev as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]

Aussie Macromedia Developers: http://lists.daemon.com.au/

Reply via email to