From: <ndi...@us...> - 2002-09-08 08:37:38
|
Update of /cvsroot/modus/org/bacfug/modus/persistence In directory usw-pr-cvs1:/tmp/cvs-serv30245/bacfug/modus/persistence Modified Files: basepersister.cfc Log Message: removed the getAllSorted() and refactored it into two methods inside the baseContentObjects. Sorting really wasn't a persistence issue. Index: basepersister.cfc =================================================================== RCS file: /cvsroot/modus/org/bacfug/modus/persistence/basepersister.cfc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** basepersister.cfc 8 Sep 2002 04:15:21 -0000 1.5 --- basepersister.cfc 8 Sep 2002 08:37:32 -0000 1.6 *************** *** 21,83 **** <cfthrow message="getAll() method not implemented!" detail="You must defined a getAll() method for #getMetaData(this).name#."> </cffunction> ! ! <!--- a function for sorting ---> ! <!--- ! ! I'm really not at all satisfied with this, but it does work, for now. ! ! ---> ! <cffunction name="getAllSorted" access="public" output="no" hint="A method to sort all instances and sort them by one or more fields"> ! <cfargument name="sortFields" required="yes" type="string"> ! <cfargument name="contentObjectType" required="yes" type="string"> ! <cfset var tempQuery = ""> ! <cfset var sortQuery = ""> ! <cfset var objectArray = getAll(arguments.contentObjectType)> ! <cfset var sortedArray = arrayNew(1)> ! <cfset var objectCount = arrayLen(objectArray)> ! <cfset var sortFieldsArray = listToArray(arguments.sortFields)> ! <cfset var ii = 0> ! <cfset var ff = 0> ! <cfset var thisObject = ""> ! <cfset var thisFieldName = ""> ! <cfscript> ! //clean the sortFieldsArray, so we can have the sort order in there too ! for(ii = 1; ii LTE arrayLen(sortFieldsArray); ii = ii + 1){ ! sortFieldsArray[ii] = getToken(sortFieldsArray[ii],1); ! } ! //prime the tempQuery ! tempQuery = queryNew("index," & arrayToList(sortFieldsArray)); ! //resize the query to however many objects there are ! queryAddRow(tempQuery,objectCount); ! //loop through all objects, populating the appropriate columns of the query ! for(ii = 1; ii LTE objectCount; ii = ii + 1){ ! thisObject = objectArray[ii]; ! querySetCell(tempQuery,"index",ii,ii); ! //loop through whatever fields we are sorting on, adding the values of those fields to the query ! for(ff = 1; ff LTE arrayLen(sortFieldsArray); ff = ff + 1){ ! thisFieldName = getToken(sortFieldsArray[ff],1); ! querySetCell(tempQuery,thisFieldName,trim(thisObject.getField(thisFieldName).getValue()),ii); ! } ! } ! </cfscript> ! <!--- ok, now let's get the sortedQuery ---> ! <cfquery name="sortQuery" dbtype="query"> ! SELECT * ! FROM tempQuery ! ORDER BY #arguments.sortFields# ! </cfquery> ! <!--- and now, we'll populate the sortedArray ---> ! <cfscript> ! //resize the array, so it doesn't have to keep allocating more memory ! arrayResize(sortedArray,objectCount); ! for(ii = 1; ii LTE objectCount; ii = ii + 1){ ! sortedArray[ii] = objectArray[sortQuery.index[ii]]; ! } ! </cfscript> ! <!--- return the sorted Array ---> ! <cfreturn sortedArray> ! </cffunction> ! ! <!--- a package function to determine if an object passed is, indeed, a baseContentObject ---> <cffunction name="isContentObject" access="package" returnType="boolean" output="no" hint="determines if something is a content object"> --- 21,25 ---- <cfthrow message="getAll() method not implemented!" detail="You must defined a getAll() method for #getMetaData(this).name#."> </cffunction> ! <!--- a package function to determine if an object passed is, indeed, a baseContentObject ---> <cffunction name="isContentObject" access="package" returnType="boolean" output="no" hint="determines if something is a content object"> |