Ejemplo n.º 1
0
 /**
  * Form definition
  */
 public function definition()
 {
     global $CFG, $DB, $PAGE;
     require_once $CFG->libdir . '/coursecatlib.php';
     $PAGE->requires->js_call_amd('tool_cat/form', 'init', array());
     $mform =& $this->_form;
     // Global update button.
     $mform->registerNoSubmitButton('updateform');
     $mform->addElement('submit', 'updateform', 'Update Form', array('class' => 'hidden'));
     // Select a category.
     $mform->addElement('header', 'info', 'Category');
     $catlist = \coursecat::make_categories_list('tool/cat:manage');
     $categories = array(0 => 'Please select a category');
     foreach ($catlist as $k => $v) {
         $categories[$k] = $v;
     }
     $mform->addElement('select', 'categoryid', 'Category', $categories);
     // Do we have a category?
     $category = optional_param('categoryid', false, PARAM_INT);
     if (!empty($category)) {
         $mform->setDefault('categoryid', $category);
         // Populate existing rules.
         $this->add_rule_fieldsets($category);
         // Print a blank rule-add row.
         $mform->addElement('header', 'rule_new', 'Add a new rule');
         $mform->setExpanded('rule_new');
         $this->add_rule_fieldset();
     }
     $this->add_action_buttons(true, 'Save rules');
 }
Ejemplo n.º 2
0
 private function get_category_tree($id)
 {
     global $DB;
     $category = $DB->get_record('course_categories', array('id' => $id));
     if ($id && !$category) {
         cli_error("Wrong category '{$id}'");
     } elseif (!$id) {
         $category = NULL;
     }
     $parentcategory = \coursecat::get($id);
     if ($parentcategory->has_children()) {
         $parentschildren = $parentcategory->get_children();
         foreach ($parentschildren as $singlecategory) {
             if ($singlecategory->has_children()) {
                 $childcategories = $this->get_category_tree($singlecategory->id);
                 $category->categories[] = $childcategories;
             } else {
                 // coursecat variables are protected, need to get data from db
                 $singlecategory = $DB->get_record('course_categories', array('id' => $singlecategory->id));
                 $category->categories[] = $singlecategory;
             }
         }
     }
     return $category;
 }
 function category_selector($url)
 {
     global $OUTPUT;
     $str = '';
     $choice = optional_param('category', 0, PARAM_INT);
     $categories = coursecat::make_categories_list();
     $str .= $OUTPUT->single_select($url, 'category', $categories, $choice, array('' => get_string('all', 'enrol_delayedcohort')));
     return $str;
 }
Ejemplo n.º 4
0
/**
 * Campus theme with the underlying Bootstrap theme.
 *
 * @package    theme
 * @subpackage campus
 * @copyright  © 2014-onwards G J Barnard in respect to modifications of the Clean theme.
 * @copyright  © 2014-onwards Work undertaken for David Bogner of Edulabs.org.
 * @author     G J Barnard - gjbarnard at gmail dot com and {@link http://moodle.org/user/profile.php?id=442195}
 * @author     Based on code originally written by Mary Evans, Bas Brands, Stuart Lamour and David Scotson.
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
function theme_campus_get_top_level_categories()
{
    global $CFG;
    include_once $CFG->libdir . '/coursecatlib.php';
    $categoryids = array();
    $categories = coursecat::get(0)->get_children();
    // Parent = 0 i.e. top-level categories only.
    foreach ($categories as $category) {
        $categoryids[$category->id] = $category->name;
    }
    return $categoryids;
}
Ejemplo n.º 5
0
    function definition() {
        global $CFG, $DB;
        $mform =& $this->_form;
        $category = $this->_customdata['category'];
        $editoroptions = $this->_customdata['editoroptions'];

        // get list of categories to use as parents, with site as the first one
        $options = array();
        if (has_capability('moodle/category:manage', context_system::instance()) || $category->parent == 0) {
            $options[0] = get_string('top');
        }
        if ($category->id) {
            // Editing an existing category.
            $options += coursecat::make_categories_list('moodle/category:manage', $category->id);
            if (empty($options[$category->parent])) {
                $options[$category->parent] = $DB->get_field('course_categories', 'name', array('id'=>$category->parent));
            }
            $strsubmit = get_string('savechanges');
        } else {
            // Making a new category
            $options += coursecat::make_categories_list('moodle/category:manage');
            $strsubmit = get_string('createcategory');
        }

        $mform->addElement('select', 'parent', get_string('parentcategory'), $options);
        $mform->addElement('text', 'name', get_string('categoryname'), array('size'=>'30'));
        $mform->addRule('name', get_string('required'), 'required', null);
        $mform->setType('name', PARAM_TEXT);
        $mform->addElement('text', 'idnumber', get_string('idnumbercoursecategory'),'maxlength="100"  size="10"');
        $mform->addHelpButton('idnumber', 'idnumbercoursecategory');
        $mform->setType('idnumber', PARAM_RAW);
        $mform->addElement('editor', 'description_editor', get_string('description'), null, $editoroptions);
        $mform->setType('description_editor', PARAM_RAW);
        if (!empty($CFG->allowcategorythemes)) {
            $themes = array(''=>get_string('forceno'));
            $allthemes = get_list_of_themes();
            foreach ($allthemes as $key=>$theme) {
                if (empty($theme->hidefromselector)) {
                    $themes[$key] = get_string('pluginname', 'theme_'.$theme->name);
                }
            }
            $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
        }

        $mform->addElement('hidden', 'id', 0);
        $mform->setType('id', PARAM_INT);
        $mform->setDefault('id', $category->id);

        $this->add_action_buttons(true, $strsubmit);
    }
Ejemplo n.º 6
0
 /**
  * Check that our hook is called when a course is deleted.
  */
 public function test_pre_course_category_delete_hook()
 {
     global $DB;
     // Should have nothing in the recycle bin.
     $this->assertEquals(0, $DB->count_records('tool_recyclebin_category'));
     delete_course($this->course, false);
     // Check the course is now in the recycle bin.
     $this->assertEquals(1, $DB->count_records('tool_recyclebin_category'));
     // Now let's delete the course category.
     $category = coursecat::get($this->course->category);
     $category->delete_full(false);
     // Check that the course was deleted from the category recycle bin.
     $this->assertEquals(0, $DB->count_records('tool_recyclebin_category'));
 }
Ejemplo n.º 7
0
function create_category_pditt($nama,$deskripsi=''){
    global $DB,  $CFG;
    $x = $DB->get_record('course_categories', array('name' => 'PDITT-' . $nama), '*');
    if (!$x){
        $data = new stdClass();
        $data->name='PDITT-' . $nama;
        $data->description=$deskripsi;
        $data->descriptionformat=0;
        $data->parent=0;
        $category = coursecat::create($data);
        return $category->id;
    } else {
        return $x->id;
    }
}
Ejemplo n.º 8
0
 protected function get_category_options($currentcontextid)
 {
     global $CFG;
     require_once $CFG->libdir . '/coursecatlib.php';
     $displaylist = coursecat::make_categories_list('moodle/cohort:manage');
     $options = array();
     $syscontext = context_system::instance();
     if (has_capability('moodle/cohort:manage', $syscontext)) {
         $options[$syscontext->id] = $syscontext->get_context_name();
     }
     foreach ($displaylist as $cid => $name) {
         $context = context_coursecat::instance($cid);
         $options[$context->id] = $name;
     }
     // Always add current - this is not likely, but if the logic gets changed it might be a problem.
     if (!isset($options[$currentcontextid])) {
         $context = context::instance_by_id($currentcontextid, MUST_EXIST);
         $options[$context->id] = $syscontext->get_context_name();
     }
     return $options;
 }
 public function get_courses(&$mform)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/course/lib.php';
     $buttonarray = array();
     // Get courses with enabled completion.
     $courses = $DB->get_records('course', array('enablecompletion' => COMPLETION_ENABLED));
     if (!empty($courses)) {
         require_once $CFG->libdir . '/coursecatlib.php';
         $list = coursecat::make_categories_list();
         $select = array();
         $selected = array();
         foreach ($courses as $c) {
             $select[$c->id] = $list[$c->category] . ' / ' . format_string($c->fullname, true, array('context' => context_course::instance($c->id)));
         }
         if ($this->id !== 0) {
             $selected = array_keys($this->params);
         }
         $settings = array('multiple' => 'multiple', 'size' => 20, 'style' => 'width:300px');
         $mform->addElement('select', 'courses', get_string('addcourse', 'badges'), $select, $settings);
         $mform->addRule('courses', get_string('requiredcourse', 'badges'), 'required');
         $mform->addHelpButton('courses', 'addcourse', 'badges');
         $buttonarray[] =& $mform->createElement('submit', 'submitcourse', get_string('addcourse', 'badges'));
         $buttonarray[] =& $mform->createElement('submit', 'cancel', get_string('cancel'));
         $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
         $mform->addElement('hidden', 'addcourse', 'addcourse');
         $mform->setType('addcourse', PARAM_TEXT);
         if ($this->id !== 0) {
             $mform->setDefault('courses', $selected);
         }
         $mform->setType('agg', PARAM_INT);
     } else {
         $mform->addElement('static', 'nocourses', '', get_string('error:nocourses', 'badges'));
         $buttonarray[] =& $mform->createElement('submit', 'cancel', get_string('continue'));
         $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
     }
 }
