public function output_select_html($data, $current, $default, $extraname = '')
 {
     $warning = '';
     $output = '';
     if (empty($current)) {
         $current = $default;
     }
     foreach ($this->options as $value => $label) {
         $attributes = array();
         $attributes['id'] = html_writer::random_id('checkbox_');
         $attributes['type'] = 'radio';
         $attributes['value'] = $value;
         $attributes['name'] = $this->get_full_name();
         $attributes['class'] = 'form-checkbox';
         if ($current == $value) {
             $attributes['checked'] = 'checked';
         }
         $radiohtml = html_writer::empty_tag('input', $attributes);
         $labelhtml = html_writer::tag('label', ' ' . $label, array('for' => $attributes['id']));
         $output .= $radiohtml;
         $output .= $labelhtml;
         $output .= html_writer::empty_tag('br');
     }
     return array($output, $warning);
 }
Esempio n. 2
0
 /**
  * Init the random variable and return it as a string.
  *
  * @return string random id.
  */
 public function __toString()
 {
     if ($this->uniqid === null) {
         $this->uniqid = \html_writer::random_id(uniqid());
     }
     return $this->uniqid;
 }
Esempio n. 3
0
function fetchSWFWidgetCode($widget, $params, $width, $height, $bgcolor = "#FFFFFF")
{
    global $CFG;
    $widgetid = html_writer::random_id('laszlobase');
    $widgetjson = \filter_poodll\poodlltools::fetchSWFWidgetJSON($widget, $params, $width, $height, $bgcolor = "#FFFFFF", $widgetid);
    $retcode = html_writer::div('', '', array('id' => $widgetid . 'Container'));
    $retcode .= '<script type="text/javascript" src="' . $CFG->httpswwwroot . '/filter/poodll/flash/embed-compressed.js"></script>
        <script type="text/javascript"> lz.embed.swf(' . $widgetjson . ')</script>';
    return $retcode;
}
Esempio n. 4
0
    /**
     * Returns HTML to display choices of option
     * @param object $options
     * @param int  $coursemoduleid
     * @param bool $vertical
     * @return string
     */
    public function display_options($options, $coursemoduleid, $vertical = false) {
        $layoutclass = 'horizontal';
        if ($vertical) {
            $layoutclass = 'vertical';
        }
        $target = new moodle_url('/mod/choice/view.php');
        //changed below to post from target john
        $attributes = array('method'=>'POST', 'action'=>$target, 'class'=> $layoutclass);

        $html = html_writer::start_tag('form', $attributes);
        $html .= html_writer::start_tag('ul', array('class'=>'choices', 'data-role'=>'controlgroup' ));

        $availableoption = count($options['options']);
        foreach ($options['options'] as $option) {
            $html .= html_writer::start_tag('li', array('class'=>'option'));
            $option->attributes->name = 'answer';
            $option->attributes->type = 'radio';
            $option->attributes->id = 'answer'.html_writer::random_id();

            $labeltext = $option->text;
            if (!empty($option->attributes->disabled)) {
                $labeltext .= ' ' . get_string('full', 'choice');
                $availableoption--;
            }

            $html .= html_writer::empty_tag('input', (array)$option->attributes);
            $html .= html_writer::tag('label', $labeltext, array('for'=>$option->attributes->id));
            $html .= html_writer::end_tag('li');
        }
        $html .= html_writer::tag('li','', array('class'=>'clearfloat'));
        $html .= html_writer::end_tag('ul');
        $html .= html_writer::tag('div', '', array('class'=>'clearfloat'));
        $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey()));
        $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=>$coursemoduleid));

        if (!empty($options['hascapability']) && ($options['hascapability'])) {
            if ($availableoption < 1) {
               $html .= html_writer::tag('label', get_string('choicefull', 'choice'));
            } else {
                $html .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('savemychoice','choice'), 'class'=>'button'));
            }

            if (!empty($options['allowupdate']) && ($options['allowupdate'])) {
                $url = new moodle_url('view.php', array('id'=>$coursemoduleid, 'action'=>'delchoice', 'sesskey'=>sesskey()));
                $html .= html_writer::link($url, get_string('removemychoice','choice'));
            }
        } else {
            $html .= html_writer::tag('label', get_string('havetologin', 'choice'));
        }

        $html .= html_writer::end_tag('ul');
        $html .= html_writer::end_tag('form');

        return $html;
    }
Esempio n. 5
0
 /**
  * Rendering assignment files
  *
  * @param assign_files $tree
  * @return string
  */
 public function render_assign_files(assign_files $tree)
 {
     $this->htmlid = html_writer::random_id('assign_files_tree');
     $this->page->requires->js_init_call('M.mod_assign.init_tree', array(true, $this->htmlid));
     $html = '<div id="' . $this->htmlid . '">';
     $html .= $this->htmllize_tree($tree, $tree->dir);
     $html .= '</div>';
     if ($tree->portfolioform) {
         $html .= $tree->portfolioform;
     }
     return $html;
 }
Esempio n. 6
0
 /**
  * Renderers a structured array of courses and categories into a nice
  * XHTML tree structure.
  *
  * This method was designed initially to display the front page course/category
  * combo view. The structure can be retrieved by get_course_category_tree()
  *
  * @param array $structure
  * @return string
  */
 public function course_category_tree(array $structure)
 {
     $this->strings->summary = get_string('summary');
     // Generate an id and the required JS call to make this a nice widget
     $id = html_writer::random_id('course_category_tree');
     $this->page->requires->js_init_call('M.util.init_toggle_class_on_click', array($id, '.category.with_children .category_label', 'collapsed', '.category.with_children'));
     // Start content generation
     $content = html_writer::start_tag('div', array('class' => 'course_category_tree', 'id' => $id));
     foreach ($structure as $category) {
         $content .= $this->course_category_tree_category($category);
     }
     $content .= html_writer::start_tag('div', array('class' => 'controls'));
     $content .= html_writer::tag('div', get_string('collapseall'), array('class' => 'addtoall expandall'));
     $content .= html_writer::tag('div', get_string('expandall'), array('class' => 'removefromall collapseall'));
     $content .= html_writer::end_tag('div');
     $content .= html_writer::end_tag('div');
     // Return the course category tree HTML
     return $content;
 }
Esempio n. 7
0
 /**
  * Render for the select user button.
  *
  * @param user_button $button instance of  gradereport_history_user_button to render
  *
  * @return string HTML to display
  */
 protected function render_user_button(user_button $button)
 {
     $attributes = array('type' => 'button', 'class' => 'selectortrigger', 'value' => $button->label, 'disabled' => $button->disabled ? 'disabled' : null, 'title' => $button->tooltip);
     if ($button->actions) {
         $id = \html_writer::random_id('single_button');
         $attributes['id'] = $id;
         foreach ($button->actions as $action) {
             $this->add_action_handler($action, $id);
         }
     }
     // First the input element.
     $output = \html_writer::empty_tag('input', $attributes);
     // Then hidden fields.
     $params = $button->url->params();
     if ($button->method === 'post') {
         $params['sesskey'] = sesskey();
     }
     foreach ($params as $var => $val) {
         $output .= \html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $var, 'value' => $val));
     }
     // Then div wrapper for xhtml strictness.
     $output = \html_writer::tag('div', $output);
     // Now the form itself around it.
     if ($button->method === 'get') {
         $url = $button->url->out_omit_querystring(true);
         // Url without params, the anchor part allowed.
     } else {
         $url = $button->url->out_omit_querystring();
         // Url without params, the anchor part not allowed.
     }
     if ($url === '') {
         $url = '#';
         // There has to be always some action.
     }
     $attributes = array('method' => $button->method, 'action' => $url, 'id' => $button->formid);
     $output = \html_writer::tag('div', $output, $attributes);
     // Finally one more wrapper with class.
     return \html_writer::tag('div', $output, array('class' => $button->class));
 }
Esempio n. 8
0
 /**
  * Returns HTML to display a tree of subcategories and courses in the given category
  *
  * @param coursecat_helper $chelper various display options
  * @param coursecat $coursecat top category (this category's name and description will NOT be added to the tree)
  * @return string
  */
 protected function coursecat_tree(coursecat_helper $chelper, $coursecat)
 {
     $categorycontent = $this->coursecat_category_content($chelper, $coursecat, 0);
     if (empty($categorycontent)) {
         return '';
     }
     // Generate an id and the required JS call to make this a nice widget
     $id = html_writer::random_id('course_category_tree');
     $this->page->requires->js_init_call('M.util.init_toggle_class_on_click', array($id, '.category.with_children.loaded > .info .name', 'collapsed', '.category.with_children.loaded'));
     // Start content generation
     $content = '';
     $attributes = $chelper->get_and_erase_attributes('course_category_tree clearfix');
     $content .= html_writer::start_tag('div', array('id' => $id, 'data-showcourses' => $chelper->get_show_courses()) + $attributes);
     $content .= html_writer::tag('div', $categorycontent, array('class' => 'content'));
     if ($coursecat->get_children_count() && $chelper->get_subcat_depth() != 1) {
         // We don't need to display "Expand all"/"Collapse all" buttons if there are no
         // subcategories or there is only one level of subcategories loaded
         // TODO if subcategories are loaded by AJAX this might still be needed!
         $content .= html_writer::start_tag('div', array('class' => 'controls'));
         $content .= html_writer::tag('div', get_string('collapseall'), array('class' => 'addtoall expandall'));
         $content .= html_writer::tag('div', get_string('expandall'), array('class' => 'removefromall collapseall'));
         $content .= html_writer::end_tag('div');
     }
     $content .= html_writer::end_tag('div');
     // .course_category_tree
     return $content;
 }
