Skip to content

Commit ed8585d

Browse files
committed
adding content license
1 parent ffedc77 commit ed8585d

File tree

9 files changed

+82
-6
lines changed

9 files changed

+82
-6
lines changed

backup/moodle2/backup_crucible_stepslib.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ protected function define_structure() {
5656
$crucible = new backup_nested_element('crucible', ['id'], [
5757
'name', 'intro', 'introformat', 'eventtemplateid', 'vmapp',
5858
'clock', 'extendevent', 'timeopen', 'timeclose', 'grade',
59-
'grademethod', 'timecreated', 'timemodified']);
59+
'grademethod', 'timecreated', 'timemodified', 'contentlicense',
60+
'showcontentlicense']);
6061

6162
// Define sources.
6263
$crucible->set_source_table('crucible', ['id' => backup::VAR_ACTIVITYID]);

db/upgrade.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,23 @@ function xmldb_crucible_upgrade($oldversion) {
537537
// Crucible savepoint reached.
538538
upgrade_mod_savepoint(true, 2021082301, 'crucible');
539539
}
540+
if ($oldversion < 2025060403) {
541+
// Define the table.
542+
$table = new xmldb_table('crucible');
543+
// Define field 'contentlicense'.
544+
$field1 = new xmldb_field('contentlicense', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'timemodified');
545+
if (!$dbman->field_exists($table, $field1)) {
546+
$dbman->add_field($table, $field1);
547+
}
548+
549+
// Define field 'showcontentlicense'.
550+
$field2 = new xmldb_field('showcontentlicense', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'contentlicense');
551+
if (!$dbman->field_exists($table, $field2)) {
552+
$dbman->add_field($table, $field2);
553+
}
554+
// Savepoint.
555+
upgrade_mod_savepoint(true, 2025060403, 'crucible');
556+
}
540557

541558
return true;
542559
}

lang/en/crucible.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
$string['configeventtemplate'] = 'Event Template GUID to be launched.';
6969
$string['configautocomplete'] = 'Display list of Event Templates in a dropdown or a searchable text box.';
7070
$string['configshowfailed'] = 'Show failed Events in the history table.';
71+
$string['contentlicense'] = 'Content License';
72+
$string['contentlicense_help'] = 'Select the appropriate content license associated with this content or lab from the dropdown menu.';
73+
$string['showcontentlicense'] = 'Display Content License to Students';
74+
$string['showcontentlicense_help'] = 'If checked, the content license text will be visible to students on the activity page.';
7175

7276
// Activity settings
7377
$string['vmapp_help'] = 'This determines whether the VM app is emebeded in an iframe or whether a link to the player is displayed';

mod_form.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
require_once($CFG->dirroot.'/course/moodleform_mod.php');
4444
require_once($CFG->dirroot.'/mod/crucible/locallib.php');
45+
require_once("$CFG->dirroot/lib/licenselib.php");
4546