Ejemplo n.º 10
0
 function definition()
 {
     global $CFG, $DB, $USER;
     $mform =& $this->_form;
     if ($pending = $DB->get_records('course_request', array('requester' => $USER->id))) {
         $mform->addElement('header', 'pendinglist', get_string('coursespending'));
         $list = array();
         foreach ($pending as $cp) {
             $list[] = format_string($cp->fullname);
         }
         $list = implode(', ', $list);
         $mform->addElement('static', 'pendingcourses', get_string('courses'), $list);
     }
     $mform->addElement('header', 'coursedetails', get_string('courserequestdetails'));
     $mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"');
     $mform->addHelpButton('fullname', 'fullnamecourse');
     $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
     $mform->setType('fullname', PARAM_TEXT);
     $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"');
     $mform->addHelpButton('shortname', 'shortnamecourse');
     $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
     $mform->setType('shortname', PARAM_TEXT);
     if (!empty($CFG->requestcategoryselection)) {
         $displaylist = coursecat::make_categories_list();
         $mform->addElement('select', 'category', get_string('category'), $displaylist);
         $mform->setDefault('category', $CFG->defaultrequestcategory);
         $mform->addHelpButton('category', 'category');
     }
     $mform->addElement('editor', 'summary_editor', get_string('summary'), null, course_request::summary_editor_options());
     $mform->addHelpButton('summary_editor', 'coursesummary');
     $mform->setType('summary_editor', PARAM_RAW);
     $mform->addElement('header', 'requestreason', get_string('courserequestreason'));
     $mform->addElement('textarea', 'reason', get_string('courserequestsupport'), array('rows' => '15', 'cols' => '50'));
     $mform->addRule('reason', get_string('missingreqreason'), 'required', null, 'client');
     $mform->setType('reason', PARAM_TEXT);
     $this->add_action_buttons(true, get_string('requestcourse'));
 }
Ejemplo n.º 11
0
 /**
  * Create the fixture
  *
  * This method must be safe to call multiple times.
  *
  * @return void
  * @throws moodle_exception
  */
 public function build()
 {
     global $CFG, $DB;
     require_once $CFG->libdir . '/coursecatlib.php';
     if (!$this->exists()) {
         $course = (object) $this->get_options();
         // Clean course table - can happen when unit tests fail...
         if (!empty($course->shortname) and $record = $DB->get_record('course', array('shortname' => $course->shortname))) {
             delete_course($record, false);
         }
         if (!empty($course->idnumber) and $record = $DB->get_record('course', array('idnumber' => $course->idnumber))) {
             delete_course($record, false);
         }
         // Try to help folks out...
         if (!property_exists($course, 'category')) {
             $course->category = coursecat::get_default()->id;
         }
         if (!property_exists($course, 'fullname')) {
             $course->fullname = '';
         }
         $course = create_course($course);
         $this->set_results($DB->get_record('course', array('id' => $course->id), '*', MUST_EXIST));
     }
 }
