Issues (3627)

app/bundles/SmsBundle/Entity/Stat.php (1 issue)

1
<?php
2
3
/*
4
 * @copyright   2016 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\SmsBundle\Entity;
13
14
use Doctrine\ORM\Mapping as ORM;
15
use Mautic\ApiBundle\Serializer\Driver\ApiMetadataDriver;
16
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
17
use Mautic\CoreBundle\Entity\IpAddress;
18
use Mautic\LeadBundle\Entity\Lead;
19
use Mautic\LeadBundle\Entity\LeadList;
20
21
/**
22
 * Class Stat.
23
 */
24
class Stat
25
{
26
    /**
27
     * @var int
28
     */
29
    private $id;
30
31
    /**
32
     * @var Sms
33
     */
34
    private $sms;
35
36
    /**
37
     * @var \Mautic\LeadBundle\Entity\Lead
38
     */
39
    private $lead;
40
41
    /**
42
     * @var \Mautic\LeadBundle\Entity\LeadList
43
     */
44
    private $list;
45
46
    /**
47
     * @var \Mautic\CoreBundle\Entity\IpAddress
48
     */
49
    private $ipAddress;
50
51
    /**
52
     * @var \DateTime
53
     */
54
    private $dateSent;
55
56
    /**
57
     * @var string
58
     */
59
    private $trackingHash;
60
61
    /**
62
     * @var string
63
     */
64
    private $source;
65
66
    /**
67
     * @var int
68
     */
69
    private $sourceId;
70
71
    /**
72
     * @var array
73
     */
74
    private $tokens = [];
75
76
    /**
77
     * @var array
78
     */
79
    private $details = [];
80
81
    /**
82
     * @var bool
83
     */
84
    private $isFailed = false;
85
86
    public static function loadMetadata(ORM\ClassMetadata $metadata)
87
    {
88
        $builder = new ClassMetadataBuilder($metadata);
89
90
        $builder->setTable('sms_message_stats')
91
            ->setCustomRepositoryClass('Mautic\SmsBundle\Entity\StatRepository')
92
            ->addIndex(['sms_id', 'lead_id'], 'stat_sms_search')
93
            ->addIndex(['tracking_hash'], 'stat_sms_hash_search')
94
            ->addIndex(['source', 'source_id'], 'stat_sms_source_search')
95
            ->addIndex(['is_failed'], 'stat_sms_failed_search');
96
97
        $builder->addBigIntIdField();
98
99
        $builder->createManyToOne('sms', 'Sms')
100
            ->inversedBy('stats')
101
            ->addJoinColumn('sms_id', 'id', true, false, 'SET NULL')
102
            ->build();
103
104
        $builder->addLead(true, 'SET NULL');
0 ignored issues
show
Deprecated Code introduced by
The function Mautic\CoreBundle\Doctri...adataBuilder::addLead() has been deprecated: Use addContact instead; existing implementations will need a migration to rename lead_id to contact_id ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

104
        /** @scrutinizer ignore-deprecated */ $builder->addLead(true, 'SET NULL');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
105
106
        $builder->createManyToOne('list', 'Mautic\LeadBundle\Entity\LeadList')
107
            ->addJoinColumn('list_id', 'id', true, false, 'SET NULL')
108
            ->build();
109
110
        $builder->addIpAddress(true);
111
112
        $builder->createField('dateSent', 'datetime')
113
            ->columnName('date_sent')
114
            ->build();
115
116
        $builder->createField('isFailed', 'boolean')
117
            ->columnName('is_failed')
118
            ->nullable()
119
            ->build();
120
121
        $builder->createField('trackingHash', 'string')
122
            ->columnName('tracking_hash')
123
            ->nullable()
124
            ->build();
125
126
        $builder->createField('source', 'string')
127
            ->nullable()
128
            ->build();
129
130
        $builder->createField('sourceId', 'integer')
131
            ->columnName('source_id')
132
            ->nullable()
133
            ->build();
134
135
        $builder->createField('tokens', 'array')
136
            ->nullable()
137
            ->build();
138
139
        $builder->addField('details', 'json_array');
140
    }
141
142
    /**
143
     * Prepares the metadata for API usage.
144
     *
145
     * @param $metadata
146
     */
147
    public static function loadApiMetadata(ApiMetadataDriver $metadata)
148
    {
149
        $metadata->setGroupPrefix('stat')
150
            ->addProperties(
151
                [
152
                    'id',
153
                    'ipAddress',
154
                    'dateSent',
155
                    'isFailed',
156
                    'source',
157
                    'sourceId',
158
                    'trackingHash',
159
                    'lead',
160
                    'sms',
161
                    'details',
162
                ]
163
            )
164
            ->build();
165
    }
166
167
    /**
168
     * @return int
169
     */
170
    public function getId()
171
    {
172
        return $this->id;
173
    }
174
175
    /**
176
     * @return Sms
177
     */
178
    public function getSms()
179
    {
180
        return $this->sms;
181
    }
182
183
    /**
184
     * @return Stat
185
     */
186
    public function setSms(Sms $sms)
187
    {
188
        $this->sms = $sms;
189
190
        return $this;
191
    }
192
193
    /**
194
     * @return Lead
195
     */
196
    public function getLead()
197
    {
198
        return $this->lead;
199
    }
200
201
    /**
202
     * @return Stat
203
     */
204
    public function setLead(Lead $lead)
205
    {
206
        $this->lead = $lead;
207
208
        return $this;
209
    }
210
211
    /**
212
     * @return LeadList
213
     */
214
    public function getList()
215
    {
216
        return $this->list;
217
    }
218
219
    /**
220
     * @return Stat
221
     */
222
    public function setList(LeadList $list)
223
    {
224
        $this->list = $list;
225
226
        return $this;
227
    }
228
229
    /**
230
     * @return IpAddress
231
     */
232
    public function getIpAddress()
233
    {
234
        return $this->ipAddress;
235
    }
236
237
    /**
238
     * @return Stat
239
     */
240
    public function setIpAddress(IpAddress $ipAddress)
241
    {
242
        $this->ipAddress = $ipAddress;
243
244
        return $this;
245
    }
246
247
    /**
248
     * @return \DateTime
249
     */
250
    public function getDateSent()
251
    {
252
        return $this->dateSent;
253
    }
254
255
    /**
256
     * @param \DateTime $dateSent
257
     *
258
     * @return Stat
259
     */
260
    public function setDateSent($dateSent)
261
    {
262
        $this->dateSent = $dateSent;
263
264
        return $this;
265
    }
266
267
    /**
268
     * @return string
269
     */
270
    public function getTrackingHash()
271
    {
272
        return $this->trackingHash;
273
    }
274
275
    /**
276
     * @param string $trackingHash
277
     *
278
     * @return Stat
279
     */
280
    public function setTrackingHash($trackingHash)
281
    {
282
        $this->trackingHash = $trackingHash;
283
284
        return $this;
285
    }
286
287
    /**
288
     * @return string
289
     */
290
    public function getSource()
291
    {
292
        return $this->source;
293
    }
294
295
    /**
296
     * @param string $source
297
     *
298
     * @return Stat
299
     */
300
    public function setSource($source)
301
    {
302
        $this->source = $source;
303
304
        return $this;
305
    }
306
307
    /**
308
     * @return int
309
     */
310
    public function getSourceId()
311
    {
312
        return $this->sourceId;
313
    }
314
315
    /**
316
     * @param int $sourceId
317
     *
318
     * @return Stat
319
     */
320
    public function setSourceId($sourceId)
321
    {
322
        $this->sourceId = $sourceId;
323
324
        return $this;
325
    }
326
327
    /**
328
     * @return array
329
     */
330
    public function getTokens()
331
    {
332
        return $this->tokens;
333
    }
334
335
    /**
336
     * @return Stat
337
     */
338
    public function setTokens(array $tokens)
339
    {
340
        $this->tokens = $tokens;
341
342
        return $this;
343
    }
344
345
    /**
346
     * @param bool $isFailed
347
     *
348
     * @return Stat
349
     */
350
    public function setIsFailed($isFailed)
351
    {
352
        $this->isFailed = $isFailed;
353
354
        return $this;
355
    }
356
357
    /**
358
     * @return bool
359
     */
360
    public function isFailed()
361
    {
362
        return $this->isFailed;
363
    }
364
365
    /**
366
     * @return array
367
     */
368
    public function getDetails()
369
    {
370
        return $this->details;
371
    }
372
373
    /**
374
     * @param array $details
375
     *
376
     * @return Stat
377
     */
378
    public function setDetails($details)
379
    {
380
        $this->details = $details;
381
382
        return $this;
383
    }
384
385
    /**
386
     * @param string $type
387
     * @param string $detail
388
     *
389
     * @return Stat
390
     */
391
    public function addDetail($type, $detail)
392
    {
393
        $this->details[$type][] = $detail;
394
395
        return $this;
396
    }
397
}
398