aboutsummaryrefslogtreecommitdiff
path: root/lib/models/NewsRange.class.php
blob: b13f0cc19e8448c8ead8dafdafcf8975caa40d05 (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
<?php
/**
 * NewsRange.class.php - model class for table Institute
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * @author      André Noack <noack@data-quest.de>
 * @copyright   2012 Stud.IP Core-Group
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category    Stud.IP
 *
 * @property string news_id database column
 * @property string range_id database column
 * @property string type computed column
 * @property string name computed column
 * @property string id computed column read/write
 * @property User user belongs_to User
 * @property Course course belongs_to Course
 * @property Institute institute belongs_to Institute
 */
class NewsRange extends SimpleORMap
{
    protected static function configure($config = [])
    {
        $config['db_table'] = 'news_range';
        $config['belongs_to']['user'] = [
            'class_name' => User::class,
            'foreign_key' => 'range_id',
        ];
        $config['belongs_to']['course'] = [
            'class_name' => Course::class,
            'foreign_key' => 'range_id',
        ];
        $config['belongs_to']['institute'] = [
            'class_name' => Institute::class,
            'foreign_key' => 'range_id',
        ];
        $config['additional_fields']['type'] = true;
        $config['additional_fields']['name'] = true;
        parent::configure($config);
    }

    function getType()
    {
        return get_object_type($this->range_id, ['sem','inst','user']);
    }

    function getName()
    {
        switch ($this->type) {
            case 'global':
                return _('Stud.IP-Startseite');
                break;
            case 'sem':
                return $this->course->name;
                break;
            case 'user':
                return $this->user->getFullname();
                break;
            case 'inst':
            case 'fak':
                return $this->institute->name;
                break;
            }
    }
}