Ejemplo n.º 12
0
 function definition()
 {
     global $USER, $CFG, $DB, $PAGE;
     $mform = $this->_form;
     $PAGE->requires->yui_module('moodle-course-formatchooser', 'M.course.init_formatchooser', array(array('formid' => $mform->getAttribute('id'))));
     $course = $this->_customdata['course'];
     // this contains the data of this form
     $category = $this->_customdata['category'];
     $editoroptions = $this->_customdata['editoroptions'];
     $returnto = $this->_customdata['returnto'];
     $systemcontext = context_system::instance();
     $categorycontext = context_coursecat::instance($category->id);
     if (!empty($course->id)) {
         $coursecontext = context_course::instance($course->id);
         $context = $coursecontext;
     } else {
         $coursecontext = null;
         $context = $categorycontext;
     }
     $courseconfig = get_config('moodlecourse');
     $this->course = $course;
     $this->context = $context;
     /// form definition with new course defaults
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('hidden', 'returnto', null);
     $mform->setType('returnto', PARAM_ALPHANUM);
     $mform->setConstant('returnto', $returnto);
     $mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"');
     $mform->addHelpButton('fullname', 'fullnamecourse');
     $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
     $mform->setType('fullname', PARAM_TEXT);
     if (!empty($course->id) and !has_capability('moodle/course:changefullname', $coursecontext)) {
         $mform->hardFreeze('fullname');
         $mform->setConstant('fullname', $course->fullname);
     }
     $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"');
     $mform->addHelpButton('shortname', 'shortnamecourse');
     $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
     $mform->setType('shortname', PARAM_TEXT);
     if (!empty($course->id) and !has_capability('moodle/course:changeshortname', $coursecontext)) {
         $mform->hardFreeze('shortname');
         $mform->setConstant('shortname', $course->shortname);
     }
     // Verify permissions to change course category or keep current.
     if (empty($course->id)) {
         if (has_capability('moodle/course:create', $categorycontext)) {
             $displaylist = coursecat::make_categories_list('moodle/course:create');
             $mform->addElement('select', 'category', get_string('coursecategory'), $displaylist);
             $mform->addHelpButton('category', 'coursecategory');
             $mform->setDefault('category', $category->id);
         } else {
             $mform->addElement('hidden', 'category', null);
             $mform->setType('category', PARAM_INT);
             $mform->setConstant('category', $category->id);
         }
     } else {
         if (has_capability('moodle/course:changecategory', $coursecontext)) {
             $displaylist = coursecat::make_categories_list('moodle/course:create');
             if (!isset($displaylist[$course->category])) {
                 //always keep current
                 $displaylist[$course->category] = coursecat::get($course->category)->get_formatted_name();
             }
             $mform->addElement('select', 'category', get_string('coursecategory'), $displaylist);
             $mform->addHelpButton('category', 'coursecategory');
         } else {
             //keep current
             $mform->addElement('hidden', 'category', null);
             $mform->setType('category', PARAM_INT);
             $mform->setConstant('category', $course->category);
         }
     }
     $choices = array();
     $choices['0'] = get_string('hide');
     $choices['1'] = get_string('show');
     $mform->addElement('select', 'visible', get_string('visible'), $choices);
     $mform->addHelpButton('visible', 'visible');
     $mform->setDefault('visible', $courseconfig->visible);
     if (!has_capability('moodle/course:visibility', $context)) {
         $mform->hardFreeze('visible');
         if (!empty($course->id)) {
             $mform->setConstant('visible', $course->visible);
         } else {
             $mform->setConstant('visible', $courseconfig->visible);
         }
     }
     $mform->addElement('date_selector', 'startdate', get_string('startdate'));
     $mform->addHelpButton('startdate', 'startdate');
     $mform->setDefault('startdate', time() + 3600 * 24);
     $mform->addElement('text', 'idnumber', get_string('idnumbercourse'), 'maxlength="100"  size="10"');
     $mform->addHelpButton('idnumber', 'idnumbercourse');
     $mform->setType('idnumber', PARAM_RAW);
     if (!empty($course->id) and !has_capability('moodle/course:changeidnumber', $coursecontext)) {
         $mform->hardFreeze('idnumber');
         $mform->setConstants('idnumber', $course->idnumber);
     }
     // Description.
     $mform->addElement('header', 'descriptionhdr', get_string('description'));
     $mform->setExpanded('descriptionhdr');
     $mform->addElement('editor', 'summary_editor', get_string('coursesummary'), null, $editoroptions);
     $mform->addHelpButton('summary_editor', 'coursesummary');
     $mform->setType('summary_editor', PARAM_RAW);
     $summaryfields = 'summary_editor';
     if ($overviewfilesoptions = course_overviewfiles_options($course)) {
         $mform->addElement('filemanager', 'overviewfiles_filemanager', get_string('courseoverviewfiles'), null, $overviewfilesoptions);
         $mform->addHelpButton('overviewfiles_filemanager', 'courseoverviewfiles');
         $summaryfields .= ',overviewfiles_filemanager';
     }
     if (!empty($course->id) and !has_capability('moodle/course:changesummary', $coursecontext)) {
         // Remove the description header it does not contain anything any more.
         $mform->removeElement('descriptionhdr');
         $mform->hardFreeze($summaryfields);
     }
     // Course format.
     $mform->addElement('header', 'courseformathdr', get_string('type_format', 'plugin'));
     $courseformats = get_sorted_course_formats(true);
     $formcourseformats = array();
     foreach ($courseformats as $courseformat) {
         $formcourseformats[$courseformat] = get_string('pluginname', "format_{$courseformat}");
     }
     if (isset($course->format)) {
         $course->format = course_get_format($course)->get_format();
         // replace with default if not found
         if (!in_array($course->format, $courseformats)) {
             // this format is disabled. Still display it in the dropdown
             $formcourseformats[$course->format] = get_string('withdisablednote', 'moodle', get_string('pluginname', 'format_' . $course->format));
         }
     }
     $mform->addElement('select', 'format', get_string('format'), $formcourseformats);
     $mform->addHelpButton('format', 'format');
     $mform->setDefault('format', $courseconfig->format);
     // Button to update format-specific options on format change (will be hidden by JavaScript).
     $mform->registerNoSubmitButton('updatecourseformat');
     $mform->addElement('submit', 'updatecourseformat', get_string('courseformatudpate'));
     // Just a placeholder for the course format options.
     $mform->addElement('hidden', 'addcourseformatoptionshere');
     $mform->setType('addcourseformatoptionshere', PARAM_BOOL);
     // Appearance.
     $mform->addElement('header', 'appearancehdr', get_string('appearance'));
     if (!empty($CFG->allowcoursethemes)) {
         $themeobjects = get_list_of_themes();
         $themes = array();
         $themes[''] = get_string('forceno');
         foreach ($themeobjects as $key => $theme) {
             if (empty($theme->hidefromselector)) {
                 $themes[$key] = get_string('pluginname', 'theme_' . $theme->name);
             }
         }
         $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
     }
     $languages = array();
     $languages[''] = get_string('forceno');
     $languages += get_string_manager()->get_list_of_translations();
     $mform->addElement('select', 'lang', get_string('forcelanguage'), $languages);
     $mform->setDefault('lang', $courseconfig->lang);
     $options = range(0, 10);
     $mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options);
     $mform->addHelpButton('newsitems', 'newsitemsnumber');
     $mform->setDefault('newsitems', $courseconfig->newsitems);
     $mform->addElement('selectyesno', 'showgrades', get_string('showgrades'));
     $mform->addHelpButton('showgrades', 'showgrades');
     $mform->setDefault('showgrades', $courseconfig->showgrades);
     $mform->addElement('selectyesno', 'showreports', get_string('showreports'));
     $mform->addHelpButton('showreports', 'showreports');
     $mform->setDefault('showreports', $courseconfig->showreports);
     // Files and uploads.
     $mform->addElement('header', 'filehdr', get_string('filesanduploads'));
     if (!empty($course->legacyfiles) or !empty($CFG->legacyfilesinnewcourses)) {
         if (empty($course->legacyfiles)) {
             //0 or missing means no legacy files ever used in this course - new course or nobody turned on legacy files yet
             $choices = array('0' => get_string('no'), '2' => get_string('yes'));
         } else {
             $choices = array('1' => get_string('no'), '2' => get_string('yes'));
         }
         $mform->addElement('select', 'legacyfiles', get_string('courselegacyfiles'), $choices);
         $mform->addHelpButton('legacyfiles', 'courselegacyfiles');
         if (!isset($courseconfig->legacyfiles)) {
             // in case this was not initialised properly due to switching of $CFG->legacyfilesinnewcourses
             $courseconfig->legacyfiles = 0;
         }
         $mform->setDefault('legacyfiles', $courseconfig->legacyfiles);
     }
     // Handle non-existing $course->maxbytes on course creation.
     $coursemaxbytes = !isset($course->maxbytes) ? null : $course->maxbytes;
     // Let's prepare the maxbytes popup.
     $choices = get_max_upload_sizes($CFG->maxbytes, 0, 0, $coursemaxbytes);
     $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices);
     $mform->addHelpButton('maxbytes', 'maximumupload');
     $mform->setDefault('maxbytes', $courseconfig->maxbytes);
     // Completion tracking.
     if (completion_info::is_enabled_for_site()) {
         $mform->addElement('header', 'completionhdr', get_string('completion', 'completion'));
         $mform->addElement('selectyesno', 'enablecompletion', get_string('enablecompletion', 'completion'));
         $mform->setDefault('enablecompletion', $courseconfig->enablecompletion);
         $mform->addHelpButton('enablecompletion', 'enablecompletion', 'completion');
     } else {
         $mform->addElement('hidden', 'enablecompletion');
         $mform->setType('enablecompletion', PARAM_INT);
         $mform->setDefault('enablecompletion', 0);
     }
     //--------------------------------------------------------------------------------
     enrol_course_edit_form($mform, $course, $context);
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'groups', get_string('groups', 'group'));
     $choices = array();
     $choices[NOGROUPS] = get_string('groupsnone', 'group');
     $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group');
     $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group');
     $mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $choices);
     $mform->addHelpButton('groupmode', 'groupmode', 'group');
     $mform->setDefault('groupmode', $courseconfig->groupmode);
     $mform->addElement('selectyesno', 'groupmodeforce', get_string('groupmodeforce', 'group'));
     $mform->addHelpButton('groupmodeforce', 'groupmodeforce', 'group');
     $mform->setDefault('groupmodeforce', $courseconfig->groupmodeforce);
     //default groupings selector
     $options = array();
     $options[0] = get_string('none');
     $mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options);
     //--------------------------------------------------------------------------------
     /// customizable role names in this course
     //--------------------------------------------------------------------------------
     $mform->addElement('header', 'rolerenaming', get_string('rolerenaming'));
     $mform->addHelpButton('rolerenaming', 'rolerenaming');
     if ($roles = get_all_roles()) {
         $roles = role_fix_names($roles, null, ROLENAME_ORIGINAL);
         $assignableroles = get_roles_for_contextlevels(CONTEXT_COURSE);
         foreach ($roles as $role) {
             $mform->addElement('text', 'role_' . $role->id, get_string('yourwordforx', '', $role->localname));
             $mform->setType('role_' . $role->id, PARAM_TEXT);
         }
     }
     //--------------------------------------------------------------------------------
     $this->add_action_buttons();
     //--------------------------------------------------------------------------------
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
     /// finally set the current form data
     //--------------------------------------------------------------------------------
     $this->set_data($course);
 }
