/** * Returns information about badge criteria in a list form. * * @param badge $badge Badge objects * @param string $short Indicates whether to print full info about this badge * @return string $output HTML string to output */ public function print_badge_criteria(badge $badge, $short = '') { $agg = $badge->get_aggregation_methods(); if (empty($badge->criteria)) { return get_string('nocriteria', 'badges'); } $overalldescr = ''; $overall = $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]; if (!$short && !empty($overall->description)) { $overalldescr = $this->output->box(format_text($overall->description, $overall->descriptionformat, array('context' => $badge->get_context())), 'criteria-description'); } // Get the condition string. if (count($badge->criteria) == 2) { $condition = ''; if (!$short) { $condition = get_string('criteria_descr', 'badges'); } } else { $condition = get_string('criteria_descr_' . $short . BADGE_CRITERIA_TYPE_OVERALL, 'badges', core_text::strtoupper($agg[$badge->get_aggregation_method()])); } unset($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]); $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, $c->descriptionformat, array('context' => $badge->get_context())), 'criteria-description'); } if (count($c->params) == 1) { $items[] = get_string('criteria_descr_single_' . $short . $c->criteriatype, 'badges') . $c->get_details($short); } else { $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, $c->descriptionformat, 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; } } } return $overalldescr . $condition . html_writer::alist($items, array(), 'ul'); }
public function print_badge_criteria(badge $badge, $short = '') { $output = ""; $agg = $badge->get_aggregation_methods(); if (empty($badge->criteria)) { return get_string('nocriteria', 'badges'); } else { if (count($badge->criteria) == 2) { if (!$short) { $output .= get_string('criteria_descr', 'badges'); } } else { $output .= get_string('criteria_descr_' . $short . BADGE_CRITERIA_TYPE_OVERALL, 'badges', strtoupper($agg[$badge->get_aggregation_method()])); } } $items = array(); unset($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]); foreach ($badge->criteria as $type => $c) { if (count($c->params) == 1) { $items[] = get_string('criteria_descr_single_' . $short . $type, 'badges') . $c->get_details($short); } else { $items[] = get_string('criteria_descr_' . $short . $type, 'badges', strtoupper($agg[$badge->get_aggregation_method($type)])) . $c->get_details($short); } } $output .= html_writer::alist($items, array(), 'ul'); return $output; }
/** * Print badge criteria. * * Modelled after core_badges_renderer::print_badge_critera(), except that * we dispatch rendering of criteria to our own renderer methods as opposed * to calling award_criteria::get_details() wherever possible. * * @param \badge $badge * @param string $short * * @return string */ public function print_badge_criteria(badge $badge, $short = '') { $output = ''; $aggregationmethods = $badge->get_aggregation_methods(); if (!$badge->criteria) { return static::string('nocriteria'); } elseif (count($badge->criteria) === 2) { if (!$short) { $output .= static::string('criteria_descr'); } } else { $stringname = 'criteria_descr_' . $short . BADGE_CRITERIA_TYPE_OVERALL; $output .= static::string($stringname, core_text::strtoupper($aggregationmethods[$badge->get_aggregation_method()])); } unset($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]); $items = array(); foreach ($badge->criteria as $type => $criteria) { $items[] = $this->print_badge_criteria_single($badge, $aggregationmethods, $type, $criteria, $short); } $output .= html_writer::alist($items, array(), 'ul'); return $output; }