Merge branch 'MDL-44660-master' of https://github.com/lucaboesch/moodle
[moodle.git] / completion / criteria / completion_criteria_self.php
CommitLineData
2be4d090 1<?php
2be4d090
MD
2// This file is part of Moodle - http://moodle.org/
3//
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.
8//
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.
13//
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/>.
16
17/**
18 * Course completion critieria - student self marked
19 *
836375ec
SH
20 * @package core_completion
21 * @category completion
22 * @copyright 2009 Catalyst IT Ltd
23 * @author Aaron Barnes <aaronb@catalyst.net.nz>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
26
27defined('MOODLE_INTERNAL') || die();
28
29/**
30 * Course completion critieria - student self marked
31 *
32 * @package core_completion
33 * @category completion
2be4d090 34 * @copyright 2009 Catalyst IT Ltd
836375ec
SH
35 * @author Aaron Barnes <aaronb@catalyst.net.nz>
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2be4d090
MD
37 */
38class completion_criteria_self extends completion_criteria {
39
95dd54ee 40 /* @var int Criteria type constant [COMPLETION_CRITERIA_TYPE_SELF] */
2be4d090
MD
41 public $criteriatype = COMPLETION_CRITERIA_TYPE_SELF;
42
43 /**
44 * Finds and returns a data_object instance based on params.
2be4d090
MD
45 *
46 * @param array $params associative arrays varname=>value
836375ec 47 * @return data_object data_object instance or false if none found.
2be4d090
MD
48 */
49 public static function fetch($params) {
50 $params['criteriatype'] = COMPLETION_CRITERIA_TYPE_SELF;
51 return self::fetch_helper('course_completion_criteria', __CLASS__, $params);
52 }
53
54 /**
55 * Add appropriate form elements to the critieria form
836375ec
SH
56 *
57 * @param moodleform $mform Moodle forms object
95dd54ee 58 * @param stdClass $data Form data
2be4d090
MD
59 */
60 public function config_form_display(&$mform, $data = null) {
61 $mform->addElement('checkbox', 'criteria_self', get_string('enable'));
62
63 if ($this->id ) {
64 $mform->setDefault('criteria_self', 1);
65 }
66 }
67
68 /**
69 * Update the criteria information stored in the database
836375ec
SH
70 *
71 * @param stdClass $data Form data
2be4d090
MD
72 */
73 public function update_config(&$data) {
74 if (!empty($data->criteria_self)) {
75 $this->course = $data->id;
76 $this->insert();
77 }
78 }
79
80 /**
81 * Mark this criteria as complete
836375ec
SH
82 *
83 * @param completion_completion $completion The user's completion record
2be4d090
MD
84 */
85 public function complete($completion) {
86 $this->review($completion, true, true);
87 }
88
89 /**
90 * Review this criteria and decide if the user has completed
836375ec
SH
91 *
92 * @param completion_completion $completion The user's completion record
95dd54ee
AA
93 * @param bool $mark Optionally set false to not save changes to database
94 * @param bool $is_complete set true to mark activity complete.
95 * @return bool
2be4d090
MD
96 */
97 public function review($completion, $mark = true, $is_complete = false) {
98 // If we are marking this as complete
836375ec 99 if ($is_complete && $mark) {
2be4d090
MD
100 $completion->completedself = 1;
101 $completion->mark_complete();
102
103 return true;
104 }
105
106 return $completion->is_complete();
107 }
108
109 /**
110 * Return criteria title for display in reports
836375ec
SH
111 *
112 * @return string
2be4d090
MD
113 */
114 public function get_title() {
115 return get_string('selfcompletion', 'completion');
116 }
117
118 /**
119 * Return a more detailed criteria title for display in reports
836375ec
SH
120 *
121 * @return string
2be4d090
MD
122 */
123 public function get_title_detailed() {
124 return $this->get_title();
125 }
126
127 /**
128 * Return criteria type title for display in reports
836375ec
SH
129 *
130 * @return string
2be4d090
MD
131 */
132 public function get_type_title() {
133 return get_string('self', 'completion');
134 }
135
136 /**
137 * Return criteria progress details for display in reports
836375ec
SH
138 *
139 * @param completion_completion $completion The user's completion record
140 * @return array An array with the following keys:
141 * type, criteria, requirement, status
2be4d090
MD
142 */
143 public function get_details($completion) {
144 $details = array();
145 $details['type'] = $this->get_title();
146 $details['criteria'] = $this->get_title();
147 $details['requirement'] = get_string('markingyourselfcomplete', 'completion');
148 $details['status'] = '';
149
150 return $details;
151 }
7062e7c6
CB
152
153 /**
154 * Return pix_icon for display in reports.
155 *
156 * @param string $alt The alt text to use for the icon
157 * @param array $attributes html attributes
158 * @return pix_icon
159 */
160 public function get_icon($alt, array $attributes = null) {
161 return new pix_icon('i/completion_self', $alt, 'moodle', $attributes);
162 }
95dd54ee 163}