Ejemplo n.º 13
0
/**
 * Print courses in category. If category is 0 then all courses are printed.
 *
 * @deprecated since 2.5
 *
 * To print a generic list of courses use:
 * $renderer = $PAGE->get_renderer('core', 'course');
 * echo $renderer->courses_list($courses);
 *
 * To print list of all courses:
 * $renderer = $PAGE->get_renderer('core', 'course');
 * echo $renderer->frontpage_available_courses();
 *
 * To print list of courses inside category:
 * $renderer = $PAGE->get_renderer('core', 'course');
 * echo $renderer->course_category($category); // this will also print subcategories
 *
 * @param int|stdClass $category category object or id.
 * @return bool true if courses found and printed, else false.
 */
function print_courses($category)
{
    global $CFG, $OUTPUT, $PAGE;
    require_once $CFG->libdir . '/coursecatlib.php';
    debugging('Function print_courses() is deprecated, please use course renderer', DEBUG_DEVELOPER);
    if (!is_object($category) && $category == 0) {
        $courses = coursecat::get(0)->get_courses(array('recursive' => true, 'summary' => true, 'coursecontacts' => true));
    } else {
        $courses = coursecat::get($category->id)->get_courses(array('summary' => true, 'coursecontacts' => true));
    }
    if ($courses) {
        $renderer = $PAGE->get_renderer('core', 'course');
        echo $renderer->courses_list($courses);
    } else {
        echo $OUTPUT->heading(get_string("nocoursesyet"));
        $context = context_system::instance();
        if (has_capability('moodle/course:create', $context)) {
            $options = array();
            if (!empty($category->id)) {
                $options['category'] = $category->id;
            } else {
                $options['category'] = $CFG->defaultrequestcategory;
            }
            echo html_writer::start_tag('div', array('class' => 'addcoursebutton'));
            echo $OUTPUT->single_button(new moodle_url('/course/edit.php', $options), get_string("addnewcourse"));
            echo html_writer::end_tag('div');
            return false;
        }
    }
    return true;
}
Ejemplo n.º 14
0
 /**
  * Returns an array of course categories
  * @return array of course categories
  */
 function get_course_categories()
 {
     global $CFG;
     require_once $CFG->libdir . '/coursecatlib.php';
     return array(0 => get_string('anycategory', 'filters')) + coursecat::make_categories_list();
 }
 /**
  * Add new course without a category.
  */
 public function test_course_add_default_category()
 {
     global $DB, $CFG;
     require_once $CFG->libdir . '/coursecatlib.php';
     $this->imsplugin->set_config('createnewcategories', false);
     // Delete the default category, to ensure the plugin handles this gracefully.
     $defaultcat = coursecat::get_default();
     $defaultcat->delete_full(false);
     // Create an course with the IMS plugin without a category.
     $course1 = new stdClass();
     $course1->idnumber = 'id1';
     $course1->imsshort = 'id1';
     $course1->category = '';
     $this->set_xml_file(false, array($course1));
     $this->imsplugin->cron();
     // Check the course has been created.
     $dbcourse = $DB->get_record('course', array('idnumber' => $course1->idnumber), '*', MUST_EXIST);
     // Check that it belongs to a category which exists.
     $this->assertTrue($DB->record_exists('course_categories', array('id' => $dbcourse->category)));
 }
Ejemplo n.º 16
0
    /**
     * Delete categories
     *
     * @param array $categories A list of category ids
     * @return array
     * @since Moodle 2.3
     */
    public static function delete_categories($categories) {
        global $CFG, $DB;
        require_once($CFG->dirroot . "/course/lib.php");
        require_once($CFG->libdir . "/coursecatlib.php");

        // Validate parameters.
        $params = self::validate_parameters(self::delete_categories_parameters(), array('categories' => $categories));

        $transaction = $DB->start_delegated_transaction();

        foreach ($params['categories'] as $category) {
            $deletecat = coursecat::get($category['id'], MUST_EXIST);
            $context = context_coursecat::instance($deletecat->id);
            require_capability('moodle/category:manage', $context);
            self::validate_context($context);
            self::validate_context(get_category_or_system_context($deletecat->parent));

            if ($category['recursive']) {
                // If recursive was specified, then we recursively delete the category's contents.
                if ($deletecat->can_delete_full()) {
                    $deletecat->delete_full(false);
                } else {
                    throw new moodle_exception('youcannotdeletecategory', '', '', $deletecat->get_formatted_name());
                }
            } else {
                // In this situation, we don't delete the category's contents, we either move it to newparent or parent.
                // If the parent is the root, moving is not supported (because a course must always be inside a category).
                // We must move to an existing category.
                if (!empty($category['newparent'])) {
                    $newparentcat = coursecat::get($category['newparent']);
                } else {
                    $newparentcat = coursecat::get($deletecat->parent);
                }

                // This operation is not allowed. We must move contents to an existing category.
                if (!$newparentcat->id) {
                    throw new moodle_exception('movecatcontentstoroot');
                }

                self::validate_context(context_coursecat::instance($newparentcat->id));
                if ($deletecat->can_move_content_to($newparentcat->id)) {
                    $deletecat->delete_move($newparentcat->id, false);
                } else {
                    throw new moodle_exception('youcannotdeletecategory', '', '', $deletecat->get_formatted_name());
                }
            }
        }

        $transaction->allow_commit();
    }
 function get_content()
 {
     global $CFG, $USER, $DB, $OUTPUT;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     $icon = '<img src="' . $OUTPUT->pix_url('i/course') . '" class="icon" alt="" />';
     $adminseesall = true;
     if (isset($CFG->block_course_list_adminview)) {
         if ($CFG->block_course_list_adminview == 'own') {
             $adminseesall = false;
         }
     }
     if (empty($CFG->disablemycourses) and isloggedin() and !isguestuser() and !(has_capability('moodle/course:update', context_system::instance()) and $adminseesall)) {
         // Just print My Courses
         if ($courses = enrol_get_my_courses(NULL, 'visible DESC, fullname ASC')) {
             foreach ($courses as $course) {
                 $coursecontext = context_course::instance($course->id);
                 $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
                 $this->content->items[] = "<a {$linkcss} title=\"" . format_string($course->shortname, true, array('context' => $coursecontext)) . "\" " . "href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">" . $icon . format_string(get_course_display_name_for_list($course)) . "</a>";
             }
             $this->title = get_string('mycourses');
             /// If we can update any course of the view all isn't hidden, show the view all courses link
             if (has_capability('moodle/course:update', context_system::instance()) || empty($CFG->block_course_list_hideallcourseslink)) {
                 $this->content->footer = "<a href=\"{$CFG->wwwroot}/course/index.php\">" . get_string("fulllistofcourses") . "</a> ...";
             }
         }
         $this->get_remote_courses();
         if ($this->content->items) {
             // make sure we don't return an empty list
             return $this->content;
         }
     }
     $categories = coursecat::get(0)->get_children();
     // Parent = 0   ie top-level categories only
     if ($categories) {
         //Check we have categories
         if (count($categories) > 1 || count($categories) == 1 && $DB->count_records('course') > 200) {
             // Just print top level category links
             foreach ($categories as $category) {
                 $categoryname = $category->get_formatted_name();
                 $linkcss = $category->visible ? "" : " class=\"dimmed\" ";
                 $this->content->items[] = "<a {$linkcss} href=\"{$CFG->wwwroot}/course/index.php?categoryid={$category->id}\">" . $icon . $categoryname . "</a>";
             }
             /// If we can update any course of the view all isn't hidden, show the view all courses link
             if (has_capability('moodle/course:update', context_system::instance()) || empty($CFG->block_course_list_hideallcourseslink)) {
                 $this->content->footer .= "<a href=\"{$CFG->wwwroot}/course/index.php\">" . get_string('fulllistofcourses') . '</a> ...';
             }
             $this->title = get_string('categories');
         } else {
             // Just print course names of single category
             $category = array_shift($categories);
             $courses = get_courses($category->id);
             if ($courses) {
                 foreach ($courses as $course) {
                     $coursecontext = context_course::instance($course->id);
                     $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
                     $this->content->items[] = "<a {$linkcss} title=\"" . format_string($course->shortname, true, array('context' => $coursecontext)) . "\" " . "href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">" . $icon . format_string(get_course_display_name_for_list($course), true, array('context' => context_course::instance($course->id))) . "</a>";
                 }
                 /// If we can update any course of the view all isn't hidden, show the view all courses link
                 if (has_capability('moodle/course:update', context_system::instance()) || empty($CFG->block_course_list_hideallcourseslink)) {
                     $this->content->footer .= "<a href=\"{$CFG->wwwroot}/course/index.php\">" . get_string('fulllistofcourses') . '</a> ...';
                 }
                 $this->get_remote_courses();
             } else {
                 $this->content->icons[] = '';
                 $this->content->items[] = get_string('nocoursesyet');
                 if (has_capability('moodle/course:create', context_coursecat::instance($category->id))) {
                     $this->content->footer = '<a href="' . $CFG->wwwroot . '/course/edit.php?category=' . $category->id . '">' . get_string("addnewcourse") . '</a> ...';
                 }
                 $this->get_remote_courses();
             }
             $this->title = get_string('courses');
         }
     }
     return $this->content;
 }
