aboutsummaryrefslogtreecommitdiff
path: root/lib/cronjobs/expire_studygroups.class.php
blob: 3ad9b934696b63828878bb8abf1ce67374d5e067 (plain)
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
<?php
/**
 * expire_studygroups.class.php - Removes studygroups that have reached their expiration date
 * and also notifies about upcoming expirations to the founders of the studygroups.
 *
 * @author Rasmus Fuhse <fuhse@data-quest.de>
 * @access public
 * @since  6.0
 */

class ExpireStudygroups extends CronJob
{

    public static function getName()
    {
        return _('Studiengruppen abräumen');
    }

    public static function getDescription()
    {
        return _('Löscht ablaufende Studiengruppen und benachrichtigt einen Monat vor Ablauf der Studiengruppe über die Löschung.');
    }

    public function execute($last_result, $parameters = [])
    {
        $statement = DBManager::get()->prepare("
            SELECT `seminare`.*
            FROM `seminare`
                INNER JOIN `config_values` ON (`config_values`.`range_id` = `seminare`.`Seminar_id` AND `config_values`.`field` = 'STUDYGROUP_EXPIRATION_DATE')
            WHERE `config_values`.`value` >= UNIX_TIMESTAMP()
        ");
        $statement->execute();
        while ($course = Course::buildExisting($statement->fetch(PDO::FETCH_ASSOC))) {
            $course->delete();
        }

        //now the notifications
        $messaging = new messaging();
        $statement = DBManager::get()->prepare("
            SELECT `seminare`.*
            FROM `seminare`
                INNER JOIN `config_values` ON (`config_values`.`range_id` = `seminare`.`Seminar_id` AND `config_values`.`field` = 'STUDYGROUP_EXPIRATION_DATE')
            WHERE `config_values`.`value` >= UNIX_TIMESTAMP() - 86400 * 31
                AND `config_values`.`value` < UNIX_TIMESTAMP() - 86400 * 30
        ");
        $statement->execute([
            'last_time' => $last_result
        ]);
        while ($course = Course::buildExisting($statement->fetch(PDO::FETCH_ASSOC))) {

        }
    }
}