Stud.IP  4.2 Revision
SimpleCollection Class Reference
Inheritance diagram for SimpleCollection:
Inheritance graph
Collaboration diagram for SimpleCollection:
Collaboration graph

Public Member Functions

 __construct ($data=array())
 
 exchangeArray ($input)
 
 toArray ()
 
 append ($newval)
 
 offsetSet ($index, $newval)
 
 offsetUnset ($index)
 
 setFinder (Closure $finder)
 
 getDeleted ()
 
 refresh ()
 
 findBy ($key, $values, $op='==')
 
 findOneBy ($key, $values, $op='==')
 
 each (Closure $func)
 
 map (Closure $func)
 
 filter (Closure $func=null, $limit=null)
 
 pluck ($columns)
 
 toGroupedArray ($group_by='id', $only_these_fields=null, Closure $group_func=null)
 
 first ()
 
 last ()
 
 val ($key)
 
 unsetBy ($key, $values, $op='==')
 
 orderBy ($order, $sort_flags=SORT_LOCALE_STRING)
 
 limit ($arg1, $arg2=null)
 
 sendMessage ($method, $params=array())
 
 __call ($method, $params)
 
 merge (SimpleCollection $a_collection)
 
- Public Member Functions inherited from StudipArrayObject
 __construct ($input=array(), $flags=self::STD_PROP_LIST, $iteratorClass='ArrayIterator')
 
 __isset ($key)
 
 __set ($key, $value)
 
 __unset ($key)
 
 __get ($key)
 
 append ($value)
 
 asort ()
 
 count ()
 
 exchangeArray ($data)
 
 getArrayCopy ()
 
 getFlags ()
 
 getIterator ()
 
 getIteratorClass ()
 
 ksort ()
 
 natcasesort ()
 
 natsort ()
 
 offsetExists ($key)
 
 offsetGet ($key)
 
 offsetSet ($key, $value)
 
 offsetUnset ($key)
 
 serialize ()
 
 setFlags ($flags)
 
 setIteratorClass ($class)
 
 uasort ($function)
 
 uksort ($function)
 
 unserialize ($data)
 

Static Public Member Functions

static createFromArray (Array $data)
 
static arrayToArrayObject ($a)
 
static getCompFunc ($operator, $args)
 
static translitLatin1 ($text)
 

Protected Attributes

 $finder
 
 $last_count
 
 $deleted
 
- Protected Attributes inherited from StudipArrayObject
 $storage
 
 $flag
 
 $iteratorClass
 
 $protectedProperties
 

Additional Inherited Members

- Data Fields inherited from StudipArrayObject
const STD_PROP_LIST = 1
 
const ARRAY_AS_PROPS = 2
 

Constructor & Destructor Documentation

◆ __construct()

__construct (   $data = array())

Constructor

Parameters
mixed$dataarray or closure to fill collection
Here is the call graph for this function:

Member Function Documentation

◆ __call()

__call (   $method,
  $params 
)

magic version of sendMessage calls undefineds methods on all elements of the collection But beware of the dark side...

Parameters
string$methodmethodname to call
array$paramsparameters for methodcall
Returns
array of all return values
Here is the call graph for this function:

◆ append()

append (   $newval)
See also
ArrayObject::append()
Here is the call graph for this function:

◆ arrayToArrayObject()

static arrayToArrayObject (   $a)
static

converts arrays or objects to ArrayObject objects if ArrayAccess interface is not available

Parameters
mixed$a
Returns
ArrayAccess
Here is the caller graph for this function:

◆ createFromArray()

static createFromArray ( Array  $data)
static

creates a collection from an array of arrays all arrays should contain same keys, but is not enforced

Parameters
array$dataarray containing assoc arrays
Returns
SimpleCollection
Here is the caller graph for this function:

◆ each()

each ( Closure  $func)

apply given callback to all elements of collection

Parameters
Closure$functhe function to call
Returns
int addition of return values

◆ exchangeArray()

exchangeArray (   $input)
Parameters
array$input
Returns
array
Here is the caller graph for this function:

◆ filter()

filter ( Closure  $func = null,
  $limit = null 
)

filter elements if given callback returns true

Parameters
Closure$functhe function to call
integer$limitlimit number of found records
Returns
SimpleCollection containing filtered elements
Here is the caller graph for this function:

◆ findBy()

findBy (   $key,
  $values,
  $op = '==' 
)

returns a new collection containing all elements where given columns value matches given value(s) using passed operator pass array for multiple values

operators: == equal, like php === identical, like php !=,<> not equal, like php !== not identical, like php <,>,<=,>= less,greater,less or equal,greater or equal >< between without borders, needs two arguments >=<= between including borders, needs two arguments %= like string, transliterate to ascii,case insensitive *= contains string ^= begins with string $= ends with string ~= regex

Parameters
string$keythe column name
mixed$valuevalue to search for
mixed$opoperator to find
Returns
SimpleCollection with found records
Here is the call graph for this function:

◆ findOneBy()

findOneBy (   $key,
  $values,
  $op = '==' 
)

returns the first element where given column has given value(s) pass array for multiple values

