Completed
Push — master ( fbcba1...2125d9 )
by Nate
04:26
created

DownloadAttachmentEvent::init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/force/license
6
 * @link       https://www.flipboxfactory.com/software/force/
7
 */
8
9
namespace flipbox\craft\salesforce\events;
10
11
use Craft;
12
use yii\base\Event;
13
14
/**
15
 * @author Flipbox Factory <[email protected]>
16
 * @since 1.2.0
17
 */
18
class DownloadAttachmentEvent extends Event
19
{
20
    /**
21
     * The 'Content Version' Salesforce Object which contained the file.
22
     *
23
     * Ref: https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_contentversion.htm
24
     * @var array
25
     */
26
    public $object;
27
28
    /**
29
     * The file name.
30
     *
31
     * @var string
32
     */
33
    public $fileName;
34
35
    /**
36
     * The raw file contents.
37
     *
38
     * @var string
39
     */
40
    public $fileContents;
41
42
    /**
43
     * @var bool whether the document can be downloaded. Defaults to true.
44
     */
45
    public $canDownload;
46
47
    /**
48
     * @var bool whether the document can be downloaded. Defaults to true.
49
     */
50
    public $unauthorizedMessage = "Unauthorized";
51
52
    /**
53
     * Allow ONLY admins to download everything by default
54
     */
55
    public function init()
56
    {
57
        if (null === $this->canDownload) {
58
            $this->canDownload = Craft::$app->getUser()->getIsAdmin();
59
        }
60
61
        parent::init();
62
    }
63
}
64