1 <?php
2 /* --------------------------------------------------------------
3 EditableKeyValueCollection.inc.php 2015-12-16
4 Gambio GmbH
5 http://www.gambio.de
6 Copyright (c) 2015 Gambio GmbH
7 Released under the GNU General Public License (Version 2)
8 [http://www.gnu.org/licenses/gpl-2.0.html]
9 --------------------------------------------------------------
10 */
11
12 MainFactory::load_class('KeyValueCollection');
13
14 /**
15 * Class EditableKeyValueCollection
16 *
17 * @category System
18 * @package Shared
19 */
20 class EditableKeyValueCollection extends KeyValueCollection
21 {
22 /**
23 * Set new key-value pair.
24 *
25 * @param string $p_keyName
26 * @param mixed $p_value
27 */
28 public function setValue($p_keyName, $p_value)
29 {
30 $this->collectionContentArray[$p_keyName] = $p_value;
31 }
32
33
34 /**
35 * Add another collection to this one.
36 *
37 * @param \KeyValueCollection $collection Collection to add.
38 *
39 * @return $this Same instance to make chained method calls possible.
40 */
41 public function addCollection(KeyValueCollection $collection)
42 {
43 $keyValueArray = $collection->getArray();
44
45 $this->_addToCollectionContentArray($keyValueArray);
46
47 return $this;
48 }
49
50
51 /**
52 * Deletes an value from the collection by the given key.
53 *
54 * @param string $p_key Key of the value that should gets delete.
55 *
56 * @return $this Same instance to make chained method calls possible.
57 */
58 public function deleteValue($p_key)
59 {
60 if($this->keyExists($p_key))
61 {
62 unset($this->collectionContentArray[$p_key]);
63 }
64 }
65
66
67 /**
68 * Return a clone of the current editable key value collection instance.
69 */
70 public function getClone()
71 {
72 return clone $this;
73 }
74 }