1 <?php
2 /* --------------------------------------------------------------
3 AttachmentCollection.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('AttachmentCollectionInterface');
14
15 /**
16 * Class AttachmentCollection
17 *
18 * Handles the attachment collections of an Email.
19 *
20 * @category System
21 * @package Email
22 * @subpackage Collections
23 */
24 class AttachmentCollection extends AbstractCollection implements AttachmentCollectionInterface
25 {
26 /**
27 * Adds a new attachment to the collection.
28 *
29 * @param EmailAttachmentInterface $attachment E-Mail attachment.
30 */
31 public function add(EmailAttachmentInterface $attachment)
32 {
33 $this->_add($attachment);
34 }
35
36
37 /**
38 * Removes an attachment from collection.
39 *
40 * @param EmailAttachmentInterface $attachment E-Mail attachment.
41 *
42 * @throws Exception If attachment could not be found.
43 */
44 public function remove(EmailAttachmentInterface $attachment)
45 {
46 $index = array_search($attachment, $this->collectionContentArray);
47
48 if($index === false)
49 {
50 throw new Exception('Could not remove attachment because it does not exist in collection.');
51 }
52
53 unset($this->collectionContentArray[$index]);
54 }
55
56
57 /**
58 * Removes all attachments 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 'EmailAttachmentInterface';
74 }
75 }