aboutsummaryrefslogtreecommitdiff
path: root/lib/models/eTask/Attempt.php
blob: 193cb24cd0840fe8b6d60bdc17bb86eef6d876b3 (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
<?php
namespace eTask;

use JSONArrayObject;

/**
 * eTask conforming assignment attempt definition.
 *
 * @property int $id database column
 * @property int $assignment_id database column
 * @property string $user_id database column
 * @property int|null $start database column
 * @property int|null $end database column
 * @property string $ip_address database column
 * @property \JSONArrayObject|null $options database column
 * @property int|null $mkdate database column
 * @property int|null $chdate database column
 * @property Assignment $assignment belongs_to Assignment
 */
class Attempt extends \SimpleORMap implements \PrivacyObject
{
    use ConfigureTrait;

    /**
     * @see SimpleORMap::configure
     */
    protected static function configure($config = [])
    {
        $config['db_table'] = 'etask_assignment_attempts';

        $config['relationTypes'] = self::configureClassNames($config);

        $config['belongs_to']['assignment'] = [
            'class_name' => $config['relationTypes']['Assignment'],
            'foreign_key' => 'assignment_id'
        ];

        $config['serialized_fields']['options'] = JSONArrayObject::class;

        parent::configure($config);
    }

    /**
     * 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)
    {
        $sorm = self::findBySQL("user_id = ?", [$storage->user_id]);
        if ($sorm) {
            $field_data = [];
            foreach ($sorm as $row) {
                $field_data[] = $row->toRawArray();
            }
            if ($field_data) {
                $storage->addTabularData(_('eTask Zuweisungen'), 'etask_assignment_attempts', $field_data);
            }
        }
    }
}