1+ <?php
2+
3+ /**
4+ * (c) Copyright Ascensio System SIA 2025.
5+ *
6+ * Licensed under the Apache License, Version 2.0 (the "License");
7+ * you may not use this file except in compliance with the License.
8+ * You may obtain a copy of the License at
9+ *
10+ * http://www.apache.org/licenses/LICENSE-2.0
11+ *
12+ * Unless required by applicable law or agreed to in writing, software
13+ * distributed under the License is distributed on an "AS IS" BASIS,
14+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ * See the License for the specific language governing permissions and
16+ * limitations under the License.
17+ */
18+
19+ declare (strict_types=1 );
20+
21+ use Chamilo \CoreBundle \Event \AbstractEvent ;
22+ use Chamilo \CoreBundle \Event \DocumentActionEvent ;
23+ use Chamilo \CoreBundle \Event \DocumentItemActionEvent ;
24+ use Chamilo \CoreBundle \Event \DocumentItemViewEvent ;
25+ use Chamilo \CoreBundle \Event \Events ;
26+ use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
27+
28+ class OnlyofficeEventSubscriber implements EventSubscriberInterface
29+ {
30+ public static function getSubscribedEvents (): array
31+ {
32+ return [
33+ Events::DOCUMENT_ACTION => 'onDocumentAction ' ,
34+ Events::DOCUMENT_ITEM_ACTION => 'onDocumentItemAction ' ,
35+ Events::DOCUMENT_ITEM_VIEW => 'onDocumentItemView ' ,
36+ ];
37+ }
38+
39+ /**
40+ * Create the Onlyoffice edit tools when the Chamilo loads document tools.
41+ */
42+ public function onDocumentAction (DocumentActionEvent $ event ): void
43+ {
44+ if (AbstractEvent::TYPE_PRE === $ event ->getType ()) {
45+ $ action = $ event ->getData ()['action ' ];
46+ $ action [] = OnlyofficeTools::getButtonCreateNew ();
47+
48+ $ event ->setData (['action ' => $ action ]);
49+ }
50+ }
51+
52+ /**
53+ * Create the Onlyoffice edit tools when the Chamilo loads document items.
54+ */
55+ public function onDocumentItemAction (DocumentItemActionEvent $ event ): void
56+ {
57+ if (AbstractEvent::TYPE_PRE === $ event ->getType ()) {
58+ $ action = $ event ->getAction ();
59+ $ action [] = OnlyofficeTools::getButtonEdit ($ event ->getDocument ());
60+
61+ $ event ->setData (['action ' => $ action ]);
62+ }
63+ }
64+
65+ /**
66+ * Create the Onlyoffice view tools when the Chamilo loads document items.
67+ */
68+ public function onDocumentItemView (DocumentItemViewEvent $ event ): void
69+ {
70+ $ document = $ event ->getDocument ();
71+
72+ $ link = OnlyofficeTools::getButtonView (
73+ [
74+ 'iid ' => $ document ->getIid (),
75+ 'title ' => $ document ->getTitle (),
76+ ]
77+ );
78+
79+ $ event ->addLink ($ link );
80+ }
81+ }
0 commit comments