forked from ONLYOFFICE/onlyoffice-humhub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvents.php
51 lines (41 loc) · 1.5 KB
/
Events.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
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\onlydocuments;
use Yii;
use humhub\modules\file\handler\FileHandlerCollection;
/**
* @author luke
*/
class Events
{
public static function onFileHandlerCollection($event)
{
/* @var $collection FileHandlerCollection */
$collection = $event->sender;
if ($collection->type === FileHandlerCollection::TYPE_CREATE) {
$collection->register(new filehandler\CreateFileHandler());
return;
}
/* @var $module \humhub\modules\onlydocuments\Module */
$module = Yii::$app->getModule('onlydocuments');
$file = $event->sender->file;
if ($module->getDocumentType($file) !== null) {
$canEdit = $collection->type == FileHandlerCollection::TYPE_EDIT && $module->canEdit($file);
$canConvert = $collection->type == FileHandlerCollection::TYPE_EDIT && $module->canConvert($file);
$canView = $collection->type == FileHandlerCollection::TYPE_VIEW && $module->canView($file);
if ($canEdit) {
$collection->register(new filehandler\EditFileHandler());
}
if ($canConvert) {
$collection->register(new filehandler\ConvertFileHandler());
}
if ($canView) {
$collection->register(new filehandler\ViewFileHandler());
}
}
}
}