/**
  * Format a column of data for display.
  *
  * @param stdClass $row
  * @return string
  */
 public function col_userid(stdClass $row)
 {
     global $USER;
     $edit = '';
     $actions = array();
     $urlparams = array('id' => $this->assignment->get_course_module()->id, 'rownum' => $this->rownum, 'action' => 'grade');
     $url = new moodle_url('/mod/assign/view.php', $urlparams);
     $noimage = null;
     if (!$row->grade) {
         $description = get_string('grade');
     } else {
         $description = get_string('updategrade', 'assign');
     }
     $actions['grade'] = new action_menu_link_secondary($url, $noimage, $description);
     // Everything we need is in the row.
     $submission = $row;
     $flags = $row;
     if ($this->assignment->get_instance()->teamsubmission) {
         // Use the cache for this.
         $submission = false;
         $group = false;
         $this->get_group_and_submission($row->id, $group, $submission, -1);
     }
     $submissionsopen = $this->assignment->submissions_open($row->id, true, $submission, $flags, $this->gradinginfo);
     $caneditsubmission = $this->assignment->can_edit_submission($row->id, $USER->id);
     // Hide for offline assignments.
     if ($this->assignment->is_any_submission_plugin_enabled()) {
         if (!$row->status || $row->status == ASSIGN_SUBMISSION_STATUS_DRAFT || !$this->assignment->get_instance()->submissiondrafts) {
             if (!$row->locked) {
                 $urlparams = array('id' => $this->assignment->get_course_module()->id, 'userid' => $row->id, 'action' => 'lock', 'sesskey' => sesskey(), 'page' => $this->currpage);
                 $url = new moodle_url('/mod/assign/view.php', $urlparams);
                 $description = get_string('preventsubmissionsshort', 'assign');
                 $actions['lock'] = new action_menu_link_secondary($url, $noimage, $description);
             } else {
                 $urlparams = array('id' => $this->assignment->get_course_module()->id, 'userid' => $row->id, 'action' => 'unlock', 'sesskey' => sesskey(), 'page' => $this->currpage);
                 $url = new moodle_url('/mod/assign/view.php', $urlparams);
                 $description = get_string('allowsubmissionsshort', 'assign');
                 $actions['unlock'] = new action_menu_link_secondary($url, $noimage, $description);
             }
         }
         if ($submissionsopen && $USER->id != $row->id && $caneditsubmission) {
             $urlparams = array('id' => $this->assignment->get_course_module()->id, 'userid' => $row->id, 'action' => 'editsubmission', 'sesskey' => sesskey(), 'page' => $this->currpage);
             $url = new moodle_url('/mod/assign/view.php', $urlparams);
             $description = get_string('editsubmission', 'assign');
             $actions['editsubmission'] = new action_menu_link_secondary($url, $noimage, $description);
         }
     }
     if (($this->assignment->get_instance()->duedate || $this->assignment->get_instance()->cutoffdate) && $this->hasgrantextension) {
         $urlparams = array('id' => $this->assignment->get_course_module()->id, 'userid' => $row->id, 'action' => 'grantextension', 'sesskey' => sesskey(), 'page' => $this->currpage);
         $url = new moodle_url('/mod/assign/view.php', $urlparams);
         $description = get_string('grantextension', 'assign');
         $actions['grantextension'] = new action_menu_link_secondary($url, $noimage, $description);
     }
     if ($row->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED && $this->assignment->get_instance()->submissiondrafts) {
         $urlparams = array('id' => $this->assignment->get_course_module()->id, 'userid' => $row->id, 'action' => 'reverttodraft', 'sesskey' => sesskey(), 'page' => $this->currpage);
         $url = new moodle_url('/mod/assign/view.php', $urlparams);
         $description = get_string('reverttodraftshort', 'assign');
         $actions['reverttodraft'] = new action_menu_link_secondary($url, $noimage, $description);
     }
     if ($row->status == ASSIGN_SUBMISSION_STATUS_DRAFT && $this->assignment->get_instance()->submissiondrafts && $caneditsubmission && $submissionsopen && $row->id != $USER->id) {
         $urlparams = array('id' => $this->assignment->get_course_module()->id, 'userid' => $row->id, 'action' => 'submitotherforgrading', 'sesskey' => sesskey(), 'page' => $this->currpage);
         $url = new moodle_url('/mod/assign/view.php', $urlparams);
         $description = get_string('submitforgrading', 'assign');
         $actions['submitforgrading'] = new action_menu_link_secondary($url, $noimage, $description);
     }
     $ismanual = $this->assignment->get_instance()->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL;
     $hassubmission = !empty($row->status);
     $notreopened = $hassubmission && $row->status != ASSIGN_SUBMISSION_STATUS_REOPENED;
     $isunlimited = $this->assignment->get_instance()->maxattempts == ASSIGN_UNLIMITED_ATTEMPTS;
     $hasattempts = $isunlimited || $row->attemptnumber < $this->assignment->get_instance()->maxattempts - 1;
     if ($ismanual && $hassubmission && $notreopened && $hasattempts) {
         $urlparams = array('id' => $this->assignment->get_course_module()->id, 'userid' => $row->id, 'action' => 'addattempt', 'sesskey' => sesskey(), 'page' => $this->currpage);
         $url = new moodle_url('/mod/assign/view.php', $urlparams);
         $description = get_string('addattempt', 'assign');
         $actions['addattempt'] = new action_menu_link_secondary($url, $noimage, $description);
     }
     $menu = new action_menu();
     $menu->set_owner_selector('.gradingtable-actionmenu');
     $menu->set_alignment(action_menu::TL, action_menu::BL);
     $menu->set_constraint('.gradingtable > .no-overflow');
     $menu->set_menu_trigger(get_string('edit'));
     foreach ($actions as $action) {
         $menu->add($action);
     }
     // Prioritise the menu ahead of all other actions.
     $menu->prioritise = true;
     $edit .= $this->output->render($menu);
     return $edit;
 }
