Stud.IP  4.0
 All Data Structures Namespaces Files Functions Variables Groups
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 (   $data = [])

Constructor

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

Member Function Documentation

__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 ( 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 (   $newval)
See Also
ArrayObject::append()
static arrayToArrayObject (   $a)
static

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

Parameters
mixed$a
Returns
StudipArrayObject|ArrayAccess
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 ( 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 ( 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 (   $input)
Parameters
array$input
Returns
array
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 (   $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 (   $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 ( )

get the first element

Returns
?T first element or null
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 ( )

get deleted records collection

Returns
SimpleCollection<T>
last ( )

get the last element

Returns
?T last element or null
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 ( 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 ( SimpleCollection  $a_collection)

merge in another collection, elements are appended

Parameters
SimpleCollection<T>$a_collection
Returns
void
offsetSet (   $index,
  $newval 
)

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

See Also
ArrayObject::offsetSet()
Returns
void
offsetUnset (   $index)

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

See Also
ArrayObject::offsetUnset()
Exceptions
InvalidArgumentException
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 (   $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 ( )

reloads the elements of the collection by calling the finder function

Returns
?int of records after refresh
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 ( callable  $finder)

sets the finder function

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

converts the object and all elements to plain arrays

Returns
array
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
static translitLatin1 (   $text)
static

transliterates latin1 string to ascii

Parameters
string$text
Returns
string
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 (   $key)

get the the value from given key from first element

Parameters
string$key
Returns
mixed

Field Documentation

$deleted
protected
$finder
protected
$last_count
protected

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