Exemple #1
0
/**
 * Get the potential assignees selector for a given context.
 *
 * If this context is a course context, or inside a course context (module or
 * some blocks) then return a core_role_potential_assignees_below_course object. Otherwise
 * return a core_role_potential_assignees_course_and_above.
 *
 * @param context $context a context.
 * @param string $name passed to user selector constructor.
 * @param array $options to user selector constructor.
 * @return user_selector_base an appropriate user selector.
 */
function core_role_get_potential_user_selector(context $context, $name, $options)
{
    $blockinsidecourse = false;
    if ($context->contextlevel == CONTEXT_BLOCK) {
        $parentcontext = $context->get_parent_context();
        $blockinsidecourse = in_array($parentcontext->contextlevel, array(CONTEXT_MODULE, CONTEXT_COURSE));
    }
    if (($context->contextlevel == CONTEXT_MODULE || $blockinsidecourse) && !is_inside_frontpage($context)) {
        $potentialuserselector = new core_role_potential_assignees_below_course('addselect', $options);
    } else {
        $potentialuserselector = new core_role_potential_assignees_course_and_above('addselect', $options);
    }
    return $potentialuserselector;
}
 function definition()
 {
     global $CFG, $DB;
     $mform = $this->_form;
     list($instance, $plugin, $course) = $this->_customdata;
     $coursecontext = context_course::instance($course->id);
     $enrol = enrol_get_plugin('cohort');
     $groups = array(0 => get_string('none'));
     foreach (groups_get_all_groups($course->id) as $group) {
         $groups[$group->id] = format_string($group->name, true, array('context' => $coursecontext));
     }
     $mform->addElement('header', 'general', get_string('pluginname', 'enrol_cohort'));
     $mform->addElement('text', 'name', get_string('custominstancename', 'enrol'));
     $mform->setType('name', PARAM_TEXT);
     $options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), ENROL_INSTANCE_DISABLED => get_string('no'));
     $mform->addElement('select', 'status', get_string('status', 'enrol_cohort'), $options);
     if ($instance->id) {
         if ($cohort = $DB->get_record('cohort', array('id' => $instance->customint1))) {
             $cohorts = array($instance->customint1 => format_string($cohort->name, true, array('context' => context::instance_by_id($cohort->contextid))));
         } else {
             $cohorts = array($instance->customint1 => get_string('error'));
         }
         $mform->addElement('select', 'customint1', get_string('cohort', 'cohort'), $cohorts);
         $mform->setConstant('customint1', $instance->customint1);
         $mform->hardFreeze('customint1', $instance->customint1);
     } else {
         $cohorts = array('' => get_string('choosedots'));
         $allcohorts = cohort_get_available_cohorts($coursecontext, 0, 0, 0);
         foreach ($allcohorts as $c) {
             $cohorts[$c->id] = format_string($c->name);
         }
         $mform->addElement('select', 'customint1', get_string('cohort', 'cohort'), $cohorts);
         $mform->addRule('customint1', get_string('required'), 'required', null, 'client');
     }
     $roles = get_assignable_roles($coursecontext);
     $roles[0] = get_string('none');
     $roles = array_reverse($roles, true);
     // Descending default sortorder.
     $mform->addElement('select', 'roleid', get_string('assignrole', 'enrol_cohort'), $roles);
     $mform->setDefault('roleid', $enrol->get_config('roleid'));
     if ($instance->id and !isset($roles[$instance->roleid])) {
         if ($role = $DB->get_record('role', array('id' => $instance->roleid))) {
             $roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS, true);
             $roles[$instance->roleid] = role_get_name($role, $coursecontext);
         } else {
             $roles[$instance->roleid] = get_string('error');
         }
     }
     $mform->addElement('select', 'customint2', get_string('addgroup', 'enrol_cohort'), $groups);
     $mform->addElement('hidden', 'courseid', null);
     $mform->setType('courseid', PARAM_INT);
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
     if ($instance->id) {
         $this->add_action_buttons(true);
     } else {
         $this->add_action_buttons(true, get_string('addinstance', 'enrol'));
     }
     $this->set_data($instance);
 }
