Exemplo n.º 1
0
/**
 * Moves a section within a course, from a position to another.
 * Be very careful: $section and $destination refer to section number,
 * not id!.
 *
 * @param object $course
 * @param int $section Section number (not id!!!)
 * @param int $destination
 * @return boolean Result
 */
function move_section_to($course, $section, $destination)
{
    /// Moves a whole course section up and down within the course
    global $USER, $DB;
    if (!$destination && $destination != 0) {
        return true;
    }
    if ($destination > $course->numsections) {
        return false;
    }
    // Get all sections for this course and re-order them (2 of them should now share the same section number)
    if (!($sections = $DB->get_records_menu('course_sections', array('course' => $course->id), 'section ASC, id ASC', 'id, section'))) {
        return false;
    }
    $movedsections = reorder_sections($sections, $section, $destination);
    // Update all sections. Do this in 2 steps to avoid breaking database
    // uniqueness constraint
    $transaction = $DB->start_delegated_transaction();
    foreach ($movedsections as $id => $position) {
        if ($sections[$id] !== $position) {
            $DB->set_field('course_sections', 'section', -$position, array('id' => $id));
        }
    }
    foreach ($movedsections as $id => $position) {
        if ($sections[$id] !== $position) {
            $DB->set_field('course_sections', 'section', $position, array('id' => $id));
        }
    }
    // Adjust destination to reflect the actual section
    $moveup = false;
    if ($section > $destination) {
        $destination++;
        $moveup = true;
    }
    // If we move the highlighted section itself, then just highlight the destination.
    // Adjust the higlighted section location if we move something over it either direction.
    if ($section == $course->marker) {
        course_set_marker($course, $destination);
    } elseif ($moveup && $section > $course->marker && $course->marker >= $destination) {
        course_set_marker($course, $course->marker + 1);
    } elseif (!$moveup && $section < $course->marker && $course->marker <= $destination) {
        course_set_marker($course, $course->marker - 1);
    }
    // if the focus is on the section that is being moved, then move the focus along
    if (course_get_display($course->id) == $section) {
        course_set_display($course->id, $destination);
    }
    $transaction->allow_commit();
    return true;
}
Exemplo n.º 2
0
/**
 * Moves a section within a course, from a position to another.
 * Be very careful: $section and $destination refer to section number,
 * not id!.
 *
 * @param object $course
 * @param int $section Section number (not id!!!)
 * @param int $destination
 * @return boolean Result
 */
