Comments: on this page. Click to read or post your own.

Class ViewableData

Description

Implements interfaces:

  • IteratorAggregate (internal interface)

Generic class for all data that will be accessed from a view.

View interrogate their controllers to provide them with the data they need. They to this by calling the methods provided by the ViewableData base-class, from which most Sapphire objects are inherited.

ViewableData cover page controls, controllers, and data objects. It's the basic unit of data exchange. More specifically, it's anything that can be put into a view.

If any public method on this class is prefixed with an underscore, the results are cached in memory through cachedCall().

Located in /sapphire/core/ViewableData.php (line 18)

Object
   |
   --ViewableData
Direct descendents
Class Description
SSViewerTest_ViewableData Generic class for all data that will be accessed from a view.
RequestHandlingTest_ControllerFailover Generic class for all data that will be accessed from a view.
RSSFeedTest_ItemA Generic class for all data that will be accessed from a view.
RSSFeedTest_ItemB Generic class for all data that will be accessed from a view.
RSSFeedTest_ItemC Generic class for all data that will be accessed from a view.
ModelViewer_Model Represents a single model in the model viewer
ModelViewer_Field Generic class for all data that will be accessed from a view.
ModelViewer_Relation Generic class for all data that will be accessed from a view.
BulkLoader Generic class for all data that will be accessed from a view.
TabularStyle This is a form decorator (a class that wraps around a form) providing us with some functions to display it in a Tabular style.
NestedForm This is a form decorator that lets you place a form inside another form.
TableListField_Item A single record in a TableListField.
HtmlEditorField_control Base class for HTML editor toolbar buttons.
ArrayData Lets you wrap a bunch of array data into a ViewableData object.
ViewableData_Customised A ViewableData object that has been customised with extra data. Use ViewableData->customise() to create.
ViewableData_ObjectCustomised A ViewableData object that has been customised with an extra object. Use ViewableData->customise() to create.
ViewableData_Debugger Debugger helper.
RequestHandler This class is the base class of any Sapphire object that can be used to handle HTTP requests.
DataObject A single database record & abstract class for the data-access-model.
DataObjectSet This class represents a set of ViewableData subclasses (mostly DataObject or ArrayData).
Versioned_Version Represents a single version of a record.
DBField Single field in the database.
Email Class to support sending emails.
RSSFeed RSSFeed class
RSSFeed_Entry RSSFeed_Entry class
RestfulService RestfulService class allows you to consume various RESTful APIs.
ImprintStats Generic class for all data that will be accessed from a view.
SSReport Base "abstract" class for all Report classes viewable in the Reports top menu section of CMS.
RecipientImportField_Cell Generic class for all data that will be accessed from a view.
Variable Summary
Method Summary
static string castingObjectCreator (string $fieldSchema)
static array castingObjectCreatorPair (string $fieldSchema)
string ATT_val (string $fieldName, [array $args = null])
string BaseHref ()
void buildCastingHelperCache (array &$cache)
mixed cachedCall (string $funcName, [string $identifier = null], [array $args = null])
string castingHelper (string $field)
array castingHelperPair (string $field)
string CSSClasses ([string $stopAtClass = false])
ViewableData customise (mixed $data)
void defineMethods ()
string escapeTypeForField (string $fieldName)
boolean Even ()
string EvenOdd ()
boolean First ()
void FirstLast ()
void getField (string $field)
array getXMLValues (array $elementList)
boolean hasField (string $field)
int HasPerm ( $permCode)
boolean hasValue (string $funcName, [array $args = null])
string i18nLocale ()
bool IsAjax ()
void iteratorProperties (int $pos, int $totalItems)
string JS_val (string $fieldName, [array $args = null])
boolean Last ()
boolean Middle ()
boolean MiddleString ()
mixed; obj (string $fieldName, [array $args = null], [boolean $forceReturnObject = false])
boolean Odd ()
int Pos ([int $startIndex = 1])
string RAW_val (string $fieldName, [array $args = null])
string renderWith (string|array|SSViewer $template, [ $params = null])
int SecurityID ()
void setCustomisedObj ($obj $obj)
void setField (string $field, mixed $val)
string SQL_val (string $fieldName, [array $args = null])
void ThemeDir ([subtheme $subtheme = null])
int TotalItems ()
void val ( $fieldName, [ $args = null])
string XML_val (string $fieldName, [array $args = null], [boolean $cache = false])
mixed __get (string $field)
boolean __isset (string $field)
void __set (string $field, mixed $val)
Variables
static mixed $casting = array(
'BaseHref' => 'Varchar',
'CSSClasses' => 'Varchar',
)
(line 905)

