This repository has been archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathEvents.php
160 lines (142 loc) · 5.17 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
namespace tracker;
use humhub\modules\content\models\Content;
use humhub\modules\space\models\Space;
use humhub\modules\space\widgets\Menu;
use tracker\models\Issue;
use yii\base\Event;
/**
* Description of TrackerEvents
*
* @author Evgeniy Tkachenko <[email protected]>
*/
class Events extends \yii\base\BaseObject
{
public static function onSpaceMenuInit(Event $event)
{
/** @var Menu $sender */
$sender = $event->sender;
if (!($sender instanceof Menu)) {
throw new \LogicException();
}
/** @var Space $space */
$space = $sender->space;
if (!($space instanceof Space)) {
throw new \LogicException();
}
if ($space->isModuleEnabled('tracker-issues')) {
$sender->addItem([
'label' => \Yii::t('TrackerIssuesModule.base', 'Tracker issues'),
'group' => 'modules',
'url' => $space->createUrl("/tracker-issues/issue/show"),
'icon' => '<i class="fa fa-check-square"></i>',
'isActive' => (\Yii::$app->controller->module->id === 'tracker-issues'),
]);
}
}
/**
* @param Event $event
* @return bool|\yii\web\Response
*/
public static function onBeforeSpaceActions(Event $event)
{
$contentId = \Yii::$app->request->getQueryParam('contentId');
if ($contentId === null) {
return true;
}
if (!Content::find()
->where(['id' => $contentId, 'object_model' => Issue::class])
->exists()) {
return true;
}
return \Yii::$app->controller->redirect(
[
'/' . Module::getIdentifier() . '/stream/index',
'contentId' => $contentId,
'cguid' => \Yii::$app->request->getQueryParam('cguid'),
'sguid' => \Yii::$app->request->getQueryParam('sguid'),
'uguid' => \Yii::$app->request->getQueryParam('uguid'),
]);
}
/**
* NOTE: It's may doesn't worked if other modules uses it too. Issue https://github.com/humhub/humhub/issues/2412
*
* @param Event $event
*/
public static function onStreamViewerCreate(Event $event)
{
if (isset($event->config['contentContainer'])) {
if ($event->config['contentContainer']->isModuleEnabled('tracker-issues')) {
$event->config['streamAction'] = '/tracker-issues/issue/stream';
}
} elseif (isset($event->config['streamAction'])) {
$event->config['streamAction'] = '/tracker-issues/dashboard/stream';
}
}
public static function onTopMenuInit(Event $event)
{
$user = \Yii::$app->user;
if ($user->isGuest) {
return;
}
if (\Yii::$app->getModule('tracker-issues')->showOnTopMenu === false) {
return;
}
$controller = \Yii::$app->controller;
/** @var $module */
$module = $controller->module;
$event->sender->addItem([
'label' => \Yii::t('TrackerIssuesModule.base', 'Tracker issues'),
'url' => ['/tracker-issues/dashboard/issues'],
'icon' => '<i class="fa fa-tasks"></i>',
'isActive' => ($module && $module->id === 'tracker-issues' && $controller->id === 'dashboard' &&
$controller->action->id === 'issues'),
'sortOrder' => 300,
]);
$event->sender->addItem([
'label' => \Yii::t('TrackerIssuesModule.views', 'Documents'),
'url' => ['/tracker-issues/document'],
'icon' => '<i class="fa fa-files-o"></i>',
'isActive' => ($module && $module->id === 'tracker-issues' && $controller->id === 'document'),
'sortOrder' => 310,
]);
$event->sender->addItem([
'label' => \Yii::t('TrackerIssuesModule.views', 'Tags'),
'url' => ['/tracker-issues/tag/index'],
'icon' => '<i class="fa fa-tags"></i>',
'isActive' => ($module && $module->id === 'tracker-issues' && $controller->id === 'tag'),
'sortOrder' => 320,
]);
}
/**
* On init of the WallEntryAddonWidget, attach the tags widget.
*
* @param Event $event
*/
public static function onWallEntryAddonInit(Event $event)
{
if ($event->sender->object instanceof Issue) {
$issue = $event->sender->object;
$event->sender
->addWidget(
widgets\DesignateTagWidget::className(),
['object' => $issue],
['sortOrder' => 30]
);
$event->sender
->addWidget(
widgets\SubtaskWidget::className(),
['object' => $issue],
['sortOrder' => 30]
);
if ($issue->status != \tracker\enum\IssueStatusEnum::TYPE_FINISHED) {
$event->sender
->addWidget(
widgets\FinishIssueWidget::className(),
['object' => $issue],
['sortOrder' => 30]
);
}
}
}
}