Exemple #3
0
 /**
  * Returns localised name of enrol instance.
  *
  * @param stdClass $instance (null is accepted too)
  * @return string
  */
 public function get_instance_name($instance)
 {
     global $DB;
     if (empty($instance)) {
         $enrol = $this->get_name();
         return get_string('pluginname', 'enrol_' . $enrol);
     } else {
         if (empty($instance->name)) {
             $enrol = $this->get_name();
             $cohort = $DB->get_record('cohort', array('id' => $instance->customint1));
             if (!$cohort) {
                 return get_string('pluginname', 'enrol_' . $enrol);
             }
             $cohortname = format_string($cohort->name, true, array('context' => context::instance_by_id($cohort->contextid)));
             if ($role = $DB->get_record('role', array('id' => $instance->roleid))) {
                 $role = role_get_name($role, context_course::instance($instance->courseid, IGNORE_MISSING));
                 return get_string('pluginname', 'enrol_' . $enrol) . ' (' . $cohortname . ' - ' . $role . ')';
             } else {
                 return get_string('pluginname', 'enrol_' . $enrol) . ' (' . $cohortname . ')';
             }
         } else {
             return format_string($instance->name, true, array('context' => context_course::instance($instance->courseid)));
         }
     }
 }
Exemple #4
0
/**
 * Form for editing HTML block instances.
 *
 * @copyright 2010 Petr Skoda (http://skodak.org)
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @package   block_html
 * @category  files
 * @param stdClass $course course object
 * @param stdClass $birecord_or_cm block instance record
 * @param stdClass $context context object
 * @param string $filearea file area
 * @param array $args extra arguments
 * @param bool $forcedownload whether or not force download
 * @param array $options additional options affecting the file serving
 * @return bool
 */
function block_html_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $SCRIPT;
    if ($context->contextlevel != CONTEXT_BLOCK) {
        send_file_not_found();
    }
    require_course_login($course);
    if ($filearea !== 'content') {
        send_file_not_found();
    }
    $fs = get_file_storage();
    $filename = array_pop($args);
    $filepath = $args ? '/' . implode('/', $args) . '/' : '/';
    if (!($file = $fs->get_file($context->id, 'block_html', 'content', 0, $filepath, $filename)) or $file->is_directory()) {
        send_file_not_found();
    }
    if ($parentcontext = context::instance_by_id($birecord_or_cm->parentcontextid, IGNORE_MISSING)) {
        if ($parentcontext->contextlevel == CONTEXT_USER) {
            // force download on all personal pages including /my/
            //because we do not have reliable way to find out from where this is used
            $forcedownload = true;
        }
    } else {
        // weird, there should be parent context, better force dowload then
        $forcedownload = true;
    }
    session_get_instance()->write_close();
    send_stored_file($file, 60 * 60, 0, $forcedownload, $options);
}
 /**
  * Retrieve the data from the url and make the base initialization
  * 
  * @return void
  */
 protected function defaultData()
 {
     $context = Context::getInstance();
     $this->setData('extension', context::getInstance()->getExtensionName());
     $this->setData('module', $context->getModuleName());
     $this->setData('action', $context->getActionName());
     if ($this->hasRequestParameter('uri')) {
         // @todo stop using session to manage uri/classUri
         $this->setSessionAttribute('uri', $this->getRequestParameter('uri'));
         // inform the client of new classUri
         $this->setData('uri', $this->getRequestParameter('uri'));
     }
     if ($this->hasRequestParameter('classUri')) {
         // @todo stop using session to manage uri/classUri
         $this->setSessionAttribute('classUri', $this->getRequestParameter('classUri'));
         if (!$this->hasRequestParameter('uri')) {
             $this->removeSessionAttribute('uri');
         }
         // inform the client of new classUri
         $this->setData('uri', $this->getRequestParameter('classUri'));
     }
     if ($this->getRequestParameter('message')) {
         $this->setData('message', $this->getRequestParameter('message'));
     }
     if ($this->getRequestParameter('errorMessage')) {
         $this->setData('errorMessage', $this->getRequestParameter('errorMessage'));
     }
     $this->setData('client_timeout', $this->getClientTimeout());
     $this->setData('client_config_url', $this->getClientConfigUrl());
 }
