Esempio n. 1
0
 /**
  * Returns a localised list of timezones.
  * @param string $currentvalue
  * @param bool $include99 should the server timezone info be included?
  * @return array
  */
 public static function get_list_of_timezones($currentvalue = null, $include99 = false)
 {
     self::init_zones();
     // Localise first.
     $timezones = array();
     foreach (self::$goodzones as $tzkey => $ignored) {
         $timezones[$tzkey] = self::get_localised_timezone($tzkey);
     }
     core_collator::asort($timezones);
     // Add '99' if requested.
     if ($include99 or $currentvalue == 99) {
         $timezones['99'] = self::get_localised_timezone('99');
     }
     if (!isset($currentvalue) or isset($timezones[$currentvalue])) {
         return $timezones;
     }
     if (is_numeric($currentvalue)) {
         // UTC offset.
         $modifier = $currentvalue > 0 ? '+' : '';
         $a = 'UTC' . $modifier . number_format($currentvalue, 1);
         $timezones[$currentvalue] = get_string('timezoneinvalid', 'core_admin', $a);
     } else {
         // Some string we don't recognise.
         $timezones[$currentvalue] = get_string('timezoneinvalid', 'core_admin', $currentvalue);
     }
     return $timezones;
 }
Esempio n. 2
0
 protected function get_javascript_init_params($course, \cm_info $cm = null, \section_info $section = null)
 {
     global $DB, $CFG;
     require_once $CFG->libdir . '/gradelib.php';
     require_once $CFG->dirroot . '/course/lib.php';
     // Get grades as basic associative array.
     $gradeoptions = array();
     $items = \grade_item::fetch_all(array('courseid' => $course->id));
     // For some reason the fetch_all things return null if none.
     $items = $items ? $items : array();
     foreach ($items as $id => $item) {
         // Don't include the grade item if it's linked with a module that is being deleted.
         if (course_module_instance_pending_deletion($item->courseid, $item->itemmodule, $item->iteminstance)) {
             continue;
         }
         // Do not include grades for current item.
         if ($cm && $cm->instance == $item->iteminstance && $cm->modname == $item->itemmodule && $item->itemtype == 'mod') {
             continue;
         }
         $gradeoptions[$id] = $item->get_name(true);
     }
     \core_collator::asort($gradeoptions);
     // Change to JS array format and return.
     $jsarray = array();
     foreach ($gradeoptions as $id => $name) {
         $jsarray[] = (object) array('id' => $id, 'name' => $name);
     }
     return array($jsarray);
 }
Esempio n. 3
0
 /**
  * Form definition.
  *
  * @return void
  */
 function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     $mform->disable_form_change_checker();
     $mform->addElement('header', 'search', get_string('search', 'search'));
     // Help info depends on the selected search engine.
     $mform->addElement('text', 'q', get_string('enteryoursearchquery', 'search'));
     $mform->addHelpButton('q', 'searchinfo', $this->_customdata['searchengine']);
     $mform->setType('q', PARAM_TEXT);
     $mform->addRule('q', get_string('required'), 'required', null, 'client');
     $mform->addElement('header', 'filtersection', get_string('filterheader', 'search'));
     $mform->setExpanded('filtersection', false);
     $mform->addElement('text', 'title', get_string('title', 'search'));
     $mform->setType('title', PARAM_TEXT);
     $search = \core_search\manager::instance();
     $searchareas = \core_search\manager::get_search_areas_list(true);
     $areanames = array();
     foreach ($searchareas as $areaid => $searcharea) {
         $areanames[$areaid] = $searcharea->get_visible_name();
     }
     // Sort the array by the text.
     \core_collator::asort($areanames);
     $options = array('multiple' => true, 'noselectionstring' => get_string('allareas', 'search'));
     $mform->addElement('autocomplete', 'areaids', get_string('searcharea', 'search'), $areanames, $options);
     $options = array('multiple' => true, 'limittoenrolled' => !is_siteadmin(), 'noselectionstring' => get_string('allcourses', 'search'));
     $mform->addElement('course', 'courseids', get_string('courses', 'core'), $options);
     $mform->setType('courseids', PARAM_INT);
     $mform->addElement('date_time_selector', 'timestart', get_string('fromtime', 'search'), array('optional' => true));
     $mform->setDefault('timestart', 0);
     $mform->addElement('date_time_selector', 'timeend', get_string('totime', 'search'), array('optional' => true));
     $mform->setDefault('timeend', 0);
     $this->add_action_buttons(false, get_string('search', 'search'));
 }
Esempio n. 4
0
/**
 * Callback for the "Complete" report - prints the activity summary for the given user
 *
 * @param object $course
 * @param object $user
 * @param object $mod
 * @param object $choice
 */
function choice_user_complete($course, $user, $mod, $choice)
{
    global $DB;
    if ($answers = $DB->get_records('choice_answers', array("choiceid" => $choice->id, "userid" => $user->id))) {
        $info = [];
        foreach ($answers as $answer) {
            $info[] = "'" . format_string(choice_get_option_text($choice, $answer->optionid)) . "'";
        }
        core_collator::asort($info);
        echo get_string("answered", "choice") . ": " . join(', ', $info) . ". " . get_string("updated", '', userdate($answer->timemodified));
    } else {
        print_string("notanswered", "choice");
    }
}
Esempio n. 5
0
 protected function get_javascript_init_params($course, \cm_info $cm = null, \section_info $section = null)
 {
     // Standard user fields.
     $standardfields = array('firstname' => get_user_field_name('firstname'), 'lastname' => get_user_field_name('lastname'), 'email' => get_user_field_name('email'), 'city' => get_user_field_name('city'), 'country' => get_user_field_name('country'), 'url' => get_user_field_name('url'), 'icq' => get_user_field_name('icq'), 'skype' => get_user_field_name('skype'), 'aim' => get_user_field_name('aim'), 'yahoo' => get_user_field_name('yahoo'), 'msn' => get_user_field_name('msn'), 'idnumber' => get_user_field_name('idnumber'), 'institution' => get_user_field_name('institution'), 'department' => get_user_field_name('department'), 'phone1' => get_user_field_name('phone1'), 'phone2' => get_user_field_name('phone2'), 'address' => get_user_field_name('address'));
     \core_collator::asort($standardfields);
     // Custom fields.
     $customfields = array();
     $options = array('context' => \context_course::instance($course->id));
     foreach (condition::get_custom_profile_fields() as $field) {
         $customfields[$field->shortname] = format_string($field->name, true, $options);
     }
     \core_collator::asort($customfields);
     // Make arrays into JavaScript format (non-associative, ordered) and return.
     return array(self::convert_associative_array_for_js($standardfields, 'field', 'display'), self::convert_associative_array_for_js($customfields, 'field', 'display'));
 }
