aboutsummaryrefslogtreecommitdiff
path: root/lib/models/WikiPageConfig.php
blob: 722356d8af6f32e7769f336d609c26d7cff03df7 (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
<?php
/**
 * WikiPageConfig.php - Wiki page permissions
 *
 * 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      Elmar Ludwig
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 */
class WikiPageConfig extends SimpleORMap
{
    /**
     * Configure the database mapping.
     */
    protected static function configure($config = [])
    {
        $config['db_table'] = 'wiki_page_config';

        $config['belongs_to']['course'] = [
            'class_name'  => Course::class,
            'foreign_key' => 'range_id',
        ];
        $config['belongs_to']['institute'] = [
            'class_name'  => Institute::class,
            'foreign_key' => 'range_id',
        ];

        parent::configure($config);
    }

    /**
     * Specialized getValue that returns the course default for edit_restricted.
     *
     * @param  string $field Field to get the value for
     * @return mixed
     */
    public function getValue($field)
    {
        if ($field !== 'edit_restricted' || !$this->isNew() || !$this->range_id) {
            return parent::getValue($field);
        }

        return CourseConfig::get($this->range_id)->WIKI_COURSE_EDIT_RESTRICTED;
    }

    /**
     * Returns whether the current settings are the default settings (db-wise
     * and from course setting).
     *
     * @return boolean
     */
    public function isDefault()
    {
        return $this->read_restricted === $this->getDefaultValue('read_restricted') &&
               $this->edit_restricted === CourseConfig::get($this->range_id)->WIKI_COURSE_EDIT_RESTRICTED;
    }
}