示例#2
0
 /**
  * Recursive function for building the table holding the grade categories and items,
  * with CSS indentation and styles.
  *
  * @param array   $element The current tree element being rendered
  * @param boolean $totals Whether or not to print category grade items (category totals)
  * @param array   $parents An array of parent categories for the current element (used for indentation and row classes)
  *
  * @return string HTML
  */
 public function build_html_tree($element, $totals, $parents, $level, &$row_count)
 {
     global $CFG, $COURSE, $PAGE, $OUTPUT;
     $object = $element['object'];
     $eid = $element['eid'];
     $object->name = $this->gtree->get_element_header($element, true, true, true, true, true);
     $object->stripped_name = $this->gtree->get_element_header($element, false, false, false);
     $is_category_item = false;
     if ($element['type'] == 'categoryitem' || $element['type'] == 'courseitem') {
         $is_category_item = true;
     }
     $rowclasses = array();
     foreach ($parents as $parent_eid) {
         $rowclasses[] = $parent_eid;
     }
     $moveaction = '';
     $actionsmenu = new action_menu();
     $actionsmenu->set_menu_trigger(get_string('edit'));
     $actionsmenu->set_owner_selector('grade-item-' . $eid);
     $actionsmenu->set_alignment(action_menu::TL, action_menu::BL);
     if (!$is_category_item && ($icon = $this->gtree->get_edit_icon($element, $this->gpr, true))) {
         $actionsmenu->add($icon);
     }
     // MDL-49281 if grade_item already has calculation, it should be editable even if global setting is off.
     $type = $element['type'];
     $iscalculated = ($type == 'item' or $type == 'courseitem' or $type == 'categoryitem') && $object->is_calculated();
     $icon = $this->gtree->get_calculation_icon($element, $this->gpr, true);
     if ($iscalculated || $this->show_calculations && $icon) {
         $actionsmenu->add($icon);
     }
     if ($element['type'] == 'item' or $element['type'] == 'category' and $element['depth'] > 1) {
         if ($this->element_deletable($element)) {
             $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'delete', 'eid' => $eid, 'sesskey' => sesskey()));
             $icon = new action_menu_link_secondary($aurl, new pix_icon('t/delete', get_string('delete')), get_string('delete'));
             $actionsmenu->add($icon);
         }
         $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'moveselect', 'eid' => $eid, 'sesskey' => sesskey()));
         $moveaction .= $OUTPUT->action_icon($aurl, new pix_icon('t/move', get_string('move')));
     }
     if ($icon = $this->gtree->get_hiding_icon($element, $this->gpr, true)) {
         $actionsmenu->add($icon);
     }
     if ($icon = $this->gtree->get_reset_icon($element, $this->gpr, true)) {
         $actionsmenu->add($icon);
     }
     $actions = $OUTPUT->render($actionsmenu);
     $returnrows = array();
     $root = false;
     $id = required_param('id', PARAM_INT);
     /// prepare move target if needed
     $last = '';
     /// print the list items now
     if ($this->moving == $eid) {
         // do not diplay children
         $cell = new html_table_cell();
         $cell->colspan = 12;
         $cell->attributes['class'] = $element['type'] . ' moving column-name level' . ($level + 1) . ' level' . ($level % 2 ? 'even' : 'odd');
         $cell->text = $object->name . ' (' . get_string('move') . ')';
         return array(new html_table_row(array($cell)));
     }
     if ($element['type'] == 'category') {
         $level++;
         $this->categories[$object->id] = $object->stripped_name;
         $category = grade_category::fetch(array('id' => $object->id));
         $item = $category->get_grade_item();
         // Add aggregation coef input if not a course item and if parent category has correct aggregation type
         $dimmed = $item->is_hidden() ? 'dimmed_text' : '';
         // Before we print the category's row, we must find out how many rows will appear below it (for the filler cell's rowspan)
         $aggregation_position = grade_get_setting($COURSE->id, 'aggregationposition', $CFG->grade_aggregationposition);
         $category_total_data = null;
         // Used if aggregationposition is set to "last", so we can print it last
         $html_children = array();
         $row_count = 0;
         foreach ($element['children'] as $child_el) {
             $moveto = null;
             if (empty($child_el['object']->itemtype)) {
                 $child_el['object']->itemtype = false;
             }
             if (($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') && !$totals) {
                 continue;
             }
             $child_eid = $child_el['eid'];
             $first = '';
             if ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') {
                 $first = array('first' => 1);
                 $child_eid = $eid;
             }
             if ($this->moving && $this->moving != $child_eid) {
                 $strmove = get_string('move');
                 $strmovehere = get_string('movehere');
                 $actions = $moveaction = '';
                 // no action icons when moving
                 $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'move', 'eid' => $this->moving, 'moveafter' => $child_eid, 'sesskey' => sesskey()));
                 if ($first) {
                     $aurl->params($first);
                 }
                 $cell = new html_table_cell();
                 $cell->colspan = 12;
                 $cell->attributes['class'] = 'movehere level' . ($level + 1) . ' level' . ($level % 2 ? 'even' : 'odd');
                 $icon = new pix_icon('movehere', $strmovehere, null, array('class' => 'movetarget'));
                 $cell->text = $OUTPUT->action_icon($aurl, $icon);
                 $moveto = new html_table_row(array($cell));
             }
             $newparents = $parents;
             $newparents[] = $eid;
             $row_count++;
             $child_row_count = 0;
             // If moving, do not print course and category totals, but still print the moveto target box
             if ($this->moving && ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category')) {
                 $html_children[] = $moveto;
             } elseif ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') {
                 // We don't build the item yet because we first need to know the deepest level of categories (for category/name colspans)
                 $category_total_item = $this->build_html_tree($child_el, $totals, $newparents, $level, $child_row_count);
                 if (!$aggregation_position) {
                     $html_children = array_merge($html_children, $category_total_item);
                 }
             } else {
                 $html_children = array_merge($html_children, $this->build_html_tree($child_el, $totals, $newparents, $level, $child_row_count));
                 if (!empty($moveto)) {
                     $html_children[] = $moveto;
                 }
                 if ($this->moving) {
                     $row_count++;
                 }
             }
             $row_count += $child_row_count;
             // If the child is a category, increment row_count by one more (for the extra coloured row)
             if ($child_el['type'] == 'category') {
                 $row_count++;
             }
         }
         // Print category total at the end if aggregation position is "last" (1)
         if (!empty($category_total_item) && $aggregation_position) {
             $html_children = array_merge($html_children, $category_total_item);
         }
         // Determine if we are at the root
         if (isset($element['object']->grade_item) && $element['object']->grade_item->is_course_item()) {
             $root = true;
         }
         $levelclass = "level{$level} level" . ($level % 2 ? 'odd' : 'even');
         $courseclass = '';
         if ($level == 1) {
             $courseclass = 'coursecategory';
         }
         $row = new html_table_row();
         $row->id = 'grade-item-' . $eid;
         $row->attributes['class'] = $courseclass . ' category ' . $dimmed;
         $row->attributes['data-category'] = $eid;
         $row->attributes['data-itemid'] = $category->get_grade_item()->id;
         foreach ($rowclasses as $class) {
             $row->attributes['class'] .= ' ' . $class;
         }
         $headercell = new html_table_cell();
         $headercell->header = true;
         $headercell->scope = 'row';
         $headercell->attributes['title'] = $object->stripped_name;
         $headercell->attributes['class'] = 'cell column-rowspan rowspan ' . $levelclass;
         $headercell->rowspan = $row_count + 1;
         $row->cells[] = $headercell;
         foreach ($this->columns as $column) {
             if (!($this->moving && $column->hide_when_moving)) {
                 $row->cells[] = $column->get_category_cell($category, $levelclass, ['id' => $id, 'name' => $object->name, 'level' => $level, 'actions' => $actions, 'moveaction' => $moveaction, 'eid' => $eid]);
             }
         }
         $returnrows[] = $row;
         $returnrows = array_merge($returnrows, $html_children);
         // Print a coloured row to show the end of the category across the table
         $endcell = new html_table_cell();
         $endcell->colspan = 19 - $level;
         $endcell->attributes['class'] = 'emptyrow colspan ' . $levelclass;
         $returnrows[] = new html_table_row(array($endcell));
     } else {
         // Dealing with a grade item
         $item = grade_item::fetch(array('id' => $object->id));
         $element['type'] = 'item';
         $element['object'] = $item;
         $categoryitemclass = '';
         if ($item->itemtype == 'category') {
             $categoryitemclass = 'categoryitem';
         }
         if ($item->itemtype == 'course') {
             $categoryitemclass = 'courseitem';
         }
         $dimmed = $item->is_hidden() ? "dimmed_text" : "";
         $gradeitemrow = new html_table_row();
         $gradeitemrow->id = 'grade-item-' . $eid;
         $gradeitemrow->attributes['class'] = $categoryitemclass . ' item ' . $dimmed;
         $gradeitemrow->attributes['data-itemid'] = $object->id;
         foreach ($rowclasses as $class) {
             $gradeitemrow->attributes['class'] .= ' ' . $class;
         }
         foreach ($this->columns as $column) {
             if (!($this->moving && $column->hide_when_moving)) {
                 $gradeitemrow->cells[] = $column->get_item_cell($item, array('id' => $id, 'name' => $object->name, 'level' => $level, 'actions' => $actions, 'element' => $element, 'eid' => $eid, 'moveaction' => $moveaction, 'itemtype' => $object->itemtype));
             }
         }
         $returnrows[] = $gradeitemrow;
     }
     return $returnrows;
 }
 /**
  * Displays a view mode selector.
  *
  * @param array $modes An array of view modes.
  * @param string $currentmode The current view mode.
  * @param moodle_url $url The URL to use when changing actions. Defaults to the page URL.
  * @param string $param The param name.
  * @return string
  */
 public function view_mode_selector(array $modes, $currentmode, moodle_url $url = null, $param = 'view')
 {
     if ($url === null) {
         $url = $this->page->url;
     }
     $menu = new action_menu();
     $menu->attributes['class'] .= ' view-mode-selector vms';
     $selected = null;
     foreach ($modes as $mode => $modestr) {
         $attributes = array('class' => 'vms-mode', 'data-mode' => $mode);
         if ($currentmode === $mode) {
             $attributes['class'] .= ' currentmode';
             $selected = $modestr;
         }
         if ($selected === null) {
             $selected = $modestr;
         }
         $modeurl = new moodle_url($url, array($param => $mode));
         if ($mode === 'default') {
             $modeurl->remove_params($param);
         }
         $menu->add(new action_menu_link_secondary($modeurl, null, $modestr, $attributes));
     }
     $menu->set_menu_trigger(get_string('viewing', 'moodle', $selected));
     $html = html_writer::start_div('view-mode-selector vms');
     $html .= $this->render($menu);
     $html .= html_writer::end_div();
     return $html;
 }