Object-casting information for class methods

  • access: public

Redefined in descendants as:
static array $castingHelperPair_cache (line 180)

Cache used by castingHelperPair().

  • access: protected
$customisedObj $customisedObj (line 61)
  • var: ViewableData_Customised|ViewableData_ObjectCustomised Saves past customisations to make them available on subsequent rendering-calls. E.g. This enables LeftAndMain to access customisations on controller-actions in Left() and Right().
  • access: protected
ViewableData $failover (line 35)

Failover object.

  • access: protected

Redefined in descendants as:
int $iteratorPos (line 23)

The iterator position.

  • access: protected
int $iteratorTotalItems (line 29)

Total number of items in the iterator.

  • access: protected
mixed $namedAs = null (line 920)

Keep a record of the parent node of this data node.

  • access: protected
mixed $parent = null (line 914)

Keep a record of the parent node of this data node.

  • access: protected

Redefined in descendants as:
array $_natural_cache = array() (line 53)

A cast of this object's controls in their native format (used by cachedCall)

  • access: protected
array $_object_cache = array() (line 41)

A cast of this object's controls in object format

  • access: protected
array $_xml_cache = array() (line 47)

A cast of this object's controls in XML-safe format

  • access: protected

Inherited Variables

Inherited from Object

Object::$class
Object::$extensions
Object::$extension_instances
Methods
static method castingObjectCreator (line 251)

Converts a field spec into an object creator.

For example: "Int" becomes "new Int($fieldName);" and "Varchar(50)" becomes "new Varchar($fieldName, 50);"

  • access: public
static string castingObjectCreator (string $fieldSchema)
  • string $fieldSchema: The field spec.
static method castingObjectCreatorPair (line 265)

Converts a field spec into an object creator pair; this is a map containing className and castingHelper.

See castingObjectCreator for more information.

  • access: public
static array castingObjectCreatorPair (string $fieldSchema)
  • string $fieldSchema: The field spec.
ATT_val (line 516)

Return the value of the given field in an XML attribute safe format.

  • access: public
string ATT_val (string $fieldName, [array $args = null])
  • string $fieldName: The field name.
  • array $args: The arguments.
BaseHref (line 787)

Return the site's absolute base URL, with a slash on the end.

string BaseHref ()
buildCastingHelperCache (line 211)

A helper function used by castingHelperPair() to build the cache.

  • access: public
void buildCastingHelperCache (array &$cache)
  • array &$cache
cachedCall (line 529)

SSViewer's data-access method.

All template calls to ViewableData are fed through this function. It takes care of caching data, and linking up parents to support Menu1_Menu2() syntax for nested data.

mixed cachedCall (string $funcName, [string $identifier = null], [array $args = null])
  • string $funcName: the method to call
  • string $identifier
  • array $args: The arguments

Redefined in descendants as:
castingHelper (line 240)

Returns the "casting helper" for the given field. A casting helper is a piece of PHP code that, when evaluated, will create an object to represent the value.

  • access: public
string castingHelper (string $field)
  • string $field: The field name.
castingHelperPair (line 193)

Returns the "casting helper" for the given field and the casting class name. A casting helper is a piece of PHP code that, when evaluated, will create an object to represent the value.

The return value is an map containing two values:

  • className: The name of the class (eg: 'Varchar')
  • castingHelper: The casting helper (eg: 'return new Varchar($fieldName);')

  • access: public
array castingHelperPair (string $field)
  • string $field: The field name

Redefined in descendants as:
CSSClasses (line 882)

Get part of class ancestry for css-class-usage.

Avoids having to subclass just to built templates with new css-classes, and allows for versatile css inheritance and overrides.

<example> <body class="$CSSClasses"> </example>

  • return: space-separated attribute encoded classes
  • uses: ClassInfo
string CSSClasses ([string $stopAtClass = false])
  • string $stopAtClass: Classname to stop traversing upwards the ancestry (Default: ViewableData)
CurrentMember (line 711)

Returns the currently logged in user.

Member CurrentMember ()

Redefined in descendants as:
CurrentPage (line 833)

Returns the current controller

Controller CurrentPage ()

Redefined in descendants as:
customise (line 746)

Add some arbitrary data to this viewabledata object. Returns a new object with the merged data.

ViewableData customise (mixed $data)
  • mixed $data: The data to add.

Redefined in descendants as:
Debug (line 824)

Return a Debugger object.