Esempio n. 6
0
 /**
  * Retrieve the list of available filter options.
  *
  * @return  array                   An array whose keys are the valid options
  *                                  And whose values are the values to display
  */
 public static function get_filter_options()
 {
     $allroles = role_get_names(null, ROLENAME_ALIAS);
     $roles = [];
     foreach ($allroles as $role) {
         if ($role->archetype === 'guest') {
             // No point in including the 'guest' role as it isn't possible to show tours to a guest.
             continue;
         }
         $roles[$role->shortname] = $role->localname;
     }
     // Add the Site Administrator pseudo-role.
     $roles[self::ROLE_SITEADMIN] = get_string('administrator', 'core');
     // Sort alphabetically too.
     \core_collator::asort($roles);
     return $roles;
 }
 function get_content()
 {
     global $CFG, $DB, $OUTPUT;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     $course = $this->page->course;
     require_once $CFG->dirroot . '/course/lib.php';
     $modinfo = get_fast_modinfo($course);
     $modfullnames = array();
     $archetypes = array();
     foreach ($modinfo->cms as $cm) {
         // Exclude activities which are not visible or have no link (=label)
         if (!$cm->uservisible or !$cm->has_view()) {
             continue;
         }
         if (array_key_exists($cm->modname, $modfullnames)) {
             continue;
         }
         if (!array_key_exists($cm->modname, $archetypes)) {
             $archetypes[$cm->modname] = plugin_supports('mod', $cm->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
         }
         if ($archetypes[$cm->modname] == MOD_ARCHETYPE_RESOURCE) {
             if (!array_key_exists('resources', $modfullnames)) {
                 $modfullnames['resources'] = get_string('resources');
             }
         } else {
             $modfullnames[$cm->modname] = $cm->modplural;
         }
     }
     core_collator::asort($modfullnames);
     foreach ($modfullnames as $modname => $modfullname) {
         if ($modname === 'resources') {
             $icon = $OUTPUT->pix_icon('icon', '', 'mod_page', array('class' => 'icon'));
             $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/resources.php?id=' . $course->id . '">' . $icon . $modfullname . '</a>';
         } else {
             $icon = '<img src="' . $OUTPUT->pix_url('icon', $modname) . '" class="icon" alt="" />';
             $this->content->items[] = '<a href="' . $CFG->wwwroot . '/mod/' . $modname . '/index.php?id=' . $course->id . '">' . $icon . $modfullname . '</a>';
         }
     }
     return $this->content;
 }
Esempio n. 8
0
 /**
  * This function renders the form elements when adding a customcert element.
  *
  * @param mod_customcert_edit_element_form $mform the edit_form instance
  */
 public function render_form_elements($mform)
 {
     // Get the user profile fields.
     $userfields = array('firstname' => get_user_field_name('firstname'), 'lastname' => get_user_field_name('lastname'), 'email' => get_user_field_name('email'), 'city' => get_user_field_name('city'), 'country' => get_user_field_name('country'), 'url' => get_user_field_name('url'), 'icq' => get_user_field_name('icq'), 'skype' => get_user_field_name('skype'), 'aim' => get_user_field_name('aim'), 'yahoo' => get_user_field_name('yahoo'), 'msn' => get_user_field_name('msn'), 'idnumber' => get_user_field_name('idnumber'), 'institution' => get_user_field_name('institution'), 'department' => get_user_field_name('department'), 'phone1' => get_user_field_name('phone1'), 'phone2' => get_user_field_name('phone2'), 'address' => get_user_field_name('address'));
     // Get the user custom fields.
     $arrcustomfields = \availability_profile\condition::get_custom_profile_fields();
     $customfields = array();
     foreach ($arrcustomfields as $key => $customfield) {
         $customfields[$customfield->id] = $key;
     }
     // Combine the two.
     $fields = $userfields + $customfields;
     core_collator::asort($fields);
     // Create the select box where the user field is selected.
     $mform->addElement('select', 'userfield', get_string('userfield', 'customcertelement_userfield'), $fields);
     $mform->setType('userfield', PARAM_ALPHANUM);
     $mform->addHelpButton('userfield', 'userfield', 'customcertelement_userfield');
     parent::render_form_elements($mform);
 }
/**
 * Get list of available import or export formats
 * @param string $type 'import' if import list, otherwise export list assumed
 * @return array sorted list of import/export formats available
 */
function get_import_export_formats($type)
{
    global $CFG;
    require_once $CFG->dirroot . '/question/format.php';
    $formatclasses = core_component::get_plugin_list_with_class('qformat', '', 'format.php');
    $fileformatname = array();
    foreach ($formatclasses as $component => $formatclass) {
        $format = new $formatclass();
        if ($type == 'import') {
            $provided = $format->provide_import();
        } else {
            $provided = $format->provide_export();
        }
        if ($provided) {
            list($notused, $fileformat) = explode('_', $component, 2);
            $fileformatnames[$fileformat] = get_string('pluginname', $component);
        }
    }
    core_collator::asort($fileformatnames);
    return $fileformatnames;
}
Esempio n. 10
0
 /**
  * Tests the static asort method.
  */
 public function test_asort()
 {
     $arr = array('b' => 'ab', 1 => 'aa', 0 => 'cc');
     $result = core_collator::asort($arr);
     $this->assertSame(array('aa', 'ab', 'cc'), array_values($arr));
     $this->assertSame(array(1, 'b', 0), array_keys($arr));
     $this->assertTrue($result);
     $arr = array('b' => 'ab', 1 => 'aa', 0 => 'cc');
     $result = core_collator::asort($arr, core_collator::SORT_STRING);
     $this->assertSame(array('aa', 'ab', 'cc'), array_values($arr));
     $this->assertSame(array(1, 'b', 0), array_keys($arr));
     $this->assertTrue($result);
     $arr = array('b' => 'aac', 1 => 'Aac', 0 => 'cc');
     $result = core_collator::asort($arr, core_collator::SORT_STRING | core_collator::CASE_SENSITIVE);
     $this->assertSame(array('Aac', 'aac', 'cc'), array_values($arr));
     $this->assertSame(array(1, 'b', 0), array_keys($arr));
     $this->assertTrue($result);
     $arr = array('b' => 'a1', 1 => 'a10', 0 => 'a3b');
     $result = core_collator::asort($arr);
     $this->assertSame(array('a1', 'a10', 'a3b'), array_values($arr));
     $this->assertSame(array('b', 1, 0), array_keys($arr));
     $this->assertTrue($result);
     $arr = array('b' => 'a1', 1 => 'a10', 0 => 'a3b');
     $result = core_collator::asort($arr, core_collator::SORT_NATURAL);
     $this->assertSame(array('a1', 'a3b', 'a10'), array_values($arr));
     $this->assertSame(array('b', 0, 1), array_keys($arr));
     $this->assertTrue($result);
     $arr = array('b' => '1.1.1', 1 => '1.2', 0 => '1.20.2');
     $result = core_collator::asort($arr, core_collator::SORT_NATURAL);
     $this->assertSame(array_values($arr), array('1.1.1', '1.2', '1.20.2'));
     $this->assertSame(array_keys($arr), array('b', 1, 0));
     $this->assertTrue($result);
     $arr = array('b' => '-1', 1 => 1000, 0 => -1.2, 3 => 1, 4 => false);
     $result = core_collator::asort($arr, core_collator::SORT_NUMERIC);
     $this->assertSame(array(-1.2, '-1', false, 1, 1000), array_values($arr));
     $this->assertSame(array(0, 'b', 4, 3, 1), array_keys($arr));
     $this->assertTrue($result);
     $arr = array('b' => array(1), 1 => array(2, 3), 0 => 1);
     $result = core_collator::asort($arr, core_collator::SORT_REGULAR);
     $this->assertSame(array(1, array(1), array(2, 3)), array_values($arr));
     $this->assertSame(array(0, 'b', 1), array_keys($arr));
     $this->assertTrue($result);
     // Test sorting of array of arrays - first element should be used for actual comparison.
     $arr = array(0 => array('bb', 'z'), 1 => array('ab', 'a'), 2 => array('zz', 'x'));
     $result = core_collator::asort($arr, core_collator::SORT_REGULAR);
     $this->assertSame(array(1, 0, 2), array_keys($arr));
     $this->assertTrue($result);
     $arr = array('a' => 'áb', 'b' => 'ab', 1 => 'aa', 0 => 'cc', 'x' => 'Áb');
     $result = core_collator::asort($arr);
     $this->assertSame(array('aa', 'ab', 'áb', 'Áb', 'cc'), array_values($arr), $this->error);
     $this->assertSame(array(1, 'b', 'a', 'x', 0), array_keys($arr), $this->error);
     $this->assertTrue($result);
     $a = array(2 => 'b', 1 => 'c');
     $c =& $a;
     $b =& $a;
     core_collator::asort($b);
     $this->assertSame($a, $b);
     $this->assertSame($c, $b);
 }
 private function get_course_activities()
 {
     // A copy of block_activity_modules.
     $course = $this->page->course;
     $modinfo = get_fast_modinfo($course);
     $course = course_get_format($course)->get_course();
     $modfullnames = array();
     $archetypes = array();
     foreach ($modinfo->get_section_info_all() as $section => $thissection) {
         if (!empty($course->numsections) and $section > $course->numsections or empty($modinfo->sections[$section])) {
             // This is a stealth section or is empty.
             continue;
         }
         foreach ($modinfo->sections[$thissection->section] as $modnumber) {
             $cm = $modinfo->cms[$modnumber];
             // Exclude activities which are not visible or have no link (=label).
             if (!$cm->uservisible or !$cm->has_view()) {
                 continue;
             }
             if (array_key_exists($cm->modname, $modfullnames)) {
                 continue;
             }
             if (!array_key_exists($cm->modname, $archetypes)) {
                 $archetypes[$cm->modname] = plugin_supports('mod', $cm->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
             }
             if ($archetypes[$cm->modname] == MOD_ARCHETYPE_RESOURCE) {
                 if (!array_key_exists('resources', $modfullnames)) {
                     $modfullnames['resources'] = get_string('resources');
                 }
             } else {
                 $modfullnames[$cm->modname] = $cm->modplural;
             }
         }
     }
     \core_collator::asort($modfullnames);
     return $modfullnames;
 }
Esempio n. 12
0
 function definition()
 {
     global $CFG, $COURSE, $DB;
     $mform =& $this->_form;
     //-------------------------------------------------------------------------------
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('text', 'name', get_string('forumname', 'forum'), array('size' => '64'));
     if (!empty($CFG->formatstringstriptags)) {
         $mform->setType('name', PARAM_TEXT);
     } else {
         $mform->setType('name', PARAM_CLEANHTML);
     }
     $mform->addRule('name', null, 'required', null, 'client');
     $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     $this->standard_intro_elements(get_string('forumintro', 'forum'));
     $forumtypes = forum_get_forum_types();
     core_collator::asort($forumtypes, core_collator::SORT_STRING);
     $mform->addElement('select', 'type', get_string('forumtype', 'forum'), $forumtypes);
     $mform->addHelpButton('type', 'forumtype', 'forum');
     $mform->setDefault('type', 'general');
     // Attachments and word count.
     $mform->addElement('header', 'attachmentswordcounthdr', get_string('attachmentswordcount', 'forum'));
     $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes, 0, $CFG->forum_maxbytes);
     $choices[1] = get_string('uploadnotallowed');
     $mform->addElement('select', 'maxbytes', get_string('maxattachmentsize', 'forum'), $choices);
     $mform->addHelpButton('maxbytes', 'maxattachmentsize', 'forum');
     $mform->setDefault('maxbytes', $CFG->forum_maxbytes);
     $choices = array(0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 20 => 20, 50 => 50, 100 => 100);
     $mform->addElement('select', 'maxattachments', get_string('maxattachments', 'forum'), $choices);
     $mform->addHelpButton('maxattachments', 'maxattachments', 'forum');
     $mform->setDefault('maxattachments', $CFG->forum_maxattachments);
     $mform->addElement('selectyesno', 'displaywordcount', get_string('displaywordcount', 'forum'));
     $mform->addHelpButton('displaywordcount', 'displaywordcount', 'forum');
     $mform->setDefault('displaywordcount', 0);
     // Subscription and tracking.
     $mform->addElement('header', 'subscriptionandtrackinghdr', get_string('subscriptionandtracking', 'forum'));
     $options = array();
     $options[FORUM_CHOOSESUBSCRIBE] = get_string('subscriptionoptional', 'forum');
     $options[FORUM_FORCESUBSCRIBE] = get_string('subscriptionforced', 'forum');
     $options[FORUM_INITIALSUBSCRIBE] = get_string('subscriptionauto', 'forum');
     $options[FORUM_DISALLOWSUBSCRIBE] = get_string('subscriptiondisabled', 'forum');
     $mform->addElement('select', 'forcesubscribe', get_string('subscriptionmode', 'forum'), $options);
     $mform->addHelpButton('forcesubscribe', 'subscriptionmode', 'forum');
     $options = array();
     $options[FORUM_TRACKING_OPTIONAL] = get_string('trackingoptional', 'forum');
     $options[FORUM_TRACKING_OFF] = get_string('trackingoff', 'forum');
     if ($CFG->forum_allowforcedreadtracking) {
         $options[FORUM_TRACKING_FORCED] = get_string('trackingon', 'forum');
     }
     $mform->addElement('select', 'trackingtype', get_string('trackingtype', 'forum'), $options);
     $mform->addHelpButton('trackingtype', 'trackingtype', 'forum');
     $default = $CFG->forum_trackingtype;
     if (!$CFG->forum_allowforcedreadtracking && $default == FORUM_TRACKING_FORCED) {
         $default = FORUM_TRACKING_OPTIONAL;
     }
     $mform->setDefault('trackingtype', $default);
     if ($CFG->enablerssfeeds && isset($CFG->forum_enablerssfeeds) && $CFG->forum_enablerssfeeds) {
         //-------------------------------------------------------------------------------
         $mform->addElement('header', 'rssheader', get_string('rss'));
         $choices = array();
         $choices[0] = get_string('none');
         $choices[1] = get_string('discussions', 'forum');
         $choices[2] = get_string('posts', 'forum');
         $mform->addElement('select', 'rsstype', get_string('rsstype'), $choices);
         $mform->addHelpButton('rsstype', 'rsstype', 'forum');
         if (isset($CFG->forum_rsstype)) {
             $mform->setDefault('rsstype', $CFG->forum_rsstype);
         }
         $choices = array();
         $choices[0] = '0';
         $choices[1] = '1';
         $choices[2] = '2';
         $choices[3] = '3';
         $choices[4] = '4';
         $choices[5] = '5';
         $choices[10] = '10';
         $choices[15] = '15';
         $choices[20] = '20';
         $choices[25] = '25';
         $choices[30] = '30';
         $choices[40] = '40';
         $choices[50] = '50';
         $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
         $mform->addHelpButton('rssarticles', 'rssarticles', 'forum');
         $mform->disabledIf('rssarticles', 'rsstype', 'eq', '0');
         if (isset($CFG->forum_rssarticles)) {
             $mform->setDefault('rssarticles', $CFG->forum_rssarticles);
         }
     }
     $mform->addElement('header', 'discussionlocking', get_string('discussionlockingheader', 'forum'));
     $options = [0 => get_string('discussionlockingdisabled', 'forum'), 1 * DAYSECS => get_string('numday', 'core', 1), 1 * WEEKSECS => get_string('numweek', 'core', 1), 2 * WEEKSECS => get_string('numweeks', 'core', 2), 30 * DAYSECS => get_string('nummonth', 'core', 1), 60 * DAYSECS => get_string('nummonths', 'core', 2), 90 * DAYSECS => get_string('nummonths', 'core', 3), 180 * DAYSECS => get_string('nummonths', 'core', 6), 1 * YEARSECS => get_string('numyear', 'core', 1)];
     $mform->addElement('select', 'lockdiscussionafter', get_string('lockdiscussionafter', 'forum'), $options);
     $mform->addHelpButton('lockdiscussionafter', 'lockdiscussionafter', 'forum');
     $mform->disabledIf('lockdiscussionafter', 'type', 'eq', 'single');
     //-------------------------------------------------------------------------------
     $mform->addElement('header', 'blockafterheader', get_string('blockafter', 'forum'));
     $options = array();
     $options[0] = get_string('blockperioddisabled', 'forum');
     $options[60 * 60 * 24] = '1 ' . get_string('day');
     $options[60 * 60 * 24 * 2] = '2 ' . get_string('days');
     $options[60 * 60 * 24 * 3] = '3 ' . get_string('days');
     $options[60 * 60 * 24 * 4] = '4 ' . get_string('days');
     $options[60 * 60 * 24 * 5] = '5 ' . get_string('days');
     $options[60 * 60 * 24 * 6] = '6 ' . get_string('days');
     $options[60 * 60 * 24 * 7] = '1 ' . get_string('week');
     $mform->addElement('select', 'blockperiod', get_string('blockperiod', 'forum'), $options);
     $mform->addHelpButton('blockperiod', 'blockperiod', 'forum');
     $mform->addElement('text', 'blockafter', get_string('blockafter', 'forum'));
     $mform->setType('blockafter', PARAM_INT);
     $mform->setDefault('blockafter', '0');
     $mform->addRule('blockafter', null, 'numeric', null, 'client');
     $mform->addHelpButton('blockafter', 'blockafter', 'forum');
     $mform->disabledIf('blockafter', 'blockperiod', 'eq', 0);
     $mform->addElement('text', 'warnafter', get_string('warnafter', 'forum'));
     $mform->setType('warnafter', PARAM_INT);
     $mform->setDefault('warnafter', '0');
     $mform->addRule('warnafter', null, 'numeric', null, 'client');
     $mform->addHelpButton('warnafter', 'warnafter', 'forum');
     $mform->disabledIf('warnafter', 'blockperiod', 'eq', 0);
     $coursecontext = context_course::instance($COURSE->id);
     plagiarism_get_form_elements_module($mform, $coursecontext, 'mod_forum');
     //-------------------------------------------------------------------------------
     $this->standard_grading_coursemodule_elements();
     $this->standard_coursemodule_elements();
     //-------------------------------------------------------------------------------
     // buttons
     $this->add_action_buttons();
 }
Esempio n. 13
0
 /**
  * View the grading table of all submissions for this assignment.
  *
  * @return string
  */
 protected function view_grading_table()
 {
     global $USER, $CFG;
     // Include grading options form.
     require_once $CFG->dirroot . '/mod/assign/gradingoptionsform.php';
     require_once $CFG->dirroot . '/mod/assign/quickgradingform.php';
     require_once $CFG->dirroot . '/mod/assign/gradingbatchoperationsform.php';
     $o = '';
     $cmid = $this->get_course_module()->id;
     $links = array();
     if (has_capability('gradereport/grader:view', $this->get_course_context()) && has_capability('moodle/grade:viewall', $this->get_course_context())) {
         $gradebookurl = '/grade/report/grader/index.php?id=' . $this->get_course()->id;
         $links[$gradebookurl] = get_string('viewgradebook', 'assign');
     }
     if ($this->is_any_submission_plugin_enabled() && $this->count_submissions()) {
         $downloadurl = '/mod/assign/view.php?id=' . $cmid . '&action=downloadall';
         $links[$downloadurl] = get_string('downloadall', 'assign');
     }
     if ($this->is_blind_marking() && has_capability('mod/assign:revealidentities', $this->get_context())) {
         $revealidentitiesurl = '/mod/assign/view.php?id=' . $cmid . '&action=revealidentities';
         $links[$revealidentitiesurl] = get_string('revealidentities', 'assign');
     }
     foreach ($this->get_feedback_plugins() as $plugin) {
         if ($plugin->is_enabled() && $plugin->is_visible()) {
             foreach ($plugin->get_grading_actions() as $action => $description) {
                 $url = '/mod/assign/view.php' . '?id=' . $cmid . '&plugin=' . $plugin->get_type() . '&pluginsubtype=assignfeedback' . '&action=viewpluginpage&pluginaction=' . $action;
                 $links[$url] = $description;
             }
         }
     }
     // Sort links alphabetically based on the link description.
     core_collator::asort($links);
     $gradingactions = new url_select($links);
     $gradingactions->set_label(get_string('choosegradingaction', 'assign'));
     $gradingmanager = get_grading_manager($this->get_context(), 'mod_assign', 'submissions');
     $perpage = get_user_preferences('assign_perpage', 10);
     $filter = get_user_preferences('assign_filter', '');
     $markerfilter = get_user_preferences('assign_markerfilter', '');
     $workflowfilter = get_user_preferences('assign_workflowfilter', '');
     $controller = $gradingmanager->get_active_controller();
     $showquickgrading = empty($controller);
     $quickgrading = get_user_preferences('assign_quickgrading', false);
     $showonlyactiveenrolopt = has_capability('moodle/course:viewsuspendedusers', $this->context);
     $markingallocation = $this->get_instance()->markingallocation && has_capability('mod/assign:manageallocations', $this->context);
     // Get markers to use in drop lists.
     $markingallocationoptions = array();
     if ($markingallocation) {
         $markers = get_users_by_capability($this->context, 'mod/assign:grade');
         $markingallocationoptions[''] = get_string('filternone', 'assign');
         foreach ($markers as $marker) {
             $markingallocationoptions[$marker->id] = fullname($marker);
         }
     }
     $markingworkflow = $this->get_instance()->markingworkflow;
     // Get marking states to show in form.
     $markingworkflowoptions = array();
     if ($markingworkflow) {
         $notmarked = get_string('markingworkflowstatenotmarked', 'assign');
         $markingworkflowoptions[''] = get_string('filternone', 'assign');
         $markingworkflowoptions[ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED] = $notmarked;
         $markingworkflowoptions = array_merge($markingworkflowoptions, $this->get_marking_workflow_states_for_current_user());
     }
     // Print options for changing the filter and changing the number of results per page.
     $gradingoptionsformparams = array('cm' => $cmid, 'contextid' => $this->context->id, 'userid' => $USER->id, 'submissionsenabled' => $this->is_any_submission_plugin_enabled(), 'showquickgrading' => $showquickgrading, 'quickgrading' => $quickgrading, 'markingworkflowopt' => $markingworkflowoptions, 'markingallocationopt' => $markingallocationoptions, 'showonlyactiveenrolopt' => $showonlyactiveenrolopt, 'showonlyactiveenrol' => $this->show_only_active_users());
     $classoptions = array('class' => 'gradingoptionsform');
     $gradingoptionsform = new mod_assign_grading_options_form(null, $gradingoptionsformparams, 'post', '', $classoptions);
     $batchformparams = array('cm' => $cmid, 'submissiondrafts' => $this->get_instance()->submissiondrafts, 'duedate' => $this->get_instance()->duedate, 'attemptreopenmethod' => $this->get_instance()->attemptreopenmethod, 'feedbackplugins' => $this->get_feedback_plugins(), 'context' => $this->get_context(), 'markingworkflow' => $markingworkflow, 'markingallocation' => $markingallocation);
     $classoptions = array('class' => 'gradingbatchoperationsform');
     $gradingbatchoperationsform = new mod_assign_grading_batch_operations_form(null, $batchformparams, 'post', '', $classoptions);
     $gradingoptionsdata = new stdClass();
     $gradingoptionsdata->perpage = $perpage;
     $gradingoptionsdata->filter = $filter;
     $gradingoptionsdata->markerfilter = $markerfilter;
     $gradingoptionsdata->workflowfilter = $workflowfilter;
     $gradingoptionsform->set_data($gradingoptionsdata);
     $actionformtext = $this->get_renderer()->render($gradingactions);
     $header = new assign_header($this->get_instance(), $this->get_context(), false, $this->get_course_module()->id, get_string('grading', 'assign'), $actionformtext);
     $o .= $this->get_renderer()->render($header);
     $currenturl = $CFG->wwwroot . '/mod/assign/view.php?id=' . $this->get_course_module()->id . '&action=grading';
     $o .= groups_print_activity_menu($this->get_course_module(), $currenturl, true);
     // Plagiarism update status apearring in the grading book.
     if (!empty($CFG->enableplagiarism)) {
         require_once $CFG->libdir . '/plagiarismlib.php';
         $o .= plagiarism_update_status($this->get_course(), $this->get_course_module());
     }
     // Load and print the table of submissions.
     if ($showquickgrading && $quickgrading) {
         $gradingtable = new assign_grading_table($this, $perpage, $filter, 0, true);
         $table = $this->get_renderer()->render($gradingtable);
         $quickformparams = array('cm' => $this->get_course_module()->id, 'gradingtable' => $table);
         $quickgradingform = new mod_assign_quick_grading_form(null, $quickformparams);
         $o .= $this->get_renderer()->render(new assign_form('quickgradingform', $quickgradingform));
     } else {
         $gradingtable = new assign_grading_table($this, $perpage, $filter, 0, false);
         $o .= $this->get_renderer()->render($gradingtable);
     }
     $currentgroup = groups_get_activity_group($this->get_course_module(), true);
     $users = array_keys($this->list_participants($currentgroup, true));
     if (count($users) != 0) {
         // If no enrolled user in a course then don't display the batch operations feature.
         $assignform = new assign_form('gradingbatchoperationsform', $gradingbatchoperationsform);
         $o .= $this->get_renderer()->render($assignform);
     }
     $assignform = new assign_form('gradingoptionsform', $gradingoptionsform, 'M.mod_assign.init_grading_options');
     $o .= $this->get_renderer()->render($assignform);
     return $o;
 }
Esempio n. 14
0
$table->define_baseurl($CFG->wwwroot . '/' . $CFG->admin . '/blocks.php');
$table->set_attribute('class', 'admintable blockstable generaltable');
$table->set_attribute('id', 'compatibleblockstable');
$table->setup();
$tablerows = array();
// Sort blocks using current locale.
$blocknames = array();
foreach ($blocks as $blockid => $block) {
    $blockname = $block->name;
    if (file_exists("{$CFG->dirroot}/blocks/{$blockname}/block_{$blockname}.php")) {
        $blocknames[$blockid] = get_string('pluginname', 'block_' . $blockname);
    } else {
        $blocknames[$blockid] = $blockname;
    }
}
core_collator::asort($blocknames);
foreach ($blocknames as $blockid => $strblockname) {
    $block = $blocks[$blockid];
    $blockname = $block->name;
    $dbversion = get_config('block_' . $block->name, 'version');
    if (!file_exists("{$CFG->dirroot}/blocks/{$blockname}/block_{$blockname}.php")) {
        $blockobject = false;
        $strblockname = '<span class="notifyproblem">' . $strblockname . ' (' . get_string('missingfromdisk') . ')</span>';
        $plugin = new stdClass();
        $plugin->version = $dbversion;
    } else {
        $plugin = new stdClass();
        $plugin->version = '???';
        if (file_exists("{$CFG->dirroot}/blocks/{$blockname}/version.php")) {
            include "{$CFG->dirroot}/blocks/{$blockname}/version.php";
        }
Esempio n. 15
0
File: lib.php Progetto: JOANMM/bcu
function theme_bcu_get_course_activities()
{
    global $CFG, $PAGE, $OUTPUT;
    // A copy of block_activity_modules.
    $course = $PAGE->course;
    $content = new stdClass();
    $modinfo = get_fast_modinfo($course);
    $modfullnames = array();
    $archetypes = array();
    foreach ($modinfo->cms as $cm) {
        // Exclude activities which are not visible or have no link (=label).
        if (!$cm->uservisible or !$cm->has_view()) {
            continue;
        }
        if (array_key_exists($cm->modname, $modfullnames)) {
            continue;
        }
        if (!array_key_exists($cm->modname, $archetypes)) {
            $archetypes[$cm->modname] = plugin_supports('mod', $cm->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
        }
        if ($archetypes[$cm->modname] == MOD_ARCHETYPE_RESOURCE) {
            if (!array_key_exists('resources', $modfullnames)) {
                $modfullnames['resources'] = get_string('resources');
            }
        } else {
            $modfullnames[$cm->modname] = $cm->modplural;
        }
    }
    core_collator::asort($modfullnames);
    return $modfullnames;
}
Esempio n. 16
0
 /**
  * Sort an array of question types according to the order the admin set up,
  * and then alphabetically for the rest.
  * @param array qtype->name() => qtype->local_name().
  * @return array sorted array.
  */
 public static function sort_qtype_array($qtypes, $config = null)
 {
     if (is_null($config)) {
         $config = self::get_config();
     }
     $sortorder = array();
     $otherqtypes = array();
     foreach ($qtypes as $name => $localname) {
         $sortvar = $name . '_sortorder';
         if (isset($config->{$sortvar})) {
             $sortorder[$config->{$sortvar}] = $name;
         } else {
             $otherqtypes[$name] = $localname;
         }
     }
     ksort($sortorder);
     core_collator::asort($otherqtypes);
     $sortedqtypes = array();
     foreach ($sortorder as $name) {
         $sortedqtypes[$name] = $qtypes[$name];
     }
     foreach ($otherqtypes as $name => $notused) {
         $sortedqtypes[$name] = $qtypes[$name];
     }
     return $sortedqtypes;
 }
Esempio n. 17
0
    /**
     * Fill in the current page data for this course.
     */
    function definition_after_data() {
        global $DB;

        $mform = $this->_form;

        // add available groupings
        if ($courseid = $mform->getElementValue('id') and $mform->elementExists('defaultgroupingid')) {
            $options = array();
            if ($groupings = $DB->get_records('groupings', array('courseid'=>$courseid))) {
                foreach ($groupings as $grouping) {
                    $options[$grouping->id] = format_string($grouping->name);
                }
            }
            core_collator::asort($options);
            $gr_el =& $mform->getElement('defaultgroupingid');
            $gr_el->load($options);
        }

        // add course format options
        $formatvalue = $mform->getElementValue('format');
        if (is_array($formatvalue) && !empty($formatvalue)) {
            $courseformat = course_get_format((object)array('format' => $formatvalue[0]));

            $elements = $courseformat->create_edit_form_elements($mform);
            for ($i = 0; $i < count($elements); $i++) {
                $mform->insertElementBefore($mform->removeElement($elements[$i]->getName(), false),
                        'addcourseformatoptionshere');
            }
        }
    }
 /**
  * Cleans the list of options and returns it as a string separating options with |||.
  *
  * @param string $value The string containing the escaped options.
  * @return string The options
  */
 protected function get_unescaped_options($value)
 {
     // Can be multiple comma separated, with valuable commas escaped with backslash.
     $optionsarray = array_map('trim', preg_replace('/\\\\,/', ',', preg_split('/(?<!\\\\),/', $value)));
     // Sort by value (keeping the keys is irrelevant).
     core_collator::asort($optionsarray, SORT_STRING);
     // Returning it as a string which is easier to match against other values.
     return implode('|||', $optionsarray);
 }
Esempio n. 19
0
 public function definition_after_data()
 {
     global $CFG, $DB;
     $mform = $this->_form;
     $course = $this->_customdata['course'];
     $context = context_course::instance($course->id);
     if (!empty($CFG->enableavailability)) {
         $mform->addElement('header', 'availabilityconditions', get_string('availabilityconditions', 'condition'));
         $mform->setExpanded('availabilityconditions', false);
         // String used by conditions more than once
         $strcondnone = get_string('none', 'condition');
         // Grouping conditions - only if grouping is enabled at site level
         if (!empty($CFG->enablegroupmembersonly)) {
             $options = array();
             if ($groupings = $DB->get_records('groupings', array('courseid' => $course->id))) {
                 foreach ($groupings as $grouping) {
                     $options[$grouping->id] = format_string($grouping->name, true, array('context' => $context));
                 }
             }
             core_collator::asort($options);
             $options = array(0 => get_string('none')) + $options;
             $mform->addElement('select', 'groupingid', get_string('groupingsection', 'group'), $options);
             $mform->addHelpButton('groupingid', 'groupingsection', 'group');
         }
         // Available from/to defaults to midnight because then the display
         // will be nicer where it tells users when they can access it (it
         // shows only the date and not time).
         $date = usergetdate(time());
         $midnight = make_timestamp($date['year'], $date['mon'], $date['mday']);
         // Date and time conditions.
         $mform->addElement('date_time_selector', 'availablefrom', get_string('availablefrom', 'condition'), array('optional' => true, 'defaulttime' => $midnight));
         $mform->addElement('date_time_selector', 'availableuntil', get_string('availableuntil', 'condition'), array('optional' => true, 'defaulttime' => $midnight));
         // Conditions based on grades
         $gradeoptions = array();
         $items = grade_item::fetch_all(array('courseid' => $course->id));
         $items = $items ? $items : array();
         foreach ($items as $id => $item) {
             $gradeoptions[$id] = $item->get_name();
         }
         asort($gradeoptions);
         $gradeoptions = array(0 => $strcondnone) + $gradeoptions;
         $grouparray = array();
         $grouparray[] = $mform->createElement('select', 'conditiongradeitemid', '', $gradeoptions);
         $grouparray[] = $mform->createElement('static', '', '', ' ' . get_string('grade_atleast', 'condition') . ' ');
         $grouparray[] = $mform->createElement('text', 'conditiongrademin', '', array('size' => 3));
         $grouparray[] = $mform->createElement('static', '', '', '% ' . get_string('grade_upto', 'condition') . ' ');
         $grouparray[] = $mform->createElement('text', 'conditiongrademax', '', array('size' => 3));
         $grouparray[] = $mform->createElement('static', '', '', '%');
         $group = $mform->createElement('group', 'conditiongradegroup', get_string('gradecondition', 'condition'), $grouparray);
         // Get full version (including condition info) of section object
         $ci = new condition_info_section($this->_customdata['cs']);
         $fullcs = $ci->get_full_section();
         $count = count($fullcs->conditionsgrade) + 1;
         // Grade conditions
         $this->repeat_elements(array($group), $count, array('conditiongradegroup[conditiongrademin]' => array('type' => PARAM_RAW), 'conditiongradegroup[conditiongrademax]' => array('type' => PARAM_RAW)), 'conditiongraderepeats', 'conditiongradeadds', 2, get_string('addgrades', 'condition'), true);
         $mform->addHelpButton('conditiongradegroup[0]', 'gradecondition', 'condition');
         // Conditions based on user fields
         $operators = condition_info::get_condition_user_field_operators();
         $useroptions = condition_info::get_condition_user_fields(array('context' => $context));
         asort($useroptions);
         $useroptions = array(0 => $strcondnone) + $useroptions;
         $grouparray = array();
         $grouparray[] =& $mform->createElement('select', 'conditionfield', '', $useroptions);
         $grouparray[] =& $mform->createElement('select', 'conditionfieldoperator', '', $operators);
         $grouparray[] =& $mform->createElement('text', 'conditionfieldvalue');
         $group = $mform->createElement('group', 'conditionfieldgroup', get_string('userfield', 'condition'), $grouparray);
         $fieldcount = count($fullcs->conditionsfield) + 1;
         $this->repeat_elements(array($group), $fieldcount, array('conditionfieldgroup[conditionfieldvalue]' => array('type' => PARAM_RAW)), 'conditionfieldrepeats', 'conditionfieldadds', 2, get_string('adduserfields', 'condition'), true);
         $mform->addHelpButton('conditionfieldgroup[0]', 'userfield', 'condition');
         // Conditions based on completion
         $completion = new completion_info($course);
         if ($completion->is_enabled()) {
             $completionoptions = array();
             $modinfo = get_fast_modinfo($course);
             foreach ($modinfo->cms as $id => $cm) {
                 // Add each course-module if it:
                 // (a) has completion turned on
                 // (b) does not belong to current course-section
                 if ($cm->completion && $fullcs->id != $cm->section) {
                     $completionoptions[$id] = $cm->name;
                 }
             }
             asort($completionoptions);
             $completionoptions = array(0 => $strcondnone) + $completionoptions;
             $completionvalues = array(COMPLETION_COMPLETE => get_string('completion_complete', 'condition'), COMPLETION_INCOMPLETE => get_string('completion_incomplete', 'condition'), COMPLETION_COMPLETE_PASS => get_string('completion_pass', 'condition'), COMPLETION_COMPLETE_FAIL => get_string('completion_fail', 'condition'));
             $grouparray = array();
             $grouparray[] = $mform->createElement('select', 'conditionsourcecmid', '', $completionoptions);
             $grouparray[] = $mform->createElement('select', 'conditionrequiredcompletion', '', $completionvalues);
             $group = $mform->createElement('group', 'conditioncompletiongroup', get_string('completioncondition', 'condition'), $grouparray);
             $count = count($fullcs->conditionscompletion) + 1;
             $this->repeat_elements(array($group), $count, array(), 'conditioncompletionrepeats', 'conditioncompletionadds', 2, get_string('addcompletions', 'condition'), true);
             $mform->addHelpButton('conditioncompletiongroup[0]', 'completionconditionsection', 'condition');
         }
         // Availability conditions - set up form values
         if (!empty($CFG->enableavailability)) {
             $num = 0;
             foreach ($fullcs->conditionsgrade as $gradeitemid => $minmax) {
                 $groupelements = $mform->getElement('conditiongradegroup[' . $num . ']')->getElements();
                 $groupelements[0]->setValue($gradeitemid);
                 $groupelements[2]->setValue(is_null($minmax->min) ? '' : format_float($minmax->min, 5, true, true));
                 $groupelements[4]->setValue(is_null($minmax->max) ? '' : format_float($minmax->max, 5, true, true));
                 $num++;
             }
             $num = 0;
             foreach ($fullcs->conditionsfield as $fieldid => $data) {
                 $groupelements = $mform->getElement('conditionfieldgroup[' . $num . ']')->getElements();
                 $groupelements[0]->setValue($fieldid);
                 $groupelements[1]->setValue(is_null($data->operator) ? '' : $data->operator);
                 $groupelements[2]->setValue(is_null($data->value) ? '' : $data->value);
                 $num++;
             }
             if ($completion->is_enabled()) {
                 $num = 0;
                 foreach ($fullcs->conditionscompletion as $othercmid => $state) {
                     $groupelements = $mform->getElement('conditioncompletiongroup[' . $num . ']')->getElements();
                     $groupelements[0]->setValue($othercmid);
                     $groupelements[1]->setValue($state);
                     $num++;
                 }
             }
         }
         // Do we display availability info to students?
         $showhide = array(CONDITION_STUDENTVIEW_SHOW => get_string('showavailabilitysection_show', 'condition'), CONDITION_STUDENTVIEW_HIDE => get_string('showavailabilitysection_hide', 'condition'));
         $mform->addElement('select', 'showavailability', get_string('showavailabilitysection', 'condition'), $showhide);
     }
     $this->add_action_buttons();
 }
Esempio n. 20
0
/**
 * Returns grade options for gradebook grade category menu
 *
 * @param int $courseid The course ID
 * @param bool $includenew Include option for new category at array index -1
 * @return array of grade categories in course
 */
function grade_get_categories_menu($courseid, $includenew = false)
{
    $result = array();
    if (!($categories = grade_category::fetch_all(array('courseid' => $courseid)))) {
        //make sure course category exists
        if (!grade_category::fetch_course_category($courseid)) {
            debugging('Can not create course grade category!');
            return $result;
        }
        $categories = grade_category::fetch_all(array('courseid' => $courseid));
    }
    foreach ($categories as $key => $category) {
        if ($category->is_course_category()) {
            $result[$category->id] = get_string('uncategorised', 'grades');
            unset($categories[$key]);
        }
    }
    if ($includenew) {
        $result[-1] = get_string('newcategory', 'grades');
    }
    $cats = array();
    foreach ($categories as $category) {
        $cats[$category->id] = $category->get_name();
    }
    core_collator::asort($cats);
    return $result + $cats;
}
Esempio n. 21
0
 /**
  * Get the list of files and directories in that repository.
  *
  * @param string $path to browse.
  * @param string $page page number.
  * @return array list of files and folders.
  */
 public function get_listing($path = '', $page = '')
 {
     global $OUTPUT;
     $list = array();
     $list['list'] = array();
     $list['manage'] = false;
     $list['dynload'] = true;
     $list['nologin'] = true;
     $list['nosearch'] = true;
     $list['path'] = array(array('name' => get_string('root', 'repository_filesystem'), 'path' => ''));
     $path = trim($path, '/');
     if (!$this->is_in_repository($path)) {
         // In case of doubt on the path, reset to default.
         $path = '';
     }
     $abspath = rtrim($this->get_rootpath() . $path, '/') . '/';
     // Construct the breadcrumb.
     $trail = '';
     if ($path !== '') {
         $parts = explode('/', $path);
         if (count($parts) > 1) {
             foreach ($parts as $part) {
                 if (!empty($part)) {
                     $trail .= '/' . $part;
                     $list['path'][] = array('name' => $part, 'path' => $trail);
                 }
             }
         } else {
             $list['path'][] = array('name' => $path, 'path' => $path);
         }
     }
     // Retrieve list of files and directories and sort them.
     $fileslist = array();
     $dirslist = array();
     if ($dh = opendir($abspath)) {
         while (($file = readdir($dh)) != false) {
             if ($file != '.' and $file != '..') {
                 if (is_file($abspath . $file)) {
                     $fileslist[] = $file;
                 } else {
                     $dirslist[] = $file;
                 }
             }
         }
     }
     core_collator::asort($fileslist, core_collator::SORT_NATURAL);
     core_collator::asort($dirslist, core_collator::SORT_NATURAL);
     // Fill the $list['list'].
     foreach ($dirslist as $file) {
         $list['list'][] = array('title' => $file, 'children' => array(), 'datecreated' => filectime($abspath . $file), 'datemodified' => filemtime($abspath . $file), 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false), 'path' => $path . '/' . $file);
     }
     foreach ($fileslist as $file) {
         $node = array('title' => $file, 'source' => $path . '/' . $file, 'size' => filesize($abspath . $file), 'datecreated' => filectime($abspath . $file), 'datemodified' => filemtime($abspath . $file), 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($file, 90))->out(false), 'icon' => $OUTPUT->pix_url(file_extension_icon($file, 24))->out(false));
         if (file_extension_in_typegroup($file, 'image') && ($imageinfo = @getimagesize($abspath . $file))) {
             // This means it is an image and we can return dimensions and try to generate thumbnail/icon.
             $token = $node['datemodified'] . $node['size'];
             // To prevent caching by browser.
             $node['realthumbnail'] = $this->get_thumbnail_url($path . '/' . $file, 'thumb', $token)->out(false);
             $node['realicon'] = $this->get_thumbnail_url($path . '/' . $file, 'icon', $token)->out(false);
             $node['image_width'] = $imageinfo[0];
             $node['image_height'] = $imageinfo[1];
         }
         $list['list'][] = $node;
     }
     $list['list'] = array_filter($list['list'], array($this, 'filter'));
     return $list;
 }
Esempio n. 22
0
 /**
  * Return list of courses to show in selector.
  *
  * @return array list of courses.
  */
 public function get_course_list()
 {
     global $DB, $SITE;
     $courses = array();
     $sitecontext = context_system::instance();
     // First check to see if we can override showcourses and showusers.
     $numcourses = $DB->count_records("course");
     if ($numcourses < COURSE_MAX_COURSES_PER_DROPDOWN && !$this->showcourses) {
         $this->showcourses = 1;
     }
     // Check if course filter should be shown.
     if (has_capability('report/log:view', $sitecontext) && $this->showcourses) {
         if ($courserecords = $DB->get_records("course", null, "fullname", "id,shortname,fullname,category")) {
             foreach ($courserecords as $course) {
                 if ($course->id == SITEID) {
                     $courses[$course->id] = format_string($course->fullname) . ' (' . get_string('site') . ')';
                 } else {
                     $courses[$course->id] = format_string(get_course_display_name_for_list($course));
                 }
             }
         }
         core_collator::asort($courses);
     }
     return $courses;
 }
Esempio n. 23
0
/**
 * Returns the localised human-readable names of all used modules
 *
 * @param bool $plural if true returns the plural forms of the names
 * @return array where key is the module name (component name without 'mod_') and
 *     the value is the human-readable string. Array sorted alphabetically by value
 */
function get_module_types_names($plural = false)
{
    static $modnames = null;
    global $DB, $CFG;
    if ($modnames === null) {
        $modnames = array(0 => array(), 1 => array());
        if ($allmods = $DB->get_records("modules")) {
            foreach ($allmods as $mod) {
                if (file_exists("{$CFG->dirroot}/mod/{$mod->name}/lib.php") && $mod->visible) {
                    $modnames[0][$mod->name] = get_string("modulename", "{$mod->name}");
                    $modnames[1][$mod->name] = get_string("modulenameplural", "{$mod->name}");
                }
            }
            core_collator::asort($modnames[0]);
            core_collator::asort($modnames[1]);
        }
    }
    return $modnames[(int) $plural];
}
 /**
  * Adds all the standard elements to a form to edit the settings for an activity module.
  */
 function standard_coursemodule_elements()
 {
     global $COURSE, $CFG, $DB;
     $mform =& $this->_form;
     $this->_outcomesused = false;
     if ($this->_features->outcomes) {
         if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
             $this->_outcomesused = true;
             $mform->addElement('header', 'modoutcomes', get_string('outcomes', 'grades'));
             foreach ($outcomes as $outcome) {
                 $mform->addElement('advcheckbox', 'outcome_' . $outcome->id, $outcome->get_name());
             }
         }
     }
     if ($this->_features->rating) {
         require_once $CFG->dirroot . '/rating/lib.php';
         $rm = new rating_manager();
         $mform->addElement('header', 'modstandardratings', get_string('ratings', 'rating'));
         $permission = CAP_ALLOW;
         $rolenamestring = null;
         if (!empty($this->_cm)) {
             $context = context_module::instance($this->_cm->id);
             $rolenames = get_role_names_with_caps_in_context($context, array('moodle/rating:rate', 'mod/' . $this->_cm->modname . ':rate'));
             $rolenamestring = implode(', ', $rolenames);
         } else {
             $rolenamestring = get_string('capabilitychecknotavailable', 'rating');
         }
         $mform->addElement('static', 'rolewarning', get_string('rolewarning', 'rating'), $rolenamestring);
         $mform->addHelpButton('rolewarning', 'rolewarning', 'rating');
         $mform->addElement('select', 'assessed', get_string('aggregatetype', 'rating'), $rm->get_aggregate_types());
         $mform->setDefault('assessed', 0);
         $mform->addHelpButton('assessed', 'aggregatetype', 'rating');
         $mform->addElement('modgrade', 'scale', get_string('scale'), false);
         $mform->disabledIf('scale', 'assessed', 'eq', 0);
         $mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'rating'));
         $mform->disabledIf('ratingtime', 'assessed', 'eq', 0);
         $mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
         $mform->disabledIf('assesstimestart', 'assessed', 'eq', 0);
         $mform->disabledIf('assesstimestart', 'ratingtime');
         $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
         $mform->disabledIf('assesstimefinish', 'assessed', 'eq', 0);
         $mform->disabledIf('assesstimefinish', 'ratingtime');
     }
     //doing this here means splitting up the grade related settings on the lesson settings page
     //$this->standard_grading_coursemodule_elements();
     $mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form'));
     $mform->addElement('modvisible', 'visible', get_string('visible'));
     if (!empty($this->_cm)) {
         $context = context_module::instance($this->_cm->id);
         if (!has_capability('moodle/course:activityvisibility', $context)) {
             $mform->hardFreeze('visible');
         }
     }
     if ($this->_features->idnumber) {
         $mform->addElement('text', 'cmidnumber', get_string('idnumbermod'));
         $mform->setType('cmidnumber', PARAM_RAW);
         $mform->addHelpButton('cmidnumber', 'idnumbermod');
     }
     if ($this->_features->groups) {
         $options = array(NOGROUPS => get_string('groupsnone'), SEPARATEGROUPS => get_string('groupsseparate'), VISIBLEGROUPS => get_string('groupsvisible'));
         $mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $options, NOGROUPS);
         $mform->addHelpButton('groupmode', 'groupmode', 'group');
     }
     if ($this->_features->groupings or $this->_features->groupmembersonly) {
         //groupings selector - used for normal grouping mode or also when restricting access with groupmembersonly
         $options = array();
         if ($groupings = $DB->get_records('groupings', array('courseid' => $COURSE->id))) {
             foreach ($groupings as $grouping) {
                 $options[$grouping->id] = format_string($grouping->name);
             }
         }
         core_collator::asort($options);
         $options = array(0 => get_string('none')) + $options;
         $mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options);
         $mform->addHelpButton('groupingid', 'grouping', 'group');
     }
     if ($this->_features->groupmembersonly) {
         $mform->addElement('checkbox', 'groupmembersonly', get_string('groupmembersonly', 'group'));
         $mform->addHelpButton('groupmembersonly', 'groupmembersonly', 'group');
     }
     if (!empty($CFG->enableavailability)) {
         // String used by conditions
         $strnone = get_string('none', 'condition');
         // Conditional availability
         // Available from/to defaults to midnight because then the display
         // will be nicer where it tells users when they can access it (it
         // shows only the date and not time).
         $date = usergetdate(time());
         $midnight = make_timestamp($date['year'], $date['mon'], $date['mday']);
         // From/until controls
         $mform->addElement('header', 'availabilityconditionsheader', get_string('availabilityconditions', 'condition'));
         $mform->addElement('date_time_selector', 'availablefrom', get_string('availablefrom', 'condition'), array('optional' => true, 'defaulttime' => $midnight));
         $mform->addHelpButton('availablefrom', 'availablefrom', 'condition');
         $mform->addElement('date_time_selector', 'availableuntil', get_string('availableuntil', 'condition'), array('optional' => true, 'defaulttime' => $midnight));
         // Conditions based on grades
         $gradeoptions = array();
         $items = grade_item::fetch_all(array('courseid' => $COURSE->id));
         $items = $items ? $items : array();
         foreach ($items as $id => $item) {
             // Do not include grades for current item
             if (!empty($this->_cm) && $this->_cm->instance == $item->iteminstance && $this->_cm->modname == $item->itemmodule && $item->itemtype == 'mod') {
                 continue;
             }
             $gradeoptions[$id] = $item->get_name();
         }
         asort($gradeoptions);
         $gradeoptions = array(0 => $strnone) + $gradeoptions;
         $grouparray = array();
         $grouparray[] =& $mform->createElement('select', 'conditiongradeitemid', '', $gradeoptions);
         $grouparray[] =& $mform->createElement('static', '', '', ' ' . get_string('grade_atleast', 'condition') . ' ');
         $grouparray[] =& $mform->createElement('text', 'conditiongrademin', '', array('size' => 3));
         $grouparray[] =& $mform->createElement('static', '', '', '% ' . get_string('grade_upto', 'condition') . ' ');
         $grouparray[] =& $mform->createElement('text', 'conditiongrademax', '', array('size' => 3));
         $grouparray[] =& $mform->createElement('static', '', '', '%');
         $group = $mform->createElement('group', 'conditiongradegroup', get_string('gradecondition', 'condition'), $grouparray);
         // Get version with condition info and store it so we don't ask
         // twice
         if (!empty($this->_cm)) {
             $ci = new condition_info($this->_cm, CONDITION_MISSING_EXTRATABLE);
             $this->_cm = $ci->get_full_course_module();
             $count = count($this->_cm->conditionsgrade) + 1;
             $fieldcount = count($this->_cm->conditionsfield) + 1;
         } else {
             $count = 1;
             $fieldcount = 1;
         }
         $this->repeat_elements(array($group), $count, array('conditiongradegroup[conditiongrademin]' => array('type' => PARAM_RAW), 'conditiongradegroup[conditiongrademax]' => array('type' => PARAM_RAW)), 'conditiongraderepeats', 'conditiongradeadds', 2, get_string('addgrades', 'condition'), true);
         $mform->addHelpButton('conditiongradegroup[0]', 'gradecondition', 'condition');
         // Conditions based on user fields
         $operators = condition_info::get_condition_user_field_operators();
         $useroptions = condition_info::get_condition_user_fields(array('context' => $this->context));
         asort($useroptions);
         $useroptions = array(0 => $strnone) + $useroptions;
         $grouparray = array();
         $grouparray[] =& $mform->createElement('select', 'conditionfield', '', $useroptions);
         $grouparray[] =& $mform->createElement('select', 'conditionfieldoperator', '', $operators);
         $grouparray[] =& $mform->createElement('text', 'conditionfieldvalue');
         $group = $mform->createElement('group', 'conditionfieldgroup', get_string('userfield', 'condition'), $grouparray);
         $this->repeat_elements(array($group), $fieldcount, array('conditionfieldgroup[conditionfieldvalue]' => array('type' => PARAM_RAW)), 'conditionfieldrepeats', 'conditionfieldadds', 2, get_string('adduserfields', 'condition'), true);
         $mform->addHelpButton('conditionfieldgroup[0]', 'userfield', 'condition');
         // Conditions based on completion
         $completion = new completion_info($COURSE);
         if ($completion->is_enabled()) {
             $completionoptions = array();
             $modinfo = get_fast_modinfo($COURSE);
             foreach ($modinfo->cms as $id => $cm) {
                 // Add each course-module if it:
                 // (a) has completion turned on
                 // (b) is not the same as current course-module
                 if ($cm->completion && (empty($this->_cm) || $this->_cm->id != $id)) {
                     $completionoptions[$id] = $cm->name;
                 }
             }
             asort($completionoptions);
             $completionoptions = array(0 => $strnone) + $completionoptions;
             $completionvalues = array(COMPLETION_COMPLETE => get_string('completion_complete', 'condition'), COMPLETION_INCOMPLETE => get_string('completion_incomplete', 'condition'), COMPLETION_COMPLETE_PASS => get_string('completion_pass', 'condition'), COMPLETION_COMPLETE_FAIL => get_string('completion_fail', 'condition'));
             $grouparray = array();
             $grouparray[] =& $mform->createElement('select', 'conditionsourcecmid', '', $completionoptions);
             $grouparray[] =& $mform->createElement('select', 'conditionrequiredcompletion', '', $completionvalues);
             $group = $mform->createElement('group', 'conditioncompletiongroup', get_string('completioncondition', 'condition'), $grouparray);
             $count = empty($this->_cm) ? 1 : count($this->_cm->conditionscompletion) + 1;
             $this->repeat_elements(array($group), $count, array(), 'conditioncompletionrepeats', 'conditioncompletionadds', 2, get_string('addcompletions', 'condition'), true);
             $mform->addHelpButton('conditioncompletiongroup[0]', 'completioncondition', 'condition');
         }
         // Do we display availability info to students?
         $mform->addElement('select', 'showavailability', get_string('showavailability', 'condition'), array(CONDITION_STUDENTVIEW_SHOW => get_string('showavailability_show', 'condition'), CONDITION_STUDENTVIEW_HIDE => get_string('showavailability_hide', 'condition')));
         $mform->setDefault('showavailability', CONDITION_STUDENTVIEW_SHOW);
     }
     // Conditional activities: completion tracking section
     if (!isset($completion)) {
         $completion = new completion_info($COURSE);
     }
     if ($completion->is_enabled()) {
         $mform->addElement('header', 'activitycompletionheader', get_string('activitycompletion', 'completion'));
         // Unlock button for if people have completed it (will
         // be removed in definition_after_data if they haven't)
         $mform->addElement('submit', 'unlockcompletion', get_string('unlockcompletion', 'completion'));
         $mform->registerNoSubmitButton('unlockcompletion');
         $mform->addElement('hidden', 'completionunlocked', 0);
         $mform->setType('completionunlocked', PARAM_INT);
         $trackingdefault = COMPLETION_TRACKING_NONE;
         // If system and activity default is on, set it.
         if ($CFG->completiondefault && $this->_features->defaultcompletion) {
             $trackingdefault = COMPLETION_TRACKING_MANUAL;
         }
         $mform->addElement('select', 'completion', get_string('completion', 'completion'), array(COMPLETION_TRACKING_NONE => get_string('completion_none', 'completion'), COMPLETION_TRACKING_MANUAL => get_string('completion_manual', 'completion')));
         $mform->setDefault('completion', $trackingdefault);
         $mform->addHelpButton('completion', 'completion', 'completion');
         // Automatic completion once you view it
         $gotcompletionoptions = false;
         if (plugin_supports('mod', $this->_modname, FEATURE_COMPLETION_TRACKS_VIEWS, false)) {
             $mform->addElement('checkbox', 'completionview', get_string('completionview', 'completion'), get_string('completionview_desc', 'completion'));
             $mform->disabledIf('completionview', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
             $gotcompletionoptions = true;
         }
         // Automatic completion once it's graded
         if (plugin_supports('mod', $this->_modname, FEATURE_GRADE_HAS_GRADE, false)) {
             $mform->addElement('checkbox', 'completionusegrade', get_string('completionusegrade', 'completion'), get_string('completionusegrade_desc', 'completion'));
             $mform->disabledIf('completionusegrade', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
             $mform->addHelpButton('completionusegrade', 'completionusegrade', 'completion');
             $gotcompletionoptions = true;
         }
         // Automatic completion according to module-specific rules
         $this->_customcompletionelements = $this->add_completion_rules();
         foreach ($this->_customcompletionelements as $element) {
             $mform->disabledIf($element, 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
         }
         $gotcompletionoptions = $gotcompletionoptions || count($this->_customcompletionelements) > 0;
         // Automatic option only appears if possible
         if ($gotcompletionoptions) {
             $mform->getElement('completion')->addOption(get_string('completion_automatic', 'completion'), COMPLETION_TRACKING_AUTOMATIC);
         }
         // Completion expected at particular date? (For progress tracking)
         $mform->addElement('date_selector', 'completionexpected', get_string('completionexpected', 'completion'), array('optional' => true));
         $mform->addHelpButton('completionexpected', 'completionexpected', 'completion');
         $mform->disabledIf('completionexpected', 'completion', 'eq', COMPLETION_TRACKING_NONE);
     }
     $this->standard_hidden_coursemodule_elements();
 }
Esempio n. 25
0
 /**
  * Adds all the standard elements to a form to edit the settings for an activity module.
  */
 function standard_coursemodule_elements()
 {
     global $COURSE, $CFG, $DB;
     $mform =& $this->_form;
     $this->_outcomesused = false;
     if ($this->_features->outcomes) {
         if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
             $this->_outcomesused = true;
             $mform->addElement('header', 'modoutcomes', get_string('outcomes', 'grades'));
             foreach ($outcomes as $outcome) {
                 $mform->addElement('advcheckbox', 'outcome_' . $outcome->id, $outcome->get_name());
             }
         }
     }
     if ($this->_features->rating) {
         require_once $CFG->dirroot . '/rating/lib.php';
         $rm = new rating_manager();
         $mform->addElement('header', 'modstandardratings', get_string('ratings', 'rating'));
         $permission = CAP_ALLOW;
         $rolenamestring = null;
         if (!empty($this->_cm)) {
             $context = context_module::instance($this->_cm->id);
             $rolenames = get_role_names_with_caps_in_context($context, array('moodle/rating:rate', 'mod/' . $this->_cm->modname . ':rate'));
             $rolenamestring = implode(', ', $rolenames);
         } else {
             $rolenamestring = get_string('capabilitychecknotavailable', 'rating');
         }
         $mform->addElement('static', 'rolewarning', get_string('rolewarning', 'rating'), $rolenamestring);
         $mform->addHelpButton('rolewarning', 'rolewarning', 'rating');
         $mform->addElement('select', 'assessed', get_string('aggregatetype', 'rating'), $rm->get_aggregate_types());
         $mform->setDefault('assessed', 0);
         $mform->addHelpButton('assessed', 'aggregatetype', 'rating');
         $mform->addElement('modgrade', 'scale', get_string('scale'), false);
         $mform->disabledIf('scale', 'assessed', 'eq', 0);
         $mform->addHelpButton('scale', 'modgrade', 'grades');
         $mform->setDefault('scale', $CFG->gradepointdefault);
         $mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'rating'));
         $mform->disabledIf('ratingtime', 'assessed', 'eq', 0);
         $mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
         $mform->disabledIf('assesstimestart', 'assessed', 'eq', 0);
         $mform->disabledIf('assesstimestart', 'ratingtime');
         $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
         $mform->disabledIf('assesstimefinish', 'assessed', 'eq', 0);
         $mform->disabledIf('assesstimefinish', 'ratingtime');
     }
     //doing this here means splitting up the grade related settings on the lesson settings page
     //$this->standard_grading_coursemodule_elements();
     $mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form'));
     $mform->addElement('modvisible', 'visible', get_string('visible'));
     if (!empty($this->_cm)) {
         $context = context_module::instance($this->_cm->id);
         if (!has_capability('moodle/course:activityvisibility', $context)) {
             $mform->hardFreeze('visible');
         }
     }
     if ($this->_features->idnumber) {
         $mform->addElement('text', 'cmidnumber', get_string('idnumbermod'));
         $mform->setType('cmidnumber', PARAM_RAW);
         $mform->addHelpButton('cmidnumber', 'idnumbermod');
     }
     if ($this->_features->groups) {
         $options = array(NOGROUPS => get_string('groupsnone'), SEPARATEGROUPS => get_string('groupsseparate'), VISIBLEGROUPS => get_string('groupsvisible'));
         $mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $options, NOGROUPS);
         $mform->addHelpButton('groupmode', 'groupmode', 'group');
     }
     if ($this->_features->groupings) {
         // Groupings selector - used to select grouping for groups in activity.
         $options = array();
         if ($groupings = $DB->get_records('groupings', array('courseid' => $COURSE->id))) {
             foreach ($groupings as $grouping) {
                 $options[$grouping->id] = format_string($grouping->name);
             }
         }
         core_collator::asort($options);
         $options = array(0 => get_string('none')) + $options;
         $mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options);
         $mform->addHelpButton('groupingid', 'grouping', 'group');
     }
     if (!empty($CFG->enableavailability)) {
         // Add special button to end of previous section if groups/groupings
         // are enabled.
         if ($this->_features->groups || $this->_features->groupings) {
             $mform->addElement('static', 'restrictgroupbutton', '', html_writer::tag('button', get_string('restrictbygroup', 'availability'), array('id' => 'restrictbygroup', 'disabled' => 'disabled')));
         }
         // Availability field. This is just a textarea; the user interface
         // interaction is all implemented in JavaScript.
         $mform->addElement('header', 'availabilityconditionsheader', get_string('restrictaccess', 'availability'));
         // Note: This field cannot be named 'availability' because that
         // conflicts with fields in existing modules (such as assign).
         // So it uses a long name that will not conflict.
         $mform->addElement('textarea', 'availabilityconditionsjson', get_string('accessrestrictions', 'availability'));
         // The _cm variable may not be a proper cm_info, so get one from modinfo.
         if ($this->_cm) {
             $modinfo = get_fast_modinfo($COURSE);
             $cm = $modinfo->get_cm($this->_cm->id);
         } else {
             $cm = null;
         }
         \core_availability\frontend::include_all_javascript($COURSE, $cm);
     }
     // Conditional activities: completion tracking section
     if (!isset($completion)) {
         $completion = new completion_info($COURSE);
     }
     if ($completion->is_enabled()) {
         $mform->addElement('header', 'activitycompletionheader', get_string('activitycompletion', 'completion'));
         // Unlock button for if people have completed it (will
         // be removed in definition_after_data if they haven't)
         $mform->addElement('submit', 'unlockcompletion', get_string('unlockcompletion', 'completion'));
         $mform->registerNoSubmitButton('unlockcompletion');
         $mform->addElement('hidden', 'completionunlocked', 0);
         $mform->setType('completionunlocked', PARAM_INT);
         $trackingdefault = COMPLETION_TRACKING_NONE;
         // If system and activity default is on, set it.
         if ($CFG->completiondefault && $this->_features->defaultcompletion) {
             $trackingdefault = COMPLETION_TRACKING_MANUAL;
         }
         $mform->addElement('select', 'completion', get_string('completion', 'completion'), array(COMPLETION_TRACKING_NONE => get_string('completion_none', 'completion'), COMPLETION_TRACKING_MANUAL => get_string('completion_manual', 'completion')));
         $mform->setDefault('completion', $trackingdefault);
         $mform->addHelpButton('completion', 'completion', 'completion');
         // Automatic completion once you view it
         $gotcompletionoptions = false;
         if (plugin_supports('mod', $this->_modname, FEATURE_COMPLETION_TRACKS_VIEWS, false)) {
             $mform->addElement('checkbox', 'completionview', get_string('completionview', 'completion'), get_string('completionview_desc', 'completion'));
             $mform->disabledIf('completionview', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
             $gotcompletionoptions = true;
         }
         // Automatic completion once it's graded
         if (plugin_supports('mod', $this->_modname, FEATURE_GRADE_HAS_GRADE, false)) {
             $mform->addElement('checkbox', 'completionusegrade', get_string('completionusegrade', 'completion'), get_string('completionusegrade_desc', 'completion'));
             $mform->disabledIf('completionusegrade', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
             $mform->addHelpButton('completionusegrade', 'completionusegrade', 'completion');
             $gotcompletionoptions = true;
             // If using the rating system, there is no grade unless ratings are enabled.
             if ($this->_features->rating) {
                 $mform->disabledIf('completionusegrade', 'assessed', 'eq', 0);
             }
         }
         // Automatic completion according to module-specific rules
         $this->_customcompletionelements = $this->add_completion_rules();
         foreach ($this->_customcompletionelements as $element) {
             $mform->disabledIf($element, 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
         }
         $gotcompletionoptions = $gotcompletionoptions || count($this->_customcompletionelements) > 0;
         // Automatic option only appears if possible
         if ($gotcompletionoptions) {
             $mform->getElement('completion')->addOption(get_string('completion_automatic', 'completion'), COMPLETION_TRACKING_AUTOMATIC);
         }
         // Completion expected at particular date? (For progress tracking)
         $mform->addElement('date_selector', 'completionexpected', get_string('completionexpected', 'completion'), array('optional' => true));
         $mform->addHelpButton('completionexpected', 'completionexpected', 'completion');
         $mform->disabledIf('completionexpected', 'completion', 'eq', COMPLETION_TRACKING_NONE);
     }
     $this->standard_hidden_coursemodule_elements();
 }
Esempio n. 26
0
/**
 * Return a {@link block_contents} representing the add a new block UI, if
 * this user is allowed to see it.
 *
 * @return block_contents an appropriate block_contents, or null if the user
 * cannot add any blocks here.
 */
function block_add_block_ui($page, $output)
{
    global $CFG, $OUTPUT;
    if (!$page->user_is_editing() || !$page->user_can_edit_blocks()) {
        return null;
    }
    $bc = new block_contents();
    $bc->title = get_string('addblock');
    $bc->add_class('block_adminblock');
    $bc->attributes['data-block'] = 'adminblock';
    $missingblocks = $page->blocks->get_addable_blocks();
    if (empty($missingblocks)) {
        $bc->content = get_string('noblockstoaddhere');
        return $bc;
    }
    $menu = array();
    foreach ($missingblocks as $block) {
        $blockobject = block_instance($block->name);
        if ($blockobject !== false && $blockobject->user_can_addto($page)) {
            $menu[$block->name] = $blockobject->get_title();
        }
    }
    core_collator::asort($menu);
    $actionurl = new moodle_url($page->url, array('sesskey' => sesskey()));
    $select = new single_select($actionurl, 'bui_addblock', $menu, null, array('' => get_string('adddots')), 'add_block');
    $select->set_label(get_string('addblock'), array('class' => 'accesshide'));
    $bc->content = $OUTPUT->render($select);
    return $bc;
}
Esempio n. 27
0
 /**
  * Obtains the last unique sufix (numeric) using the test course prefix.
  *
  * @return int The last generated numeric value.
  */
 protected static function get_last_testcourse_id()
 {
     global $DB;
     $params = array();
     $params['shortnameprefix'] = $DB->sql_like_escape(self::SHORTNAMEPREFIX) . '%';
     $like = $DB->sql_like('shortname', ':shortnameprefix');
     if (!($testcourses = $DB->get_records_select('course', $like, $params, '', 'shortname'))) {
         return 0;
     }
     // SQL order by is not appropiate here as is ordering strings.
     $shortnames = array_keys($testcourses);
     core_collator::asort($shortnames, core_collator::SORT_NATURAL);
     $shortnames = array_reverse($shortnames);
     // They come ordered by shortname DESC, so non-numeric values will be the first ones.
     $prefixnchars = strlen(self::SHORTNAMEPREFIX);
     foreach ($shortnames as $shortname) {
         $sufix = substr($shortname, $prefixnchars);
         if (preg_match('/^[\\d]+$/', $sufix)) {
             return $sufix;
         }
     }
     // If all sufixes are not numeric this is the first make test site run.
     return 0;
 }
Esempio n. 28
0
 /**
  * Returns array of localised human-readable module names used in this course
  *
  * @param bool $plural if true returns the plural form of modules names
  * @return array
  */
 public function get_used_module_names($plural = false) {
     $modnames = get_module_types_names($plural);
     $modnamesused = array();
     foreach ($this->get_cms() as $cmid => $mod) {
         if (isset($modnames[$mod->modname]) && $mod->uservisible) {
             $modnamesused[$mod->modname] = $modnames[$mod->modname];
         }
     }
     core_collator::asort($modnamesused);
     return $modnamesused;
 }
Esempio n. 29
0
/**
 * Get the names of all the filters installed in this Moodle.
 *
 * @return array path => filter name from the appropriate lang file. e.g.
 * array('tex' => 'TeX Notation');
 * sorted in alphabetical order of name.
 */
function filter_get_all_installed()
{
    global $CFG;
    $filternames = array();
    foreach (core_component::get_plugin_list('filter') as $filter => $fulldir) {
        if (is_readable("{$fulldir}/filter.php")) {
            $filternames[$filter] = filter_get_name($filter);
        }
    }
    core_collator::asort($filternames);
    return $filternames;
}
Esempio n. 30
0
 /**
  * Get the list of files and directories in that repository.
  *
  * @param string $fullpath Path to explore. This is assembled by {@link self::build_node_path()}.
  * @param string $page Page number.
  * @return array List of files and folders.
  */
 public function get_listing($fullpath = '', $page = '')
 {
     global $OUTPUT;
     $list = array('list' => array(), 'manage' => false, 'dynload' => true, 'nologin' => true, 'path' => array());
     // We analyse the path to extract what to browse.
     $fullpath = empty($fullpath) ? $this->build_node_path('root') : $fullpath;
     $trail = explode('|', $fullpath);
     $trail = array_pop($trail);
     list($mode, $path, $unused) = $this->explode_node_path($trail);
     // Is that a search?
     if ($mode === 'search') {
         return $this->search($path, $page);
     }
     // Cleaning up the requested path.
     $path = trim($path, '/');
     if (!$this->is_in_repository($path)) {
         // In case of doubt on the path, reset to default.
         $path = '';
     }
     $rootpath = $this->get_rootpath();
     $abspath = rtrim($rootpath . $path, '/') . '/';
     // Retrieve list of files and directories and sort them.
     $fileslist = array();
     $dirslist = array();
     if ($dh = opendir($abspath)) {
         while (($file = readdir($dh)) != false) {
             if ($file != '.' and $file != '..') {
                 if (is_file($abspath . $file)) {
                     $fileslist[] = $file;
                 } else {
                     $dirslist[] = $file;
                 }
             }
         }
     }
     core_collator::asort($fileslist, core_collator::SORT_NATURAL);
     core_collator::asort($dirslist, core_collator::SORT_NATURAL);
     // Fill the results.
     foreach ($dirslist as $file) {
         $list['list'][] = $this->build_node($rootpath, $path, $file, true, $fullpath);
     }
     foreach ($fileslist as $file) {
         $list['list'][] = $this->build_node($rootpath, $path, $file, false, $fullpath);
     }
     $list['path'] = $this->build_breadcrumb($fullpath);
     $list['list'] = array_filter($list['list'], array($this, 'filter'));
     return $list;
 }