Ejemplo n.º 1
0
 public function execute()
 {
     global $CFG, $DB;
     $roleid = $this->arguments[0];
     $filearg = $this->arguments[1];
     if (substr($filearg, 0, 1) == '/') {
         // Absolute file.
         $filename = $filearg;
     } else {
         // Relative to current directory.
         $filename = $this->cwd . DIRECTORY_SEPARATOR . $filearg;
     }
     $fh = fopen($filename, 'r');
     $roledefinition = fread($fh, filesize($filename));
     if ($roledefinition) {
         $systemcontext = \context_system::instance();
         $options = array('shortname' => 1, 'name' => 1, 'description' => 1, 'permissions' => 1, 'archetype' => 1, 'contextlevels' => 1, 'allowassign' => 1, 'allowoverride' => 1, 'allowswitch' => 1, 'permissions' => 1);
         $definitiontable = new \core_role_define_role_table_advanced($systemcontext, $roleid);
         // Add all permissions from definition file to $_POST, otherwise, they won't be applied.
         $info = \core_role_preset::parse_preset($roledefinition);
         $_POST = $info['permissions'];
         $definitiontable->read_submitted_permissions();
         $definitiontable->force_preset($roledefinition, $options);
         $definitiontable->save_changes();
     }
 }
Ejemplo n.º 2
0
/**
 * Upgrade the calendar_month block
 * @param int $oldversion
 * @param object $block
 */
function xmldb_block_calendar_month_upgrade($oldversion, $block)
{
    global $DB;
    if ($oldversion < 2014062600) {
        // Add this block the default blocks on /my.
        $blockname = 'calendar_month';
        // Do not try to add the block if we cannot find the default my_pages entry.
        // Private => 1 refers to MY_PAGE_PRIVATE.
        if ($systempage = $DB->get_record('my_pages', array('userid' => null, 'private' => 1))) {
            $page = new moodle_page();
            $page->set_context(context_system::instance());
            // Check to see if this block is already on the default /my page.
            $criteria = array('blockname' => $blockname, 'parentcontextid' => $page->context->id, 'pagetypepattern' => 'my-index', 'subpagepattern' => $systempage->id);
            if (!$DB->record_exists('block_instances', $criteria)) {
                // Add the block to the default /my.
                $page->blocks->add_region(BLOCK_POS_RIGHT);
                $page->blocks->add_block($blockname, BLOCK_POS_RIGHT, 0, false, 'my-index', $systempage->id);
            }
        }
        upgrade_block_savepoint(true, 2014062600, $blockname);
    }
    // Moodle v2.8.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.9.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v3.0.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v3.1.0 release upgrade line.
    // Put any upgrade step following this.
    return true;
}
Ejemplo n.º 3
0
 public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig)
 {
     global $CFG, $USER, $DB, $OUTPUT, $PAGE;
     // In case settings.php wants to refer to them.
     $ADMIN = $adminroot;
     // May be used in settings.php.
     $plugininfo = $this;
     // Also can be used inside settings.php.
     $qtype = $this;
     // Also can be used inside settings.php.
     if (!$this->is_installed_and_upgraded()) {
         return;
     }
     $section = $this->get_settings_section_name();
     $settings = null;
     $systemcontext = \context_system::instance();
     if ($hassiteconfig && file_exists($this->full_path('settings.php'))) {
         $settings = new admin_settingpage($section, $this->displayname, 'moodle/site:config', $this->is_enabled() === false);
         include $this->full_path('settings.php');
         // This may also set $settings to null.
     }
     if ($settings) {
         $ADMIN->add($parentnodename, $settings);
     }
 }
 public function get_csswww()
 {
     global $CFG;
     if (!$this->theme_essential_lte_ie9()) {
         if (right_to_left()) {
             $moodlecss = 'essential-rtl.css';
         } else {
             $moodlecss = 'essential.css';
         }
         $syscontext = context_system::instance();
         $itemid = theme_get_revision();
         $url = moodle_url::make_file_url("{$CFG->wwwroot}/pluginfile.php", "/{$syscontext->id}/theme_essential/style/{$itemid}/{$moodlecss}");
         $url = preg_replace('|^https?://|i', '//', $url->out(false));
         return '<link rel="stylesheet" href="' . $url . '">';
     } else {
         if (right_to_left()) {
             $moodlecssone = 'essential-rtl_ie9-blessed1.css';
             $moodlecsstwo = 'essential-rtl_ie9.css';
         } else {
             $moodlecssone = 'essential_ie9-blessed1.css';
             $moodlecsstwo = 'essential_ie9.css';
         }
         $syscontext = context_system::instance();
         $itemid = theme_get_revision();
         $urlone = moodle_url::make_file_url("{$CFG->wwwroot}/pluginfile.php", "/{$syscontext->id}/theme_essential/style/{$itemid}/{$moodlecssone}");
         $urlone = preg_replace('|^https?://|i', '//', $urlone->out(false));
         $urltwo = moodle_url::make_file_url("{$CFG->wwwroot}/pluginfile.php", "/{$syscontext->id}/theme_essential/style/{$itemid}/{$moodlecsstwo}");
         $urltwo = preg_replace('|^https?://|i', '//', $urltwo->out(false));
         return '<link rel="stylesheet" href="' . $urlone . '"><link rel="stylesheet" href="' . $urltwo . '">';
     }
 }