function move_section_to($course, $section, $destination)
{
    /// Moves a whole course section up and down within the course
    global $USER;
    if (!$destination && $destination != 0) {
        return true;
    }
    if ($destination > $course->numsections) {
        return false;
    }
    // Get all sections for this course and re-order them (2 of them should now share the same section number)
    if (!($sections = get_records_menu('course_sections', 'course', $course->id, 'section ASC, id ASC', 'id, section'))) {
        return false;
    }
    $sections = reorder_sections($sections, $section, $destination);
    // Update all sections
    foreach ($sections as $id => $position) {
        set_field('course_sections', 'section', $position, 'id', $id);
    }
    // if the focus is on the section that is being moved, then move the focus along
    if (isset($USER->display[$course->id]) and $USER->display[$course->id] == $section) {
        course_set_display($course->id, $destination);
    }
    return true;
}
Exemplo n.º 3
0
$lmax = empty($THEME->block_l_max_width) ? 210 : $THEME->block_l_max_width;
$rmin = empty($THEME->block_r_min_width) ? 100 : $THEME->block_r_min_width;
$rmax = empty($THEME->block_r_max_width) ? 210 : $THEME->block_r_max_width;
define('BLOCK_L_MIN_WIDTH', $lmin);
define('BLOCK_L_MAX_WIDTH', $lmax);
define('BLOCK_R_MIN_WIDTH', $rmin);
define('BLOCK_R_MAX_WIDTH', $rmax);
$preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), BLOCK_L_MAX_WIDTH);
$preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), BLOCK_R_MAX_WIDTH);
if ($week != -1) {
    $displaysection = course_set_display($course->id, $week);
} else {
    if (isset($USER->display[$course->id])) {
        $displaysection = $USER->display[$course->id];
    } else {
        $displaysection = course_set_display($course->id, 0);
    }
}
$streditsummary = get_string('editsummary');
$stradd = get_string('add');
$stractivities = get_string('activities');
$strshowallweeks = get_string('showallweeks');
$strweek = get_string('week');
$strgroups = get_string('groups');
$strgroupmy = get_string('groupmy');
$editing = $PAGE->user_is_editing();
if ($editing) {
    $strstudents = moodle_strtolower($course->students);
    $strweekhide = get_string('weekhide', '', $strstudents);
    $strweekshow = get_string('weekshow', '', $strstudents);
    $strmoveup = get_string('moveup');
Exemplo n.º 4
0
Arquivo: lib.php Projeto: r007/PMoodle
function move_section($course, $section, $move)
{
    /// Moves a whole course section up and down within the course
    global $USER;
    if (!$move) {
        return true;
    }
    $sectiondest = $section + $move;
    if ($sectiondest > $course->numsections or $sectiondest < 1) {
        return false;
    }
    if (!($sectionrecord = get_record("course_sections", "course", $course->id, "section", $section))) {
        return false;
    }
    if (!($sectiondestrecord = get_record("course_sections", "course", $course->id, "section", $sectiondest))) {
        return false;
    }
    if (!set_field("course_sections", "section", $sectiondest, "id", $sectionrecord->id)) {
        return false;
    }
    if (!set_field("course_sections", "section", $section, "id", $sectiondestrecord->id)) {
        return false;
    }
    // if the focus is on the section that is being moved, then move the focus along
    if (isset($USER->display[$course->id]) and $USER->display[$course->id] == $section) {
        course_set_display($course->id, $sectiondest);
    }
    // Check for duplicates and fix order if needed.
    // There is a very rare case that some sections in the same course have the same section id.
    $sections = get_records_select('course_sections', "course = {$course->id}", 'section ASC');
    $n = 0;
    foreach ($sections as $section) {
        if ($section->section != $n) {
            if (!set_field('course_sections', 'section', $n, 'id', $section->id)) {
                return false;
            }
        }
        $n++;
    }
    return true;
}
 * 800x600, 1024x768... on IE6, Firefox. Below 800 columns will shift downwards.
 *
 * http://www.maxdesign.com.au/presentation/em/ Ideal length for content.
 * http://www.svendtofte.com/code/max_width_in_ie/ Max width in IE.
 *
 * @copyright &copy; 2006 The Open University
 * @author N.D.Freear@open.ac.uk, and others.
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package
 */
defined('MOODLE_INTERNAL') || die;
require_once $CFG->libdir . '/filelib.php';
require_once $CFG->libdir . '/completionlib.php';
$topic = optional_param('topic', -1, PARAM_INT);
if ($topic != -1) {
    $displaysection = course_set_display($course->id, $topic);
} else {
    $displaysection = course_get_display($course->id);
}
$context = get_context_instance(CONTEXT_COURSE, $course->id);
if ($marker >= 0 && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
    $course->marker = $marker;
    $DB->set_field("course", "marker", $marker, array("id" => $course->id));
}
$streditsummary = get_string('editsummary');
$stradd = get_string('add');
$stractivities = get_string('activities');
$strshowalltopics = get_string('showalltopics');
$strtopic = get_string('topic');
$strgroups = get_string('groups');
$strgroupmy = get_string('groupmy');
 function sections($config)
 {
     global $COURSE, $CFG, $USER, $THEME;
     // probably inefficient, but it works
     get_all_mods($COURSE->id, $mods, $modnames, $modnamesplural, $modnamesused);
     // sections
     $sections = get_all_sections($COURSE->id);
     // name for sections
     $sectionname = get_string("name{$COURSE->format}", "format_{$COURSE->format}");
     // TODO: this fallback should be unnecessary
     if ($sectionname == "[[name{$COURSE->format}]]") {
         $sectionname = get_string("name{$COURSE->format}");
     }
     $return = array();
     // check what the course format is like
     // highlight for current week or highlighted topic
     if (in_array($COURSE->format, array('weeks', 'weekscss'))) {
         $format = 'week';
         $highlight = ceil((time() - $COURSE->startdate) / 604800);
     } else {
         $format = 'topic';
         $highlight = $COURSE->marker;
     }
     $modinfo = unserialize($COURSE->modinfo);
     // I think $display is the section currently being displayed
     // Why are we calling course_set_display?
     // For Moodle 2.0 we should just use $PAGE and check type
     // and also $PAGE->activityrecord
     $path = str_replace($CFG->httpswwwroot . '/', '', $CFG->pagepath);
     if (substr($path, 0, 7) == 'course/') {
         //TODO: this code is hackish, we shouldn't use course_set_display
         # get current section being displayed
         $week = optional_param('week', -1, PARAM_INT);
         if ($week != -1) {
             // the course format should already be doing this
             $display = course_set_display($COURSE->id, $week);
         } else {
             if (isset($USER->display[$COURSE->id])) {
                 $display = $USER->display[$COURSE->id];
             } else {
                 $display = course_set_display($COURSE->id, 0);
             }
         }
     } elseif (substr($path, 0, 4) == 'mod/') {
         // Moodle 2: use $PAGE->activityrecord->section;
         $id = optional_param('id', -1, PARAM_INT);
         if ($id == -1) {
             $display = 0;
         } else {
             $sql = "select section from {$CFG->prefix}course_sections where id=(select section from {$CFG->prefix}course_modules where id={$id})";
             $row = get_record_sql($sql);
             $display = $row->section;
         }
     } else {
         $display = 0;
     }
     foreach ($sections as $section) {
         // don't show the flowing sections
         if (!($section->visible && $section->section && $section->section <= $COURSE->numsections)) {
             continue;
         }
         $text = trim($section->summary);
         if (empty($text)) {
             $text = ucwords($sectionname) . " " . $section->section;
         } else {
             $text = $this->truncate_html(filter_text($text, $COURSE->id), $config);
         }
         // expand section if it's the one currently displayed
         $expand = false;
         if ($section->section == $display) {
             $expand = true;
         }
         $sectionstyle = 'yui_menu_icon_section';
         // highlight marked section
         if ($section->section == $highlight) {
             $sectionstyle .= ' highlight';
         }
         $iconpath = $CFG->wwwroot;
         if ($THEME->custompix) {
             $iconpath .= "/theme/" . current_theme() . "/pix";
         } else {
             $iconpath .= '/pix';
             //$iconpath .= '/';
         }
         $iconpath = $CFG->wwwroot . "/theme/" . current_theme() . "/pix";
         // decide what URL we want to use
         // A lot of this should really be done by the course format
         //
         // = intoaction config values =
         // * 'introhide' link to the section page (this effectively
         //   hides the other sections
         // * 'introscroll' link to the fragment id of the section on
         //   on the current page
         // whether or not any of the sections are hidden
         $hidden = false;
         foreach (array('topic', 'week') as $param) {
             if (isset($_GET[$param]) && $_GET[$param] != 'all') {
                 $hidden = true;
             }
         }
         $introaction = isset($config->introaction) ? $config->introaction : 'introhide';
         if ($introaction == 'introhide' || $hidden) {
             // link to the section, this will effectively hide all
             // the other sections
             $url = "{$CFG->wwwroot}/course/view.php?id={$COURSE->id}" . "&{$format}={$section->section}";
         } else {
             // this pretty much just a hack
             // use $PAGE in Moodle 2 for great justice
             if (strpos($_SERVER['REQUEST_URI'], 'course/view.php') != 0) {
                 $url = "#section-{$section->section}";
             } else {
                 $url = false;
             }
         }
         if ($url === false) {
             $item = new yui_menu_item($this, $text, '');
             //$iconpath . '/i/one.gif'); // redundant icons, lets save space (nadavkav)
         } else {
             $item = new yui_menu_item_link($this, $text, $url, '');
             // $iconpath . '/i/one.gif'); // redundant icons, lets save space (nadavkav)
         }
         $item->expand = $expand;
         if (isset($section->sequence)) {
             $sectionmods = explode(",", $section->sequence);
         } else {
             $sectionmods = array();
         }
         foreach ($sectionmods as $modnumber) {
             if (empty($mods[$modnumber])) {
                 continue;
             }
             $mod = $mods[$modnumber];
             // don't do anything invisible or labels
             if (!$mod->visible || $mod->modname == 'label') {
                 continue;
             }
             // figure out the text and url
             $text = urldecode($modinfo[$modnumber]->name);
             if (!empty($CFG->filterall)) {
                 $text = filter_text($text, $COURSE->id);
             }
             if (trim($text) == '') {
                 $text = $mod->modfullname;
             }
             $text = $this->truncate_html($text, $config);
             $url = "{$CFG->wwwroot}/mod/{$mod->modname}/view.php?id={$mod->id}";
             $name = "yui_menu_mod_{$mod->modname}_{$modnumber}";
             // figure out if it is the current page
             $pageurl = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
             $pageurl = '~https?://' . preg_quote($pageurl, '~') . '~';
             if (preg_match($pageurl, $CFG->wwwroot . $url)) {
                 $style = "yui_menu_mod_{$mod->modname} highlight";
             } else {
                 $style = "yui_menu_mod_{$mod->modname}";
             }
             $icon = "{$iconpath}/mod/{$mod->modname}/icon.gif";
             if ($mod->modname == 'resource') {
                 $info = resource_get_coursemodule_info($mod);
                 if (isset($info) && isset($info->icon)) {
                     $icon = "{$CFG->pixpath}/{$info->icon}";
                 }
             }
             $child = new yui_menu_item_link($this, $text, $url, $icon);
             $child->style = $style;
             $item->children[$modnumber] = $child;
         }
         $return[] = $item;
     }
     return $return;
 }
Exemplo n.º 7
0
 * 800x600, 1024x768... on IE6, Firefox. Below 800 columns will shift downwards.
 *
 * http://www.maxdesign.com.au/presentation/em/ Ideal length for content.
 * http://www.svendtofte.com/code/max_width_in_ie/ Max width in IE.
 *
 * @copyright &copy; 2006 The Open University
 * @author N.D.Freear@open.ac.uk, and others.
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package
 */
defined('MOODLE_INTERNAL') || die;
require_once $CFG->libdir . '/filelib.php';
require_once $CFG->libdir . '/completionlib.php';
$week = optional_param('week', -1, PARAM_INT);
if ($week != -1) {
    $displaysection = course_set_display($course->id, $week);
} else {
    $displaysection = course_get_display($course->id);
}
$streditsummary = get_string('editsummary');
$stradd = get_string('add');
$stractivities = get_string('activities');
$strshowallweeks = get_string('showallweeks');
$strweek = get_string('week');
$strgroups = get_string('groups');
$strgroupmy = get_string('groupmy');
$editing = $PAGE->user_is_editing();
if ($editing) {
    $strweekhide = get_string('hideweekfromothers');
    $strweekshow = get_string('showweekfromothers');
    $strmoveup = get_string('moveup');
 /**
  * specialization
  */
 function specialization()
 {
     global $COURSE, $DB, $USER, $displaysection, $section;
     // set default config values
     $defaults = array('title' => get_string('defaulttitle', 'block_taskchain_navigation'), 'showcourse' => 0, 'coursenamefield' => 'shortname', 'coursenametext' => '', 'coursegradeposition' => 0, 'minimumdepth' => 0, 'maximumdepth' => 0, 'categoryskipempty' => 0, 'categoryskiphidden' => 0, 'categoryskipzeroweighted' => 0, 'categorycollapse' => 0, 'categoryshortnames' => 0, 'categoryshowweighting' => 0, 'categoryignorechars' => '', 'categoryprefixlength' => 0, 'categoryprefixchars' => '', 'categoryprefixlong' => 0, 'categoryprefixkeep' => 0, 'categorysuffixlength' => 0, 'categorysuffixchars' => '', 'categorysuffixlong' => 0, 'categorysuffixkeep' => 0, 'sectionshowhidden' => 2, 'sectionshowburied' => 0, 'sectionshowungraded' => 0, 'sectionshowzeroweighted' => 0, 'sectionshowuncategorized' => 0, 'sectiontitletags' => '', 'sectionshorttitles' => 0, 'sectionignorecase' => 0, 'sectionignorechars' => '', 'sectionprefixlength' => 0, 'sectionprefixchars' => '', 'sectionprefixlong' => 0, 'sectionprefixkeep' => 0, 'sectionsuffixlength' => 0, 'sectionsuffixchars' => '', 'sectionsuffixlong' => 0, 'sectionsuffixkeep' => 0, 'gradedisplay' => 1, 'showaverages' => 1, 'highgrade' => 90, 'mediumgrade' => 60, 'lowgrade' => 0, 'showactivitygrades' => '', 'sectionjumpmenu' => 1, 'sectionnumbers' => 1, 'singlesection' => 1, 'defaultsection' => 1, 'arrowup' => '', 'arrowdown' => '', 'gradebooklink' => 0, 'accesscontrol' => 0, 'hiddensections' => 0, 'hiddensectionstitle' => 0, 'hiddensectionsstyle' => 0, 'namelength' => 28, 'headlength' => 10, 'taillength' => 10, 'currentsection' => 0, 'groupsmenu' => 0, 'groupslabel' => 0, 'groupscountusers' => 0, 'groupssort' => 0, 'loginasmenu' => 0, 'loginassort' => 1, 'moodlecss' => 2, 'externalcss' => '', 'internalcss' => '');
     if (!isset($this->config)) {
         $this->config = new stdClass();
     }
     foreach ($defaults as $name => $value) {
         if (!isset($this->config->{$name})) {
             $this->config->{$name} = $value;
         }
     }
     // load user-defined title (may be empty)
     $this->title = $this->config->title;
     if (empty($COURSE->context)) {
         $COURSE->context = self::context(CONTEXT_COURSE, $COURSE->id);
     }
     $this->config->numsections = self::get_numsections($COURSE);
     // make sure user is only shown one course section at a time
     if (isset($USER->id) && isset($COURSE->id) && $this->config->singlesection) {
         $update = false;
         if (function_exists('course_get_display')) {
             // Moodle <= 2.2
             $displaysection = course_get_display($COURSE->id);
         } else {
             // Moodle >= 2.3
             $name = get_class($this) . '_course' . $COURSE->id;
             $displaysection = get_user_preferences($name, 0);
             if ($section == 0) {
                 $section = $displaysection;
             } else {
                 if ($displaysection == $section) {
                     // do nothing
                 } else {
                     $displaysection = $section;
                     $update = true;
                 }
             }
         }
         if ($displaysection == 0) {
             // no course section is currently selected for this user
             if ($displaysection = $this->config->defaultsection) {
                 // use default display section
             } else {
                 if ($displaysection = $COURSE->marker) {
                     // use highlighted section
                 } else {
                     // use first visible section
                     $select = 'course = ? AND section > ? AND visible = ?';
                     $params = array($COURSE->id, 0, 1);
                     $displaysection = $DB->get_field_select('course_sections', 'MIN(section)', $select, $params);
                 }
             }
             $update = true;
         }
         if ($update) {
             if (function_exists('course_set_display')) {
                 // Moodle <= 2.2
                 course_set_display($COURSE->id, $displaysection);
             } else {
                 // Moodle >= 2.3
                 $name = get_class($this) . '_course' . $COURSE->id;
                 set_user_preference($name, $displaysection);
             }
         }
     }
     // disable up/down arrows on Moodle >= 2.3
     if (function_exists('course_get_format')) {
         $this->config->arrowup = '';
         $this->config->arrowdown = '';
     }
     // disable hiddensections functionality, if the block is in the right column
     if (isset($this->instance->region) && $this->instance->region == BLOCK_POS_RIGHT) {
         $this->config->hiddensections = 0;
     }
     if (has_capability('moodle/course:manageactivities', $COURSE->context)) {
         $this->fix_course_format();
         $this->fix_section_visibility();
         $this->fix_course_marker();
     }
     $this->config->displaysection = $displaysection;
     $this->config->courseformat = $this->get_course_format($COURSE);
     $this->config->sectiontype = $this->get_section_type();
     $this->config->coursestartdate = $COURSE->startdate;
 }
 function get_sections()
 {
     global $CFG, $USER, $DB, $OUTPUT;
     if (!empty($this->instance)) {
         get_all_mods($this->course->id, $mods, $modnames, $modnamesplural, $modnamesused);
         $context = get_context_instance(CONTEXT_COURSE, $this->course->id);
         $isteacher = has_capability('moodle/course:update', $context);
         $courseFormat = $this->course->format == 'topics' ? 'topic' : 'week';
         // displaysection - current section
         $week = optional_param($courseFormat, -1, PARAM_INT);
         if ($week != -1) {
             $displaysection = course_set_display($this->course->id, $week);
         } else {
             if (isset($USER->display[$this->course->id])) {
                 $displaysection = $USER->display[$this->course->id];
             } else {
                 $displaysection = course_set_display($this->course->id, 0);
             }
         }
         $genericName = get_string("name" . $this->course->format, $this->blockname);
         $allSections = get_all_sections($this->course->id);
         $sections = array();
         if ($this->course->format != 'social' && $this->course->format != 'scorm') {
             foreach ($allSections as $k => $section) {
                 if ($k <= $this->course->numsections) {
                     // get_all_sections() may return sections that are in the db but not displayed because the number of the sections for this course was lowered - bug [CM-B10]
                     if (!empty($section)) {
                         $newSec = array();
                         $newSec['visible'] = $section->visible;
                         if (!empty($section->name)) {
                             $strsummary = trim($section->name);
                         } else {
                             $strsummary = ucwords($genericName) . " " . $k;
                             // just a default name
                         }
                         $strsummary = $this->trim($strsummary);
                         $strsummary = trim($this->clearEnters($strsummary));
                         $newSec['name'] = $strsummary;
                         // url
                         if ($displaysection != 0) {
                             $newSec['url'] = "{$CFG->wwwroot}/course/view.php?id={$this->course->id}&{$courseFormat}={$k}";
                         } else {
                             $newSec['url'] = "#section-{$k}";
                         }
                         // resources
                         $modinfo = unserialize($this->course->modinfo);
                         $newSec['resources'] = array();
                         $sectionmods = explode(",", $section->sequence);
                         foreach ($sectionmods as $modnumber) {
                             if (empty($mods[$modnumber])) {
                                 continue;
                             }
                             $mod = $mods[$modnumber];
                             if ($mod->visible or $isteacher) {
                                 $instancename = urldecode($modinfo[$modnumber]->name);
                                 if (!empty($CFG->filterall)) {
                                     $instancename = filter_text($instancename, $this->course->id);
                                 }
                                 if (!empty($modinfo[$modnumber]->extra)) {
                                     $extra = urldecode($modinfo[$modnumber]->extra);
                                 } else {
                                     $extra = "";
                                 }
                                 // don't do anything for labels
                                 if ($mod->modname != 'label') {
                                     // Normal activity
                                     if ($mod->visible) {
                                         if (!strlen(trim($instancename))) {
                                             $instancename = $mod->modfullname;
                                         }
                                         $instancename = $this->truncate_description($instancename);
                                         $resource = array();
                                         if ($mod->modname != 'resource') {
                                             $resource['name'] = $this->truncate_description($instancename, 200);
                                             $resource['url'] = "{$CFG->wwwroot}/mod/{$mod->modname}/view.php?id={$mod->id}";
                                             $icon = $OUTPUT->pix_url("icon", $mod->modname);
                                             if (is_object($icon)) {
                                                 $resource['icon'] = $icon->__toString();
                                             } else {
                                                 $resource['icon'] = '';
                                             }
                                         } else {
                                             require_once $CFG->dirroot . '/mod/resource/lib.php';
                                             $info = resource_get_coursemodule_info($mod);
                                             if (isset($info->icon)) {
                                                 $resource['name'] = $this->truncate_description($info->name, 200);
                                                 $resource['url'] = "{$CFG->wwwroot}/mod/{$mod->modname}/view.php?id={$mod->id}";
                                                 $icon = $OUTPUT->pix_url("icon", $mod->modname);
                                                 if (is_object($icon)) {
                                                     $resource['icon'] = $icon->__toString();
                                                 } else {
                                                     $resource['icon'] = '';
                                                 }
                                             } else {
                                                 if (!isset($info->icon)) {
                                                     $resource['name'] = $this->truncate_description($info->name, 200);
                                                     $resource['url'] = "{$CFG->wwwroot}/mod/{$mod->modname}/view.php?id={$mod->id}";
                                                     $icon = $OUTPUT->pix_url("icon", $mod->modname);
                                                     if (is_object($icon)) {
                                                         $resource['icon'] = $icon->__toString();
                                                     } else {
                                                         $resource['icon'] = $OUTPUT->pix_url("icon", $mod->modname);
                                                     }
                                                 }
                                             }
                                         }
                                         $newSec['resources'][] = $resource;
                                     }
                                 }
                             }
                         }
                         //hide hidden sections from students if the course settings say that - bug #212
                         $coursecontext = get_context_instance(CONTEXT_COURSE, $this->course->id);
                         if (!($section->visible == 0 && !has_capability('moodle/course:viewhiddensections', $coursecontext))) {
                             $sections[] = $newSec;
                         }
                     }
                 }
             }
             // get rid of the first one
             array_shift($sections);
         }
         return $sections;
     }
     return array();
 }
	        	    $responseobj->success = 0;
	        	    break;
				}
				$num--;
				$section_id += $dir;
			}
	 		if ($responseobj->success == 1) {
				$responseobj->reason = "Section moved ";
	        } else {
				$responseobj->reason = "An error occurred while moving a section " . $dir . ". broke at " . $num;
	        }
	        // Clear the navigation cache at this point so that the affects
	        // are seen immediatly on the navigation.
	        // $PAGE->navigation->clear_cache();
		}
        break;
	case ACTION_SET_DISPLAY :
		if($section_id >= 0) {
			course_set_display($course_id, $section_id);
		} else {
			$responseobj->success = 0;
	        $responseobj->reason = "Section out of range";
		}
		break;
	case ACTION_POSITION :
		
		break;
}

