Merge branch 'MDL-40320-master' of git://github.com/sammarshallou/moodle
authorMarina Glancy <marina@moodle.com>
Mon, 5 Aug 2013 02:30:56 +0000 (12:30 +1000)
committerMarina Glancy <marina@moodle.com>
Mon, 5 Aug 2013 02:30:56 +0000 (12:30 +1000)
1  2 
course/renderer.php

diff --combined course/renderer.php
@@@ -325,54 -325,20 +325,54 @@@ class core_course_renderer extends plug
       *
       * @see course_get_cm_edit_actions()
       *
 -     * @param array $actions array of action_link or pix_icon objects
 +     * @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) {
 -        $output = html_writer::start_tag('span', array('class' => 'commands'));
 +    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_contraint($constraint);
 +        $menu->set_alignment(action_menu::TL, action_menu::TR);
 +        if (isset($CFG->modeditingmenu) && !$CFG->modeditingmenu || !empty($displayoptions['donotenhance'])) {
 +            $menu->do_not_enhance();
 +        }
          foreach ($actions as $action) {
 -            if ($action instanceof renderable) {
 -                $output .= $this->output->render($action);
 -            } else {
 -                $output .= $action;
 +            if ($action instanceof action_menu_link) {
 +                $action->add_class('cm-edit-action');
              }
 +            $menu->add($action);
          }
 -        $output .= html_writer::end_tag('span');
 -        return $output;
 +        $menu->attributes['class'] .= ' section-cm-edit-actions commands';
 +        return $this->render($menu);
      }
  
      /**
              return $output;
          }
          $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
-         $conditionalhidden = $this->is_cm_conditionally_hidden($mod);
-         $accessiblebutdim = !$mod->visible || $conditionalhidden;
+         if ($this->page->user_is_editing()) {
+             // In editing mode, when an item is conditionally hidden from some users
+             // we show it as greyed out.
+             $conditionalhidden = $this->is_cm_conditionally_hidden($mod);
+             $dim = !$mod->visible || $conditionalhidden;
+         } else {
+             // When not in editing mode, we only show item as hidden if it is
+             // actually not available to the user
+             $conditionalhidden = false;
+             $dim = !$mod->uservisible;
+         }
          $textclasses = '';
          $accesstext = '';
-         if ($accessiblebutdim) {
+         if ($dim) {
              $textclasses .= ' dimmed_text';
              if ($conditionalhidden) {
                  $textclasses .= ' conditionalhidden';
  
          if ($this->page->user_is_editing()) {
              $editactions = course_get_cm_edit_actions($mod, $mod->indent, $sectionreturn);
 -            $output .= ' '. $this->course_section_cm_edit_actions($editactions);
 +            $output .= ' '. $this->course_section_cm_edit_actions($editactions, $mod, $displayoptions);
              $output .= $mod->get_after_edit_icons();
          }