示例#4
0
 /**
  * Renders HTML for displaying the sequence of course module editing buttons
  *
  * @see course_get_cm_edit_actions()
  *
  * @param action_link[] $actions Array of action_link objects
  * @param cm_info $mod The module we are displaying actions for.
  * @param array $displayoptions additional display options:
  *     ownerselector => A JS/CSS selector that can be used to find an cm node.
  *         If specified the owning node will be given the class 'action-menu-shown' when the action
  *         menu is being displayed.
  *     constraintselector => A JS/CSS selector that can be used to find the parent node for which to constrain
  *         the action menu to when it is being displayed.
  *     donotenhance => If set to true the action menu that gets displayed won't be enhanced by JS.
  * @return string
  */
 public function course_section_cm_edit_actions($actions, cm_info $mod = null, $displayoptions = array())
 {
     global $CFG;
     if (empty($actions)) {
         return '';
     }
     if (isset($displayoptions['ownerselector'])) {
         $ownerselector = $displayoptions['ownerselector'];
     } else {
         if ($mod) {
             $ownerselector = '#module-' . $mod->id;
         } else {
             debugging('You should upgrade your call to ' . __FUNCTION__ . ' and provide $mod', DEBUG_DEVELOPER);
             $ownerselector = 'li.activity';
         }
     }
     if (isset($displayoptions['constraintselector'])) {
         $constraint = $displayoptions['constraintselector'];
     } else {
         $constraint = '.course-content';
     }
     $menu = new action_menu();
     $menu->set_owner_selector($ownerselector);
     $menu->set_constraint($constraint);
     $menu->set_alignment(action_menu::TR, action_menu::BR);
     $menu->set_menu_trigger(get_string('edit'));
     if (isset($CFG->modeditingmenu) && !$CFG->modeditingmenu || !empty($displayoptions['donotenhance'])) {
         $menu->do_not_enhance();
         // Swap the left/right icons.
         // Normally we have have right, then left but this does not
         // make sense when modactionmenu is disabled.
         $moveright = null;
         $_actions = array();
         foreach ($actions as $key => $value) {
             if ($key === 'moveright') {
                 // Save moveright for later.
                 $moveright = $value;
             } else {
                 if ($moveright) {
                     // This assumes that the order was moveright, moveleft.
                     // If we have a moveright, then we should place it immediately after the current value.
                     $_actions[$key] = $value;
                     $_actions['moveright'] = $moveright;
                     // Clear the value to prevent it being used multiple times.
                     $moveright = null;
                 } else {
                     $_actions[$key] = $value;
                 }
             }
         }
         $actions = $_actions;
         unset($_actions);
     }
     foreach ($actions as $action) {
         if ($action instanceof action_menu_link) {
             $action->add_class('cm-edit-action');
         }
         $menu->add($action);
     }
     $menu->attributes['class'] .= ' section-cm-edit-actions commands';
     // Prioritise the menu ahead of all other actions.
     $menu->prioritise = true;
     return $this->render($menu);
 }
