-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_form.php
108 lines (87 loc) · 3.76 KB
/
mod_form.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
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Add olw form
*
* @package mod
* @subpackage olw
* @copyright 2006 Jamie Pratt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once ($CFG->dirroot.'/course/moodleform_mod.php');
class mod_olw_mod_form extends moodleform_mod {
function definition() {
GLOBAL $DB;
$mform = $this->_form;
$mform->addElement('header', 'generalhdr', get_string('general'));
/*
$this->add_intro_editor(true, get_string('olwtext', 'olw'));
$mform->removeElement('introeditor');
*/
$attributes=array('size'=>'200', 'style' => 'width:40%');
$mform->addElement('text', 'link', get_string('enterlink', 'olw'), $attributes);
if(isset($_REQUEST['update'])) {
$count = $DB->count_records('course_modules', array('id' => $_REQUEST['update']));
if($count > 0) {
$instance = $DB->get_record('course_modules', array('id' => $_REQUEST['update']), $fields='instance', $strictness='MUST_EXIST');
$link = $DB->get_record('olw', array('id' => $instance->instance), 'intro, materialid', $strictness='MUST_EXIST');
$matID = $link->materialid;
//echo "<pre>".print_r ($link->intro)."</pre>";
//echo "<pre>".print_r ($link)."</pre>";
//echo "<pre>".print_r ($matID)."</pre>";
// Sammlung oder Material?
if(strpos($link->intro, "collection") > 0) {
$domain = "https://openlearnware.tu-darmstadt.de/collection/";
$feed_url = "https://openlearnware.tu-darmstadt.de/olw-rest-db/api/collection-detailview/".$matID;
}
else {
$domain = "https://openlearnware.tu-darmstadt.de/resource/";
$feed_url = "https://openlearnware.tu-darmstadt.de/olw-rest-db/api/resource-detailview/".$matID;
}
// Wir filtern uns den Namen aus der olw-rest-db
$c = new curl(array('cache'=>true, 'module_cache'=>'repository'));
$content = $c->get($feed_url);
$elements = json_decode($content, true);
$name = $elements["name"];
//echo "<pre>".print_r ($name)."</pre>";
//Dann ersetzen wir alle Leerzeichen mit Bindestrichen
$name_new = str_replace ( " " , "-" , $name );
//echo "<pre>".print_r ($name_new)."</pre>";
//.. und f�gen die ID hinter den Namen ein
$nameID = $name_new."-".$matID;
//echo "<pre>".print_r ($nameID)."</pre>";
// Hier wird der Link rekonstruiert, der dann bei der Bearbeitung des Moduls erscheint
$mform->setDefault('link', $domain.$nameID);
}
}
$mform->addRule('link', get_string('error'), 'required', 'extra', 'server', false, false);
$mform->addHelpButton('link', 'link', 'olw');
$mform->setType('link', PARAM_TEXT);
$this->standard_coursemodule_elements();
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons(true, false, null);
}
function validation($data, $files) {
$errors = parent::validation($data, $files);
$explosion = explode("/",$data['link']);
if(!isset($explosion[4])) {
$errors['option[0]'] = get_string('wronglink', 'olw');
}
return $errors;
}
}