Wikibase
MediaWiki Wikibase extension
|
Helper for managing objects indexed by property id. More...
Public Member Functions | |
__construct ( $input=null) | |
getPropertyIds () | |
Returns the property ids used for indexing. | |
getByPropertyId (PropertyId $propertyId) | |
Returns the objects featuring the provided property id in the index. | |
getFlatArrayIndexOfObject ( $object) | |
Returns the absolute index of an object or false if the object could not be found. | |
toFlatArray () | |
Returns the objects in a flat array (using the indexed form for generating the array). | |
moveObjectToIndex ( $object, $toIndex) | |
Moves an existing object to a new index. | |
addObjectAtIndex ( $object, $index=null) | |
Adds an object at a specific index. | |
Private Member Functions | |
assertIndexIsBuild () | |
Checks whether id indexed array has been generated. | |
getFlatArrayIndices (PropertyId $propertyId) | |
Returns the absolute numeric indices of objects featuring the same property id. | |
moveObjectInPropertyGroup ( $object, $toIndex) | |
Moves an object within its "property group". | |
moveObjectToEndOfPropertyGroup ( $object) | |
Moves an object to the end of its "property group". | |
removeObject ( $object) | |
Removes an object from the array structures. | |
insertObjectAtIndex ( $object, $index) | |
Inserts an object at a specific index. | |
movePropertyGroup (PropertyId $propertyId, $toIndex) | |
getPropertyGroupIndex (PropertyId $propertyId) | |
Returns the index of a "property group" (the first object in the flat array that features the specified property). | |
addObjectToPropertyGroup ( $object, $index=null) | |
Adds an object to an existing property group at the specified absolute index. | |
Private Attributes | |
$byId = null | |
Helper for managing objects indexed by property id.
This is a light weight alternative approach to using something like GenericArrayObject with the advantages that no extra interface is needed and that indexing does not happen automatically.
Lack of automatic indexing means that you will need to call the buildIndex method before doing any look-ups.
Since no extra interface is used, the user is responsible for only adding objects that have a getPropertyId method that returns either a string or integer when called with no arguments.
Objects may be added or moved within the structure. Absolute indices (indices according to the flat list of objects) may be specified to add or move objects. These management operations take the property grouping into account. Adding or moving objects outside their "property groups" shifts the whole group towards that index.
Example of moving an object within its "property group": o1 (p1) o1 (p1) o2 (p2) /-> o3 (p2) o3 (p2) ---> move to index 1 -/ o2 (p2)
Example of moving an object that triggers moving the whole "property group": o1 (p1) /-> o3 (p2) o2 (p2) | o2 (p2) o3 (p2) ---> move to index 0 -/ o1 (p1)
Wikibase\DataModel\ByPropertyIdArray::__construct | ( | $input = null | ) |
PropertyIdProvider[] | Traversable | null | $input |
InvalidArgumentException |
Wikibase\DataModel\ByPropertyIdArray::addObjectAtIndex | ( | $object, | |
$index = null ) |
Adds an object at a specific index.
If no index is specified, the object will be append to the end of its "property group" or - if no objects featuring the same property exist - to the absolute end of the array. Specifying an index outside a "property group" will place the new object at the specified index with the existing "property group" objects being shifted towards the new object.
PropertyIdProvider | $object | |
int | null | $index | Absolute index where to place the new object. |
OutOfBoundsException | |
RuntimeException |
|
private |
Adds an object to an existing property group at the specified absolute index.
PropertyIdProvider | $object | |
int | null | $index |
OutOfBoundsException |
|
private |
Checks whether id indexed array has been generated.
RuntimeException |
Wikibase\DataModel\ByPropertyIdArray::getByPropertyId | ( | PropertyId | $propertyId | ) |
Returns the objects featuring the provided property id in the index.
PropertyId | $propertyId |
OutOfBoundsException | |
RuntimeException |
Wikibase\DataModel\ByPropertyIdArray::getFlatArrayIndexOfObject | ( | $object | ) |
Returns the absolute index of an object or false if the object could not be found.
PropertyIdProvider | $object |
RuntimeException |
|
private |
Returns the absolute numeric indices of objects featuring the same property id.
PropertyId | $propertyId |
RuntimeException |
|
private |
Returns the index of a "property group" (the first object in the flat array that features the specified property).
Returns false if property id could not be found.
PropertyId | $propertyId |
Wikibase\DataModel\ByPropertyIdArray::getPropertyIds | ( | ) |
Returns the property ids used for indexing.
RuntimeException |
|
private |
Inserts an object at a specific index.
PropertyIdProvider | $object | |
int | $index | Absolute index within the flat list of objects. |
|
private |
Moves an object within its "property group".
PropertyIdProvider | $object | |
int | $toIndex | Absolute index within a "property group". |
OutOfBoundsException |
|
private |
Moves an object to the end of its "property group".
PropertyIdProvider | $object |
Wikibase\DataModel\ByPropertyIdArray::moveObjectToIndex | ( | $object, | |
$toIndex ) |
Moves an existing object to a new index.
Specifying an index outside the object's "property group" will move the object to the edge of the "property group" and shift the whole group to achieve the designated index for the object to move.
PropertyIdProvider | $object | |
int | $toIndex | Absolute index where to move the object to. |
OutOfBoundsException | |
RuntimeException |
|
private |
PropertyId | $propertyId | |
int | $toIndex |
|
private |
Removes an object from the array structures.
PropertyIdProvider | $object |
Wikibase\DataModel\ByPropertyIdArray::toFlatArray | ( | ) |
Returns the objects in a flat array (using the indexed form for generating the array).
RuntimeException |
|
private |