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
325131
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');;
    }
1322121
protected function render_badge_user_collection(badge_user_collection $badges) {
        global $CFG, $USER, $SITE;
        $backpack = $badges->backpack;
        $mybackpack = new moodle_url('/badges/mybackpack.php');

        $paging = new paging_bar($badges->totalcount, $badges->page, $badges->perpage, $this->page->url, 'page');
        $htmlpagingbar = $this->render($paging);

        // Set backpack connection string.
        $backpackconnect = '';
        if (!empty($CFG->badges_allowexternalbackpack) && is_null($backpack)) {
            $backpackconnect = $this->output->box(get_string('localconnectto', 'badges', $mybackpack->out()), 'noticebox');
        }
        // Search box.
        $searchform = $this->output->box($this->helper_search_form($badges->search), 'boxwidthwide boxaligncenter');

        // Download all button.
        $downloadall = $this->output->single_button(
                    new moodle_url('/badges/mybadges.php', array('downloadall' => true, 'sesskey' => sesskey())),
                    get_string('downloadall'), 'POST', array('class' => 'activatebadge'));

        // Local badges.
        $localhtml = html_writer::start_tag('div', array('id' => 'issued-badge-table', 'class' => 'generalbox'));
        $heading = get_string('localbadges', 'badges', format_string($SITE->fullname, true, array('context' => context_system::instance())));
        $localhtml .= $this->output->heading_with_help($heading, 'localbadgesh', 'badges');
        if ($badges->badges) {
            $downloadbutton = $this->output->heading(get_string('badgesearned', 'badges', $badges->totalcount), 4, 'activatebadge');
            $downloadbutton .= $downloadall;

            $htmllist = $this->print_badges_list($badges->badges, $USER->id);
            $localhtml .= $backpackconnect . $downloadbutton . $searchform . $htmlpagingbar . $htmllist . $htmlpagingbar;
        } else {
            $localhtml .= $searchform . $this->output->notification(get_string('nobadges', 'badges'));
        }
        $localhtml .= html_writer::end_tag('div');

        // External badges.
        $externalhtml = "";
        if (!empty($CFG->badges_allowexternalbackpack)) {
            $externalhtml .= html_writer::start_tag('div', array('class' => 'generalbox'));
            $externalhtml .= $this->output->heading_with_help(get_string('externalbadges', 'badges'), 'externalbadges', 'badges');
            if (!is_null($backpack)) {
                if ($backpack->totalcollections == 0) {
                    $externalhtml .= get_string('nobackpackcollections', 'badges', $backpack);
                } else {
                    if ($backpack->totalbadges == 0) {
                        $externalhtml .= get_string('nobackpackbadges', 'badges', $backpack);
                    } else {
                        $externalhtml .= get_string('backpackbadges', 'badges', $backpack);
                        $externalhtml .= '<br/><br/>' . $this->print_badges_list($backpack->badges, $USER->id, true, true);
                    }
                }
            } else {
                $externalhtml .= get_string('externalconnectto', 'badges', $mybackpack->out());
            }

            $externalhtml .= html_writer::end_tag('div');
        }

        return $localhtml . $externalhtml;
    }
888689
public function getLanguageByShortCode($shortCode)
    {
        return isset($this->getLanguages()[$shortCode]) ? $this->getLanguages()[$shortCode] : false;
    }
1136797
public function listBadges($userId, $optParams = array()) {
      $params = array('userId' => $userId);
      $params = array_merge($params, $optParams);
      $data = $this->__call('list', array($params));
      if ($this->useObjects()) {
        return new BadgeList($data);
      } else {
        return $data;
      }
    }
157686
public function get_details($short = '') {
        $output = array();

        foreach ($this->params as $p) {
            $competency = new \core_competency\competency($p['competency']);
            if ($short) {
                $competency->set('description', '');
            }
            // Render the competency even if competencies are not currently enabled.
            \core_competency\api::skip_enabled();
            if ($pluginsfunction = get_plugins_with_function('render_competency_summary')) {
                foreach ($pluginsfunction as $plugintype => $plugins) {
                    foreach ($plugins as $pluginfunction) {
                        $output[] = $pluginfunction($competency, $competency->get_framework(), false, false, true);
                    }
                }
            }
            \core_competency\api::check_enabled();
        }

        return '<dl><dd class="p-3 mb-2 bg-light text-dark border">' .
               implode('</dd><dd class="p-3 mb-2 bg-light text-dark border">', $output) .
               '</dd></dl>';
    }
289427
public function parse($badge)
    {
        if (isset($badge['badgeIndex'])) {
            $this->setBadgeIndex($badge['badgeIndex']);
        }
        $this->setCode($badge['code']);
        $this->setName($badge['name']);
        $this->setDescription($badge['description']);
    }
