Stud.IP  5.4
SimpleCollection Class Reference
Inheritance diagram for SimpleCollection:
StudipArrayObject SimpleORMapCollection OpenGraphURLCollection

Public Member Functions

 __construct ($data=[])
 
 exchangeArray ($input)
 
 toArray ()
 
 append ($newval)
 
 offsetSet ($index, $newval)
 
 offsetUnset ($index)
 
 setFinder (callable $finder)
 
 getDeleted ()
 
 refresh ()
 
 findBy ($key, $values, $op='==')
 
 findOneBy ($key, $values, $op='==')
 
 each (callable $func)
 
 map (callable $func)
 
 filter (callable $func=null, $limit=null)
 
 any (callable $func)
 
 every (callable $func)
 
 pluck ($columns)
 
 toGroupedArray ($group_by='id', $only_these_fields=null, callable $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=[])
 
 __call ($method, $params)
 
 merge (SimpleCollection $a_collection)
 
- Public Member Functions inherited from StudipArrayObject
 __construct ($input=[], $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)
 
 contains ($value)
 

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
 
- Protected Member Functions inherited from StudipArrayObject
 validateKeyUsage ($key)
 

Constructor & Destructor Documentation

◆ __construct()

__construct (   $data = [])

Constructor

Parameters
array<T>|callable()array<T> $data array or closure to fill collection

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
literal-string$methodmethodname to call
array$paramsparameters for methodcall
Returns
array of all return values

◆ any()

any ( callable  $func)

Returns whether any element of the collection returns true for the given callback.

Parameters
callable(T,mixed)bool $func the function to call
Returns
bool

◆ append()

append (   $newval)
See also
ArrayObject::append()

◆ arrayToArrayObject()

static arrayToArrayObject (   $a)
static

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

Parameters
mixed$a
Returns
StudipArrayObject|ArrayAccess

◆ 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<T>$data array containing assoc arrays
Returns
SimpleCollection<T>

◆ each()

each ( callable  $func)

apply given callback to all elements of collection

Parameters
callable(T)int $func the function to call
Returns
int|false addition of return values

◆ every()

every ( callable  $func)

Returns whether every element of the collection returns true for the given callback.

Parameters
callable(T,mixed)bool $func the function to call
Returns
bool

◆ exchangeArray()

exchangeArray (   $input)
Parameters
array$input
Returns
array

◆ filter()

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

filter elements if given callback returns true

Parameters
?callable(T,mixed)bool $func the function to call
?integer$limit limit number of found records
Returns
SimpleCollection<T> containing filtered elements

◆ 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$valuesvalue to search for
string | callable$opoperator to find
Returns
SimpleCollection<T> with found records

◆ 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$valuesvalue to search for,
string | callable$opoperator to find
Returns
?T found record

◆ first()

first ( )

get the first element

Returns
?T first element or null

◆ getCompFunc()

static getCompFunc (   $operator,
  $args 
)
static

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

Parameters
string|callable(mixed,mixed|array)bool $operator
mixed | array$args
Exceptions
InvalidArgumentException
Returns
callable(mixed): bool comparison function

◆ getDeleted()

getDeleted ( )

get deleted records collection

Returns
SimpleCollection<T>

◆ last()

last ( )

get the last element

Returns
?T last element or null

◆ 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<T>

◆ map()

map ( callable  $func)

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

Parameters
callable(T,mixed)mixed $func the function to call
Returns
array<mixed>

◆ merge()

merge ( SimpleCollection  $a_collection)

merge in another collection, elements are appended

Parameters
SimpleCollection<T>$a_collection
Returns
void

◆ offsetSet()

offsetSet (   $index,
  $newval 
)

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

Parameters
mixed$index
mixed$newval
See also
ArrayObject::offsetSet()
Returns
void

◆ offsetUnset()

offsetUnset (   $index)

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

See also
ArrayObject::offsetUnset()
Exceptions
InvalidArgumentException

◆ 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
$this the sorted collection

◆ 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

◆ refresh()

refresh ( )

reloads the elements of the collection by calling the finder function

Returns
?int of records after refresh

◆ sendMessage()

sendMessage (   $method,
  $params = [] 
)

calls the given method on all elements of the collection

Parameters
literal-string$methodmethodname to call
array$paramsparameters for methodcall
Returns
array of all return values

◆ setFinder()

setFinder ( callable  $finder)

sets the finder function

Parameters
callable()array<T> $finder
Returns
void

◆ toArray()

toArray ( )

converts the object and all elements to plain arrays

Returns
array

◆ toGroupedArray()

toGroupedArray (   $group_by = 'id',
  $only_these_fields = null,
callable  $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
string | array | null$only_these_fieldslimit returned fields
?callable$group_func closure to aggregate grouped entries
Returns
array assoc array

◆ translitLatin1()

static translitLatin1 (   $text)
static

transliterates latin1 string to ascii

Parameters
string$text
Returns
string

◆ 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
string|callable(mixed,mixed|array)bool $op operator to find elements
Returns
int|false number of unsetted elements

◆ val()

val (   $key)

get the the value from given key from first element

Parameters
string$key
Returns
mixed

Field Documentation

◆ $deleted

$deleted
protected

◆ $finder

$finder
protected

◆ $last_count

$last_count
protected

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