Permalink
Browse files

Added pageOrder to pages

  • Loading branch information...
Russ Johnson
Russ Johnson committed Dec 4, 2011
1 parent 8f50f20 commit cd1e12d54afa19f4a569bbe871aec7d397995f89
Showing with 75 additions and 29 deletions.
  1. +1 −1 controllers/Pages.cfc
  2. +30 −0 db/migrate/20111204164801_add_page_order_to_pages.cfc
  3. +42 −28 models/Page.cfc
  4. +2 −0 views/pages/index.cfm
View
@@ -5,7 +5,7 @@
</cffunction>
<cffunction name="index">
- <cfset pages = model('page').findAll(order="pageClassId DESC,title")>
+ <cfset pages = model('page').findAll(order="pageClassId ASC, parentid, pageOrder")>
<cfset pages = queryTreeSort(pages)>
</cffunction>
@@ -0,0 +1,30 @@
+<!---
+ |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+ | Parameter | Required | Type | Default | Description |
+ |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+ | table | Yes | string | | existing table name |
+ | columnType | Yes | string | | type of column to add |
+ | columnName | No | string | | name for new column, required if columnType is not 'reference' |
+ | referenceName | No | string | | name for new reference column, see documentation for references function, required if columnType is 'reference' |
+ | default | No | string | | default value for column |
+ | null | No | boolean | | whether nulls are allowed |
+ | limit | No | number | | character or integer size limit for column |
+ | precision | No | number | | precision value for decimal columns, i.e. number of digits the column can hold |
+ | scale | No | number | | scale value for decimal columns, i.e. number of digits that can be placed to the right of the decimal point (must be less than or equal to precision) |
+ |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+
+ EXAMPLE:
+ addColumn(table='users', columnType='string', columnName='password', default='', null=true);
+--->
+<cfcomponent extends="plugins.dbmigrate.Migration" hint="add page order to pages">
+ <cffunction name="up">
+ <cfscript>
+ addColumn(table='pages', columnType='integer', columnName='pageOrder');
+ </cfscript>
+ </cffunction>
+ <cffunction name="down">
+ <cfscript>
+ removeColumn(table='pages',columnName='pageOrder');
+ </cfscript>
+ </cffunction>
+</cfcomponent>
View
@@ -1,24 +1,33 @@
<cfcomponent extends="Model" output="false">
- <cffunction name="init">
+ <cffunction name="init">
<cfset hasMany('PageParts')>
- <cfset belongsTo(name='pageLayout', class="layout", foreignKey="layoutID")>
- <cfset belongsTo('PageClass')>
- <cfset belongsTo(name="author", class="user", foreignKey="createdByID")>
+ <cfset belongsTo(name='pageLayout', class="layout", foreignKey="layoutID")>
+ <cfset belongsTo('PageClass')>
+ <cfset belongsTo(name="author", class="user", foreignKey="createdByID")>
- <cfset validatesPresenceOf(property="title" , message="Your page must have a title.")>
+ <cfset validatesPresenceOf(property="title" , message="Your page must have a title.")>
<cfset validatesLengthOf(properties="title,keywords,description", message="You have exceeded the maximun length", allowBlank="true", maximum="255")>
- <cfset validatesPresenceOf(property="slug" , message="Your page must have a slug." )>
- <cfset validatesUniquenessOf(property="slug", message="The slug you entered already exists.")>
+ <cfset validatesPresenceOf(property="slug" , message="Your page must have a slug." )>
+ <cfset validatesUniquenessOf(property="slug", message="The slug you entered already exists.")>
<cfset validatesLengthOf(property="slug", message="You have exceeded the maximun length for the slug", maximum="100")>
<cfset validatesLengthOf(property="breadcrumb", message="You have exceeded the maximun length for the breadcrumb", allowBlank="true", maximum="160")>
- <cfset beforeCreate('setCreatedByID')>
- <cfset beforeUpdate('setUpdatedByID')>
- <cfset beforeSave('checkPublished,setLayoutId')>
- </cffunction>
+ <cfset beforeCreate('setCreatedByID')>
+ <cfset beforeUpdate('setUpdatedByID')>
+ <cfset beforeSave('checkPublished,setLayoutId')>
+ </cffunction>
- <cffunction name="getChildren" access="public">
+ <cffunction name="getParent" access="public" output="false">
+ <cfset parent = model('Page').findByKey(key=this.parentID, returnAs="objects")>
+ <cfif isObject(parent)>
+ <cfreturn parent />
+ <cfelse>
+ <cfreturn model('Page').new() />
+ </cfif>
+ </cffunction>
+
+ <cffunction name="getChildren" access="public">
<cfset var loc = arguments.attributeCollection >
<cfset var childPages = "">
@@ -31,26 +40,31 @@
<cfset childPages = this.findAll(argumentCollection=loc)>
- <cfreturn childPages>
- </cffunction>
+ <cfreturn childPages>
+ </cffunction>
+
+ <cffunction name="getSiblings" access="public" output="false">
+ <cfset var siblings = model('Page').findAll(where="parentid=#this.parentID# AND status='published'", returnAs="objects")>
+ <cfreturn siblings />
+ </cffunction>
<!--- PRIVATE METHODS --->
- <cffunction name="checkPublished" access="private">
- <cfif this.isNew() and this.status is 'published'>
- <cfset this.publishedAt = now()>
- <cfelseif this.StatusHasChanged() and this.status is 'published'>
- <cfset this.publishedAt = now()>
- </cfif>
- </cffunction>
+ <cffunction name="checkPublished" access="private">
+ <cfif this.isNew() and this.status is 'published'>
+ <cfset this.publishedAt = now()>
+ <cfelseif this.StatusHasChanged() and this.status is 'published'>
+ <cfset this.publishedAt = now()>
+ </cfif>
+ </cffunction>
- <cffunction name="setLayoutId" access="private">
- <cfset var loc = {}>
- <cfif this.layoutId IS "">
- <cfset loc.parentPageId = this.findByKey(key=this.parentId, select="layoutId")>
- <cfset this.layoutId = loc.parentPageId.layoutId>
- </cfif>
- </cffunction>
+ <cffunction name="setLayoutId" access="private">
+ <cfset var loc = {}>
+ <cfif this.layoutId IS "">
+ <cfset loc.parentPageId = this.findByKey(key=this.parentId, select="layoutId")>
+ <cfset this.layoutId = loc.parentPageId.layoutId>
+ </cfif>
+ </cffunction>
</cfcomponent>
View
@@ -13,6 +13,7 @@
<thead>
<tr>
<th class="first">Page</th>
+ <th>Order</th>
<th>Status</th>
<th class="last">&nbsp;</th>
</tr>
@@ -28,6 +29,7 @@
</cfif>
#linkTo(text=pageTitle, route="edit_page_path", key=id, parentID=parentid, class="page")#
</td>
+ <td<cfif !parentid is 1 and !parentid is 0> style="color:##ccc;"</cfif>>#pageorder#</td>
<td><cfif status is "Draft"><span class="red">#status#</span><cfelse>#status#</cfif></td>
<td>
#linkTo(text='#imageTag("add-child.png")#', route='new_page_path', parentid=id)#

0 comments on commit cd1e12d

Please sign in to comment.