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

Class DataObjectSet

Description

Implements interfaces:

  • IteratorAggregate (internal interface)

This class represents a set of ViewableData subclasses (mostly DataObject or ArrayData).

It is used by the ORM-layer of Silverstripe to return query-results from SQLQuery.

Located in /sapphire/core/model/DataObjectSet.php (line 14)

Object
   |
   --ViewableData
      |
      --DataObjectSet
Direct descendents
Class Description
FieldSet DataObjectSet designed for form fields.
ComponentSet This is a special kind of DataObjectSet used to represent the items linked to in a 1-many or many-many join. It provides add and remove methods that will update the database.
Variable Summary
boolean $first
array $items
boolean $last
mixed $odd
Method Summary
DataObjectSet __construct ([ViewableData|array|mixed $items = null])
void addWithoutWrite (DataObject $field)
string buildNestedUL (array $nestingLevels, [string $ulExtraAttributes = ""])
array column ([string $value = "ID"])
array consolidate ( $args, array|string $args,...)
string consolidateString ()
void containsIDs ($idList $idList)
int Count ()
int CurrentPage ()
string debug ()
void destroy ()
boolean exists ()
void filter_map ( $key,  $value)
ViewableData find ( $key,  $value)
void FirstItem ()
string forTemplate ()
string getChildrenAsUL (array $nestingLevels, [int $level = 0], [string $template = "<li id=\"record-\$ID\" class=\"\$EvenOdd\">\$Title"], [string $ulExtraAttributes = null], [ &$itemCount = 0])
DataObjectSet getRange (int $offset, int $length)
array groupBy (string $index)
DataObjectSet GroupedBy (string $index, [string $childControl = "Children"])
DataObjectSet groupWithParents (string $groupField, string $groupClassName, [string $sortParents = null], [string $parentField = 'ID'], [boolean $collapse = false], [string $requiredParents = null])
void insertFirst (DataObject $item, [string $key = null])
void LastItem ()
array map ([string $key = "ID"], [string $value = "Title"], [string $includeBlank = null])
array map_multiple ([string $key = "ID"], [array $values = array("FirstName", "Surname")], [boolean $withdash = false])
void merge (DataObjectSet $anotherSet)
boolean MoreThanOnePage ()
string NextLink ()
boolean NotFirstPage ()
boolean NotLastPage ()
void onlyContainsIDs ($idList $idList)
DataObjectSet Pages ([int $maxPages = 0])
void parseQueryLimit (SQLQuery $query)
string PrevLink ()
void push (DataObject $item, [string $key = null])
void remove (DataObject $itemObject)
void setPageLength (int $length)
void setPageLimits (int $pageStart, int $pageLength, int $totalSize)
void setPaginationGetVar (string $var)
void shift (DataObject $item)
void sort (string $fieldname, [string $direction = "ASC"])
array toArray ([string $index = null])
array toDropDownMap ([string $index = "ID"], [string $titleField = "Title"], [string $emptyString = null])
array toNestedArray ([string $index = null])
int TotalItems ()
int TotalPages ()
string UL ()
Variables
DataObject $current = null (line 39)

The current DataObject in this set.

  • access: protected
boolean $first = true (line 27)

True if the current DataObject is the first in this set.

  • access: protected
array $items = array() (line 19)

The DataObjects in this set.

  • access: protected
boolean $last = false (line 33)

True if the current DataObject is the last in this set.

  • access: protected
mixed $odd = 0 (line 21)
  • access: protected
int $pageLength (line 51)

The number of objects per page.

  • access: protected
int $pageStart (line 45)

The number object the current page starts at.

  • access: protected
string $paginationGetVar = "start" (line 63)

The pagination GET variable that controls the start of this set.

  • access: protected
int $totalSize (line 57)

Total number of DataObjects in this set.

  • access: protected

Inherited Variables

Inherited from ViewableData

ViewableData::$casting
ViewableData::$castingHelperPair_cache
ViewableData::$customisedObj
ViewableData::$failover
ViewableData::$iteratorPos
ViewableData::$iteratorTotalItems
ViewableData::$namedAs
ViewableData::$parent
ViewableData::$_natural_cache
ViewableData::$_object_cache
ViewableData::$_xml_cache

Inherited from Object

Object::$builtInMethods
Object::$class
Object::$classConstructed
Object::$extensions
Object::$extension_instances
Object::$extraMethods
Object::$extraStatics
Object::$statics
Object::$static_cached
Methods
Constructor __construct (line 71)

