Generates the content of the block and returns it.

If the content has already been generated then the previously generated content is returned.

@return stdClass
16613
public function get_content() {

        // The config should be loaded by now.
        // If its empty then we will use the global config for the section links block.
        if (isset($this->config)){
            $config = $this->config;
        } else{
            $config = get_config('block_section_links');
        }

        if ($this->content !== null) {
            return $this->content;
        }

        $this->content = new stdClass;
        $this->content->footer = '';
        $this->content->text   = '';

        if (empty($this->instance)) {
            return $this->content;
        }

        $course = $this->page->course;
        $courseformat = course_get_format($course);
        $numsections = $courseformat->get_last_section_number();
        $context = context_course::instance($course->id);

        // Course format options 'numsections' is required to display the block.
        if (empty($numsections)) {
            return $this->content;
        }

        // Prepare the increment value.
        if (!empty($config->numsections1) and ($numsections > $config->numsections1)) {
            $inc = $config->incby1;
        } else if ($numsections > 22) {
            $inc = 2;
        } else {
            $inc = 1;
        }
        if (!empty($config->numsections2) and ($numsections > $config->numsections2)) {
            $inc = $config->incby2;
        } else {
            if ($numsections > 40) {
                $inc = 5;
            }
        }

        // Prepare an array of sections to create links for.
        $sections = array();
        $canviewhidden = has_capability('moodle/course:update', $context);
        $coursesections = $courseformat->get_sections();
        $coursesectionscount = count($coursesections);
        $sectiontojumpto = false;
        for ($i = $inc; $i <= $coursesectionscount; $i += $inc) {
            if ($i > $numsections || !isset($coursesections[$i])) {
                continue;
            }
            $section = $coursesections[$i];
            if ($section->section && ($section->visible || $canviewhidden)) {
                $sections[$i] = (object)array(
                    'section' => $section->section,
                    'visible' => $section->visible,
                    'highlight' => false
                );
                if ($courseformat->is_section_current($section)) {
                    $sections[$i]->highlight = true;
                    $sectiontojumpto = $section->section;
                }
            }
        }

        if (!empty($sections)) {
            // Render the sections.
            $renderer = $this->page->get_renderer('block_section_links');
            $this->content->text = $renderer->render_section_links($this->page->course, $sections, $sectiontojumpto);
        }

        return $this->content;
    }
184545
public function Content()
    {
        $content = $this->owner->Content;

        // Internal links.
        $matches = array();
        preg_match_all('/<a.*href="\[file_link,id=([0-9]+)\].*".*>.*<\/a>/U', $content, $matches);

        for ($i = 0; $i < count($matches[0]); $i++) {
            $file = DataObject::get_by_id('File', $matches[1][$i]);
            if ($file) {
                $size     = $file->getSize();
                $ext     = strtoupper($file->getExtension());
                $newLink = $matches[0][$i] . "<span class='fileExt'> [$ext, $size]</span>";
                $content = str_replace($matches[0][$i], $newLink, $content);
            }
        }

        // and now external links
        $pattern     = '/<a href=\"(h[^\"]*)\">(.*)<\/a>/iU';
        $replacement = '<a href="$1" class="external">$2</a>';
        $result         = preg_replace($pattern, $replacement, $content, -1);
        return $result;
    }