Ejemplo n.º 5
0
/**
 * EditPDF upgrade code
 * @param int $oldversion
 * @return bool
 */
function xmldb_assignfeedback_editpdf_upgrade($oldversion)
{
    global $CFG;
    if ($oldversion < 2013110800) {
        // Check that no stamps where uploaded.
        $fs = get_file_storage();
        $stamps = $fs->get_area_files(context_system::instance()->id, 'assignfeedback_editpdf', 'stamps', 0, "filename", false);
        // Add default stamps.
        if (empty($stamps)) {
            // List of default stamps.
            $defaultstamps = array('smile.png', 'sad.png', 'tick.png', 'cross.png');
            // Stamp file object.
            $filerecord = new stdClass();
            $filerecord->component = 'assignfeedback_editpdf';
            $filerecord->contextid = context_system::instance()->id;
            $filerecord->userid = get_admin()->id;
            $filerecord->filearea = 'stamps';
            $filerecord->filepath = '/';
            $filerecord->itemid = 0;
            // Add all default stamps.
            foreach ($defaultstamps as $stamp) {
                $filerecord->filename = $stamp;
                $fs->create_file_from_pathname($filerecord, $CFG->dirroot . '/mod/assign/feedback/editpdf/pix/' . $filerecord->filename);
            }
        }
        upgrade_plugin_savepoint(true, 2013110800, 'assignfeedback', 'editpdf');
    }
    // Moodle v2.6.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.7.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.8.0 release upgrade line.
    // Put any upgrade step following this.
    return true;
}
Ejemplo n.º 6
0
 /**
  * Constructor
  *
  * @param string $elementName (optional) name of the editor
  * @param string $elementLabel (optional) editor label
  * @param array $attributes (optional) Either a typical HTML attribute string
  *              or an associative array
  * @param array $options set of options to initalize filepicker
  */
 function MoodleQuickForm_editor($elementName = null, $elementLabel = null, $attributes = null, $options = null)
 {
     global $CFG, $PAGE;
     $options = (array) $options;
     foreach ($options as $name => $value) {
         if (array_key_exists($name, $this->_options)) {
             $this->_options[$name] = $value;
         }
     }
     if (!empty($options['maxbytes'])) {
         $this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']);
     }
     if (!$this->_options['context']) {
         // trying to set context to the current page context to make legacy files show in filepicker (e.g. forum post)
         if (!empty($PAGE->context->id)) {
             $this->_options['context'] = $PAGE->context;
         } else {
             $this->_options['context'] = context_system::instance();
         }
     }
     $this->_options['trusted'] = trusttext_trusted($this->_options['context']);
     parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
     // Note: for some reason the code using this setting does not like bools.
     $this->_options['subdirs'] = (int) ($this->_options['subdirs'] == 1);
     editors_head_setup();
 }
Ejemplo n.º 7
0
 /**
  * Initialise required event data properties.
  */
 protected function init()
 {
     $this->context = \context_system::instance();
     $this->data['objecttable'] = 'user';
     $this->data['crud'] = 'r';
     $this->data['edulevel'] = self::LEVEL_OTHER;
 }
 function get_content()
 {
     if ($this->content !== NULL) {
         return $this->content;
     }
     $context = context_system::instance();
     $this->content = new stdClass();
     $this->content->footer = '';
     $this->content->text = '';
     $content = array();
     $canview = has_capability('block/enrol_token_manager:viewtokens', $context) === true;
     $cancreate = has_capability('block/enrol_token_manager:createtokens', $context) === true;
     $canrevoke = has_capability('block/enrol_token_manager:revoketokens', $context) === true;
     // view tokens link
     if ($canview) {
         $content[] = html_writer::link(new moodle_url('/blocks/enrol_token_manager/viewrevoke_tokens.php'), get_string('linkTextViewTokens', 'block_enrol_token_manager'));
     }
     // create tokens link
     if ($cancreate) {
         $content[] = html_writer::link(new moodle_url('/blocks/enrol_token_manager/create_tokens.php'), get_string('linkTextCreateTokens', 'block_enrol_token_manager'));
     }
     // revoke tokens link
     if ($canrevoke) {
         $content[] = html_writer::link(new moodle_url('/blocks/enrol_token_manager/viewrevoke_tokens.php'), get_string('linkTextRevokeTokens', 'block_enrol_token_manager'));
     }
     if ($cancreate || $canrevoke || $canview) {
         $this->content->text = html_writer::alist($content);
     }
     return $this->content;
 }