Ejemplo n.º 18
0
         continue;
     }
     list($ignored, $roleid) = explode('_', $fieldname);
     $rolename = new stdClass();
     $rolename->catid = $id;
     $rolename->roleid = $roleid;
     $rolename->name = $value;
     $newrolenames[] = $rolename;
 }
 // This is for updating all categories and courses.
 $cats = array(coursecat::get($id));
 $courses = array();
 if ($categories = coursecat::get($id)->get_children()) {
     foreach ($categories as $cat) {
         array_push($cats, $cat);
         $cats = array_merge($cats, coursecat::get($cat->id)->get_children());
     }
 }
 // Update all the category's.
 foreach ($cats as $coursecat) {
     $courses = array_merge($courses, get_courses($coursecat->id));
     foreach ($newrolenames as $role) {
         if (!$role->name) {
             $DB->delete_records('cat_role_names', array('catid' => $coursecat->id, 'roleid' => $role->roleid));
         } else {
             if ($rolename = $DB->get_record('cat_role_names', array('catid' => $coursecat->id, 'roleid' => $role->roleid))) {
                 $rolename->name = $role->name;
                 $DB->update_record('cat_role_names', $rolename);
             } else {
                 $rolename = new stdClass();
                 $rolename->catid = $coursecat->id;
 protected function coursecat_coursebox_content(coursecat_helper $chelper, $course)
 {
     global $CFG;
     if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
         return '';
     }
     if ($course instanceof stdClass) {
         require_once $CFG->libdir . '/coursecatlib.php';
         $course = new course_in_list($course);
     }
     $content = '';
     // Display course overview files.
     $contentimages = $contentfiles = '';
     foreach ($course->get_course_overviewfiles() as $file) {
         $isimage = $file->is_valid_image();
         $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
         if ($isimage) {
             $contentimages .= html_writer::start_tag('div', array('class' => 'imagebox'));
             $images = html_writer::empty_tag('img', array('src' => $url, 'alt' => 'Course Image ' . $course->fullname, 'class' => 'courseimage'));
             $contentimages .= html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)), $images);
             $contentimages .= html_writer::end_tag('div');
         } else {
             $image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle');
             $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')) . html_writer::tag('span', $file->get_filename(), array('class' => 'fp-filename'));
             $contentfiles .= html_writer::tag('span', html_writer::link($url, $filename), array('class' => 'coursefile fp-filename-icon'));
         }
     }
     $content .= $contentimages . $contentfiles;
     // Display course summary.
     if ($course->has_summary()) {
         $content .= $chelper->get_course_formatted_summary($course);
     }
     // Display course contacts. See course_in_list::get_course_contacts().
     if ($course->has_course_contacts()) {
         $content .= html_writer::start_tag('ul', array('class' => 'teachers'));
         foreach ($course->get_course_contacts() as $userid => $coursecontact) {
             $name = $coursecontact['rolename'] . ': ' . html_writer::link(new moodle_url('/user/view.php', array('id' => $userid, 'course' => SITEID)), $coursecontact['username']);
             $content .= html_writer::tag('li', $name);
         }
         $content .= html_writer::end_tag('ul');
         // End .teachers div.
     }
     // Display course category if necessary (for example in search results).
     if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT) {
         require_once $CFG->libdir . '/coursecatlib.php';
         if ($cat = coursecat::get($course->category, IGNORE_MISSING)) {
             $content .= html_writer::start_tag('div', array('class' => 'coursecat'));
             $content .= get_string('category') . ': ' . html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)), $cat->get_formatted_name(), array('class' => $cat->visible ? '' : 'dimmed'));
             $content .= html_writer::end_tag('div');
             // End .coursecat div.
         }
     }
     return $content;
 }
Ejemplo n.º 20
0
 /**
  * Search courses following the specified criteria.
  *
  * @param string $criterianame  Criteria name (search, modulelist (only admins), blocklist (only admins), tagid)
  * @param string $criteriavalue Criteria value
  * @param int $page             Page number (for pagination)
  * @param int $perpage          Items per page
  * @param array $requiredcapabilities Optional list of required capabilities (used to filter the list).
  * @param int $limittoenrolled  Limit to only enrolled courses
  * @return array of course objects and warnings
  * @since Moodle 3.0
  * @throws moodle_exception
  */
 public static function search_courses($criterianame, $criteriavalue, $page = 0, $perpage = 0, $requiredcapabilities = array(), $limittoenrolled = 0)
 {
     global $CFG;
     require_once $CFG->libdir . '/coursecatlib.php';
     $warnings = array();
     $parameters = array('criterianame' => $criterianame, 'criteriavalue' => $criteriavalue, 'page' => $page, 'perpage' => $perpage, 'requiredcapabilities' => $requiredcapabilities);
     $params = self::validate_parameters(self::search_courses_parameters(), $parameters);
     self::validate_context(context_system::instance());
     $allowedcriterianames = array('search', 'modulelist', 'blocklist', 'tagid');
     if (!in_array($params['criterianame'], $allowedcriterianames)) {
         throw new invalid_parameter_exception('Invalid value for criterianame parameter (value: ' . $params['criterianame'] . '),' . 'allowed values are: ' . implode(',', $allowedcriterianames));
     }
     if ($params['criterianame'] == 'modulelist' or $params['criterianame'] == 'blocklist') {
         require_capability('moodle/site:config', context_system::instance());
     }
     $paramtype = array('search' => PARAM_RAW, 'modulelist' => PARAM_PLUGIN, 'blocklist' => PARAM_INT, 'tagid' => PARAM_INT);
     $params['criteriavalue'] = clean_param($params['criteriavalue'], $paramtype[$params['criterianame']]);
     // Prepare the search API options.
     $searchcriteria = array();
     $searchcriteria[$params['criterianame']] = $params['criteriavalue'];
     $options = array();
     if ($params['perpage'] != 0) {
         $offset = $params['page'] * $params['perpage'];
         $options = array('offset' => $offset, 'limit' => $params['perpage']);
     }
     // Search the courses.
     $courses = coursecat::search_courses($searchcriteria, $options, $params['requiredcapabilities']);
     $totalcount = coursecat::search_courses_count($searchcriteria, $options, $params['requiredcapabilities']);
     if (!empty($limittoenrolled)) {
         // Get the courses where the current user has access.
         $enrolled = enrol_get_my_courses(array('id', 'cacherev'));
     }
     $finalcourses = array();
     $categoriescache = array();
     foreach ($courses as $course) {
         if (!empty($limittoenrolled)) {
             // Filter out not enrolled courses.
             if (!isset($enrolled[$course->id])) {
                 $totalcount--;
                 continue;
             }
         }
         $coursecontext = context_course::instance($course->id);
         $finalcourses[] = self::get_course_public_information($course, $coursecontext);
     }
     return array('total' => $totalcount, 'courses' => $finalcourses, 'warnings' => $warnings);
 }
