/
FileItem.php
85 lines (71 loc) · 1.73 KB
/
FileItem.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
<?php
namespace Concrete\Core\Backup\ContentImporter\ValueInspector\Item;
use Concrete\Core\File\File;
class FileItem implements ItemInterface
{
protected $filename;
protected $prefix;
/**
* FileItem constructor.
* @param $filename
* @param $prefix
*/
public function __construct($filename, $prefix = null)
{
$this->filename = $filename;
$this->prefix = $prefix;
}
public function getReference()
{
$reference = '';
if ($this->prefix) {
$reference = $this->prefix . ':';
}
$reference .= $this->filename;
return $reference;
}
/**
* @return mixed
*/
public function getFilename()
{
return $this->filename;
}
/**
* @return null
*/
public function getPrefix()
{
return $this->prefix;
}
public function getDisplayName()
{
return t('File');
}
public function getContentObject()
{
$db = \Database::connection();
$fID = null;
if ($this->prefix) {
$fID = $db->GetOne('select fID from FileVersions where fvPrefix = ? and fvFilename = ?', [$this->prefix, $this->filename]);
} else {
$fID = $db->GetOne('select fID from FileVersions where fvFilename = ?', [$this->filename]);
}
if ($fID) {
$f = File::getByID($fID);
return $f;
}
}
public function getContentValue()
{
if ($o = $this->getContentObject()) {
return sprintf("{CCM:FID_DL_%s}", $o->getFileID());
}
}
public function getFieldValue()
{
if ($o = $this->getContentObject()) {
return $o->getFileID();
}
}
}