4647
/**
4748
* Form definition for creating or editing Crucible activity instances.
@@ -109,6 +110,22 @@ public function definition() {
109110
$mform->setDefault('eventtemplateid', null);
110111
$mform->addHelpButton('eventtemplateid', 'eventtemplate', 'crucible');
111112

113+
$licenses = license_manager::get_licenses();
114+
if ($licenses) {
115+
foreach ($licenses as $license) {
116+
$license_options[$license->shortname] = $license->fullname;
117+
}
118+
} else {
119+
debugging('No licenses found.', DEBUG_DEVELOPER);
120+
}
121+
122+
$mform->addElement('select', 'contentlicense', get_string('contentlicense', 'crucible'), $license_options);
123+
$mform->setType('contentlicense', PARAM_TEXT);
124+
$mform->addHelpButton('contentlicense', 'contentlicense', 'crucible');
125+
126+
$mform->addElement('checkbox', 'showcontentlicense', get_string('showcontentlicense', 'crucible'));
127+
$mform->addHelpButton('showcontentlicense', 'showcontentlicense', 'crucible');
128+
112129
$mform->addElement('header', 'optionssection', get_string('appearance'));
113130

114131
$options = ['Display Link to Player', 'Embed VM App'];
@@ -225,6 +242,10 @@ public function data_postprocessing($data) {
225242
$data->intro = strip_tags($rawdescription); // Removes all HTML tags.
226243
$data->introformat = FORMAT_PLAIN;
227244

245+
if (!isset($data->showcontentlicense)) {
246+
$data->showcontentlicense = 0; // Checkbox unchecked, set to 0.
247+
}
248+
228249
// TODO if grade method changed, update all grades.
229250
}
230251

renderer.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,18 @@ class mod_crucible_renderer extends plugin_renderer_base {
5555
* @param object $crucible Crucible activity instance.
5656
* @param string $duration Formatted duration string to display.
5757
*/
58-
public function display_detail($crucible, $duration) {
58+
public function display_detail($crucible, $duration, $content_license = null) {
5959
$data = new stdClass();
6060
$data->name = $crucible->name;
6161
$data->intro = strip_tags($crucible->intro);
6262
$data->durationtext = get_string('durationtext', 'mod_crucible');
6363
$data->duration = $duration;
64+
65+
if ($content_license) {
66+
$data->license_fullname = $content_license->fullname;
67+
$data->license_source = $content_license->source;
68+
}
69+
6470
echo $this->render_from_template('mod_crucible/detail', $data);
6571
}
6672

styles.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,19 @@
4141
color: #00434e;
4242
background-color: #cce6ea;
4343
border-color: #b8dce2;
44+
}
45+
46+
.license-info {
47+
font-family: Arial, sans-serif; /* Modern font */
48+
font-size: 14px; /* Readable font size */
49+
line-height: 1.5; /* Better line spacing */
50+
}
51+
52+
.license-info a {
53+
color: #0073e6; /* Link color */
54+
text-decoration: none; /* Remove underline */
55+
}
56+
57+
.license-info a:hover {
58+
text-decoration: underline; /* Underline on hover */
4459
}

templates/detail.mustache

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ DM20-0196
3737
}}
3838

3939
<h1>{{name}}</h1>
40-
40+
{{#license_fullname}}
41+
<div class="license-info">
42+
<p><strong>License:</strong> <a href="{{license_source}}" target="_blank">{{license_fullname}}</a></p>
43+
</div>
44+
{{/license_fullname}}
4145
{{#duration}}
4246
<div class="notification-style notification-box">
4347
{{durationtext}}: {{duration}} hour(s)

version.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
defined('MOODLE_INTERNAL') || die();
4343

4444
// This is the version of the plugin.
45-
$plugin->version = 2025060400;
45+
$plugin->version = 2025060402;
4646

4747
// This is the version of Moodle this plugin requires.
48-
$plugin->requires = 2022112801;
48+
$plugin->requires = 2025041401;
4949

5050
// This is the component name of the plugin - it always starts with 'component_'.
5151
$plugin->component = 'mod_crucible';

view.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
require_once("$CFG->dirroot/mod/crucible/lib.php");
4545
require_once("$CFG->dirroot/mod/crucible/locallib.php");
4646
require_once($CFG->libdir . '/completionlib.php');
47+
require_once("$CFG->dirroot/lib/licenselib.php");
4748

4849
$id = optional_param('id', 0, PARAM_INT); // Course_module ID.
4950
$c = optional_param('c', 0, PARAM_INT); // Instance ID - it should be named as the first character of the module.
@@ -265,7 +266,14 @@
265266
$renderer = $PAGE->get_renderer('mod_crucible');
266267
echo $renderer->header();
267268

268-
$renderer->display_detail($crucible, $object->eventtemplate->durationHours);
269+
$license_info = null;
270+
271+
if ($object->crucible->showcontentlicense) {
272+
$license_id = $object->crucible->contentlicense;
273+
$license_info = license_manager::get_license_by_shortname($license_id);
274+
}
275+
276+
$renderer->display_detail($crucible, $object->eventtemplate->durationHours, $license_info);
269277

270278
$formattempts = $object->get_all_attempts_for_form();
271279

0 commit comments

Comments
 (0)