aboutsummaryrefslogtreecommitdiff
path: root/lib/models/Courseware/TaskGroup.php
blob: 092edf644a44583d8a84798a92b7211ff0322429 (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
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
<?php

namespace Courseware;

use User;

/**
 * Courseware's tasks.
 *
 * @author  Ron Lucke <lucke@elan-ev.de>
 * @license GPL2 or any later version
 *
 * @since   Stud.IP 5.1
 *
 * @property int $id database column
 * @property string $seminar_id database column
 * @property string $lecturer_id database column
 * @property int $target_id database column
 * @property int $task_template_id database column
 * @property int $solver_may_add_blocks database column
 * @property string $title database column
 * @property int $mkdate database column
 * @property int $chdate database column
 * @property \SimpleORMapCollection|Task[] $tasks has_many Task
 * @property \User $lecturer belongs_to \User
 * @property \Course $course belongs_to \Course
 */
class TaskGroup extends \SimpleORMap implements \PrivacyObject
{
    protected static function configure($config = [])
    {
        $config['db_table'] = 'cw_task_groups';

        $config['belongs_to']['lecturer'] = [
            'class_name' => User::class,
            'foreign_key' => 'lecturer_id',
        ];

        $config['belongs_to']['course'] = [
            'class_name' => \Course::class,
            'foreign_key' => 'seminar_id',
        ];

        $config['has_many']['tasks'] = [
            'class_name' => Task::class,
            'assoc_foreign_key' => 'task_group_id',
            'on_delete' => 'delete',
            'on_store' => 'store',
            'order_by' => 'ORDER BY mkdate',
        ];

        parent::configure($config);
    }

    public function getSolvers(): iterable
    {
        $solvers = $this->tasks->pluck('solver');

        return $solvers;
    }

    /**
     * Export available data of a given user into a storage object
     * (an instance of the StoredUserData class) for that user.
     *
     * @param StoredUserData $storage object to store data into
     */
    public static function exportUserData(\StoredUserData $storage)
    {
        $task_groups = \DBManager::get()->fetchAll(
            'SELECT * FROM cw_task_groups WHERE lecturer_id = ?',
            [$storage->user_id]
        );
        if ($task_groups) {
            $storage->addTabularData(_('Courseware Aufgaben'), 'cw_task_groups', $task_groups);
        }
        
    }
}