From: <ndi...@us...> - 2002-09-08 08:48:58
|
Update of /cvsroot/modus/org/bacfug/modus In directory usw-pr-cvs1:/tmp/cvs-serv32217/bacfug/modus Modified Files: basecontentobject.cfc Log Message: just rearranging code internally, a bit more logical Index: basecontentobject.cfc =================================================================== RCS file: /cvsroot/modus/org/bacfug/modus/basecontentobject.cfc,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** basecontentobject.cfc 8 Sep 2002 08:38:49 -0000 1.7 --- basecontentobject.cfc 8 Sep 2002 08:48:55 -0000 1.8 *************** *** 77,137 **** </cffunction> - <!--- the sort method ---> - <!--- - - I'm really not at all satisfied with this, but it does work, for now. - - ---> - <cffunction name="sortContentObjects" access="public" output="no" returnType="array" hint="takes an array of contentObjects and sorts them based on the field(s) passed in"> - <cfargument name="contentObjects" type="array" required="yes"> - <cfargument name="sortFields" type="string" required="yes"> - <cfset var tempQuery = ""> - <cfset var sortQuery = ""> - <cfset var sortedArray = arrayNew(1)> - <cfset var objectCount = arrayLen(arguments.contentObjects)> - <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 = 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> - </cffunction> - - <!--- --- 77,80 ---- *************** *** 298,301 **** --- 241,300 ---- ---> + <!--- the sort method ---> + <!--- + + I'm really not at all satisfied with this, but it does work, for now. + + ---> + <cffunction name="sortContentObjects" access="public" output="no" returnType="array" hint="takes an array of contentObjects and sorts them based on the field(s) passed in"> + <cfargument name="contentObjects" type="array" required="yes"> + <cfargument name="sortFields" type="string" required="yes"> + <cfset var tempQuery = ""> + <cfset var sortQuery = ""> + <cfset var sortedArray = arrayNew(1)> + <cfset var objectCount = arrayLen(arguments.contentObjects)> + <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 = 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> + </cffunction> + <cffunction name="renderBasicForm" output="no" access="public" returnType="string" hint="Create a very simple form for this instance"> <cfargument name="action" default="#getFileFromPath(getBaseTemplatePath())#"> |