TIP_Content

Index

Introduction

The root of data based modules

Source file
/Type/module/content.php
Extends
TIP_Module

This class mainly adds a data management infrastructure to TIP_Module, allowing for a full interaction between TIP_Template and TIP_Data throught the use of TIP_Data_View instances.

Properties

data : TIP_Data

Contains a reference to the binded TIP_Data object

access
protected

view_template : string

The file to run on view actions

access
protected

browse_template : string

The file to run on browse actions

access
protected

pager_pre_template : string

The file to run at the beginning of a 'pager' tag

access
protected

This template must reside in the application directory.

pager_template : string

The file to run for every row on the 'pager' tag

access
protected

pager_empty_template : string

The file to run on empty result set

access
protected

This template must reside in the application directory.

pager_post_template : string

The file to run at the end of a 'pager' tag

access
protected

This template must reside in the application directory.

atom_template : string

The file to run to generate the atom feed

access
protected

creation_field : string

The magic field id containing the creation datetime

access
protected

owner_field : string

The magic field id containing to owner user id

access
protected

browse_field : string

The magic field id to use by default on browse actions

access
protected

edited_field : string

The magic field id containing the last edit datetime

access
protected

editor_field : string

The magic field id containing the user id of the last editor

access
protected

edits_field : string

The magic field id containing the counter of edits performed a row

access
protected

hits_field : string

The magic field id containing the counter of actionView

access
protected

title_field : string

The magic field id specifying the title for rendering operations

access
protected

tooltip_field : string|null

The magic field id specifying the tooltip for rendering operations

access
protected

last_hit_field : string

The magic field containing the date of the last actionView

access
protected

search_field : string|array

The search field(s) to be scanned

access
protected

user_statistic : array

Statistic user fields

access
protected

An associative array of field ids in TIP_User to increment whenever a callback action in this module has been called.

default_conditions : array|string

Default browse conditions

access
protected

A default filter, specified as string, or an array of "field id" => values to be applied on any browse action.

default_order : string

Default order field

access
protected

browsable_fields : array

Browsable fields

access
protected

An array of field ids enabled in the 'browse' action, specified for each privilege.

form_options : array

Explicit options to pass to the form

access
protected

id_type : string

The type of the id field: any valid settype() type is allowed

access
protected

ownership_expiration : string

Enable expiration time for row ownership

access
protected

If set, the isOwner() and related methods will return true only if the request is done before this time is elapsed after the creation of the row. Obviously, this means the "creation_field" property must be set and work properly.

Any value accepted by the strtotime() function is valid.

Methods

checkOptions (&$options)

&$options
lines
231 - 250
static
yes
access
protected

__construct ($options)

Constructor

$options
array
Properties values
lines
259 - 262
access
protected

Initializes a TIP_Content instance.

getData () : &TIP_Data

Get the active TIP_Data instance

lines
272 - 275
access
public

getCurrentView () : &TIP_View|null

Get the current view

lines
282 - 285
access
public

getField ($id) : mixed|null

Get a field value

$id
string
The field id
lines
295 - 298
access
public

Gets a field from the current row of the current view.

getSummary ($id) : mixed|null

Get a summary value

$id
string
The summary id
lines
308 - 311
access
public

Gets a summary value from the current view.

getItem ($id) : mixed|null

Return the value of a generic item

$id
string
The item id
lines
339 - 365
access
public

Gets the value of a generic item. This implementation adds the field feature to the TIP_Module::getItem() method.

Getting an item performs some search operations with this priority:

* If the field is not found but the current view is not a TIP_Data_View (that is, it is not a TIP_Data_View object), it scans the view stack for the last view that was of TIP_Data_View type and checks if $id is present as a field in the current row. This because views others than TIP_Data_View are considered "weaks",

that is their values are not built from real data fields.

* Summary value of the current view throught getSummary().

* Chain-up the parent method TIP_Module::getItem().

The first succesful search operation will stop the sequence.

form ($action, [$id], [$options]) : bool|null

Form management

$action
TIP_FORM_ACTION_...
The action
$id
array|null [ = null ]
A row id to use as default
$options
array [ = array() ]
The options to pass to the form
lines
389 - 412
access
protected

Generates a form with the specified $options and executes $action on it.

The default values of the form (that usually must be present in $options['defaults']) can also be specified by providing a row $id. If both are provided, the two arrays are merged, with the one in $options['defaults'] with higher priority. Before merging, if $action is TIP_FORM_ACTION_ADD, the primary key on the read row is stripped.

If $action is not TIP_FORM_ACTION_ADD and either $id or $options['defaults'] are not provided, the current row is assumed as default values. If there is not current row, an error is raised.

push (&$view) : &TIP_View|null

Push a view

&$view
TIP_View
The view to push
lines
423 - 433
access
public