echo json_encode($responseobj);
Exemplo n.º 11
0
 /**
  * Validate that the version 1 plugin deletes appropriate associations when
  * deleting a course
  */
 public function test_version1importdeletecoursedeletesassociations()
 {
     global $DB, $CFG, $USER;
     require_once $CFG->dirroot . '/user/lib.php';
     require_once $CFG->dirroot . '/lib/gradelib.php';
     require_once $CFG->dirroot . '/group/lib.php';
     require_once $CFG->dirroot . '/lib/conditionlib.php';
     require_once $CFG->dirroot . '/lib/enrollib.php';
     require_once $CFG->dirroot . '/tag/lib.php';
     require_once $CFG->dirroot . '/lib/questionlib.php';
     // Setup.
     $initialnumcontexts = $DB->count_records('context', array('contextlevel' => CONTEXT_COURSE));
     $DB->delete_records('block_instances');
     // Set up the course with one section, including default blocks.
     set_config('defaultblocks_topics', 'search_forums');
     set_config('maxsections', 10, 'moodlecourse');
     $this->run_core_course_import(array('shortname' => 'deleteassociationsshortname', 'numsections' => 1));
     // Create a user record.
     $record = new stdClass();
     $record->username = '******';
     $record->password = '******';
     $userid = user_create_user($record);
     // Create a course-level role.
     $courseid = $DB->get_field('course', 'id', array('shortname' => 'deleteassociationsshortname'));
     $coursecontext = context_course::instance($courseid);
     $roleid = create_role('deleterole', 'deleterole', 'deleterole');
     set_role_contextlevels($roleid, array(CONTEXT_COURSE));
     $enrol = new stdClass();
     $enrol->enrol = 'manual';
     $enrol->courseid = $courseid;
     $enrol->status = ENROL_INSTANCE_ENABLED;
     if (!$DB->record_exists('enrol', (array) $enrol)) {
         $DB->insert_record('enrol', $enrol);
     }
     // Assign the user to the course-level role.
     enrol_try_internal_enrol($courseid, $userid, $roleid);
     // Create a grade item.
     $gradeitem = new grade_item(array('courseid' => $courseid, 'itemtype' => 'manual', 'itemname' => 'testitem'), false);
     $gradeitem->insert();
     $gradegrade = new grade_grade(array('itemid' => $gradeitem->id, 'userid' => $userid), false);
     // Assign the user a grade.
     $gradegrade->insert();
     // Create a grade outcome.
     $gradeoutcome = new grade_outcome(array('courseid' => $courseid, 'shortname' => 'bogusshortname', 'fullname' => 'bogusfullname'));
     $gradeoutcome->insert();
     // Create a grade scale.
     $gradescale = new grade_scale(array('courseid' => $courseid, 'name' => 'bogusname', 'userid' => $userid, 'scale' => 'bogusscale', 'description' => 'bogusdescription'));
     $gradescale->insert();
     // Set a grade setting value.
     grade_set_setting($courseid, 'bogus', 'bogus');
     // Set up a grade letter.
     $gradeletter = new stdClass();
     $gradeletter->contextid = $coursecontext->id;
     $gradeletter->lowerboundary = 80;
     $gradeletter->letter = 'A';
     $DB->insert_record('grade_letters', $gradeletter);
     // Set up a forum instance.
     $forum = new stdClass();
     $forum->course = $courseid;
     $forum->intro = 'intro';
     $forum->id = $DB->insert_record('forum', $forum);
     // Add it as a course module.
     $forum->module = $DB->get_field('modules', 'id', array('name' => 'forum'));
     $forum->instance = $forum->id;
     $cmid = add_course_module($forum);
     // Set up a completion record.
     $completion = new stdClass();
     $completion->coursemoduleid = $cmid;
     $completion->completionstate = 0;
     $completion->userid = 9999;
     $completion->timemodified = time();
     $DB->insert_record('course_modules_completion', $completion);
     // Set up a completion condition.
     $forum->id = $cmid;
     $ci = new condition_info($forum, CONDITION_MISSING_EVERYTHING, false);
     $ci->add_completion_condition($cmid, COMPLETION_ENABLED);
     // Set the blocks position.
     $instances = $DB->get_records('block_instances', array('parentcontextid' => $coursecontext->id));
     $page = new stdClass();
     $page->context = $coursecontext;
     $page->pagetype = 'course-view-*';
     $page->subpage = false;
     foreach ($instances as $instance) {
         blocks_set_visibility($instance, $page, 1);
     }
     // Create a group.
     $group = new stdClass();
     $group->name = 'testgroup';
     $group->courseid = $courseid;
     $groupid = groups_create_group($group);
     // Add the user to the group.
     groups_add_member($groupid, $userid);
     // Create a grouping containing our group.
     $grouping = new stdClass();
     $grouping->name = 'testgrouping';
     $grouping->courseid = $courseid;
     $groupingid = groups_create_grouping($grouping);
     groups_assign_grouping($groupingid, $groupid);
     // Set up a user tag.
     tag_set('course', $courseid, array('testtag'));
     // Add a course-level log.
     add_to_log($courseid, 'bogus', 'bogus');
     // Set up the default course question category.
     $newcategory = question_make_default_categories(array($coursecontext));
     // Create a test question.
     $question = new stdClass();
     $question->qtype = 'truefalse';
     $form = new stdClass();
     $form->category = $newcategory->id;
     $form->name = 'testquestion';
     $form->correctanswer = 1;
     $form->feedbacktrue = array('text' => 'bogustext', 'format' => FORMAT_HTML);
     $form->feedbackfalse = array('text' => 'bogustext', 'format' => FORMAT_HTML);
     $question = question_bank::get_qtype('truefalse')->save_question($question, $form);
     if (function_exists('course_set_display')) {
         // Set a "course display" setting.
         course_set_display($courseid, 1);
     }
     // Make a bogus backup record.
     $backupcourse = new stdClass();
     $backupcourse->courseid = $courseid;
     $DB->insert_record('backup_courses', $backupcourse);
     // Add a user lastaccess record.
     $lastaccess = new stdClass();
     $lastaccess->userid = $userid;
     $lastaccess->courseid = $courseid;
     $DB->insert_record('user_lastaccess', $lastaccess);
     // Make a bogus backup log record.
     $log = new stdClass();
     $log->backupid = $courseid;
     $log->timecreated = time();
     $log->loglevel = 1;
     $log->message = 'bogus';
     $DB->insert_record('backup_logs', $log);
     // Get initial counts.
     $initialnumcourse = $DB->count_records('course');
     $initialnumroleassignments = $DB->count_records('role_assignments');
     $initialnumuserenrolments = $DB->count_records('user_enrolments');
     $initialnumgradeitems = $DB->count_records('grade_items');
     $initialnumgradegrades = $DB->count_records('grade_grades');
     $initialnumgradeoutcomes = $DB->count_records('grade_outcomes');
     $initialnumgradeoutcomescourses = $DB->count_records('grade_outcomes_courses');
     $initialnumscale = $DB->count_records('scale');
     $initialnumgradesettings = $DB->count_records('grade_settings');
     $initialnumgradeletters = $DB->count_records('grade_letters');
     $initialnumforum = $DB->count_records('forum');
     $initialnumcoursemodules = $DB->count_records('course_modules');
     $initialnumcoursemodulescompletion = $DB->count_records('course_modules_completion');
     $initialnumcoursemodulesavailability = $DB->count_records('course_modules_availability');
     $initialnumblockinstances = $DB->count_records('block_instances');
     $initialnumblockpositions = $DB->count_records('block_positions');
     $initialnumgroups = $DB->count_records('groups');
     $initialnumgroupsmembers = $DB->count_records('groups_members');
     $initialnumgroupings = $DB->count_records('groupings');
     $initialnumgroupingsgroups = $DB->count_records('groupings_groups');
     $initialnumtaginstance = $DB->count_records('tag_instance');
     $initialnumcoursesections = $DB->count_records('course_sections');
     $initialnumquestioncategories = $DB->count_records('question_categories');
     $initialnumquestion = $DB->count_records('question');
     if (self::$coursedisplay) {
         $initialnumcoursedisplay = $DB->count_records('course_display');
     }
     $initialnumbackupcourses = $DB->count_records('backup_courses');
     $initialnumuserlastaccess = $DB->count_records('user_lastaccess');
     $initialnumbackuplogs = $DB->count_records('backup_logs');
     // Delete the course.
     $data = array('action' => 'delete', 'shortname' => 'deleteassociationsshortname');
     $this->run_core_course_import($data, false);
     // Validate the result.
     $this->assertEquals($DB->count_records('course'), $initialnumcourse - 1);
     $this->assertEquals($DB->count_records('role_assignments'), $initialnumroleassignments - 1);
     $this->assertEquals($DB->count_records('user_enrolments'), $initialnumuserenrolments - 1);
     $this->assertEquals($DB->count_records('grade_items'), $initialnumgradeitems - 2);
     $this->assertEquals($DB->count_records('grade_grades'), $initialnumgradegrades - 1);
     $this->assertEquals($DB->count_records('grade_outcomes'), $initialnumgradeoutcomes - 1);
     $this->assertEquals($DB->count_records('grade_outcomes_courses'), $initialnumgradeoutcomescourses - 1);
     $this->assertEquals($DB->count_records('scale'), $initialnumscale - 1);
     $this->assertEquals($DB->count_records('grade_settings'), $initialnumgradesettings - 1);
     $this->assertEquals($DB->count_records('grade_letters'), $initialnumgradeletters - 1);
     $this->assertEquals($DB->count_records('forum'), $initialnumforum - 1);
     $this->assertEquals($DB->count_records('course_modules'), $initialnumcoursemodules - 1);
     /*
      Uncomment the two lines below when this fix is available: http://tracker.moodle.org/browse/MDL-32988
      $this->assertEquals($DB->count_records('course_modules_completion'), $initialnumcourse_modules_completion - 1);
      $this->assertEquals($DB->count_records('course_modules_availability'), $initialnumcourse_modules_availability - 1);
     */
     $this->assertEquals($initialnumblockinstances - 4, $DB->count_records('block_instances'));
     $this->assertEquals($DB->count_records('block_positions'), 0);
     $this->assertEquals($DB->count_records('groups'), $initialnumgroups - 1);
     $this->assertEquals($DB->count_records('groups_members'), $initialnumgroupsmembers - 1);
     $this->assertEquals($DB->count_records('groupings'), $initialnumgroupings - 1);
     $this->assertEquals($DB->count_records('groupings_groups'), $initialnumgroupingsgroups - 1);
     $this->assertEquals($DB->count_records('log', array('course' => $courseid)), 0);
     $this->assertEquals($DB->count_records('tag_instance'), $initialnumtaginstance - 1);
     $this->assertEquals($DB->count_records('course_sections'), $initialnumcoursesections - 1);
     $this->assertEquals($DB->count_records('question_categories'), $initialnumquestioncategories - 1);
     $this->assertEquals($DB->count_records('question'), $initialnumquestion - 1);
     if (self::$coursedisplay) {
         $this->assertEquals($DB->count_records('course_display'), $initialnumcoursedisplay - 1);
     }
     $this->assertEquals($DB->count_records('backup_courses'), $initialnumbackupcourses - 1);
     $this->assertEquals($DB->count_records('user_lastaccess'), $initialnumuserlastaccess - 1);
 }
