PageService Class
Service for interacting with site pages in the database. Located in the namespace Canteen\Services.
Item Index
Methods
- __call
- addPage
- autoDetectItem
- bindObject
- bindObjects
- call
- callByItem
- field
- gateway
- getCaller
- getPage
- getPageByUri
- getPages
- getPagesByParentId
- getProtectedUris
- getStack
- hasDefaultField
- install
- installItem
- installItems
- internalAdd
- internalGetAll
- internalGetByIndex
- internalGetTotalAll
- internalGetTotalByIndex
- internalRemoveByIndex
- internalUpdateByIndex
- parse
- privilege
- registerItem
- removePage
- service
- setPrepends
- setProperties
- setup
- setWhere
- template
- updatePage
- valueSet
- verify
- verifyField
Methods
__call
-
method
-
args
Override of the dynamic call method to call verify* methods, for instance if we're validating Name it would be $this->verifyName($value)
addPage
-
propertiesOrUri
-
[title='']
-
[description='']
-
[keywords='']
-
[privilege=0]
-
[redirectId=null]
-
[parentId=null]
-
[isDynamic=false]
-
[cache=true]
Add a new page to the site
Parameters:
-
propertiesOrUri
Dictionary | StringThe collection of page properties
-
[title='']
String optionalThe page title
-
[description='']
String optionalThe description of the page
-
[keywords='']
String optionalThe collection of keywords for meta
-
[privilege=0]
Int optionalThe minimum privilege required to view this page
-
[redirectId=null]
Int | Null optionalAlways redirect to another page
-
[parentId=null]
Int | Null optionalOptional page to specify as the parent (default is null at the root level)
-
[isDynamic=false]
Boolean optionalIf the page can have additional arguments after the stub URI
-
[cache=true]
Boolean optionalIf the page should always respect the site cache
Returns:
The ID if successful, false if not
autoDetectItem
-
method
Auto detect the item name based on the name of the method that called it
Parameters:
-
method
StringThe name of the method
Returns:
Returns the item or throw error
bindObject
-
data
-
dataClass
-
[prepends=null]
-
[useFirstRow=true]
Bind an associate array to a data object
Parameters:
-
data
ArrayThe data to bind
-
dataClass
StringThe name of the data class (string to bind)
-
[prepends=null]
Array optionalThe array of maps to prepend to the variables used for prepending a path or directory to a file/path/url
-
[useFirstRow=true]
Boolean optionalIf to just return the row in a return, only getting one item from a mysql array call
Returns:
The typed data object
bindObjects
-
data
-
dataClass
-
[prepends=null]
Same as bindObject but done on a whole collection
Parameters:
Returns:
The data object
call
-
[args*]
This allows for the internal dynamic calling of methods, the methods supported include getItems, getItem, updateItem, removeItem, getTotalItems, getTotalItem, getItemBy[IndexName], getTotalItemBy[IndexName], removeItemBy[IndexName], updateItemBy[IndexName].
Parameters:
-
[args*]
Mixed optionalThe collection of arguments
callByItem
-
item
-
method
-
args
Generally called for calling the item methods
Parameters:
-
item
ObjectServiceItemThe item to call for
-
method
StringThe method name to call
-
args
ArrayThe collection of additional arguments
Returns:
The result of the method call
field
-
id
-
[type=null]
-
[name=null]
Convenience function for creating a new field
Parameters:
Returns:
The new custom field object
gateway
-
uri
-
method
-
[privilege=Privilege::ANONYMOUS]
Add for use on the Gateway, these methods can be
called from javascript. For an example see the
TimeService
class.
Parameters:
Returns:
Return the instance of this for chaining
getCaller
-
[ignore=1]
Get the method/function name of the caller function
Parameters:
-
[ignore=1]
Int optionalThe depth of the call, default is the immediate function before this one is called
getPagesByParentId
-
parentId
Get all of the children pages nested within a page
Parameters:
-
parentId
IntA page's parent ID
Returns:
The collection of Page objects
getProtectedUris
()
Array
Get the collection of protected pages that are required by Canteen
Returns:
The collection protected page URIs
getStack
-
[limit=0]
-
[ignore=1]
Get the method/function name of the caller function
Parameters:
-
[limit=0]
Int optionalThe number of stack items to return, default is all
-
[ignore=1]
Int optionalThe number of stack levesl to ignore, default is the immediate function before this one is called.
hasDefaultField
-
method
Get the default part of the property name
Parameters:
-
method
StringThe name of the default method (without "ByField")
install
()
Boolean
protected
Use the install method that comes built-in, this is experimental and may not set the best default data type on the table. It's encouraged that manual adjustments are made afterwards.
Returns:
If the install was successful
installItem
-
item
Auto install the service item
Parameters:
-
item
ObjectServiceItemRegistered item
Returns:
If item was installed successfully
installItems
-
items
Auto install multiple service items
Parameters:
-
items
Array | ObjectServiceItemRegistered items as different arguments or as a collection of ObjectServiceItems
Returns:
If item was installed successfully
internalAdd
-
item
-
properties
Conviencence method to inserting a new row into a table, this does all the field validation and insert.
Parameters:
-
item
ObjectServiceItemThe item to use
-
properties
Dictionary | ObjectThe collection map of field names to values
Returns:
The result
internalGetAll
-
item
-
[lengthOrIndex=null]
-
[duration=null]
Internal getting a collection of items
Parameters:
-
item
ObjectServiceItemThe item definition
-
[lengthOrIndex=null]
Int optionalThe starting index or elements to return
-
[duration=null]
Int optionalThe duration of the items
Returns:
The collection of objects
internalGetByIndex
-
item
-
index
-
isSingle
-
search
-
[lengthOrIndex=null]
-
[duration=null]
Internal method for getting result by an index
Parameters:
-
item
ObjectServiceItemThe item definition
-
index
ObjectServiceFieldThe index field to search on
-
isSingle
BooleanIf the index search is a single
-
search
Array | MixedThe value to search on
-
[lengthOrIndex=null]
Int optionalThe starting index or elements to return
-
[duration=null]
Int optionalThe duration of the items
internalGetTotalAll
-
item
Internal getting a total number of items
Parameters:
-
item
ObjectServiceItemThe item definition
Returns:
The number of items in selection
internalGetTotalByIndex
-
item
-
index
-
isSingle
-
search
Internal method for getting result by an index
Parameters:
-
item
ObjectServiceItemThe item definition
-
index
ObjectServiceFieldThe index field to search on
-
isSingle
BooleanIf the index search is a single
-
search
Array | MixedThe value to search on
internalRemoveByIndex
-
item
-
index
-
search
The internal remove of items by index
Parameters:
-
item
ObjectServiceItemThe item definition
-
index
ObjectServiceFieldThe index field to search on
-
search
Array | MixedThe value to search on
Returns:
If the remove was successful
internalUpdateByIndex
-
item
-
index
-
search
-
prop
-
[value=null]
The internal remove of items by index
Parameters:
-
item
ObjectServiceItemThe item definition
-
index
ObjectServiceFieldThe index field to search on
-
search
MixedThe value to search on
-
prop
Dictionary | StringThe property name or map of properties to update
-
[value=null]
Mixed optionalIf updating a single property, the property name
Returns:
If the remove was successful
parse
-
content
-
substitutions
Convenience method for parsing content
Parameters:
-
content
StringThe string to parse
-
substitutions
DictionaryThe dictionary of tags to replace
Returns:
The parsed string
privilege
-
[required=Privilege::GUEST]
You can run to make sure a process requires a particular privilege
Parameters:
-
[required=Privilege::GUEST]
Int optionalThe privilege level required, default is anonymous
registerItem
-
className
-
table
-
field
-
itemName
-
itemsName
Add a new Item definition to the service. This is required before using any of the methods for updating, getting, removing. Located in the namespace Canteen\Services.
Parameters:
Returns:
The new service definition created
removePage
-
id
Remove a page
Parameters:
-
id
IdThe Page ID to remove
Returns:
If page was deleted successfully
service
-
alias
Get a service by alias
Parameters:
-
alias
StringThe alias
Returns:
The service matching the alias
setPrepends
-
maps
-
[value=null]
Set the collection or single prepend the field value
Parameters:
Returns:
The instance of this class, for chaining
setProperties
-
[props=null]
Set additional selection properties not part of the field set
Parameters:
Returns:
The instance of this class, for chaining
setup
()
Install the pages table into the database
setWhere
-
args
Register additional where clauses for the SQL select on get methods
Parameters:
Returns:
The instance of this class, for chaining
template
-
name
-
[substitutions=[]
Convenience method for parsing content
Parameters:
-
name
StringThe name of the template to parse
-
[substitutions=[]
Dictionary optionalThe dictionary of tags to replace
Returns:
The parsed string
updatePage
-
id
-
prop
-
[value=null]
Update a user property or properties
Parameters:
-
id
IntThe page ID
-
prop
String | DictionaryThe property name or an array of property => value
-
[value=null]
Mixed optionalThe value to update to
Returns:
If successfully updated
valueSet
-
A
-
[validationType=null]
Get a set of ids
Parameters:
Returns:
The MySQL formatted set of IDs
verify
-
data
-
[type=null]
-
[suppressErrors=false]
Sanitize input data using the validation types above
Parameters:
Returns:
If we don't verify and suppress errors, returns false, else returns the data
verifyField
-
item
-
name
-
[value=null]
The more manual method for verifying a field value.
Parameters:
-
item
ObjectServiceItemRegistered item
-
name
Dictionary | StringThe name of the field or a map of name=>values
-
[value=null]
Mixed optionalThe value to check against
Returns:
The instance of this object for chaining
Properties
db
Database
Convenience getter for the database connection
items
Dictionary
The dictionary of item names to ObjectServiceItem objects
parser
Parser
The parser is responsible for rendering templates
prepends
Dictionary
The list of prepend map
profiler
Profiler
The instance of the profiler for debugging performance