Esempio n. 9
0
 /**
  * Generates code required to embed the player.
  *
  * @param array $urls Moodle URLs of media files
  * @param string $name Display name; '' to use default
  * @param int $width Optional width; 0 to use default
  * @param int $height Optional height; 0 to use default
  * @param array $options Options array
  *                       image
  *                           use 'image' key with a moodle_url to an image as poster image
  *                           displayed before playback starts.
  *                       subtitles
  *                           use 'subtitles' key with an array of subtitle track files
  *                           in vtt or srt format indexed by label name.
  *                           Example: $options['subtitles']['English'] = http://example.com/english.vtt
  * @return string HTML code for embed
  */
 public function embed($urls, $name, $width, $height, $options)
 {
     global $PAGE, $CFG;
     // We do embedding only here. JW player setup is done in the filter.
     $output = '';
     $sources = array();
     $playersetupdata = array();
     $isstream = false;
     foreach ($urls as $url) {
         // Add the details for this source.
         $source = array('file' => urldecode($url->out(false)));
         // Help to determine the type of mov.
         $ext = strtolower(pathinfo($url, PATHINFO_EXTENSION));
         if ($ext === 'mov') {
             $source['type'] = 'mp4';
         }
         if ($url->get_scheme() === 'rtmp' || $ext === 'm3u8' || $ext === 'smil') {
             // For RTMP, HLS and Dynamic RTMP we set rendering mode to Flash to
             // ensure streams play is possible even when mp4 fallbacks are given.
             // Also make sure that URL is the first in the list.
             $playersetupdata['primary'] = 'flash';
             array_unshift($sources, $source);
             $isstream = true;
         } else {
             $sources[] = $source;
         }
     }
     if (count($sources) > 0) {
         $playerid = 'filter_jwplayer_media_' . html_writer::random_id();
         $playersetupdata['title'] = $this->get_name('', $urls);
         $playlistitem = array('sources' => $sources);
         // Setup poster image.
         if (isset($options['image'])) {
             $playlistitem['image'] = urldecode($options['image']->out(false));
         } else {
             if ($poster = get_config('filter_jwplayer', 'defaultposter')) {
                 $syscontext = context_system::instance();
                 $playlistitem['image'] = moodle_url::make_pluginfile_url($syscontext->id, 'filter_jwplayer', 'defaultposter', null, null, $poster)->out(true);
             }
         }
         // Setup subtitle tracks.
         if (isset($options['subtitles'])) {
             $tracks = array();
             foreach ($options['subtitles'] as $label => $subtitlefileurl) {
                 $tracks[] = array('file' => urldecode($subtitlefileurl->out(false)), 'label' => $label);
             }
             $playlistitem['tracks'] = $tracks;
         }
         $playersetupdata['playlist'] = array($playlistitem);
         // If we are dealing with audio, show just the control bar.
         if (mimeinfo('string', $sources[0]['file']) === 'audio') {
             $width = FILTER_JWPLAYER_AUDIO_WIDTH;
             $height = FILTER_JWPLAYER_AUDIO_HEIGHT;
         }
         // If width is not provided, use default.
         if (!$width) {
             // Use responsive width if choosen in settings otherwise default to fixed width.
             if (get_config('filter_jwplayer', 'displaystyle') === 'responsive') {
                 $width = FILTER_JWPLAYER_VIDEO_WIDTH_RESPONSIVE;
             } else {
                 $width = FILTER_JWPLAYER_VIDEO_WIDTH;
             }
         }
         if (is_numeric($width)) {
             $width = round($width);
         }
         $playersetupdata['width'] = $width;
         // If width is a percentage surrounding span needs to have its width set so it does not default to 0px.
         $outerspanargs = array('class' => 'filter_jwplayer_playerblock');
         if (!is_numeric($width)) {
             $outerspanargs['style'] = 'width: ' . $width . ';';
             $width = '100%';
             // As the outer span in now at the required width, we set the width of the player to 100%.
         }
         // Automatically set the height unless it is specified.
         if ($height) {
             if (is_numeric($height)) {
                 $playersetupdata['height'] = $height;
             } else {
                 if (is_numeric($width)) {
                     // If width is numeric and height is percentage, calculate height from width.
                     $playersetupdata['height'] = round($width * floatval($height) / 100);
                 } else {
                     // If width is also percentage, then set aspect ratio.
                     $playersetupdata['aspectratio'] = "100:" . floatval($height);
                 }
             }
         } else {
             if (is_numeric($width)) {
                 // If width is numeric calculate height from default aspect ratio.
                 $playersetupdata['height'] = round($width * FILTER_JWPLAYER_VIDEO_ASPECTRATIO_H / FILTER_JWPLAYER_VIDEO_ASPECTRATIO_W);
             } else {
                 // Responsive videos need aspect ratio set to automatically set height.
                 $playersetupdata['aspectratio'] = FILTER_JWPLAYER_VIDEO_ASPECTRATIO_W . ":" . FILTER_JWPLAYER_VIDEO_ASPECTRATIO_H;
             }
         }
         // Load skin.
         if ($customskin = get_config('filter_jwplayer', 'customskin')) {
             $syscontext = context_system::instance();
             $playersetupdata['skin'] = moodle_url::make_pluginfile_url($syscontext->id, 'filter_jwplayer', 'playerskin', null, null, $customskin)->out(true);
         } else {
             if ($skin = get_config('filter_jwplayer', 'skin')) {
                 $playersetupdata['skin'] = $skin;
             }
         }
         $downloadbtn = null;
         if (get_config('filter_jwplayer', 'downloadbutton') && !$isstream) {
             $downloadbtn = array('img' => $CFG->wwwroot . '/filter/jwplayer/img/download.png', 'tttext' => get_string('videodownloadbtntttext', 'filter_jwplayer'));
         }
         if (get_config('filter_jwplayer', 'googleanalytics')) {
             $playersetupdata['ga'] = array('trackingobject' => get_config('filter_jwplayer', 'gatrackingobject'));
         }
         $playersetup = array('playerid' => $playerid, 'setupdata' => $playersetupdata, 'downloadbtn' => $downloadbtn);
         // Set up the player.
         $jsmodule = array('name' => $playerid, 'fullpath' => '/filter/jwplayer/module.js');
         $this->setup();
         $PAGE->requires->js_init_call('M.filter_jwplayer.init', $playersetup, true, $jsmodule);
         $playerdiv = html_writer::tag('span', $this->get_name('', $urls), array('id' => $playerid));
         $outerspan = html_writer::tag('span', $playerdiv, $outerspanargs);
         $output .= html_writer::tag('span', $outerspan, array('class' => 'filter_jwplayer_media'));
     }
     return $output;
 }
