Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alert coordinators #58

Merged
merged 5 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions classes/course_evasys_courses_allocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,26 @@ protected static function define_properties() {
),
);
}

/** Returns array of evasysids that belong to this course.
* @param $courseid int id of moodle course
* @return array of evasysids
* @throws \dml_exception
*/
public static function raw_get_evasyscourses($courseid) {
global $DB;
$courses = $DB->get_field(self::TABLE, 'evasyscourses', array('course' => $courseid));
$idcourse = $DB->get_field('course', 'idnumber', array('id' => $courseid));
$coursearray = array();
if ($courses) {
$coursearray = explode('#', $courses);
}
if ($idcourse) {
if (!in_array($idcourse, $coursearray)) {
$coursearray[] = $idcourse;
}
}
array_unique($coursearray);
return $coursearray;
}
}
32 changes: 32 additions & 0 deletions classes/evasys_inviter.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,36 @@ public static function getmode($category) {
$default = get_config('block_evasys_sync', 'default_evasys_mode');
return (bool)$default;
}

/**
* Alerts the Evaluation-coordinator of a given course, that a teacher has set a timeframe for the evaluation.
* @param $courseid int
* @param $startdate \DateTime Startdate
* @param $enddate \DateTime
* @throws \coding_exception
* @throws \dml_exception
*/
public static function alert_coordinator($courseid, $startdate, $enddate) {
global $USER;
$course = get_course($courseid);
$evacourses = course_evasys_courses_allocation::raw_get_evasyscourses($courseid);
$coursestring = '';
foreach ($evacourses as $evacourse) {
// Add courses with two tabulators.
$coursestring .= "\t\t". $evacourse . "\n";
}
$usercoordinator = evasys_synchronizer::get_assigned_user($course);
$data = array(
'name' => $course->fullname,
'teacher' => $USER->firstname . " " . $USER->lastname,
'start' => $startdate->format('d.m.Y H:i:s'),
'end' => $enddate->format('d.m.Y H:i:s'),
'evasyscourses' => $coursestring
);
$subject = get_string("alert_email_subject", "block_evasys_sync", $course->fullname);
$message = get_string("alert_email_body", "block_evasys_sync", $data);

email_to_user($usercoordinator, $USER, $subject, $message, '', '' , '',
true, $USER->email, $USER->firstname . " " . $USER->lastname);
}
}
2 changes: 1 addition & 1 deletion invite.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
)
);
$event->trigger();

\block_evasys_sync\evasys_inviter::alert_coordinator($courseid, $startdate, $enddate);