示例#5
0
    /**
     * Construct a user menu, returning HTML that can be echoed out by a
     * layout file.
     *
     * @param stdClass $user A user object, usually $USER.
     * @param bool $withlinks true if a dropdown should be built.
     * @return string HTML fragment.
     */
    public function user_menu($user = null, $withlinks = null) {
        global $USER, $CFG;
        require_once($CFG->dirroot . '/user/lib.php');

        if (is_null($user)) {
            $user = $USER;
        }

        // Note: this behaviour is intended to match that of core_renderer::login_info,
        // but should not be considered to be good practice; layout options are
        // intended to be theme-specific. Please don't copy this snippet anywhere else.
        if (is_null($withlinks)) {
            $withlinks = empty($this->page->layout_options['nologinlinks']);
        }

        // Add a class for when $withlinks is false.
        $usermenuclasses = 'usermenu';
        if (!$withlinks) {
            $usermenuclasses .= ' withoutlinks';
        }

        $returnstr = "";

        // If during initial install, return the empty return string.
        if (during_initial_install()) {
            return $returnstr;
        }

        $loginpage = $this->is_login_page();
        $loginurl = get_login_url();
        // If not logged in, show the typical not-logged-in string.
        if (!isloggedin()) {
            $returnstr = get_string('loggedinnot', 'moodle');
            if (!$loginpage) {
                $returnstr .= " (<a href=\"$loginurl\">" . get_string('login') . '</a>)';
            }
            return html_writer::div(
                html_writer::span(
                    $returnstr,
                    'login'
                ),
                $usermenuclasses
            );

        }

        // If logged in as a guest user, show a string to that effect.
        if (isguestuser()) {
            $returnstr = get_string('loggedinasguest');
            if (!$loginpage && $withlinks) {
                $returnstr .= " (<a href=\"$loginurl\">".get_string('login').'</a>)';
            }

            return html_writer::div(
                html_writer::span(
                    $returnstr,
                    'login'
                ),
                $usermenuclasses
            );
        }

        // Get some navigation opts.
        $opts = user_get_user_navigation_info($user, $this->page);

        $avatarclasses = "avatars";
        $avatarcontents = html_writer::span($opts->metadata['useravatar'], 'avatar current');
        $usertextcontents = $opts->metadata['userfullname'];

        // Other user.
        if (!empty($opts->metadata['asotheruser'])) {
            $avatarcontents .= html_writer::span(
                $opts->metadata['realuseravatar'],
                'avatar realuser'
            );
            $usertextcontents = $opts->metadata['realuserfullname'];
            $usertextcontents .= html_writer::tag(
                'span',
                get_string(
                    'loggedinas',
                    'moodle',
                    html_writer::span(
                        $opts->metadata['userfullname'],
                        'value'
                    )
                ),
                array('class' => 'meta viewingas')
            );
        }

        // Role.
        if (!empty($opts->metadata['asotherrole'])) {
            $role = core_text::strtolower(preg_replace('#[ ]+#', '-', trim($opts->metadata['rolename'])));
            $usertextcontents .= html_writer::span(
                $opts->metadata['rolename'],
                'meta role role-' . $role
            );
        }

        // User login failures.
        if (!empty($opts->metadata['userloginfail'])) {
            $usertextcontents .= html_writer::span(
                $opts->metadata['userloginfail'],
                'meta loginfailures'
            );
        }

        // MNet.
        if (!empty($opts->metadata['asmnetuser'])) {
            $mnet = strtolower(preg_replace('#[ ]+#', '-', trim($opts->metadata['mnetidprovidername'])));
            $usertextcontents .= html_writer::span(
                $opts->metadata['mnetidprovidername'],
                'meta mnet mnet-' . $mnet
            );
        }

        $returnstr .= html_writer::span(
            html_writer::span($usertextcontents, 'usertext') .
            html_writer::span($avatarcontents, $avatarclasses),
            'userbutton'
        );

        // Create a divider (well, a filler).
        $divider = new action_menu_filler();
        $divider->primary = false;

        $am = new action_menu();
        $am->initialise_js($this->page);
        $am->set_menu_trigger(
            $returnstr
        );
        $am->set_alignment(action_menu::TR, action_menu::BR);
        $am->set_nowrap_on_items();
        if ($withlinks) {
            $navitemcount = count($opts->navitems);
            $idx = 0;
            foreach ($opts->navitems as $key => $value) {

                switch ($value->itemtype) {
                    case 'divider':
                        // If the nav item is a divider, add one and skip link processing.
                        $am->add($divider);
                        break;

                    case 'invalid':
                        // Silently skip invalid entries (should we post a notification?).
                        break;

                    case 'link':
                        // Process this as a link item.
                        $pix = null;
                        if (isset($value->pix) && !empty($value->pix)) {
                            $pix = new pix_icon($value->pix, $value->title, null, array('class' => 'iconsmall'));
                        } else if (isset($value->imgsrc) && !empty($value->imgsrc)) {
                            $value->title = html_writer::img(
                                $value->imgsrc,
                                $value->title,
                                array('class' => 'iconsmall')
                            ) . $value->title;
                        }
                        $al = new action_menu_link_secondary(
                            $value->url,
                            $pix,
                            $value->title,
                            array('class' => 'icon')
                        );
                        $am->add($al);
                        break;
                }

                $idx++;

                // Add dividers after the first item and before the last item.
                if ($idx == 1 || $idx == $navitemcount - 1) {
                    $am->add($divider);
                }
            }
        }

        return html_writer::div(
            $this->render($am),
            $usermenuclasses
        );
    }