Esempio n. 10
0
 /**
  * Render the editpdf widget in the grading form.
  *
  * @param assignfeedback_editpdf_widget $widget - Renderable widget containing assignment, user and attempt number.
  * @return string
  */
 public function render_assignfeedback_editpdf_widget(assignfeedback_editpdf_widget $widget)
 {
     global $CFG;
     $html = '';
     $html .= html_writer::div(get_string('jsrequired', 'assignfeedback_editpdf'), 'hiddenifjs');
     $linkid = html_writer::random_id();
     if ($widget->readonly) {
         $launcheditorlink = html_writer::tag('a', get_string('viewfeedbackonline', 'assignfeedback_editpdf'), array('id' => $linkid, 'class' => 'btn', 'href' => '#'));
     } else {
         $launcheditorlink = html_writer::tag('a', get_string('launcheditor', 'assignfeedback_editpdf'), array('id' => $linkid, 'class' => 'btn', 'href' => '#'));
     }
     $links = $launcheditorlink;
     $links .= html_writer::tag('div', get_string('unsavedchanges', 'assignfeedback_editpdf'), array('class' => 'assignfeedback_editpdf_unsavedchanges warning'));
     $html .= html_writer::div($links, 'visibleifjs');
     $header = get_string('pluginname', 'assignfeedback_editpdf');
     $body = '';
     // Create the page navigation.
     $navigation1 = '';
     $navigation2 = '';
     // Pick the correct arrow icons for right to left mode.
     if (right_to_left()) {
         $nav_prev = 'nav_next';
         $nav_next = 'nav_prev';
     } else {
         $nav_prev = 'nav_prev';
         $nav_next = 'nav_next';
     }
     $iconalt = get_string('navigateprevious', 'assignfeedback_editpdf');
     $iconhtml = $this->pix_icon($nav_prev, $iconalt, 'assignfeedback_editpdf');
     $navigation1 .= html_writer::tag('button', $iconhtml, array('disabled' => 'true', 'class' => 'navigate-previous-button', 'accesskey' => $this->get_shortcut('navigate-previous-button')));
     $navigation1 .= html_writer::tag('select', null, array('disabled' => 'true', 'aria-label' => get_string('gotopage', 'assignfeedback_editpdf'), 'class' => 'navigate-page-select', 'accesskey' => $this->get_shortcut('navigate-page-select')));
     $iconalt = get_string('navigatenext', 'assignfeedback_editpdf');
     $iconhtml = $this->pix_icon($nav_next, $iconalt, 'assignfeedback_editpdf');
     $navigation1 .= html_writer::tag('button', $iconhtml, array('disabled' => 'true', 'class' => 'navigate-next-button', 'accesskey' => $this->get_shortcut('navigate-next-button')));
     $navigation1 = html_writer::div($navigation1, 'navigation', array('role' => 'navigation'));
     $navigation2 .= $this->render_toolbar_button('comment_search', 'searchcomments', $this->get_shortcut('searchcomments'));
     $navigation2 = html_writer::div($navigation2, 'navigation-search', array('role' => 'navigation'));
     $toolbar1 = '';
     $toolbar2 = '';
     $toolbar3 = '';
     $toolbar4 = '';
     $clearfix = html_writer::div('', 'clearfix');
     if (!$widget->readonly) {
         // Comments.
         $toolbar1 .= $this->render_toolbar_button('comment', 'comment', $this->get_shortcut('comment'));
         $toolbar1 .= $this->render_toolbar_button('background_colour_clear', 'commentcolour', $this->get_shortcut('commentcolour'));
         $toolbar1 = html_writer::div($toolbar1, 'toolbar', array('role' => 'toolbar'));
         // Select Tool.
         $toolbar2 .= $this->render_toolbar_button('select', 'select', $this->get_shortcut('select'));
         $toolbar2 = html_writer::div($toolbar2, 'toolbar', array('role' => 'toolbar'));
         // Other Tools.
         $toolbar3 = $this->render_toolbar_button('pen', 'pen', $this->get_shortcut('pen'));
         $toolbar3 .= $this->render_toolbar_button('line', 'line', $this->get_shortcut('line'));
         $toolbar3 .= $this->render_toolbar_button('rectangle', 'rectangle', $this->get_shortcut('rectangle'));
         $toolbar3 .= $this->render_toolbar_button('oval', 'oval', $this->get_shortcut('oval'));
         $toolbar3 .= $this->render_toolbar_button('highlight', 'highlight', $this->get_shortcut('highlight'));
         $toolbar3 .= $this->render_toolbar_button('background_colour_clear', 'annotationcolour', $this->get_shortcut('annotationcolour'));
         $toolbar3 = html_writer::div($toolbar3, 'toolbar', array('role' => 'toolbar'));
         // Stamps.
         $toolbar4 .= $this->render_toolbar_button('stamp', 'stamp', 'n');
         $toolbar4 .= $this->render_toolbar_button('background_colour_clear', 'currentstamp', $this->get_shortcut('currentstamp'));
         $toolbar4 = html_writer::div($toolbar4, 'toolbar', array('role' => 'toolbar'));
     }
     // Toobars written in reverse order because they are floated right.
     $pageheader = html_writer::div($navigation1 . $navigation2 . $toolbar4 . $toolbar3 . $toolbar2 . $toolbar1 . $clearfix, 'pageheader');
     $body = $pageheader;
     // Loading progress bar.
     $progressbar = html_writer::div('', 'bar', array('style' => 'width: 0%'));
     $progressbar = html_writer::div($progressbar, 'progress progress-info progress-striped active', array('title' => get_string('loadingeditor', 'assignfeedback_editpdf'), 'role' => 'progressbar', 'aria-valuenow' => 0, 'aria-valuemin' => 0, 'aria-valuemax' => 100));
     $progressbarlabel = html_writer::div(get_string('generatingpdf', 'assignfeedback_editpdf'), 'progressbarlabel');
     $loading = html_writer::div($progressbar . $progressbarlabel, 'loading');
     $canvas = html_writer::div($loading, 'drawingcanvas');
     $body .= html_writer::div($canvas, 'drawingregion');
     $body .= '<hr/>';
     $footer = '';
     $editorparams = array(array('header' => $header, 'body' => $body, 'footer' => $footer, 'linkid' => $linkid, 'assignmentid' => $widget->assignment, 'userid' => $widget->userid, 'attemptnumber' => $widget->attemptnumber, 'stampfiles' => $widget->stampfiles, 'readonly' => $widget->readonly, 'pagetotal' => $widget->pagetotal));
     $this->page->requires->yui_module('moodle-assignfeedback_editpdf-editor', 'M.assignfeedback_editpdf.editor.init', $editorparams);
     $this->page->requires->strings_for_js(array('yellow', 'white', 'red', 'blue', 'green', 'black', 'clear', 'colourpicker', 'loadingeditor', 'pagexofy', 'deletecomment', 'addtoquicklist', 'filter', 'searchcomments', 'commentcontextmenu', 'deleteannotation', 'stamp', 'stamppicker', 'cannotopenpdf', 'pagenumber'), 'assignfeedback_editpdf');
     return $html;
 }
 protected function render_help_icon(help_icon $helpicon)
 {
     global $CFG;
     $output = bootstrap::icon_help();
     if (!empty($helpicon->linktext)) {
         $output .= ' ' . $helpicon->linktext;
     }
     $url = new moodle_url($CFG->httpswwwroot . '/help.php', array('component' => $helpicon->component, 'identifier' => $helpicon->identifier, 'lang' => current_language()));
     $title = get_string($helpicon->identifier, $helpicon->component);
     $title = get_string('helpprefix2', '', trim($title, ". \t"));
     $id = html_writer::random_id('helpicon');
     $attributes = array('href' => $url, 'title' => $title, 'id' => $id);
     $output = html::a($attributes, $output);
     $this->page->requires->js_init_call('M.util.help_icon.add', array(array('id' => $id, 'url' => $url->out(false))));
     return $output;
 }
 /**
  * Rendering a list of student, to be displayed within a larger table
  *
  * @param scheduler_slot_table $slottable the table to rended
  * @return string the HTML output
  */
 public function render_scheduler_student_list(scheduler_student_list $studentlist)
 {
     $o = '';
     $toggleid = html_writer::random_id('toggle');
     if ($studentlist->expandable && count($studentlist->students) > 0) {
         $this->page->requires->yui_module('moodle-mod_scheduler-studentlist', 'M.mod_scheduler.studentlist.init', array($toggleid, (bool) $studentlist->expanded));
         $imgclass = 'studentlist-togglebutton';
         $alttext = get_string('showparticipants', 'scheduler');
         $o .= $this->output->pix_icon('t/switch', $alttext, 'moodle', array('id' => $toggleid, 'class' => $imgclass));
     }
     $divprops = array('id' => 'list' . $toggleid);
     $o .= html_writer::start_div('studentlist', $divprops);
     if (count($studentlist->students) > 0) {
         $editable = $studentlist->actionurl && $studentlist->editable;
         if ($editable) {
             $o .= html_writer::start_tag('form', array('action' => $studentlist->actionurl, 'method' => 'post', 'class' => 'studentselectform'));
         }
         foreach ($studentlist->students as $student) {
             $class = 'otherstudent';
             $checkbox = '';
             if ($studentlist->checkboxname) {
                 if ($editable) {
                     $checkbox = html_writer::checkbox($studentlist->checkboxname, $student->entryid, $student->checked, '', array('class' => 'studentselect'));
                 } else {
                     $img = $student->checked ? 'ticked' : 'unticked';
                     $checkbox = $this->render(new pix_icon($img, '', 'scheduler', array('class' => 'statictickbox')));
                 }
             }
             if ($studentlist->linkappointment) {
                 $name = $this->appointment_link($studentlist->scheduler, $student->user, $student->entryid);
             } else {
                 $name = fullname($student->user);
             }
             if ($student->highlight) {
                 $class .= ' highlight';
             }
             $picture = $this->user_picture($student->user, array('courseid' => $studentlist->scheduler->courseid));
             $grade = '';
             if ($studentlist->showgrades && $student->grade) {
                 $grade = $this->format_grade($studentlist->scheduler, $student->grade, true);
             }
             $o .= html_writer::div($checkbox . $picture . ' ' . $name . ' ' . $grade, $class);
         }
         if ($editable) {
             $o .= html_writer::empty_tag('input', array('type' => 'submit', 'class' => 'studentselectsubmit', 'value' => $studentlist->buttontext));
             $o .= html_writer::end_tag('form');
         }
     }
     $o .= html_writer::end_div();
     return $o;
 }
Esempio n. 13
0
 /**
  * Internal implementation of user image rendering.
  * @param user_picture $userpicture
  * @return string
  */
 protected function render_user_picture(user_picture $userpicture)
 {
     global $CFG, $DB;
     $user = $userpicture->user;
     if ($userpicture->alttext) {
         if (!empty($user->imagealt)) {
             $alt = $user->imagealt;
         } else {
             $alt = get_string('pictureof', '', fullname($user));
         }
     } else {
         $alt = '';
     }
     if (empty($userpicture->size)) {
         $file = 'f2';
         $size = 35;
     } else {
         if ($userpicture->size === true or $userpicture->size == 1) {
             $file = 'f1';
             $size = 100;
         } else {
             if ($userpicture->size >= 50) {
                 $file = 'f1';
                 $size = $userpicture->size;
             } else {
                 $file = 'f2';
                 $size = $userpicture->size;
             }
         }
     }
     $class = $userpicture->class;
     if ($user->picture == 1) {
         $usercontext = get_context_instance(CONTEXT_USER, $user->id);
         $src = moodle_url::make_pluginfile_url($usercontext->id, 'user', 'icon', NULL, '/', $file);
     } else {
         if ($user->picture == 2) {
             //TODO: gravatar user icon support
         } else {
             // Print default user pictures (use theme version if available)
             $class .= ' defaultuserpic';
             $src = $this->pix_url('u/' . $file);
         }
     }
     $attributes = array('src' => $src, 'alt' => $alt, 'title' => $alt, 'class' => $class, 'width' => $size, 'height' => $size);
     // get the image html output fisrt
     $output = html_writer::empty_tag('img', $attributes);
     // then wrap it in link if needed
     if (!$userpicture->link) {
         return $output;
     }
     if (empty($userpicture->courseid)) {
         $courseid = $this->page->course->id;
     } else {
         $courseid = $userpicture->courseid;
     }
     if ($courseid == SITEID) {
         $url = new moodle_url('/user/profile.php', array('id' => $user->id));
     } else {
         $url = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $courseid));
     }
     $attributes = array('href' => $url);
     if ($userpicture->popup) {
         $id = html_writer::random_id('userpicture');
         $attributes['id'] = $id;
         $this->add_action_handler(new popup_action('click', $url), $id);
     }
     return html_writer::tag('a', $output, $attributes);
 }
