Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 15... Línea 15...
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
17
/**
17
/**
18
 * First step page for creating a new badge
18
 * First step page for creating a new badge
19
 *
19
 *
20
 * @package    core
-
 
21
 * @subpackage badges
20
 * @package    core_badges
22
 * @copyright  2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
21
 * @copyright  2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
23
 * @author     Yuliya Bozhko <yuliya.bozhko@totaralms.com>
-
 
24
 * @deprecated since 4.5. Use badges/edit.php instead.
24
 * @author     Yuliya Bozhko <yuliya.bozhko@totaralms.com>
25
 * @todo       MDL-82383 This file will be deleted in Moodle 6.0.
Línea 25... Línea 26...
25
 */
26
 */
26
 
-
 
Línea 27... Línea -...
27
require_once(__DIR__ . '/../config.php');
-
 
28
require_once($CFG->libdir . '/badgeslib.php');
27
 
Línea 29... Línea 28...
29
 
28
require_once(__DIR__ . '/../config.php');
Línea 30... Línea -...
30
$type = required_param('type', PARAM_INT);
-
 
31
$courseid = optional_param('id', 0, PARAM_INT);
-
 
32
 
-
 
33
require_login();
-
 
34
 
-
 
35
if (empty($CFG->enablebadges)) {
-
 
36
    throw new \moodle_exception('badgesdisabled', 'badges');
-
 
37
}
-
 
38
 
-
 
39
if (empty($CFG->badges_allowcoursebadges) && ($type == BADGE_TYPE_COURSE)) {
-
 
40
    throw new \moodle_exception('coursebadgesdisabled', 'badges');
-
 
41
}
-
 
42
 
-
 
43
$title = get_string('create', 'badges');
-
 
44
$PAGE->add_body_class('limitedwidth');
-
 
45
 
-
 
46
if (($type == BADGE_TYPE_COURSE) && ($course = $DB->get_record('course', array('id' => $courseid)))) {
-
 
47
    require_login($course);
-
 
48
    $coursecontext = context_course::instance($course->id);
-
 
49
    $PAGE->set_context($coursecontext);
-
 
50
    $PAGE->set_pagelayout('incourse');
-
 
51
    $PAGE->set_url('/badges/newbadge.php', array('type' => $type, 'id' => $course->id));
-
 
52
    $heading = format_string($course->fullname, true, array('context' => $coursecontext)) . ": " . $title;
-
 
53
    $PAGE->set_heading($heading);
-
 
54
    $PAGE->set_title($heading);
-
 
55
} else {
-
 
56
    $PAGE->set_context(context_system::instance());
-
 
57
    $PAGE->set_pagelayout('admin');
-
 
58
    $PAGE->set_url('/badges/newbadge.php', array('type' => $type));
-
 
59
    $PAGE->set_heading($title);
-
 
60
    $PAGE->set_title($title);
-
 
61
}
-
 
62
 
-
 
63
require_capability('moodle/badges:createbadge', $PAGE->context);
-
 
64
 
-
 
65
$fordb = new stdClass();
-
 
66
$fordb->id = null;
29
 
67
 
-
 
68
$form = new \core_badges\form\badge($PAGE->url, array('action' => 'new'));
-
 
69
 
-
 
70
if ($form->is_cancelled()) {
-
 
71
    redirect(new moodle_url('/badges/index.php', array('type' => $type, 'id' => $courseid)));
-
 
72
} else if ($data = $form->get_data()) {
-
 
73
    // Creating new badge here.
-
 
74
    $now = time();
-
 
75
 
-
 
76
    $fordb->name = $data->name;
-
 
77
    $fordb->version = $data->version;
-
 
78
    $fordb->language = $data->language;
-
 
79
    $fordb->description = $data->description;
-
 
80
    $fordb->imageauthorname = $data->imageauthorname;
-
 
81
    $fordb->imageauthoremail = $data->imageauthoremail;
-
 
82
    $fordb->imageauthorurl = $data->imageauthorurl;
-
 
83
    $fordb->imagecaption = $data->imagecaption;
-
 
84
    $fordb->timecreated = $now;
-
 
85
    $fordb->timemodified = $now;
-
 
86
    $fordb->usercreated = $USER->id;
-
 
87
    $fordb->usermodified = $USER->id;
-
 
88
 
-
 
89
    if (badges_open_badges_backpack_api() == OPEN_BADGES_V1) {
-
 
90
        $fordb->issuername = $data->issuername;
-
 
91
        $fordb->issuerurl = $data->issuerurl;
-
 
92
        $fordb->issuercontact = $data->issuercontact;
-
 
93
    } else {
-
 
94
        $url = parse_url($CFG->wwwroot);
-
 
95
        $fordb->issuerurl = $url['scheme'] . '://' . $url['host'];
-
 
96
        $fordb->issuername = $CFG->badges_defaultissuername;
-
 
97
        $fordb->issuercontact = $CFG->badges_defaultissuercontact;
-
 
98
    }
-
 
99
 
30
$courseid = optional_param('id', 0, PARAM_INT);
100
    $fordb->expiredate = ($data->expiry == 1) ? $data->expiredate : null;
-
 
101
    $fordb->expireperiod = ($data->expiry == 2) ? $data->expireperiod : null;
-
 
102
    $fordb->type = $type;
-
 
103
    $fordb->courseid = ($type == BADGE_TYPE_COURSE) ? $courseid : null;
-
 
104
    $fordb->messagesubject = get_string('messagesubject', 'badges');
-
 
105
    $fordb->message = get_string('messagebody', 'badges',
-
 
106
            html_writer::link($CFG->wwwroot . '/badges/mybadges.php', get_string('managebadges', 'badges')));
-
 
107
    $fordb->attachment = 1;
-
 
108
    $fordb->notification = BADGE_MESSAGE_NEVER;
-
 
109
    $fordb->status = BADGE_STATUS_INACTIVE;
-
 
110
 
-
 
111
    $newid = $DB->insert_record('badge', $fordb, true);
-
 
112
 
-
 
113
    // Trigger event, badge created.
-
 
114
    $eventparams = array('objectid' => $newid, 'context' => $PAGE->context);
-
 
115
    $event = \core\event\badge_created::create($eventparams);
-
 
116
    $event->trigger();
-
 
117
 
-
 
118
    $newbadge = new badge($newid);
-
 
119
    core_tag_tag::set_item_tags('core_badges', 'badge', $newid, $PAGE->context, $data->tags);
-
 
120
    badges_process_badge_image($newbadge, $form->save_temp_file('image'));
-
 
121
    // If a user can configure badge criteria, they will be redirected to the criteria page.
-
 
122
    if (has_capability('moodle/badges:configurecriteria', $PAGE->context)) {
-
 
123
        redirect(new moodle_url('/badges/criteria.php', array('id' => $newid)));
-
 
124
    }
-
 
125
    redirect(new moodle_url('/badges/overview.php', array('id' => $newid)));
-
 
126
}
-
 
127
 
-
 
128
echo $OUTPUT->header();
-