Skip to content

Commit 70e46e2

Browse files
author
Laur0r
authored
Merge pull request #69 from Laur0r/nohisconnection
Nohisconnection
2 parents 543c26f + f8d05b5 commit 70e46e2

9 files changed

+62
-63
lines changed

addcourse.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

1717
require_once('../../config.php');
18-
require_once('classes/add_course_form.php');
18+
//require_once('classes/add_course_form.php');
1919
$id = required_param('id', PARAM_INT);
2020

2121
require_course_login($id);
@@ -26,11 +26,17 @@
2626
$PAGE->set_title(get_string('add_course_header', 'block_evasys_sync'));
2727

2828
$record = $DB->get_record('block_evasys_sync_courseeval', array('course' => $id));
29-
if ($record !== false and ($record->state > \block_evasys_sync\course_evaluation_allocation::STATE_AUTO_NOTOPENED) and !is_siteadmin()) {
29+
if ($record !== false and ($record->state > \block_evasys_sync\course_evaluation_allocation::STATE_AUTO_NOTOPENED) and
30+
!is_siteadmin() or !get_config('block_evasys_sync', 'default_his_connection')) {
3031
echo $OUTPUT->header();
3132
echo get_string('forbidden', 'block_evasys_sync');
3233
echo $OUTPUT->footer();
3334
return;
35+
} else if(!array_key_exists('lsf_unification', core_plugin_manager::instance()->get_plugins_of_type('local'))){
36+
echo $OUTPUT->header();
37+
throw new \moodle_exception('nohisconnection_error', 'block_evasys_sync');
38+
echo $OUTPUT->footer();
39+
return;
3440
}
3541

3642
$mform = new \block_evasys_sync\add_course_form();

adminsettings.php

+5
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@
9595
} else {
9696
set_config('default_evasys_mode', 0, 'block_evasys_sync');
9797
}
98+
if (isset($data->default_his_connection)) {
99+
set_config('default_his_connection', $data->default_his_connection, 'block_evasys_sync');
100+
} else {
101+
set_config('default_his_connection', 0, 'block_evasys_sync');
102+
}
98103

