forked from ONLYOFFICE/onlyoffice-humhub
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Events.php
61 lines (49 loc) · 1.74 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
52
53
54
55
56
57
58
59
60
61
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
/**
* Copyright (c) Ascensio System SIA 2023. All rights reserved.
* http://www.onlyoffice.com
*/
namespace humhub\modules\onlyoffice;
use Yii;
use humhub\modules\file\handler\FileHandlerCollection;
use humhub\modules\onlyoffice\permissions\CanUseOnlyOffice;
/**
* @author luke
*/
class Events
{
public static function onFileHandlerCollection($event)
{
if (!Yii::$app->user->can(CanUseOnlyOffice::class)) {
return;
}
/* @var $collection FileHandlerCollection */
$collection = $event->sender;
if ($collection->type === FileHandlerCollection::TYPE_CREATE) {
$collection->register(new filehandler\CreateFileHandler());
return;
}
/* @var $module \humhub\modules\onlyoffice\Module */
$module = Yii::$app->getModule('onlyoffice');
$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());
}
}
}
}