| @@ 8-62 (lines=55) @@ | ||
| 5 | /** |
|
| 6 | * Date: 19/08/15 |
|
| 7 | */ |
|
| 8 | class ContactListCollection extends ArrayCollection |
|
| 9 | { |
|
| 10 | /** |
|
| 11 | * @param mixed $offset |
|
| 12 | * |
|
| 13 | * @return ContactList|null |
|
| 14 | */ |
|
| 15 | public function offsetGet($offset) |
|
| 16 | { |
|
| 17 | return parent::offsetGet($offset); |
|
| 18 | } |
|
| 19 | ||
| 20 | /** |
|
| 21 | * @param ContactList $contactList |
|
| 22 | * |
|
| 23 | * @return void |
|
| 24 | */ |
|
| 25 | public function add($contactList) |
|
| 26 | { |
|
| 27 | if (!$this->exists( |
|
| 28 | function ($key, ContactList $element) use ($contactList) { |
|
| 29 | return $contactList->getId() == $element->getId(); |
|
| 30 | } |
|
| 31 | ) |
|
| 32 | ) { |
|
| 33 | parent::add($contactList); |
|
| 34 | } |
|
| 35 | } |
|
| 36 | ||
| 37 | /** |
|
| 38 | * @param string $name |
|
| 39 | * |
|
| 40 | * @return self |
|
| 41 | */ |
|
| 42 | public function findByName($name) |
|
| 43 | { |
|
| 44 | return $this->filter( |
|
| 45 | function (ContactList $element) use ($name) { |
|
| 46 | return $element->getName() == $name; |
|
| 47 | } |
|
| 48 | ); |
|
| 49 | } |
|
| 50 | ||
| 51 | /** |
|
| 52 | * @param string $name |
|
| 53 | * |
|
| 54 | * @return mixed |
|
| 55 | */ |
|
| 56 | public function findOneByName($name) |
|
| 57 | { |
|
| 58 | $elements = $this->findByName($name); |
|
| 59 | ||
| 60 | return $elements->first(); |
|
| 61 | } |
|
| 62 | } |
|
| 63 | ||
| @@ 9-51 (lines=43) @@ | ||
| 6 | * Class SegmentCollection |
|
| 7 | * @package Mailxpert\Model |
|
| 8 | */ |
|
| 9 | class SegmentCollection extends ArrayCollection |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * @param mixed $offset |
|
| 13 | * |
|
| 14 | * @return Segment|null |
|
| 15 | */ |
|
| 16 | public function offsetGet($offset) |
|
| 17 | { |
|
| 18 | return parent::offsetGet($offset); |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @param Segment $segment |
|
| 23 | * |
|
| 24 | * @return void |
|
| 25 | */ |
|
| 26 | public function add($segment) |
|
| 27 | { |
|
| 28 | if (!$this->exists( |
|
| 29 | function ($key, Segment $element) use ($segment) { |
|
| 30 | return $segment->getId() == $element->getId(); |
|
| 31 | } |
|
| 32 | ) |
|
| 33 | ) { |
|
| 34 | parent::add($segment); |
|
| 35 | } |
|
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * @param integer $id |
|
| 40 | * |
|
| 41 | * @return Segment|null |
|
| 42 | */ |
|
| 43 | public function findById($id) |
|
| 44 | { |
|
| 45 | $contacts = $this->filter(function (Segment $element) use ($id) { |
|
| 46 | return $element->getId() == $id; |
|
| 47 | }); |
|
| 48 | ||
| 49 | return $contacts->first(); |
|
| 50 | } |
|
| 51 | } |
|
| 52 | ||