1018289
public function generate()
	{
		$arrOptions = array();
		$strClass = 'tl_select';
		$strStyle = '<style>.group-result {padding-top: 5px !important; line-height: 20px !important;}';
		$count = 1;

		if ($this->multiple)
		{
			$this->strName .= '[]';
			$strClass = 'tl_mselect';
		}

		// Add an empty option (XHTML) if there are none
		if (empty($this->arrOptions))
		{
			$this->arrOptions = array(array('value'=>'', 'label'=>'-'));
		}
		
		foreach ($this->arrOptions as $strKey=>$arrOption)
		{
			if (isset($arrOption['value']))
			{
				$arrOptions[] = sprintf('<option value="%s"%s>%s</option>',
										 \StringUtil::specialchars($arrOption['value']),
										 $this->isSelected($arrOption),
										 $arrOption['label']);

				if (isset($GLOBALS['TL_CTB_IMG'][$arrOptgroup['value']]))
				{
					$objImage = \FilesModel::findByUuid($GLOBALS['TL_CTB_IMG'][$arrOptgroup['value']]);
				}
				
				if ($objImage === null)
				{
					$strStyle .= '#ctrl_type_chzn_o_'.$count.' {position: relative; padding-left: 90px; line-height: 41px;}#ctrl_type_chzn_o_'.$count++.'::before {content: ""; position: absolute; left: 20px; top:2px; width: 60px; height: 40px; border: 1px solid #ccc; background: #eee; background-size: 60px 40px;}';
				}
				else
				{
					$strStyle .= '#ctrl_type_chzn_o_'.$count.' {position: relative; padding-left: 90px; line-height: 41px;}#ctrl_type_chzn_o_'.$count++.'::before {content: ""; position: absolute; left: 20px; top:2px; width: 60px; height: 40px; border: 1px solid #ccc; background: #eee url('.$objImage->path.'); background-size: 60px 40px;}';
				}
			}
			else
			{
				$arrOptgroups = array();

				foreach ($arrOption as $arrOptgroup)
				{
					$arrOptgroups[] = sprintf('<option value="%s"%s>%s</option>',
											   \StringUtil::specialchars($arrOptgroup['value']),
											   $this->isSelected($arrOptgroup),
											   $arrOptgroup['label']);

					if (isset($GLOBALS['TL_CTB_IMG'][$arrOptgroup['value']]))
					{
						$objImage = \FilesModel::findByUuid($GLOBALS['TL_CTB_IMG'][$arrOptgroup['value']]);
					}

					if ($objImage === null)
					{
						$strStyle .= '#ctrl_type_chzn_o_'.$count.' {position: relative; padding-left: 90px; line-height: 41px;}#ctrl_type_chzn_o_'.$count++.'::before {content: ""; position: absolute; left: 20px; top:2px; width: 60px; height: 40px; border: 1px solid #ccc; background: #eee; background-size: 60px 40px;}';
					}
					else
					{
						$strStyle .= '#ctrl_type_chzn_o_'.$count.' {position: relative; padding-left: 90px; line-height: 41px;}#ctrl_type_chzn_o_'.$count++.'::before {content: ""; position: absolute; left: 20px; top:2px; width: 60px; height: 40px; border: 1px solid #ccc; background: #eee url('.$objImage->path.'); background-size: 60px 40px;}';
					}

				}

				$arrOptions[] = sprintf('<optgroup label="&nbsp;%s">%s</optgroup>', \StringUtil::specialchars($strKey), implode('', $arrOptgroups));
				$count++;
			}
		}

		// Chosen
		if ($this->chosen)
		{
			$strClass .= ' tl_chosen';
		}


		$strStyle .= '</style>';
	
		return sprintf('%s<select name="%s" id="ctrl_%s" class="%s%s"%s onfocus="Backend.getScrollOffset()">%s</select>%s',
						($this->multiple ? '<input type="hidden" name="'. rtrim($this->strName, '[]') .'" value="">' : ''),
						$this->strName,
						$this->strId,
						$strClass,
						(($this->strClass != '') ? ' ' . $this->strClass : ''),
						$this->getAttributes(),
						implode('', $arrOptions),
						$strStyle);
	}
948905
public function generateFile()
    {
        parent::generateFile();

        if (count($this->uses) > 0) {
            sort($this->uses);
            $uses = '';
            foreach ($this->uses as $use) {
                $uses .= 'use ' . $use . ';' . $this->getNewlineCharacter();
            }
            $this->file_content = str_replace('{{ uses }}', $uses, $this->file_content);
        } else {
            $this->file_content = str_replace('{{ uses }}', '', $this->file_content);
        }
        $this->file_content = str_replace('{{ className }}', $this->class_name, $this->file_content);

        return $this->file_content;
    }
598275
public function generate()
    {
        $code = array();

        $doc = $this->generateDocumentation();
        if ($doc !== null) {
            $code[] = $doc;
        }

        if ($this->isAbstract() === true) {
            $code[] = $this->generateSignature() . ';';
        } else {
            $code[] = $this->generateSignature();
            $code[] = $this->getIndentation() . $this->generateBody();
        }

        return implode($this->getLineFeed(), $code);
    }
672095
final public function getHtml()
    {
        $result = $this->renderHtml();
        if (is_array($result) && array_key_exists('RenderView', $result)) {
            $result['RenderView']['options']['block_manager'] = $this;
        }

        return $result;
    }
