public function add_form(&$mform, $locks)
 {
     global $COURSE;
     $optgrps = array('' => array(0 => get_string('choose')));
     // Need to filter out modules have have already been added
     $modules = page_get_modules($COURSE, 'name');
     foreach ($modules as $modnameplural => $instances) {
         foreach ($instances as $cmid => $name) {
             foreach ($locks as $lock) {
                 if ($lock['type'] == 'access' and $lock['cmid'] == $cmid) {
                     continue 2;
                 }
             }
             $optgrps[$modnameplural][$cmid] = $name;
         }
     }
     if (count($optgrps) == 1) {
         $mform->addElement('static', 'addaccessnone', '', get_string('activitiesfound', 'format_page'));
     } else {
         $mform->addElement('selectgroups', 'addaccess', get_string('activityaccessed', 'format_page'), $optgrps);
         $mform->setHelpButton('addaccess', array('accesslock', get_string('activityaccessed', 'format_page'), 'format_page'));
         $mform->setDefault('addaccess', 0);
         $mform->setType('addaccess', PARAM_INT);
     }
 }
Example #2
0
/**
 * This function displays the controls to add modules and blocks to a page
 *
 * @param object $page A fully populated page object
 * @param object $course A fully populated course object
 * @uses $USER;
 * @uses $CFG;
 */
function page_print_add_mods_form($page, $course)
{
    global $USER, $CFG, $PAGE;
    if (empty($PAGE)) {
        $PAGE = page_create_object(PAGE_COURSE_VIEW, $course->id);
    }
    print_box_start('centerpara addpageitems');
    // Add drop down to add blocks
    if ($blocks = get_records('block', 'visible', '1', 'name')) {
        $format = $PAGE->get_format_name();
        $options = array();
        foreach ($blocks as $b) {
            if (in_array($b->name, array('format_page', 'page_module'))) {
                continue;
            }
            if (!blocks_name_allowed_in_format($b->name, $format)) {
                continue;
            }
            $blockobject = block_instance($b->name);
            if ($blockobject !== false && $blockobject->user_can_addto($PAGE)) {
                $options[$b->id] = $blockobject->get_title();
            }
        }
        asort($options);
        print '<span class="addblock">';
        $common = $CFG->wwwroot . '/course/format/page/format.php?id=' . $course->id . '&amp;page=' . $page->id . '&amp;blockaction=add&amp;sesskey=' . sesskey() . '&amp;blockid=';
        popup_form($common, $options, 'addblock', '', get_string('addblock', 'format_page'));
        print '</span>&nbsp;';
    }
    // Add drop down to add existing module instances
    if ($modules = page_get_modules($course, 'name')) {
        // From our modules object we can build an existing module menu using separators
        $options = array();
        foreach ($modules as $modplural => $instances) {
            // Sets an optgroup which can't be selected/submitted
            $options[$modplural . '_group_start'] = "--{$modplural}";
            foreach ($instances as $cmid => $name) {
                $options[$cmid] = shorten_text($name);
            }
            // Ends an optgroup
            $options[$modplural . '_group_end'] = '--';
        }
        print '<span class="addexistingmodule">';
        $common = $CFG->wwwroot . '/course/format/page/format.php?id=' . $course->id . '&amp;page=' . $page->id . '&amp;blockaction=addmod&amp;sesskey=' . sesskey() . '&amp;instance=';
        popup_form($common, $options, 'addinstance', '', get_string('addexistingmodule', 'format_page'));
        print '</span>';
    }
    print_box_end();
}