Exemple #6
0
 /**
  * @brief pay
  */
 function procCashpayDoIt()
 {
     $oEpayController = getController('epay');
     $vars = Context::getRequestVars();
     $output = $oEpayController->beforePayment($vars);
     if (!$output->toBool()) {
         return $output;
     }
     $obj = new stdClass();
     $obj->bank_name = $this->module_info->bank_name;
     $obj->account_number = $this->module_info->account_number;
     $obj->account_holder = $this->module_info->account_holder;
     $output = new Object();
     $output->add('transaction_srl', Context::get('transaction_srl'));
     $output->add('state', '1');
     // not completed
     $output->add('payment_method', 'BT');
     $output->add('payment_amount', Context::get('price'));
     $output->add('result_code', '0');
     $output->add('result_message', 'success');
     $output->add('pg_tid', $this->keygen());
     $output->add('vact_bankname', $obj->bank_name);
     $output->add('vact_num', $obj->account_number);
     $output->add('vact_name', $obj->account_holder);
     $output->add('vact_inputname', context::get('depositor_name'));
     // afterPayment will call an after trigger
     $output = $oEpayController->afterPayment($output);
     if (!$output->toBool()) {
         return $output;
     }
     $return_url = $output->get('return_url');
     if ($return_url) {
         $this->setRedirectUrl($return_url);
     }
 }
Exemple #7
0
    public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) {
        global $SESSION, $CFG, $DB, $PAGE;
        if (!is_numeric($repositoryid)) {
            // ELIS-8550: were constructing these with repositoryid = 'elisfiles'
            $sql = 'SELECT MIN(ri.id)
                      FROM {repository} r
                      JOIN {repository_instances} ri
                        ON r.id = ri.typeid
                     WHERE r.type = ?';
            $repositoryid = $DB->get_field_sql($sql, array($repositoryid));
        }
        parent::__construct($repositoryid, $context, $options);

        require_once dirname(__FILE__). '/ELIS_files_factory.class.php';

        if (is_object($context)) {
            $this->context = $context;
        } else {
            $this->context = context::instance_by_id($context);
        }

        /// ELIS files class
        $this->elis_files = repository_factory::factory();
        $this->config = get_config('elisfiles');
        $this->current_node = null;

        // jQuery files required for file picker - just for this repository
        $PAGE->requires->js('/repository/elisfiles/js/jquery-1.6.2.min.js');
        $PAGE->requires->js('/repository/elisfiles/js/jquery-ui-1.8.16.custom.min.js');
        $PAGE->requires->js('/repository/elisfiles/js/fileuploader.js');
        $PAGE->requires->js('/repository/elisfiles/lib/HTML_TreeMenu-1.2.0/TreeMenu.js', true);
    }
 /**
  * Add question-type specific form fields.
  *
  * @param MoodleQuickForm $mform the form being built.
  */
 public function __construct($submiturl, $question, $regenerate)
 {
     global $SESSION, $CFG, $DB;
     $this->regenerate = $regenerate;
     $this->question = $question;
     $this->qtypeobj = question_bank::get_qtype($this->question->qtype);
     // Validate the question category.
     if (!($category = $DB->get_record('question_categories', array('id' => $question->category)))) {
         print_error('categorydoesnotexist', 'question', $returnurl);
     }
     $this->category = $category;
     $this->categorycontext = context::instance_by_id($category->contextid);
     // Get the dataset defintions for this question.
     if (empty($question->id)) {
         $this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, $SESSION->calculated->definitionform->dataset);
     } else {
         if (empty($question->options)) {
             $this->get_question_options($question);
         }
         $this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, array());
     }
     foreach ($this->datasetdefs as $datasetdef) {
         // Get maxnumber.
         if ($this->maxnumber == -1 || $datasetdef->itemcount < $this->maxnumber) {
             $this->maxnumber = $datasetdef->itemcount;
         }
     }
     foreach ($this->datasetdefs as $defid => $datasetdef) {
         if (isset($datasetdef->id)) {
             $this->datasetdefs[$defid]->items = $this->qtypeobj->get_database_dataset_items($datasetdef->id);
         }
     }
     parent::__construct($submiturl);
 }
 /**
  * If this block belongs to a activity context, then return that activity's id.
  * Otherwise, return 0.
  * @return stdclass the activity record.
  */
 public function get_owning_activity()
 {
     global $DB;
     // Set some defaults.
     $result = new stdClass();
     $result->id = 0;
     if (empty($this->instance->parentcontextid)) {
         return $result;
     }
     $parentcontext = context::instance_by_id($this->instance->parentcontextid);
     if ($parentcontext->contextlevel != CONTEXT_MODULE) {
         return $result;
     }
     $cm = get_coursemodule_from_id($this->page->cm->modname, $parentcontext->instanceid);
     if (!$cm) {
         return $result;
     }
     // Get the grade_items id.
     $rec = $DB->get_record('grade_items', array('iteminstance' => $cm->instance, 'itemmodule' => $this->page->cm->modname));
     if (!$rec) {
         return $result;
     }
     // See if it is a gradable activity.
     if ($rec->gradetype != GRADE_TYPE_VALUE && $rec->gradetype != GRADE_TYPE_SCALE) {
         return $result;
     }
     return $rec;
 }
 /**
  * @return context
  */
 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new context();
     }
     return self::$instance;
 }