Esempio n. 14
0
 /**
  * Add short static javascript code fragment to page footer.
  * This is intended primarily for loading of js modules and initialising page layout.
  * Ideally the JS code fragment should be stored in plugin renderer so that themes
  * may override it.
  *
  * @param string $jscode
  * @param bool $ondomready wait for dom ready (helps with some IE problems when modifying DOM)
  * @param array $module JS module specification array
  */
 public function js_init_code($jscode, $ondomready = false, array $module = null)
 {
     $jscode = trim($jscode, " ;\n") . ';';
     $uniqid = html_writer::random_id();
     $startjs = " M.util.js_pending('" . $uniqid . "');";
     $endjs = " M.util.js_complete('" . $uniqid . "');";
     if ($module) {
         $this->js_module($module);
         $modulename = $module['name'];
         $jscode = "{$startjs} Y.use('{$modulename}', function(Y) { {$jscode} {$endjs} });";
     }
     if ($ondomready) {
         $jscode = "{$startjs} Y.on('domready', function() { {$jscode} {$endjs} });";
     }
     $this->jsinitcode[] = $jscode;
 }
Esempio n. 15
0
 /**
  * Generates code required to embed the player.
  *
  * @param array $urls Moodle URLs of media files
  * @param string $name Display name; '' to use default
  * @param int $width Optional width; 0 to use default
  * @param int $height Optional height; 0 to use default
  * @param array $options Options array
  *                       image
  *                           use 'image' key with a moodle_url to an image as poster image
  *                           displayed before playback starts.
  *                       subtitles
  *                           use 'subtitles' key with an array of subtitle track files
  *                           in vtt or srt format indexed by label name.
  *                           Example: $options['subtitles']['English'] = http://example.com/english.vtt
  * @return string HTML code for embed
  */
 public function embed($urls, $name, $width, $height, $options)
 {
     global $PAGE, $CFG;
     // We do embedding only here. JW player setup is done in the filter.
     $output = '';
     $sources = array();
     $streams = array();
     $playersetupdata = array();
     foreach ($urls as $url) {
         // Add the details for this source.
         $source = array('file' => urldecode($url->out(false)));
         // Help to determine the type of mov.
         $ext = core_media::get_extension($url);
         if ($ext === 'mov') {
             $source['type'] = 'mp4';
         }
         if ($ext === 'mpd') {
             // Dash variable needs to be set if we have a dash stream_bucket_append
             $playersetupdata['dash'] = true;
             $streams[] = $source;
         } else {
             if ($url->get_scheme() === 'rtmp' || $ext === 'm3u8' || $ext === 'smil') {
                 // For RTMP, HLS and Dynamic RTMP we set rendering mode to Flash to
                 // ensure streams play is possible even when mp4 fallbacks are given.
                 $playersetupdata['primary'] = 'flash';
                 $streams[] = $source;
             } else {
                 $sources[] = $source;
             }
         }
     }
     // Make sure that stream URLs are at the start of the list.
     $sources = array_merge($streams, $sources);
     if (count($sources) > 0) {
         $playerid = 'filter_jwplayer_media_' . html_writer::random_id();
         // Process data-jwplayer attributes.
         if (!empty($options['htmlattributes'])) {
             foreach ($options['htmlattributes'] as $attrib => $atval) {
                 if (strpos($attrib, 'data-jwplayer-') === 0) {
                     // Treat attributes starting data-jwplayer as options.
                     $opt = preg_replace('~^data-jwplayer-~', '', $attrib);
                     $atval = trim((string) $atval);
                     if (strpos($atval, ': ') || strpos($atval, '; ') || strpos($atval, ', ')) {
                         // If attribute contains any of :;, it needs to be split to an array.
                         $atvalarray = preg_split('~[,;] ~', $atval);
                         $newatval = array();
                         foreach ($atvalarray as $dataval) {
                             $newdata = explode(': ', $dataval, 2);
                             if (count($newdata) > 1) {
                                 $newdata[1] = trim($newdata[1]);
                                 if (filter_var($newdata[1], FILTER_VALIDATE_URL)) {
                                     // If value is a URL convert to moodle_url.
                                     $newdata[1] = new moodle_url($newdata[1]);
                                 }
                                 $newatval[trim($newdata[0])] = $newdata[1];
                             } else {
                                 $newdata[0] = trim($newdata[0]);
                                 if (filter_var($newdata[0], FILTER_VALIDATE_URL)) {
                                     // If value is a URL convert to moodle_url.
                                     $newdata[0] = new moodle_url($newdata[0]);
                                 }
                                 $newatval[] = $newdata[0];
                             }
                         }
                         $atval = $newatval;
                     } else {
                         if (filter_var($atval, FILTER_VALIDATE_URL)) {
                             // If value is a URL convert to moodle_url.
                             $atval = new moodle_url($atval);
                         }
                     }
                     $options[$opt] = $atval;
                 } else {
                     // Pass any other global HTML attributes to the player span tag.
                     $globalhtmlattributes = array('accesskey', 'class', 'contenteditable', 'contextmenu', 'dir', 'draggable', 'dropzone', 'hidden', 'id', 'lang', 'spellcheck', 'style', 'tabindex', 'title', 'translate');
                     if (in_array($attrib, $globalhtmlattributes) || strpos($attrib, 'data-' === 0)) {
                         $newattributes[$attrib] = $atval;
                     }
                 }
             }
         }
         // Set up playlist.
         $playlistitem = array('sources' => $sources);
         // Set Title from title attribute of a tag if it has one if not default to filename.
         if (isset($options['htmlattributes']['title'])) {
             $playlistitem['title'] = (string) $options['htmlattributes']['title'];
         } else {
             $playlistitem['title'] = $this->get_name('', $urls);
         }
         // Setup video description.
         if (isset($options['description'])) {
             $playlistitem['description'] = $options['description'];
         }
         // Setup video mediaid and use this for the playerid.
         if (isset($options['mediaid']) && strlen(trim($options['mediaid']))) {
             $playlistitem['mediaid'] = $options['mediaid'];
             $playerid = 'filter_jwplayer_media_' . preg_replace('/\\s+/', '', $options['mediaid']);
         }
         // Setup poster image.
         if (isset($options['image']) && $options['image'] instanceof moodle_url) {
             $playlistitem['image'] = urldecode($options['image']->out(false));
         } else {
             if ($poster = get_config('filter_jwplayer', 'defaultposter')) {
                 $syscontext = context_system::instance();
                 $playlistitem['image'] = moodle_url::make_pluginfile_url($syscontext->id, 'filter_jwplayer', 'defaultposter', null, null, $poster)->out(true);
             }
         }
         // Setup subtitle tracks.
         if (isset($options['subtitles'])) {
             $tracks = array();
             foreach ($options['subtitles'] as $label => $subtitlefileurl) {
                 if ($subtitlefileurl instanceof moodle_url) {
                     $tracks[] = array('file' => urldecode($subtitlefileurl->out(false)), 'label' => $label);
                 }
             }
             $playlistitem['tracks'] = $tracks;
         }
         $playersetupdata['playlist'] = array($playlistitem);
         // If width and/or height are set in the options override those from URL or defaults.
         if (isset($options['width'])) {
             $width = $options['width'];
         }
         if (isset($options['height'])) {
             $height = $options['height'];
         }
         // If we are dealing with audio, show just the control bar.
         if (mimeinfo('string', $sources[0]['file']) === 'audio') {
             $width = FILTER_JWPLAYER_AUDIO_WIDTH;
             $height = FILTER_JWPLAYER_AUDIO_HEIGHT;
         }
         // If width is not provided, use default.
         if (!$width) {
             // Use responsive width if choosen in settings otherwise default to fixed width.
             if (get_config('filter_jwplayer', 'displaystyle') === 'responsive') {
                 $width = FILTER_JWPLAYER_VIDEO_WIDTH_RESPONSIVE;
             } else {
                 $width = FILTER_JWPLAYER_VIDEO_WIDTH;
             }
         }
         if (is_numeric($width)) {
             $width = round($width);
         }
         $playersetupdata['width'] = $width;
         // If width is a percentage surrounding span needs to have its width set so it does not default to 0px.
         $outerspanargs = array('class' => 'filter_jwplayer_playerblock');
         if (!is_numeric($width)) {
             $outerspanargs['style'] = 'width: ' . $width . ';';
             $width = '100%';
             // As the outer span in now at the required width, we set the width of the player to 100%.
         }
         // Automatically set the height unless it is specified.
         if ($height) {
             if (is_numeric($height)) {
                 $playersetupdata['height'] = $height;
             } else {
                 if (is_numeric($width)) {
                     // If width is numeric and height is percentage, calculate height from width.
                     $playersetupdata['height'] = round($width * floatval($height) / 100);
                 } else {
                     // If width is also percentage, then set aspect ratio.
                     $playersetupdata['aspectratio'] = "100:" . floatval($height);
                 }
             }
         } else {
             if (is_numeric($width)) {
                 // If width is numeric calculate height from default aspect ratio.
                 $playersetupdata['height'] = round($width * FILTER_JWPLAYER_VIDEO_ASPECTRATIO_H / FILTER_JWPLAYER_VIDEO_ASPECTRATIO_W);
             } else {
                 if (isset($options['aspectratio'])) {
                     // Responsive videos need aspect ratio set to automatically set height, if this is set in $options use that.
                     $playersetupdata['aspectratio'] = $options['aspectratio'];
                 } else {
                     // Use default aspectration.
                     $playersetupdata['aspectratio'] = FILTER_JWPLAYER_VIDEO_ASPECTRATIO_W . ":" . FILTER_JWPLAYER_VIDEO_ASPECTRATIO_H;
                 }
             }
         }
         // Set additional player options: autostart, mute, controls, repeat, hlslabels, androidhls, primary.
         if (isset($options['autostart'])) {
             $playersetupdata['autostart'] = $options['autostart'];
         }
         if (isset($options['mute'])) {
             $playersetupdata['mute'] = $options['mute'];
         }
         if (isset($options['controls'])) {
             $playersetupdata['controls'] = $options['controls'];
         }
         if (isset($options['repeat'])) {
             $playersetupdata['repeat'] = $options['repeat'];
         }
         if (isset($options['hlslabels']) && is_array($options['hlslabels'])) {
             $playersetupdata['hlslabels'] = $options['hlslabels'];
         }
         if (isset($options['androidhls'])) {
             $playersetupdata['androidhls'] = $options['androidhls'];
         }
         if (isset($options['primary'])) {
             // if primary is set in $options then this will override all defaults including those for streams set above.
             $playersetupdata['primary'] = $options['primary'];
         }
         // Load skin.
         if ($customskincss = get_config('filter_jwplayer', 'customskincss')) {
             $playersetupdata['skin'] = $customskincss;
         } else {
             if ($skin = get_config('filter_jwplayer', 'skin')) {
                 $playersetupdata['skin'] = $skin;
             }
         }
         // Set Google Analytics settings if enabled.
         if (get_config('filter_jwplayer', 'googleanalytics')) {
             if (isset($options['gaidstring'])) {
                 $gaidstring = $options['gaidstring'];
             } else {
                 $gaidstring = get_config('filter_jwplayer', 'gaidstring');
             }
             if (isset($options['galabel'])) {
                 $galabel = $options['galabel'];
             } else {
                 $galabel = get_config('filter_jwplayer', 'galabel');
             }
             $playersetupdata['ga'] = array('idstring' => $gaidstring, 'label' => $galabel);
         }
         $playersetup = new stdClass();
         $playersetup->playerid = $playerid;
         $playersetup->setupdata = $playersetupdata;
         // Add download button if required and supported.
         if (get_config('filter_jwplayer', 'downloadbutton') && !count($streams)) {
             $playersetup->downloadbtn = array('img' => $CFG->wwwroot . '/filter/jwplayer/img/download.png', 'tttext' => get_string('videodownloadbtntttext', 'filter_jwplayer'));
         }
         // Pass the page context variables for logging
         $playersetup->logcontext = $PAGE->context->id;
         $playersetup->logevents = $this->get_supported_events();
         // Set required class for player span tag.
         if (isset($options['htmlattributes']['class'])) {
             $newattributes['class'] .= ' filter_jwplayer_media';
         } else {
             $newattributes['class'] = 'filter_jwplayer_media';
         }
         // Set up the player.
         $PAGE->requires->js_call_amd('filter_jwplayer/jwplayer', 'setupPlayer', array($playersetup));
         $playerdiv = html_writer::tag('span', $this->get_name('', $urls), array('id' => $playerid));
         $outerspan = html_writer::tag('span', $playerdiv, $outerspanargs);
         $output .= html_writer::tag('span', $outerspan, $newattributes);
     }
     return $output;
 }
