/
controller.php
170 lines (135 loc) · 3.57 KB
/
controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
namespace Concrete\Block\File;
use Concrete\Core\Block\BlockController;
use Concrete\Core\Feature\Features;
use Concrete\Core\Feature\UsesFeatureInterface;
use Concrete\Core\File\File;
use Concrete\Core\File\Tracker\FileTrackableInterface;
class Controller extends BlockController implements FileTrackableInterface, UsesFeatureInterface
{
protected $btInterfaceWidth = 300;
protected $btCacheBlockRecord = true;
protected $btCacheBlockOutput = true;
protected $btCacheBlockOutputOnPost = true;
protected $btCacheBlockOutputForRegisteredUsers = true;
protected $btInterfaceHeight = 320;
protected $btTable = 'btContentFile';
protected $btExportFileColumns = ['fID'];
/**
* @var string
*/
public $fileLinkText;
/**
* @var int|null
*/
public $fID;
/**
* @var boolean|null
*/
public $forceDownload;
/**
* @var boolean|null
*/
public $filePassword;
/**
* Used for localization. If we want to localize the name/description we have to include this.
*/
public function getBlockTypeDescription()
{
return t('Link to files stored in the asset library.');
}
public function getBlockTypeName()
{
return t('File');
}
public function getRequiredFeatures(): array
{
return [
Features::BASICS,
];
}
public function getSearchableContent()
{
return $this->fileLinkText;
}
public function add()
{
$this->set('bf', null);
$this->set('fileLinkText', null);
$this->set('forceDownload', 0);
$this->set('al', $this->app->make('helper/concrete/file_manager'));
}
public function edit()
{
$this->set('al', $this->app->make('helper/concrete/file_manager'));
$this->set('bf', $this->getFileObject());
$this->set('fileLinkText', $this->getLinkText());
}
public function composer()
{
$this->edit();
}
public function validate_composer()
{
$f = $this->getFileObject();
$e = $this->app->make('helper/validation/error');
if (!is_object($f) || !$f->getFileID()) {
$e->add(t('You must specify a valid file.'));
}
return $e;
}
public function isComposerControlDraftValueEmpty()
{
$f = $this->getFileObject();
if (is_object($f)) {
return false;
}
return true;
}
public function save($args)
{
if (is_array($args) && isset($args['forceDownload'])) {
$args['forceDownload'] = ($args['forceDownload']) ? '1' : '0';
}
parent::save($args);
}
public function validate($args)
{
$e = $this->app->make('helper/validation/error');
if ($args['fID'] < 1) {
$e->add(t('You must select a file.'));
}
if (trim($args['fileLinkText']) == '') {
$e->add(t('You must enter the link text.'));
}
return $e;
}
public function getFileID()
{
return $this->fID;
}
/**
* @return \Concrete\Core\Entity\File\File|null
*/
public function getFileObject()
{
if ($this->fID) {
return File::getByID($this->fID);
}
return null;
}
public function getLinkText()
{
if ($this->fileLinkText) {
return $this->fileLinkText;
}
$f = $this->getFileObject();
if ($f) {
return $f->getTitle();
}
}
public function getUsedFiles()
{
return [$this->fID];
}
}