Banner::setImpressions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
namespace DERHANSEN\SfBanners\Domain\Model;
3
4
/*
5
 * This file is part of the Extension "sf_banners" for TYPO3 CMS.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.txt file that was distributed with this source code.
9
 */
10
11
use TYPO3\CMS\Core\Utility\GeneralUtility;
12
use TYPO3\CMS\Extbase\Annotation as Extbase;
13
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
14
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
15
16
/**
17
 * Banner domain model
18
 *
19
 * @author Torben Hansen <[email protected]>
20
 */
21
class Banner extends AbstractEntity
22
{
23
    /**
24
     * Title
25
     *
26
     * @var string
27
     */
28
    protected $title;
29
30
    /**
31
     * Description
32
     *
33
     * @var string
34
     */
35
    protected $description;
36
37
    /**
38
     * Type
39
     *
40
     * @var int
41
     */
42
    protected $type;
43
44
    /**
45
     * Category
46
     *
47
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\Category>
48
     * @Extbase\ORM\Lazy
49
     */
50
    protected $category;
51
52
    /**
53
     * Fal media items
54
     *
55
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
56
     */
57
    protected $assets;
58
59
    /**
60
     * Margin top
61
     *
62
     * @var int
63
     */
64
    protected $marginTop;
65
66
    /**
67
     * Margin right
68
     *
69
     * @var int
70
     */
71
    protected $marginRight;
72
73
    /**
74
     * Margin bottom
75
     *
76
     * @var int
77
     */
78
    protected $marginBottom;
79
80
    /**
81
     * Margin top
82
     *
83
     * @var int
84
     */
85
    protected $marginLeft;
86
87
    /**
88
     * HTML
89
     *
90
     * @var string
91
     */
92
    protected $html;
93
94
    /**
95
     * Max impressions
96
     *
97
     * @var int
98
     */
99
    protected $impressionsMax;
100
101
    /**
102
     * Max clicks
103
     *
104
     * @var int
105
     */
106
    protected $clicksMax;
107
108
    /**
109
     * Total impressions
110
     *
111
     * @var int
112
     */
113
    protected $impressions;
114
115
    /**
116
     * Total clicks
117
     *
118
     * @var int
119
     */
120
    protected $clicks;
121
122
    /**
123
     * Do not display on pages
124
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\DERHANSEN\SfBanners\Domain\Model\Page>
125
     * @Extbase\ORM\Lazy
126
     */
127
    protected $excludepages;
128
129
    /**
130
     * Recursively use excludepages
131
     * @var bool
132
     */
133
    protected $recursive;
134
135
    /**
136
     * __construct
137
     */
138
    public function __construct()
139
    {
140
        //Do not remove the next line: It would break the functionality
141
        $this->initStorageObjects();
142
    }
143
144
    /**
145
     * Initializes all ObjectStorage properties
146
     * Do not modify this method!
147
     * It will be rewritten on each save in the extension builder
148
     * You may modify the constructor of this class instead
149
     *
150
     * @return void
151
     */
152
    protected function initStorageObjects()
153
    {
154
        $this->category = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
155
        $this->excludepages = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
156
        $this->assets = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
157
    }
158
159
    /**
160
     * Returns the title
161
     *
162
     * @return string $title
163
     */
164
    public function getTitle()
165
    {
166
        return $this->title;
167
    }
168
169
    /**
170
     * Sets the title
171
     *
172
     * @param string $title The title
173
     * @return void
174
     */
175
    public function setTitle($title)
176
    {
177
        $this->title = $title;
178
    }
179
180
    /**
181
     * Returns the description
182
     *
183
     * @return string $description
184
     */
185
    public function getDescription()
186
    {
187
        return $this->description;
188
    }
189
190
    /**
191
     * Sets the description
192
     *
193
     * @param string $description The description
194
     * @return void
195
     */
196
    public function setDescription($description)
197
    {
198
        $this->description = $description;
199
    }
200
201
    /**
202
     * Returns the type
203
     *
204
     * @return int $type
205
     */
206
    public function getType()
207
    {
208
        return $this->type;
209
    }
210
211
    /**
212
     * Sets the type
213
     *
214
     * @param int $type The type
215
     * @return void
216
     */
217
    public function setType($type)
218
    {
219
        $this->type = $type;
220
    }
221
222
    /**
223
     * Adds a category
224
     *
225
     * @param \TYPO3\CMS\Extbase\Domain\Model\Category $category
226
     * @return void
227
     */
228
    public function addCategory(\TYPO3\CMS\Extbase\Domain\Model\Category $category)
229
    {
230
        $this->category->attach($category);
231
    }
232
233
    /**
234
     * Removes a category
235
     *
236
     * @param \TYPO3\CMS\Extbase\Domain\Model\Category $categoryToRemove
237
     * @return void
238
     */
239
    public function removeCategory(\TYPO3\CMS\Extbase\Domain\Model\Category $categoryToRemove)
240
    {
241
        $this->category->detach($categoryToRemove);
242
    }
243
244
    /**
245
     * Returns the category
246
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage $category
247
     */
248
    public function getCategory()
249
    {
250
        return $this->category;
251
    }
252
253
    /**
254
     * Sets the category
255
     *
256
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $category One or multiple categories
257
     * @return void
258
     */
259
    public function setCategory($category)
260
    {
261
        $this->category = $category;
262
    }
263
264
    /**
265
     * Setter for clicks
266
     *
267
     * @param int $clicks Clicks
268
     * @return void
269
     */
270
    public function setClicks($clicks)
271
    {
272
        $this->clicks = $clicks;
273
    }
274
275
    /**
276
     * getter for clicks
277
     *
278
     * @return int
279
     */
280
    public function getClicks()
281
    {
282
        return $this->clicks;
283
    }
284
285
    /**
286
     * Setter for clicksmax
287
     *
288
     * @param int $clicksMax MaxClicks
289
     * @return void
290
     */
291
    public function setClicksMax($clicksMax)
292
    {
293
        $this->clicksMax = $clicksMax;
294
    }
295
296
    /**
297
     * Getter for clicksmax
298
     *
299
     * @return int
300
     */
301
    public function getClicksMax()
302
    {
303
        return $this->clicksMax;
304
    }
305
306
    /**
307
     * Adds a page
308
     *
309
     * @param \DERHANSEN\SfBanners\Domain\Model\Page $page
310
     * @return void
311
     */
312
    public function addExcludepages(\DERHANSEN\SfBanners\Domain\Model\Page $page)
313
    {
314
        $this->excludepages->attach($page);
315
    }
316
317
    /**
318
     * Removes a page
319
     *
320
     * @param \DERHANSEN\SfBanners\Domain\Model\page $pageToRemove
321
     * @return void
322
     */
323
    public function removeExcludepages(\DERHANSEN\SfBanners\Domain\Model\page $pageToRemove)
324
    {
325
        $this->excludepages->detach($pageToRemove);
326
    }
327
328
    /**
329
     * Setter for excludepages
330
     *
331
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $excludepages Excludepages
332
     * @return void
333
     */
334
    public function setExcludepages($excludepages)
335
    {
336
        $this->excludepages = $excludepages;
337
    }
338
339
    /**
340
     * Getter for excludepages
341
     *
342
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
343
     */
344
    public function getExcludepages()
345
    {
346
        return $this->excludepages;
347
    }
348
349
    /**
350
     * Setter for HTML
351
     *
352
     * @param string $html HTML
353
     * @return void
354
     */
355
    public function setHtml($html)
356
    {
357
        $this->html = $html;
358
    }
359
360
    /**
361
     * Getter for HTML
362
     *
363
     * @return string
364
     */
365
    public function getHtml()
366
    {
367
        return $this->html;
368
    }
369
370
    /**
371
     * Setter for impressions
372
     *
373
     * @param int $impressions Impressions
374
     * @return void
375
     */
376
    public function setImpressions($impressions)
377
    {
378
        $this->impressions = $impressions;
379
    }
380
381
    /**
382
     * Getter for impressions
383
     *
384
     * @return int
385
     */
386
    public function getImpressions()
387
    {
388
        return $this->impressions;
389
    }
390
391
    /**
392
     * Setter for max impressions
393
     *
394
     * @param int $impressionsMax Max impressions
395
     * @return void
396
     */
397
    public function setImpressionsMax($impressionsMax)
398
    {
399
        $this->impressionsMax = $impressionsMax;
400
    }
401
402
    /**
403
     * Getter for max impressions
404
     *
405
     * @return int
406
     */
407
    public function getImpressionsMax()
408 2
    {
409
        return $this->impressionsMax;
410 2
    }
411
412
    /**
413
     * Getter for link
414
     *
415
     * @return string
416
     */
417
    public function getLink()
418
    {
419
        $this->assets->rewind();
420
421
        /** @var \TYPO3\CMS\Extbase\Domain\Model\FileReference $fileReference */
422
        $fileReference = $this->assets->current();
423
424
        if ($fileReference === null) {
425
            return '';
426
        }
427
428
        /** @var \TYPO3\CMS\Core\Resource\FileReference $originalFileReference */
429 8
        $originalFileReference = $fileReference->getOriginalResource();
430
        return $originalFileReference->getLink();
431 8
    }
432
433
    /**
434
     * Setter for margin bottom
435
     *
436
     * @param int $marginBottom Margin bottom
437
     * @return void
438
     */
439
    public function setMarginBottom($marginBottom)
440
    {
441
        $this->marginBottom = $marginBottom;
442
    }
443
444
    /**
445
     * Getter for margin bottom
446
     *
447
     * @return int
448
     */
449
    public function getMarginBottom()
450
    {
451
        return $this->marginBottom;
452
    }
453
454
    /**
455
     * Setter for margin left
456
     *
457
     * @param int $marginLeft Margin left
458
     * @return void
459
     */
460
    public function setMarginLeft($marginLeft)
461
    {
462
        $this->marginLeft = $marginLeft;
463
    }
464
465
    /**
466
     * Getter for margin left
467
     *
468
     * @return int
469
     */
470
    public function getMarginLeft()
471
    {
472 8
        return $this->marginLeft;
473
    }
474 8
475
    /**
476
     * Setter for margin right
477
     *
478
     * @param int $marginRight Margin right
479
     * @return void
480
     */
481
    public function setMarginRight($marginRight)
482
    {
483
        $this->marginRight = $marginRight;
484
    }
485
486
    /**
487
     * Getter for margin right
488
     *
489
     * @return int
490
     */
491
    public function getMarginRight()
492
    {
493
        return $this->marginRight;
494
    }
495
496
    /**
497
     * Setter for margin top
498
     *
499
     * @param int $marginTop Margin top
500
     * @return void
501
     */
502
    public function setMarginTop($marginTop)
503
    {
504
        $this->marginTop = $marginTop;
505
    }
506
507
    /**
508
     * Getter for margin top
509
     *
510
     * @return int
511
     */
512
    public function getMarginTop()
513
    {
514
        return $this->marginTop;
515
    }
516
517
    /**
518
     * Sets the recursive flag
519
     *
520
     * @param bool $recursive
521
     * @return void
522
     */
523
    public function setRecursive($recursive)
524
    {
525
        $this->recursive = $recursive;
526
    }
527
528
    /**
529
     * Returns the recursive flag
530
     *
531
     * @return bool
532
     */
533
    public function getRecursive()
534
    {
535
        return $this->recursive;
536
    }
537
538
    /**
539
     * Updates the Impressions by 1
540
     *
541
     * @return void
542
     */
543
    public function increaseImpressions()
544
    {
545
        $this->impressions += 1;
546
    }
547
548
    /**
549
     * Updates the Impressions by 1
550
     *
551
     * @return void
552
     */
553
    public function increaseClicks()
554
    {
555
        $this->clicks += 1;
556
    }
557
558
    /**
559
     * Returns the uri of the link
560
     *
561
     * @return mixed
562
     */
563
    public function getLinkUrl()
564
    {
565
        $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
566
        return $cObj->getTypoLink_URL($this->getLink());
567
    }
568
569
    /**
570
     * Returns the target of the link
571
     *
572
     * @return string
573
     */
574
    public function getLinkTarget()
575
    {
576
        $link = $this->getLink();
577
        $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
578
        $cObj->getTypoLink_URL($link);
579
        return $cObj->lastTypoLinkTarget;
580
    }
581
582
    /**
583
     * Get the Fal media items
584
     *
585
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
0 ignored issues
show
Documentation introduced by
The doc-type \TYPO3\CMS\Extbase\Persi...in\Model\FileReference> could not be parsed: Expected "|" or "end of type", but got "<" at position 44. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
586
     */
587
    public function getAssets()
588
    {
589
        return $this->assets;
590
    }
591
592
    /**
593
     * Set Fal media relation
594
     *
595
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> $assets
0 ignored issues
show
Documentation introduced by
The doc-type \TYPO3\CMS\Extbase\Persi...in\Model\FileReference> could not be parsed: Expected "|" or "end of type", but got "<" at position 44. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
596
     * @return void
597
     */
598 2
    public function setAssets(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $assets)
599
    {
600 2
        $this->assets = $assets;
601
    }
602
603
    /**
604
     * Add a Fal media file reference
605
     *
606
     * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $asset
607
     */
608
    public function addAsset(\TYPO3\CMS\Extbase\Domain\Model\FileReference $asset)
609
    {
610
        $this->assets->attach($asset);
611
    }
612
613
    /**
614
     * Remove a Fal media file reference
615
     *
616
     * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $asset
617
     */
618
    public function removeAsset(\TYPO3\CMS\Extbase\Domain\Model\FileReference $asset)
619 8
    {
620
        $this->assets->detach($asset);
621 8
    }
622
}
623