Exemple #11
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);
 }
 function definition()
 {
     global $CFG, $DB;
     $mform = $this->_form;
     $course = $this->_customdata;
     $coursecontext = context_course::instance($course->id);
     $enrol = enrol_get_plugin('cohort');
     $cohorts = array('' => get_string('choosedots'));
     list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($coursecontext));
     $sql = "SELECT id, name, contextid\n                  FROM {cohort}\n                 WHERE contextid {$sqlparents}\n              ORDER BY name ASC";
     $rs = $DB->get_recordset_sql($sql, $params);
     foreach ($rs as $c) {
         $context = context::instance_by_id($c->contextid);
         if (!has_capability('moodle/cohort:view', $context)) {
             continue;
         }
         $cohorts[$c->id] = format_string($c->name);
     }
     $rs->close();
     $roles = get_assignable_roles($coursecontext);
     $roles[0] = get_string('none');
     $roles = array_reverse($roles, true);
     // descending default sortorder
     $mform->addElement('header', 'general', get_string('pluginname', 'enrol_cohort'));
     $mform->addElement('select', 'cohortid', get_string('cohort', 'cohort'), $cohorts);
     $mform->addRule('cohortid', get_string('required'), 'required', null, 'client');
     $mform->addElement('select', 'roleid', get_string('role'), $roles);
     $mform->addRule('roleid', get_string('required'), 'required', null, 'client');
     $mform->setDefault('roleid', $enrol->get_config('roleid'));
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
     $this->add_action_buttons(true, get_string('addinstance', 'enrol'));
     $this->set_data(array('id' => $course->id));
 }
