if (!confirm_sesskey()) { print_error('sesskey'); } $usercontext = context_user::instance($USER->id); switch ($action) { case 'addinterest': if (!core_tag_tag::is_enabled('core', 'user')) { print_error('tagdisabled'); } $tag = required_param('tag', PARAM_TAG); core_tag_tag::add_item_tag('core', 'user', $USER->id, $usercontext, $tag); $tc = core_tag_area::get_collection('core', 'user'); redirect(core_tag_tag::make_url($tc, $tag)); break; case 'removeinterest': if (!core_tag_tag::is_enabled('core', 'user')) { print_error('tagdisabled'); } $tag = required_param('tag', PARAM_TAG); core_tag_tag::remove_item_tag('core', 'user', $USER->id, $tag); $tc = core_tag_area::get_collection('core', 'user'); redirect(core_tag_tag::make_url($tc, $tag)); break; case 'flaginappropriate': require_capability('moodle/tag:flag', context_system::instance()); $id = required_param('id', PARAM_INT); $tagobject = core_tag_tag::get($id, '*', MUST_EXIST); $tagobject->flag(); redirect($tagobject->get_view_url(), get_string('responsiblewillbenotified', 'tag')); break; default:
protected function process_tag($data) { global $CFG, $DB; $data = (object) $data; $newquestion = $this->get_new_parentid('question'); $questioncreated = (bool) $this->get_mappingid('question_created', $this->get_old_parentid('question')); if (!$questioncreated) { // This question already exists in the question bank. Nothing for us to do. return; } if (core_tag_tag::is_enabled('core_question', 'question')) { $tagname = $data->rawname; // Get the category, so we can then later get the context. $categoryid = $this->get_new_parentid('question_category'); if (empty($this->cachedcategory) || $this->cachedcategory->id != $categoryid) { $this->cachedcategory = $DB->get_record('question_categories', array('id' => $categoryid)); } // Add the tag to the question. core_tag_tag::add_item_tag('core_question', 'question', $newquestion, context::instance_by_id($this->cachedcategory->contextid), $tagname); } }
/** * Checks if tagging is enabled for this itemtype * * @return boolean */ protected function is_tagging_enabled() { if (!empty($this->tagsoptions['itemtype']) && !empty($this->tagsoptions['component'])) { $enabled = core_tag_tag::is_enabled($this->tagsoptions['component'], $this->tagsoptions['itemtype']); if ($enabled === false) { return false; } } // Backward compatibility with code developed before Moodle 3.0 where itemtype/component were not specified. return true; }
/** * Private function to factor common code out of get_question_options(). * * @param object $question the question to tidy. * @param boolean $loadtags load the question tags from the tags table. Optional, default false. */ function _tidy_question($question, $loadtags = false) { global $CFG; // Load question-type specific fields. if (!question_bank::is_qtype_installed($question->qtype)) { $question->questiontext = html_writer::tag('p', get_string('warningmissingtype', 'qtype_missingtype')) . $question->questiontext; } question_bank::get_qtype($question->qtype)->get_question_options($question); // Convert numeric fields to float. (Prevents these being displayed as 1.0000000.) $question->defaultmark += 0; $question->penalty += 0; if (isset($question->_partiallyloaded)) { unset($question->_partiallyloaded); } if ($loadtags && core_tag_tag::is_enabled('core_question', 'question')) { $question->tags = core_tag_tag::get_item_tags_array('core_question', 'question', $question->id); } }
/** * Given one restoreid, create in DB all the users present * in backup_ids having newitemid = 0, as far as * precheck_included_users() have left them there * ready to be created. Also, annotate their newids * once created for later reference. * * This function will start and end a new progress section in the progress * object. * * @param string $basepath Base path of unzipped backup * @param string $restoreid Restore ID * @param int $userid Default userid for files * @param \core\progress\base $progress Object used for progress tracking */ public static function create_included_users($basepath, $restoreid, $userid, \core\progress\base $progress) { global $CFG, $DB; $progress->start_progress('Creating included users'); $authcache = array(); // Cache to get some bits from authentication plugins $languages = get_string_manager()->get_list_of_translations(); // Get languages for quick search later $themes = get_list_of_themes(); // Get themes for quick search later // Iterate over all the included users with newitemid = 0, have to create them $rs = $DB->get_recordset('backup_ids_temp', array('backupid' => $restoreid, 'itemname' => 'user', 'newitemid' => 0), '', 'itemid, parentitemid, info'); foreach ($rs as $recuser) { $progress->progress(); $user = (object) backup_controller_dbops::decode_backup_temp_info($recuser->info); // if user lang doesn't exist here, use site default if (!array_key_exists($user->lang, $languages)) { $user->lang = $CFG->lang; } // if user theme isn't available on target site or they are disabled, reset theme if (!empty($user->theme)) { if (empty($CFG->allowuserthemes) || !in_array($user->theme, $themes)) { $user->theme = ''; } } // if user to be created has mnet auth and its mnethostid is $CFG->mnet_localhost_id // that's 100% impossible as own server cannot be accesed over mnet. Change auth to email/manual if ($user->auth == 'mnet' && $user->mnethostid == $CFG->mnet_localhost_id) { // Respect registerauth if ($CFG->registerauth == 'email') { $user->auth = 'email'; } else { $user->auth = 'manual'; } } unset($user->mnethosturl); // Not needed anymore // Disable pictures based on global setting if (!empty($CFG->disableuserimages)) { $user->picture = 0; } // We need to analyse the AUTH field to recode it: // - if the auth isn't enabled in target site, $CFG->registerauth will decide // - finally, if the auth resulting isn't enabled, default to 'manual' if (!is_enabled_auth($user->auth)) { if ($CFG->registerauth == 'email') { $user->auth = 'email'; } else { $user->auth = 'manual'; } } if (!is_enabled_auth($user->auth)) { // Final auth check verify, default to manual if not enabled $user->auth = 'manual'; } // Now that we know the auth method, for users to be created without pass // if password handling is internal and reset password is available // we set the password to "restored" (plain text), so the login process // will know how to handle that situation in order to allow the user to // recover the password. MDL-20846 if (empty($user->password)) { // Only if restore comes without password if (!array_key_exists($user->auth, $authcache)) { // Not in cache $userauth = new stdClass(); $authplugin = get_auth_plugin($user->auth); $userauth->preventpassindb = $authplugin->prevent_local_passwords(); $userauth->isinternal = $authplugin->is_internal(); $userauth->canresetpwd = $authplugin->can_reset_password(); $authcache[$user->auth] = $userauth; } else { $userauth = $authcache[$user->auth]; // Get from cache } // Most external plugins do not store passwords locally if (!empty($userauth->preventpassindb)) { $user->password = AUTH_PASSWORD_NOT_CACHED; // If Moodle is responsible for storing/validating pwd and reset functionality is available, mark } else { if ($userauth->isinternal and $userauth->canresetpwd) { $user->password = '******'; } } } // Creating new user, we must reset the policyagreed always $user->policyagreed = 0; // Set time created if empty if (empty($user->timecreated)) { $user->timecreated = time(); } // Done, let's create the user and annotate its id $newuserid = $DB->insert_record('user', $user); self::set_backup_ids_record($restoreid, 'user', $recuser->itemid, $newuserid); // Let's create the user context and annotate it (we need it for sure at least for files) // but for deleted users that don't have a context anymore (MDL-30192). We are done for them // and nothing else (custom fields, prefs, tags, files...) will be created. if (empty($user->deleted)) { $newuserctxid = $user->deleted ? 0 : context_user::instance($newuserid)->id; self::set_backup_ids_record($restoreid, 'context', $recuser->parentitemid, $newuserctxid); // Process custom fields if (isset($user->custom_fields)) { // if present in backup foreach ($user->custom_fields['custom_field'] as $udata) { $udata = (object) $udata; // If the profile field has data and the profile shortname-datatype is defined in server if ($udata->field_data) { if ($field = $DB->get_record('user_info_field', array('shortname' => $udata->field_name, 'datatype' => $udata->field_type))) { /// Insert the user_custom_profile_field $rec = new stdClass(); $rec->userid = $newuserid; $rec->fieldid = $field->id; $rec->data = $udata->field_data; $DB->insert_record('user_info_data', $rec); } } } } // Process tags if (core_tag_tag::is_enabled('core', 'user') && isset($user->tags)) { // If enabled in server and present in backup. $tags = array(); foreach ($user->tags['tag'] as $usertag) { $usertag = (object) $usertag; $tags[] = $usertag->rawname; } core_tag_tag::set_item_tags('core', 'user', $newuserid, context_user::instance($newuserid), $tags); } // Process preferences if (isset($user->preferences)) { // if present in backup foreach ($user->preferences['preference'] as $preference) { $preference = (object) $preference; // Prepare the record and insert it $preference->userid = $newuserid; $status = $DB->insert_record('user_preferences', $preference); } } // Special handling for htmleditor which was converted to a preference. if (isset($user->htmleditor)) { if ($user->htmleditor == 0) { $preference = new stdClass(); $preference->userid = $newuserid; $preference->name = 'htmleditor'; $preference->value = 'textarea'; $status = $DB->insert_record('user_preferences', $preference); } } // Create user files in pool (profile, icon, private) by context restore_dbops::send_files_to_pool($basepath, $restoreid, 'user', 'icon', $recuser->parentitemid, $userid, null, null, null, false, $progress); restore_dbops::send_files_to_pool($basepath, $restoreid, 'user', 'profile', $recuser->parentitemid, $userid, null, null, null, false, $progress); } } $rs->close(); $progress->end_progress(); }
/** * 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; $isupdate = false; if (!empty($this->_cm)) { $isupdate = true; $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'); $gradeoptions = array('isupdate' => $isupdate, 'currentgrade' => false, 'hasgrades' => false, 'canrescale' => $this->_features->canrescale, 'useratings' => $this->_features->rating); if ($isupdate) { $gradeitem = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $this->_cm->modname, 'iteminstance' => $this->_cm->instance, 'itemnumber' => 0, 'courseid' => $COURSE->id)); if ($gradeitem) { $gradeoptions['currentgrade'] = $gradeitem->grademax; $gradeoptions['currentgradetype'] = $gradeitem->gradetype; $gradeoptions['currentscaleid'] = $gradeitem->scaleid; $gradeoptions['hasgrades'] = $gradeitem->has_grades(); } } $mform->addElement('modgrade', 'scale', get_string('scale'), $gradeoptions); $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); } // Populate module tags. if (core_tag_tag::is_enabled('core', 'course_modules')) { $mform->addElement('header', 'tagshdr', get_string('tags', 'tag')); $mform->addElement('tags', 'tags', get_string('tags'), array('itemtype' => 'course_modules', 'component' => 'core')); if ($this->_cm) { $tags = core_tag_tag::get_item_tags_array('core', 'course_modules', $this->_cm->id); $mform->setDefault('tags', $tags); } } $this->standard_hidden_coursemodule_elements(); $this->plugin_extend_coursemodule_standard_elements(); }
/** * Update the module info. * This function doesn't check the user capabilities. It updates the course module and the module instance. * Then execute common action to create/update module process (trigger event, rebuild cache, save plagiarism settings...). * * @param object $cm course module * @param object $moduleinfo module info * @param object $course course of the module * @param object $mform - the mform is required by some specific module in the function MODULE_update_instance(). This is due to a hack in this function. * @return array list of course module and module info. */ function update_moduleinfo($cm, $moduleinfo, $course, $mform = null) { global $DB, $CFG; $data = new stdClass(); if ($mform) { $data = $mform->get_data(); } // Attempt to include module library before we make any changes to DB. include_modulelib($moduleinfo->modulename); $moduleinfo->course = $course->id; $moduleinfo = set_moduleinfo_defaults($moduleinfo); if (!empty($course->groupmodeforce) or !isset($moduleinfo->groupmode)) { $moduleinfo->groupmode = $cm->groupmode; // Keep original. } // Update course module first. $cm->groupmode = $moduleinfo->groupmode; if (isset($moduleinfo->groupingid)) { $cm->groupingid = $moduleinfo->groupingid; } $completion = new completion_info($course); if ($completion->is_enabled()) { // Completion settings that would affect users who have already completed // the activity may be locked; if so, these should not be updated. if (!empty($moduleinfo->completionunlocked)) { $cm->completion = $moduleinfo->completion; $cm->completiongradeitemnumber = $moduleinfo->completiongradeitemnumber; $cm->completionview = $moduleinfo->completionview; } // The expected date does not affect users who have completed the activity, // so it is safe to update it regardless of the lock status. $cm->completionexpected = $moduleinfo->completionexpected; } if (!empty($CFG->enableavailability)) { // This code is used both when submitting the form, which uses a long // name to avoid clashes, and by unit test code which uses the real // name in the table. if (property_exists($moduleinfo, 'availabilityconditionsjson')) { if ($moduleinfo->availabilityconditionsjson !== '') { $cm->availability = $moduleinfo->availabilityconditionsjson; } else { $cm->availability = null; } } else { if (property_exists($moduleinfo, 'availability')) { $cm->availability = $moduleinfo->availability; } } // If there is any availability data, verify it. if ($cm->availability) { $tree = new \core_availability\tree(json_decode($cm->availability)); // Save time and database space by setting null if the only data // is an empty tree. if ($tree->is_empty()) { $cm->availability = null; } } } if (isset($moduleinfo->showdescription)) { $cm->showdescription = $moduleinfo->showdescription; } else { $cm->showdescription = 0; } $DB->update_record('course_modules', $cm); $modcontext = context_module::instance($moduleinfo->coursemodule); // Update embedded links and save files. if (plugin_supports('mod', $moduleinfo->modulename, FEATURE_MOD_INTRO, true)) { $moduleinfo->intro = file_save_draft_area_files($moduleinfo->introeditor['itemid'], $modcontext->id, 'mod_' . $moduleinfo->modulename, 'intro', 0, array('subdirs' => true), $moduleinfo->introeditor['text']); $moduleinfo->introformat = $moduleinfo->introeditor['format']; unset($moduleinfo->introeditor); } // Get the a copy of the grade_item before it is modified incase we need to scale the grades. $oldgradeitem = null; $newgradeitem = null; if (!empty($data->grade_rescalegrades) && $data->grade_rescalegrades == 'yes') { // Fetch the grade item before it is updated. $oldgradeitem = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $moduleinfo->modulename, 'iteminstance' => $moduleinfo->instance, 'itemnumber' => 0, 'courseid' => $moduleinfo->course)); } $updateinstancefunction = $moduleinfo->modulename . "_update_instance"; if (!$updateinstancefunction($moduleinfo, $mform)) { print_error('cannotupdatemod', '', course_get_url($course, $cm->section), $moduleinfo->modulename); } // This needs to happen AFTER the grademin/grademax have already been updated. if (!empty($data->grade_rescalegrades) && $data->grade_rescalegrades == 'yes') { // Get the grade_item after the update call the activity to scale the grades. $newgradeitem = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $moduleinfo->modulename, 'iteminstance' => $moduleinfo->instance, 'itemnumber' => 0, 'courseid' => $moduleinfo->course)); if ($newgradeitem && $oldgradeitem->gradetype == GRADE_TYPE_VALUE && $newgradeitem->gradetype == GRADE_TYPE_VALUE) { $params = array($course, $cm, $oldgradeitem->grademin, $oldgradeitem->grademax, $newgradeitem->grademin, $newgradeitem->grademax); if (!component_callback('mod_' . $moduleinfo->modulename, 'rescale_activity_grades', $params)) { print_error('cannotreprocessgrades', '', course_get_url($course, $cm->section), $moduleinfo->modulename); } } } // Make sure visibility is set correctly (in particular in calendar). if (has_capability('moodle/course:activityvisibility', $modcontext)) { set_coursemodule_visible($moduleinfo->coursemodule, $moduleinfo->visible); } if (isset($moduleinfo->cmidnumber)) { // Label. // Set cm idnumber - uniqueness is already verified by form validation. set_coursemodule_idnumber($moduleinfo->coursemodule, $moduleinfo->cmidnumber); } // Update module tags. if (core_tag_tag::is_enabled('core', 'course_modules') && isset($moduleinfo->tags)) { core_tag_tag::set_item_tags('core', 'course_modules', $moduleinfo->coursemodule, $modcontext, $moduleinfo->tags); } // Now that module is fully updated, also update completion data if required. // (this will wipe all user completion data and recalculate it) if ($completion->is_enabled() && !empty($moduleinfo->completionunlocked)) { $completion->reset_all_state($cm); } $cm->name = $moduleinfo->name; \core\event\course_module_updated::create_from_cm($cm, $modcontext)->trigger(); $moduleinfo = edit_module_post_actions($moduleinfo, $course); return array($cm, $moduleinfo); }
function get_content() { global $CFG, $SITE, $USER, $DB, $OUTPUT; if ($this->content !== NULL) { return $this->content; } // make sure blog and tags are actually enabled if (empty($CFG->bloglevel)) { $this->content = new stdClass(); $this->content->text = ''; if ($this->page->user_is_editing()) { $this->content->text = get_string('blogdisable', 'blog'); } return $this->content; } else { if (!core_tag_tag::is_enabled('core', 'post')) { $this->content = new stdClass(); $this->content->text = ''; if ($this->page->user_is_editing()) { $this->content->text = get_string('tagsaredisabled', 'tag'); } return $this->content; } else { if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL and (!isloggedin() or isguestuser())) { $this->content = new stdClass(); $this->content->text = ''; return $this->content; } } } // require the libs and do the work require_once $CFG->dirroot . '/blog/lib.php'; if (empty($this->config)) { $this->config = new stdClass(); } if (empty($this->config->timewithin)) { $this->config->timewithin = BLOCK_BLOG_TAGS_DEFAULTTIMEWITHIN; } if (empty($this->config->numberoftags)) { $this->config->numberoftags = BLOCK_BLOG_TAGS_DEFAULTNUMBEROFTAGS; } if (empty($this->config->sort)) { $this->config->sort = BLOCK_BLOG_TAGS_DEFAULTSORT; } $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; /// Get a list of tags $timewithin = time() - $this->config->timewithin * 24 * 60 * 60; /// convert to seconds $context = $this->page->context; // admins should be able to read all tags $type = ''; if (!has_capability('moodle/user:readuserblogs', context_system::instance())) { $type = " AND (p.publishstate = 'site' or p.publishstate='public')"; } $sql = "SELECT t.id, t.isstandard, t.rawname, t.name, COUNT(DISTINCT ti.id) AS ct\n FROM {tag} t, {tag_instance} ti, {post} p, {blog_association} ba\n WHERE t.id = ti.tagid AND p.id = ti.itemid\n {$type}\n AND ti.itemtype = 'post'\n AND ti.component = 'core'\n AND ti.timemodified > {$timewithin}"; if ($context->contextlevel == CONTEXT_MODULE) { $sql .= " AND ba.contextid = {$context->id} AND p.id = ba.blogid "; } else { if ($context->contextlevel == CONTEXT_COURSE) { $sql .= " AND ba.contextid = {$context->id} AND p.id = ba.blogid "; } } $sql .= "\n GROUP BY t.id, t.isstandard, t.name, t.rawname\n ORDER BY ct DESC, t.name ASC"; if ($tags = $DB->get_records_sql($sql, null, 0, $this->config->numberoftags)) { /// There are 2 things to do: /// 1. tags with the same count should have the same size class /// 2. however many tags we have should be spread evenly over the /// 20 size classes $totaltags = count($tags); $currenttag = 0; $size = 20; $lasttagct = -1; $etags = array(); foreach ($tags as $tag) { $currenttag++; if ($currenttag == 1) { $lasttagct = $tag->ct; $size = 20; } else { if ($tag->ct != $lasttagct) { $lasttagct = $tag->ct; $size = 20 - (int) (($currenttag - 1) / $totaltags * 20); } } $tag->class = ($tag->isstandard ? "standardtag " : "") . "s{$size}"; $etags[] = $tag; } /// Now we sort the tag display order $CFG->tagsort = $this->config->sort; usort($etags, "block_blog_tags_sort"); /// Finally we create the output /// Accessibility: markup as a list. $this->content->text .= "\n<ul class='inline-list'>\n"; foreach ($etags as $tag) { $blogurl = new moodle_url('/blog/index.php'); switch ($CFG->bloglevel) { case BLOG_USER_LEVEL: $blogurl->param('userid', $USER->id); break; default: if ($context->contextlevel == CONTEXT_MODULE) { $blogurl->param('modid', $context->instanceid); } else { if ($context->contextlevel == CONTEXT_COURSE) { $blogurl->param('courseid', $context->instanceid); } } break; } $blogurl->param('tagid', $tag->id); $link = html_writer::link($blogurl, core_tag_tag::make_display_name($tag), array('class' => $tag->class, 'title' => get_string('numberofentries', 'blog', $tag->ct))); $this->content->text .= '<li>' . $link . '</li> '; } $this->content->text .= "\n</ul>\n"; } return $this->content; }
/** * Blog form definition. */ public function definition() { global $CFG, $DB; $mform =& $this->_form; $entry = $this->_customdata['entry']; $courseid = $this->_customdata['courseid']; $modid = $this->_customdata['modid']; $summaryoptions = $this->_customdata['summaryoptions']; $attachmentoptions = $this->_customdata['attachmentoptions']; $sitecontext = $this->_customdata['sitecontext']; $mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('text', 'subject', get_string('entrytitle', 'blog'), array('size' => 60, 'maxlength' => 128)); $mform->addElement('editor', 'summary_editor', get_string('entrybody', 'blog'), null, $summaryoptions); $mform->setType('subject', PARAM_TEXT); $mform->addRule('subject', get_string('emptytitle', 'blog'), 'required', null, 'client'); $mform->addRule('subject', get_string('maximumchars', '', 128), 'maxlength', 128, 'client'); $mform->setType('summary_editor', PARAM_RAW); $mform->addRule('summary_editor', get_string('emptybody', 'blog'), 'required', null, 'client'); $mform->addElement('filemanager', 'attachment_filemanager', get_string('attachment', 'forum'), null, $attachmentoptions); // Disable publishstate options that are not allowed. $publishstates = array(); $i = 0; foreach (blog_entry::get_applicable_publish_states() as $state => $desc) { $publishstates[$state] = $desc; // No maximum was set. $i++; } $mform->addElement('select', 'publishstate', get_string('publishto', 'blog'), $publishstates); $mform->addHelpButton('publishstate', 'publishto', 'blog'); $mform->setDefault('publishstate', 0); if (core_tag_tag::is_enabled('core', 'post')) { $mform->addElement('header', 'tagshdr', get_string('tags', 'tag')); } $mform->addElement('tags', 'tags', get_string('tags'), array('itemtype' => 'post', 'component' => 'core')); $allmodnames = array(); if (!empty($CFG->useblogassociations)) { if (!empty($entry->courseassoc) || !empty($courseid) && empty($modid)) { if (!empty($courseid)) { $course = $DB->get_record('course', array('id' => $courseid)); $context = context_course::instance($courseid); $a = new stdClass(); $a->coursename = format_string($course->fullname, true, array('context' => $context)); $contextid = $context->id; } else { $context = context::instance_by_id($entry->courseassoc); $sql = 'SELECT fullname FROM {course} cr LEFT JOIN {context} ct ON ct.instanceid = cr.id WHERE ct.id = ?'; $a = new stdClass(); $a->coursename = $DB->get_field_sql($sql, array($entry->courseassoc)); $contextid = $entry->courseassoc; } $mform->addElement('header', 'assochdr', get_string('associations', 'blog')); $mform->addElement('advcheckbox', 'courseassoc', get_string('associatewithcourse', 'blog', $a), null, null, array(0, $contextid)); $mform->setDefault('courseassoc', $contextid); } else { if (!empty($entry->modassoc) || !empty($modid)) { if (!empty($modid)) { $mod = get_coursemodule_from_id(false, $modid); $a = new stdClass(); $a->modtype = get_string('modulename', $mod->modname); $a->modname = $mod->name; $context = context_module::instance($modid); } else { $context = context::instance_by_id($entry->modassoc); $cm = $DB->get_record('course_modules', array('id' => $context->instanceid)); $a = new stdClass(); $a->modtype = $DB->get_field('modules', 'name', array('id' => $cm->module)); $a->modname = $DB->get_field($a->modtype, 'name', array('id' => $cm->instance)); $modid = $context->instanceid; } $mform->addElement('header', 'assochdr', get_string('associations', 'blog')); $mform->addElement('advcheckbox', 'modassoc', get_string('associatewithmodule', 'blog', $a), null, null, array(0, $context->id)); $mform->setDefault('modassoc', $context->id); } } } $this->add_action_buttons(); $mform->addElement('hidden', 'action'); $mform->setType('action', PARAM_ALPHANUMEXT); $mform->setDefault('action', ''); $mform->addElement('hidden', 'entryid'); $mform->setType('entryid', PARAM_INT); $mform->setDefault('entryid', $entry->id); $mform->addElement('hidden', 'modid'); $mform->setType('modid', PARAM_INT); $mform->setDefault('modid', $modid); $mform->addElement('hidden', 'courseid'); $mform->setType('courseid', PARAM_INT); $mform->setDefault('courseid', $courseid); }
/** * Build the form definition. * * This adds all the form fields that the default question type supports. * If your question type does not support all these fields, then you can * override this method and remove the ones you don't want with $mform->removeElement(). */ protected function definition() { global $COURSE, $CFG, $DB, $PAGE; $qtype = $this->qtype(); $langfile = "qtype_{$qtype}"; $mform = $this->_form; // Standard fields at the start of the form. $mform->addElement('header', 'generalheader', get_string("general", 'form')); if (!isset($this->question->id)) { if (!empty($this->question->formoptions->mustbeusable)) { $contexts = $this->contexts->having_add_and_use(); } else { $contexts = $this->contexts->having_cap('moodle/question:add'); } // Adding question. $mform->addElement('questioncategory', 'category', get_string('category', 'question'), array('contexts' => $contexts)); } else { if (!($this->question->formoptions->canmove || $this->question->formoptions->cansaveasnew)) { // Editing question with no permission to move from category. $mform->addElement('questioncategory', 'category', get_string('category', 'question'), array('contexts' => array($this->categorycontext))); $mform->addElement('hidden', 'usecurrentcat', 1); $mform->setType('usecurrentcat', PARAM_BOOL); $mform->setConstant('usecurrentcat', 1); } else { // Editing question with permission to move from category or save as new q. $currentgrp = array(); $currentgrp[0] = $mform->createElement('questioncategory', 'category', get_string('categorycurrent', 'question'), array('contexts' => array($this->categorycontext))); if ($this->question->formoptions->canedit || $this->question->formoptions->cansaveasnew) { // Not move only form. $currentgrp[1] = $mform->createElement('checkbox', 'usecurrentcat', '', get_string('categorycurrentuse', 'question')); $mform->setDefault('usecurrentcat', 1); } $currentgrp[0]->freeze(); $currentgrp[0]->setPersistantFreeze(false); $mform->addGroup($currentgrp, 'currentgrp', get_string('categorycurrent', 'question'), null, false); $mform->addElement('questioncategory', 'categorymoveto', get_string('categorymoveto', 'question'), array('contexts' => array($this->categorycontext))); if ($this->question->formoptions->canedit || $this->question->formoptions->cansaveasnew) { // Not move only form. $mform->disabledIf('categorymoveto', 'usecurrentcat', 'checked'); } } } $mform->addElement('text', 'name', get_string('questionname', 'question'), array('size' => 50, 'maxlength' => 255)); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'required', null, 'client'); $mform->addElement('editor', 'questiontext', get_string('questiontext', 'question'), array('rows' => 15), $this->editoroptions); $mform->setType('questiontext', PARAM_RAW); $mform->addRule('questiontext', null, 'required', null, 'client'); $mform->addElement('text', 'defaultmark', get_string('defaultmark', 'question'), array('size' => 7)); $mform->setType('defaultmark', PARAM_FLOAT); $mform->setDefault('defaultmark', 1); $mform->addRule('defaultmark', null, 'required', null, 'client'); $mform->addElement('editor', 'generalfeedback', get_string('generalfeedback', 'question'), array('rows' => 10), $this->editoroptions); $mform->setType('generalfeedback', PARAM_RAW); $mform->addHelpButton('generalfeedback', 'generalfeedback', 'question'); // Any questiontype specific fields. $this->definition_inner($mform); if (core_tag_tag::is_enabled('core_question', 'question')) { $mform->addElement('header', 'tagsheader', get_string('tags')); } $mform->addElement('tags', 'tags', get_string('tags'), array('itemtype' => 'question', 'component' => 'core_question')); if (!empty($this->question->id)) { $mform->addElement('header', 'createdmodifiedheader', get_string('createdmodifiedheader', 'question')); $a = new stdClass(); if (!empty($this->question->createdby)) { $a->time = userdate($this->question->timecreated); $a->user = fullname($DB->get_record('user', array('id' => $this->question->createdby))); } else { $a->time = get_string('unknown', 'question'); $a->user = get_string('unknown', 'question'); } $mform->addElement('static', 'created', get_string('created', 'question'), get_string('byandon', 'question', $a)); if (!empty($this->question->modifiedby)) { $a = new stdClass(); $a->time = userdate($this->question->timemodified); $a->user = fullname($DB->get_record('user', array('id' => $this->question->modifiedby))); $mform->addElement('static', 'modified', get_string('modified', 'question'), get_string('byandon', 'question', $a)); } } $this->add_hidden_fields(); $mform->addElement('hidden', 'qtype'); $mform->setType('qtype', PARAM_ALPHA); $mform->addElement('hidden', 'makecopy'); $mform->setType('makecopy', PARAM_INT); $buttonarray = array(); $buttonarray[] = $mform->createElement('submit', 'updatebutton', get_string('savechangesandcontinueediting', 'question')); if ($this->can_preview()) { $previewlink = $PAGE->get_renderer('core_question')->question_preview_link($this->question->id, $this->context, true); $buttonarray[] = $mform->createElement('static', 'previewlink', '', $previewlink); } $mform->addGroup($buttonarray, 'updatebuttonar', '', array(' '), false); $mform->closeHeaderBefore('updatebuttonar'); $this->add_action_buttons(true, get_string('savechanges')); if (!empty($this->question->id) && !($this->question->formoptions->canedit || $this->question->formoptions->cansaveasnew)) { $mform->hardFreezeAllVisibleExcept(array('categorymoveto', 'buttonar', 'currentgrp')); } }
protected function definition() { global $CFG; $mform = $this->_form; // BEWARE HACK: In order for things to work we need to override the form id and set it to mform1. // The first form to be instantiated never gets displayed so this should be safe. $mform->updateAttributes(array('id' => 'mform1')); $version = $this->_customdata['version']; $format = $this->_customdata['format']; if (empty($this->_customdata['contextid'])) { // Hack alert // This is being done ONLY to aid those who may have created there own wiki pages. It should be removed sometime // after the release of 2.3 (not creating an issue because this whole thing should be reviewed) debugging('You must always provide mod_wiki_edit_form with a contextid in its custom data', DEBUG_DEVELOPER); global $PAGE; $contextid = $PAGE->context->id; } else { $contextid = $this->_customdata['contextid']; } if (isset($this->_customdata['pagetitle'])) { // Page title must be formatted properly here as this is output and not an element. $pagetitle = get_string('editingpage', 'wiki', format_string($this->_customdata['pagetitle'], true, array('context' => context::instance_by_id($contextid, MUST_EXIST)))); } else { $pagetitle = get_string('editing', 'wiki'); } //editor $mform->addElement('header', 'general', $pagetitle); $fieldname = get_string('format' . $format, 'wiki'); if ($format != 'html') { // Use wiki editor $extensions = file_get_typegroup('extension', 'web_image'); $fs = get_file_storage(); $tree = $fs->get_area_tree($contextid, 'mod_wiki', $this->_customdata['filearea'], $this->_customdata['fileitemid']); $files = array(); foreach ($tree['files'] as $file) { $filename = $file->get_filename(); foreach ($extensions as $ext) { if (preg_match('#' . $ext . '$#i', $filename)) { $files[] = $filename; } } } $mform->addElement('wikieditor', 'newcontent', $fieldname, array('cols' => 100, 'rows' => 20, 'wiki_format' => $format, 'files' => $files)); $mform->addHelpButton('newcontent', 'format' . $format, 'wiki'); $mform->setType('newcontent', PARAM_RAW); // processed by trust text or cleaned before the display } else { $mform->addElement('editor', 'newcontent_editor', $fieldname, null, page_wiki_edit::$attachmentoptions); $mform->addHelpButton('newcontent_editor', 'formathtml', 'wiki'); $mform->setType('newcontent_editor', PARAM_RAW); // processed by trust text or cleaned before the display } //hiddens if ($version >= 0) { $mform->addElement('hidden', 'version', $version); $mform->setType('version', PARAM_FLOAT); } $mform->addElement('hidden', 'contentformat', $format); $mform->setType('contentformat', PARAM_ALPHANUMEXT); if (core_tag_tag::is_enabled('mod_wiki', 'wiki_pages')) { $mform->addElement('header', 'tagshdr', get_string('tags', 'tag')); } $mform->addElement('tags', 'tags', get_string('tags'), array('itemtype' => 'wiki_pages', 'component' => 'mod_wiki')); $buttongroup = array(); $buttongroup[] = $mform->createElement('submit', 'editoption', get_string('save', 'wiki'), array('id' => 'save')); $buttongroup[] = $mform->createElement('submit', 'editoption', get_string('preview'), array('id' => 'preview')); $buttongroup[] = $mform->createElement('submit', 'editoption', get_string('cancel'), array('id' => 'cancel')); $mform->addGroup($buttongroup, 'buttonar', '', array(' '), false); $mform->closeHeaderBefore('buttonar'); }
/** * Form definition. */ function definition() { global $CFG, $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']; $returnurl = $this->_customdata['returnurl']; $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('hidden', 'returnurl', null); $mform->setType('returnurl', PARAM_LOCALURL); $mform->setConstant('returnurl', $returnurl); $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, MUST_EXIST, true)->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 (!empty($course->id)) { if (!has_capability('moodle/course:visibility', $coursecontext)) { $mform->hardFreeze('visible'); $mform->setConstant('visible', $course->visible); } } else { if (!guess_if_creator_will_have_course_capability('moodle/course:visibility', $categorycontext)) { $mform->hardFreeze('visible'); $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('date_selector', 'enddate', get_string('enddate'), array('optional' => true)); $mform->addHelpButton('enddate', 'enddate'); $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); // Multi-Calendar Support - see MDL-18375. $calendartypes = \core_calendar\type_factory::get_list_of_calendar_types(); // We do not want to show this option unless there is more than one calendar type to display. if (count($calendartypes) > 1) { $calendars = array(); $calendars[''] = get_string('forceno'); $calendars += $calendartypes; $mform->addElement('select', 'calendartype', get_string('forcecalendartype', 'calendar'), $calendars); } $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('groupsettingsheader', '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); if (empty($course->id) && guess_if_creator_will_have_course_capability('moodle/course:renameroles', $categorycontext) || !empty($course->id) && has_capability('moodle/course:renameroles', $coursecontext)) { // 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); } } } if (core_tag_tag::is_enabled('core', 'course') && (empty($course->id) && guess_if_creator_will_have_course_capability('moodle/course:tag', $categorycontext) || !empty($course->id) && has_capability('moodle/course:tag', $coursecontext))) { $mform->addElement('header', 'tagshdr', get_string('tags', 'tag')); $mform->addElement('tags', 'tags', get_string('tags'), array('itemtype' => 'course', 'component' => 'core')); } // When two elements we need a group. $buttonarray = array(); $classarray = array('class' => 'form-submit'); if ($returnto !== 0) { $buttonarray[] =& $mform->createElement('submit', 'saveandreturn', get_string('savechangesandreturn'), $classarray); } $buttonarray[] =& $mform->createElement('submit', 'saveanddisplay', get_string('savechangesanddisplay'), $classarray); $buttonarray[] =& $mform->createElement('cancel'); $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); $mform->closeHeaderBefore('buttonar'); $mform->addElement('hidden', 'id', null); $mform->setType('id', PARAM_INT); // Finally set the current form data $this->set_data($course); }
/** * Import all the question tags * * @param object $qo the question data that is being constructed. * @param array $questionxml The xml representing the question. * @return array of objects representing the tags in the file. */ public function import_question_tags($qo, $questionxml) { global $CFG; if (core_tag_tag::is_enabled('core_question', 'question') && array_key_exists('tags', $questionxml['#']) && !empty($questionxml['#']['tags'][0]['#']['tag'])) { $qo->tags = array(); foreach ($questionxml['#']['tags'][0]['#']['tag'] as $tagdata) { $qo->tags[] = $this->getpath($tagdata, array('#', 'text', 0, '#'), '', true); } } }
/** * Prints the tag search results * * @deprecated since 3.1 * @param string $query text that tag names will be matched against * @param int $page current page * @param int $perpage nr of users displayed per page * @param bool $return if true return html string * @return string|null a HTML string or null if this function does the output */ function tag_print_search_results($query, $page, $perpage, $return = false) { global $CFG, $USER, $OUTPUT; debugging('Function tag_print_search_results() is deprecated without replacement. ' . 'In /tag/search.php the search results are printed using the core_tag/tagcloud template.', DEBUG_DEVELOPER); $query = clean_param($query, PARAM_TAG); $count = count(tag_find_tags($query, false)); $tags = array(); if ($found_tags = tag_find_tags($query, true, $page * $perpage, $perpage)) { $tags = array_values($found_tags); } $baseurl = $CFG->wwwroot . '/tag/search.php?query=' . rawurlencode($query); $output = ''; // link "Add $query to my interests" $addtaglink = ''; if (core_tag_tag::is_enabled('core', 'user') && !core_tag_tag::is_item_tagged_with('core', 'user', $USER->id, $query)) { $addtaglink = html_writer::link(new moodle_url('/tag/user.php', array('action' => 'addinterest', 'sesskey' => sesskey(), 'tag' => $query)), get_string('addtagtomyinterests', 'tag', s($query))); } if (!empty($tags)) { // there are results to display!! $output .= $OUTPUT->heading(get_string('searchresultsfor', 'tag', htmlspecialchars($query)) . " : {$count}", 3, 'main'); //print a link "Add $query to my interests" if (!empty($addtaglink)) { $output .= $OUTPUT->box($addtaglink, 'box', 'tag-management-box'); } $nr_of_lis_per_ul = 6; $nr_of_uls = ceil(sizeof($tags) / $nr_of_lis_per_ul); $output .= '<ul id="tag-search-results">'; for ($i = 0; $i < $nr_of_uls; $i++) { foreach (array_slice($tags, $i * $nr_of_lis_per_ul, $nr_of_lis_per_ul) as $tag) { $output .= '<li>'; $tag_link = html_writer::link(core_tag_tag::make_url($tag->tagcollid, $tag->rawname), core_tag_tag::make_display_name($tag)); $output .= $tag_link; $output .= '</li>'; } } $output .= '</ul>'; $output .= '<div> </div>'; // <-- small layout hack in order to look good in Firefox $output .= $OUTPUT->paging_bar($count, $page, $perpage, $baseurl); } else { //no results were found!! $output .= $OUTPUT->heading(get_string('noresultsfor', 'tag', htmlspecialchars($query)), 3, 'main'); //print a link "Add $query to my interests" if (!empty($addtaglink)) { $output .= $OUTPUT->box($addtaglink, 'box', 'tag-management-box'); } } if ($return) { return $output; } else { echo $output; } }
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once "../config.php"; require_once $CFG->dirroot . '/course/tags_form.php'; $id = required_param('id', PARAM_INT); // Course id. $returnurl = optional_param('return', null, PARAM_LOCALURL); $course = get_course($id); require_login(); // Check capabilities but do not call require_login($course) - the user does not have to be enrolled. $context = context_course::instance($course->id); if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) { print_error('coursehidden', '', $CFG->wwwroot . '/'); } require_capability('moodle/course:tag', $context); if (!core_tag_tag::is_enabled('core', 'course')) { print_error('tagsaredisabled', 'tag'); } $PAGE->set_course($course); $PAGE->set_pagelayout('incourse'); $PAGE->set_url('/course/tags.php', array('id' => $course->id)); $PAGE->set_title(get_string('coursetags', 'tag')); $PAGE->set_heading($course->fullname); $form = new coursetags_form(); $data = array('id' => $course->id, 'tags' => core_tag_tag::get_item_tags_array('core', 'course', $course->id)); $form->set_data($data); $redirecturl = $returnurl ? new moodle_url($returnurl) : course_get_url($course); if ($form->is_cancelled()) { redirect($redirecturl); } else { if ($data = $form->get_data()) {
/** * Powerful function that is used by edit and editadvanced to add common form elements/rules/etc. * * @param moodleform $mform * @param array $editoroptions * @param array $filemanageroptions * @param stdClass $user */ function useredit_shared_definition(&$mform, $editoroptions, $filemanageroptions, $user) { global $CFG, $USER, $DB; if ($user->id > 0) { useredit_load_preferences($user, false); } $strrequired = get_string('required'); $stringman = get_string_manager(); // Add the necessary names. foreach (useredit_get_required_name_fields() as $fullname) { $mform->addElement('text', $fullname, get_string($fullname), 'maxlength="100" size="30"'); if ($stringman->string_exists('missing' . $fullname, 'core')) { $strmissingfield = get_string('missing' . $fullname, 'core'); } else { $strmissingfield = $strrequired; } $mform->addRule($fullname, $strmissingfield, 'required', null, 'client'); $mform->setType($fullname, PARAM_NOTAGS); } $enabledusernamefields = useredit_get_enabled_name_fields(); // Add the enabled additional name fields. foreach ($enabledusernamefields as $addname) { $mform->addElement('text', $addname, get_string($addname), 'maxlength="100" size="30"'); $mform->setType($addname, PARAM_NOTAGS); } // Do not show email field if change confirmation is pending. if ($user->id > 0 and !empty($CFG->emailchangeconfirmation) and !empty($user->preference_newemail)) { $notice = get_string('emailchangepending', 'auth', $user); $notice .= '<br /><a href="edit.php?cancelemailchange=1&id=' . $user->id . '">' . get_string('emailchangecancel', 'auth') . '</a>'; $mform->addElement('static', 'emailpending', get_string('email'), $notice); } else { $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"'); $mform->addRule('email', $strrequired, 'required', null, 'client'); $mform->setType('email', PARAM_RAW_TRIMMED); } $choices = array(); $choices['0'] = get_string('emaildisplayno'); $choices['1'] = get_string('emaildisplayyes'); $choices['2'] = get_string('emaildisplaycourse'); $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices); $mform->setDefault('maildisplay', core_user::get_property_default('maildisplay')); $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="21"'); $mform->setType('city', PARAM_TEXT); if (!empty($CFG->defaultcity)) { $mform->setDefault('city', $CFG->defaultcity); } $choices = get_string_manager()->get_list_of_countries(); $choices = array('' => get_string('selectacountry') . '...') + $choices; $mform->addElement('select', 'country', get_string('selectacountry'), $choices); if (!empty($CFG->country)) { $mform->setDefault('country', core_user::get_property_default('country')); } if (isset($CFG->forcetimezone) and $CFG->forcetimezone != 99) { $choices = core_date::get_list_of_timezones($CFG->forcetimezone); $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]); $mform->addElement('hidden', 'timezone'); $mform->setType('timezone', core_user::get_property_type('timezone')); } else { $choices = core_date::get_list_of_timezones($user->timezone, true); $mform->addElement('select', 'timezone', get_string('timezone'), $choices); } if (!empty($CFG->allowuserthemes)) { $choices = array(); $choices[''] = get_string('default'); $themes = get_list_of_themes(); foreach ($themes as $key => $theme) { if (empty($theme->hidefromselector)) { $choices[$key] = get_string('pluginname', 'theme_' . $theme->name); } } $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices); } $mform->addElement('editor', 'description_editor', get_string('userdescription'), null, $editoroptions); $mform->setType('description_editor', PARAM_CLEANHTML); $mform->addHelpButton('description_editor', 'userdescription'); if (empty($USER->newadminuser)) { $mform->addElement('header', 'moodle_picture', get_string('pictureofuser')); $mform->setExpanded('moodle_picture', true); if (!empty($CFG->enablegravatar)) { $mform->addElement('html', html_writer::tag('p', get_string('gravatarenabled'))); } $mform->addElement('static', 'currentpicture', get_string('currentpicture')); $mform->addElement('checkbox', 'deletepicture', get_string('delete')); $mform->setDefault('deletepicture', 0); $mform->addElement('filemanager', 'imagefile', get_string('newpicture'), '', $filemanageroptions); $mform->addHelpButton('imagefile', 'newpicture'); $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"'); $mform->setType('imagealt', PARAM_TEXT); } // Display user name fields that are not currenlty enabled here if there are any. $disabledusernamefields = useredit_get_disabled_name_fields($enabledusernamefields); if (count($disabledusernamefields) > 0) { $mform->addElement('header', 'moodle_additional_names', get_string('additionalnames')); foreach ($disabledusernamefields as $allname) { $mform->addElement('text', $allname, get_string($allname), 'maxlength="100" size="30"'); $mform->setType($allname, PARAM_NOTAGS); } } if (core_tag_tag::is_enabled('core', 'user') and empty($USER->newadminuser)) { $mform->addElement('header', 'moodle_interests', get_string('interests')); $mform->addElement('tags', 'interests', get_string('interestslist'), array('itemtype' => 'user', 'component' => 'core')); $mform->addHelpButton('interests', 'interestslist'); } // Moodle optional fields. $mform->addElement('header', 'moodle_optional', get_string('optional', 'form')); $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"'); $mform->setType('url', core_user::get_property_type('url')); $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"'); $mform->setType('icq', core_user::get_property_type('icq')); $mform->setForceLtr('icq'); $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"'); $mform->setType('skype', core_user::get_property_type('skype')); $mform->setForceLtr('skype'); $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"'); $mform->setType('aim', core_user::get_property_type('aim')); $mform->setForceLtr('aim'); $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"'); $mform->setType('yahoo', core_user::get_property_type('yahoo')); $mform->setForceLtr('yahoo'); $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"'); $mform->setType('msn', core_user::get_property_type('msn')); $mform->setForceLtr('msn'); $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="255" size="25"'); $mform->setType('idnumber', core_user::get_property_type('idnumber')); $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="255" size="25"'); $mform->setType('institution', core_user::get_property_type('institution')); $mform->addElement('text', 'department', get_string('department'), 'maxlength="255" size="25"'); $mform->setType('department', core_user::get_property_type('department')); $mform->addElement('text', 'phone1', get_string('phone1'), 'maxlength="20" size="25"'); $mform->setType('phone1', core_user::get_property_type('phone1')); $mform->setForceLtr('phone1'); $mform->addElement('text', 'phone2', get_string('phone2'), 'maxlength="20" size="25"'); $mform->setType('phone2', core_user::get_property_type('phone2')); $mform->setForceLtr('phone2'); $mform->addElement('text', 'address', get_string('address'), 'maxlength="255" size="25"'); $mform->setType('address', core_user::get_property_type('address')); }
protected function process_wiki_tag($data) { global $CFG, $DB; $data = (object) $data; $oldid = $data->id; if (!core_tag_tag::is_enabled('mod_wiki', 'wiki_pages')) { // Tags disabled in server, nothing to process. return; } $tag = $data->rawname; $itemid = $this->get_new_parentid('wiki_page'); $wikiid = $this->get_new_parentid('wiki'); $context = context_module::instance($this->task->get_moduleid()); core_tag_tag::add_item_tag('mod_wiki', 'wiki_pages', $itemid, $context, $tag); }