Ejemplo n.º 21
0
 /**
  * Returns the category where this course request should be created
  *
  * Note that we don't check here that user has a capability to view
  * hidden categories if he has capabilities 'moodle/site:approvecourse' and
  * 'moodle/course:changecategory'
  *
  * @return coursecat
  */
 public function get_category()
 {
     global $CFG;
     require_once $CFG->libdir . '/coursecatlib.php';
     // If the category is not set, if the current user does not have the rights to change the category, or if the
     // category does not exist, we set the default category to the course to be approved.
     // The system level is used because the capability moodle/site:approvecourse is based on a system level.
     if (empty($this->properties->category) || !has_capability('moodle/course:changecategory', context_system::instance()) || !($category = coursecat::get($this->properties->category, IGNORE_MISSING, true))) {
         $category = coursecat::get($CFG->defaultrequestcategory, IGNORE_MISSING, true);
     }
     if (!$category) {
         $category = coursecat::get_default();
     }
     return $category;
 }
Ejemplo n.º 22
0
/**
 * Searches for categories using a substring match.
 *
 * @param string $query The substring to search for.
 * @return array Matching categories or returns no matches found.
 */
function report_ncccscensus_category_search($query)
{
    global $DB;
    $sqlquery = 'SELECT id, name FROM {course_categories} WHERE name LIKE ? ';
    $categories = $DB->get_records_sql($sqlquery, array("%{$query}%"));
    $results = array();
    foreach ($categories as $category) {
        $category = coursecat::get($category->id);
        $parents = $category->get_parents();
        $categorynames = array();
        foreach ($parents as $categoryid) {
            $tempcategory = coursecat::get($categoryid);
            array_push($categorynames, $tempcategory->get_formatted_name());
        }
        array_push($categorynames, $category->get_formatted_name());
        $name = array_pop($categorynames);
        if (count($categorynames) > 0) {
            $name = array_pop($categorynames) . ' / ' . $name;
        }
        array_push($results, array('id' => $category->id, 'name' => $name));
    }
    if (count($results) === 0) {
        array_push($results, array('name' => get_string('noresults', 'report_ncccscensus') . " {$query}"));
    }
    return $results;
}
Ejemplo n.º 23
0
 /**
  * Returns list of course contacts (usually teachers) to display in course link
  *
  * Roles to display are set up in $CFG->coursecontact
  *
  * The result is the list of users where user id is the key and the value
  * is an array with elements:
  *  - 'user' - object containing basic user information
  *  - 'role' - object containing basic role information (id, name, shortname, coursealias)
  *  - 'rolename' => role_get_name($role, $context, ROLENAME_ALIAS)
  *  - 'username' => fullname($user, $canviewfullnames)
  *
  * @return array
  */
 public function get_course_contacts()
 {
     global $CFG;
     if (empty($CFG->coursecontact)) {
         // No roles are configured to be displayed as course contacts.
         return array();
     }
     if ($this->coursecontacts === null) {
         $this->coursecontacts = array();
         $context = context_course::instance($this->id);
         if (!isset($this->record->managers)) {
             // Preload course contacts from DB.
             $courses = array($this->id => &$this->record);
             coursecat::preload_course_contacts($courses);
         }
         // Build return array with full roles names (for this course context) and users names.
         $canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
         foreach ($this->record->managers as $ruser) {
             if (isset($this->coursecontacts[$ruser->id])) {
                 // Only display a user once with the highest sortorder role.
                 continue;
             }
             $user = new stdClass();
             $user = username_load_fields_from_object($user, $ruser, null, array('id', 'username'));
             $role = new stdClass();
             $role->id = $ruser->roleid;
             $role->name = $ruser->rolename;
             $role->shortname = $ruser->roleshortname;
             $role->coursealias = $ruser->rolecoursealias;
             $this->coursecontacts[$user->id] = array('user' => $user, 'role' => $role, 'rolename' => role_get_name($role, $context, ROLENAME_ALIAS), 'username' => fullname($user, $canviewfullnames));
         }
     }
     return $this->coursecontacts;
 }