Ejemplo n.º 9
0
 protected function specific_definition($mform)
 {
     global $CFG;
     // Fields for editing HTML block title and contents.
     $mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
     $mform->addElement('text', 'config_title', get_string('configtitle', 'block_tags'));
     $mform->setType('config_title', PARAM_TEXT);
     $mform->setDefault('config_title', get_string('pluginname', 'block_tags'));
     $this->add_collection_selector($mform);
     $numberoftags = array();
     for ($i = 1; $i <= 200; $i++) {
         $numberoftags[$i] = $i;
     }
     $mform->addElement('select', 'config_numberoftags', get_string('numberoftags', 'blog'), $numberoftags);
     $mform->setDefault('config_numberoftags', 80);
     $defaults = array('official' => get_string('officialonly', 'block_tags'), '' => get_string('anytype', 'block_tags'));
     $mform->addElement('select', 'config_tagtype', get_string('defaultdisplay', 'block_tags'), $defaults);
     $mform->setDefault('config_tagtype', '');
     $defaults = array(0 => context_system::instance()->get_context_name());
     $parentcontext = context::instance_by_id($this->block->instance->parentcontextid);
     if ($parentcontext->contextlevel > CONTEXT_COURSE) {
         $coursecontext = $parentcontext->get_course_context();
         $defaults[$coursecontext->id] = $coursecontext->get_context_name();
     }
     if ($parentcontext->contextlevel != CONTEXT_SYSTEM) {
         $defaults[$parentcontext->id] = $parentcontext->get_context_name();
     }
     $mform->addElement('select', 'config_ctx', get_string('taggeditemscontext', 'block_tags'), $defaults);
     $mform->addHelpButton('config_ctx', 'taggeditemscontext', 'block_tags');
     $mform->setDefault('config_ctx', 0);
     $mform->addElement('advcheckbox', 'config_rec', get_string('recursivecontext', 'block_tags'));
     $mform->addHelpButton('config_rec', 'recursivecontext', 'block_tags');
     $mform->setDefault('config_rec', 1);
 }
 public function definition()
 {
     global $CFG, $PAGE, $DB;
     $context = context_system::instance();
     $mform =& $this->_form;
     $strrequired = get_string('required');
     $mform->addElement('hidden', 'id', $this->classroomid);
     $mform->addElement('hidden', 'companyid', $this->companyid);
     $mform->setType('id', PARAM_INT);
     $mform->setType('companyid', PARAM_INT);
     // Then show the fields about where this block appears.
     $mform->addElement('header', 'header', get_string('classroom', 'block_iomad_company_admin'));
     $mform->addElement('text', 'name', get_string('classroom_name', 'block_iomad_company_admin'), 'maxlength="100" size="50"');
     $mform->setType('name', PARAM_NOTAGS);
     $mform->addRule('name', $strrequired, 'required', null, 'client');
     $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="50"');
     $mform->addRule('address', $strrequired, 'required', null, 'client');
     $mform->setType('address', PARAM_NOTAGS);
     $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="50"');
     $mform->addRule('city', $strrequired, 'required', null, 'client');
     $mform->setType('city', PARAM_NOTAGS);
     $mform->addElement('text', 'postcode', get_string('postcode', 'block_iomad_commerce'), 'maxlength="20" size="20"');
     $mform->addRule('postcode', $strrequired, 'required', null, 'client');
     $mform->setType('postcode', PARAM_NOTAGS);
     $choices = get_string_manager()->get_list_of_countries();
     $choices = array('' => get_string('selectacountry') . '...') + $choices;
     $mform->addElement('select', 'country', get_string('selectacountry'), $choices);
     $mform->addRule('country', $strrequired, 'required', null, 'client');
     $mform->addElement('text', 'capacity', get_string('classroom_capacity', 'block_iomad_company_admin'));
     $mform->addRule('capacity', $strrequired, 'required', null, 'client');
     $mform->setType('capacity', PARAM_INTEGER);
     $this->add_action_buttons();
 }
 /**
  * Init method.
  */
 protected function init()
 {
     $this->data['objecttable'] = 'lti';
     $this->data['crud'] = 'r';
     $this->data['level'] = self::LEVEL_OTHER;
     $this->data['context'] = \context_system::instance();
 }
