| 1 | efrain | 1 | <?php
 | 
        
           |  |  | 2 |   | 
        
           |  |  | 3 | // This file defines everything related to frontpage
 | 
        
           |  |  | 4 |   | 
        
           |  |  | 5 | if (!during_initial_install()) { //do not use during installation
 | 
        
           |  |  | 6 |     $frontpagecontext = context_course::instance(SITEID);
 | 
        
           |  |  | 7 |   | 
        
           |  |  | 8 |     if ($hassiteconfig or has_any_capability(array(
 | 
        
           |  |  | 9 |             'moodle/course:update',
 | 
        
           |  |  | 10 |             'moodle/role:assign',
 | 
        
           |  |  | 11 |             'moodle/restore:restorecourse',
 | 
        
           |  |  | 12 |             'moodle/backup:backupcourse',
 | 
        
           |  |  | 13 |             'moodle/course:managefiles',
 | 
        
           |  |  | 14 |             'moodle/question:add',
 | 
        
           |  |  | 15 |             'moodle/question:editmine',
 | 
        
           |  |  | 16 |             'moodle/question:editall',
 | 
        
           |  |  | 17 |             'moodle/question:viewmine',
 | 
        
           |  |  | 18 |             'moodle/question:viewall',
 | 
        
           |  |  | 19 |             'moodle/question:movemine',
 | 
        
           |  |  | 20 |             'moodle/question:moveall'), $frontpagecontext)) {
 | 
        
           |  |  | 21 |   | 
        
           |  |  | 22 |         // "frontpage" settingpage
 | 
        
           |  |  | 23 |         $temp = new admin_settingpage('frontpagesettings', new lang_string('frontpagesettings','admin'), 'moodle/course:update', false, $frontpagecontext);
 | 
        
           |  |  | 24 |         $temp->add(new admin_setting_sitesettext('fullname', new lang_string('fullsitename'), '', NULL)); // no default
 | 
        
           |  |  | 25 |         $temp->add(new admin_setting_sitesettext('shortname', new lang_string('shortsitename'), '', NULL)); // no default
 | 
        
           |  |  | 26 |         $temp->add(new admin_setting_special_frontpagedesc());
 | 
        
           |  |  | 27 |         $temp->add(new admin_setting_courselist_frontpage(false)); // non-loggedin version of the setting (that's what the parameter is for :) )
 | 
        
           |  |  | 28 |         $temp->add(new admin_setting_courselist_frontpage(true)); // loggedin version of the setting
 | 
        
           |  |  | 29 |   | 
        
           |  |  | 30 |         $options = array();
 | 
        
           |  |  | 31 |         $options[] = new lang_string('unlimited');
 | 
        
           |  |  | 32 |         for ($i=1; $i<100; $i++) {
 | 
        
           |  |  | 33 |             $options[$i] = $i;
 | 
        
           |  |  | 34 |         }
 | 
        
           |  |  | 35 |         $temp->add(new admin_setting_configselect('maxcategorydepth', new lang_string('configsitemaxcategorydepth','admin'), new lang_string('configsitemaxcategorydepthhelp','admin'), 2, $options));
 | 
        
           |  |  | 36 |   | 
        
           |  |  | 37 |         $temp->add(new admin_setting_configtext('frontpagecourselimit', new lang_string('configfrontpagecourselimit','admin'), new lang_string('configfrontpagecourselimithelp','admin'), 200, PARAM_INT));
 | 
        
           |  |  | 38 |   | 
        
           |  |  | 39 |         $temp->add(new admin_setting_sitesetcheckbox('numsections', new lang_string('sitesection'), new lang_string('sitesectionhelp','admin'), 1));
 | 
        
           |  |  | 40 |         $temp->add(new admin_setting_sitesetselect('newsitems', new lang_string('newsitemsnumber'), '', 3,
 | 
        
           |  |  | 41 |              array('0' => '0',
 | 
        
           |  |  | 42 |                    '1' => '1',
 | 
        
           |  |  | 43 |                    '2' => '2',
 | 
        
           |  |  | 44 |                    '3' => '3',
 | 
        
           |  |  | 45 |                    '4' => '4',
 | 
        
           |  |  | 46 |                    '5' => '5',
 | 
        
           |  |  | 47 |                    '6' => '6',
 | 
        
           |  |  | 48 |                    '7' => '7',
 | 
        
           |  |  | 49 |                    '8' => '8',
 | 
        
           |  |  | 50 |                    '9' => '9',
 | 
        
           |  |  | 51 |                    '10' => '10')));
 | 
        
           |  |  | 52 |         $temp->add(new admin_setting_configtext('commentsperpage', new lang_string('commentsperpage', 'admin'), '', 15, PARAM_INT));
 | 
        
           |  |  | 53 |   | 
        
           |  |  | 54 |         // front page default role
 | 
        
           |  |  | 55 |         $options = array(0=>new lang_string('none')); // roles to choose from
 | 
        
           |  |  | 56 |         $defaultfrontpageroleid = 0;
 | 
        
           |  |  | 57 |         $roles = role_fix_names(get_all_roles(), null, ROLENAME_ORIGINALANDSHORT);
 | 
        
           |  |  | 58 |         foreach ($roles as $role) {
 | 
        
           |  |  | 59 |             if (empty($role->archetype) or $role->archetype === 'guest' or $role->archetype === 'frontpage' or $role->archetype === 'student') {
 | 
        
           |  |  | 60 |                 $options[$role->id] = $role->localname;
 | 
        
           |  |  | 61 |                 if ($role->archetype === 'frontpage' && !$defaultfrontpageroleid) {
 | 
        
           |  |  | 62 |                     $defaultfrontpageroleid = $role->id;
 | 
        
           |  |  | 63 |                 }
 | 
        
           |  |  | 64 |             }
 | 
        
           |  |  | 65 |         }
 | 
        
           |  |  | 66 |         if ($defaultfrontpageroleid and (!isset($CFG->defaultfrontpageroleid) or $CFG->defaultfrontpageroleid)) {
 | 
        
           |  |  | 67 |             //frotpage role may not exist in old upgraded sites
 | 
        
           |  |  | 68 |             unset($options[0]);
 | 
        
           |  |  | 69 |         }
 | 
        
           |  |  | 70 |         $temp->add(new admin_setting_configselect('defaultfrontpageroleid', new lang_string('frontpagedefaultrole', 'admin'), '', $defaultfrontpageroleid, $options));
 | 
        
           |  |  | 71 |   | 
        
           |  |  | 72 |         $ADMIN->add('frontpage', $temp);
 | 
        
           |  |  | 73 |     }
 | 
        
           |  |  | 74 | }
 |