99104
$records = \block_evasys_sync\user_cat_allocation::get_records();
100105
foreach ($records as $allocation) {

block_evasys_sync.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function get_content() {
9191
}
9292
$evasyssynchronizer = new \block_evasys_sync\evasys_synchronizer($this->page->course->id);
9393
try {
94-
$evasyscourses = $evasyssynchronizer->get_courses_from_lsf();
94+
$evasyscourses = $evasyssynchronizer->get_allocated_courses();
9595
} catch (Exception $exception) {
9696
\core\notification::warning(get_string('syncnotpossible', 'block_evasys_sync'));
9797
$this->content->text .= html_writer::div(get_string('syncnotpossible', 'block_evasys_sync'));
@@ -169,11 +169,11 @@ public function get_content() {
169169
// Query course data (put in function).
170170
foreach ($evasyscourses as $evasyscourseinfo) {
171171
$course = array();
172-
$course['evasyscoursetitle'] = $evasyssynchronizer->get_course_name($evasyscourseinfo['id']);
173-
$course['technicalid'] = $evasyssynchronizer->get_course_id($evasyscourseinfo['id']);
174-
$course['evasyscourseid'] = $evasyscourseinfo['id'];
175-
$course['c_participants'] = format_string($evasyssynchronizer->get_amount_participants($evasyscourseinfo['id']));
176-
$rawsurveys = $evasyssynchronizer->get_surveys($evasyscourseinfo['id']);
172+
$course['evasyscoursetitle'] = $evasyssynchronizer->get_course_name($evasyscourseinfo);
173+
$course['technicalid'] = $evasyssynchronizer->get_course_id($evasyscourseinfo);
174+
$course['evasyscourseid'] = $evasyscourseinfo;
175+
$course['c_participants'] = format_string($evasyssynchronizer->get_amount_participants($evasyscourseinfo));
176+
$rawsurveys = $evasyssynchronizer->get_surveys($evasyscourseinfo);
177177
$surveys = array();
178178
foreach ($rawsurveys as $rawsurvey) {
179179
$survey = array();
@@ -213,6 +213,7 @@ public function get_content() {
213213
}
214214

215215
$standardttimemode = (!$ismodeautomated && $recordhasstandardtime && !$record);
216+
$hisconnection = get_config('block_evasys_sync', 'default_his_connection');
216217

217218
// Create the data object for the mustache table.
218219
$data = array(
@@ -234,7 +235,7 @@ public function get_content() {
234235
// If the evaluation hasn't ended yet, display option to restart it.
235236
'startoption' => $startoption,
236237
// Only allow coursemapping before starting an evaluation.
237-
'coursemappingenabled' => !$startdisabled or is_siteadmin(),
238+
'coursemappingenabled' => $hisconnection and (!$startdisabled or is_siteadmin()),
238239
'nostudents' => $nostudents,
239240
'emailsentnotice' => $emailsentnotice,
240241
'evaluationperiodsetnotice' => $periodsetnotice,

classes/admin_form.php

+8
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ protected function definition() {
7474
$mform->setType($name, PARAM_BOOL);
7575
$mform->setDefault($name, get_config('block_evasys_sync', 'default_evasys_mode'));
7676

77+
// Default Mode.
78+
$name = 'default_his_connection';
79+
$title = get_string('his_connection', 'block_evasys_sync');
80+
$mform->addElement('checkbox', $name, $title);
81+
$mform->setType($name, PARAM_BOOL);
82+
$mform->addHelpButton('default_his_connection','his_connection', 'block_evasys_sync');
83+
$mform->setDefault($name, get_config('block_evasys_sync', 'default_his_connection'));
84+
7785
// Heading Add Category.
7886
$mform->addElement('html', '<h3>' . get_string('hd_user_cat', 'block_evasys_sync') . '</h3>');
7987

classes/evasys_inviter.php

+8-19
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
namespace block_evasys_sync;
1818

1919
defined('MOODLE_INTERNAL') || die();
20-
require_once($CFG->dirroot . "/local/lsf_unification/lib_his.php");
20+
2121
require_once($CFG->libdir . '/adminlib.php');
2222
require_once($CFG->dirroot . '/course/lib.php');
2323
/**
@@ -55,27 +55,16 @@ public static function get_evasysids($courseid) {
5555
$extras = [];
5656
}
5757
$extras = array_filter($extras);
58-
establish_secondary_DB_connection();
59-
// Fetch the Evasysids for the courses.
60-
$relevantcourses = array();
61-
foreach ($extras as $course) {
62-
$courseinfo = get_course_by_veranstid(intval($course));
63-
if (!is_object($courseinfo)) {
64-
throw new \Exception('Cannot sync: Connection to LSF could not be established. Please try again later.');
65-
}
66-
$relevantcourses[] = trim($courseinfo->veranstnr) . ' ' . trim($courseinfo->semestertxt);
67-
}
68-
// Maybe add entry via the $course->idnumber.
58+
59+
// Maybe add entry via the $course->idnumber.
6960
$course = get_course($courseid);
7061
if ($course->idnumber) {
71-
$courseinfo = get_course_by_veranstid(intval($course->idnumber));
72-
$maincourse = trim($courseinfo->veranstnr) . ' ' . trim($courseinfo->semestertxt);
62+
$maincourse = $course->idnumber;
7363
}
74-
if (!in_array($maincourse, $relevantcourses)) {
75-
$relevantcourses[] = $maincourse;
64+
if (!in_array($maincourse, $extras)) {
65+
$extras[] = $maincourse;
7666
}
77-
close_secondary_DB_connection();
78-
return $relevantcourses;
67+
return $extras;
7968
}
8069

8170
/**
@@ -363,4 +352,4 @@ public static function alert_coordinator($courseid, $startdate, $enddate) {
363352
email_to_user($usercoordinator, $USER, $subject, $message, '', '' , '',
364353
true, $USER->email, $USER->firstname . " " . $USER->lastname);
365354
}
366-
}
355+
}

classes/evasys_synchronizer.php

+15-31
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
defined('MOODLE_INTERNAL') || die();
2020

21-
require_once($CFG->dirroot . "/local/lsf_unification/lib_his.php");
2221
require_once($CFG->libdir . '/adminlib.php');
2322
require_once($CFG->dirroot . '/course/lib.php');
2423

@@ -27,7 +26,7 @@ class evasys_synchronizer {
2726
protected $soapclient;
2827
private $blockcontext;
2928
private $courseinformation;
30-
private $lsfcourses;
29+
private $evasyscourses;
3130

3231
public function __construct($courseid) {
3332
$this->courseid = $courseid;
@@ -36,26 +35,20 @@ public function __construct($courseid) {
3635
$this->courseinformation = $this->get_course_information();
3736
}
3837

39-
public function get_courses_from_lsf() {
38+
public function get_allocated_courses() {
4039
global $DB;
41-
if ($this->lsfcourses !== null) {
42-
return $this->lsfcourses;
40+
41+
if ($this->evasyscourses !== null) {
42+
return $this->evasyscourses;
4343
}
4444
$course = get_course($this->courseid);
4545

46-
// Fetch veranstnr from LSF view.
4746
if ($course->idnumber) {
48-
establish_secondary_DB_connection();
49-
$lsfentry = get_course_by_veranstid(intval($course->idnumber));
50-
close_secondary_DB_connection();
51-
52-
if (!is_object($lsfentry)) {
53-
throw new \Exception('Cannot sync: Connection to LSF could not be established. Please try again later.');
54-
}
55-
$maincourse = trim($lsfentry->veranstid);
47+
$maincourse = $course->idnumber;
5648
}
5749
// Fetch persistent object id.
5850
$pid = $DB->get_field('block_evasys_sync_courses', 'id', array('course' => $this->courseid));
51+
5952
// Get all associated courses.
6053
if (!$pid === false) {
6154
$extras = new \block_evasys_sync\course_evasys_courses_allocation($pid);
@@ -70,18 +63,8 @@ public function get_courses_from_lsf() {
7063
}
7164
}
7265
$extras = array_filter($extras);
73-
establish_secondary_DB_connection();
74-
// Fetch metadata (id, title) for the courses.
75-
$result = array();
76-
foreach ($extras as $course) {
77-
$courseinfo = get_course_by_veranstid(intval($course));
78-
$result[] = array(
79-
'title' => $courseinfo->titel,
80-
'id' => trim($courseinfo->veranstnr) . ' ' . trim($courseinfo->semestertxt));
81-
}
82-
close_secondary_DB_connection();
83-
$this->lsfcourses = $result;
84-
return $this->lsfcourses;
66+
$this->evasyscourses = $extras;
67+
return $this->evasyscourses;
8568
}
8669

8770
private function init_soap_client() {
@@ -101,15 +84,16 @@ private function init_soap_client() {
10184

10285
private function get_course_information() {
10386
$result = [];
104-
foreach ($this->get_courses_from_lsf() as $course) {
105-
$soapresult = $this->soapclient->GetCourse($course['id'], 'PUBLIC', true, true);
87+
foreach ($this->get_allocated_courses() as $course) {
88+
$soapresult = $this->soapclient->GetCourse($course, 'PUBLIC', true, true);
10689
if (is_soap_fault($soapresult)) {
90+
//var_dump("soap verbindung nicht funktioniert");
10791
// This happens e.g. if there is no corresponding course in EvaSys.
10892
return null;
10993
}
110-
$result[$course['id']] = $soapresult;
94+
$result[$course] = $soapresult;
11195
}
112-
return $result;
96+
return $result;
11397
}
11498

11599
/**
@@ -145,7 +129,7 @@ public function get_surveys($courseid) {
145129
public function get_all_surveys() {
146130
// Gets all surveys from the associated evasys courses.
147131
$surveys = [];
148-
foreach ($this->lsfcourses as $course) {
132+
foreach ($this->evasyscourses as $course) {
149133
$surveys = array_merge($surveys, $this->get_surveys($course['id']));
150134
}
151135
return $surveys;

lang/de/block_evasys_sync.php

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
$string['coursename'] = "Kursname";
5656
$string['associated'] = "zugeordnet";
5757
$string['forbidden'] = "Die Aktion ist im aktuellen Status des Kurses nicht zulässig";
58+
$string['hisconnection_error'] = "Um diese Funktion nutzen zu können, muss das lokale Plugin lsf_unification installiert werden";
5859
$string['maincoursepredefined'] = 'Vordefinierte Zuordnung.';
5960
$string['maincoursepredefined_help'] = 'Dieser LSF-Kurs ist fest zugeordnet, da dies der entsprechende Learnweb-Kurs ist. Falls Sie dies für nicht korrekt halten, wenden Sie sich bitte an den Learnweb-Support.';
6061

@@ -154,6 +155,10 @@
154155
$string['settings_wsdl_url'] = 'EvaSys WSDL URL';
155156
$string['settings_moodleuser'] = 'Standard Nutzer-ID des Benachrichtigungsempfängers nach Sync';
156157
$string['settings_mode'] = 'Standardmodus für Kategorien';
158+
$string['his_connection'] = 'Aktiviere Mehrfach-Evaluationen (Achtung, externes Plugin notwendig!)';
159+
$string['his_connection_help'] = 'Optionales Feature, dass es ermöglicht einem Kurs mehrere evasys Evaluationen zuzuordnen.
160+
Dazu wird ein externes lokale Plugin lsf_unification (https://github.com/learnweb/his_unification) und
161+
eine Anbindung an das CMS Software HIS LSF benötigt um weitere Veranstaltungen von den verantwortlichen Lehrenden zu identifizieren.';
157162
$string['settings_moodleuser_select'] = 'Kurskategorien';
158163
$string['settings_cc_select'] = 'Kurskategorie auswählen';
159164
$string['settings_cc_user'] = 'Nutzer-ID des Empfängers für die gewählte Kurskategorie';

lang/en/block_evasys_sync.php

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
$string['coursename'] = "Course name";
5555
$string['associated'] = "associated";
5656
$string['forbidden'] = "This action is currently prohibited.";
57+
$string['nohisconnection_error'] = "To be able to use this feature, the local plugin lsf_unification needs to be installed.";
5758
$string['maincoursepredefined'] = 'Fixed association.';
5859
$string['maincoursepredefined_help'] = 'This LSF course is fixed, as it has been directly associated with this Moodle course. If you think that this is incorrect, please contact the support team.';
5960

@@ -161,6 +162,10 @@
161162
$string['settings_wsdl_url'] = 'EvaSys WSDL URL';
162163
$string['settings_moodleuser'] = 'Default user ID of mail recipient after sync';
163164
$string['settings_mode'] = 'Default mode for categories';
165+
$string['his_connection'] = 'Enable multiple evaluations (Caution, this requires an external plugin)';
166+
$string['his_connection_help'] = 'Optional Feature which enables to assign multiple evasys evaluations to one course. This
167+
requires the external local plugin lsf_unification (https://github.com/learnweb/his_unification) and a connection to the CMS Software HIS LSF
168+
to identify further lectures of the corresponding teachers.';
164169
$string['settings_moodleuser_select'] = 'Course categories';
165170
$string['settings_cc_select'] = 'Select course category';
166171
$string['settings_cc_user'] = 'Recipient (moodle user id) for selected course category';

version.php

-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,3 @@
2121
$plugin->version = 2019203100; // YYYYMMDDHH (year, month, day, 24-hr time).
2222
$plugin->requires = 2017111300; // YYYmoYMMDDHH (This is the release version for Moodle 2.0).
2323
$plugin->maturity = MATURITY_RC;
24-
25-
$plugin->dependencies = array(
26-
'local_lsf_unification' => 2013090304, // The lsf_unification module is needed for retrieving the lsf id.
27-
);

0 commit comments

Comments
 (0)