function qtype_ddmarker_course_context_id($catcontextid)
{
    $context = context::instance_by_id($catcontextid);
    while ($context->contextlevel != CONTEXT_COURSE) {
        $context = $context->get_parent_context();
    }
    return $context->id;
}
 /**
  * Retrieves ajax parameters for content and update or delete
  * user data depending on params.
  *
  * @throws \coding_exception
  */
 public static function handle_ajax()
 {
     global $DB;
     // Query String Parameters.
     $content_id = required_param('content_id', PARAM_INT);
     $data_id = required_param('data_type', PARAM_RAW);
     $sub_content_id = required_param('sub_content_id', PARAM_INT);
     // Form Data.
     $data = optional_param('data', null, PARAM_RAW);
     $pre_load = optional_param('preload', null, PARAM_INT);
     $invalidate = optional_param('invalidate', null, PARAM_INT);
     if ($content_id === null || $data_id === null || $sub_content_id === null) {
         \H5PCore::ajaxError(get_string('missingparameters', 'hvp'));
         exit;
         // Missing parameters.
     }
     // Saving data
     if ($data !== NULL && $pre_load !== NULL && $invalidate !== NULL) {
         // Validate token
         if (!\H5PCore::validToken('contentuserdata', required_param('token', PARAM_RAW))) {
             \H5PCore::ajaxError(get_string('invalidtoken', 'hvp'));
             exit;
         }
         // Use context id if supplied
         $context_id = optional_param('contextId', null, PARAM_INT);
         if ($context_id) {
             $context = \context::instance_by_id($context_id);
         } else {
             // Otherwise try to find it from content id
             $context = \context_course::instance($DB->get_field('hvp', 'course', array('id' => $content_id)));
         }
         // Check permissions
         if (!has_capability('mod/hvp:savecontentuserdata', $context)) {
             \H5PCore::ajaxError(get_string('nopermissiontosavecontentuserdata', 'hvp'));
             http_response_code(403);
             exit;
         }
         if ($data === '0') {
             // Delete user data.
             self::delete_user_data($content_id, $sub_content_id, $data_id);
         } else {
             // Save user data.
             self::save_user_data($content_id, $sub_content_id, $data_id, $pre_load, $invalidate, $data);
         }
         \H5PCore::ajaxSuccess();
     } else {
         // Fetch user data
         $user_data = self::get_user_data($content_id, $sub_content_id, $data_id);
         if ($user_data === false) {
             // Did not find data, return nothing
             \H5PCore::ajaxSuccess();
         } else {
             // Found data, return encoded data
             \H5PCore::ajaxSuccess($user_data->data);
         }
     }
     exit;
 }
 /**
  * Decides which content types the editor should have.
  *
  * Two usecases:
  * 1. No input, will list all the available content types.
  * 2. Libraries supported are specified, load additional data and verify
  * that the content types are available. Used by e.g. the Presentation Tool
  * Editor that already knows which content types are supported in its
  * slides.
  *
  * @param array $libraries List of library names + version to load info for
  * @return array List of all libraries loaded
  */
 public function getLibraries($libraries = null)
 {
     global $DB;
     $context_id = required_param('contextId', PARAM_RAW);
     $super_user = has_capability('mod/hvp:userestrictedlibraries', \context::instance_by_id($context_id));
     if ($libraries !== null) {
         // Get details for the specified libraries only.
         $librarieswithdetails = array();
         foreach ($libraries as $library) {
             // Look for library
             $details = $DB->get_record_sql("SELECT title,\n                                runnable,\n                                restricted,\n                                tutorial_url\n                           FROM {hvp_libraries}\n                          WHERE machine_name = ?\n                            AND major_version = ?\n                            AND minor_version = ?\n                            AND semantics IS NOT NULL\n                        ", array($library->name, $library->majorVersion, $library->minorVersion));
             if ($details) {
                 // Library found, add details to list
                 $library->tutorialUrl = $details->tutorial_url;
                 $library->title = $details->title;
                 $library->runnable = $details->runnable;
                 $library->restricted = $super_user ? false : ($details->restricted === '1' ? true : false);
                 $librarieswithdetails[] = $library;
             }
         }
         // Done, return list with library details
         return $librarieswithdetails;
     }
     // Load all libraries
     $libraries = array();
     $librariesresult = $DB->get_records_sql("SELECT id,\n                        machine_name AS name,\n                        title,\n                        major_version,\n                        minor_version,\n                        tutorial_url,\n                        restricted\n                   FROM {hvp_libraries}\n                  WHERE runnable = 1\n                    AND semantics IS NOT NULL\n               ORDER BY title");
     foreach ($librariesresult as $library) {
         // Remove unique index
         unset($library->id);
         // Convert snakes to camels
         $library->majorVersion = (int) $library->major_version;
         unset($library->major_version);
         $library->minorVersion = (int) $library->minor_version;
         unset($library->minor_version);
         if (!empty($library->tutorial_url)) {
             $library->tutorialUrl = $library->tutorial_url;
         }
         unset($library->tutorial_url);
         // Make sure we only display the newest version of a library.
         foreach ($libraries as $key => $existinglibrary) {
             if ($library->name === $existinglibrary->name) {
                 // Found library with same name, check versions
                 if ($library->majorVersion === $existinglibrary->majorVersion && $library->minorVersion > $existinglibrary->minorVersion || $library->majorVersion > $existinglibrary->majorVersion) {
                     // This is a newer version
                     $existinglibrary->isOld = true;
                 } else {
                     // This is an older version
                     $library->isOld = true;
                 }
             }
         }
         // Check to see if content type should be restricted
         $library->restricted = $super_user ? false : ($library->restricted === '1' ? true : false);
         // Add new library
         $libraries[] = $library;
     }
     return $libraries;
 }
 /**
  * Returns a string describing the rule.
  *
  * @return string
  */
 public function get_description()
 {
     $context = context::instance_by_id($this->value, IGNORE_MISSING);
     $contextname = get_string('errorunknownmodule', 'block_xp');
     if ($context) {
         $contextname = $context->get_context_name();
     }
     return get_string('rulecmdesc', 'block_xp', (object) array('contextname' => $contextname));
 }