示例#6
0
 /**
  * Renders an action menu component.
  *
  * ARIA references:
  *   - http://www.w3.org/WAI/GL/wiki/Using_ARIA_menus
  *   - http://stackoverflow.com/questions/12279113/recommended-wai-aria-implementation-for-navigation-bar-menu
  *
  * @param action_menu $menu
  * @return string HTML
  */
 public function render_action_menu(action_menu $menu)
 {
     $menu->initialise_js($this->page);
     $output = html_writer::start_tag('div', $menu->attributes);
     $output .= html_writer::start_tag('ul', $menu->attributesprimary);
     foreach ($menu->get_primary_actions($this) as $action) {
         if ($action instanceof renderable) {
             $content = $this->render($action);
         } else {
             $content = $action;
         }
         $output .= html_writer::tag('li', $content, array('role' => 'presentation'));
     }
     $output .= html_writer::end_tag('ul');
     $output .= html_writer::start_tag('ul', $menu->attributessecondary);
     foreach ($menu->get_secondary_actions() as $action) {
         if ($action instanceof renderable) {
             $content = $this->render($action);
         } else {
             $content = $action;
         }
         $output .= html_writer::tag('li', $content, array('role' => 'presentation'));
     }
     $output .= html_writer::end_tag('ul');
     $output .= html_writer::end_tag('div');
     return $output;
 }
