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