forked from humhub/questions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
112 lines (98 loc) · 2.51 KB
/
Module.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
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\questions;
use humhub\modules\content\components\ActiveQueryContent;
use humhub\modules\content\components\ContentContainerActiveRecord;
use humhub\modules\questions\helpers\Url;
use humhub\modules\questions\models\Question;
use humhub\modules\space\models\Space;
use humhub\modules\content\components\ContentContainerModule;
use Yii;
/**
* Questions Module is the WebModule for the Q&A system.
*
* @package humhub.modules.questions
* @author Luke
*/
class Module extends ContentContainerModule
{
/**
* @inheritdoc
*/
public $resourcesPath = 'resources';
/**
* @inheritdoc
*/
public function getPermissions($contentContainer = null)
{
if ($contentContainer instanceof Space) {
return [
new permissions\CreateQuestion(),
new permissions\SelectBestAnswer()
];
}
return [];
}
/**
* @inheritdoc
*/
public function getContentContainerConfigUrl(ContentContainerActiveRecord $container)
{
return Url::toContainerSettings($container);
}
/**
* @inheritdoc
*/
public function getContentContainerTypes()
{
return [Space::class];
}
/**
* @inheritdoc
*/
public function getContentClasses(): array
{
return [Question::class];
}
/**
* @inheritdoc
*/
public function getContentContainerName(ContentContainerActiveRecord $container)
{
return Yii::t('QuestionsModule.base', 'Questions and Answers');
}
/**
* @inheritdoc
*/
public function getContentContainerDescription(ContentContainerActiveRecord $container)
{
return Yii::t('QuestionsModule.base', 'Allows to create questions.');
}
/**
* @inheritdoc
*/
public function disable()
{
$this->deleteRecords(Question::find());
parent::disable();
}
/**
* @inheritdoc
*/
public function disableContentContainer(ContentContainerActiveRecord $container)
{
$this->deleteRecords(Question::find()->contentContainer($container));
parent::disableContentContainer($container);
}
private function deleteRecords(ActiveQueryContent $query)
{
foreach ($query->each() as $question) {
/* @var Question $question */
$question->hardDelete();
}
}
}