636706
private function view()
    {
        if (isset(static::$view)) {
            return static::$view;
        }

        $classNamespace = $this->getModuleName();
        $className = $this->getComponentName();

        return "{$classNamespace}::blocks.{$className}";
    }
835016
public function generate()
    {
        return sprintf(
            '<%s %s>%s</%s>%s',
            $this->tag,
            parent::generate(),
            $this->label,
            $this->tag,
            PHP_EOL
        );
    }
946238
function &generateClassIDArray()
    {
        $classIDArray = array();
        foreach( $this->NodeObjectArray as $nodeObject )
        {
            $contentObject = $nodeObject->object();
            $classIDArray[] = $contentObject->attribute( 'contentclass_id' );
        }
        $classIDArray = array_unique( $classIDArray );
        return $classIDArray;
    }
139252
public function get_content() {
        global $USER, $CFG, $DB;

        if ($this->content !== null) {
            return $this->content;
        }

        $this->content = new stdClass;
        $this->content->text = '';
        $this->content->footer = '';

        if (empty($this->instance)) {
            return $this->content;
        }

        // We are configured so use the configuration.
        if (!empty($this->config->activitygradeitemid)) {
            // We are configured.
            $activitygradeitemid = $this->config->activitygradeitemid;

            // Lookup the module in the grade_items table.
            $activity = $DB->get_record('grade_items', array('id' => $activitygradeitemid));
            if (empty($activity)) {
                // Activity does not exist.
                $this->content->text = get_string('error_emptyactivityrecord', 'block_activity_results');
                return $this->content;
            }
            $courseid = $activity->courseid;
            $inactivity = false;
        } else {
            // Not configured.
            $activitygradeitemid = 0;
        }

        // Check to see if we are in the moule we are displaying results for.
        if (!empty($this->config->activitygradeitemid)) {
            if ($this->get_owning_activity()->id == $this->config->activitygradeitemid) {
                $inactivity = true;
            } else {
                $inactivity = false;
            }
        }

        // Activity ID is missing.
        if (empty($activitygradeitemid)) {
            $this->content->text = get_string('error_emptyactivityid', 'block_activity_results');
            return $this->content;
        }

        // Check to see if we are configured.
        if (empty($this->config->showbest) && empty($this->config->showworst)) {
            $this->content->text = get_string('configuredtoshownothing', 'block_activity_results');
            return $this->content;
        }

        // Check to see if it is a supported grade type.
        if (empty($activity->gradetype) || ($activity->gradetype != GRADE_TYPE_VALUE && $activity->gradetype != GRADE_TYPE_SCALE)) {
            $this->content->text = get_string('error_unsupportedgradetype', 'block_activity_results');
            return $this->content;
        }

        // Get the grades for this activity.
        $sql = 'SELECT * FROM {grade_grades}
                 WHERE itemid = ? AND finalgrade is not NULL
                 ORDER BY finalgrade, timemodified DESC';

        $grades = $DB->get_records_sql($sql, array( $activitygradeitemid));

        if (empty($grades) || $activity->hidden) {
            // No grades available, The block will hide itself in this case.
            return $this->content;
        }

        // Set up results.
        $groupmode = NOGROUPS;
        $best      = array();
        $worst     = array();

        if (!empty($this->config->nameformat)) {
            $nameformat = $this->config->nameformat;
        } else {
            $nameformat = B_ACTIVITYRESULTS_NAME_FORMAT_FULL;
        }

        // Get $cm and context.
        if ($inactivity) {
            $cm = $this->page->cm;
            $context = $this->page->context;
        } else {
            $cm = get_coursemodule_from_instance($activity->itemmodule, $activity->iteminstance, $courseid);
            $context = context_module::instance($cm->id);
        }

        if (!empty($this->config->usegroups)) {
            $groupmode = groups_get_activity_groupmode($cm);

            if ($groupmode == SEPARATEGROUPS && has_capability('moodle/site:accessallgroups', $context)) {
                // If you have the ability to see all groups then lets show them.
                $groupmode = VISIBLEGROUPS;
            }
        }

        switch ($groupmode) {
            case VISIBLEGROUPS:
                // Display group-mode results.
                $groups = groups_get_all_groups($courseid);

                if (empty($groups)) {
                    // No groups exist, sorry.
                    $this->content->text = get_string('error_nogroupsexist', 'block_activity_results');
                    return $this->content;
                }

                // Find out all the userids which have a submitted grade.
                $userids = array();
                $gradeforuser = array();
                foreach ($grades as $grade) {
                    $userids[] = $grade->userid;
                    $gradeforuser[$grade->userid] = (float)$grade->finalgrade;
                }

                // Now find which groups these users belong in.
                list($usertest, $params) = $DB->get_in_or_equal($userids);
                $params[] = $courseid;
                $usergroups = $DB->get_records_sql('
                        SELECT gm.id, gm.userid, gm.groupid, g.name
                        FROM {groups} g
                        LEFT JOIN {groups_members} gm ON g.id = gm.groupid
                        WHERE gm.userid ' . $usertest . ' AND g.courseid = ?', $params);

                // Now, iterate the grades again and sum them up for each group.
                $groupgrades = array();
                foreach ($usergroups as $usergroup) {
                    if (!isset($groupgrades[$usergroup->groupid])) {
                        $groupgrades[$usergroup->groupid] = array(
                                'sum' => (float)$gradeforuser[$usergroup->userid],
                                'number' => 1,
                                'group' => $usergroup->name);
                    } else {
                        $groupgrades[$usergroup->groupid]['sum'] += $gradeforuser[$usergroup->userid];
                        $groupgrades[$usergroup->groupid]['number'] += 1;
                    }
                }

                foreach ($groupgrades as $groupid => $groupgrade) {
                    $groupgrades[$groupid]['average'] = $groupgrades[$groupid]['sum'] / $groupgrades[$groupid]['number'];
                }

                // Sort groupgrades according to average grade, ascending.
                uasort($groupgrades, function($a, $b) {
                    if ($a["average"] == $b["average"]) {
                        return 0;
                    }
                    return ($a["average"] > $b["average"] ? 1 : -1);
                });

                // How many groups do we have with graded member submissions to show?
                $numbest  = empty($this->config->showbest) ? 0 : min($this->config->showbest, count($groupgrades));
                $numworst = empty($this->config->showworst) ? 0 : min($this->config->showworst, count($groupgrades) - $numbest);

                // Collect all the group results we are going to use in $best and $worst.
                $remaining = $numbest;
                $groupgrade = end($groupgrades);
                while ($remaining--) {
                    $best[key($groupgrades)] = $groupgrade['average'];
                    $groupgrade = prev($groupgrades);
                }

                $remaining = $numworst;
                $groupgrade = reset($groupgrades);
                while ($remaining--) {
                    $worst[key($groupgrades)] = $groupgrade['average'];
                    $groupgrade = next($groupgrades);
                }

                // Ready for output!
                if ($activity->gradetype == GRADE_TYPE_SCALE) {
                    // We must display the results using scales.
                    $gradeformat = B_ACTIVITYRESULTS_GRADE_FORMAT_SCALE;
                    // Preload the scale.
                    $scale = $this->get_scale($activity->scaleid);
                } else if (intval(empty($this->config->gradeformat))) {
                    $gradeformat = B_ACTIVITYRESULTS_GRADE_FORMAT_PCT;
                } else {
                    $gradeformat = $this->config->gradeformat;
                }

                // Generate the header.
                $this->content->text .= $this->activity_link($activity, $cm);

                if ($nameformat == B_ACTIVITYRESULTS_NAME_FORMAT_FULL) {
                    if (has_capability('moodle/course:managegroups', $context)) {
                        $grouplink = $CFG->wwwroot.'/group/overview.php?id='.$courseid.'&amp;group=';
                    } else if (course_can_view_participants($context)) {
                        $grouplink = $CFG->wwwroot.'/user/index.php?id='.$courseid.'&amp;group=';
                    } else {
                        $grouplink = '';
                    }
                }

                $rank = 0;
                if (!empty($best)) {
                    $this->content->text .= '<table class="grades"><caption>';
                    if ($numbest == 1) {
                        $this->content->text .= get_string('bestgroupgrade', 'block_activity_results');
                    } else {
                        $this->content->text .= get_string('bestgroupgrades', 'block_activity_results', $numbest);
                    }
                    $this->content->text .= '</caption><colgroup class="number" />';
                    $this->content->text .= '<colgroup class="name" /><colgroup class="grade" /><tbody>';
                    foreach ($best as $groupid => $averagegrade) {
                        switch ($nameformat) {
                            case B_ACTIVITYRESULTS_NAME_FORMAT_ANON:
                            case B_ACTIVITYRESULTS_NAME_FORMAT_ID:
                                $thisname = get_string('group');
                            break;
                            default:
                            case B_ACTIVITYRESULTS_NAME_FORMAT_FULL:
                                if ($grouplink) {
                                    $thisname = '<a href="'.$grouplink.$groupid.'">'.$groupgrades[$groupid]['group'].'</a>';
                                } else {
                                    $thisname = $groupgrades[$groupid]['group'];
                                }
                            break;
                        }
                        $this->content->text .= '<tr><td>'.(++$rank).'.</td><td>'.$thisname.'</td><td>';
                        switch ($gradeformat) {
                            case B_ACTIVITYRESULTS_GRADE_FORMAT_SCALE:
                                // Round answer up and locate appropriate scale.
                                $answer = (round($averagegrade, 0, PHP_ROUND_HALF_UP) - 1);
                                if (isset($scale[$answer])) {
                                    $this->content->text .= $scale[$answer];
                                } else {
                                    // Value is not in the scale.
                                    $this->content->text .= get_string('unknown', 'block_activity_results');
                                }
                            break;
                            case B_ACTIVITYRESULTS_GRADE_FORMAT_FRA:
                                $this->content->text .= $this->activity_format_grade($averagegrade)
                                    . '/' . $this->activity_format_grade($activity->grademax);
                            break;
                            case B_ACTIVITYRESULTS_GRADE_FORMAT_ABS:
                                $this->content->text .= $this->activity_format_grade($averagegrade);
                            break;
                            default:
                            case B_ACTIVITYRESULTS_GRADE_FORMAT_PCT:
                                $this->content->text .= $this->activity_format_grade((float)$averagegrade /
                                        (float)$activity->grademax * 100).'%';
                            break;
                        }
                        $this->content->text .= '</td></tr>';
                    }
                    $this->content->text .= '</tbody></table>';
                }

                $rank = 0;
                if (!empty($worst)) {
                    $worst = array_reverse($worst, true);
                    $this->content->text .= '<table class="grades"><caption>';
                    if ($numworst == 1) {
                        $this->content->text .= get_string('worstgroupgrade', 'block_activity_results');
                    } else {
                        $this->content->text .= get_string('worstgroupgrades', 'block_activity_results', $numworst);
                    }
                    $this->content->text .= '</caption><colgroup class="number" />';
                    $this->content->text .= '<colgroup class="name" /><colgroup class="grade" /><tbody>';
                    foreach ($worst as $groupid => $averagegrade) {
                        switch ($nameformat) {
                            case B_ACTIVITYRESULTS_NAME_FORMAT_ANON:
                            case B_ACTIVITYRESULTS_NAME_FORMAT_ID:
                                $thisname = get_string('group');
                            break;
                            default:
                            case B_ACTIVITYRESULTS_NAME_FORMAT_FULL:
                                if ($grouplink) {
                                    $thisname = '<a href="'.$grouplink.$groupid.'">'.$groupgrades[$groupid]['group'].'</a>';
                                } else {
                                    $thisname = $groupgrades[$groupid]['group'];
                                }
                            break;
                        }
                        $this->content->text .= '<tr><td>'.(++$rank).'.</td><td>'.$thisname.'</td><td>';
                        switch ($gradeformat) {
                            case B_ACTIVITYRESULTS_GRADE_FORMAT_SCALE:
                                // Round answer up and locate appropriate scale.
                                $answer = (round($averagegrade, 0, PHP_ROUND_HALF_UP) - 1);
                                if (isset($scale[$answer])) {
                                    $this->content->text .= $scale[$answer];
                                } else {
                                    // Value is not in the scale.
                                    $this->content->text .= get_string('unknown', 'block_activity_results');
                                }
                            break;
                            case B_ACTIVITYRESULTS_GRADE_FORMAT_FRA:
                                $this->content->text .= $this->activity_format_grade($averagegrade)
                                    . '/' . $this->activity_format_grade($activity->grademax);
                            break;
                            case B_ACTIVITYRESULTS_GRADE_FORMAT_ABS:
                                $this->content->text .= $this->activity_format_grade($averagegrade);
                            break;
                            default:
                            case B_ACTIVITYRESULTS_GRADE_FORMAT_PCT:
                                $this->content->text .= $this->activity_format_grade((float)$averagegrade /
                                        (float)$activity->grademax * 100).'%';
                            break;
                        }
                        $this->content->text .= '</td></tr>';
                    }
                    $this->content->text .= '</tbody></table>';
                }
            break;

            case SEPARATEGROUPS:
                // This is going to be just like no-groups mode, only we 'll filter
                // out the grades from people not in our group.
                if (!isloggedin()) {
                    // Not logged in, so show nothing.
                    return $this->content;
                }

                $mygroups = groups_get_all_groups($courseid, $USER->id);
                if (empty($mygroups)) {
                    // Not member of a group, show nothing.
                    return $this->content;
                }

                // Get users from the same groups as me.
                list($grouptest, $params) = $DB->get_in_or_equal(array_keys($mygroups));
                $mygroupsusers = $DB->get_records_sql_menu(
                        'SELECT DISTINCT userid, 1 FROM {groups_members} WHERE groupid ' . $grouptest,
                        $params);

                // Filter out the grades belonging to other users, and proceed as if there were no groups.
                foreach ($grades as $key => $grade) {
                    if (!isset($mygroupsusers[$grade->userid])) {
                        unset($grades[$key]);
                    }
                }

                // No break, fall through to the default case now we have filtered the $grades array.
            default:
            case NOGROUPS:
                // Single user mode.
                $numbest  = empty($this->config->showbest) ? 0 : min($this->config->showbest, count($grades));
                $numworst = empty($this->config->showworst) ? 0 : min($this->config->showworst, count($grades) - $numbest);

                // Collect all the usernames we are going to need.
                $remaining = $numbest;
                $grade = end($grades);
                while ($remaining--) {
                    $best[$grade->userid] = $grade->id;
                    $grade = prev($grades);
                }

                $remaining = $numworst;
                $grade = reset($grades);
                while ($remaining--) {
                    $worst[$grade->userid] = $grade->id;
                    $grade = next($grades);
                }

                if (empty($best) && empty($worst)) {
                    // Nothing to show, for some reason...
                    return $this->content;
                }

                // Now grab all the users from the database.
                $userids = array_merge(array_keys($best), array_keys($worst));
                $fields = array_merge(array('id', 'idnumber'), get_all_user_name_fields());
                $fields = implode(',', $fields);
                $users = $DB->get_records_list('user', 'id', $userids, '', $fields);

                // Ready for output!
                if ($activity->gradetype == GRADE_TYPE_SCALE) {
                    // We must display the results using scales.
                    $gradeformat = B_ACTIVITYRESULTS_GRADE_FORMAT_SCALE;
                    // Preload the scale.
                    $scale = $this->get_scale($activity->scaleid);
                } else if (intval(empty($this->config->gradeformat))) {
                    $gradeformat = B_ACTIVITYRESULTS_GRADE_FORMAT_PCT;
                } else {
                    $gradeformat = $this->config->gradeformat;
                }

                // Generate the header.
                $this->content->text .= $this->activity_link($activity, $cm);

                $rank = 0;
                if (!empty($best)) {
                    $this->content->text .= '<table class="grades"><caption>';
                    if ($numbest == 1) {
                        $this->content->text .= get_string('bestgrade', 'block_activity_results');
                    } else {
                        $this->content->text .= get_string('bestgrades', 'block_activity_results', $numbest);
                    }
                    $this->content->text .= '</caption><colgroup class="number" />';
                    $this->content->text .= '<colgroup class="name" /><colgroup class="grade" /><tbody>';
                    foreach ($best as $userid => $gradeid) {
                        switch ($nameformat) {
                            case B_ACTIVITYRESULTS_NAME_FORMAT_ID:
                                $thisname = get_string('user').' '.$users[$userid]->idnumber;
                            break;
                            case B_ACTIVITYRESULTS_NAME_FORMAT_ANON:
                                $thisname = get_string('user');
                            break;
                            default:
                            case B_ACTIVITYRESULTS_NAME_FORMAT_FULL:
                                if (has_capability('moodle/user:viewdetails', $context)) {
                                    $thisname = html_writer::link(new moodle_url('/user/view.php',
                                        array('id' => $userid, 'course' => $courseid)), fullname($users[$userid]));
                                } else {
                                    $thisname = fullname($users[$userid]);
                                }
                            break;
                        }
                        $this->content->text .= '<tr><td>'.(++$rank).'.</td><td>'.$thisname.'</td><td>';
                        switch ($gradeformat) {
                            case B_ACTIVITYRESULTS_GRADE_FORMAT_SCALE:
                                // Round answer up and locate appropriate scale.
                                $answer = (round($grades[$gradeid]->finalgrade, 0, PHP_ROUND_HALF_UP) - 1);
                                if (isset($scale[$answer])) {
                                    $this->content->text .= $scale[$answer];
                                } else {
                                    // Value is not in the scale.
                                    $this->content->text .= get_string('unknown', 'block_activity_results');
                                }
                            break;
                            case B_ACTIVITYRESULTS_GRADE_FORMAT_FRA:
                                $this->content->text .= $this->activity_format_grade($grades[$gradeid]->finalgrade);
                                $this->content->text .= '/'.$this->activity_format_grade($activity->grademax);
                            break;
                            case B_ACTIVITYRESULTS_GRADE_FORMAT_ABS:
                                $this->content->text .= $this->activity_format_grade($grades[$gradeid]->finalgrade);
                            break;
                            default:
                            case B_ACTIVITYRESULTS_GRADE_FORMAT_PCT:
                                if ($activity->grademax) {
                                    $this->content->text .= $this->activity_format_grade((float)$grades[$gradeid]->finalgrade /
                                            (float)$activity->grademax * 100).'%';
                                } else {
                                    $this->content->text .= '--%';
                                }
                            break;
                        }
                        $this->content->text .= '</td></tr>';
                    }
                    $this->content->text .= '</tbody></table>';
                }

                $rank = 0;
                if (!empty($worst)) {
                    $worst = array_reverse($worst, true);
                    $this->content->text .= '<table class="grades"><caption>';
                    if ($numbest == 1) {
                        $this->content->text .= get_string('worstgrade', 'block_activity_results');
                    } else {
                        $this->content->text .= get_string('worstgrades', 'block_activity_results', $numworst);
                    }
                    $this->content->text .= '</caption><colgroup class="number" />';
                    $this->content->text .= '<colgroup class="name" /><colgroup class="grade" /><tbody>';
                    foreach ($worst as $userid => $gradeid) {
                        switch ($nameformat) {
                            case B_ACTIVITYRESULTS_NAME_FORMAT_ID:
                                $thisname = get_string('user').' '.$users[$userid]->idnumber;
                            break;
                            case B_ACTIVITYRESULTS_NAME_FORMAT_ANON:
                                $thisname = get_string('user');
                            break;
                            default:
                            case B_ACTIVITYRESULTS_NAME_FORMAT_FULL:
                                if (has_capability('moodle/user:viewdetails', $context)) {
                                    $thisname = html_writer::link(new moodle_url('/user/view.php',
                                        array('id' => $userid, 'course' => $courseid)), fullname($users[$userid]));
                                } else {
                                    $thisname = fullname($users[$userid]);
                                }
                            break;
                        }
                        $this->content->text .= '<tr><td>'.(++$rank).'.</td><td>'.$thisname.'</td><td>';
                        switch ($gradeformat) {
                            case B_ACTIVITYRESULTS_GRADE_FORMAT_SCALE:
                                // Round answer up and locate appropriate scale.
                                $answer = (round($grades[$gradeid]->finalgrade, 0, PHP_ROUND_HALF_UP) - 1);
                                if (isset($scale[$answer])) {
                                    $this->content->text .= $scale[$answer];
                                } else {
                                    // Value is not in the scale.
                                    $this->content->text .= get_string('unknown', 'block_activity_results');
                                }
                            break;
                            case B_ACTIVITYRESULTS_GRADE_FORMAT_FRA:
                                $this->content->text .= $this->activity_format_grade($grades[$gradeid]->finalgrade);
                                $this->content->text .= '/'.$this->activity_format_grade($activity->grademax);
                            break;
                            case B_ACTIVITYRESULTS_GRADE_FORMAT_ABS:
                                $this->content->text .= $this->activity_format_grade($grades[$gradeid]->finalgrade);
                            break;
                            default:
                            case B_ACTIVITYRESULTS_GRADE_FORMAT_PCT:
                                if ($activity->grademax) {
                                    $this->content->text .= $this->activity_format_grade((float)$grades[$gradeid]->finalgrade /
                                            (float)$activity->grademax * 100).'%';
                                } else {
                                    $this->content->text .= '--%';
                                }
                            break;
                        }
                        $this->content->text .= '</td></tr>';
                    }
                    $this->content->text .= '</tbody></table>';
                }
            break;
        }

        return $this->content;
    }
825992
public function generate()
    {
        if (feof($this->h))
            rewind($this->h);

        return (float) fgets($this->h);
    }
1095382
public function Build()
    {
        $obj           = new \stdClass();
        $obj->metadata = $this->metadata;
        $obj->contents = $this->contents;

        return \json_encode($obj);
    }
876895
public function generate()
    {
        // Add empty option (XHTML) if there are none
        if (empty($this->arrOptions)) {
            $this->arrOptions = array(
                array(
                    'value' => '',
                    'label' => '-'
                )
            );
        }

        $strClass = ('' !== $this->strClass ? ' class="' . $this->strClass . '"' : '');
        $strStyle = ('' !== $this->arrAttributes['style'] ? ' style="' . $this->arrAttributes['style'] . '"' : '');

        return $this->checkOptGroup($this->arrOptions, $strClass, $strStyle);
    }
985334
public static function generate()
    {
        self::dispatchEvent(self::EVENT_GET_MENU);

        $return = '';

        // sort menu by it's order
        uksort(self::$menu, 'strnatcmp');;

        /** @var Menu $item */
        foreach (self::$menu as $item) {
            if ($item->resources && !self::userHasResource($item->resources)) {
                continue;
            }

            if ($children = $item->getChildren()) {
                $subItems = '';

                // sort menu by it's order
                uksort($children, 'strnatcmp');;

                /** @var Menu $child */
                foreach ($children as $child) {
                    if ($child->resources && !self::userHasResource($child->resources)) {
                        continue;
                    }

                    $subItems .= '<li><a href="' . $child->getLink() . '">' . $child->getLabel() . '</a></li>';
                }

                $return .= '<li class="treeview">
                  <a href="#">
                    <i class="fa ' . $item->getIcon() . '"></i>
                    <span>' . $item->getLabel() . '</span>
                    <i class="fa fa-angle-left pull-right"></i>
                  </a>
                  <ul class="treeview-menu">
                    ' . $subItems . '
                  </ul>
                </li>';
            } else {
                $return .= '<li>
                        <a href="' . $item->getLink() . '">
                            <i class="fa ' . $item->getIcon() . ' fa-fw"></i> <span>' . $item->getLabel() . '</span>
                        </a>
                    </li>';
            }
        }

        return $return;
    }
413714
public static function create()
    {
        $ob = new stdClass;
        $ob->value = self::DEFAULT_CONTENT_TYPE;

        return new self(null, $ob);
    }
116495
public function generate()
	{		
		// Get the content element object
		$this->objElement = \ElementsModel::findPublishedByAlias($this->type);

		if ($this->objElement === null)
		{
			return;
		}

		// Register the custom template
		if (!array_key_exists($this->objElement->template, TemplateLoader::getFiles()))
		{
			TemplateLoader::addFile($this->objElement->template, $this->objElement->getRelated('pid')->templates);
		}

		if (TL_MODE == 'BE' && $this->objElement->backendTpl)
		{
			$this->strTemplate = $this->objElement->backendTpl;
		}
		else
		{
			$this->strTemplate = $this->objElement->template;
		}
				
		if (TL_MODE == 'FE' && !BE_USER_LOGGED_IN && ($this->invisible || ($this->start != '' && $this->start > time()) || ($this->stop != '' && $this->stop < time())))
		{
			return '';
		}

		$this->Template = new Template($this->strTemplate);
	
		// Deliver some general element data
		$this->Template->setData(
			array (
				'id' => $this->id,
				'pid' => $this->pid,
				'ptable' => $this->ptable,
				'element' => $this->type,
				'tstamp' => $this->tstamp,
				'start' => $this->start,
				'stop' => $this->stop,
				'protected' => $this->protected,
				'inColumn' => $this->strColumn
			)
		);

		// compile pattern to prepare values
		$this->compile();
		
		return $this->Template->parse();
	}
1222908
protected function Init()
    {
        $block = ContentBlock::Schema()->ByContent($this->content);
        $this->tag = $block->GetTagName();
        return parent::Init();
    }