Pushes a view object in the stack of this module. You can restore the previous view calling pop().

pop () : &TIP_View|null|false

Pop a view

lines
444 - 462
access
public

Pops a view object from the stack of this module. This operation restores the previously active view.

startView ($type, [$options]) : &TIP_View|null

Start a generic view

$type
string
The view type
$options
array [ = array() ]
The constructor arguments to pass to the TIP_View derived instance
lines
481 - 497
access
public

Starts a view trying to instantiate the class named "TIP_{$type}_View".

Furthermore, some options are automatically set to the following defaults if not explicitely specified in the $options array: * $options['data'] = the TIP_Data object of this module

startDataView ([$filter], [$options]) : &TIP_Data_View|null

Start a data view

$filter
string [ = null ]
The filter conditions
$options
array [ = array() ]
The constructor arguments to pass to the TIP_Data_View instance
lines
518 - 562
access
public

Creates a TIP_Data_View instance, providing also an easy way to specify the filter instead of setting $options['filter'].

The main difference between this function and using startView() directly is that here "default_conditions" and "default_order" properties are automatically applied on global queries (that is, whenever $filter is empty). In this case, the model used by the rendering operations is populated too.

See startView() for further details.

endView () : bool

Ends a view

lines
577 - 585
access
public

Ends the current view. Ending a view means the previously active view in the internal stack is made current.

Usually, you always have to close all views. Anyway, in some situations, is useful to have the base view ever active (so called default view) where all tags of a TIP_Content refers if no views were started. In any case, you can't have more endView() than start[Data]View().

fromGet ([$id], [$type]) : mixed|null

Get a specific GET value

$id
mixed [ = null ]
The get id
$type
[ = 'integer' ]
lines
599 - 608
access
public

If $id is not specified, it defaults to the primary key of the binded data.

This is an high level method that notify errors to the user if $id is not found.

fromGetOrPost ([$id], [$type]) : mixed|null

Get a specific GET or POST value

$id
mixed [ = null ]
The get/post id
$type
[ = 'integer' ]
lines
622 - 636
access
public

If $id is not specified, it defaults to the primary key of the binded data.

This is an high level method that notify errors to the user if $id is not found.

fromRow ([$id], [$end_view]) : &array|null

Get a specific row

$id
mixed [ = null ]
The row id
$end_view
bool [ = true ]
Whether to end the view or not
lines
654 - 683
access
public

Gets a reference to a specific row. If $id is not specified, the current row is assumed.

This is an high level method that notify errors to the user if the row is not found.

The method starts (and ends) a view to find a row, so every further requests will be cached.

isOwner ([$id]) : bool

Check if a row is owned by the current user

$id
mixed [ = null ]
The row id
lines
700 - 713
access
public

Checks if the owner field in the row identified by $id is equal to the current user id, that is if $id is owned by the current user.

This is an high level method that raises errors and notify them to the user on any errors: use it only when error notify is needed.

If there are no errors but the row is not owned by the current user, the 'denied' error is notified.

isNotOwner ([$id]) : bool

Check if a row is not owned by the current user

$id
mixed [ = null ]
The row id
lines
724 - 737
access
public

Similar to isOwner(), but works in the reverse way: check if the row identified by $id is NOT owned by the current user.

filterOwnedBy ($user) : string

Shortcut to build a filter on the owned field

$user
mixed
The user id
lines
744 - 747
access
public

setMagicFields (&$row)

Update the magic fields

&$row
array
The row to check
lines
757 - 761
access
public

Fills the magic fields (if found and not set) with their magic values.

toHtml ([$action]) : string|null

Render to XHTML

$action
string [ = null ]
The action template string
lines
769 - 776
access
public

toRows ([$action]) : array|null

Render to rows

$action
string [ = null ]
The action template string
lines
788 - 795
access
public

Builds an array of rows from this content data. Useful to automatically define the options of a <select> item for a TIP_Form instance.

toRow ($ids, [$action]) : array|null

Render specific rows

$ids
mixed|array
The id/ids of the rows to render
$action
string [ = null ]
The action template string
lines
807 - 825
access
public

Works in the same way of toRows(), but rendering only the rows with the id specified in the $ids array.

tagHtml ($params, [$raise_error]) : string|null

Htmlize the first defined request

$params
string
Parameters of the tag
$raise_error
boolean [ = false ]
Whether to generate an error
lines
843 - 872
access
protected

Overrides the default tagHtml() providing highlighting on requests of search fields.

tagSubset ($params) : string|null

Fields to use in the next queries

$params
string
Parameters of the tag
lines
881 - 885
access
protected

Changes the field subset in SELECT queries. $params must be a comma separated list of field ids. If $params is empty the default fieldset will be used.