Esempio n. 16
0
 /**
  * Return the notices.
  *
  * @param block_xp_manager $manager The manager.
  * @return string The notices.
  */
 public function notices($manager)
 {
     global $CFG;
     $o = '';
     if (!$manager->can_manage()) {
         return $o;
     }
     if (!get_user_preferences(block_xp_manager::USERPREF_NOTICES, false)) {
         require_once $CFG->libdir . '/ajax/ajaxlib.php';
         user_preference_allow_ajax_update(block_xp_manager::USERPREF_NOTICES, PARAM_BOOL);
         $moodleorgurl = new moodle_url('https://moodle.org/plugins/view.php?plugin=block_xp');
         $githuburl = new moodle_url('https://github.com/FMCorz/moodle-block_xp');
         $text = get_string('likenotice', 'block_xp', (object) array('moodleorg' => $moodleorgurl->out(), 'github' => $githuburl->out()));
         $id = html_writer::random_id();
         $this->page->requires->js_init_call("Y.one('.block-xp-rocks').on('click', function(e) {\n                e.preventDefault();\n                M.util.set_user_preference('" . block_xp_manager::USERPREF_NOTICES . "', 1);\n                Y.one('.block-xp-notices').hide();\n            });");
         $icon = new pix_icon('t/delete', get_string('dismissnotice', 'block_xp'));
         $actionicon = $this->action_icon(new moodle_url($this->page->url), $icon, null, array('class' => 'block-xp-rocks'));
         $text .= html_writer::div($actionicon, 'dismiss-action');
         $o .= html_writer::div($this->notification($text, 'notifysuccess'), 'block-xp-notices');
     }
     return $o;
 }
Esempio n. 17
0
 /**
  * Generate YUI view of table and paging
  *
  * @param mr_html_table $table Table instance
  * @param mr_html_paging $paging Paging instance
  * @param bool $autoload
  * @param null $id
  * @return string
  */
 public function mr_html_table_ajax(mr_html_table $table, mr_html_paging $paging, $autoload = true, $id = null)
 {
     global $PAGE;
     // Columns
     $columns = array();
     foreach ($table->get_columns(true) as $column) {
         // Must set sortable to false if table is not sort enabled or if empty $rows
         if (!$table->get_sortenabled()) {
             $column->set_config('sortable', false);
         }
         $col = (object) array('key' => $column->get_name(), 'label' => $column->get_config()->heading, 'sortable' => $column->get_config()->sortable);
         if ($column->get_config()->editor) {
             $col->editor = $column->get_config()->editor;
         }
         $columns[] = $col;
     }
     // Page size
     $opts = array();
     if ($paging->get_perpageopts()) {
         foreach ($paging->get_perpageopts() as $opt) {
             if ($opt == 'all') {
                 $opts[] = (object) array('value' => 10000, 'text' => get_string('all'));
             } else {
                 $opts[] = (object) array('value' => $opt, 'text' => $opt);
             }
         }
     }
     // Place holder div's ID
     if (empty($id)) {
         $id = html_writer::random_id();
     }
     $loadingmsg = $this->output->pix_icon('i/ajaxloader', get_string('loadingdotdotdot', 'local_mr')) . '&nbsp;' . get_string('loadingdotdotdot', 'local_mr');
     $module = array('name' => 'local_mr', 'fullpath' => '/local/mr/renderer.js', 'requires' => array('yui2-yahoo', 'yui2-dom', 'yui2-event', 'yui2-element', 'yui2-paginator', 'yui2-datasource', 'yui2-json', 'yui2-connection', 'yui2-get', 'yui2-dragdrop', 'yui2-datatable', 'moodle-local_mr-livelog'), 'strings' => array(array('tablesortedbydesc', 'local_mr'), array('tablesortedbyasc', 'local_mr')));
     $arguments = (object) array('id' => $id, 'url' => $table->get_url()->out(false, array('tjson' => 1)), 'sort' => $table->get_sort(), 'order' => $table->get_order(), 'page' => $paging->get_page(), 'perpage' => $paging->get_perpage(), 'loadingmsg' => $loadingmsg, 'perpageopts' => $opts, 'columns' => $columns, 'asc' => SORT_ASC, 'desc' => SORT_DESC, 'autoload' => $autoload);
     if (!is_null($table->get_summary())) {
         $arguments->summary = $table->get_summary();
     }
     if (!empty($table->caption)) {
         $arguments->caption = $table->caption;
     }
     $PAGE->requires->js_init_call('M.local_mr.init_mr_html_table', array($arguments), false, $module);
     $PAGE->requires->strings_for_js(array('paginatorfirstlabel', 'paginatorfirsttitle', 'paginatorlastlabel', 'paginatorlasttitle', 'paginatorprevlabel', 'paginatorprevtitle', 'paginatornextlabel', 'paginatornexttitle'), 'local_mr');
     return html_writer::tag('div', '', array('id' => $id, 'class' => 'mr_html_table mr_ajax_table'));
 }
Esempio n. 18
0
 /**
  * Generates code required to embed the player.
  *
  * @param array $urls Moodle URLs of media files
  * @param string $name Display name; '' to use default
  * @param int $width Optional width; 0 to use default
  * @param int $height Optional height; 0 to use default
  * @param array $options Options array
  * @return string HTML code for embed
  */
 public function embed($urls, $name, $width, $height, $options)
 {
     global $PAGE, $CFG;
     // We do embedding only here. JW player setup is done in the filter.
     $output = '';
     $sources = array();
     $playersetupdata = array();
     foreach ($urls as $url) {
         // Add the details for this source.
         $source = array('file' => urldecode($url));
         // Help to determine the type of mov.
         if (strtolower(pathinfo($url, PATHINFO_EXTENSION)) === 'mov') {
             $source['type'] = 'mp4';
         }
         if ($url->get_scheme() === 'rtmp') {
             // For RTMP we set rendering mode to Flash and making sure
             // URL is the first in the list.
             $playersetupdata['primary'] = 'flash';
             array_unshift($sources, $source);
         } else {
             $sources[] = $source;
         }
     }
     if (count($sources) > 0) {
         $playerid = 'filter_jwplayer_media_' . html_writer::random_id();
         $playersetupdata['title'] = $this->get_name('', $urls);
         $playersetupdata['playlist'] = array(array('sources' => $sources));
         // If width is not provided, use default.
         if (!$width) {
             $width = FILTER_JWPLAYER_VIDEO_WIDTH;
         }
         $playersetupdata['width'] = $width;
         // Let player choose the height unless it is provided.
         if ($height) {
             $playersetupdata['height'] = $height;
         }
         // If we are dealing with audio, show just the control bar.
         if (mimeinfo('string', $sources[0]['file']) === 'audio') {
             $playersetupdata['width'] = FILTER_JWPLAYER_AUDIO_WIDTH;
             $playersetupdata['height'] = FILTER_JWPLAYER_AUDIO_HEIGTH;
         }
         // Load skin.
         if ($skin = get_config('filter_jwplayer', 'skin')) {
             $playersetupdata['skin'] = $skin;
         }
         // Set up the player.
         $jsmodule = array('name' => $playerid, 'fullpath' => '/filter/jwplayer/module.js');
         $playersetup = array('playerid' => $playerid, 'setupdata' => $playersetupdata);
         $PAGE->requires->js_init_call('M.filter_jwplayer.init', $playersetup, true, $jsmodule);
         if (get_config('filter_jwplayer', 'downloadbutton')) {
             $img = $CFG->wwwroot . '/filter/jwplayer/img/download.png';
             $tttext = get_string('videodownloadbtntttext', 'filter_jwplayer');
             $addbuttonparams = array('playerid' => $playerid, 'img' => $img, 'tttext' => $tttext);
             $PAGE->requires->js_init_call('M.filter_jwplayer.add_button', $addbuttonparams, true, $jsmodule);
         }
         $playerdiv = html_writer::tag('div', $this->get_name('', $urls), array('id' => $playerid));
         $output .= html_writer::tag('div', $playerdiv, array('class' => 'filter_jwplayer_media'));
     }
     return $output;
 }