示例#7
0
 /**
  * Generate the edit control action menu
  *
  * @param array $controls The edit control items from section_edit_control_items
  * @param stdClass $course The course entry from DB
  * @param stdClass $section The course_section entry from DB
  * @return string HTML to output.
  */
 protected function section_edit_control_menu($controls, $course, $section)
 {
     $o = "";
     if (!empty($controls)) {
         $menu = new action_menu();
         $menu->set_menu_trigger(get_string('edit'));
         $menu->attributes['class'] .= ' section-actions';
         foreach ($controls as $value) {
             $url = empty($value['url']) ? '' : $value['url'];
             $icon = empty($value['icon']) ? '' : $value['icon'];
             $name = empty($value['name']) ? '' : $value['name'];
             $attr = empty($value['attr']) ? '' : $value['attr'];
             $class = empty($item['pixattr']['class']) ? '' : $item['pixattr']['class'];
             $alt = empty($item['pixattr']['alt']) ? '' : $item['pixattr']['alt'];
             $al = new action_menu_link_secondary(new moodle_url($url), new pix_icon($icon, $name, null, array('class' => "smallicon " . $class, 'alt' => $alt)), $name, $attr);
             $menu->add($al);
         }
         $o .= html_writer::div($this->render($menu), 'section_action_menu');
     }
     return $o;
 }
示例#8
0
    /**
     * Export for template.
     *
     * @param renderer_base $output The renderer.
     * @return stdClass
     */
    public function export_for_template(renderer_base $output) {
        static $instance = 1;

        $data = parent::export_for_template($output);
        $data->instance = $instance++;

        // Ignore what the parent did with the attributes, except for ID and class.
        $data->attributes = [];
        $attributes = $this->attributes;
        unset($attributes['id']);
        unset($attributes['class']);

        // Handle text being a renderable.
        $comparetoalt = $this->text;
        if ($this->text instanceof renderable) {
            $data->text = $this->render($this->text);
            $comparetoalt = '';
        }
        $comparetoalt = (string) $comparetoalt;

        $data->showtext = (!$this->icon || $this->primary === false);

        $data->icon = null;
        if ($this->icon) {
            $icon = $this->icon;
            if ($this->primary || !$this->actionmenu->will_be_enhanced()) {
                $attributes['title'] = $data->text;
            }
            if (!$this->primary && $this->actionmenu->will_be_enhanced()) {
                if ((string) $icon->attributes['alt'] === $comparetoalt) {
                    $icon->attributes['alt'] = '';
                }
                if (isset($icon->attributes['title']) && (string) $icon->attributes['title'] === $comparetoalt) {
                    unset($icon->attributes['title']);
                }
            }
            $data->icon = $icon ? $icon->export_for_template($output) : null;
        }

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

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

        return $data;
    }