if ($invitedirect) {
$invitedusers = count_enrolled_users(context_course::instance($courseid), 'block/evasys_sync:mayevaluate');
Expand Down
12 changes: 12 additions & 0 deletions lang/de/block_evasys_sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@
$string['content_send_invalid'] = "Eine Evaluationsperiode beginnt nachdem sie endet! <br />" .
"Alle anderen Evaluationsperioden wurden wie gewohnt geändert.";

// Alert Coordinator mail.
$string['alert_email_subject'] = 'Evaluationszeitraum gesetzt für {$a}';
$string['alert_email_body'] = 'Sehr geehrte*r Evaluationskoordinator*in, ' . "\n" .
'Sie erhalten diese E-Mail da im Learnweb-Kurs "{$a->name}" der Evaluationszeitraum wie folgt festgesetzt wurde:' . "\n\n" .
"\t".'Start: {$a->start}' . "\n" .
"\t".'Ende: {$a->end}' . "\n" .
"\t".'Verantwortliche*r: {$a->teacher}' . "\n" .
"\t".'EvaSys-IDs:' . "\n" .
'{$a->evasyscourses}' . "\n" .
'Mit freundlichen Grüßen' . "\n" .
'Ihr Learnweb-Support';

// New invite strings.
$string['title_success'] = "Erfolgreich";
$string['content_success_invite'] = "Die Evaluation wurde erfolgreich gestartet";
Expand Down
12 changes: 12 additions & 0 deletions lang/en/block_evasys_sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@
"This is not allowed. Some evaluationperiods may have been altered.<br />";
$string['content_confirm_reactivate'] = "Are you sure you want to reactivate the invite options? This will restart all surveys with at least one new participant";

// Alert Coordinator mail.
$string['alert_email_subject'] = 'Evaluationszeitraum gesetzt für {$a}';
$string['alert_email_body'] = 'Sehr geehrte*r Evaluationskoordinator*in, ' . "\n" .
'Sie erhalten diese E-Mail da im Learnweb-Kurs "{$a->name}" der Evaluationszeitraum wie folgt festgesetzt wurde:' . "\n\n" .
"\t".'Start: {$a->start}' . "\n" .
"\t".'Ende: {$a->end}' . "\n" .
"\t".'Verantwortliche*r: {$a->teacher}' . "\n" .
"\t".'EvaSys-IDs:' . "\n" .
'{$a->evasyscourses}' . "\n" .
'Mit freundlichen Grüßen' . "\n" .
'Ihr Learnweb-Support';

// New invite strings.
$string['title_success'] = "Success";
$string['content_success_invite'] = "Evaluation has been started";
Expand Down
143 changes: 143 additions & 0 deletions tests/courses_allocation_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?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/>.
/**
* Tests the class evasys_courses_allocation
* @package block_evasys_sync
* @category test
* @copyright 2019 T Reischmann
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();

/**
* PHPUnit evasys testcase
* @package block_evasys_sync
* @category test
* @copyright 2019 T Reischmann
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_evasys_courses_allocation_testcase extends advanced_testcase {

/**
* Tests if a course has a idnumber, but no allocation entry.
*/
public function test_idnumber_only() {
$this->resetAfterTest(true);

$idnumber = '123456789';

$courseone = $this->getDataGenerator()->create_course(array('name' => 'First course', 'idnumber' => $idnumber));

$result = \block_evasys_sync\course_evasys_courses_allocation::raw_get_evasyscourses($courseone->id);

$this->assertCount(1, $result);
$this->assertEquals($idnumber, array_pop($result));
}

/**
* Tests if a course has neither an idnumber, nor an allocation entry.
*/
public function test_no_idnumber() {
$this->resetAfterTest(true);

$courseone = $this->getDataGenerator()->create_course(array('name' => 'First course'));

$result = \block_evasys_sync\course_evasys_courses_allocation::raw_get_evasyscourses($courseone->id);

$this->assertCount(0, $result);
}

/**
* Tests if a course has an idnumber and an allocation entry.
*/
public function test_idnumber_and_allocation_entries() {
$this->resetAfterTest(true);

$idnumber = 'idnumber';
$evasysid1 = 'evasysid1';
$evasysid2 = 'evasysid2';

$courseone = $this->getDataGenerator()->create_course(array('name' => 'First course', 'idnumber' => $idnumber));

$allocation = new \block_evasys_sync\course_evasys_courses_allocation();

// Add first evasysid.
$evasysids = array();
$evasysids[] = $evasysid1;
$allocation->set('course', $courseone->id);
$allocation->set('evasyscourses', implode('#', $evasysids));
$allocation->save();

// Query evasyscourses and test them.
$result = \block_evasys_sync\course_evasys_courses_allocation::raw_get_evasyscourses($courseone->id);

$this->assertCount(2, $result);
$this->assertContains($idnumber, $result);
$this->assertContains($evasysid1, $result);

// Add a second evasysid.
$evasysids[] = $evasysid2;
$allocation->set('evasyscourses', implode('#', $evasysids));
$allocation->save();

// Query evasyscourses and test them.
$result = \block_evasys_sync\course_evasys_courses_allocation::raw_get_evasyscourses($courseone->id);

$this->assertCount(3, $result);
$this->assertContains($idnumber, $result);
$this->assertContains($evasysid1, $result);
$this->assertContains($evasysid2, $result);
}

/**
* Tests if a course has no idnumber, but an allocation entry.
*/
public function test_only_allocation_entries() {
$this->resetAfterTest(true);

$evasysid1 = 'evasysid1';
$evasysid2 = 'evasysid2';

$courseone = $this->getDataGenerator()->create_course(array('name' => 'First course'));

$allocation = new \block_evasys_sync\course_evasys_courses_allocation();

// Add first evasysid.
$evasysids = array();
$evasysids[] = $evasysid1;
$allocation->set('course', $courseone->id);
$allocation->set('evasyscourses', implode('#', $evasysids));
$allocation->save();

// Query evasyscourses and test them.
$result = \block_evasys_sync\course_evasys_courses_allocation::raw_get_evasyscourses($courseone->id);

$this->assertCount(1, $result);
$this->assertContains($evasysid1, $result);

// Add a second evasysid.
$evasysids[] = $evasysid2;
$allocation->set('evasyscourses', implode('#', $evasysids));
$allocation->save();

// Query evasyscourses and test them.
$result = \block_evasys_sync\course_evasys_courses_allocation::raw_get_evasyscourses($courseone->id);

$this->assertCount(2, $result);
$this->assertContains($evasysid1, $result);
$this->assertContains($evasysid2, $result);
}
}