Create a new DataObjectSet. If you pass one or more arguments, it will try to convert them into ArrayData objects.

  • todo: Does NOT automatically convert objects with complex datatypes (e.g. converting arrays within an objects to its own DataObjectSet)
  • access: public
DataObjectSet __construct ([ViewableData|array|mixed $items = null])
  • ViewableData|array|mixed $items: Parameters to use in this set, either as an associative array, object with simple properties, or as multiple parameters.

Redefinition of:
Object::__construct()

Redefined in descendants as:
addWithoutWrite (line 902)

Add a field to this set without writing it to the database

void addWithoutWrite (DataObject $field)
buildNestedUL (line 696)

Returns a nested unordered list out of a "chain" of DataObject-relations, using the automagic ComponentSet-relation-methods to find subsequent DataObjectSets.

The formatting of the list can be different for each level, and is evaluated as an SS-template with access to the current DataObjects attributes and methods.

Example: Groups (Level 0, the "calling" DataObjectSet, needs to be queried externally) and their Members (Level 1, determined by the Group->Members()-relation).

  • return: Unordered List (HTML)
  • access: public
string buildNestedUL (array $nestingLevels, [string $ulExtraAttributes = ""])
  • array $nestingLevels: Defines relation-methods on DataObjects as a string, plus custom SS-template-code for the list-output. Use "Root" for the current DataObjectSet (is will not evaluate into a function). Caution: Don't close the list-elements (determined programatically). You need to escape dollar-signs that need to be evaluated as SS-template-code. Use $EvenOdd to get appropriate classes for CSS-styling. Format: array( array( "dataclass" => "Root", "template" => "<li class=\"\$EvenOdd\"><a href=\"admin/crm/show/\$ID\">\$AccountName</a>" ), array( "dataclass" => "GrantObjects", "template" => "<li class=\"\$EvenOdd\"><a href=\"admin/crm/showgrant/\$ID\">#\$GrantNumber: \$TotalAmount.Nice, \$ApplicationDate.ShortMonth \$ApplicationDate.Year</a>" ) );
  • string $ulExtraAttributes: Extra attributes
column (line 624)

Return a column of the given field

  • access: public
array column ([string $value = "ID"])
  • string $value: The field name
consolidate (line 104)

Consolidate the DataObjectSet into an array of arrays

The array will contain the field values of the specified fields

  • access: public
array consolidate ( $args, array|string $args,...)
  • array|string $args,...: The field names, either as an array, or as multiple strings.
  • $args
consolidateString (line 121)

Consolidate the DataObjectSet into XHTML The string will contain the field values of the specified fields.

  • access: public
string consolidateString ()
containsIDs (line 910)

Returns true if the DataObjectSet contains all of the IDs givem

void containsIDs ($idList $idList)
  • $idList $idList: An array of object IDs
Count (line 506)

Returns the actual number of items in this dataset.

  • access: public
int Count ()
CurrentPage (line 246)

Returns the number of the current page.

  • access: public
int CurrentPage ()

Redefinition of:
ViewableData::CurrentPage()
Returns the current controller
debug (line 784)

Returns information about this set in HTML format for debugging.

  • access: public
string debug ()

Redefined in descendants as:
destroy (line 138)

Destory all of the DataObjects in this set.

  • access: public
void destroy ()
exists (line 466)

Returns false if the set is empty.

  • access: public
boolean exists ()

Redefinition of:
Object::exists()
Returns true if this object "exists", i.e., has a sensible value.
filter_map (line 600)

Temporary filter method for filtering a list based on multiple fields of the DataObject.

Question: should any args be passed to the filter function?

  • todo: deprecate toDropdownMap() and map_multiple(), rename this method to map()
  • access: public
void filter_map ( $key,  $value)
  • $key
  • $value
find (line 613)

Find an item in this list where the field $key is equal to $value

Eg: $doSet->find('ID', 4);

  • return: The first matching item.
  • access: public
ViewableData find ( $key,  $value)
  • $key
  • $value
First (line 474)

Return the first item in the set.

  • access: public
DataObject First ()

Redefinition of:
ViewableData::First()
Returns true if this item is the first in the container set.
FirstItem (line 331)
void FirstItem ()
forTemplate (line 530)

Returns this set as a XHTML unordered list.

  • access: public
string forTemplate ()
getChildrenAsUL (line 709)

Gets called recursively on the child-objects of the chain.

  • access: protected