Ejemplo n.º 12
0
 function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     $syscontext = context_system::instance();
     $actions = array(0 => get_string('choose') . '...');
     if (has_capability('moodle/user:update', $syscontext)) {
         $actions[1] = get_string('confirm');
     }
     if (has_capability('moodle/site:readallmessages', $syscontext) && !empty($CFG->messaging)) {
         $actions[2] = get_string('messageselectadd');
     }
     if (has_capability('moodle/user:delete', $syscontext)) {
         $actions[3] = get_string('delete');
     }
     $actions[4] = get_string('displayonpage');
     if (has_capability('moodle/user:update', $syscontext)) {
         $actions[5] = get_string('download', 'admin');
     }
     if (has_capability('moodle/role:assign', $syscontext)) {
         //TODO: MDL-24064
         //$actions[6] = get_string('enrolmultipleusers', 'admin');
     }
     if (has_capability('moodle/user:update', $syscontext)) {
         $actions[7] = get_string('forcepasswordchange');
     }
     if (has_capability('moodle/cohort:assign', $syscontext)) {
         $actions[8] = get_string('bulkadd', 'core_cohort');
     }
     $objs = array();
     $objs[] =& $mform->createElement('select', 'action', null, $actions);
     $objs[] =& $mform->createElement('submit', 'doaction', get_string('go'));
     $mform->addElement('group', 'actionsgrp', get_string('withselectedusers'), $objs, ' ', false);
 }
Ejemplo n.º 13
0
/**
 * Obtiene el rol del usuario logeado.
 * @return string Rol {'Alumno', 'Profesor', 'Decano', 'Rector'}
 */
