本文整理汇总了PHP中cache::make方法的典型用法代码示例。如果您正苦于以下问题:PHP cache::make方法的具体用法?PHP cache::make怎么用?PHP cache::make使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cache
的用法示例。
在下文中一共展示了cache::make方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: definition
function definition()
{
global $DB;
$mform = $this->_form;
// Clear the observer cache to ensure observers for any newly-installed plugins are added
$cache = \cache::make('core', 'observers');
$cache->delete('all');
list($instance, $plugin, $context) = $this->_customdata;
$mform->addElement('header', 'header', get_string('pluginname', 'enrol_auto'));
$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_auto'), $options);
$mform->addHelpButton('status', 'status', 'enrol_auto');
$options = array(ENROL_AUTO_COURSE_VIEWED => get_string('courseview', 'enrol_auto'), ENROL_AUTO_LOGIN => get_string('userlogin', 'enrol_auto'), ENROL_AUTO_MOD_VIEWED => get_string('modview', 'enrol_auto'));
$mform->addElement('select', 'customint3', get_string('enrolon', 'enrol_auto'), $options);
$mform->addHelpButton('customint3', 'enrolon', 'enrol_auto');
$mods = \enrol_auto\helper::get_mods_with_viewed_event();
$modgroup = array();
foreach ($mods as $modname) {
$modgroup[] = $mform->createElement('checkbox', $modname, '', get_string('pluginname', "mod_{$modname}"));
}
$mform->addGroup($modgroup, 'customtext2', get_string('modviewmods', 'enrol_auto'), '<br>', true);
$mform->disabledIf('customtext2', 'customint3', 'neq', ENROL_AUTO_MOD_VIEWED);
$roles = $this->extend_assignable_roles($context, $instance->roleid);
$mform->addElement('select', 'roleid', get_string('role', 'enrol_auto'), $roles);
$mform->addElement('advcheckbox', 'customint2', get_string('sendcoursewelcomemessage', 'enrol_auto'));
$mform->addHelpButton('customint2', 'sendcoursewelcomemessage', 'enrol_auto');
$mform->addElement('textarea', 'customtext1', get_string('customwelcomemessage', 'enrol_auto'), array('cols' => '60', 'rows' => '8'));
$mform->addHelpButton('customtext1', 'customwelcomemessage', 'enrol_auto');
$mform->disabledIf('customtext1', 'customint2', 'notchecked');
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'courseid');
$mform->setType('courseid', PARAM_INT);
$this->add_action_buttons(true, $instance->id ? null : get_string('addinstance', 'enrol'));
$instance->customtext2 = array_flip(explode(',', $instance->customtext2));
$instance->customtext2 = array_map(function ($a) {
return 1;
}, $instance->customtext2);
$this->set_data($instance);
}
示例2: __construct
/**
* Create new instance of string manager
*
* @param string $otherroot location of downloaded lang packs - usually $CFG->dataroot/lang
* @param string $localroot usually the same as $otherroot
* @param array $translist limit list of visible translations
*/
public function __construct($otherroot, $localroot, $translist)
{
$this->otherroot = $otherroot;
$this->localroot = $localroot;
if ($translist) {
$this->translist = array_combine($translist, $translist);
} else {
$this->translist = array();
}
if ($this->get_revision() > 0) {
// We can use a proper cache, establish the cache using the 'String cache' definition.
$this->cache = cache::make('core', 'string');
$this->menucache = cache::make('core', 'langmenu');
} else {
// We only want a cache for the length of the request, create a static cache.
$options = array('simplekeys' => true, 'simpledata' => true);
$this->cache = cache::make_from_params(cache_store::MODE_REQUEST, 'core', 'string', array(), $options);
$this->menucache = cache::make_from_params(cache_store::MODE_REQUEST, 'core', 'langmenu', array(), $options);
}
}
示例3: validation
public function validation($data, $files)
{
$errors = array();
// Submit is redirected if error occurs, so we store errordata in session.
$sessionerrordata = array();
$cache = cache::make('format_socialwall', 'commentformerrors');
$cache->delete($data['postid']);
// ... check if comment is all empty.
if (isset($data['submitcomment'])) {
if (empty($data['text'])) {
$errors['text'] = get_string('textrequired', 'format_socialwall');
$sessionerrordata['text'] = array('message' => $errors['text'], 'value' => $data['text']);
}
}
// ... store or clean.
if (!empty($sessionerrordata)) {
$cache->set($data['postid'], $sessionerrordata);
}
return $errors;
}
示例4: block_twitter_get_tweets
function block_twitter_get_tweets($handle)
{
global $CFG, $COURSE, $DB;
$cache = cache::make('block_twitter', 'tweets');
$tweets = $cache->get('tweets_' . $handle);
if ($tweets !== false) {
return $tweets;
}
$tconf = get_config('block_twitter');
$connection = new TwitterOAuth($tconf->consumerkey, $tconf->consumersecret, $tconf->accesstoken, $tconf->accesssecret);
$connection->resetLastResponse();
$tweets = $connection->get("statuses/user_timeline", ["screen_name" => $handle, 'exclude_replies' => true, 'trim_user' => false]);
if (isset($tweets->errors)) {
$error = reset($tweets->errors);
debugging(get_string('error') . ' ' . $error->code . ': ' . $error->message, DEBUG_DEVELOPER);
return '';
}
$cache->set('tweets_' . $handle, $tweets);
return $tweets;
}
示例5: get_option
/**
* Get settings for repository instance.
*
* @param string $config a specific option to get.
* @return mixed returns an array of options. If $config is not empty, then it returns that option,
* or null if the option does not exist.
*/
public function get_option($config = '')
{
global $DB;
$cache = cache::make('core', 'repositories');
if (($entries = $cache->get('ops:' . $this->id)) === false) {
$entries = $DB->get_records('repository_instance_config', array('instanceid' => $this->id));
$cache->set('ops:' . $this->id, $entries);
}
$ret = array();
foreach ($entries as $entry) {
$ret[$entry->name] = $entry->value;
}
if (!empty($config)) {
if (isset($ret[$config])) {
return $ret[$config];
} else {
return null;
}
} else {
return $ret;
}
}
示例6: __construct
/**
* Override the cache::construct method.
*
* This function gets overriden so that we can process any invalidation events if need be.
* If the definition doesn't have any invalidation events then this occurs exactly as it would for the cache class.
* Otherwise we look at the last invalidation time and then check the invalidation data for events that have occured
* between then now.
*
* You should not call this method from your code, instead you should use the cache::make methods.
*
* @param cache_definition $definition
* @param cache_store $store
* @param cache_loader|cache_data_source $loader
*/
public function __construct(cache_definition $definition, cache_store $store, $loader = null)
{
// First up copy the loadeduserid to the current user id.
$this->currentuserid = self::$loadeduserid;
parent::__construct($definition, $store, $loader);
// This will trigger check tracked user. If this gets removed a call to that will need to be added here in its place.
$this->set(self::LASTACCESS, cache::now());
if ($definition->has_invalidation_events()) {
$lastinvalidation = $this->get('lastsessioninvalidation');
if ($lastinvalidation === false) {
// This is a new session, there won't be anything to invalidate. Set the time of the last invalidation and
// move on.
$this->set('lastsessioninvalidation', cache::now());
return;
} else {
if ($lastinvalidation == cache::now()) {
// We've already invalidated during this request.
return;
}
}
// Get the event invalidation cache.
$cache = cache::make('core', 'eventinvalidation');
$events = $cache->get_many($definition->get_invalidation_events());
$todelete = array();
$purgeall = false;
// Iterate the returned data for the events.
foreach ($events as $event => $keys) {
if ($keys === false) {
// No data to be invalidated yet.
continue;
}
// Look at each key and check the timestamp.
foreach ($keys as $key => $timestamp) {
// If the timestamp of the event is more than or equal to the last invalidation (happened between the last
// invalidation and now)then we need to invaliate the key.
if ($timestamp >= $lastinvalidation) {
if ($key === 'purged') {
$purgeall = true;
break;
} else {
$todelete[] = $key;
}
}
}
}
if ($purgeall) {
$this->purge();
} else {
if (!empty($todelete)) {
$todelete = array_unique($todelete);
$this->delete_many($todelete);
}
}
// Set the time of the last invalidation.
$this->set('lastsessioninvalidation', cache::now());
}
}
示例7: sync_reference
/**
* Performs synchronisation of an external file if the previous one has expired.
*
* This function must be implemented for external repositories supporting
* FILE_REFERENCE, it is called for existing aliases when their filesize,
* contenthash or timemodified are requested. It is not called for internal
* repositories (see {@link repository::has_moodle_files()}), references to
* internal files are updated immediately when source is modified.
*
* Referenced files may optionally keep their content in Moodle filepool (for
* thumbnail generation or to be able to serve cached copy). In this
* case both contenthash and filesize need to be synchronized. Otherwise repositories
* should use contenthash of empty file and correct filesize in bytes.
*
* Note that this function may be run for EACH file that needs to be synchronised at the
* moment. If anything is being downloaded or requested from external sources there
* should be a small timeout. The synchronisation is performed to update the size of
* the file and/or to update image and re-generated image preview. There is nothing
* fatal if syncronisation fails but it is fatal if syncronisation takes too long
* and hangs the script generating a page.
*
* Note: If you wish to call $file->get_filesize(), $file->get_contenthash() or
* $file->get_timemodified() make sure that recursion does not happen.
*
* Called from {@link stored_file::sync_external_file()}
*
* @uses stored_file::set_missingsource()
* @uses stored_file::set_synchronized()
* @param stored_file $file
* @return bool false when file does not need synchronisation, true if it was synchronised
*/
public function sync_reference(stored_file $file) {
if ($file->get_repository_id() != $this->id) {
// This should not really happen because the function can be called from stored_file only.
return false;
}
if ($this->has_moodle_files()) {
// References to local files need to be synchronised only once.
// Later they will be synchronised automatically when the source is changed.
if ($file->get_referencelastsync()) {
return false;
}
$fs = get_file_storage();
$params = file_storage::unpack_reference($file->get_reference(), true);
if (!is_array($params) || !($storedfile = $fs->get_file($params['contextid'],
$params['component'], $params['filearea'], $params['itemid'], $params['filepath'],
$params['filename']))) {
$file->set_missingsource();
} else {
$file->set_synchronized($storedfile->get_contenthash(), $storedfile->get_filesize());
}
return true;
}
// Backward compatibility (Moodle 2.3-2.5) implementation that calls
// methods repository::get_reference_file_lifetime(), repository::sync_individual_file()
// and repository::get_file_by_reference(). These methods are removed from the
// base repository class but may still be implemented by the child classes.
// THIS IS NOT A GOOD EXAMPLE of implementation. For good examples see the overwriting methods.
if (!method_exists($this, 'get_file_by_reference')) {
// Function get_file_by_reference() is not implemented. No synchronisation.
return false;
}
// Check if the previous sync result is still valid.
if (method_exists($this, 'get_reference_file_lifetime')) {
$lifetime = $this->get_reference_file_lifetime($file->get_reference());
} else {
// Default value that was hardcoded in Moodle 2.3 - 2.5.
$lifetime = 60 * 60 * 24;
}
if (($lastsynced = $file->get_referencelastsync()) && $lastsynced + $lifetime >= time()) {
return false;
}
$cache = cache::make('core', 'repositories');
if (($lastsyncresult = $cache->get('sync:'.$file->get_referencefileid())) !== false) {
if ($lastsyncresult === true) {
// We are in the process of synchronizing this reference.
// Avoid recursion when calling $file->get_filesize() and $file->get_contenthash().
return false;
} else {
// We have synchronised the same reference inside this request already.
// It looks like the object $file was created before the synchronisation and contains old data.
if (!empty($lastsyncresult['missing'])) {
$file->set_missingsource();
} else {
$cache->set('sync:'.$file->get_referencefileid(), true);
if ($file->get_contenthash() != $lastsyncresult['contenthash'] ||
$file->get_filesize() != $lastsyncresult['filesize']) {
$file->set_synchronized($lastsyncresult['contenthash'], $lastsyncresult['filesize']);
}
$cache->set('sync:'.$file->get_referencefileid(), $lastsyncresult);
}
return true;
}
}
//.........这里部分代码省略.........
示例8: get_temp_tables_cache
/**
* Handle the creation and caching of the temporary tables.
*
* @return cache_application The temp_tables cachestore to complete operations on.
*/
protected function get_temp_tables_cache()
{
// Using connection data to prevent collisions when using the same temp table name with different db connections.
$properties = array('dbfamily' => $this->get_dbfamily(), 'settings' => $this->get_settings_hash());
return cache::make('core', 'temp_tables', $properties);
}
示例9: add_moodle_metadata
/**
* Add the moodle YUI module metadata for the moodle group to the YUI_config instance.
*
* If js caching is disabled, metadata will not be served causing YUI to calculate
* module dependencies as each module is loaded.
*
* If metadata does not exist it will be created and stored in a MUC entry.
*
* @return void
*/
public function add_moodle_metadata()
{
global $CFG;
if (!isset($this->groups['moodle'])) {
throw new coding_exception('The Moodle YUI module does not exist. You must define the moodle module config using YUI_config->add_module_config first.');
}
if (!isset($this->groups['moodle']['modules'])) {
$this->groups['moodle']['modules'] = array();
}
$cache = cache::make('core', 'yuimodules');
if (!isset($CFG->jsrev) || $CFG->jsrev == -1) {
$metadata = array();
$cache->delete('metadata');
} else {
// Attempt to get the metadata from the cache.
if (!($metadata = $cache->get('metadata'))) {
$metadata = $this->get_moodle_metadata();
$cache->set('metadata', $metadata);
}
}
// Merge with any metadata added specific to this page which was added manually.
$this->groups['moodle']['modules'] = array_merge($this->groups['moodle']['modules'], $metadata);
}
示例10: get_enabled_portfolios
/**
* Returns list of enabled portfolio plugins
*
* Portfolio plugin is enabled if there is at least one record in the {portfolio_instance}
* table for it.
*
* @param bool $disablecache do not attempt to obtain data from the cache
* @return array array of stdClasses with properties plugin and visible indexed by plugin
*/
protected static function get_enabled_portfolios($disablecache = false)
{
global $DB;
$cache = cache::make('core', 'plugininfo_portfolio');
$enabled = $cache->get('enabled');
if ($enabled === false or $disablecache) {
$enabled = array();
$instances = $DB->get_recordset('portfolio_instance', null, '', 'plugin,visible');
foreach ($instances as $instance) {
if (isset($enabled[$instance->plugin])) {
if ($instance->visible) {
$enabled[$instance->plugin]->visible = $instance->visible;
}
} else {
$enabled[$instance->plugin] = $instance;
}
}
$instances->close();
$cache->set('enabled', $enabled);
}
return $enabled;
}
示例11: purify_html
/**
* KSES replacement cleaning function - uses HTML Purifier.
*
* @param string $text The (X)HTML string to purify
* @param array $options Array of options; currently only option supported is 'allowid' (if set,
* does not remove id attributes when cleaning)
* @return string
*/
function purify_html($text, $options = array())
{
global $CFG;
$text = (string) $text;
static $purifiers = array();
static $caches = array();
// Purifier code can change only during major version upgrade.
$version = empty($CFG->version) ? 0 : $CFG->version;
$cachedir = "{$CFG->localcachedir}/htmlpurifier/{$version}";
if (!file_exists($cachedir)) {
// Purging of caches may remove the cache dir at any time,
// luckily file_exists() results should be cached for all existing directories.
$purifiers = array();
$caches = array();
gc_collect_cycles();
make_localcache_directory('htmlpurifier', false);
check_dir_exists($cachedir);
}
$allowid = empty($options['allowid']) ? 0 : 1;
$allowobjectembed = empty($CFG->allowobjectembed) ? 0 : 1;
$type = 'type_' . $allowid . '_' . $allowobjectembed;
if (!array_key_exists($type, $caches)) {
$caches[$type] = cache::make('core', 'htmlpurifier', array('type' => $type));
}
$cache = $caches[$type];
// Add revision number and all options to the text key so that it is compatible with local cluster node caches.
$key = "|{$version}|{$allowobjectembed}|{$allowid}|{$text}";
$filteredtext = $cache->get($key);
if ($filteredtext === true) {
// The filtering did not change the text last time, no need to filter anything again.
return $text;
} else {
if ($filteredtext !== false) {
return $filteredtext;
}
}
if (empty($purifiers[$type])) {
require_once $CFG->libdir . '/htmlpurifier/HTMLPurifier.safe-includes.php';
require_once $CFG->libdir . '/htmlpurifier/locallib.php';
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.DefinitionID', 'moodlehtml');
$config->set('HTML.DefinitionRev', 2);
$config->set('Cache.SerializerPath', $cachedir);
$config->set('Cache.SerializerPermissions', $CFG->directorypermissions);
$config->set('Core.NormalizeNewlines', false);
$config->set('Core.ConvertDocumentToFragment', true);
$config->set('Core.Encoding', 'UTF-8');
$config->set('HTML.Doctype', 'XHTML 1.0 Transitional');
$config->set('URI.AllowedSchemes', array('http' => true, 'https' => true, 'ftp' => true, 'irc' => true, 'nntp' => true, 'news' => true, 'rtsp' => true, 'rtmp' => true, 'teamspeak' => true, 'gopher' => true, 'mms' => true, 'mailto' => true));
$config->set('Attr.AllowedFrameTargets', array('_blank'));
if ($allowobjectembed) {
$config->set('HTML.SafeObject', true);
$config->set('Output.FlashCompat', true);
$config->set('HTML.SafeEmbed', true);
}
if ($allowid) {
$config->set('Attr.EnableID', true);
}
if ($def = $config->maybeGetRawHTMLDefinition()) {
$def->addElement('nolink', 'Block', 'Flow', array());
// Skip our filters inside.
$def->addElement('tex', 'Inline', 'Inline', array());
// Tex syntax, equivalent to $$xx$$.
$def->addElement('algebra', 'Inline', 'Inline', array());
// Algebra syntax, equivalent to @@xx@@.
$def->addElement('lang', 'Block', 'Flow', array(), array('lang' => 'CDATA'));
// Original multilang style - only our hacked lang attribute.
$def->addAttribute('span', 'xxxlang', 'CDATA');
// Current very problematic multilang.
}
$purifier = new HTMLPurifier($config);
$purifiers[$type] = $purifier;
} else {
$purifier = $purifiers[$type];
}
$multilang = strpos($text, 'class="multilang"') !== false;
$filteredtext = $text;
if ($multilang) {
$filteredtextregex = '/<span(\\s+lang="([a-zA-Z0-9_-]+)"|\\s+class="multilang"){2}\\s*>/';
$filteredtext = preg_replace($filteredtextregex, '<span xxxlang="${2}">', $filteredtext);
}
$filteredtext = (string) $purifier->purify($filteredtext);
if ($multilang) {
$filteredtext = preg_replace('/<span xxxlang="([a-zA-Z0-9_-]+)">/', '<span lang="${1}" class="multilang">', $filteredtext);
}
if ($text === $filteredtext) {
// No need to store the filtered text, next time we will just return unfiltered text
// because it was not changed by purifying.
$cache->set($key, true);
} else {
$cache->set($key, $filteredtext);
}
//.........这里部分代码省略.........
示例12: invalidate_filters_cache
/**
* Invalidate the filters cache.
*
* @return void
*/
public function invalidate_filters_cache()
{
$cache = cache::make('block_xp', 'filters');
$cache->delete('filters_' . $this->manager->get_courseid());
}
示例13: header
$moodle_url = "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . "/moodle";
header('Location: ' . $moodle_url);
}
// get the OMERO server URL
$omero_server = get_config('omero', 'omero_restendpoint');
// get the Image ID
$image_id = required_param("id", PARAM_INT);
// get the Image LastUpdate
$image_last_update = required_param("lastUpdate", PARAM_INT);
// get the size of the image thumbnail
$image_width = optional_param("width", 128, PARAM_INT);
$image_height = optional_param("height", 128, PARAM_INT);
// optional param for forcing image reload
$force_reload = optional_param("force", false, PARAM_BOOL);
// get a reference to the cache
$cache = cache::make('repository_omero', 'thumbnail_cache');
// computer the key of the cached element
$cache_key = urlencode("{$omero_server}-{$image_id}-{$image_last_update}");
// try to the get thumbnail from the cache
$file = $force_reload ? null : $cache->get($cache_key);
// download the file is needed and update the cache
if ($force_reload || !$file) {
$cache->acquire_lock($cache_key);
try {
$file = $force_reload ? null : $cache->get($cache_key);
if (!$file) {
$url = "{$omero_server}/ome_seadragon/deepzoom/get/thumbnail/{$image_id}.dzi";
//$url = "${omero_server}/webgateway/render_thumbnail/${image_id}/${image_width}/${image_height}";
$c = new curl();
$file = $c->download_one($url, array("size" => $image_height, "width" => $image_width, "height" => $image_height));
if ($file) {
示例14: block_progress_attempts
/**
* Checked if a user has attempted/viewed/etc. an activity/resource
*
* @param array $modules The modules used in the course
* @param stdClass $config The blocks configuration settings
* @param array $events The possible events that can occur for modules
* @param int $userid The user's id
* @param int $instance The instance of the block
* @return array an describing the user's attempts based on module+instance identifiers
*/
function block_progress_attempts($modules, $config, $events, $userid, $course)
{
global $DB;
$attempts = array();
$modernlogging = false;
$cachingused = false;
// Get readers for 2.7 onwards.
if (function_exists('get_log_manager')) {
$modernlogging = true;
$logmanager = get_log_manager();
$readers = $logmanager->get_readers();
$numreaders = count($readers);
}
// Get cache store if caching is working 2.4 onwards.
if (class_exists('cache')) {
$cachingused = true;
$cachedlogs = cache::make('block_progress', 'cachedlogs');
$cachedlogviews = $cachedlogs->get($userid);
if (empty($cachedlogviews)) {
$cachedlogviews = array();
}
$cachedlogsupdated = false;
}
foreach ($events as $event) {
$module = $modules[$event['type']];
$uniqueid = $event['type'] . $event['id'];
$parameters = array('courseid' => $course, 'courseid1' => $course, 'userid' => $userid, 'userid1' => $userid, 'eventid' => $event['id'], 'eventid1' => $event['id'], 'cmid' => $event['cm']->id, 'cmid1' => $event['cm']->id);
// Check for passing grades as unattempted, passed or failed.
if (isset($config->{'action_' . $uniqueid}) && $config->{'action_' . $uniqueid} == 'passed') {
$query = $module['actions'][$config->{'action_' . $uniqueid}];
$graderesult = $DB->get_record_sql($query, $parameters);
if ($graderesult === false || $graderesult->finalgrade === null) {
$attempts[$uniqueid] = false;
} else {
$attempts[$uniqueid] = $graderesult->finalgrade >= $graderesult->gradepass ? true : 'failed';
}
} else {
if (isset($config->{'action_' . $uniqueid}) && $config->{'action_' . $uniqueid} == 'viewed') {
$attempts[$uniqueid] = false;
// Check if the value is cached.
if ($cachingused && array_key_exists($uniqueid, $cachedlogviews) && $cachedlogviews[$uniqueid]) {
$attempts[$uniqueid] = true;
} else {
if ($modernlogging) {
foreach ($readers as $logstore => $reader) {
if ($reader instanceof \core\log\sql_internal_table_reader || $reader instanceof \core\log\sql_internal_reader) {
$logtable = '{' . $reader->get_internal_log_table_name() . '}';
$query = preg_replace('/\\{log\\}/', $logtable, $module['actions']['viewed']['sql_internal_reader']);
} else {
if ($reader instanceof logstore_legacy\log\store) {
$query = $module['actions']['viewed']['logstore_legacy'];
} else {
// No logs available.
continue;
}
}
$attempts[$uniqueid] = $DB->record_exists_sql($query, $parameters) ? true : false;
if ($attempts[$uniqueid]) {
$cachedlogviews[$uniqueid] = true;
$cachedlogsupdated = true;
break;
}
}
} else {
$query = $module['actions']['viewed']['logstore_legacy'];
$attempts[$uniqueid] = $DB->record_exists_sql($query, $parameters) ? true : false;
if ($cachingused && $attempts[$uniqueid]) {
$cachedlogviews[$uniqueid] = true;
$cachedlogsupdated = true;
}
}
}
} else {
// If activity completion is used, check completions table.
if (isset($config->{'action_' . $uniqueid}) && $config->{'action_' . $uniqueid} == 'activity_completion') {
$query = 'SELECT id
FROM {course_modules_completion}
WHERE userid = :userid
AND coursemoduleid = :cmid
AND completionstate >= 1';
} else {
$action = isset($config->{'action_' . $uniqueid}) ? $config->{'action_' . $uniqueid} : $module['defaultAction'];
$query = $module['actions'][$action];
}
// Check if the user has attempted the module.
$attempts[$uniqueid] = $DB->record_exists_sql($query, $parameters) ? true : false;
}
}
}
// Update log cache if new values were added.
//.........这里部分代码省略.........
示例15: calendar_update_subscription
/**
* Update a calendar subscription. Also updates the associated cache.
*
* @param stdClass|array $subscription Subscription record.
* @throws coding_exception If something goes wrong
* @since Moodle 2.5
*/
function calendar_update_subscription($subscription)
{
global $DB;
if (is_array($subscription)) {
$subscription = (object) $subscription;
}
if (empty($subscription->id) || !$DB->record_exists('event_subscriptions', array('id' => $subscription->id))) {
throw new coding_exception('Cannot update a subscription without a valid id');
}
$DB->update_record('event_subscriptions', $subscription);
// Update cache.
$cache = cache::make('core', 'calendar_subscriptions');
$cache->set($subscription->id, $subscription);
// Trigger event, calendar subscription updated.
$eventparams = array('userid' => $subscription->userid, 'objectid' => $subscription->id, 'context' => calendar_get_calendar_context($subscription), 'other' => array('eventtype' => $subscription->eventtype, 'courseid' => $subscription->courseid));
$event = \core\event\calendar_subscription_updated::create($eventparams);
$event->trigger();
}