示例#9
0
 /**
  * Renders HTML for displaying the sequence of course module editing buttons
  *
  * @see course_get_cm_edit_actions()
  *
  * @param action_link[] $actions Array of action_link objects
  * @param cm_info $mod The module we are displaying actions for.
  * @param array $displayoptions additional display options:
  *     ownerselector => A JS/CSS selector that can be used to find an cm node.
  *         If specified the owning node will be given the class 'action-menu-shown' when the action
  *         menu is being displayed.
  *     constraintselector => A JS/CSS selector that can be used to find the parent node for which to constrain
  *         the action menu to when it is being displayed.
  *     donotenhance => If set to true the action menu that gets displayed won't be enhanced by JS.
  * @return string
  */
 public function course_section_cm_edit_actions($actions, cm_info $mod = null, $displayoptions = array())
 {
     global $CFG;
     if (empty($actions)) {
         return '';
     }
     if (isset($displayoptions['ownerselector'])) {
         $ownerselector = $displayoptions['ownerselector'];
     } else {
         if ($mod) {
             $ownerselector = '#module-' . $mod->id;
         } else {
             debugging('You should upgrade your call to ' . __FUNCTION__ . ' and provide $mod', DEBUG_DEVELOPER);
             $ownerselector = 'li.activity';
         }
     }
     if (isset($displayoptions['constraintselector'])) {
         $constraint = $displayoptions['constraintselector'];
     } else {
         $constraint = '.course-content';
     }
     $menu = new action_menu();
     $menu->set_owner_selector($ownerselector);
     $menu->set_constraint($constraint);
     $menu->set_alignment(action_menu::TR, action_menu::BR);
     $menu->set_menu_trigger(get_string('edit'));
     foreach ($actions as $action) {
         if ($action instanceof action_menu_link) {
             $action->add_class('cm-edit-action');
         }
         $menu->add($action);
     }
     $menu->attributes['class'] .= ' section-cm-edit-actions commands';
     // Prioritise the menu ahead of all other actions.
     $menu->prioritise = true;
     return $this->render($menu);
 }
