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

namespace Courseware;

use User;

/**
 * Courseware's clipboards.
 *
 * @author  Ron Lucke <lucke@elan-ev.de>
 * @license GPL2 or any later version
 *
 * @since   Stud.IP 5.4
 * 
 * @property int                            $id                     database column
 * @property string                         $user_id                database column
 * @property string                         $name                   database column
 * @property string                         $description            database column
 * @property int                            $block_id               database column
 * @property int                            $container_id           database column
 * @property int                            $structural_element_id  database column
 * @property string                         $object_type            database column
 * @property string                         $object_kind            database column
 * @property string                         $backup                 database column
 * @property int                            $mkdate                 database column
 * @property int                            $chdate                 database column
 * @property \User                          $user                   belongs_to User
 * @property Block $block belongs_to Block
 * @property Container $container belongs_to Container
 * @property StructuralElement $structural_element belongs_to StructuralElement
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
 * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
 */

class Clipboard extends \SimpleORMap
{
    protected static function configure($config = [])
    {
        $config['db_table'] = 'cw_clipboards';

        $config['belongs_to']['user'] = [
            'class_name' => User::class,
            'foreign_key' => 'user_id',
            'on_delete' => 'delete',
        ];

        $config['belongs_to']['block'] = [
            'class_name' => Block::class,
            'foreign_key' => 'block_id',
        ];

        $config['belongs_to']['container'] = [
            'class_name' => Container::class,
            'foreign_key' => 'container_id',
        ];
    
        $config['belongs_to']['structural_element'] = [
            'class_name' => StructuralElement::class,
            'foreign_key' => 'structural_element_id',
        ];

        parent::configure($config);
    }

    public static function findUsersClipboards($user): array
    {
        return self::findBySQL('user_id = ?', [$user->id]);
    }

    public static function deleteUsersClipboards($user, $type): void
    {
        self::deleteBySQL(
            'user_id = ? AND object_type = ?',
            [$user->id, $type]
        );
    }

}