This is set up like so that you can put $Debug.Content into your template to get debugging information about $Content.

defineMethods (line 68)

Define custom methods for this object. Called once per class.

Implements failover and cached methods.

void defineMethods ()

Redefinition of:
Object::defineMethods()

Redefined in descendants as:
escapeTypeForField (line 288)

Return the string-format type for the given field.

  • return: 'xml'|'raw'
string escapeTypeForField (string $fieldName)
  • string $fieldName
Even (line 668)

Returns true if this item is an even item in the container set.

boolean Even ()
EvenOdd (line 685)

Returns 'even' if this item is an even item in the container set.

Returns 'odd' if this item is an odd item in the container set.

string EvenOdd ()
First (line 619)

Returns true if this item is the first in the container set.

boolean First ()

Redefined in descendants as:
FirstLast (line 635)

Returns 'first' if this item is the first in the container set.

Returns 'last' if this item is the last in the container set.

void FirstLast ()
getField (line 156)

Get a field by it's name. This should be overloaded in child classes.

  • access: protected
void getField (string $field)
  • string $field: fieldname

Redefined in descendants as:
getIterator (line 97)

Returns a "1 record iterator" Views <%control %> tags operate by looping over an item for as many instances as are available. When you stick a single ViewableData object in a control tag, the foreach() loop still needs to work. We do this by creating an iterator that only returns one record.

This will always return the current ViewableData object.

  • return: A 1 record iterator
ViewableData_Iterator getIterator ()

Implementation of:
IteratorAggregate::getIterator

Redefined in descendants as:
getXMLValues (line 472)

Return a named array of calls to XML_val with different parameters.

Each value in the array is used as the first argument to XML_val. The result is a named array of the return values.

The intended use-case is when converting simple templates to PHP methods to optimise code, as we did in the form classes. If you're calling renderWith more than a few times on a very simple template, this can be useful.

extract(getXMLValues(array('Title','Field','Message'))) // You can now use $Title, $Field, and $Message as you would in a template

  • access: public
array getXMLValues (array $elementList)
  • array $elementList: The list of field names.
hasField (line 173)

Checks if a field exists on this object. This should be overloaded in child classes.

  • access: public
boolean hasField (string $field)
  • string $field: The field name

Redefined in descendants as:
HasPerm (line 736)

Checks if the current user has the given permission.

Can be used to implement security-specific sections within templates

  • return: The Permission record-ID if the permission can be found, null otherwise
int HasPerm ( $permCode)
  • $permCode
hasValue (line 594)

Returns true if the given method/parameter has a value

If the item is an object, it will use the exists() method to determine existence

boolean hasValue (string $funcName, [array $args = null])
  • string $funcName: The function name.
  • array $args: The arguments.

Redefined in descendants as:
i18nLocale (line 814)
  • return: Locale configured in environment settings or user profile (e.g. 'en_US')
string i18nLocale ()
IsAjax (line 807)

Returns wether the current request is triggered by an XMLHTTPRequest object.

bool IsAjax ()
iteratorProperties (line 610)

Set up the "iterator properties" for this object.

These are properties that give information about where we are in the set.

void iteratorProperties (int $pos, int $totalItems)
  • int $pos: Position in iterator
  • int $totalItems: Total number of items
JS_val (line 506)

Return the value of the given field in an JavaScript safe format.

  • access: public
string JS_val (string $fieldName, [array $args = null])
  • string $fieldName: The field name.
  • array $args: The arguments.
Last (line 627)

Returns true if this item is the last in the container set.

boolean Last ()

Redefined in descendants as:
Me (line 797)

When rendering some objects it is necessary to iterate over the object being rendered, to do this, you need access to itself.

ViewableData Me ()
Middle (line 660)

Returns true if this item is one of the middle items in the container set.

boolean Middle ()
MiddleString (line 649)

Returns 'middle' if this item is between first and last.

boolean MiddleString ()
obj (line 303)

Return the object version of the given field/method.

  • access: public
mixed; obj (string $fieldName, [array $args = null], [boolean $forceReturnObject = false])
  • string $fieldName: The name of the field/method.
  • array $args: The arugments.
  • boolean $forceReturnObject: If true, this method will *always* return an object. If there's no sensible one available, it will return new ViewableData()

Redefined in descendants as:
Odd (line 676)

Returns true if this item is an even item in the container set.

boolean Odd ()
Pos (line 695)

Returns the numerical number of this item in the dataset.

The count starts from $startIndex, which defaults to 1.

int Pos ([int $startIndex = 1])
  • int $startIndex: Number to start count from.
