Skip to content

Commit

Permalink
MDL-63876 badges: Remove invalid table from badges
Browse files Browse the repository at this point in the history
  • Loading branch information
Damyon Wiese committed Mar 29, 2019
1 parent 0920f35 commit e8bfd9b
Show file tree
Hide file tree
Showing 18 changed files with 206 additions and 183 deletions.
18 changes: 9 additions & 9 deletions badges/competency.php → badges/alignment.php
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* List competencies, skills, or standards are targeted by a BadgeClass.
* List alignments, skills, or standards are targeted by a BadgeClass.
*
* @package core
* @subpackage badges
Expand All @@ -24,7 +24,7 @@
*/
require_once(__DIR__ . '/../config.php');
require_once($CFG->libdir . '/badgeslib.php');
require_once($CFG->dirroot . '/badges/competency_form.php');
require_once($CFG->dirroot . '/badges/alignment_form.php');

$badgeid = required_param('id', PARAM_INT);
$alignmentid = optional_param('alignmentid', 0, PARAM_INT);
Expand Down Expand Up @@ -53,7 +53,7 @@
navigation_node::override_active_url($navurl, true);
}

$currenturl = new moodle_url('/badges/competency.php', array('id' => $badge->id));
$currenturl = new moodle_url('/badges/alignment.php', array('id' => $badge->id));
$PAGE->set_context($context);
$PAGE->set_url($currenturl);
$PAGE->set_heading($badge->name);
Expand All @@ -63,8 +63,8 @@
$output = $PAGE->get_renderer('core', 'badges');
$msg = optional_param('msg', '', PARAM_TEXT);
$emsg = optional_param('emsg', '', PARAM_TEXT);
$url = new moodle_url('/badges/competency.php', array('id' => $badge->id, 'action' => $action, 'alignmentid' => $alignmentid));
$mform = new competency_alignment_form($url, array('badge' => $badge, 'action' => $action, 'alignmentid' => $alignmentid));
$url = new moodle_url('/badges/alignment.php', array('id' => $badge->id, 'action' => $action, 'alignmentid' => $alignmentid));
$mform = new alignment_form($url, array('badge' => $badge, 'action' => $action, 'alignmentid' => $alignmentid));
if ($mform->is_cancelled()) {
redirect($currenturl);
} else if ($mform->is_submitted() && $mform->is_validated() && ($data = $mform->get_data())) {
Expand Down Expand Up @@ -94,12 +94,12 @@
$mform->display();
} else if (empty($action)) {
if (!$badge->is_active() && !$badge->is_locked()) {
$urlbutton = new moodle_url('/badges/competency.php', array('id' => $badge->id, 'action' => 'add'));
$urlbutton = new moodle_url('/badges/alignment.php', array('id' => $badge->id, 'action' => 'add'));
echo $OUTPUT->box($OUTPUT->single_button($urlbutton, get_string('addalignment', 'badges')), 'clearfix mdl-align');
}
$alignment = $badge->get_alignment();
if (count($alignment) > 0) {
$renderrelated = new badge_competencies_alignment($alignment, $badgeid);
$alignments = $badge->get_alignments();
if (count($alignments) > 0) {
$renderrelated = new badge_alignments($alignments, $badgeid);
echo $output->render($renderrelated);
} else {
echo $output->notification(get_string('noalignment', 'badges'));
Expand Down
6 changes: 3 additions & 3 deletions badges/competency_action.php → badges/alignment_action.php
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Processing actions with competencies alignment.
* Processing actions with alignments.
*
* @package core
* @subpackage badges
Expand All @@ -30,12 +30,12 @@
$action = optional_param('action', 'remove', PARAM_TEXT); // Remove.

require_login();
$return = new moodle_url('/badges/competency.php', array('id' => $badgeid));
$return = new moodle_url('/badges/alignment.php', array('id' => $badgeid));
$badge = new badge($badgeid);
$context = $badge->get_context();
require_capability('moodle/badges:configuredetails', $context);

if ($action == 'remove') {
$badge->delete_alignment($alignmentid);
}
redirect($return);
redirect($return);
10 changes: 5 additions & 5 deletions badges/competency_form.php → badges/alignment_form.php
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Form competency for editing.
* Form alignment for editing.
*
* @package core
* @subpackage badges
Expand All @@ -27,13 +27,13 @@
require_once($CFG->libdir . '/badgeslib.php');

/**
* Form to edit competency alignment.
* Form to edit alignment.
*
* @copyright 2018 Tung Thai
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
*/
class competency_alignment_form extends moodleform {
class alignment_form extends moodleform {

/**
* Defines the form.
Expand Down Expand Up @@ -68,7 +68,7 @@ public function definition() {
$this->add_action_buttons();
if ($action == 'edit' || $alignmentid) {
$alignment = new stdClass();
$alignment = $DB->get_record_select('badge_competencies', 'id = ?', array($alignmentid));
$alignment = $DB->get_record_select('badge_alignment', 'id = ?', array($alignmentid));
$this->set_data($alignment);
// Freeze all elements if badge is active or locked.
if ($badge->is_active() || $badge->is_locked()) {
Expand All @@ -91,4 +91,4 @@ public function validation($data, $files) {
}
return $errors;
}
}
}
8 changes: 4 additions & 4 deletions badges/badge_json.php
Expand Up @@ -95,9 +95,9 @@
$json['endorsement'] = $endorsementurl->out(false);
}

$competencies = $badge->get_alignment();
if (!empty($competencies)) {
foreach ($competencies as $item) {
$alignments = $badge->get_alignments();
if (!empty($alignments)) {
foreach ($alignments as $item) {
$alignment = array('targetName' => $item->targetname, 'targetUrl' => $item->targeturl);
if ($item->targetdescription) {
$alignment['targetDescription'] = $item->targetdescription;
Expand All @@ -123,4 +123,4 @@
$json['error'] = get_string('error:relatedbadgedoesntexist', 'badges');
}
echo $OUTPUT->header();
echo json_encode($json);
echo json_encode($json);
12 changes: 6 additions & 6 deletions badges/classes/assertion.php
Expand Up @@ -223,15 +223,15 @@ public function get_criteria_badge_class() {
}

/**
* Get competencies alignment of the badge.
* Get alignment of the badge.
*
* @return array competencies information.
* @return array information.
*/
public function get_competencies_alignment() {
public function get_alignments() {
global $DB;
$badgeid = $this->_data->id;
$alignments = array();
$items = $DB->get_records_select('badge_competencies', 'badgeid = ?', array($badgeid));
$items = $DB->get_records_select('badge_alignment', 'badgeid = ?', array($badgeid));
foreach ($items as $item) {
$alignment = array('targetName' => $item->targetname, 'targetUrl' => $item->targeturl);
if ($item->targetdescription) {
Expand Down Expand Up @@ -301,8 +301,8 @@ protected function embed_data_badge_version2 (&$json, $type = OPEN_BADGES_V2_TYP
$endorsementurl = new moodle_url('/badges/endorsement_json.php', array('id' => $this->_data->id));
$json['endorsement'] = $endorsementurl->out(false);
}
if ($competencies = $this->get_competencies_alignment()) {
$json['alignment'] = $competencies;
if ($alignments = $this->get_alignments()) {
$json['alignment'] = $alignments;
}
if ($this->_data->imageauthorname ||
$this->_data->imageauthoremail ||
Expand Down
14 changes: 7 additions & 7 deletions badges/classes/external.php
Expand Up @@ -150,17 +150,17 @@ public static function get_user_badges($userid = 0, $courseid = 0, $page = 0, $p
// Create a badge instance to be able to get the endorsement and other info.
$badgeinstance = new badge($badge->id);
$endorsement = $badgeinstance->get_endorsement();
$competencies = $badgeinstance->get_alignment();
$alignments = $badgeinstance->get_alignments();
$relatedbadges = $badgeinstance->get_related_badges();

if (!$canconfiguredetails) {
// Return only the properties visible by the user.

if (!empty($competencies)) {
foreach ($competencies as $competency) {
unset($competency->targetdescription);
unset($competency->targetframework);
unset($competency->targetcode);
if (!empty($alignments)) {
foreach ($alignments as $alignment) {
unset($alignment->targetdescription);
unset($alignment->targetframework);
unset($alignment->targetcode);
}
}

Expand All @@ -176,7 +176,7 @@ public static function get_user_badges($userid = 0, $courseid = 0, $page = 0, $p
$related = array(
'context' => $context,
'endorsement' => $endorsement ? $endorsement : null,
'competencies' => $competencies,
'alignments' => $alignments,
'relatedbadges' => $relatedbadges,
);

Expand Down
Expand Up @@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Contains competency class for displaying a badge competency.
* Contains alignment class for displaying a badge alignment.
*
* @package core_badges
* @copyright 2018 Dani Palou <dani@moodle.com>
Expand All @@ -29,13 +29,13 @@
use core\external\exporter;

/**
* Class for displaying a badge competency.
* Class for displaying a badge alignment.
*
* @package core_badges
* @copyright 2018 Dani Palou <dani@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class competency_exporter extends exporter {
class alignment_exporter extends exporter {

/**
* Return the list of properties.
Expand All @@ -46,7 +46,7 @@ protected static function define_properties() {
return [
'id' => [
'type' => PARAM_INT,
'description' => 'Competency id',
'description' => 'Alignment id',
],
'badgeid' => [
'type' => PARAM_INT,
Expand Down
22 changes: 11 additions & 11 deletions badges/classes/external/user_badge_exporter.php
Expand Up @@ -30,7 +30,7 @@
use renderer_base;
use moodle_url;
use core_badges\external\endorsement_exporter;
use core_badges\external\competency_exporter;
use core_badges\external\alignment_exporter;
use core_badges\external\related_info_exporter;

/**
Expand Down Expand Up @@ -234,7 +234,7 @@ protected static function define_related() {
return array(
'context' => 'context',
'endorsement' => 'stdClass?',
'competencies' => 'stdClass[]',
'alignments' => 'stdClass[]',
'relatedbadges' => 'stdClass[]',
);
}
Expand All @@ -255,9 +255,9 @@ protected static function define_other_properties() {
'description' => 'Badge endorsement',
'optional' => true,
],
'competencies' => [
'type' => competency_exporter::read_properties_definition(),
'description' => 'Badge competencies (alignment)',
'alignments' => [
'type' => alignment_exporter::read_properties_definition(),
'description' => 'Badge alignments',
'multiple' => true,
],
'relatedbadges' => [
Expand All @@ -277,13 +277,13 @@ protected static function define_other_properties() {
protected function get_other_values(renderer_base $output) {
$context = $this->related['context'];
$endorsement = $this->related['endorsement'];
$competencies = $this->related['competencies'];
$alignments = $this->related['alignments'];
$relatedbadges = $this->related['relatedbadges'];

$values = array(
'badgeurl' => moodle_url::make_webservice_pluginfile_url($context->id, 'badges', 'badgeimage', $this->data->id, '/',
'f1')->out(false),
'competencies' => array(),
'alignments' => array(),
'relatedbadges' => array(),
);

Expand All @@ -292,10 +292,10 @@ protected function get_other_values(renderer_base $output) {
$values['endorsement'] = $endorsementexporter->export($output);
}

if (!empty($competencies)) {
foreach ($competencies as $competency) {
$competencyexporter = new competency_exporter($competency, array('context' => $context));
$values['competencies'][] = $competencyexporter->export($output);
if (!empty($alignments)) {
foreach ($alignments as $alignment) {
$alignmentexporter = new alignment_exporter($alignment, array('context' => $context));
$values['alignments'][] = $alignmentexporter->export($output);
}
}

Expand Down

0 comments on commit e8bfd9b

Please sign in to comment.