\ValidFormBuilderCollection

Create an iterable collection

Summary

Methods
Properties
Constants
__construct()
addObject()
addObjectAtPosition()
addObjects()
seek()
random()
randomize()
count()
current()
next()
previous()
key()
isFirst()
isLast()
getFirst()
getLast()
merge()
valid()
rewind()
reverse()
end()
rebuild()
inCollection()
remove()
removeRecursive()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

__construct()

__construct(array  $initArray = array()) 

Constructor method

Parameters

array $initArray

An array of items to initialize the collection with.

addObject()

addObject(object  $value, boolean  $blnAddToBeginning = false) 

Add object to the collection

Parameters

object $value

The object

boolean $blnAddToBeginning

Add object to beginning of array or not

addObjectAtPosition()

addObjectAtPosition(object  $value, integer  $intPosition) 

Add object to the collection at a specified position

Parameters

object $value

The object

integer $intPosition

The position the object should be placed at.

addObjects()

addObjects(array  $arrObjects, boolean  $blnAddToBeginning = false) 

Add objects to the collection

Parameters

array $arrObjects

An array of items / collection of objects to be added

boolean $blnAddToBeginning

Add objects to beginning of array or not

seek()

seek(integer  $intPosition) 

Advance internal pointer to a specific index

Parameters

integer $intPosition

The index to advance to

random()

random() : mixed

Pick a random child element

Returns

mixed —

Randomly selected item from collection

randomize()

randomize() 

Randomize the collection

count()

count() : integer

Get the item count.

Returns

integer —

The length of the collection

current()

current() : mixed

Get the current item from the collection.

Returns

mixed —

The current item

next()

next() : mixed

Place the pointer one item forward and return the item.

Returns

mixed —

The next item

previous()

previous() : mixed

Place the pointer one item back and return the item.

Returns

mixed —

The previous item

key()

key() : mixed|null

Get the current position of the pointer.

Returns

mixed|null —

The key function simply returns the key of the array element that's currently being pointed to by the internal pointer. It does not move the pointer in any way. If the internal pointer points beyond the end of the elements list or the array is empty, key returns null.

isFirst()

isFirst() : boolean

Check if the pointer is at the first record.

Returns

boolean —

True if current item is first item

isLast()

isLast() : boolean

Check if the pointer is at the last record.

Returns

boolean —

True if current item is last item

getFirst()

getFirst() : mixed

Get first element in collection

Returns

mixed —

Returns first element in collection, null if collection is empty

getLast()

getLast(string  $strType = "") : mixed

Get last element in collection

Parameters

string $strType

Optional type to search for. For example, you can search the Collection for the last Hidden element by doing: $objCollection->getLast("\\ValidFormBuilder\\Hidden").

Returns

mixed —

Returns last element in collection, null if collection is empty

merge()

merge(\ValidFormBuilder\Collection  $collection) 

Merge a collection with this collection.

Parameters

\ValidFormBuilder\Collection $collection

Collection to merge with

valid()

valid() : boolean

Test if the requested item is valid.

Returns

boolean —

True if its valid, false if not.

rewind()

rewind() : \ValidFormBuilder\Collection

Reset the internal pointer of the collection to the first item.

Returns

\ValidFormBuilder\Collection

Returns itself after the internal pointer is reset.

reverse()

reverse() : \ValidFormBuilder\Collection

Reverse the order of the collection and return it.

Returns

\ValidFormBuilder\Collection

Returns itself after the internal collection is reversed.

end()

end() : mixed

Set the internal pointer of the collection to the last item and return it.

Returns

mixed —

The last item in the collection

rebuild()

rebuild() 

Rebuild the collection index.

inCollection()

inCollection(mixed  $varValue, boolean  $blnReturnKey = false) 

Check if an object is in the collection

Parameters

mixed $varValue

Value to search for

boolean $blnReturnKey

If true, returns the position of the item if found. Default: false.

remove()

remove(object  $objElement) : boolean

Remove an element from the collection

Parameters

object $objElement

The element that will be removed

Returns

boolean —

Always returns true. If it couldn't be found, its gone. If the element is found, it will be removed.

removeRecursive()

removeRecursive(\ValidFormBuilder\Base  $objElement) 

Same as `remove()` but this is executed recursively.

Parameters

\ValidFormBuilder\Base $objElement