tagWiki ($params) : string|null

Wikize the field specified in $params

$params
string
Parameters of the tag
lines
894 - 931
access
protected

The value of the field with $params id is parsed and rendered by the Text_Wiki renderer accordling to the wiki rules defined in the widget args of this field.

tagPartialWiki ($params) : string|null

Get a partial content of a wiki field

$params
string
Parameters of the tag
lines
941 - 992
access
protected

$params must be a string in the form "field_id[,len[,wordlen]]", where id is the id of a wiki field, len is the number of characters to be echoed and wordlen is the maximum length of a single word. len defaults to 100 while wordlen defaults to 25.

tagAtom ($params) : string|null

Return a link to the atom feeder

$params
string
Parameters of the tag
lines
1003 - 1071
access
protected

In $params you can specify a query to perform, a date field or leave it blank to use the default behavior (that is use the $creation_field).

The default behaviour is to keep the last three days or (for empty result set) the last ten records.

tagChronology ($params) : string|null

Browse the content throught a chronology interface

$params
string
Parameters of the tag
lines
1085 - 1126
access
protected

Renders the whole data content in a chronology tree. The options must be specified in the $params argument as a comma-separated list of field ids in the following sequence:

date_field,title_field,tooltip_field,count_field,base_action

All the fields are optionals, in which case the TIP_Chronology default value is used.

tagPager ($params) : string|null

Perform the browse query throught a pager

$params
string
Parameters of the tag
lines
1141 - 1243
access
protected

$params is a string in the form "quanto,query_adds".

The quanto is the number of rows per page: leave it undefined to disable the pager. In query_adds you can specify additional SQL commands to append to the query, such as ORDER clauses.

This function checks if there is a row more than what specified in the quanto: this provides a simple way to know whether the 'NEXT' button must be rendered or not.

tagShow ($params) : string|null

Echo the rendered XHTML

$params
string
Parameters of the tag
lines
1251 - 1254
access
protected

Renders the whole TIP_Content rows in XHTML. In $params there should be the template action string to use to build the links.

tagView ($params) : string|null

View the current row content

$params
string
Parameters of the tag
lines
1262 - 1287
access
protected

Shows the current row using a standard frozen form. If $params is specified, the row with $params as primary key is shown instead.

actionAdd ([$id], [$options]) : bool

Perform an add action

$id
mixed [ = null ]
The identifier of the row to duplicate
$options
array [ = array() ]
Options to pass to the form() call
lines
1312 - 1339
access
protected

Generates and executes a TIP_Form instance to add a new row. The $id argument can be used to duplicate an existing row. If left null, an empty row is used as default.

If no $options are specified, the default behaviour is to render the form in the page and to try to call actionView() on the result when the form is validated.

Notice also that $options['on_process'], if not specified, will be set to the _onAdd() default callback.

actionEdit ($id, [$options]) : bool

Perform an edit action

$id
mixed
The identifier of the row to edit
$options
array [ = array() ]
Options to pass to the form() call
lines
1356 - 1365
access
protected

Generates and executes a TIP_Form instance to edit a row.

If no $options are specified, the default behaviour is to render both valid and invalid form in the page.

Notice also that $options['on_process'], if not specified, will be set to the _onEdit() default callback.

actionDelete ($id, [$options]) : bool

Perform a delete action

$id
mixed
The identifier of the row to delete
$options
array [ = array() ]
Options to pass to the form() call
lines
1382 - 1391
access
protected

Generates and executes a TIP_Form instance to delete a row.

If no $options are specified, the default behaviour is to render both valid and invalid form in the page.

Notice also that $options['on_process'], if not specified, will be set to the _onDelete() default callback.

actionView ($id) : bool

Perform a view action

$id
mixed
The identifier of the row to view
lines
1402 - 1416
access
protected

Runs the file identified by the 'view_template' property for the specified row. The rendered result is appended to the page.

actionBrowse (&$conditions) : bool

Perform a browse action

&$conditions
array
The browse conditions
lines
1428 - 1438
access
protected

In $conditions, you must specify an associative array of 'field_id' => 'value' to impose for this browse action. Only equal conditions are allowed.

actionSearch ($pattern) : bool

Perform a search action

$pattern
string
The search pattern
lines
1446 - 1456
access
protected

runManagerAction ($action)

$action
lines
1458 - 1469
access
protected

runAdminAction ($action)

$action
lines
1471 - 1482
access
protected

runTrustedAction ($action)

$action
lines
1484 - 1502
access
protected

runUntrustedAction ($action)

$action
lines
1504 - 1513
access
protected

runAction ($action)

$action
lines
1515 - 1563
access
protected
TIP_Content was last modified by TiP on Mon 25 May 2009 06:22:25 PM CEST
Hosted by BerliOS Developer Logo