Example #1
0
                 if ($isaddednewblock || $undifinedinsertedid) {
                     if (!empty($countrecords)) {
                         $destweight = $recordexists ? $instweight->weight : $instweight->weight + 1;
                     } else {
                         $destweight = 0;
                     }
                 } else {
                     if (!empty($countrecords)) {
                         $destweight = $recordexists ? $instweight->weight : $instweight->weight + 1;
                     } else {
                         $destweight = 0;
                     }
                 }
             }
             blocks_move_block($PAGE, $blockinstance, $column, $destweight);
             $current_blocks = blocks_get_by_page_pinned($PAGE);
             global $COURSE;
             foreach ($current_blocks as $pos => $blocks) {
                 if (count($current_blocks[$pos]) == 0) {
                     print_side_block('', '', NULL, NULL, '', array('id' => $pos . 'inst0', 'class' => 'tempblockhandle'), '');
                 }
             }
             break;
     }
     break;
 case 'section':
     if (!record_exists('course_sections', 'course', $course->id, 'section', $id)) {
         error_log('AJAX commands.php: Bad Section ID ' . $id);
         die;
     }
     switch ($field) {
function blocks_setup(&$PAGE, $pinned = BLOCKS_PINNED_FALSE)
{
    switch ($pinned) {
        case BLOCKS_PINNED_TRUE:
            $pageblocks = blocks_get_pinned($PAGE);
            break;
        case BLOCKS_PINNED_BOTH:
            $pageblocks = blocks_get_by_page_pinned($PAGE);
            break;
        case BLOCKS_PINNED_FALSE:
        default:
            $pageblocks = blocks_get_by_page($PAGE);
            break;
    }
    blocks_execute_url_action($PAGE, $pageblocks, $pinned == BLOCKS_PINNED_TRUE);
    return $pageblocks;
}
Example #3
0
/**
 * Recursive function which, given a context, find all its children context ids.
 * @param object $context.
 * @return array of children context ids.
 */
function get_child_contexts($context)
{
    global $CFG;
    $children = array();
    switch ($context->contextlevel) {
        case CONTEXT_BLOCK:
            // No children.
            return array();
            break;
        case CONTEXT_MODULE:
            // No children.
            return array();
            break;
        case CONTEXT_GROUP:
            // No children.
            return array();
            break;
        case CONTEXT_COURSE:
            // Find all block instances for the course.
            $page = new page_course();
            $page->id = $context->instanceid;
            $page->type = 'course-view';
            if ($blocks = blocks_get_by_page_pinned($page)) {
                foreach ($blocks['l'] as $leftblock) {
                    if ($child = get_context_instance(CONTEXT_BLOCK, $leftblock->id)) {
                        array_push($children, $child->id);
                    }
                }
                foreach ($blocks['r'] as $rightblock) {
                    if ($child = get_context_instance(CONTEXT_BLOCK, $rightblock->id)) {
                        array_push($children, $child->id);
                    }
                }
            }
            // Find all module instances for the course.
            if ($modules = get_records('course_modules', 'course', $context->instanceid)) {
                foreach ($modules as $module) {
                    if ($child = get_context_instance(CONTEXT_MODULE, $module->id)) {
                        array_push($children, $child->id);
                    }
                }
            }
            // Find all group instances for the course.
            if ($groupids = groups_get_groups($context->instanceid)) {
                foreach ($groupids as $groupid) {
                    if ($child = get_context_instance(CONTEXT_GROUP, $groupid)) {
                        array_push($children, $child->id);
                    }
                }
            }
            return $children;
            break;
        case CONTEXT_COURSECAT:
            // We need to get the contexts for:
            //   1) The subcategories of the given category
            //   2) The courses in the given category and all its subcategories
            //   3) All the child contexts for these courses
            $categories = get_all_subcategories($context->instanceid);
            // Add the contexts for all the subcategories.
            foreach ($categories as $catid) {
                if ($catci = get_context_instance(CONTEXT_COURSECAT, $catid)) {
                    array_push($children, $catci->id);
                }
            }
            // Add the parent category as well so we can find the contexts
            // for its courses.
            array_unshift($categories, $context->instanceid);
            foreach ($categories as $catid) {
                // Find all courses for the category.
                if ($courses = get_records('course', 'category', $catid)) {
                    foreach ($courses as $course) {
                        if ($courseci = get_context_instance(CONTEXT_COURSE, $course->id)) {
                            array_push($children, $courseci->id);
                            $children = array_merge($children, get_child_contexts($courseci));
                        }
                    }
                }
            }
            return $children;
            break;
        case CONTEXT_USER:
            // No children.
            return array();
            break;
        case CONTEXT_PERSONAL:
            // No children.
            return array();
            break;
        case CONTEXT_SYSTEM:
            // Just get all the contexts except for CONTEXT_SYSTEM level.
            $sql = 'SELECT c.id ' . 'FROM ' . $CFG->prefix . 'context AS c ' . 'WHERE contextlevel != ' . CONTEXT_SYSTEM;
            $contexts = get_records_sql($sql);
            foreach ($contexts as $cid) {
                array_push($children, $cid->id);
            }
            return $children;
            break;
        default:
            error('This is an unknown context (' . $context->contextlevel . ') in get_child_contexts!');
            return false;
    }
}