-
Notifications
You must be signed in to change notification settings - Fork 5
/
controller.php
103 lines (86 loc) · 3.52 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
<?php
/**
* Created by Pure/Web for Pure/Multiple files
* www.pure-web.ru
* © 2016
*/
namespace Concrete\Package\PureMultipleFiles;
use \Concrete\Core\Attribute\Type as AttributeType;
use \Concrete\Core\File\File;
use \Concrete\Core\Package\Package as PackageInstaller;
use \Concrete\Core\Support\Facade\Route;
defined('C5_EXECUTE') or die("Access Denied.");
class Controller extends PackageInstaller {
protected $pkgHandle = 'pure_multiple_files';
protected $appVersionRequired = '9.0.0';
protected $pkgVersion = '1.1.0';
public function getPackageName() {
return t("Multiple files attribute");
}
public function getPackageDescription() {
return t("Multiple file selection attribute");
}
public function on_start() {
//*******************************************
//Assets
$al = \Concrete\Core\Asset\AssetList::getInstance();
//JS
$al->register(
'javascript', //asset type
'jquery/tmpl', //asset name
'assets/js/jquery.tmpl.min.js', //path
array(),
'pure_multiple_files' //from package
);
//********************
//*******************************************
//Routes
Route::register('/ccm/multiple_files_attribute/get_file_info/', function() {
/** @var \Concrete\Core\Validation\CSRF\Token $token */
$token = $this->app->make('token');
/** @var \Concrete\Core\Error\ErrorList\ErrorList $e */
$e = $this->app->make('error');
/** @var \Concrete\Core\Http\ResponseFactoryInterface $responseFactory */
$responseFactory = $this->app->make(\Concrete\Core\Http\ResponseFactoryInterface::class);
if ($token->validate('get_files_info')) {
//$fIDs = explode(',', $_GET['fIDs']);
$fIDs = $_GET['fIDs'];
if (is_array($fIDs) && count($fIDs) > 0) {
foreach ($fIDs as $fID) {
/** @var \Concrete\Core\File\File $file */
$file = File::getByID($fID);
//var_dump($file); exit;
if ($file instanceof \Concrete\Core\Entity\File\File) {
/** @var \Concrete\Core\Entity\File\Version $fv */
$fv = $file->getRecentVersion();
$fileInfo = new \StdClass();
$fileInfo->fID = $fv->getFileID();
$fileInfo->filename = $fv->getTitle();
$fileInfo->thumbnailIMG = $fv->getListingThumbnailImage();
$files[] = $fileInfo;
} else {
$e->add(t('File not found'));
break;
}
}
} else {
$e->add(t('File IDs is not valid'));
}
} else {
$e->add($token->getErrorMessage());
}
if (!$e->has()) {
return $responseFactory->json($files);
} else {
return $responseFactory->json($e);
}
});
//*********************
}
public function install() {
/** @var $pkg \Concrete\Core\Entity\Package() */
$pkg = parent::install(); //parent is \Concrete\Core\Package\Package
//\Concrete\Core\Attribute\Type as AttributeType
AttributeType::add("pure_multiple_files", "Multiple Files Attribute", $pkg);
}
}