Completed
Pull Request — develop (#303)
by
unknown
13:30
created

OrganizationImage::getResourceId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
/** UserImage.php */
11
namespace Organizations\Entity;
12
13
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
14
use Zend\Permissions\Acl\Resource\ResourceInterface;
15
use Core\Entity\FileEntity;
16
use Zend\EventManager\EventManager;
17
use Zend\EventManager\EventManagerInterface;
18
19
/**
20
 * Defines the logo of an organization.
21
 *
22
 * @ODM\HasLifecycleCallbacks()
23
 * @ODM\Document(collection="organizations.images", repositoryClass="Organizations\Repository\OrganizationImage")
24
 */
25
class OrganizationImage extends FileEntity implements ResourceInterface
26
{
27
    
28
    const EVENT_GET_URI = 'getUri';
29
    
30
    /**
31
     * Organization which belongs to the company logo
32
     *
33
     * @var Organization
34
     * @ODM\ReferenceOne(targetDocument="\Organizations\Entity\Organization", mappedBy="image")
35
     */
36
    protected $organization;
37
38
    /**
39
     * @var EventManagerInterface
40
     */
41
    protected $eventManager;
42
43
    /**
44
     * @param EventManagerInterface $eventManager
45
     * @return OrganizationImage
46
     * @since 0.28
47
     */
48
    public function setEventManager(EventManagerInterface $eventManager)
49
    {
50
        $this->eventManager = $eventManager;
51
        
52
        return $this;
53
    }
54
55
    /**
56
     * @return EventManagerInterface
57
     * @since 0.28
58
     */
59
    public function getEventManager()
60
    {
61
        if (! $this->eventManager) {
62
            $this->setEventManager(new EventManager());
63
        }
64
        
65
        return $this->eventManager;
66
    }
67
68
    /**
69
     * {@inheritDoc}
70
     * @see \Zend\Permissions\Acl\Resource\ResourceInterface::getResourceId()
71
     */
72
    public function getResourceId()
73
    {
74
        return 'Entity/OrganizationImage';
75
    }
76
77
    /**
78
     * Gets the URI of an attachment
79
     *
80
     * @return string
81
     */
82
    function getUri()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
83
    {
84
        $results = $this->getEventManager()->trigger(static::EVENT_GET_URI, $this, [], function ($uri) {
85
            return is_string($uri);
86
        });
87
        
88
        if ($results->stopped()) {
89
            return $results->last();
90
        }
91
        
92
        return '/' . trim('file/Organizations.OrganizationImage/' . $this->id . "/" . urlencode($this->name),'/');
93
    }
94
    
95
    /**
96
     * Gets the organization of an company logo
97
     *
98
     * @return Organization
99
     */
100
    public function getOrganization()
101
    {
102
        return $this->organization;
103
    }
104
105
    /**
106
     * @param Organization $organization
107
     */
108
    public function setOrganization(Organization $organization)
109
    {
110
        $this->organization = $organization;
111
    }
112
113
    /**
114
     * Tells Doctrine to delete the image reference, if the image is deleted.
115
     *
116
     * @ODM\PreRemove()
117
     */
118
    public function preRemove()
119
    {
120
        $this->getOrganization()->setImage(null);
121
    }
122
}
123