-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDefaultScope.cfc
99 lines (80 loc) · 3.13 KB
/
DefaultScope.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<cfcomponent output="false">
<cffunction name="init">
<cfscript>
this.version = "1.0.5,1.0.4,1.0.3,1.0.2,1.0.1,1.0,1.1";
return this;
</cfscript>
</cffunction>
<cffunction name="findAll" access="public" mixin="model">
<cfscript>
var findAllOriginal = core.findAll; // this is to avoid a bug in CF8 where a method called as part of a struct will throw an error when passed an argument collection.
var key = "";
if(not structKeyExists(arguments, "exclusive")) arguments.exclusive = false;
// loop over the default arguments
if (StructKeyExists(variables.wheels.class,"defaultScope") and not arguments.exclusive) {
for(key in variables.wheels.class.defaultScope) {
// if not present in the arguments, copy the default value
if($IsValidFindAllArgument(key)) {
if (not StructKeyExists(arguments,key)) {
arguments[key] = variables.wheels.class.defaultScope[key];
} else {
switch(key) {
case "select": case "order":
arguments[key] = "#arguments[key]#, #variables.wheels.class.defaultScope[key]#";
break;
case "where":
arguments[key] = "#arguments[key]# AND #variables.wheels.class.defaultScope[key]#";
break;
}
}
}
}
}
return findAllOriginal(argumentCollection=arguments);
</cfscript>
</cffunction>
<cffunction name="defaultScope" access="public" mixin="model">
<cfscript>
var key = "";
// create/clear the settings struct
variables.wheels.class.defaultScope = {};
//loop over the incoming arguments and set them into the struct
for(key in arguments) {
if ($IsValidFindAllArgument(key))
variables.wheels.class.defaultScope[key] = arguments[key];
}
</cfscript>
</cffunction>
<cffunction name="$IsValidFindAllArgument">
<cfargument name="scopeName" type="string" required="true">
<cfscript>
return ( ListFindNoCase("where,order,select,distinct,include,maxRows,page,perPage,count,handle,cache,reload,parameterize,returnAs,returnIncluded",arguments.scopeName) gt 0);
</cfscript>
</cffunction>
<!--- adding default ordering will break column statistics, so force remove it in the following overrides --->
<cffunction name="count" access="public" mixin="model">
<cfset var coreMethod = core.count>
<cfset arguments.order = "">
<cfreturn coreMethod(argumentCollection=arguments)>
</cffunction>
<cffunction name="average" access="public" mixin="model">
<cfset var coreMethod = core.average>
<cfset arguments.order = "">
<cfreturn coreMethod(argumentCollection=arguments)>
</cffunction>
<cffunction name="minimum" access="public" mixin="model">
<cfset var coreMethod = core.minimum>
<cfset arguments.order = "">
<cfreturn coreMethod(argumentCollection=arguments)>
</cffunction>
<cffunction name="maximum" access="public" mixin="model">
<cfset var coreMethod = core.maximum>
<cfset arguments.order = "">
<cfreturn coreMethod(argumentCollection=arguments)>
</cffunction>
<cffunction name="sum" access="public" mixin="model">
<cfset var coreMethod = core.sum>
<cfset arguments.order = "">
<cfreturn coreMethod(argumentCollection=arguments)>
</cffunction>
</cfcomponent>