1 <?php
2 /* --------------------------------------------------------------
3 ContactCollection.inc.php 2015-01-30 gm
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('AbstractCollection');
13 MainFactory::load_class('ContactCollectionInterface');
14
15 /**
16 * Class ContactCollection
17 *
18 * Handles collection of EmailContact objects.
19 *
20 * @category System
21 * @package Email
22 * @subpackage Collections
23 */
24 class ContactCollection extends AbstractCollection implements ContactCollectionInterface
25 {
26 /**
27 * Adds a new contact into the collection.
28 *
29 * @param EmailContactInterface $contact E-Mail contact.
30 */
31 public function add(EmailContactInterface $contact)
32 {
33 $this->_add($contact);
34 }
35
36
37 /**
38 * Removes a contact from collection.
39 *
40 * @param EmailContactInterface $contact E-Mail contact.
41 *
42 * @throws Exception If contact cannot be found.
43 */
44 public function remove(EmailContactInterface $contact)
45 {
46 $index = array_search($contact, $this->collectionContentArray);
47
48 if($index === false)
49 {
50 throw new Exception('Could not remove contact because it does not exist in collection.');
51 }
52
53 unset($this->collectionContentArray[$index]);
54 }
55
56
57 /**
58 * Removes all contacts of collection.
59 */
60 public function clear()
61 {
62 $this->collectionContentArray = array();
63 }
64
65
66 /**
67 * Returns the type of the collection items.
68 *
69 * @return string Valid type.
70 */
71 protected function _getValidType()
72 {
73 return 'EmailContactInterface';
74 }
75 }