1
0
mirror of https://github.com/moodle/moodle.git synced 2025-04-17 14:35:29 +02:00

MDL-49543 badges: Fix format_text and description layout

Signed-off-by: Yuliya <yuliya.bozhko@gmail.com>
This commit is contained in:
Yuliya 2015-03-20 21:21:35 +13:00
parent 3784d3be98
commit 0b6ba27a04
6 changed files with 65 additions and 19 deletions

@ -247,7 +247,11 @@ abstract class award_criteria {
echo $OUTPUT->heading($this->get_title() . $OUTPUT->help_icon('criteria_' . $this->criteriatype, 'badges'), 3, 'main help');
if (!empty($this->description)) {
echo $OUTPUT->box(clean_text($this->description, FORMAT_HTML), array('criteria-description'));
$badge = new badge($this->badgeid);
echo $OUTPUT->box(
format_text($this->description, FORMAT_HTML, array('context' => $badge->get_context())),
'criteria-description'
);
}
if (!empty($this->params)) {

@ -76,7 +76,10 @@ class award_criteria_course extends award_criteria {
echo $OUTPUT->heading($this->get_title() . $OUTPUT->help_icon('criteria_' . $this->criteriatype, 'badges'), 3, 'main help');
if (!empty($this->description)) {
echo $OUTPUT->box(clean_text($this->description, FORMAT_HTML), array('criteria-description'));
echo $OUTPUT->box(
format_text($this->description, FORMAT_HTML, array('context' => context_course::instance($this->courseid))),
'criteria-description'
);
}
if (!empty($this->params)) {

@ -46,7 +46,10 @@ class award_criteria_overall extends award_criteria {
if (count($data->criteria) > 2) {
echo $OUTPUT->box_start();
if (!empty($this->description)) {
echo $OUTPUT->box(clean_text($this->description, FORMAT_HTML), array('criteria-description'));
$badge = new badge($this->badgeid);
echo $OUTPUT->box(
format_text($this->description, FORMAT_HTML, array('context' => $badge->get_context())),
'criteria-description');
}
echo $OUTPUT->heading($this->get_title(), 2);

@ -712,42 +712,73 @@ class core_badges_renderer extends plugin_renderer_base {
* @return string $output HTML string to output
*/
public function print_badge_criteria(badge $badge, $short = '') {
$output = "";
$agg = $badge->get_aggregation_methods();
if (empty($badge->criteria)) {
return get_string('nocriteria', 'badges');
}
$overalldescr = '';
if (!$short) {
$overall = $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL];
$overalldescr .= $this->output->box(clean_text($overall->description, FORMAT_HTML));
$overall = $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL];
if (!$short && !empty($overall->description)) {
$overalldescr = $this->output->box(
format_text($overall->description, FORMAT_HTML, array('context' => $badge->get_context())),
'criteria-description'
);
}
// Get the condition string.
if (count($badge->criteria) == 2) {
$condition = '';
if (!$short) {
$output .= $overalldescr . get_string('criteria_descr', 'badges');
$condition = get_string('criteria_descr', 'badges');
}
} else {
$output .= $overalldescr . get_string('criteria_descr_' . $short . BADGE_CRITERIA_TYPE_OVERALL, 'badges',
$condition = get_string('criteria_descr_' . $short . BADGE_CRITERIA_TYPE_OVERALL, 'badges',
core_text::strtoupper($agg[$badge->get_aggregation_method()]));
}
$items = array();
unset($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]);
foreach ($badge->criteria as $type => $c) {
$criteriadescr = '';
if (!$short) {
$criteriadescr = $this->output->box(clean_text($c->description, FORMAT_HTML));
$items = array();
// If only one criterion left, make sure its description goe to the top.
if (count($badge->criteria) == 1) {
$c = reset($badge->criteria);
if (!$short && !empty($c->description)) {
$overalldescr = $this->output->box(
format_text($c->description, FORMAT_HTML, array('context' => $badge->get_context())),
'criteria-description'
);
}
if (count($c->params) == 1) {
$items[] = $criteriadescr . get_string('criteria_descr_single_' . $short . $type , 'badges') .
$items[] = get_string('criteria_descr_single_' . $short . $c->criteriatype , 'badges') .
$c->get_details($short);
} else {
$items[] = $criteriadescr . get_string('criteria_descr_' . $short . $type , 'badges',
core_text::strtoupper($agg[$badge->get_aggregation_method($type)])) . $c->get_details($short);
$items[] = get_string('criteria_descr_' . $short . $c->criteriatype, 'badges',
core_text::strtoupper($agg[$badge->get_aggregation_method($c->criteriatype)])) .
$c->get_details($short);
}
} else {
foreach ($badge->criteria as $type => $c) {
$criteriadescr = '';
if (!$short && !empty($c->description)) {
$criteriadescr = $this->output->box(
format_text($c->description, FORMAT_HTML, array('context' => $badge->get_context())),
'criteria-description'
);
}
if (count($c->params) == 1) {
$items[] = get_string('criteria_descr_single_' . $short . $type , 'badges') .
$c->get_details($short) . $criteriadescr;
} else {
$items[] = get_string('criteria_descr_' . $short . $type , 'badges',
core_text::strtoupper($agg[$badge->get_aggregation_method($type)])) .
$c->get_details($short) .
$criteriadescr;
}
}
}
$output .= html_writer::alist($items, array(), 'ul');
return $output;
return $overalldescr . $condition . html_writer::alist($items, array(), 'ul');;
}
// Prints criteria actions for badge editing.

@ -16,13 +16,17 @@ Feature: Award badges
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I set the field "type" to "Profile completion"
And I expand all fieldsets
And I set the field "First name" to "1"
And I set the field "Email address" to "1"
And I set the field "Phone" to "1"
And I set the field "id_description" to "Criterion description"
When I press "Save"
Then I should see "Profile completion"
And I should see "First name"
And I should see "Email address"
And I should see "Phone"
And I should see "Criterion description"
And I should not see "Criteria for this badge have not been set up yet."
And I press "Enable access"
And I press "Continue"

@ -1982,6 +1982,7 @@ $capabilities = array(
// Set up/edit criteria of earning a badge.
'moodle/badges:configurecriteria' => array(
'riskbitmask' => RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(