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' => get_config('tool_lp', 'pushcourseratingstouserplans')
60 * Get a the course settings for a single course.
62 * @param int $courseid The course id
63 * @return course_competency_settings
65 public static function get_by_courseid($courseid) {
69 'courseid' => $courseid
72 $settings = new static(null, (object) $params);
73 if ($record = $DB->get_record(self::TABLE, $params)) {
74 $settings->from_record($record);
81 * Can the current user view competency settings for this course.
83 * @param int $data The course ID.
86 public static function can_read($courseid) {
87 $context = context_course::instance($courseid);
89 $capabilities = array('tool/lp:coursecompetencyview');
91 return has_any_capability($capabilities, $context);
95 * Can the current user change competency settings for this course.
97 * @param int $data The course ID.
100 public static function can_manage_course($courseid) {
101 $context = context_course::instance($courseid);
103 $capabilities = array('tool/lp:coursecompetencyconfigure');
105 return has_any_capability($capabilities, $context);
109 * Can the current user change competency settings for this course.
113 public function can_manage() {
114 return static::can_manage_course($this->get_courseid());
118 * Validate course ID.
120 * @param int $data The course ID.
121 * @return true|lang_string
123 protected function validate_courseid($data) {
125 if (!$DB->record_exists('course', array('id' => $data))) {
126 return new lang_string('invalidcourseid', 'error');
134 * @return context The context
136 public function get_context() {
137 return context_course::instance($this->get_courseid());