/** * Get the global static instance of mr_var * * @return mr_var */ public static function instance() { if (self::$_instance === NULL) { // Automatically set mrconfig $config = get_config('local/mr'); if (empty($config)) { $config = new stdClass(); } self::$_instance = new mr_var(array('mrconfig' => $config)); } return self::$_instance; }
/** * Constructor - create a new interface to the cache * * @param string $prefix Prefix all cache IDs with this string */ public function __construct($prefix = NULL) { // Setup Zend mr_bootstrap::zend(); require_once 'Zend/Cache.php'; require_once 'Zend/Cache/Exception.php'; // For prefixes, switch forward slashes, which are not accepted, to underscores if (!is_null($prefix)) { $prefix = str_replace('/', '_', $prefix); } // DISABLED!!! Not yet implemented on our servers if (defined('MR_CACHE_TEST') and !empty(mr_var::instance()->get('mrconfig')->cache_lifetime)) { $frontendoptions = array('cache_id_prefix' => $prefix, 'lifetime' => mr_var::instance()->get('mrconfig')->cache_lifetime); $backendoptions = array(); try { $this->cache = Zend_Cache::factory(self::FRONTEND, self::BACKEND, $frontendoptions, $backendoptions); } catch (Zend_Cache_Exception $e) { $this->cache = false; } } }
/** * Get global plugin config * * @return object * @example settings.php See how to save global config to work with this method * @todo This should use $this->component instead of $this->plugin. This will break mod/assignment/efolio */ public function get_config() { if (!mr_var::instance()->exists($this->plugin)) { if (!($config = get_config($this->plugin))) { $config = new stdClass(); } mr_var::instance()->set($this->plugin, $config); } return mr_var::instance()->get($this->plugin); }
public function test_cache_broken() { if (!defined('MR_CACHE_TEST')) { return; } $old = mr_var::instance()->get('mrconfig')->cache_lifetime; mr_var::instance()->get('mrconfig')->cache_lifetime = 0; $cache = new mr_cache('test/mr/cache'); $this->assertFalse($cache->test('key')); $this->assertTrue($cache->save('value', 'key')); $this->assertFalse($cache->test('key')); $this->assertFalse($cache->load('key')); $this->assertTrue($cache->touch('key', 60)); $this->assertTrue($cache->remove('key')); mr_var::instance()->get('mrconfig')->cache_lifetime = $old; }
/** * Construct * * @param moodle_url $url Base URL * @param int $courseid Course ID * @param boolean $autorun Automatically run the report SQL and * retrieve rows for rendering or exporting */ public function __construct(moodle_url $url, $courseid = NULL, $autorun = true) { if (is_null($courseid) or $courseid == 0) { $courseid = SITEID; } $this->url = $url; $this->courseid = $courseid; $this->config = new mr_var(); $this->preferences = new mr_preferences($courseid, $this->type()); // Setup config defaults $this->config->set(array('cache' => false, 'ajax' => false, 'ajaxdefault' => 1, 'export' => false, 'maxrows' => 65000, 'perpage' => false, 'perpageopts' => array('all', 10, 25, 50, 100, 200, 500, 1000))); $this->_init(); if ($autorun) { $this->run(); } }
/** * A config setter - overwrites old value * * @param string $name Name of the config to set * @param mixed $value The value of the config * @return mr_html_table_column */ public function set_config($name, $value) { $this->config->set($name, $value); return $this; }