string getChildrenAsUL (array $nestingLevels, [int $level = 0], [string $template = "<li id=\"record-\$ID\" class=\"\$EvenOdd\">\$Title"], [string $ulExtraAttributes = null], [ &$itemCount = 0])
  • array $nestingLevels: see {@buildNestedUL}
  • int $level: Current nesting level
  • string $template: Template for list item
  • string $ulExtraAttributes: Extra attributes
  • &$itemCount
getIterator (line 458)

Returns an Iterator for this DataObjectSet.

This function allows you to use DataObjectSets in foreach loops

  • access: public
DataObjectSet_Iterator getIterator ()

Redefinition of:
ViewableData::getIterator()
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.

Implementation of:
IteratorAggregate::getIterator
getRange (line 443)

Gets a specific slice of an existing set.

  • access: public
DataObjectSet getRange (int $offset, int $length)
  • int $offset
  • int $length
groupBy (line 637)

Returns an array of DataObjectSets. The array is keyed by index.

  • access: public
array groupBy (string $index)
  • string $index: The field name to index the array by.
GroupedBy (line 654)

Groups the items by a given field.

Returns a DataObjectSet suitable for use in a nested template.

  • access: public
DataObjectSet GroupedBy (string $index, [string $childControl = "Children"])
  • string $index: The field to group by
  • string $childControl: The name of the nested page control
groupWithParents (line 805)

Groups the set by $groupField and returns the parent of each group whose class is $groupClassName. If $collapse is true, the group will be collapsed up until an ancestor with the given class is found.

  • access: public
DataObjectSet groupWithParents (string $groupField, string $groupClassName, [string $sortParents = null], [string $parentField = 'ID'], [boolean $collapse = false], [string $requiredParents = null])
  • string $groupField: The field to group by.
  • string $groupClassName: Classname.
  • string $sortParents: SORT clause to insert into the parents SQL.
  • string $parentField: Parent field.
  • boolean $collapse: Collapse up until an ancestor with the given class is found.
  • string $requiredParents: Required parents
insertFirst (line 392)

Add an item to the beginning of the DataObjectSet

  • access: public
void insertFirst (DataObject $item, [string $key = null])
  • DataObject $item: Item to add
  • string $key: Key to index this DataObject by.
Last (line 486)

Return the last item in the set.

  • access: public
DataObject Last ()

Redefinition of:
ViewableData::Last()
Returns true if this item is the last in the container set.
LastItem (line 335)
void LastItem ()
map (line 567)

Returns the dataset as an array of ID => Title.

  • todo: Duplication from toDropdownMap()
  • access: public
array map ([string $key = "ID"], [string $value = "Title"], [string $includeBlank = null])
  • string $key: The field you wish to use as a key for the array
  • string $value: The field or method you wish to use to get values for the map
  • string $includeBlank: String for no option selected
map_multiple (line 541)

Returns the dataset as an array of ID => "FirstName Surname"

  • access: public
array map_multiple ([string $key = "ID"], [array $values = array("FirstName", "Surname")], [boolean $withdash = false])
  • string $key: Field name to index the array.
  • array $values: An array of fieldnames to insert in array
  • boolean $withdash: Add dashes inbetween values
merge (line 428)

Merge another set onto the end of this set.

  • access: public
void merge (DataObjectSet $anotherSet)
MoreThanOnePage (line 327)

Returns true if there is more than one page.

  • access: public
boolean MoreThanOnePage ()
NextLink (line 357)

Returns the URL of the next page.

  • access: public
string NextLink ()
NotFirstPage (line 311)

Returns true if the current page is not the first page.

  • access: public
boolean NotFirstPage ()
NotLastPage (line 319)

Returns true if the current page is not the last page.

  • access: public
boolean NotLastPage ()
onlyContainsIDs (line 921)

Returns true if the DataObjectSet contains all of and *only* the IDs given.

Note that it won't like duplicates very much.

void onlyContainsIDs ($idList $idList)
  • $idList $idList: An array of object IDs
Pages (line 272)

Return a datafeed of page-links, good for use in search results, etc.

$maxPages will put an upper limit on the number of pages to return. It will show the pages surrounding the current page, so you can still get to the deeper pages.

  • access: public
DataObjectSet Pages ([int $maxPages = 0])
  • int $maxPages: The maximum number of pages to return
parseQueryLimit (line 224)

Use the limit from the given query to add prev/next buttons to this DataObjectSet.

  • access: public
void parseQueryLimit (SQLQuery $query)
  • SQLQuery $query: The query used to generate this DataObjectSet
PrevLink (line 347)

Returns the URL of the previous page.

  • access: public