Exemple #17
0
 public function testObserver()
 {
     $context = new context(new StateA());
     $this->assertInstanceOf('Behavioral\\State\\State\\A', $context->getState());
     $context->request();
     $this->assertInstanceOf('Behavioral\\State\\State\\B', $context->getState());
     $context->request();
     $this->assertInstanceOf('Behavioral\\State\\State\\C', $context->getState());
     $context->request();
     $this->assertInstanceOf('Behavioral\\State\\State\\A', $context->getState());
 }
/**
 * Calculates capability data organised by context for the given roles.
 *
 * @param string $capability The capability to get data for.
 * @param array $roles An array of roles to get data for.
 * @return context[] An array of contexts.
 */
function tool_capability_calculate_role_data($capability, array $roles)
{
    global $DB;
    $systemcontext = context_system::instance();
    $roleids = array_keys($roles);
    // Work out the bits needed for the SQL WHERE clauses.
    $params = array($capability);
    list($sqlroletest, $roleparams) = $DB->get_in_or_equal($roleids);
    $params = array_merge($params, $roleparams);
    $sqlroletest = 'AND roleid ' . $sqlroletest;
    // Get all the role_capabilities rows for this capability - that is, all
    // role definitions, and all role overrides.
    $sql = 'SELECT id, roleid, contextid, permission
              FROM {role_capabilities}
             WHERE capability = ? ' . $sqlroletest;
    $rolecaps = $DB->get_records_sql($sql, $params);
    // In order to display a nice tree of contexts, we need to get all the
    // ancestors of all the contexts in the query we just did.
    $sql = 'SELECT DISTINCT con.path, 1
              FROM {context} con
              JOIN {role_capabilities} rc ON rc.contextid = con.id
             WHERE capability = ? ' . $sqlroletest;
    $relevantpaths = $DB->get_records_sql_menu($sql, $params);
    $requiredcontexts = array($systemcontext->id);
    foreach ($relevantpaths as $path => $notused) {
        $requiredcontexts = array_merge($requiredcontexts, explode('/', trim($path, '/')));
    }
    $requiredcontexts = array_unique($requiredcontexts);
    // Now load those contexts.
    list($sqlcontexttest, $contextparams) = $DB->get_in_or_equal($requiredcontexts);
    $contexts = get_sorted_contexts('ctx.id ' . $sqlcontexttest, $contextparams);
    // Prepare some empty arrays to hold the data we are about to compute.
    foreach ($contexts as $conid => $con) {
        $contexts[$conid]->children = array();
        $contexts[$conid]->rolecapabilities = array();
    }
    // Put the contexts into a tree structure.
    foreach ($contexts as $conid => $con) {
        $context = context::instance_by_id($conid);
        $parentcontext = $context->get_parent_context();
        if ($parentcontext) {
            $contexts[$parentcontext->id]->children[] = $conid;
        }
    }
    // Put the role capabilities into the context tree.
    foreach ($rolecaps as $rolecap) {
        $contexts[$rolecap->contextid]->rolecapabilities[$rolecap->roleid] = $rolecap->permission;
    }
    // Fill in any missing rolecaps for the system context.
    foreach ($roleids as $roleid) {
        if (!isset($contexts[$systemcontext->id]->rolecapabilities[$roleid])) {
            $contexts[$systemcontext->id]->rolecapabilities[$roleid] = CAP_INHERIT;
        }
    }
    return $contexts;
}
Exemple #19
0
 /**
  * Generate the name column.
  *
  * @param \stdClass $tool event data.
  * @return string
  */
 public function col_name($tool)
 {
     if (empty($tool->name)) {
         $toolcontext = \context::instance_by_id($tool->contextid);
         $name = $toolcontext->get_context_name();
     } else {
         $name = $tool->name;
     }
     return $this->get_display_text($tool, $name);
 }
/**
 * Form for editing Information Spot  block instances.
 *
 * @copyright 2014 Roberto Pinna
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @package   block_informationspot
 * @category  files
 * @param stdClass $course course object
 * @param stdClass $birecord_or_cm block instance record
 * @param stdClass $context context object
 * @param string $filearea file area
 * @param array $args extra arguments
 * @param bool $forcedownload whether or not force download
 * @param array $options additional options affecting the file serving
 * @return bool
 */