function get_rol()
{
    global $USER, $DB, $SESSION;
    if (isset($SESSION->rol)) {
        return $SESSION->rol;
        exit;
    }
    $context = context_system::instance();
    $rolesportada = get_user_roles($context, false);
    foreach ($rolesportada as $rol) {
        if ($rol->name == 'Rector') {
            $SESSION->rol = 'Rector';
            return 'Rector';
        }
    }
    $facultades = $DB->get_records_sql("SELECT DISTINCT {course}.category\n\t\t\t\t\t\t\t\t\t\tFROM {course} INNER JOIN {context} ON ({course}.category = {context}.instanceid)\n\t\t\t\t\t\t\t\t\t\tINNER JOIN {role_assignments} ON ({context}.id = {role_assignments}.contextid)\n\t\t\t\t\t\t\t\t\t\tINNER JOIN {role} ON ({role_assignments}.roleid = {role}.id)\n\t\t\t\t\t\t\t\t\t\tWHERE {role}.name = 'Decano' AND {role_assignments}.userid = " . $USER->id);
    if (!empty($facultades)) {
        $SESSION->rol = 'Decano';
        $SESSION->facultades = array_keys($facultades);
        return 'Decano';
    }
    $profesores = $DB->get_records_sql("SELECT DISTINCT id_profesor FROM {local_toolbox_score}");
    if (array_key_exists($USER->id, $profesores)) {
        $SESSION->rol = 'Profesor';
        return 'Profesor';
    }
    $SESSION->rol = 'Alumno';
    return 'Alumno';
}
Ejemplo n.º 14
0
 function get_content()
 {
     global $CFG, $OUTPUT;
     if (empty($this->instance)) {
         $this->content = '';
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     // user/index.php expect course context, so get one if page has module context.
     $currentcontext = $this->page->context->get_course_context(false);
     if (empty($currentcontext)) {
         $this->content = '';
         return $this->content;
     } else {
         if ($this->page->course->id == SITEID) {
             if (!has_capability('moodle/site:viewparticipants', context_system::instance())) {
                 $this->content = '';
                 return $this->content;
             }
         } else {
             if (!has_capability('moodle/course:viewparticipants', $currentcontext)) {
                 $this->content = '';
                 return $this->content;
             }
         }
     }
     $icon = '<img src="' . $OUTPUT->pix_url('i/users') . '" class="icon" alt="" />&nbsp;';
     $this->content->items[] = '<a title="' . get_string('listofallpeople') . '" href="' . $CFG->wwwroot . '/user/index.php?contextid=' . $currentcontext->id . '">' . $icon . get_string('participants') . '</a>';
     return $this->content;
 }
Ejemplo n.º 15
0
 public function __DisplayBadges($uid, $callFor, $bid)
 {
     global $CFG, $DB;
     $systemcontext = context_system::instance();
     $response = new CliniqueServiceResponce();
     $param_total = array('user_id' => $uid);
     $params = array('user_badge_id' => $bid, 'user_id' => $uid);
     if ($callFor == 'getBadges') {
         $badgedetails = array_values($DB->get_records_sql('SELECT id,badge_name,badge_value FROM {badge} ORDER BY badge_value'));
         //  $users_badges = array_values($DB->get_records_sql('SELECT ub.user_badge_id,ub.user_badge_value,b.badge_name FROM {badge_user} ub,{badge} b WHERE ub.user_id=? AND ub.user_badge_id=b.id', $param_total));
         $users_badges = array_values($DB->get_records_sql('SELECT ub.id,ub.user_badge_id,b.badge_value,b.badge_name FROM {badge_user} ub INNER JOIN {badge} b WHERE ub.user_id=? AND ub.user_badge_id=b.id;', $param_total));
         if (!empty($uid) && !empty($bid)) {
             //$userbadgecnt = count($badge_userdetails);
             // if ($userbadgecnt == 0) {
             $DB->insert_record('badge_user', $params);
             //}
         }
         $badges = @array_merge(array("badges" => $badgedetails, "userbadges" => $users_badges));
         if (!empty($badges)) {
             $response->response(false, 'done', $badges);
         } else {
             $response->response(true, 'no_records', $badges);
         }
     }
 }
Ejemplo n.º 16
0
 public function __construct()
 {
     // Use this context for filtering.
     $this->context = context_system::instance();
     // Define FORMAT_HTML as only one filtering in DB.
     set_config('formats', implode(',', array(FORMAT_HTML)), get_class($this));
 }
Ejemplo n.º 17
0
 /**
  * block contents
  *
  * @return object
  */
 public function get_content()
 {
     global $CFG, $COURSE, $USER, $PAGE;
     if ($this->content !== NULL) {
         return $this->content;
     }
     if ($COURSE->id == SITEID) {
         $context = context_system::instance();
     } else {
         $context = context_course::instance($COURSE->id);
     }
     $this->content = new stdClass();
     $this->content->text = '';
     $this->content->footer = '';
     $mymoodle = 0;
     if (strcmp('my-index', $PAGE->pagetype) == 0) {
         $mymoodle = 1;
     }
     if (has_capability('block/enrolsurvey:edit', $context)) {
         $editpage = get_string('editpage', 'block_enrolsurvey');
         $this->content->text .= "<a\nhref=\"{$CFG->wwwroot}/blocks/enrolsurvey/edit_survey.php?id={$this->instance->id}&courseid={$COURSE->id}&mymoodle={$mymoodle}\">{$editpage}</a><br\n/>";
     }
     if (has_capability('block/enrolsurvey:take', $context) && cm_get_crlmuserid($USER->id) !== false) {
         // MUST have ELIS user record to take survey!
         if (!empty($this->config->force_user) && !is_survey_taken($USER->id, $this->instance->id)) {
             redirect("{$CFG->wwwroot}/blocks/enrolsurvey/survey.php?id={$this->instance->id}");
         }
         $takepage = get_string('takepage', 'block_enrolsurvey');
         $this->content->text .= "<a\nhref=\"{$CFG->wwwroot}/blocks/enrolsurvey/survey.php?id={$this->instance->id}&courseid={$COURSE->id}&mymoodle={$mymoodle}\">{$takepage}</a><br\n/>";
     }
     // $this->content->text .= "<br/> crontime = {$this->config->cron_time}";
     return $this->content;
 }
Ejemplo n.º 18
0
 /**
  * Validate that redirection from My Moodle does not happen for admins
  */
 public function test_mymoodleredirectreturnsfalseforadmin()
 {
     global $CFG, $USER, $DB;
     require_once $CFG->dirroot . '/user/lib.php';
     // Make sure we're not a guest.
     set_config('siteguest', '');
     // Obtain the system context.
     $syscontext = context_system::instance();
     // Set up the current user global.
     $user = new stdClass();
     $user->username = "******";
     $userid = user_create_user($user);
     $USER = $DB->get_record('user', array('id' => $userid));
     // Enable functionaltiy.
     pm_set_config('mymoodle_redirect', 1);
     elis::$config = new elis_config();
     // Give the admin sufficient permissions.
     $roleid = create_role('adminrole', 'adminrole', 'adminrole');
     assign_capability('moodle/site:config', CAP_ALLOW, $roleid, $syscontext->id);
     role_assign($roleid, $USER->id, $syscontext->id);
     // Validate that redirection does not happen for admins.
     $result = pm_mymoodle_redirect();
     // Clear out cached permissions data so we don't affect other tests.
     accesslib_clear_all_caches(true);
     $this->assertFalse($result);
 }
Ejemplo n.º 19
0
 /**
  * Test update question flag
  */
 public function test_core_question_update_flag()
 {
     $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
     // Create a question category.
     $cat = $questiongenerator->create_question_category();
     $quba = question_engine::make_questions_usage_by_activity('core_question_update_flag', context_system::instance());
     $quba->set_preferred_behaviour('deferredfeedback');
     $questiondata = $questiongenerator->create_question('numerical', null, array('category' => $cat->id));
     $question = question_bank::load_question($questiondata->id);
     $slot = $quba->add_question($question);
     $qa = $quba->get_question_attempt($slot);
     self::setUser($this->student);
     $quba->start_all_questions();
     question_engine::save_questions_usage_by_activity($quba);
     $qubaid = $quba->get_id();
     $questionid = $question->id;
     $qaid = $qa->get_database_id();
     $checksum = md5($qubaid . "_" . $this->student->secret . "_" . $questionid . "_" . $qaid . "_" . $slot);
     $flag = core_question_external::update_flag($qubaid, $questionid, $qaid, $slot, $checksum, true);
     $this->assertTrue($flag['status']);
     // Test invalid checksum.
     try {
         // Using random_string to force failing.
         $checksum = md5($qubaid . "_" . random_string(11) . "_" . $questionid . "_" . $qaid . "_" . $slot);
         core_question_external::update_flag($qubaid, $questionid, $qaid, $slot, $checksum, true);
         $this->fail('Exception expected due to invalid checksum.');
     } catch (moodle_exception $e) {
         $this->assertEquals('errorsavingflags', $e->errorcode);
     }
 }
Ejemplo n.º 20
0
 /**
  * Set basic event properties.
  */
 protected function init()
 {
     $this->context = \context_system::instance();
     $this->data['objecttable'] = 'post';
     $this->data['crud'] = 'u';
     $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
 }
Ejemplo n.º 21
0
 /**
  * Export this data so it can be used as the context for a mustache template.
  *
  * @param renderer_base $output
  * @return stdClass
  */
 public function export_for_template(renderer_base $output)
 {
     global $CFG;
     require_once $CFG->libdir . '/externallib.php';
     $r = new stdClass();
     $r->id = (int) $this->record->id;
     $r->rawname = clean_param($this->record->rawname, PARAM_TAG);
     $r->name = clean_param($this->record->name, PARAM_TAG);
     $format = clean_param($this->record->descriptionformat, PARAM_INT);
     list($r->description, $r->descriptionformat) = external_format_text($this->record->description, $format, \context_system::instance()->id, 'core', 'tag', $r->id);
     $r->flag = clean_param($this->record->flag, PARAM_INT);
     if (isset($this->record->official)) {
         $r->official = clean_param($this->record->official, PARAM_INT);
     } else {
         $r->official = $this->record->tagtype === 'official' ? 1 : 0;
     }
     $url = new moodle_url('/tag/index.php', array('id' => $this->record->id));
     $r->viewurl = $url->out(false);
     $manageurl = new moodle_url('/tag/manage.php', array('sesskey' => sesskey(), 'tagid' => $this->record->id));
     $url = new moodle_url($manageurl);
     $url->param('action', 'changetype');
     $url->param('tagtype', $r->official ? 'default' : 'official');
     $r->changetypeurl = $url->out(false);
     $url = new moodle_url($manageurl);
     $url->param('action', $this->record->flag ? 'resetflag' : 'setflag');
     $r->changeflagurl = $url->out(false);
     return $r;
 }
Ejemplo n.º 22
0
Archivo: lib.php Proyecto: dg711/moodle
/**
 * Manage inplace editable saves.
 *
 * @param   string      $itemtype       The type of item.
 * @param   int         $itemid         The ID of the item.
 * @param   mixed       $newvalue       The new value
 * @return  string
 */
function tool_usertours_inplace_editable($itemtype, $itemid, $newvalue)
{
    $context = \context_system::instance();
    external_api::validate_context($context);
    require_capability('tool/usertours:managetours', $context);
    if ($itemtype === 'tourname') {
        $tour = helper::get_tour($itemid);
        $tour->set_name($newvalue)->persist();
        return helper::render_tourname_inplace_editable($tour);
    } else {
        if ($itemtype === 'tourdescription') {
            $tour = helper::get_tour($itemid);
            $tour->set_description($newvalue)->persist();
            return helper::render_tourdescription_inplace_editable($tour);
        } else {
            if ($itemtype === 'tourenabled') {
                $tour = helper::get_tour($itemid);
                $tour->set_enabled(!!$newvalue)->persist();
                return helper::render_tourenabled_inplace_editable($tour);
            } else {
                if ($itemtype === 'stepname') {
                    $step = helper::get_step($itemid);
                    $step->set_title($newvalue)->persist();
                    return helper::render_stepname_inplace_editable($step);
                }
            }
        }
    }
}
Ejemplo n.º 23
0
 /**
  * Test send_instant_messages
  */
 public function test_send_instant_messages()
 {
     global $DB, $USER, $CFG;
     $this->resetAfterTest(true);
     // Transactions used in tests, tell phpunit use alternative reset method.
     $this->preventResetByRollback();
     // Turn off all message processors (so nothing is really sent)
     require_once $CFG->dirroot . '/message/lib.php';
     $messageprocessors = get_message_processors();
     foreach ($messageprocessors as $messageprocessor) {
         $messageprocessor->enabled = 0;
         $DB->update_record('message_processors', $messageprocessor);
     }
     // Set the required capabilities by the external function
     $contextid = context_system::instance()->id;
     $roleid = $this->assignUserCapability('moodle/site:sendmessage', $contextid);
     $user1 = self::getDataGenerator()->create_user();
     // Create test message data.
     $message1 = array();
     $message1['touserid'] = $user1->id;
     $message1['text'] = 'the message.';
     $message1['clientmsgid'] = 4;
     $messages = array($message1);
     $sentmessages = core_message_external::send_instant_messages($messages);
     // We need to execute the return values cleaning process to simulate the web service server.
     $sentmessages = external_api::clean_returnvalue(core_message_external::send_instant_messages_returns(), $sentmessages);
     $themessage = $DB->get_record('message', array('id' => $sentmessages[0]['msgid']));
     // Confirm that the message was inserted correctly.
     $this->assertEquals($themessage->useridfrom, $USER->id);
     $this->assertEquals($themessage->useridto, $message1['touserid']);
     $this->assertEquals($themessage->smallmessage, $message1['text']);
     $this->assertEquals($sentmessages[0]['clientmsgid'], $message1['clientmsgid']);
 }
Ejemplo n.º 24
0
/**
 * @package block
 * @subpackage demostudent
 * @author Dominik Royko royko@ualberta.ca
 */
function xmldb_block_demostudent_install()
{
    global $DB;
    $result = true;
    $systemcontext = context_system::instance();
    // Create DemoStudent role.
    $contextlevels = array(CONTEXT_COURSE, CONTEXT_MODULE);
    if (!($demostudentrole = $DB->get_record('role', array('shortname' => 'demostudent')))) {
        if ($roleid = create_role(get_string('roledemostudentname', 'block_demostudent'), 'demostudent', get_string('roledemostudentdescription', 'block_demostudent'), 'student')) {
            $newrole = new stdClass();
            $newrole->id = $roleid;
            // Set the capabilities to the archetype (student).
            // Caution: new capabilities un/set here can get clobbered by 'clonepermissionsfrom',
            // defined in access.php.
            reset_role_capabilities($roleid);
            // DemoStudent needs to see the DemoStudent block.
            $result = $result && assign_capability('block/demostudent:seedemostudentblock', CAP_ALLOW, $newrole->id, $systemcontext->id);
            // DemoStudent should be able to see hidden courses to facilitate testing.
            $result = $result && assign_capability('moodle/course:viewhiddencourses', CAP_ALLOW, $newrole->id, $systemcontext->id);
            // DemoStudent should NOT be able to add more demostudents!
            $result = $result && unassign_capability('block/demostudent:addinstance', $newrole->id);
            $systemcontext->mark_dirty();
            set_role_contextlevels($newrole->id, $contextlevels);
        } else {
            $result = false;
        }
    }
    return $result;
}
Ejemplo n.º 25
0
 /**
  * Fill in record defaults
  * @param stdClass $record
  * @return stdClass
  */
 protected function prepare_record(stdClass $record)
 {
     $record->blockname = $this->get_blockname();
     if (!isset($record->parentcontextid)) {
         $record->parentcontextid = context_system::instance()->id;
     }
     if (!isset($record->showinsubcontexts)) {
         $record->showinsubcontexts = 1;
     }
     if (!isset($record->pagetypepattern)) {
         $record->pagetypepattern = '';
     }
     if (!isset($record->subpagepattern)) {
         $record->subpagepattern = null;
     }
     if (!isset($record->defaultregion)) {
         $record->defaultregion = '';
     }
     if (!isset($record->defaultweight)) {
         $record->defaultweight = '';
     }
     if (!isset($record->configdata)) {
         $record->configdata = null;
     }
     return $record;
 }
Ejemplo n.º 26
0
 /**
  * Returns an array of the shared presets (in moodledata) the user is allowed to access
  * @param in $presetarea  PRESET_COURSEAREA/PRESET_SITEAREA
  */
 public function get_user_presets($presetarea)
 {
     global $USER, $PAGE;
     $presets = array();
     $fs = get_file_storage();
     if ($presetarea == self::PRESET_COURSEAREA) {
         $df = mod_dataform_dataform::instance($this->_dataformid);
         $context = context_course::instance($df->course->id);
         $files = $fs->get_area_files($context->id, 'mod_dataform', $presetarea);
     } else {
         if ($presetarea == self::PRESET_SITEAREA) {
             $context = context_system::instance();
             $files = $fs->get_area_files(SYSCONTEXTID, 'mod_dataform', $presetarea);
         }
     }
     $canviewall = has_capability('mod/dataform:presetsviewall', $context);
     if (!empty($files)) {
         foreach ($files as $file) {
             if ($file->is_directory() || ($file->get_userid() != $USER->id and !$canviewall)) {
                 continue;
             }
             $preset = new stdClass();
             $preset->contextid = $file->get_contextid();
             $preset->path = $file->get_filepath();
             $preset->name = $file->get_filename();
             $preset->shortname = pathinfo($preset->name, PATHINFO_FILENAME);
             $preset->userid = $file->get_userid();
             $preset->itemid = $file->get_itemid();
             $preset->id = $file->get_id();
             $preset->area = $presetarea;
             $presets[] = $preset;
         }
     }
     return $presets;
 }
 /**
  * Init method.
  *
  * @return void
  */
 protected function init()
 {
     $this->context = \context_system::instance();
     $this->data['crud'] = 'u';
     $this->data['level'] = self::LEVEL_OTHER;
     $this->data['objecttable'] = 'external_services';
 }
Ejemplo n.º 28
0
 /**
  * Convenience to take a fixture test file and create a stored_file.
  *
  * @param string $filepath
  * @return stored_file
  */
 protected function create_stored_file_from_path($filepath)
 {
     $syscontext = context_system::instance();
     $filerecord = array('contextid' => $syscontext->id, 'component' => 'mod_scorm', 'filearea' => 'unittest', 'itemid' => 0, 'filepath' => '/', 'filename' => basename($filepath));
     $fs = get_file_storage();
     return $fs->create_file_from_pathname($filerecord, $filepath);
 }
Ejemplo n.º 29
0
 /**
  * Constructor
  *
  * @param array $tagset array of core_tag or stdClass elements, each of them must have attributes:
  *              name, rawname, tagcollid
  *              preferrably also have attributes:
  *              tagtype, count, flag
  * @param int $totalcount total count of tags (for example to indicate that there are more tags than the count of tagset)
  *            leave 0 if count of tagset is the actual count of tags
  * @param int $fromctx context id where this tag cloud is displayed
  * @param int $ctx context id for tag view link
  * @param int $rec recursive argument for tag view link
  */
 public function __construct($tagset, $totalcount = 0, $fromctx = 0, $ctx = 0, $rec = 1)
 {
     $canmanagetags = has_capability('moodle/tag:manage', \context_system::instance());
     $maxcount = 1;
     foreach ($tagset as $tag) {
         if (isset($tag->count) && $tag->count > $maxcount) {
             $maxcount = $tag->count;
         }
     }
     $this->tagset = array();
     foreach ($tagset as $idx => $tag) {
         $this->tagset[$idx] = new stdClass();
         $this->tagset[$idx]->name = core_tag_tag::make_display_name($tag, false);
         if ($canmanagetags && !empty($tag->flag)) {
             $this->tagset[$idx]->flag = 1;
         }
         $viewurl = core_tag_tag::make_url($tag->tagcollid, $tag->rawname, 0, $fromctx, $ctx, $rec);
         $this->tagset[$idx]->viewurl = $viewurl->out(false);
         if (!empty($tag->tagtype)) {
             $this->tagset[$idx]->tagtype = $tag->tagtype;
         }
         if (!empty($tag->count)) {
             $this->tagset[$idx]->count = $tag->count;
             $this->tagset[$idx]->size = (int) ($tag->count / $maxcount * 20);
         }
     }
     $this->totalcount = $totalcount ? $totalcount : count($this->tagset);
 }
Ejemplo n.º 30
0
 public function get_content()
 {
     global $CFG, $OUTPUT, $USER, $PAGE, $DB;
     if ($this->content !== null) {
         return $this->content;
     }
     $config = turnitintooltwo_admin_config();
     $output = '';
     // Show link to Helpdesk wizard if enabled and the logged in user is an instrutor.
     if (!empty($USER->id) && $config->helpdeskwizard && has_capability('moodle/course:manageactivities', context_system::instance())) {
         $output = $OUTPUT->box(html_writer::tag('p', html_writer::link($CFG->wwwroot . '/mod/turnitintooltwo/extras.php?cmd=supportwizard', get_string('helpdesklink', 'block_turnitin'))));
     }
     if (!empty($USER->id) && has_capability('moodle/course:create', context_system::instance())) {
         $PAGE->requires->jquery();
         $PAGE->requires->jquery_plugin('block-turnitin', 'block_turnitin');
         $cssurl = new moodle_url($CFG->wwwroot . '/mod/turnitintooltwo/css/styles_block.css');
         $PAGE->requires->css($cssurl);
         $output .= $OUTPUT->box($OUTPUT->pix_icon('loader', '', 'mod_turnitintooltwo'), 'centered_cell', 'block_loading');
         $output .= html_writer::link($CFG->wwwroot . '/mod/turnitintooltwo/extras.php?cmd=courses', html_writer::tag('noscript', get_string('coursestomigrate', 'block_turnitin', '')), array('id' => 'block_migrate_content'));
     }
     $this->content = new stdClass();
     $this->content->text = $output;
     $this->content->footer = '';
     return $this->content;
 }