Exemplo n.º 12
0
 function get_content()
 {
     // cache content
     if (isset($this->content)) {
         return $this->content;
     }
     global $USER, $CFG;
     require_once $CFG->dirroot . '/course/lib.php';
     require_once $CFG->libdir . '/ajax/ajaxlib.php';
     $course = get_record('course', 'id', $this->instance->pageid);
     // if we're looking at the course home page
     if (strpos($_SERVER['REQUEST_URI'], 'course/view.php') != 0) {
         # get current section being displayed
         $week = optional_param('week', -1, PARAM_INT);
         if ($week != -1) {
             $display = course_set_display($course->id, $week);
         } else {
             if (isset($USER->display[$course->id])) {
                 $display = $USER->display[$course->id];
             } else {
                 $display = course_set_display($course->id, 0);
             }
         }
     } elseif (strpos($_SERVER['REQUEST_URI'], '/mod/') !== false) {
         // use on a module page
         $sql = 'select section from ' . $CFG->prefix . 'course_sections where id=(select section from ' . $CFG->prefix . 'course_modules where id=' . $_GET['id'] . ')';
         $row = get_record_sql($sql);
         $display = $row->section;
     } else {
         $display = 0;
     }
     if (in_array($course->format, array('topics', 'twu'))) {
         $format = 'topic';
     } else {
         $format = 'week';
     }
     get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
     $items = $this->visible_items($course);
     if (isset($items['outline'])) {
         //echo require_js(array('yui_yahoo','yui_event','yui_treeview'));
         echo require_js(array('yui_yahoo', 'yui_event', 'yui_dom-event', 'yui_treeview'));
     }
     // merge items
     $script = '';
     $menu = '';
     $menuid = 'yui_menu_tree_' . $this->instance->id;
     $even = true;
     $script = '';
     foreach ($items as $item => $v) {
         // add them to the tree in the order from configuration
         // even/odd classes
         $mod = 'r' . ($even ? '0' : '1');
         $even = !$even;
         // required parameters
         $url = htmlspecialchars($CFG->wwwroot . $v['url']);
         $ico = htmlspecialchars($v['icon']);
         $txt = htmlspecialchars($v['text']);
         // optional title attribute
         if (isset($v['title'])) {
             $title = " title = '" . htmlspecialchars($v['title']) . "'";
         } else {
             $title = '';
         }
         // add to menu
         $menu .= "\n<li class='{$mod} yui_menu_item_{$item}'>\n<div class='icon column c0'><img src='{$ico}' alt='' /></div>\n<div class='column c1'><a href='{$url}'{$title}>{$txt}</a></div>";
         if ($item == "outline") {
             if ($course->format != 'course-view-social') {
                 $menu .= "<div id='{$menuid}' class='yui_menu_outline_tree'></div>";
                 $script .= $this->course_sections($course, $mods, $display);
             }
         }
         $menu .= "</li>";
     }
     // print the tree
     // note: YUI treeview css must be included in theme
     $output = "\n        <ul class='list'>\n        {$menu}\n        </ul>";
     if (isset($items['outline'])) {
         $output .= "\n<script type='text/javascript'>//<![CDATA[\n\nfunction addTreeIcons(node) {\n    for(var c in node.children) {\n        child = node.children[c];\n        // e might be null, meaning the child hasn't been expanded yet\n        if (child._yui_menu_icon && (e = child.getLabelEl())) {\n            e.style.backgroundImage = 'url('+child._yui_menu_icon+')';\n            // more efficent if this is added as and event\n            child._yui_menu_icon = null;\n        }\n    }\n}\n\nvar tree = new YAHOO.widget.TreeView('{$menuid}');\nvar root = tree.getRoot();\n{$script}\ntree.draw();\n// configure icons for elements that have already been loaded\nfor(var c in root.children) addTreeIcons(root.children[c]);\n// for icons not yet loaded\ntree.subscribe('expandComplete', addTreeIcons);\n//]]>\n</script>\n";
     }
     $this->content = new stdClass();
     $this->content->text = $output;
     $this->content->footer = '';
     return $this->content;
 }