forked from symbiote/silverstripe-multivaluefield
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solves symbiote#45. Note that this is meant for the older version 3 of this module. I didn't start from the master branch because I still have SilverStripe 3 so I wouln't be able to test with SS4. But I guess this can be easily adapted to the newer version.
- Loading branch information
Showing
1 changed file
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
* | ||
* @author Marcus Nyeholt <[email protected]> | ||
*/ | ||
class MultiValueField extends DBField implements CompositeDBField | ||
class MultiValueField extends DBField implements CompositeDBField, ArrayAccess | ||
{ | ||
|
||
/** | ||
|
@@ -211,4 +211,72 @@ protected function restoreValueFromDb($value) | |
} | ||
return $value ?: array(); | ||
} | ||
|
||
/** | ||
* Whether a offset exists | ||
* @link http://php.net/manual/en/arrayaccess.offsetexists.php | ||
* @param mixed $offset <p> | ||
* An offset to check for. | ||
* </p> | ||
* @return boolean true on success or false on failure. | ||
* </p> | ||
* <p> | ||
* The return value will be casted to boolean if non-boolean was returned. | ||
* @since 5.0.0 | ||
*/ | ||
public function offsetExists($offset) | ||
{ | ||
$field_values = $this->getValue(); | ||
return isset($field_values[$offset]); | ||
} | ||
|
||
/** | ||
* Offset to retrieve | ||
* @link http://php.net/manual/en/arrayaccess.offsetget.php | ||
* @param mixed $offset <p> | ||
* The offset to retrieve. | ||
* </p> | ||
* @return mixed Can return all value types. | ||
* @since 5.0.0 | ||
*/ | ||
public function offsetGet($offset) | ||
{ | ||
$field_values = $this->getValue(); | ||
return $field_values[$offset]; | ||
} | ||
|
||
/** | ||
* Offset to set | ||
* @link http://php.net/manual/en/arrayaccess.offsetset.php | ||
* @param mixed $offset <p> | ||
* The offset to assign the value to. | ||
* </p> | ||
* @param mixed $value <p> | ||
* The value to set. | ||
* </p> | ||
* @return void | ||
* @since 5.0.0 | ||
*/ | ||
public function offsetSet($offset, $value) | ||
{ | ||
$field_values = $this->getValue(); | ||
$field_values[$offset] = $value; | ||
$this->setValue($field_values); | ||
} | ||
|
||
/** | ||
* Offset to unset | ||
* @link http://php.net/manual/en/arrayaccess.offsetunset.php | ||
* @param mixed $offset <p> | ||
* The offset to unset. | ||
* </p> | ||
* @return void | ||
* @since 5.0.0 | ||
*/ | ||
public function offsetUnset($offset) | ||
{ | ||
$field_values = $this->getValue(); | ||
unset($field_values[$offset]); | ||
$this->setValue($field_values); | ||
} | ||
} |