Ejemplo n.º 24
0
 /**
  * Defines the form.
  */
 public function definition()
 {
     $mform = $this->_form;
     $this->coursecat = $this->_customdata;
     $categorycontext = context_coursecat::instance($this->coursecat->id);
     $categoryname = $this->coursecat->get_formatted_name();
     // Check permissions, to see if it OK to give the option to delete
     // the contents, rather than move elsewhere.
     $candeletecontent = $this->coursecat->can_delete_full();
     // Get the list of categories we might be able to move to.
     $displaylist = $this->coursecat->move_content_targets_list();
     // Now build the options.
     $options = array();
     if ($displaylist) {
         $options[0] = get_string('movecontentstoanothercategory');
     }
     if ($candeletecontent) {
         $options[1] = get_string('deleteallcannotundo');
     }
     if (empty($options)) {
         print_error('youcannotdeletecategory', 'error', 'index.php', $categoryname);
     }
     // Now build the form.
     $mform->addElement('header', 'general', get_string('categorycurrentcontents', '', $categoryname));
     // Describe the contents of this category.
     $contents = '';
     if ($this->coursecat->has_children()) {
         $contents .= '<li>' . get_string('subcategories') . '</li>';
     }
     if ($this->coursecat->has_courses()) {
         $contents .= '<li>' . get_string('courses') . '</li>';
     }
     if (question_context_has_any_questions($categorycontext)) {
         $contents .= '<li>' . get_string('questionsinthequestionbank') . '</li>';
     }
     if (!empty($contents)) {
         $mform->addElement('static', 'emptymessage', get_string('thiscategorycontains'), html_writer::tag('ul', $contents));
     } else {
         $mform->addElement('static', 'emptymessage', '', get_string('deletecategoryempty'));
     }
     // Give the options for what to do.
     $mform->addElement('select', 'fulldelete', get_string('whattodo'), $options);
     if (count($options) == 1) {
         $optionkeys = array_keys($options);
         $option = reset($optionkeys);
         $mform->hardFreeze('fulldelete');
         $mform->setConstant('fulldelete', $option);
     }
     if ($displaylist) {
         $mform->addElement('select', 'newparent', get_string('movecategorycontentto'), $displaylist);
         if (in_array($this->coursecat->parent, $displaylist)) {
             $mform->setDefault('newparent', $this->coursecat->parent);
         }
         $mform->disabledIf('newparent', 'fulldelete', 'eq', '1');
     }
     $mform->addElement('hidden', 'categoryid', $this->coursecat->id);
     $mform->setType('categoryid', PARAM_ALPHANUM);
     $mform->addElement('hidden', 'action', 'deletecategory');
     $mform->setType('action', PARAM_ALPHANUM);
     $mform->addElement('hidden', 'sure');
     // This gets set by default to ensure that if the user changes it manually we can detect it.
     $mform->setDefault('sure', md5(serialize($this->coursecat)));
     $mform->setType('sure', PARAM_ALPHANUM);
     $this->add_action_buttons(true, get_string('delete'));
 }
 public function frontpage_available_courses()
 {
     /* available courses */
     global $CFG, $OUTPUT, $PAGE;
     require_once $CFG->libdir . '/coursecatlib.php';
     $chelper = new coursecat_helper();
     $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED)->set_courses_display_options(array('recursive' => true, 'limit' => $CFG->frontpagecourselimit, 'viewmoreurl' => new moodle_url('/course/index.php'), 'viewmoretext' => new lang_string('fulllistofcourses')));
     $chelper->set_attributes(array('class' => 'frontpage-course-list-all'));
     $courses = coursecat::get(0)->get_courses($chelper->get_courses_display_options());
     $totalcount = coursecat::get(0)->get_courses_count($chelper->get_courses_display_options());
     $rcourseids = array_keys($courses);
     $acourseids = array_chunk($rcourseids, 5);
     $newcourse = get_string('availablecourses');
     $header = '<div id="frontpage-course-list">
     <h2>' . $newcourse . '</h2>
     <div class="courses frontpage-course-list-all">';
     $footer = '
     </div>
     </div>';
     $content = '';
     if (count($rcourseids) > 0) {
         foreach ($acourseids as $courseids) {
             $content .= '<div class="row-fluid">';
             $rowcontent = '';
             foreach ($courseids as $courseid) {
                 $course = get_course($courseid);
                 $no = get_config('theme_pioneer', 'patternselect');
                 $nimgp = empty($no) || $no == "default" ? 'no-image' : 'cs0' . $no . '/no-image';
                 $summary = theme_pioneer_strip_html_tags($course->summary);
                 $summary = theme_pioneer_course_trim_char($summary, 20);
                 $trimtitle = theme_pioneer_course_trim_char($course->fullname, 25);
                 $noimgurl = $OUTPUT->pix_url($nimgp, 'theme');
                 $courseurl = new moodle_url('/course/view.php', array('id' => $courseid));
                 if ($course instanceof stdClass) {
                     require_once $CFG->libdir . '/coursecatlib.php';
                     $course = new course_in_list($course);
                 }
                 $imgurl = '';
                 $context = context_course::instance($course->id);
                 foreach ($course->get_course_overviewfiles() as $file) {
                     $isimage = $file->is_valid_image();
                     $imgurl = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
                     if (!$isimage) {
                         $imgurl = $noimgurl;
                     }
                 }
                 if (empty($imgurl)) {
                     $imgurl = $PAGE->theme->setting_file_url('headerbackgroundimage', 'headerbackgroundimage', true);
                     if (!$imgurl) {
                         $imgurl = $noimgurl;
                     }
                 }
                 $rowcontent .= '
                     <div style="background-image: url(' . $imgurl . ');background-repeat: no-repeat;background-size:cover; background-position:center;" class="fp-avail-courses">
                     <div class="fp-coursebox">
                     <div class="fp-courseinfo">
                     <p><a href="' . $courseurl . '" id="button" data-toggle="tooltip" data-placement="top" title="' . $course->fullname . '" >' . $trimtitle . '</a></p>
                     </div>
                     </div>
                     </div>
                     ';
             }
             $content .= $rowcontent;
             $content .= '</div>';
         }
     }
     $coursehtml = $header . $content . $footer;
     echo $coursehtml;
     if (!$totalcount && !$this->page->user_is_editing() && has_capability('moodle/course:create', context_system::instance())) {
         // Print link to create a new course, for the 1st available category.
         echo $this->add_new_course_button();
     }
 }