示例#10
0
 /**
  * Adds editing actions to the question name in the edit mode
  * @param stdClass $item
  * @param HTML_QuickForm_element $element
  */
 protected function enhance_name_for_edit($item, $element)
 {
     global $OUTPUT;
     $menu = new action_menu();
     $menu->set_owner_selector('#' . $this->guess_element_id($item, $element));
     $menu->set_constraint('.feedback_form');
     $menu->set_alignment(action_menu::TR, action_menu::BR);
     $menu->set_menu_trigger(get_string('edit'));
     $menu->prioritise = true;
     $itemobj = feedback_get_item_class($item->typ);
     $actions = $itemobj->edit_actions($item, $this->get_feedback(), $this->get_cm());
     foreach ($actions as $action) {
         $menu->add($action);
     }
     $editmenu = $OUTPUT->render($menu);
     $name = $element->getLabel();
     $name = html_writer::span('', 'itemdd', array('id' => 'feedback_item_box_' . $item->id)) . html_writer::span($name, 'itemname') . html_writer::span($editmenu, 'itemactions');
     $element->setLabel(html_writer::span($name, 'itemtitle'));
 }
 /**
  * Returns the add menu that is output once per page.
  * @param structure $structure object containing the structure of the quiz.
  * @param int $page the page number that this menu will add to.
  * @param \moodle_url $pageurl the canonical URL of this page.
  * @param \question_edit_contexts $contexts the relevant question bank contexts.
  * @param array $pagevars the variables from {@link \question_edit_setup()}.
  * @return string HTML to output.
  */
 public function add_menu_actions(structure $structure, $page, \moodle_url $pageurl, \question_edit_contexts $contexts, array $pagevars)
 {
     $actions = $this->edit_menu_actions($structure, $page, $pageurl, $pagevars);
     if (empty($actions)) {
         return '';
     }
     $menu = new \action_menu();
     $menu->set_alignment(\action_menu::TR, \action_menu::BR);
     $menu->set_constraint('.mod-quiz-edit-content');
     $trigger = html_writer::tag('span', get_string('add', 'quiz'), array('class' => 'add-menu'));
     $menu->set_menu_trigger($trigger);
     // The menu appears within an absolutely positioned element causing width problems.
     // Make sure no-wrap is set so that we don't get a squashed menu.
     $menu->set_nowrap_on_items(true);
     // Disable the link if quiz has attempts.
     if (!$structure->can_be_edited()) {
         return $this->render($menu);
     }
     foreach ($actions as $action) {
         if ($action instanceof \action_menu_link) {
             $action->add_class('add-menu');
         }
         $menu->add($action);
     }
     $menu->attributes['class'] .= ' page-add-actions commands';
     // Prioritise the menu ahead of all other actions.
     $menu->prioritise = true;
     return $this->render($menu);
 }
                    $params['action'] = 'hiderecording';
                    $urlobj = new moodle_url('/mod/webexactivity/view.php', $params);
                    $actions['showhide'] = new action_menu_link_secondary($urlobj, new \pix_icon('t/hide', 'Hide'), get_string('hide'));
                } else {
                    $params['action'] = 'showrecording';
                    $urlobj = new moodle_url('/mod/webexactivity/view.php', $params);
                    $actions['showhide'] = new action_menu_link_secondary($urlobj, new \pix_icon('t/show', 'Show'), get_string('show'));
                }
                unset($params['action']);
                $params['view'] = 'directlinks';
                $urlobj = new moodle_url('/mod/webexactivity/view.php', $params);
                $actions['direct'] = new action_menu_link_secondary($urlobj, new \pix_icon('t/restore', 'Direct Links'), 'Direct links');
                $params['action'] = 'deleterecording';
                $urlobj = new moodle_url('/mod/webexactivity/view.php', $params);
                $actions['delete'] = new action_menu_link_secondary($urlobj, new \pix_icon('t/delete', 'Delete'), get_string('delete'));
                $menu = new action_menu();
                $menu->set_menu_trigger(get_string('edit'));
                foreach ($actions as $action) {
                    $menu->add($action);
                }
                $menu->prioritise = true;
                echo $OUTPUT->render($menu);
                echo '</div>';
            }
            // Close the recording row.
            echo '</div>';
        }
        echo '</div>';
    }
} else {
    if ($view === 'guest') {
示例#13
0
 protected function action_menu($actions)
 {
     if (empty($actions)) {
         return '';
     }
     $menu = new action_menu();
     $menu->set_alignment(action_menu::TR, action_menu::BR);
     foreach ($actions as $action) {
         $menu->add($action);
     }
     // Prioritise the menu ahead of all other actions.
     $menu->prioritise = true;
     $output = $this->output->render($menu);
     return str_replace('iconsmall', '', $output);
 }
示例#14
0
 /**
  * Returns the add menu that is output once per page.
  * @param structure $structure object containing the structure of the quiz.
  * @param int $page the page number that this menu will add to.
  * @param \moodle_url $pageurl the canonical URL of this page.
  * @param \question_edit_contexts $contexts the relevant question bank contexts.
  * @param array $pagevars the variables from {@link \question_edit_setup()}.
  * @return string HTML to output.
  */
 public function add_menu_actions(structure $structure, $page, \moodle_url $pageurl, \question_edit_contexts $contexts, array $pagevars)
 {
     $actions = $this->edit_menu_actions($structure, $page, $pageurl, $pagevars);
     if (empty($actions)) {
         return '';
     }
     $menu = new \action_menu();
     $menu->set_alignment(\action_menu::TR, \action_menu::BR);
     $trigger = html_writer::tag('span', get_string('add', 'quiz'), array('class' => 'add-menu'));
     $menu->set_menu_trigger($trigger);
     // Disable the link if quiz has attempts.
     if (!$structure->can_be_edited()) {
         return $this->render($menu);
     }
     foreach ($actions as $action) {
         if ($action instanceof \action_menu_link) {
             $action->add_class('add-menu');
         }
         $menu->add($action);
     }
     $menu->attributes['class'] .= ' page-add-actions commands';
     // Prioritise the menu ahead of all other actions.
     $menu->prioritise = true;
     return $this->render($menu);
 }
 public function block_controls($actions, $blockid = null)
 {
     global $CFG;
     if (empty($actions)) {
         return '';
     }
     $menu = new action_menu($actions);
     if ($blockid !== null) {
         $menu->set_owner_selector('#' . $blockid);
     }
     $menu->attributes['class'] .= ' block-control-actions commands icon';
     if (isset($CFG->blockeditingmenu) && !$CFG->blockeditingmenu) {
         $menu->do_not_enhance();
     }
     return $this->render($menu);
 }
示例#16
0
 /**
  *
  */
 protected function display_action_menu($entry, array $options = null)
 {
     global $OUTPUT;
     $menu = new action_menu();
     $menu->set_menu_trigger($OUTPUT->pix_icon('t/contextmenu', ''));
     // Edit.
     if ($action = $this->display_edit($entry, array('actionmenu' => 1))) {
         $menu->add_secondary_action($action);
     }
     // More.
     if ($action = $this->display_more($entry, array('actionmenu' => 1))) {
         $menu->add_secondary_action($action);
     }
     // Duplicate.
     if ($action = $this->display_duplicate($entry, array('actionmenu' => 1))) {
         $menu->add_secondary_action($action);
     }
     // Export.
     if ($action = $this->display_export($entry, array('actionmenu' => 1))) {
         $menu->add_secondary_action($action);
     }
     // Delete.
     if ($action = $this->display_delete($entry, array('actionmenu' => 1))) {
         $menu->add_secondary_action($action);
     }
     return $OUTPUT->render_action_menu($menu);
 }