From: <ndi...@us...> - 2002-09-09 21:19:02
|
Update of /cvsroot/modus/org/bacfug/modus In directory usw-pr-cvs1:/tmp/cvs-serv8296/bacfug/modus Modified Files: basecontentobject.cfc Log Message: fixed a bug with the sorting that broke if there are no objects to sort Index: basecontentobject.cfc =================================================================== RCS file: /cvsroot/modus/org/bacfug/modus/basecontentobject.cfc,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** basecontentobject.cfc 8 Sep 2002 08:48:55 -0000 1.8 --- basecontentobject.cfc 9 Sep 2002 21:18:59 -0000 1.9 *************** *** 266,296 **** //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 = arguments.contentObjects[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,lcase(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] = arguments.contentObjects[sortQuery.index[ii]]; ! } ! </cfscript> <!--- return the sorted Array ---> <cfreturn sortedArray> --- 266,303 ---- //prime the tempQuery tempQuery = queryNew("index," & arrayToList(sortFieldsArray)); ! //if there any objects, then loop through and make them ! if(objectCount){ ! //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 = arguments.contentObjects[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,lcase(thisObject.getField(thisFieldName).getValue()),ii); ! } } } </cfscript> ! <!--- if there are objects to sort, query them, then build the new array ---> ! <cfif objectCount> ! <!--- 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] = arguments.contentObjects[sortQuery.index[ii]]; ! } ! </cfscript> ! </cfif> ! <!--- return the sorted Array ---> <cfreturn sortedArray> |