function block_informationspot_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $DB, $CFG, $USER;
    if ($context->contextlevel != CONTEXT_BLOCK) {
        send_file_not_found();
    }
    // If block is in course context, then check if user has capability to access course.
    if ($context->get_course_context(false)) {
        require_course_login($course);
    } else {
        if ($CFG->forcelogin) {
            require_login();
        } else {
            // Get parent context and see if user have proper permission.
            $parentcontext = $context->get_parent_context();
            if ($parentcontext->contextlevel === CONTEXT_COURSECAT) {
                // Check if category is visible and user can view this category.
                $category = $DB->get_record('course_categories', array('id' => $parentcontext->instanceid), '*', MUST_EXIST);
                if (!$category->visible) {
                    require_capability('moodle/category:viewhiddencategories', $parentcontext);
                }
            } else {
                if ($parentcontext->contextlevel === CONTEXT_USER && $parentcontext->instanceid != $USER->id) {
                    // The block is in the context of a user, it is only visible to the user who it belongs to.
                    send_file_not_found();
                }
            }
            // At this point there is no way to check SYSTEM context, so ignoring it.
        }
    }
    if ($filearea != 'image') {
        send_file_not_found();
    }
    $fs = get_file_storage();
    $imageid = array_shift($args);
    $filename = array_pop($args);
    $filepath = $args ? '/' . implode('/', $args) . '/' : '/';
    if (!($file = $fs->get_file($context->id, 'block_informationspot', $filearea, $imageid, $filepath, $filename)) or $file->is_directory()) {
        send_file_not_found();
    }
    if ($parentcontext = context::instance_by_id($birecord_or_cm->parentcontextid, IGNORE_MISSING)) {
        if ($parentcontext->contextlevel == CONTEXT_USER) {
            // force download on all personal pages including /my/
            //because we do not have reliable way to find out from where this is used
            $forcedownload = true;
        }
    } else {
        // weird, there should be parent context, better force dowload then
        $forcedownload = true;
    }
    // NOTE: it woudl be nice to have file revisions here, for now rely on standard file lifetime,
    //       do not lower it because the files are dispalyed very often.
    \core\session\manager::write_close();
    send_stored_file($file, null, 0, $forcedownload, $options);
}
Exemple #21
0
 /**
  * Updates cohort name and returns instance of this object
  *
  * @param int $cohortid
  * @param string $newvalue
  * @return static
  */
 public static function update($cohortid, $newvalue)
 {
     global $DB;
     $cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
     $cohortcontext = \context::instance_by_id($cohort->contextid);
     require_capability('moodle/cohort:manage', $cohortcontext);
     $record = (object) array('id' => $cohort->id, 'idnumber' => $newvalue, 'contextid' => $cohort->contextid);
     cohort_update_cohort($record);
     $cohort->idnumber = $newvalue;
     return new static($cohort);
 }
Exemple #22
0
 public static function getContent(&$rs, $absolute_urls = false)
 {
     if ($rs->core->blog->settings->use_smilies) {
         $c = parent::getContent($rs, $absolute_urls);
         if (!isset($GLOBALS['__smilies'])) {
             $GLOBALS['__smilies'] = context::getSmilies($rs->core->blog);
         }
         return context::addSmilies($c);
     }
     return parent::getContent($rs, $absolute_urls);
 }
