Issues (3627)

app/bundles/PageBundle/Entity/Redirect.php (2 issues)

1
<?php
2
3
/*
4
 * @copyright   2014 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        http://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\PageBundle\Entity;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\ORM\Mapping as ORM;
16
use Mautic\ApiBundle\Serializer\Driver\ApiMetadataDriver;
17
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
18
use Mautic\CoreBundle\Entity\FormEntity;
19
20
class Redirect extends FormEntity
21
{
22
    /**
23
     * @var int
24
     */
25
    private $id;
26
27
    /**
28
     * @var string
29
     */
30
    private $redirectId;
31
32
    private $url;
33
34
    /**
35
     * @var int
36
     */
37
    private $hits = 0;
38
39
    /**
40
     * @var int
41
     */
42
    private $uniqueHits = 0;
43
44
    /**
45
     * @var ArrayCollection
46
     */
47
    private $trackables;
48
49
    /**
50
     * Redirect constructor.
51
     */
52
    public function __construct()
53
    {
54
        $this->trackables = new ArrayCollection();
55
    }
56
57
    public static function loadMetadata(ORM\ClassMetadata $metadata)
58
    {
59
        $builder = new ClassMetadataBuilder($metadata);
60
61
        $builder->setTable('page_redirects')
62
            ->setCustomRepositoryClass('Mautic\PageBundle\Entity\RedirectRepository');
63
64
        $builder->addBigIntIdField();
65
66
        $builder->createField('redirectId', 'string')
67
            ->columnName('redirect_id')
68
            ->length(25)
69
            ->build();
70
71
        $builder->addField('url', 'text');
72
73
        $builder->addField('hits', 'integer');
74
75
        $builder->createField('uniqueHits', 'integer')
76
            ->columnName('unique_hits')
77
            ->build();
78
79
        $builder->createOneToMany('trackables', 'Trackable')
80
            ->mappedBy('redirect')
81
            ->fetchExtraLazy()
82
            ->build();
83
    }
84
85
    /**
86
     * Prepares the metadata for API usage.
87
     *
88
     * @param $metadata
89
     */
90
    public static function loadApiMetadata(ApiMetadataDriver $metadata)
91
    {
92
        $metadata->setGroupPrefix('redirect')
93
            ->addListProperties(
94
                [
95
                    'id',
96
                    'redirectId',
97
                    'url',
98
                ]
99
            )
100
            ->addProperties(
101
                [
102
                    'hits',
103
                    'uniqueHits',
104
                ]
105
            )
106
            ->build();
107
    }
108
109
    /**
110
     * @return int
111
     */
112
    public function getId()
113
    {
114
        return $this->id;
115
    }
116
117
    /**
118
     * @return string
119
     */
120
    public function getRedirectId()
121
    {
122
        return $this->redirectId;
123
    }
124
125
    /**
126
     * @param string $redirectId
127
     */
128
    public function setRedirectId($redirectId = null)
129
    {
130
        if (null === $redirectId) {
131
            $redirectId = substr(hash('sha1', uniqid(mt_rand())), 0, 25);
132
        }
133
        $this->redirectId = $redirectId;
134
    }
135
136
    /**
137
     * @return string
138
     */
139
    public function getUrl()
140
    {
141
        return $this->url;
142
    }
143
144
    /**
145
     * @param string $url
146
     */
147
    public function setUrl($url)
148
    {
149
        $this->url = $url;
150
    }
151
152
    /**
153
     * Set hits.
154
     *
155
     * @param int $hits
156
     *
157
     * @return Page
158
     */
159
    public function setHits($hits)
160
    {
161
        $this->hits = $hits;
162
163
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Mautic\PageBundle\Entity\Redirect which is incompatible with the documented return type Mautic\PageBundle\Entity\Page.
Loading history...
164
    }
165
166
    /**
167
     * Get hits.
168
     *
169
     * @return int
170
     */
171
    public function getHits()
172
    {
173
        return $this->hits;
174
    }
175
176
    /**
177
     * Set uniqueHits.
178
     *
179
     * @param int $uniqueHits
180
     *
181
     * @return Page
182
     */
183
    public function setUniqueHits($uniqueHits)
184
    {
185
        $this->uniqueHits = $uniqueHits;
186
187
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Mautic\PageBundle\Entity\Redirect which is incompatible with the documented return type Mautic\PageBundle\Entity\Page.
Loading history...
188
    }
189
190
    /**
191
     * Get uniqueHits.
192
     *
193
     * @return int
194
     */
195
    public function getUniqueHits()
196
    {
197
        return $this->uniqueHits;
198
    }
199
200
    /**
201
     * @return ArrayCollection
202
     */
203
    public function getTrackableList()
204
    {
205
        return $this->trackables;
206
    }
207
208
    /**
209
     * @param ArrayCollection $trackables
210
     *
211
     * @return Redirect
212
     */
213
    public function setTrackables($trackables)
214
    {
215
        $this->trackables = $trackables;
216
217
        return $this;
218
    }
219
}
220