2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Class for course_competency_settings persistence.
21 * @copyright 2016 Damyon Wiese
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 defined('MOODLE_INTERNAL') || die();
32 * Class for course_competency_settings persistence.
34 * @copyright 2016 Damyon Wiese
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class course_competency_settings extends persistent {
39 /** Table name for plan_competency persistency */
40 const TABLE = 'tool_lp_coursecompsettings';
43 * Return the definition of the properties of this model.
47 protected static function define_properties() {
52 'pushratingstouserplans' => array(
54 'default' => function() {
55 return get_config('tool_lp', 'pushcourseratingstouserplans');
62 * Get a the course settings for a single course.
64 * @param int $courseid The course id
65 * @return course_competency_settings
67 public static function get_by_courseid($courseid) {
71 'courseid' => $courseid
74 $settings = new static(null, (object) $params);
75 if ($record = $DB->get_record(self::TABLE, $params)) {
76 $settings->from_record($record);
83 * Can the current user view competency settings for this course.
85 * @param int $data The course ID.
88 public static function can_read($courseid) {
89 $context = context_course::instance($courseid);
91 $capabilities = array('tool/lp:coursecompetencyview');
93 return has_any_capability($capabilities, $context);
97 * Can the current user change competency settings for this course.
99 * @param int $data The course ID.
102 public static function can_manage_course($courseid) {
103 $context = context_course::instance($courseid);
105 $capabilities = array('tool/lp:coursecompetencyconfigure');
107 return has_any_capability($capabilities, $context);
111 * Can the current user change competency settings for this course.
115 public function can_manage() {
116 return static::can_manage_course($this->get_courseid());
120 * Validate course ID.
122 * @param int $data The course ID.
123 * @return true|lang_string
125 protected function validate_courseid($data) {
127 if (!$DB->record_exists('course', array('id' => $data))) {
128 return new lang_string('invalidcourseid', 'error');
136 * @return context The context
138 public function get_context() {
139 return context_course::instance($this->get_courseid());