forked from GreenMeteor/codebox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.php
84 lines (72 loc) · 1.97 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
<?php
namespace humhub\modules\codebox;
use Yii;
use yii\helpers\Url;
use humhub\components\Module as BaseModule;
use humhub\modules\codebox\models\ConfigureForm;
class Module extends BaseModule
{
public $resourcesPath = 'resources';
/**
* Returns the URL to the configuration page.
*
* @return string the URL to the configuration page
*/
public function getConfigUrl()
{
return Url::to(['/codebox/admin']);
}
/**
* Retrieves all settings from the database.
*
* @return array the settings
*/
protected function getSettings()
{
$models = ConfigureForm::find()->all();
$settings = [];
foreach ($models as $model) {
$settings[$model->getAttribute('name')] = $model->getAttribute('value');
}
return $settings;
}
/**
* Retrieves a setting from the database.
*
* @param string $name the name of the setting attribute
* @param mixed $defaultValue the default value if the setting is not found
* @return mixed the value of the setting
*/
protected function getSetting($name, $defaultValue = null)
{
$settings = $this->getSettings();
return isset($settings[$name]) ? $settings[$name] : $defaultValue;
}
/**
* Retrieves the title from the module settings.
*
* @return string the title
*/
public function getTitle()
{
return $this->getSetting('title');
}
/**
* Retrieves the HTML code snippet from the module settings.
*
* @return string the HTML code snippet
*/
public function getHtmlCode()
{
return $this->getSetting('htmlCode');
}
/**
* Retrieves the sort order from the module settings.
*
* @return int the sort order
*/
public function getOrder()
{
return $this->getSetting('sortOrder', 100);
}
}