Ejemplo n.º 26
0
 $output .= html_writer::tag('h2', get_string('restorationheader', 'turnitintooltwo'));
 $output .= html_writer::tag('p', get_string('coursebrowserdesc', 'turnitintooltwo'));
 $coursesearchform = html_writer::label(get_string('coursetitle', 'turnitintooltwo') . ': ', 'search_course_title');
 $coursesearchform .= html_writer::empty_tag('input', array('type' => 'text', 'id' => 'search_course_title', 'name' => 'search_course_title'));
 $coursesearchform .= html_writer::label(get_string('integration', 'turnitintooltwo') . ': ', 'search_course_integration');
 $coursesearchform .= html_writer::select($tiiintegrationids, 'search_course_integration', '', array('' => 'choosedots'), array('id' => 'search_course_integration'));
 $coursesearchform .= html_writer::label(get_string('ced', 'turnitintooltwo') . ': ', 'search_course_end_date');
 $coursesearchform .= html_writer::empty_tag('input', array('type' => 'text', 'id' => 'search_course_end_date', 'name' => 'search_course_end_date'));
 $coursesearchform .= html_writer::tag('button', get_string('searchcourses', 'turnitintooltwo'), array("id" => "search_courses_button"));
 $output .= $OUTPUT->box($coursesearchform, 'generalbox', 'course_search_options');
 $displaylist = array();
 $parentlist = array();
 require_once $CFG->dirroot . "/course/lib.php";
 if (file_exists($CFG->libdir . '/coursecatlib.php')) {
     require_once $CFG->libdir . '/coursecatlib.php';
     $displaylist = coursecat::make_categories_list('');
 } else {
     make_categories_list($displaylist, $parentlist, '');
 }
 $categoryselectlabel = html_writer::label(get_string('selectcoursecategory', 'turnitintooltwo'), 'create_course_category');
 $categoryselect = html_writer::select($displaylist, 'create_course_category', '', array(), array('class' => 'create_course_category'));
 $createassigncheckbox = html_writer::checkbox('create_assign', 1, false, get_string('createmoodleassignments', 'turnitintooltwo'), array("class" => "create_assignment_checkbox"));
 $createassign = html_writer::tag('div', $createassigncheckbox, array("class" => "create_assign_checkbox_container"));
 $createbutton = html_writer::tag('button', get_string('createmoodlecourses', 'turnitintooltwo'), array("id" => "create_classes_button"));
 $output .= $OUTPUT->box($categoryselectlabel . " " . $categoryselect . $createassign . $createbutton, 'create_checkboxes navbar');
 $table = new html_table();
 $table->id = "courseBrowserTable";
 $rows = array();
 // Make up json array for drop down in table.
 $integrationidsjson = array();
 foreach ($tiiintegrationids as $k => $v) {
 /**
  * Renderers a search result course list item.
  *
  * This function will be called for every course being displayed by course_listing.
  *
  * @param course_in_list $course The course to produce HTML for.
  * @param int $selectedcourse The id of the currently selected course.
  * @return string
  */
 public function search_listitem(course_in_list $course, $selectedcourse)
 {
     $text = $course->get_formatted_name();
     $attributes = array('class' => 'listitem listitem-course', 'data-id' => $course->id, 'data-selected' => $selectedcourse == $course->id ? '1' : '0', 'data-visible' => $course->visible ? '1' : '0');
     $bulkcourseinput = array('type' => 'checkbox', 'name' => 'bc[]', 'value' => $course->id, 'class' => 'bulk-action-checkbox');
     $viewcourseurl = new moodle_url($this->page->url, array('courseid' => $course->id));
     $categoryname = coursecat::get($course->category)->get_formatted_name();
     $html = html_writer::start_tag('li', $attributes);
     $html .= html_writer::start_div('clearfix');
     $html .= html_writer::start_div('float-left');
     $html .= html_writer::empty_tag('input', $bulkcourseinput) . '&nbsp;';
     $html .= html_writer::end_div();
     $html .= html_writer::link($viewcourseurl, $text, array('class' => 'float-left coursename'));
     $html .= html_writer::tag('span', $categoryname, array('class' => 'float-left categoryname'));
     $html .= html_writer::start_div('float-right');
     $html .= $this->search_listitem_actions($course);
     $html .= html_writer::tag('span', s($course->idnumber), array('class' => 'dimmed idnumber'));
     $html .= html_writer::end_div();
     $html .= html_writer::end_div();
     $html .= html_writer::end_tag('li');
     return $html;
 }
Ejemplo n.º 28
0
/**
 * Recursive function to print all the categories ready for editing.
 *
 * @param html_table $table The table to add data to.
 * @param coursecat $category The category to render
 * @param int $depth The depth of the category.
 * @param bool $up True if this category can be moved up.
 * @param bool $down True if this category can be moved down.
 */
function print_category_edit(html_table $table, coursecat $category, $depth = -1, $up = false, $down = false) {
    global $OUTPUT;

    static $str = null;

    if (is_null($str)) {
        $str = new stdClass;
        $str->edit = new lang_string('edit');
        $str->delete = new lang_string('delete');
        $str->moveup = new lang_string('moveup');
        $str->movedown = new lang_string('movedown');
        $str->edit = new lang_string('editthiscategory');
        $str->hide = new lang_string('hide');
        $str->show = new lang_string('show');
        $str->cohorts = new lang_string('cohorts', 'cohort');
        $str->spacer = $OUTPUT->spacer().' ';
    }

    if ($category->id) {

        $categorycontext = context_coursecat::instance($category->id);

        $attributes = array();
        $attributes['class'] = $category->visible ? '' : 'dimmed';
        $attributes['title'] = $str->edit;
        $categoryurl = new moodle_url('/course/manage.php', array('categoryid' => $category->id, 'sesskey' => sesskey()));
        $categoryname = $category->get_formatted_name();
        $categorypadding = str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', $depth);
        $categoryname = $categorypadding . html_writer::link($categoryurl, $categoryname, $attributes);

        $icons = array();
        if (has_capability('moodle/category:manage', $categorycontext)) {
            // Edit category.
            $icons[] = $OUTPUT->action_icon(
                new moodle_url('/course/editcategory.php', array('id' => $category->id)),
                new pix_icon('t/edit', $str->edit, 'moodle', array('class' => 'iconsmall')),
                null, array('title' => $str->edit)
            );
            // Delete category.
            $icons[] = $OUTPUT->action_icon(
                new moodle_url('/course/manage.php', array('deletecat' => $category->id, 'sesskey' => sesskey())),
                new pix_icon('t/delete', $str->delete, 'moodle', array('class' => 'iconsmall')),
                null, array('title' => $str->delete)
            );
            // Change visibility.
            if (!empty($category->visible)) {
                $icons[] = $OUTPUT->action_icon(
                    new moodle_url('/course/manage.php', array('hidecat' => $category->id, 'sesskey' => sesskey())),
                    new pix_icon('t/hide', $str->hide, 'moodle', array('class' => 'iconsmall')),
                    null, array('title' => $str->hide)
                );
            } else {
                $icons[] = $OUTPUT->action_icon(
                    new moodle_url('/course/manage.php', array('showcat' => $category->id, 'sesskey' => sesskey())),
                    new pix_icon('t/show', $str->show, 'moodle', array('class' => 'iconsmall')),
                    null, array('title' => $str->show)
                );
            }
            // Cohorts.
            if (has_any_capability(array('moodle/cohort:manage', 'moodle/cohort:view'), $categorycontext)) {
                $icons[] = $OUTPUT->action_icon(
                    new moodle_url('/cohort/index.php', array('contextid' => $categorycontext->id)),
                    new pix_icon('t/cohort', $str->cohorts, 'moodle', array('class' => 'iconsmall')),
                    null, array('title' => $str->cohorts)
                );
            }
            // Move up/down.
            if ($up) {
                $icons[] = $OUTPUT->action_icon(
                    new moodle_url('/course/manage.php', array('moveupcat' => $category->id, 'sesskey' => sesskey())),
                    new pix_icon('t/up', $str->moveup, 'moodle', array('class' => 'iconsmall')),
                    null, array('title' => $str->moveup)
                );
            } else {
                $icons[] = $str->spacer;
            }
            if ($down) {
                $icons[] = $OUTPUT->action_icon(
                    new moodle_url('/course/manage.php', array('movedowncat' => $category->id, 'sesskey' => sesskey())),
                    new pix_icon('t/down', $str->movedown, 'moodle', array('class' => 'iconsmall')),
                    null, array('title' => $str->movedown)
                );
            } else {
                $icons[] = $str->spacer;
            }
        }

        $actions = '';
        if (has_capability('moodle/category:manage', $categorycontext)) {
            $popupurl = new moodle_url('/course/manage.php', array('movecat' => $category->id, 'sesskey' => sesskey()));
            $tempdisplaylist = array(0 => get_string('top')) + coursecat::make_categories_list('moodle/category:manage', $category->id);
            $select = new single_select($popupurl, 'movetocat', $tempdisplaylist, $category->parent, null, "moveform$category->id");
            $select->set_label(get_string('frontpagecategorynames'), array('class' => 'accesshide'));
            $actions = $OUTPUT->render($select);
        }

        $table->data[] = new html_table_row(array(
            // Category name.
            new html_table_cell($categoryname),
            // Course count.
            new html_table_cell($category->coursecount),
            // Icons.
            new html_table_cell(join(' ', $icons)),
            // Actions.
            new html_table_cell($actions)
        ));
    }

    if ($categories = $category->get_children()) {
        // Print all the children recursively.
        $countcats = count($categories);
        $count = 0;
        $first = true;
        $last = false;
        foreach ($categories as $cat) {
            $count++;
            if ($count == $countcats) {
                $last = true;
            }
            $up = $first ? false : true;
            $down = $last ? false : true;
            $first = false;

            print_category_edit($table, $cat, $depth+1, $up, $down);
        }
    }
}
Ejemplo n.º 29
0
 /**
  * Get the list of categories leading to this course.
  *
  * This function is used by {@link navbar::get_items()} to add back the "courses"
  * node and category chain leading to the current course.  Note that this is only ever
  * called for the current course, so we don't need to bother taking in any parameters.
  *
  * @return array
  */
 private function get_course_categories()
 {
     global $CFG;
     require_once $CFG->dirroot . '/course/lib.php';
     require_once $CFG->libdir . '/coursecatlib.php';
     $categories = array();
     $cap = 'moodle/category:viewhiddencategories';
     $showcategories = coursecat::count_all() > 1;
     if ($showcategories) {
         foreach ($this->page->categories as $category) {
             if (!$category->visible && !has_capability($cap, get_category_or_system_context($category->parent))) {
                 continue;
             }
             $url = new moodle_url('/course/index.php', array('categoryid' => $category->id));
             $name = format_string($category->name, true, array('context' => context_coursecat::instance($category->id)));
             $categorynode = breadcrumb_navigation_node::create($name, $url, self::TYPE_CATEGORY, null, $category->id);
             if (!$category->visible) {
                 $categorynode->hidden = true;
             }
             $categories[] = $categorynode;
         }
     }
     // Don't show the 'course' node if enrolled in this course.
     if (!is_enrolled(context_course::instance($this->page->course->id, null, '', true))) {
         $courses = $this->page->navigation->get('courses');
         if (!$courses) {
             // Courses node may not be present.
             $courses = breadcrumb_navigation_node::create(get_string('courses'), new moodle_url('/course/index.php'), self::TYPE_CONTAINER);
         }
         $categories[] = $courses;
     }
     return $categories;
 }
Ejemplo n.º 30
0
 /**
  * Returns HTML to print tree of course categories (with number of courses) for the frontpage
  *
  * @return string
  */
 public function frontpage_categories_list()
 {
     global $CFG;
     require_once $CFG->libdir . '/coursecatlib.php';
     $chelper = new coursecat_helper();
     $chelper->set_subcat_depth($CFG->maxcategorydepth)->set_show_courses(self::COURSECAT_SHOW_COURSES_COUNT)->set_categories_display_options(array('limit' => $CFG->coursesperpage, 'viewmoreurl' => new moodle_url('/course/index.php', array('browse' => 'categories', 'page' => 1))))->set_attributes(array('class' => 'frontpage-category-names'));
     return $this->coursecat_tree($chelper, coursecat::get(0));
 }