/** * 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; }
/** * Output the row of editing icons for a block, as defined by the controls array. * * @param array $controls an array like {@link block_contents::$controls}. * @param string $blockid The ID given to the block. * @return string HTML fragment. */ 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->set_constraint('.block-region'); $menu->attributes['class'] .= ' block-control-actions commands'; if (isset($CFG->blockeditingmenu) && !$CFG->blockeditingmenu) { $menu->do_not_enhance(); } return $this->render($menu); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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')); }