-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.cfm
executable file
·86 lines (84 loc) · 3.54 KB
/
index.cfm
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
<h1>Simple Sorting 1.1</h1>
<h3>A plugin for <a href="http://cfwheels.org" target="_blank">Coldfusion on Wheels</a> by <a href="http://cfwheels.org/user/profile/24" target="_blank">Andy Bellenie</a></h3>
<p>This plugin provides methods for sorting any model by an integer field. </p>
<h2>Usage</h2>
<p>Add simpleSorting([sortColumn,scope]) to the init of your model to enable the plugin. </p>
<ul><li>sortColumm (string, default 'sortOrder') - the column used for sorting (integer)</li>
<li>scope (string, default '') - Limits all functions to the scope of the provided column(s) (see 'Scoping' below)</li>
</ul>
<pre>
<cffunction name="init">
<cfset simpleSorting(sortColumn="mySortColumn",scope="myScopeField1,myScopeField2")>
</cffunction>
</pre>
<h3>Inserting a new model</h3>
<p>If there is no sort position specified (or a sort position of zero) then the model will be added at the bottom of the sort table during inserts. If you wish to insert at a specific location, set the sort position into the model before calling create() or save(), e.g.</p>
<pre>
<cfset myModel = model("foo").create(title="bar")> <!--- inserts at the bottom --->
<cfset myModel = model("foo").create(title="bar", sortOrder=0)> <!--- inserts at the bottom --->
<cfset myModel = model("foo").create(title="bar", sortOrder=1)> <!--- inserts at the top --->
<cfset myModel = model("foo").create(title="bar", sortOrder=3)> <!--- inserts at position three --->
</pre>
<h3>Moving a model</h3>
<p>To move a model simply set a new sorting position and call update() or save(). If you specify a value of zero, it will move the model to the bottom of the table, e.g.</p>
<pre>
<cfset myModel.update()> <!--- no move --->
<cfset myModel.update(sortOrder=0)> <!--- moves to the bottom --->
<cfset myModel.update(sortOrder=3)> <!--- moves to position 3 --->
<cfset myModel.update(sortOrder=1)> <!--- moves to the top --->
</pre>
<h3>Scoping</h3>
<p>By adding one or more columns to the scope argument, you can have multiple
independant sorts within a single table, e.g. - a comments table:</p>
<table width="*">
<tr>
<th>id</th>
<th>postId</th>
<th>sortOrder</th>
<th>text</th>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
<td>This is the FIRST comment for the FIRST post</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>2</td>
<td>This is the SECOND comment for the FIRST post</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>3</td>
<td>This is the THIRD comment for the FIRST post</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>1</td>
<td>This is the FIRST comment for the SECOND post</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>2</td>
<td>This is the SECOND comment for the SECOND post</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>This is the THIRD comment for the SECOND post</td>
</tr>
</table>
<p>For this example, you would add the scope argument to the initial plugin call, i.e.</p>
<pre>
<cfset simpleSorting(scope="postId">
</pre>
<p>This effectively adds a "where postId = #this.postId#" to all sorting functions.</p>
<h2>Support</h2>
<p>I try to keep my plugins free from bugs and up to date with Wheels releases, but if you encounter a problem please log an issue using the tracker on github, where you can also browse my other plugins.<br />
<a href="https://github.com/andybellenie" target="_blank">https://github.com/andybellenie</a></p>