Parameters
string$keythe column name
mixed$valuevalue to search for,
mixed$opoperator to find
Returns
SimpleORMap found record
Here is the call graph for this function:
Here is the caller graph for this function:

◆ first()

first ( )

get the first element

Returns
Array first element or null
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCompFunc()

static getCompFunc (   $operator,
  $args 
)
static

returns closure to compare a value against given arguments using given operator

Parameters
string$operator
mixed$args
Exceptions
InvalidArgumentException
Returns
Closure comparison function
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDeleted()

getDeleted ( )

get deleted records collection

Returns
SimpleCollection

◆ last()

last ( )

get the last element

Returns
Array last element or null
Here is the call graph for this function:

◆ limit()

limit (   $arg1,
  $arg2 = null 
)

returns a new collection contaning a sequence of original collection mimics the sql limit constrain: used with one parameter, the first x elements are extracted used with two parameters, the first parameter denotes the offset, the second the number of elements

Parameters
integer$arg1
integer$arg2
Returns
SimpleCollection

◆ map()

map ( Closure  $func)

apply given callback to all elements of collection and give back array of return values

Parameters
Closure$functhe function to call
Returns
array
Here is the caller graph for this function:

◆ merge()

merge ( SimpleCollection  $a_collection)

merge in another collection, elements are appended

Parameters
SimpleCollection$a_collection
Here is the call graph for this function:

◆ offsetSet()

offsetSet (   $index,
  $newval 
)

Sets the value at the specified index ensures the value has ArrayAccess

See also
ArrayObject::offsetSet()
Here is the call graph for this function:

◆ offsetUnset()

offsetUnset (   $index)

Unsets the value at the specified index value is moved to internal deleted collection

See also
ArrayObject::offsetUnset()
Exceptions
InvalidArgumentException
Here is the call graph for this function:

◆ orderBy()

orderBy (   $order,
  $sort_flags = SORT_LOCALE_STRING 
)

sorts the collection by columns of contained elements and returns it

works like sql order by: first param is a string containing combinations of column names and sort direction, separated by comma e.g. 'name asc, nummer desc ' sorts first by name ascending and then by nummer descending second param denotes the sort type (using PHP sort constants): SORT_LOCALE_STRING: compare items as strings, transliterate latin1 to ascii, case insensitiv, natural order for numbers SORT_NUMERIC: compare items as integers SORT_STRING: compare items as strings SORT_NATURAL: compare items as strings using "natural ordering" SORT_FLAG_CASE: can be combined (bitwise OR) with SORT_STRING or SORT_NATURAL to sort strings case-insensitively

Parameters
string$ordercolumns to order by
integer$sort_flags
Returns
SimpleCollection the sorted collection
Here is the call graph for this function:

◆ pluck()

pluck (   $columns)

extract array of columns values pass array or space-delimited string for multiple columns

Parameters
string | array$columnsthe column(s) to extract
Returns
array of extracted values
Here is the call graph for this function:

◆ refresh()

refresh ( )

reloads the elements of the collection by calling the finder function

Returns
number of records after refresh
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendMessage()

sendMessage (   $method,
  $params = array() 
)

calls the given method on all elements of the collection

Parameters
string$methodmethodname to call
array$paramsparameters for methodcall
Returns
array of all return values
Here is the caller graph for this function:

◆ setFinder()

setFinder ( Closure  $finder)

sets the finder function

Parameters
Closure$finder

◆ toArray()

toArray ( )

converts the object and all elements to plain arrays

Returns
array
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toGroupedArray()

toGroupedArray (   $group_by = 'id',
  $only_these_fields = null,
Closure  $group_func = null 
)

returns the collection as grouped array first param is the column to group by, it becomes the key in the resulting array, default is pk. Limit returned fields with second param The grouped entries can optoionally go through the given callback. If no callback is provided, only the first grouped entry is returned, suitable for grouping by unique column

Parameters
string$group_bythe column to group by, pk if ommitted
mixed$only_these_fieldslimit returned fields
Closure$group_funcclosure to aggregate grouped entries
Returns
array assoc array
Here is the call graph for this function:

◆ translitLatin1()

static translitLatin1 (   $text)
static

transliterates latin1 string to ascii

Parameters
string$text
Returns
string
Here is the caller graph for this function:

◆ unsetBy()

unsetBy (   $key,
  $values,
  $op = '==' 
)

mark element(s) for deletion where given column has given value(s) element(s) are moved to internal deleted collection pass array for multiple values

operators: == equal, like php === identical, like php !=,<> not equal, like php !== not identical, like php <,>,<=,>= less,greater,less or equal,greater or equal >< between without borders, needs two arguments >=<= between including borders, needs two arguments %= like string, transliterate to ascii,case insensitive *= contains string ^= begins with string $= ends with string ~= regex

Parameters
string$key
mixed$values
mixed$opoperator to find elements
Returns
number of unsetted elements
Here is the caller graph for this function:

◆ val()

val (   $key)

get the the value from given key from first element

Returns
mixed
Here is the call graph for this function:

Field Documentation

◆ $deleted

$deleted
protected

◆ $finder

$finder
protected

◆ $last_count

$last_count
protected

The documentation for this class was generated from the following file: