Skip to content

Commit 3e79d66

Browse files
committed
Merge branch 'feature/blocks-filter' into 'develop'
Feature MD File Blocks See merge request ILIAS/Plugins/Community/MDViewer!4
2 parents 859a59c + 702eb80 commit 3e79d66

9 files changed

+392
-171
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ MDViewer
33
### Description
44
Display Markdown-Text from an external source such as Github-Repos.
55

6+
With version >=1.4.0 of this plugin, external sources can contain blocks that follow a specific syntax which is similar to the one known from `ilTemplate`. An example can be found below.
7+
```
8+
<!-- BEGIN block_name_1 -->
9+
...
10+
### My Block title
11+
Lorem ipsdum dolor sit amet ...
12+
...
13+
<!-- END block_name_1 -->
14+
```
15+
As you can see, the block "tags" are simple HTML-comments which are not visible when rendering the actual MD file.
16+
17+
Of course, `block_name_1` can be replaced by the name of your choosing and wrap any content you like. Note that there is no duplicate protection though, so if multiple blocks with the same name are found, the first one will be used.
18+
619
### Installation
720
Start at your ILIAS root directory
821
```bash

classes/class.ilMDViewerConfig.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class ilMDViewerConfig extends ActiveRecord
99

1010
const TABLE_NAME = 'md_tme_config';
1111
const KEY_IDS_OF_AUTHORIZED_ROLES = "ids_of_authorized_roles";
12+
const KEY_MD_BLOCKS_FILTER_ACTIVE = 'md_blocks_filter_active';
1213

1314
/**
1415
* @return string

classes/class.ilMDViewerConfigGUI.php

Lines changed: 83 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@ class ilMDViewerConfigGUI extends ilPluginConfigGUI
1212
const CMD_CONFIGURE = 'configure';
1313
const CMD_SAVE = 'save';
1414
const CMD_CANCEL = 'cancel';
15+
16+
/**
17+
* @var \ILIAS\DI\HTTPServices
18+
*/
19+
protected $http;
20+
/**
21+
* @var \ILIAS\DI\RBACServices
22+
*/
23+
protected $rbac;
24+
/**
25+
* @var ilMDViewerPlugin
26+
*/
27+
protected $plugin;
28+
/**
29+
* @var \ILIAS\DI\UIServices
30+
*/
31+
protected $ui;
1532
/**
1633
* @var ilCtrl
1734
*/
@@ -24,10 +41,6 @@ class ilMDViewerConfigGUI extends ilPluginConfigGUI
2441
* @var ilTemplate
2542
*/
2643
protected $tpl;
27-
/**
28-
* @var ilPropertyFormGUI
29-
*/
30-
private $config_form;
3144

3245
/**
3346
* ilMDViewerConfigGUI constructor.
@@ -39,6 +52,10 @@ public function __construct()
3952
$this->ctrl = $DIC->ctrl();
4053
$this->lng = $DIC->language();
4154
$this->tpl = $DIC->ui()->mainTemplate();
55+
$this->http = $DIC->http();
56+
$this->rbac = $DIC->rbac();
57+
$this->plugin = $this->getPluginObject() ?? (new ilMDViewerPlugin());
58+
$this->ui = $DIC->ui();
4259
}
4360

4461
/**
@@ -60,22 +77,39 @@ public function performCommand($cmd)
6077
*/
6178
public function configure()
6279
{
63-
$this->initForm();
64-
$this->fillForm();
65-
$this->tpl->setContent($this->config_form->getHTML());
80+
$this->tpl->setContent(
81+
$this->ui->renderer()->render(
82+
$this->initForm()
83+
)
84+
);
6685
}
6786

6887
/**
6988
* Save configuration
7089
*/
7190
public function save()
7291
{
73-
ilMDViewerConfig::set(
74-
ilMDViewerConfig::KEY_IDS_OF_AUTHORIZED_ROLES,
75-
$_POST[ilMDViewerConfig::KEY_IDS_OF_AUTHORIZED_ROLES]
92+
$form = $this->initForm();
93+
$form = $form->withRequest($this->http->request());
94+
$data = $form->getData();
95+
96+
if (!empty($data)) {
97+
foreach ($data as $key => $value) {
98+
ilMDViewerConfig::set(
99+
$key,
100+
$value
101+
);
102+
}
103+
104+
ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
105+
$this->ctrl->redirect($this, self::CMD_CONFIGURE);
106+
}
107+
108+
$this->tpl->setContent(
109+
$this->ui->renderer()->render(
110+
$form
111+
)
76112
);
77-
ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
78-
$this->ctrl->redirect($this, self::CMD_CONFIGURE);
79113
}
80114

81115
/**
@@ -88,40 +122,53 @@ public function cancel()
88122

89123
/**
90124
* Initialize configuration-form
125+
* @return \ILIAS\UI\Component\Input\Container\Form\Standard
91126
*/
92127
protected function initForm()
93128
{
94-
// form
95-
$this->config_form = new ilPropertyFormGUI();
96-
$this->config_form->setFormAction($this->ctrl->getFormAction($this));
97-
$this->config_form->setTitle($this->getPluginObject()->txt('config_configuration'));
98-
99-
// multi select input for roles that shall be allowed to use the plugin
100-
$authorized_roles = new ilMultiSelectInputGUI(
101-
$this->getPluginObject()->txt("config_authorized_roles"),
102-
ilMDViewerConfig::KEY_IDS_OF_AUTHORIZED_ROLES
129+
return $this->ui->factory()->input()->container()->form()->standard(
130+
$this->ctrl->getFormActionByClass(self::class, self::CMD_SAVE),
131+
[
132+
// multi select input for roles that shall be allowed to use the plugin.
133+
ilMDViewerConfig::KEY_IDS_OF_AUTHORIZED_ROLES => $this->ui->factory()->input()->field()->multiSelect(
134+
$this->plugin->txt('config_authorized_roles'),
135+
$this->getConfigurableRoles()
136+
)->withByline(
137+
$this->plugin->txt('config_info_authorized_roles')
138+
)->withValue(
139+
ilMDViewerConfig::get(ilMDViewerConfig::KEY_IDS_OF_AUTHORIZED_ROLES) ?? ''
140+
),
141+
142+
// checkbox input for activating the blocks filter.
143+
ilMDViewerConfig::KEY_MD_BLOCKS_FILTER_ACTIVE => $this->ui->factory()->input()->field()->checkbox(
144+
$this->plugin->txt('config_blocks_filter')
145+
)->withByline(
146+
$this->plugin->txt('config_info_blocks_filter')
147+
)->withValue(
148+
ilMDViewerConfig::get(ilMDViewerConfig::KEY_MD_BLOCKS_FILTER_ACTIVE) ?? false
149+
),
150+
]
103151
);
104-
$authorized_roles->setOptions(self::getRoles(ilRbacReview::FILTER_ALL_GLOBAL));
105-
$authorized_roles->setInfo($this->getPluginObject()->txt("config_info_authorized_roles"));
106-
$authorized_roles->setRequired(true);
107-
$this->config_form->addItem($authorized_roles);
108-
109-
// save and cancel buttons
110-
$this->config_form->addCommandButton(self::CMD_SAVE, $this->lng->txt('save'));
111-
$this->config_form->addCommandButton(self::CMD_CANCEL, $this->lng->txt('cancel'));
112152
}
113153

114-
public function fillForm()
154+
/**
155+
* @return array<int, string>
156+
*/
157+
protected function getConfigurableRoles()
115158
{
116-
$array = array(
117-
ilMDViewerConfig::KEY_IDS_OF_AUTHORIZED_ROLES => ilMDViewerConfig::get(
118-
ilMDViewerConfig::KEY_IDS_OF_AUTHORIZED_ROLES
119-
),
120-
);
121-
$this->config_form->setValuesByArray($array);
159+
$roles = [];
160+
foreach ($this->rbac->review()->getRolesByFilter(ilRbacReview::FILTER_ALL) as $role_data) {
161+
$role_name = ilObjRole::_getTranslation($role_data['title']);
162+
$role_id = (int) $role_data['obj_id'];
163+
164+
$roles[$role_id] = $role_name;
165+
}
166+
167+
return $roles;
122168
}
123169

124170
/**
171+
* @deprecated
125172
* @param int $filter
126173
* @param bool $with_text
127174
* @return array

classes/class.ilMDViewerPlugin.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,25 @@ public function getPluginName()
2525
*/
2626
public function isValidParentType($a_parent_type)
2727
{
28-
global $rbacreview, $ilUser;
28+
/** @var $ilUser ilObjUser */
29+
global $ilUser;
30+
31+
return $this->isUserAuthorized($ilUser->getId());
32+
}
33+
34+
/**
35+
* @param int $user_id
36+
* @return bool
37+
*/
38+
public function isUserAuthorized($user_id)
39+
{
40+
/** @var $rbacreview ilRbacReview */
41+
global $rbacreview;
2942

3043
$authorized_roles = ilMDViewerConfig::get(ilMDViewerConfig::KEY_IDS_OF_AUTHORIZED_ROLES);
3144
if (!empty($authorized_roles)) {
3245
foreach ($authorized_roles as $authorized_role) {
33-
/**
34-
* @var $rbacreview ilRbacReview
35-
*/
36-
if ($rbacreview->isAssigned($ilUser->getId(), $authorized_role)) {
46+
if ($rbacreview->isAssigned($user_id, $authorized_role)) {
3747
return true;
3848
}
3949
}

0 commit comments

Comments
 (0)