string PrevLink ()
push (line 378)

Add an item to the DataObject Set.

  • access: public
void push (DataObject $item, [string $key = null])
  • DataObject $item: Item to add.
  • string $key: Key to index this DataObject by.

Redefined in descendants as:
remove (line 416)

Remove a DataObject from this set.

  • access: public
void remove (DataObject $itemObject)

Redefined in descendants as:
removeDuplicates (line 770)

Remove duplicates from this set based on the dataobjects ID.

Assumes all items contained in the set all have IDs.

  • access: public
void removeDuplicates ()
setPageLength (line 204)

Set number of objects on each page.

  • access: public
void setPageLength (int $length)
  • int $length: Number of objects per page
setPageLimits (line 214)

Set the page limits.

  • access: public
void setPageLimits (int $pageStart, int $pageLength, int $totalSize)
  • int $pageStart: The start of this page.
  • int $pageLength: Number of objects per page
  • int $totalSize: Total number of objects.
setPaginationGetVar (line 369)

Allows us to use multiple pagination GET variables on the same page (eg. if you have search results and page comments on a single page)

Example: @see PageCommentInterface::Comments()

  • access: public
void setPaginationGetVar (string $var)
  • string $var: The variable to go in the GET string (Defaults to 'start')
shift (line 408)

Insert a DataObject at the beginning of this set.

  • access: public
void shift (DataObject $item)
sort (line 760)

Returns a new DataObjectSet of the sorted array

  • access: public
void sort (string $fieldname, [string $direction = "ASC"])
  • string $fieldname: the name of the field on the dataobject that you wish to sort the set by
  • string $direction: the direction of the sort e.g. Ascending = ASC ( LIKE SQL )
toArray (line 149)

Convert this DataObjectSet to an array of DataObjects.

  • access: public
array toArray ([string $index = null])
  • string $index: Index the array by this field.
toDropDownMap (line 189)

Returns an array of ID => $titleField

  • access: public
array toDropDownMap ([string $index = "ID"], [string $titleField = "Title"], [string $emptyString = null])
  • string $index: The field you wish to use as a key for the array
  • string $titleField: The field or method you wish to use to get values for the map
  • string $emptyString: String for no option selected
toNestedArray (line 168)

Convert this DataObjectSet to an array of maps.

  • access: public
array toNestedArray ([string $index = null])
  • string $index: Index the array by this field.
TotalItems (line 498)

Return the total number of items in this dataset.

  • access: public
int TotalItems ()

Redefinition of:
ViewableData::TotalItems()
Return the total number of "sibling" items in the dataset.
TotalPages (line 254)

Returns the total number of pages.

  • access: public
int TotalPages ()
UL (line 514)

Returns this set as a XHTML unordered list.

  • access: public
string UL ()

Inherited Methods

Inherited From ViewableData

ViewableData::ATT_val()
ViewableData::BaseHref()
ViewableData::buildCastingHelperCache()
ViewableData::cachedCall()
ViewableData::castingHelper()
ViewableData::castingHelperPair()
ViewableData::castingObjectCreator()
ViewableData::castingObjectCreatorPair()
ViewableData::CSSClasses()
ViewableData::CurrentMember()
ViewableData::CurrentPage()
ViewableData::customise()
ViewableData::Debug()
ViewableData::defineMethods()
ViewableData::escapeTypeForField()
ViewableData::Even()
ViewableData::EvenOdd()
ViewableData::First()
ViewableData::FirstLast()
ViewableData::getField()
ViewableData::getIterator()
ViewableData::getXMLValues()
ViewableData::hasField()
ViewableData::HasPerm()
ViewableData::hasValue()
ViewableData::i18nLocale()
ViewableData::IsAjax()
ViewableData::iteratorProperties()
ViewableData::JS_val()
ViewableData::Last()
ViewableData::Me()
ViewableData::Middle()
ViewableData::MiddleString()
ViewableData::obj()
ViewableData::Odd()
ViewableData::Pos()
ViewableData::RAW_val()
ViewableData::renderWith()
ViewableData::SecurityID()
ViewableData::setCustomisedObj()
ViewableData::setField()
ViewableData::SQL_val()
ViewableData::ThemeDir()
ViewableData::Top()
ViewableData::TotalItems()
ViewableData::val()
ViewableData::XML_val()
ViewableData::__get()
ViewableData::__isset()
ViewableData::__set()

Inherited From Object

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

Documentation generated on Sun, 19 Oct 2008 06:39:58 +1300 by phpDocumentor 1.3.2