Esempio n. 19
0
    /**
     * Export for template.
     *
     * @param renderer_base $output The renderer.
     * @return stdClass
     */
    public function export_for_template(renderer_base $output) {
        $data = new stdClass();
        $attributes = $this->attributes;

        if (empty($attributes['id'])) {
            $attributes['id'] = html_writer::random_id('action_link');
        }
        $data->id = $attributes['id'];
        unset($attributes['id']);

        $data->disabled = !empty($attributes['disabled']);
        unset($attributes['disabled']);

        $data->text = $this->text instanceof renderable ? $output->render($this->text) : (string) $this->text;
        $data->url = $this->url ? $this->url->out(false) : '';
        $data->icon = $this->icon ? $this->icon->export_for_template($output) : null;
        $data->classes = isset($attributes['class']) ? $attributes['class'] : '';
        unset($attributes['class']);

        $data->attributes = array_map(function($key, $value) {
            return [
                'name' => $key,
                'value' => $value
            ];
        }, array_keys($attributes), $attributes);

        $data->actions = array_map(function($action) use ($output) {
            return $action->export_for_template($output);
        }, !empty($this->actions) ? $this->actions : []);
        $data->hasactions = !empty($this->actions);

        return $data;
    }
Esempio n. 20
0
 function get_content()
 {
     global $USER, $CFG, $DB, $OUTPUT;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     if (empty($this->instance)) {
         return $this->content;
     }
     $course = $this->page->course;
     require_once $CFG->dirroot . '/course/lib.php';
     $context = context_course::instance($course->id);
     $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
     /// extra fast view mode
     if (!$isediting) {
         $modinfo = get_fast_modinfo($course);
         if (!empty($modinfo->sections[0])) {
             foreach ($modinfo->sections[0] as $cmid) {
                 $cm = $modinfo->cms[$cmid];
                 if (!$cm->uservisible) {
                     continue;
                 }
                 if ($cm->indent > 0) {
                     $indent = '<div class="mod-indent mod-indent-' . $cm->indent . '"></div>';
                 } else {
                     $indent = '';
                 }
                 if (!empty($cm->url)) {
                     $attrs = array();
                     $attrs['title'] = $cm->modfullname;
                     $attrs['class'] = $cm->extraclasses . ' activity-action';
                     if ($cm->onclick) {
                         $attrs['id'] = html_writer::random_id('onclick');
                         $OUTPUT->add_action_handler(new component_action('click', $cm->onclick), $attrs['id']);
                     }
                     if (!$cm->visible) {
                         $attrs['class'] .= ' dimmed';
                     }
                     $icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" />';
                     $content = html_writer::link($cm->url, $icon . $cm->get_formatted_name(), $attrs);
                 } else {
                     $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
                 }
                 $this->content->items[] = $indent . html_writer::div($content, 'main-menu-content');
             }
         }
         return $this->content;
     }
     // Slow & hacky editing mode.
     /** @var core_course_renderer $courserenderer */
     $courserenderer = $this->page->get_renderer('core', 'course');
     $ismoving = ismoving($course->id);
     course_create_sections_if_missing($course, 0);
     $modinfo = get_fast_modinfo($course);
     $section = $modinfo->get_section_info(0);
     if ($ismoving) {
         $strmovehere = get_string('movehere');
         $strmovefull = strip_tags(get_string('movefull', '', "'{$USER->activitycopyname}'"));
         $strcancel = get_string('cancel');
         $stractivityclipboard = $USER->activitycopyname;
     } else {
         $strmove = get_string('move');
     }
     $editbuttons = '';
     if ($ismoving) {
         $this->content->icons[] = '<img src="' . $OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
         $this->content->items[] = $USER->activitycopyname . '&nbsp;(<a href="' . $CFG->wwwroot . '/course/mod.php?cancelcopy=true&amp;sesskey=' . sesskey() . '">' . $strcancel . '</a>)';
     }
     if (!empty($modinfo->sections[0])) {
         $options = array('overflowdiv' => true);
         foreach ($modinfo->sections[0] as $modnumber) {
             $mod = $modinfo->cms[$modnumber];
             if (!$mod->uservisible) {
                 continue;
             }
             if (!$ismoving) {
                 $actions = course_get_cm_edit_actions($mod, $mod->indent);
                 // Prepend list of actions with the 'move' action.
                 $actions = array('move' => new action_menu_link_primary(new moodle_url('/course/mod.php', array('sesskey' => sesskey(), 'copy' => $mod->id)), new pix_icon('t/move', $strmove, 'moodle', array('class' => 'iconsmall', 'title' => '')), $strmove)) + $actions;
                 $editbuttons = html_writer::tag('div', $courserenderer->course_section_cm_edit_actions($actions, $mod, array('donotenhance' => true)), array('class' => 'buttons'));
             } else {
                 $editbuttons = '';
             }
             if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $mod->context)) {
                 if ($ismoving) {
                     if ($mod->id == $USER->activitycopy) {
                         continue;
                     }
                     $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&amp;sesskey=' . sesskey() . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $OUTPUT->pix_url('movehere') . '" alt="' . $strmovehere . '" /></a>';
                     $this->content->icons[] = '';
                 }
                 if ($mod->indent > 0) {
                     $indent = '<div class="mod-indent mod-indent-' . $mod->indent . '"></div>';
                 } else {
                     $indent = '';
                 }
                 $url = $mod->url;
                 if (!$url) {
                     $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
                 } else {
                     //Accessibility: incidental image - should be empty Alt text
                     $attrs = array();
                     $attrs['title'] = $mod->modfullname;
                     $attrs['class'] = $mod->extraclasses . ' activity-action';
                     if ($mod->onclick) {
                         $attrs['id'] = html_writer::random_id('onclick');
                         $OUTPUT->add_action_handler(new component_action('click', $mod->onclick), $attrs['id']);
                     }
                     if (!$mod->visible) {
                         $attrs['class'] .= ' dimmed';
                     }
                     $icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" />';
                     $content = html_writer::link($url, $icon . $mod->get_formatted_name(), $attrs);
                 }
                 $this->content->items[] = $indent . html_writer::div($content . $editbuttons, 'main-menu-content');
             }
         }
     }
     if ($ismoving) {
         $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&amp;sesskey=' . sesskey() . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $OUTPUT->pix_url('movehere') . '" alt="' . $strmovehere . '" /></a>';
         $this->content->icons[] = '';
     }
     $this->content->footer = $courserenderer->course_section_add_cm_control($course, 0, null, array('inblock' => true));
     return $this->content;
 }
 /**
  * Render messages
  *
  * @param message_output_badge_model_message[] $messages
  * @return string
  */
 public function messages(array $messages)
 {
     global $COURSE;
     $messagehtml = array();
     foreach ($messages as $message) {
         $messagehtml[] = $this->render($message);
     }
     if ($this->is_mobile()) {
         if (empty($messages)) {
             return html_writer::link(new moodle_url('/course/view.php', array('id' => $COURSE->id)), get_string('nomorealerts', 'message_badge'), array('data-role' => 'button', 'data-icon' => 'home'));
         }
         if (!empty($this->page->theme->settings->mswatch)) {
             $showswatch = $this->page->theme->settings->mswatch;
         } else {
             $showswatch = '';
         }
         if ($showswatch == 'lightblue') {
             $dtheme = 'b';
         } else {
             if ($showswatch == 'darkgrey') {
                 $dtheme = 'a';
             } else {
                 if ($showswatch == 'black') {
                     $dtheme = 'a';
                 } else {
                     if ($showswatch == 'lightgrey') {
                         $dtheme = 'c';
                     } else {
                         if ($showswatch == 'mediumgrey') {
                             $dtheme = 'd';
                         } else {
                             if ($showswatch == 'glassy') {
                                 $dtheme = 'j';
                             } else {
                                 if ($showswatch == 'yellow') {
                                     $dtheme = 'e';
                                 } else {
                                     if ($showswatch == 'verydark') {
                                         $dtheme = 'a';
                                     } else {
                                         if ($showswatch == 'mrooms') {
                                             $dtheme = 'm';
                                         } else {
                                             $dtheme = 'm';
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         return html_writer::alist($messagehtml, array('data-role' => 'listview', 'data-inset' => 'true', 'data-theme' => $dtheme, 'class' => 'message_badge_mobile_messages'));
     }
     if (!empty($messagehtml)) {
         $hide = ' message_badge_hidden';
     } else {
         $hide = '';
     }
     $messagehtml = implode('', $messagehtml);
     $messagehtml .= html_writer::tag('div', get_string('nomorealerts', 'message_badge'), array('class' => "message_badge_empty{$hide}"));
     $bddiv = html_writer::tag('div', $messagehtml, array('id' => html_writer::random_id(), 'class' => 'yui3-widget-bd message_badge_messages'));
     $ftdiv = html_writer::tag('div', '', array('id' => html_writer::random_id(), 'class' => 'yui3-widget-ft'));
     // GT MOD 2014-05-12 removed message_badge_hidden.
     $overlay = html_writer::tag('div', $bddiv . $ftdiv, array('id' => html_writer::random_id(), 'class' => 'message_badge_overlay'));
     return html_writer::tag('div', $overlay, array('id' => html_writer::random_id(), 'class' => 'message_badge_container'));
 }
Esempio n. 22
0
 /**
  * Constructs the table
  *
  * @param course_enrolment_manager $manager
  */
 public function __construct(course_enrolment_manager $manager)
 {
     $this->manager = $manager;
     $this->page = optional_param(self::PAGEVAR, 0, PARAM_INT);
     $this->perpage = optional_param(self::PERPAGEVAR, self::DEFAULTPERPAGE, PARAM_INT);
     $this->sort = optional_param(self::SORTVAR, self::DEFAULTSORT, PARAM_ALPHANUM);
     $this->sortdirection = optional_param(self::SORTDIRECTIONVAR, self::DEFAULTSORTDIRECTION, PARAM_ALPHA);
     $this->attributes = array('class' => 'userenrolment');
     if (!in_array($this->sort, self::$sortablefields)) {
         $this->sort = self::DEFAULTSORT;
     }
     if ($this->page < 0) {
         $this->page = 0;
     }
     if ($this->sortdirection !== 'ASC' && $this->sortdirection !== 'DESC') {
         $this->sortdirection = self::DEFAULTSORTDIRECTION;
     }
     $this->id = html_writer::random_id();
     // Collect the bulk operations for the currently filtered plugin if there is one.
     $plugin = $manager->get_filtered_enrolment_plugin();
     if ($plugin and enrol_is_enabled($plugin->get_name())) {
         $this->bulkoperations = $plugin->get_bulk_operations($manager);
     }
 }
Esempio n. 23
0
    public function render_user_picture(user_picture $userpicture) {
        global $CFG, $DB;

        $user = $userpicture->user;

        if ($userpicture->alttext) {
            if (!empty($user->imagealt)) {
                $alt = $user->imagealt;
            } else {
                $alt = get_string('pictureof', '', fullname($user));
            }
        } else {
            $alt = '';
        }

        if (empty($userpicture->size)) {
            $size = 15;
        } else if ($userpicture->size === true or $userpicture->size == 1) {
            $size = 100;
        } else {
            $size = $userpicture->size;
        }

        $class = $userpicture->class;

        if ($user->picture == 0) {
            $class .= ' defaultuserpic';
        }

        $src = $userpicture->get_url($this->page, $this);

        $attributes = array('src'=>$src, 'alt'=>$alt, 'title'=>$alt, 'class'=>$class);

        // get the image html output fisrt
        $output = html_writer::empty_tag('img', $attributes);

        // then wrap it in link if needed
        if (!$userpicture->link) {
            return $output;
        }

        if (empty($userpicture->courseid)) {
            $courseid = $this->page->course->id;
        } else {
            $courseid = $userpicture->courseid;
        }

        //if ($courseid == SITEID) {
            // $url = new moodle_url('local/users/profile.php', array('id' => $user->id));
        //} else {
            $url = new moodle_url($CFG->wwwroot.'/user/view.php', array('id' => $user->id, 'course' => $courseid));
        //}

        $attributes = array('href'=>$url);

        if ($userpicture->popup) {
            $id = html_writer::random_id('userpicture');
            $attributes['id'] = $id;
            $this->add_action_handler(new popup_action('click', $url), $id);
        }

        return html_writer::tag('a', $output, $attributes);
    }
Esempio n. 24
0
 /**
  * Build the navigation node.
  *
  * @param navigation_node $node the navigation node object.
  * @param array $attrs list of attributes.
  * @param int $depth the depth, default to 1.
  * @return string the navigation node code.
  */
 protected function navigation_node(navigation_node $node, $attrs = array(), $depth = 1)
 {
     $items = $node->children;
     // exit if empty, we don't want an empty ul element
     if ($items->count() == 0) {
         return '';
     }
     // array of nested li elements
     $lis = array();
     $number = 0;
     foreach ($items as $item) {
         $number++;
         if (!$item->display) {
             continue;
         }
         $isbranch = $item->children->count() > 0 || $item->nodetype == navigation_node::NODETYPE_BRANCH;
         if ($isbranch) {
             $item->hideicon = true;
         }
         $content = $this->output->render($item);
         $id = $item->id ? $item->id : html_writer::random_id();
         $ulattr = ['id' => $id . '_group', 'role' => 'group'];
         $liattr = ['class' => [$item->get_css_type(), 'depth_' . $depth], 'tabindex' => '-1'];
         $pattr = ['class' => ['tree_item'], 'role' => 'treeitem'];
         $pattr += !empty($item->id) ? ['id' => $item->id] : [];
         $hasicon = !$isbranch && $item->icon instanceof renderable;
         if ($isbranch) {
             $liattr['class'][] = 'contains_branch';
             if (!$item->forceopen || !$item->forceopen && $item->collapse || $item->children->count() == 0 && $item->nodetype == navigation_node::NODETYPE_BRANCH) {
                 $pattr += ['aria-expanded' => 'false'];
             } else {
                 $pattr += ['aria-expanded' => 'true'];
             }
             if ($item->requiresajaxloading) {
                 $pattr['data-requires-ajax'] = 'true';
                 $pattr['data-loaded'] = 'false';
             } else {
                 $pattr += ['aria-owns' => $id . '_group'];
             }
         } else {
             if ($hasicon) {
                 $liattr['class'][] = 'item_with_icon';
                 $pattr['class'][] = 'hasicon';
             }
         }
         if ($item->isactive === true) {
             $liattr['class'][] = 'current_branch';
         }
         if (!empty($item->classes) && count($item->classes) > 0) {
             $pattr['class'] = array_merge($pattr['class'], $item->classes);
         }
         $nodetextid = 'label_' . $depth . '_' . $number;
         // class attribute on the div item which only contains the item content
         $pattr['class'][] = 'tree_item';
         if ($isbranch) {
             $pattr['class'][] = 'branch';
         } else {
             $pattr['class'][] = 'leaf';
         }
         $liattr['class'] = join(' ', $liattr['class']);
         $pattr['class'] = join(' ', $pattr['class']);
         if (isset($pattr['aria-expanded']) && $pattr['aria-expanded'] === 'false') {
             $ulattr += ['aria-hidden' => 'true'];
         }
         $content = html_writer::tag('p', $content, $pattr) . $this->navigation_node($item, $ulattr, $depth + 1);
         if (!empty($item->preceedwithhr) && $item->preceedwithhr === true) {
             $content = html_writer::empty_tag('hr') . $content;
         }
         $liattr['aria-labelledby'] = $nodetextid;
         $content = html_writer::tag('li', $content, $liattr);
         $lis[] = $content;
     }
     if (count($lis)) {
         if (empty($attrs['role'])) {
             $attrs['role'] = 'group';
         }
         return html_writer::tag('ul', implode("\n", $lis), $attrs);
     } else {
         return '';
     }
 }
Esempio n. 25
0
 /**
  * Produces a navigation node for the navigation tree
  *
  * @param navigation_node[] $items
  * @param array $attrs
  * @param int $expansionlimit
  * @param array $options
  * @param int $depth
  * @return string
  */
 protected function navigation_node($items, $attrs = array(), $expansionlimit = null, array $options = array(), $depth = 1)
 {
     // Exit if empty, we don't want an empty ul element.
     if (count($items) === 0) {
         return '';
     }
     // Turn our navigation items into list items.
     $lis = array();
     // Set the number to be static for unique id's.
     static $number = 0;
     foreach ($items as $item) {
         $number++;
         if (!$item->display && !$item->contains_active_node()) {
             continue;
         }
         $isexpandable = empty($expansionlimit) || ($item->type > navigation_node::TYPE_ACTIVITY || $item->type < $expansionlimit) || $item->contains_active_node() && $item->children->count() > 0;
         // Skip elements which have no content and no action - no point in showing them
         if (!$isexpandable && empty($item->action)) {
             continue;
         }
         $id = $item->id ? $item->id : html_writer::random_id();
         $content = $item->get_content();
         $title = $item->get_title();
         $ulattr = ['id' => $id . '_group', 'role' => 'group'];
         $liattr = ['class' => [$item->get_css_type(), 'depth_' . $depth]];
         $pattr = ['class' => ['tree_item'], 'role' => 'treeitem'];
         $pattr += !empty($item->id) ? ['id' => $item->id] : [];
         $isbranch = $isexpandable && ($item->children->count() > 0 || $item->has_children() && (isloggedin() || $item->type <= navigation_node::TYPE_CATEGORY));
         $hasicon = (!$isbranch || $item->type == navigation_node::TYPE_ACTIVITY || $item->type == navigation_node::TYPE_RESOURCE) && $item->icon instanceof renderable;
         $icon = '';
         if ($hasicon) {
             $liattr['class'][] = 'item_with_icon';
             $pattr['class'][] = 'hasicon';
             $icon = $this->output->render($item->icon);
             // Because an icon is being used we're going to wrap the actual content in a span.
             // This will allow designers to create columns for the content, as we've done in styles.css.
             $content = $icon . html_writer::span($content, 'item-content-wrap');
         }
         if ($item->helpbutton !== null) {
             $content = trim($item->helpbutton) . html_writer::tag('span', $content, array('class' => 'clearhelpbutton'));
         }
         if (empty($content)) {
             continue;
         }
         $nodetextid = 'label_' . $depth . '_' . $number;
         $attributes = array('tabindex' => '-1', 'id' => $nodetextid);
         if ($title !== '') {
             $attributes['title'] = $title;
         }
         if ($item->hidden) {
             $attributes['class'] = 'dimmed_text';
         }
         if (is_string($item->action) || empty($item->action) || ($item->type === navigation_node::TYPE_CATEGORY || $item->type === navigation_node::TYPE_MY_CATEGORY) && empty($options['linkcategories'])) {
             $content = html_writer::tag('span', $content, $attributes);
         } else {
             if ($item->action instanceof action_link) {
                 //TODO: to be replaced with something else
                 $link = $item->action;
                 $link->text = $icon . html_writer::span($link->text, 'item-content-wrap');
                 $link->attributes = array_merge($link->attributes, $attributes);
                 $content = $this->output->render($link);
             } else {
                 if ($item->action instanceof moodle_url) {
                     $content = html_writer::link($item->action, $content, $attributes);
                 }
             }
         }
         if ($isbranch) {
             $pattr['class'][] = 'branch';
             $liattr['class'][] = 'contains_branch';
             $pattr += ['aria-expanded' => $item->has_children() && (!$item->forceopen || $item->collapse) ? "false" : "true"];
             if ($item->requiresajaxloading) {
                 $pattr += ['data-requires-ajax' => 'true', 'data-loaded' => 'false', 'data-node-id' => $item->id, 'data-node-key' => $item->key, 'data-node-type' => $item->type];
             } else {
                 $pattr += ['aria-owns' => $id . '_group'];
             }
         }
         if ($item->isactive === true) {
             $liattr['class'][] = 'current_branch';
         }
         if (!empty($item->classes) && count($item->classes) > 0) {
             $pattr['class'] = array_merge($pattr['class'], $item->classes);
         }
         $liattr['class'] = join(' ', $liattr['class']);
         $pattr['class'] = join(' ', $pattr['class']);
         $pattr += $depth == 1 ? ['data-collapsible' => 'false'] : [];
         if (isset($pattr['aria-expanded']) && $pattr['aria-expanded'] === 'false') {
             $ulattr += ['aria-hidden' => 'true'];
         }
         // Create the structure.
         $content = html_writer::tag('p', $content, $pattr);
         if ($isexpandable) {
             $content .= $this->navigation_node($item->children, $ulattr, $expansionlimit, $options, $depth + 1);
         }
         if (!empty($item->preceedwithhr) && $item->preceedwithhr === true) {
             $content = html_writer::empty_tag('hr') . $content;
         }
         $liattr['aria-labelledby'] = $nodetextid;
         $content = html_writer::tag('li', $content, $liattr);
         $lis[] = $content;
     }
     if (count($lis) === 0) {
         // There is still a chance, despite having items, that nothing had content and no list items were created.
         return '';
     }
     // We used to separate using new lines, however we don't do that now, instead we'll save a few chars.
     // The source is complex already anyway.
     return html_writer::tag('ul', implode('', $lis), $attrs);
 }
Esempio n. 26
0
    /**
     * Renders a single select instance
     *
     * @param single_select $select
     * @return string
     */
    protected function render_single_select(single_select $select) {
        $select = clone($select);
        if (empty($select->formid)) {
            $select->formid = html_writer::random_id('single_select_f');
        }

        $output = '';
        $params = $select->url->params();
        if ($select->method === 'post') {
            $params['sesskey'] = sesskey();
        }
        foreach ($params as $name=>$value) {
            $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>$name, 'value'=>$value));
        }

        if (empty($select->attributes['id'])) {
            $select->attributes['id'] = html_writer::random_id('single_select');
            //$select->attributes['data-native-menu'] = 'false';
            //above by john for select elements to use native style and help performance?
        }

        if ($select->disabled) {
            $select->attributes['disabled'] = 'disabled';
        }

        if ($select->tooltip) {
            $select->attributes['title'] = $select->tooltip;
        }

        $select->attributes['class'] = 'autosubmit';
        if ($select->class) {
            $select->attributes['class'] .= ' ' . $select->class;
        }

        if ($select->label) {
            $output .= html_writer::label($select->label, $select->attributes['id']);
        }

        if ($select->helpicon instanceof help_icon) {
            $output .= $this->render($select->helpicon);
        } else if ($select->helpicon instanceof old_help_icon) {
            $output .= $this->render($select->helpicon);
        }

        $output .= html_writer::select($select->options, $select->name, $select->selected, $select->nothing, $select->attributes);

        //by john show go button to fix selects
        $go = '';
        $output .= html_writer::empty_tag('input data-inline="true"', array('type' => 'submit','value' => get_string('go')));
        $output .= html_writer::tag('noscript', html_writer::tag('div', $go), array('style' => 'inline'));

        $nothing = empty($select->nothing) ? false : key($select->nothing);
        $this->page->requires->yui_module('moodle-core-formautosubmit',
            'M.core.init_formautosubmit',
            array(array('selectid' => $select->attributes['id'], 'nothing' => $nothing))
        );

        // then div wrapper for xhtml strictness
        $output = html_writer::tag('div', $output);

        // now the form itself around it
        $formattributes = array(
            'method' => $select->method,
            'action' => $select->url->out_omit_querystring(),
            'id'     => $select->formid
        );
        $output = html_writer::tag('form', $output, $formattributes);

        // and finally one more wrapper with class
        return html_writer::tag('div', $output, array('class' => $select->class));
    }
Esempio n. 27
0
    /**
     * Internal implementation of user image rendering.
     *
     * @param user_picture $userpicture
     * @return string
     */
    protected function render_user_picture(user_picture $userpicture) {
        global $CFG, $DB;

        $user = $userpicture->user;

        if ($userpicture->alttext) {
            if (!empty($user->imagealt)) {
                $alt = $user->imagealt;
            } else {
                $alt = get_string('pictureof', '', fullname($user));
            }
        } else {
            $alt = '';
        }

        if (empty($userpicture->size)) {
            $size = 35;
        } else if ($userpicture->size === true or $userpicture->size == 1) {
            $size = 100;
        } else {
            $size = $userpicture->size;
        }

        $class = $userpicture->class;

        if ($user->picture == 0) {
            $class .= ' defaultuserpic';
        }

        $src = $userpicture->get_url($this->page, $this);

        $attributes = array('src'=>$src, 'alt'=>$alt, 'title'=>$alt, 'class'=>$class, 'width'=>$size, 'height'=>$size);
        if (!$userpicture->visibletoscreenreaders) {
            $attributes['role'] = 'presentation';
        }

        // get the image html output fisrt
        $output = html_writer::empty_tag('img', $attributes);

        // then wrap it in link if needed
        if (!$userpicture->link) {
            return $output;
        }

        if (empty($userpicture->courseid)) {
            $courseid = $this->page->course->id;
        } else {
            $courseid = $userpicture->courseid;
        }

        if ($courseid == SITEID) {
            $url = new moodle_url('/user/profile.php', array('id' => $user->id));
        } else {
            $url = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $courseid));
        }

        $attributes = array('href'=>$url);
        if (!$userpicture->visibletoscreenreaders) {
            $attributes['tabindex'] = '-1';
            $attributes['aria-hidden'] = 'true';
        }

        if ($userpicture->popup) {
            $id = html_writer::random_id('userpicture');
            $attributes['id'] = $id;
            $this->add_action_handler(new popup_action('click', $url), $id);
        }

        return html_writer::tag('a', $output, $attributes);
    }
Esempio n. 28
0
 public static function fetchSWFWidgetCode($widget, $paramsArray, $width, $height, $bgcolor = "#FFFFFF")
 {
     global $CFG, $PAGE;
     $lm = new \filter_poodll\licensemanager();
     if (!$lm->validate_registrationkey($CFG->filter_poodll_registrationkey)) {
         return $lm->fetch_unregistered_content();
     }
     //get our module javascript all ready to go
     $jsmodule = array('name' => 'filter_poodll', 'fullpath' => '/filter/poodll/module.js', 'requires' => array('json'));
     $widgetopts = array();
     $widgetid = \html_writer::random_id('laszlobase');
     //'lzapp_' . rand(100000, 999999);
     $widgetopts['widgetjson'] = self::fetchSWFWidgetJSON($widget, $paramsArray, $width, $height, $bgcolor, $widgetid);
     $renderer = $PAGE->get_renderer('filter_poodll');
     return $renderer->fetchLazloEmbedCode($widgetopts, $widgetid, $jsmodule);
 }
Esempio n. 29
0
 /**
  * Constructs the table
  *
  * @param course_enrolment_manager $manager
  */
 public function __construct(course_enrolment_manager $manager, moodle_page $moodlepage)
 {
     $this->manager = $manager;
     $this->moodlepage = $moodlepage;
     $this->page = optional_param(self::PAGEVAR, 0, PARAM_INT);
     $this->perpage = optional_param(self::PERPAGEVAR, self::DEFAULTPERPAGE, PARAM_INT);
     $this->sort = optional_param(self::SORTVAR, self::DEFAULTSORT, PARAM_ALPHA);
     $this->sortdirection = optional_param(self::SORTDIRECTIONVAR, self::DEFAULTSORTDIRECTION, PARAM_ALPHA);
     $this->attributes = array('class' => 'userenrolment');
     if (!in_array($this->sort, self::$sortablefields)) {
         $this->sort = self::DEFAULTSORT;
     }
     if ($this->page < 0) {
         $this->page = 0;
     }
     if ($this->sortdirection !== 'ASC' && $this->sortdirection !== 'DESC') {
         $this->sortdirection = self::DEFAULTSORTDIRECTION;
     }
     $this->id = html_writer::random_id();
 }
Esempio n. 30
0
 public function action_link(moodle_url $url, $titlekey, $iconkey, $confirmkey = null, $id = null)
 {
     $title = get_string($titlekey, 'scheduler');
     $pix = new pix_icon($iconkey, $title, 'moodle', array('class' => 'iconsmall', 'title' => ''));
     $attributes = array();
     if ($id) {
         $attributes['id'] = $id;
     }
     if ($confirmkey) {
         if (!$id) {
             $id = html_writer::random_id('command_link');
         }
         $attributes['id'] = $id;
         $this->linkactions[$id] = new confirm_action(get_string($confirmkey, 'scheduler'));
     }
     $act = new action_menu_link_secondary($url, $pix, $title, $attributes);
     return $act;
 }