[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 * Form class for mybackpack.php 19 * 20 * @package core 21 * @subpackage badges 22 * @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 24 * @author Yuliya Bozhko <yuliya.bozhko@totaralms.com> 25 */ 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 require_once($CFG->libdir . '/formslib.php'); 30 require_once($CFG->libdir . '/badgeslib.php'); 31 32 /** 33 * Form to edit backpack initial details. 34 * 35 */ 36 class edit_backpack_form extends moodleform { 37 38 /** 39 * Defines the form 40 */ 41 public function definition() { 42 global $USER, $PAGE, $OUTPUT; 43 $mform = $this->_form; 44 45 $mform->addElement('html', html_writer::tag('span', '', array('class' => 'notconnected', 'id' => 'connection-error'))); 46 $mform->addElement('header', 'backpackheader', get_string('backpackconnection', 'badges')); 47 $mform->addHelpButton('backpackheader', 'backpackconnection', 'badges'); 48 $mform->addElement('static', 'url', get_string('url'), BADGE_BACKPACKURL); 49 $status = html_writer::tag('span', get_string('notconnected', 'badges'), 50 array('class' => 'notconnected', 'id' => 'connection-status')); 51 $mform->addElement('static', 'status', get_string('status'), $status); 52 53 $nojs = html_writer::tag('noscript', get_string('error:personaneedsjs', 'badges'), 54 array('class' => 'notconnected')); 55 $personadiv = $OUTPUT->container($nojs, null, 'persona-container'); 56 57 $mform->addElement('static', 'persona', '', $personadiv); 58 $mform->addHelpButton('persona', 'personaconnection', 'badges'); 59 60 $PAGE->requires->js(new moodle_url('https://login.persona.org/include.js')); 61 $PAGE->requires->js('/badges/backpack.js'); 62 $PAGE->requires->js_init_call('badges_init_persona_login_button', null, false); 63 $PAGE->requires->strings_for_js(array('error:backpackloginfailed', 'signinwithyouremail', 64 'error:noassertion', 'error:connectionunknownreason', 'error:badjson', 'connecting', 65 'notconnected'), 'badges'); 66 67 $mform->addElement('hidden', 'userid', $USER->id); 68 $mform->setType('userid', PARAM_INT); 69 70 $mform->addElement('hidden', 'backpackurl', BADGE_BACKPACKURL); 71 $mform->setType('backpackurl', PARAM_URL); 72 73 } 74 75 /** 76 * Validates form data 77 */ 78 public function validation($data, $files) { 79 global $DB; 80 $errors = parent::validation($data, $files); 81 82 $check = new stdClass(); 83 $check->backpackurl = $data['backpackurl']; 84 $check->email = $data['email']; 85 86 $bp = new OpenBadgesBackpackHandler($check); 87 $request = $bp->curl_request('user'); 88 if (isset($request->status) && $request->status == 'missing') { 89 $errors['email'] = get_string('error:nosuchuser', 'badges'); 90 } 91 return $errors; 92 } 93 } 94 95 /** 96 * Form to select backpack collections. 97 * 98 */ 99 class edit_collections_form extends moodleform { 100 101 /** 102 * Defines the form 103 */ 104 public function definition() { 105 global $USER; 106 $mform = $this->_form; 107 $email = $this->_customdata['email']; 108 $bid = $this->_customdata['backpackid']; 109 $selected = $this->_customdata['selected']; 110 111 if (isset($this->_customdata['groups'])) { 112 $groups = $this->_customdata['groups']; 113 $nogroups = null; 114 } else { 115 $groups = null; 116 $nogroups = $this->_customdata['nogroups']; 117 } 118 119 $mform->addElement('header', 'backpackheader', get_string('backpackconnection', 'badges')); 120 $mform->addHelpButton('backpackheader', 'backpackconnection', 'badges'); 121 $mform->addElement('static', 'url', get_string('url'), BADGE_BACKPACKURL); 122 123 $status = html_writer::tag('span', get_string('connected', 'badges'), array('class' => 'connected')); 124 $mform->addElement('static', 'status', get_string('status'), $status); 125 $mform->addElement('static', 'email', get_string('email'), $email); 126 $mform->addHelpButton('email', 'backpackemail', 'badges'); 127 $mform->addElement('submit', 'disconnect', get_string('disconnect', 'badges')); 128 129 $mform->addElement('header', 'collectionheader', get_string('backpackimport', 'badges')); 130 $mform->addHelpButton('collectionheader', 'backpackimport', 'badges'); 131 132 if (!empty($groups)) { 133 $mform->addElement('static', 'selectgroup', '', get_string('selectgroup_start', 'badges')); 134 foreach ($groups as $group) { 135 $name = $group->name . ' (' . $group->badges . ')'; 136 $mform->addElement('advcheckbox', 'group[' . $group->groupId . ']', null, $name, array('group' => 1), array(false, $group->groupId)); 137 if (in_array($group->groupId, $selected)) { 138 $mform->setDefault('group[' . $group->groupId . ']', $group->groupId); 139 } 140 } 141 $mform->addElement('static', 'selectgroup', '', get_string('selectgroup_end', 'badges')); 142 } else { 143 $mform->addElement('static', 'selectgroup', '', $nogroups); 144 } 145 146 $mform->addElement('hidden', 'backpackid', $bid); 147 $mform->setType('backpackid', PARAM_INT); 148 149 $this->add_action_buttons(); 150 } 151 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |