aboutsummaryrefslogtreecommitdiff
path: root/lib/models/resources/ResourceCategoryProperty.class.php
blob: f52e5cdc6795e76e13c7648c28d3fa5f5734e451 (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

/**
 * ResourceCategoryProperty.class.php - model class for
 * resource category properties
 *
 * 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      Moritz Strohm <strohm@data-quest.de>
 * @copyright   2017-2019
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category    Stud.IP
 * @package     resources
 * @since       4.5
 *
 * @property string category_id database column
 * @property string property_id database column
 * @property string requestable database column
 * @property string protected database column
 * @property string system database column
 * @property string form_text database column
 * @property string mkdate database column
 * @property string chdate database column
 */


class ResourceCategoryProperty extends SimpleORMap
{
    protected static function configure($config = [])
    {
        $config['db_table'] = 'resource_category_properties';

        $config['belongs_to']['category'] = [
            'class_name' => 'ResourceCategory',
            'foreign_key' => 'category_id',
            'assoc_func' => 'find'
        ];

        $config['belongs_to']['definition'] = [
            'class_name' => 'ResourcePropertyDefinition',
            'foreign_key' => 'property_id',
            'assoc_func' => 'find'
        ];

        $config['additional_fields']['name'] = ['definition', 'name'];
        $config['additional_fields']['type'] = ['definition', 'type'];

        parent::configure($config);
    }

    public static function findByNameAndCategoryId($name, $category_id)
    {
        return self::findOneBySql(
            'INNER JOIN resource_property_definitions rpd
            USING (property_id)
            WHERE
            rpd.name = :name
            AND
            resource_category_properties.category_id = :category_id',
            [
                'name' => $name,
                'category_id' => $category_id
            ]
        );
    }
}