1012707
protected function getDescription($shortName)
    {
        return sprintf(
            '%s has been %s with %s = "%s"',
            $shortName,
            $this->getEventShortName(),
            $this->getIdField(),
            $this->getIdValue()
        );
    }
823750
public function get_details($short = '') {
        global $OUTPUT;
        $output = array();
        foreach ($this->params as $p) {
            $str = self::get_role_name($p['role']);
            if (!$str) {
                $output[] = $OUTPUT->error_text(get_string('error:nosuchrole', 'badges'));
            } else {
                $output[] = $str;
            }
        }

        if ($short) {
            return implode(', ', $output);
        } else {
            return html_writer::alist($output, array(), 'ul');
        }
    }
118742
protected function render_badge_alignments(badge_alignments $alignments) {
        $currentbadge = new badge($alignments->currentbadgeid);
        $paging = new paging_bar($alignments->totalcount, $alignments->page, $alignments->perpage, $this->page->url, 'page');
        $htmlpagingbar = $this->render($paging);
        $table = new html_table();
        $table->attributes['class'] = 'generaltable boxaligncenter boxwidthwide';
        $table->head = array('Name', 'URL', '');

        foreach ($alignments->alignments as $item) {
            $urlaligment = new moodle_url('alignment.php',
                array(
                    'id' => $currentbadge->id,
                    'alignmentid' => $item->id,
                )
            );
            $row = array(
                html_writer::link($urlaligment, $item->targetname),
                html_writer::link($item->targeturl, $item->targeturl, array('target' => '_blank'))
            );
            if (!$currentbadge->is_active() && !$currentbadge->is_locked()) {
                $delete = $this->output->action_icon(
                    new moodle_url('alignment_action.php',
                        array(
                            'id' => $currentbadge->id,
                            'alignmentid' => $item->id,
                            'action' => 'remove'
                        )
                    ), new pix_icon('t/delete', get_string('delete')));
                $edit = $this->output->action_icon(
                    new moodle_url('alignment.php',
                        array(
                            'id' => $currentbadge->id,
                            'alignmentid' => $item->id,
                            'action' => 'edit'
                        )
                    ), new pix_icon('t/edit', get_string('edit')));
                $actions = html_writer::tag('div', $edit . $delete, array('class' => 'badge-actions'));
                array_push($row, $actions);
            }
            $table->data[] = $row;
        }
        $htmltable = html_writer::table($table);

        return $htmlpagingbar . $htmltable . $htmlpagingbar;
    }
772507
protected function addFluentBadge($badgeField, DataObject $record)
    {
        // Check for a fluent state before continuing
        if (!FluentState::singleton()->getLocale()
            || !$record->has_extension(FluentVersionedExtension::class)
        ) {
            return null;
        }

        $fluentBadge = $this->getBadge($record);
        // Add fluent badge before any existing badges
        $newBadge = DBField::create_field('HTMLFragment', $fluentBadge . $badgeField);

        return $newBadge;
    }
24318
private function setBadge($badge)
	{
		// Validate the badge int
		if ((int)$badge < 0) {
			throw new \InvalidArgumentException('Badge must be 0 or higher.');
		}

		// Cast to int or set to null
		$this->badge = (null === $badge) ? null : (int)$badge;
	}
474489
public function Link($short = false)
    {
        if ($this->getIsDefaultEntity()) {
            $base = Controller::join_links(
                Director::baseURL(),
                Config::inst()->get('DocumentationViewer', 'link_base'),
                $this->getLanguage(),
                '/'
            );
        } else {
            $base = Controller::join_links(
                Director::baseURL(),
                Config::inst()->get('DocumentationViewer', 'link_base'),
                $this->getLanguage(),
                $this->getKey(),
                '/'
            );
        }

        if ($short && $this->stable) {
            return $base;
        }

        return Controller::join_links(
            $base,
            $this->getVersion(),
            '/'
        );
    }
131195
public function badge($text, $options = [])
    {
        $defaults = array_merge(['class' => 'badge'], $options);
        return parent::tag('span', $text, $defaults);
    }
427490
public function badge($label, $colorOrStatus = null, $toolTipLabel = null) {
        switch (true) {
            case !isset($this->list[$this->listCount - 1]) : 
                Checkers::notice('Unable to put badge [' . $label . '] in list group, no element.');
                break;
            case $this->list[$this->listCount - 1] instanceof Button : 
                Checkers::notice('Unable to badge a list group button. Use an element instead.');
                break;
            case is_array($this->list[$this->listCount - 1]) : 
                $this->badges[$this->listCount - 1][] = $this->getBadgeHtml($label, $colorOrStatus, $toolTipLabel);
                break;
            default : 
                Checkers::notice('Unable to find what to do with your badge [' . $label . ']...');
        }
        return $this;
    }
