forked from data-quest/EvasysPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload_participants.cronjob.php
103 lines (98 loc) · 4.57 KB
/
upload_participants.cronjob.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
<?php
class EvasysUploadParticipantsJob extends CronJob
{
/**
* Returns the name of the cronjob.
*/
public static function getName()
{
return dgettext("evasys", 'EvaSys: Teilnehmer erneut hochladen');
}
/**
* Returns the description of the cronjob.
*/
public static function getDescription()
{
return dgettext("evasys", 'Gleicht alle in den nächten 28 Stunden startenden Evaluationen nochmal mit dem EvaSys-Server ab und lädt zum Beispiel die aktuelle Teilnehmerliste automatisch mit hoch.');
}
/**
* Setup method. Loads neccessary classes and checks environment. Will
* bail out with an exception if environment does not match requirements.
*/
public function setUp()
{
ini_set("memory_limit","1024M"); //won't work with suhosin
require_once __DIR__."/EvasysPlugin.class.php";
}
/**
* Return the parameters for this cronjob.
*
* @return Array Parameters.
*/
public static function getParameters()
{
return [
'prevent_paper' => [
'type' => 'boolean',
'default' => "0",
'status' => 'optional',
'description' => _('Wenn diese Option gewählt ist, werden keine papierbasierten Evaluationen mit übertragen.')
]
];
}
/**
* Executes the cronjob.
*
* @param mixed $last_result What the last execution of this cronjob
* returned.
* @param Array $parameters Parameters for this cronjob instance which
* were defined during scheduling.
* Only valid parameter at the moment is
* "verbose" which toggles verbose output while
* purging the cache.
*/
public function execute($last_result, $parameters = array())
{
$start = mktime(0, 0, 0, date("n"), date("j") + 1); // 0 Uhr des nächsten Tages
$end = $start + 86400; // 0 Uhr des übernächsten Tages
$sql = "
SELECT `evasys_course_profiles`.`seminar_id`
FROM `evasys_course_profiles`
LEFT JOIN seminare ON (`evasys_course_profiles`.`seminar_id` = `seminare`.`Seminar_id`)
LEFT JOIN evasys_institute_profiles ON (`evasys_institute_profiles`.`institut_id` = `seminare`.`Institut_id`
AND evasys_institute_profiles.semester_id = `evasys_course_profiles`.`semester_id`)
LEFT JOIN `Institute` ON (`seminare`.`Institut_id` = `Institute`.`Institut_id`)
LEFT JOIN `evasys_institute_profiles` AS `evasys_fakultaet_profiles` ON (`evasys_fakultaet_profiles`.`institut_id` = `Institute`.`fakultaets_id`
AND `evasys_fakultaet_profiles`.`semester_id` = `evasys_course_profiles`.`semester_id`)
LEFT JOIN evasys_global_profiles ON (`evasys_global_profiles`.`semester_id` = `evasys_course_profiles`.`semester_id`)
WHERE `evasys_course_profiles`.`transferred` = '1'
AND IFNULL(`evasys_course_profiles`.`begin`, IFNULL(evasys_institute_profiles.begin, IFNULL(evasys_fakultaet_profiles.begin, evasys_global_profiles.begin))) >= :start
AND IFNULL(`evasys_course_profiles`.`begin`, IFNULL(evasys_institute_profiles.begin, IFNULL(evasys_fakultaet_profiles.begin, evasys_global_profiles.begin))) < :end
";
if ($parameters['prevent_paper']) {
$sql .= " AND `evasys_course_profiles`.`mode` = 'online'";
}
$statement = DBManager::get()->prepare($sql);
$statement->execute(array(
'start' => $start,
'end' => $end
));
$seminars = array();
foreach ($statement->fetchAll(PDO::FETCH_COLUMN, 0) as $seminar_id) {
$seminars[] = new EvasysSeminar($seminar_id);
}
if (count($seminars)) {
echo count($seminars) . " Veranstaltungen werden mit EvaSys synchronisiert.\n";
echo implode(" ", array_map(function ($s) { return $s->getId(); }, $seminars))."\n";
$error = EvasysSeminar::UploadSessions($seminars);
if (is_string($error)) {
echo "error: " . $error . "\n";
}
foreach (PageLayout::getMessages() as $messagebox) {
echo $messagebox->class . ": " . $messagebox->message . "\n";
}
} else {
echo "Es müssen keine Evaluationen am ".date("d.m.Y", $start)." gestartet werden, daher wird auch nichts synchronisiert.";
}
}
}