source: moodle/trunk/fuentes/badges/criteria_settings.php @ 136

Last change on this file since 136 was 136, checked in by mabarracus, 3 years ago

Ported code to xenial

File size: 4.3 KB
Line 
1<?php
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 * Page for editing badges criteria settings.
19 *
20 * @package    core
21 * @subpackage badges
22 * @copyright  2013 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
23 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 * @author     Yuliya Bozhko <yuliya.bozhko@totaralms.com>
25 */
26
27require_once(dirname(dirname(__FILE__)) . '/config.php');
28require_once($CFG->libdir . '/badgeslib.php');
29require_once($CFG->dirroot . '/badges/criteria_form.php');
30
31$badgeid = optional_param('badgeid', 0, PARAM_INT); // Badge ID.
32$type    = optional_param('type', 0, PARAM_INT); // Criteria type.
33$edit    = optional_param('edit', 0, PARAM_INT); // Edit criteria ID.
34$crit    = optional_param('crit', 0, PARAM_INT); // Criteria ID for managing params.
35$param   = optional_param('param', '', PARAM_TEXT); // Param name for managing params.
36$goback    = optional_param('cancel', '', PARAM_TEXT);
37$addcourse = optional_param('addcourse', '', PARAM_TEXT);
38$submitcourse = optional_param('submitcourse', '', PARAM_TEXT);
39
40require_login();
41
42$return = new moodle_url('/badges/criteria.php', array('id' => $badgeid));
43$badge = new badge($badgeid);
44$context = $badge->get_context();
45$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type));
46
47require_capability('moodle/badges:configurecriteria', $context);
48
49if (!empty($goback)) {
50    redirect($return);
51}
52
53// Make sure that no actions available for locked or active badges.
54if ($badge->is_active() || $badge->is_locked()) {
55    redirect($return);
56}
57
58if ($badge->type == BADGE_TYPE_COURSE) {
59    require_login($badge->courseid);
60    $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
61    $PAGE->set_pagelayout('standard');
62    navigation_node::override_active_url($navurl);
63} else {
64    $PAGE->set_pagelayout('admin');
65    navigation_node::override_active_url($navurl, true);
66}
67
68$PAGE->set_context($context);
69$PAGE->set_url('/badges/criteria_settings.php');
70$PAGE->set_heading($badge->name);
71$PAGE->set_title($badge->name);
72$PAGE->navbar->add($badge->name, new moodle_url('overview.php', array('id' => $badge->id)))->add(get_string('criteria_' . $type, 'badges'));
73
74$cparams = array('criteriatype' => $type, 'badgeid' => $badge->id);
75if ($edit) {
76    $criteria = $badge->criteria[$type];
77    $msg = 'criteriaupdated';
78} else {
79    $criteria = award_criteria::build($cparams);
80    $msg = 'criteriacreated';
81}
82
83$mform = new edit_criteria_form($FULLME, array('criteria' => $criteria, 'addcourse' => $addcourse, 'course' => $badge->courseid));
84
85if (!empty($addcourse)) {
86    if ($data = $mform->get_data()) {
87        // If no criteria yet, add overall aggregation.
88        if (count($badge->criteria) == 0) {
89            $criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $badge->id));
90            $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ALL));
91        }
92
93        $id = $criteria->add_courses($data->courses);
94        redirect(new moodle_url('/badges/criteria_settings.php',
95            array('badgeid' => $badgeid, 'edit' => true, 'type' => BADGE_CRITERIA_TYPE_COURSESET, 'crit' => $id)));
96    }
97} else if ($data = $mform->get_data()) {
98    // If no criteria yet, add overall aggregation.
99    if (count($badge->criteria) == 0) {
100        $criteria_overall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $badge->id));
101        $criteria_overall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ALL));
102    }
103    $criteria->save($data);
104    $return->param('msg', $msg);
105    redirect($return);
106}
107
108echo $OUTPUT->header();
109$mform->display();
110echo $OUTPUT->footer();
Note: See TracBrowser for help on using the repository browser.