145867
public function serialize(BadgeClass $badge, array $options = [])
    {
        $data = [
            'id' => $badge->getUuid(),
            'name' => $badge->getName(),
            'description' => $badge->getDescription(),
            'criteria' => $badge->getCriteria(),
            'duration' => $badge->getDurationValidation(),
            'image' => $badge->getImage() && $this->om->getRepository(PublicFile::class)->findOneBy([
                  'url' => $badge->getImage(),
              ]) ? $this->publicFileSerializer->serialize($this->om->getRepository(PublicFile::class)->findOneBy([
                  'url' => $badge->getImage(),
              ])
            ) : null,
            'issuer' => $this->organizationSerializer->serialize($badge->getIssuer()),
            //only in non list mode I guess
            'tags' => $this->serializeTags($badge),
        ];

        if (!in_array(APIOptions::SERIALIZE_LIST, $options)) {
            $data['assignable'] = $this->isAssignable($badge);
        }

        if (in_array(Options::ENFORCE_OPEN_BADGE_JSON, $options)) {
            $data['id'] = $this->router->generate('apiv2_open_badge__badge_class', ['badge' => $badge->getUuid()], UrlGeneratorInterface::ABSOLUTE_URL);
            $data['type'] = 'BadgeClass';
            $data['criteria'] = $this->criteriaSerializer->serialize($badge)['id'];
            $image = $this->om->getRepository(PublicFile::class)->findOneBy(['url' => $badge->getImage()]);

            if ($image) {
                //wtf, this is for mozillabackpack
                $data['image'] = $this->imageSerializer->serialize($image)['id'];
            }

            $data['issuer'] = $this->profileSerializer->serialize($badge->getIssuer());
        } else {
            $data['issuingMode'] = $badge->getIssuingMode();
            $data['meta'] = [
               'created' => $badge->getCreated()->format('Y-m-d\TH:i:s'),
               'updated' => $badge->getUpdated()->format('Y-m-d\TH:i:s'),
               'enabled' => $badge->getEnabled(),
            ];
            $data['workspace'] = $badge->getWorkspace() ? $this->workspaceSerializer->serialize($badge->getWorkspace(), [APIOptions::SERIALIZE_MINIMAL]) : null;
            $data['allowedUsers'] = array_map(function (User $user) {
                return $this->userSerializer->serialize($user);
            }, $badge->getAllowedIssuers()->toArray());
            $data['allowedGroups'] = array_map(function (Group $group) {
                return $this->groupSerializer->serialize($group);
            }, $badge->getAllowedIssuersGroups()->toArray());
        }

        return $data;
    }
1004891
public function get_criteria() {
        global $DB;
        $criteria = array();

        if ($records = (array)$DB->get_records('badge_criteria', array('badgeid' => $this->id))) {
            foreach ($records as $record) {
                $criteria[$record->criteriatype] = award_criteria::build((array)$record);
            }
        }

        return $criteria;
    }
166422
public function get_badges_option($badge) {
        global $DB;
        $sql = "SELECT b.id, b.name, b.version, b.language, b.type
                  FROM {badge} b
                 WHERE b.id <> :badgeid
                       AND b.id NOT IN (
                            SELECT DISTINCT b.id
                              FROM {badge_related} br
                              JOIN {badge} b ON (br.relatedbadgeid = b.id OR br.badgeid = b.id)
                             WHERE (br.badgeid = :badgeid2 OR br.relatedbadgeid = :badgeid3) AND b.id != :badgeid4)";
        $params = ['badgeid' => $badge->id, 'badgeid2' => $badge->id, 'badgeid3' => $badge->id, 'badgeid4' => $badge->id];
        if ($badge->type == BADGE_TYPE_COURSE) {
            $sql .= " AND (b.courseid = :courseid OR b.type = :badgetype)";
            $params['courseid'] = $badge->courseid;
            $params['badgetype'] = BADGE_TYPE_SITE;
        }

        $records = $DB->get_records_sql($sql, $params);
        $languages = get_string_manager()->get_list_of_languages();
        $options = array();
        foreach ($records as $record) {
            $language = isset($languages[$record->language]) ? $languages[$record->language] : '';
            $options[$record->id] = $record->name .
                ' (version: ' . $record->version . ', language: ' . $language . ', ' .
                ($record->type == BADGE_TYPE_COURSE ? get_string('badgesview', 'badges') : get_string('sitebadges', 'badges')) .
                ')';
        }
        return $options;
    }