/
DefaultConfiguration.php
101 lines (84 loc) · 3.19 KB
/
DefaultConfiguration.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
<?php
namespace Concrete\Core\File\Component\Chooser;
use Concrete\Core\Entity\File\Folder\FavoriteFolder;
use Concrete\Core\Entity\Search\SavedFileSearch;
use Concrete\Core\Entity\User\User;
use Concrete\Core\File\Component\Chooser\Option\ExternalFileProviderOption;
use Concrete\Core\File\Component\Chooser\Option\FileManagerOption;
use Concrete\Core\File\Component\Chooser\Option\FileSetsOption;
use Concrete\Core\File\Component\Chooser\Option\FileUploadOption;
use Concrete\Core\File\Component\Chooser\Option\FolderBookmarkOption;
use Concrete\Core\File\Component\Chooser\Option\RecentUploadsOption;
use Concrete\Core\File\Component\Chooser\Option\SavedSearchOption;
use Concrete\Core\File\Component\Chooser\Option\SearchOption;
use Concrete\Core\File\ExternalFileProvider\ExternalFileProviderFactory;
use Concrete\Core\File\Set\Set;
use Doctrine\ORM\EntityManager;
class DefaultConfiguration implements ChooserConfigurationInterface
{
public function __construct(
EntityManager $entityManager,
ExternalFileProviderFactory $externalFileProviderFactory
)
{
$sets = Set::getMySets();
$searches = $entityManager->getRepository(SavedFileSearch::class)->findAll();
$this->addChooser(new RecentUploadsOption());
$this->addChooser(new FileManagerOption());
$this->addChooser(new SearchOption());
if (count($sets) > 0) {
$this->addChooser(new FileSetsOption());
}
if (count($searches) > 0) {
$this->addChooser(new SavedSearchOption());
}
$this->addUploader(new FileUploadOption());
// get external file providers
foreach ($externalFileProviderFactory->fetchList() as $externalFileProvider) {
$this->addUploader(new ExternalFileProviderOption($externalFileProvider));
}
// get all favored folders
$user = new \Concrete\Core\User\User();
$favoriteFolderRepository = $entityManager->getRepository(FavoriteFolder::class);
$userRepository = $entityManager->getRepository(User::class);
/** @var User $userEntity */
$userEntity = $userRepository->findOneBy(["uID" => $user->getUserID()]);
$favoriteFolderEntries = $favoriteFolderRepository->findBy([
"owner" => $userEntity
]);
foreach ($favoriteFolderEntries as $favoriteFolderEntry) {
/** @noinspection PhpUnhandledExceptionInspection */
$this->addChooser(new FolderBookmarkOption($favoriteFolderEntry));
}
}
/**
* @var UploaderOptionInterface[]
*/
protected $uploaders = [];
/**
* @var ChooserOptionInterface[]
*/
protected $choosers = [];
public function addChooser(ChooserOptionInterface $chooserOption)
{
$this->choosers[] = $chooserOption;
}
public function addUploader(UploaderOptionInterface $uploaderOption)
{
$this->uploaders[] = $uploaderOption;
}
/**
* @return UploaderOptionInterface[]
*/
public function getUploaders(): array
{
return $this->uploaders;
}
/**
* @return ChooserOptionInterface[]
*/
public function getChoosers(): array
{
return $this->choosers;
}
}