RAW_val (line 486)

Return the value of the given field without any escaping.

  • access: public
string RAW_val (string $fieldName, [array $args = null])
  • string $fieldName: The field name.
  • array $args: The arguments.
renderWith (line 765)

Render this data using the given template, and return the result as a string You can pass one of the following:

  • A template name.

  • An array of template names. The first template that exists will be used.
  • An SSViewer object.

string renderWith (string|array|SSViewer $template, [ $params = null])
  • string|array|SSViewer $template: The template.
  • $params
SecurityID (line 720)

Returns the Security ID.

This is used to prevent CRSF attacks in forms.

int SecurityID ()
setCustomisedObj (line 583)
void setCustomisedObj ($obj $obj)
  • $obj $obj: ViewableData_Customised|ViewableData_ObjectCustomised
setField (line 164)

Set a fields value. This should be overloaded in child classes.

  • access: protected
void setField (string $field, mixed $val)
  • string $field: The field name.
  • mixed $val: The field value.

Redefined in descendants as:
SQL_val (line 496)

Return the value of the given field in an SQL safe format.

  • access: public
string SQL_val (string $fieldName, [array $args = null])
  • string $fieldName: The field name.
  • array $args: The arguments.
ThemeDir (line 859)

Returns the root directory of the theme we're working with.

This can be useful for referencing images within the theme. For example, you might put a reference to <img src="$ThemeDir/images/something.gif"> in your template.

If your image is within a subtheme, such as mytheme_forum, you can set the subtheme parameter. For example, <img src="$ThemeDir(forum)/images/something.gif">

We don't recommend that you use this method when no theme is selected. That is, we recommend that you only put $ThemeDir into your theme templates. However, if no theme is selected, this will be the project folder/

  • access: public
void ThemeDir ([subtheme $subtheme = null])
  • subtheme $subtheme: The subtheme name.
Top (line 841)

Returns the top level ViewableData being rendered.

ViewableData Top ()
TotalItems (line 703)

Return the total number of "sibling" items in the dataset.

int TotalItems ()

Redefined in descendants as:
val (line 369)

Return the value (non-object) version of the given field/method.

  • deprecated: ViewableData->val() is deprecated, use XML_val() instead
  • access: public
void val ( $fieldName, [ $args = null])
  • $fieldName
  • $args
XML_val (line 380)

Returns the value of the given field / method in an XML-safe format.

  • access: public
string XML_val (string $fieldName, [array $args = null], [boolean $cache = false])
  • string $fieldName: The field name.
  • array $args: The arguments.
  • boolean $cache: Cache calls to this function.

Redefined in descendants as:
__get (line 108)

Accessor overloader.

Allows default getting of fields via $this->getVal(), or mediation via a getParamName() method.

  • return: The field.
  • access: public
mixed __get (string $field)
  • string $field: The field name.

Redefined in descendants as:
__isset (line 140)

Is-set overloader.

Will check to see if the given field exists on this object. Calls the hasField() method, as well as checking failover classes.

  • return: True if field exists
  • access: public
boolean __isset (string $field)
  • string $field: The field name.
__set (line 125)

Setter overloader.

Allows default setting of fields in $this->setValue(), or mediation via a getParamName() method.

  • access: public
void __set (string $field, mixed $val)
  • string $field: The field name.
  • mixed $val: The field value.

Redefined in descendants as:

Inherited Methods

Inherited From Object

Object::__construct()
Object::addMethodsFrom()
Object::addStaticVars()
Object::addWrapperMethod()
Object::add_extension()
Object::add_static_var()
Object::allMethodNames()
Object::buildMethodList()
Object::cacheToFile()
Object::cacheToFileWithArgs()
Object::clearCache()
Object::combined_static()
Object::create()
Object::createMethod()
Object::defineMethods()
Object::exists()
Object::extend()
Object::extInstance()
Object::getCustomClass()
Object::get_static()
Object::hasExtension()
Object::hasMethod()
Object::has_extension()
Object::invokeWithExtensions()
Object::is_a()
Object::loadCache()
Object::parentClass()
Object::remove_extension()
Object::sanitiseCachename()
Object::saveCache()
Object::set_stat()
Object::set_static()
Object::set_uninherited()
Object::stat()
Object::strong_create()
Object::uninherited()
Object::uninherited_static()
Object::useCustomClass()
Object::__call()
Object::__toString()
blog comments powered by Disqus

Documentation generated on Mon, 23 Mar 2009 06:58:51 +1300 by phpDocumentor 1.3.2