Exemple #23
0
 private function context_info($contextid)
 {
     global $DB;
     $context = \context::instance_by_id($contextid, MUST_EXIST);
     $out = '';
     //var_dump($context);
     if (is_a($context, "context_module")) {
         /** @var \context_module $context */
         $out .= "{$contextid}, module: " . $context->get_context_name();
     }
     return $out;
 }
 public function getCheckoutOptions()
 {
     $shipping_method_service = new ShippingMethodService();
     $payment_method_service = new PaymentMethodService();
     $customer = context::getCustomer();
     $zones = [];
     if ($customer != NULL) {
         //load country and zones
         $customer->load('defaultAddress', 'addresses');
     }
     return Response::json(['customer' => $customer, 'shipping_methods' => $shipping_method_service->getAll(['sorting' => ['sort_order']], context::getLanguageId()), 'payment_methods' => $payment_method_service->getAll(['sorting' => ['sort_order']], context::getLanguageId())]);
 }
 /**
  * Add question-type specific form fields.
  *
  * @param MoodleQuickForm $mform the form being built.
  */
 public function __construct($submiturl, $question) {
     global $DB;
     $this->question = $question;
     $this->qtypeobj = question_bank::get_qtype($this->question->qtype);
     // Validate the question category.
     if (!$category = $DB->get_record('question_categories',
             array('id' => $question->category))) {
         print_error('categorydoesnotexist', 'question', $returnurl);
     }
     $this->category = $category;
     $this->categorycontext = context::instance_by_id($category->contextid);
     parent::__construct($submiturl);
 }
 /**
  * @param string $name control name
  * @param array $options should have two elements with keys groupid and courseid.
  */
 public function __construct($name, $options)
 {
     global $CFG;
     if (isset($options['context'])) {
         $this->context = $options['context'];
     } else {
         $this->context = context::instance_by_id($options['contextid']);
     }
     $options['accesscontext'] = $this->context;
     parent::__construct($name, $options);
     $this->roleid = $options['roleid'];
     require_once $CFG->dirroot . '/group/lib.php';
 }
 /**
  * Construct this renderable.
  * @param int $courseid The course record for this page.
  */
 public function __construct($courseid)
 {
     $this->context = context_course::instance($courseid);
     $this->courseid = $courseid;
     $this->coursecompetencylist = api::list_course_competencies($courseid);
     $this->canmanagecoursecompetencies = has_capability('moodle/competency:coursecompetencymanage', $this->context);
     $this->canconfigurecoursecompetencies = has_capability('moodle/competency:coursecompetencyconfigure', $this->context);
     $this->cangradecompetencies = has_capability('moodle/competency:competencygrade', $this->context);
     $this->coursecompetencysettings = api::read_course_competency_settings($courseid);
     $this->coursecompetencystatistics = new course_competency_statistics($courseid);
     // Check the lowest level in which the user can manage the competencies.
     $this->manageurl = null;
     $this->canmanagecompetencyframeworks = false;
     $contexts = array_reverse($this->context->get_parent_contexts(true));
     foreach ($contexts as $context) {
         $canmanage = has_capability('moodle/competency:competencymanage', $context);
         if ($canmanage) {
             $this->manageurl = new moodle_url('/admin/tool/lp/competencyframeworks.php', array('pagecontextid' => $context->id));
             $this->canmanagecompetencyframeworks = true;
             break;
         }
     }
 }
Exemple #28
0
 /**
  * Updates cohort name and returns instance of this object
  *
  * @param int $cohortid
  * @param string $newvalue
  * @return static
  */
 public static function update($cohortid, $newvalue)
 {
     global $DB;
     $cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
     $cohortcontext = \context::instance_by_id($cohort->contextid);
     require_capability('moodle/cohort:manage', $cohortcontext);
     $newvalue = clean_param($newvalue, PARAM_TEXT);
     if (strval($newvalue) !== '') {
         $record = (object) array('id' => $cohort->id, 'name' => $newvalue, 'contextid' => $cohort->contextid);
         cohort_update_cohort($record);
         $cohort->name = $newvalue;
     }
     return new static($cohort);
 }
 /**
  * If this block belongs to a course context, then return that course id.
  * Otherwise, return 0.
  *
  * @return int the course id.
  */
 public function get_owning_course()
 {
     if (empty($this->instance->parentcontextid)) {
         return 0;
     }
     $parentcontext = context::instance_by_id($this->instance->parentcontextid);
     if ($parentcontext->contextlevel != CONTEXT_COURSE) {
         return 0;
     }
     $coursecontext = $parentcontext->get_course_context(true);
     if (!$coursecontext) {
         return 0;
     }
     return $coursecontext->instanceid;
 }
 /**
  * If this block belongs to a quiz context, then return that quiz's id.
  * Otherwise, return 0.
  * @return integer the quiz id.
  */
 public function get_owning_quiz()
 {
     if (empty($this->instance->parentcontextid)) {
         return 0;
     }
     $parentcontext = context::instance_by_id($this->instance->parentcontextid);
     if ($parentcontext->contextlevel != CONTEXT_MODULE) {
         return 0;
     }
     $cm = get_coursemodule_from_id('quiz', $parentcontext->instanceid);
     if (!$cm) {
         return 0;
     }
     return $cm->instance;
 }