id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
212,000
moodle/moodle
files/converter/unoconv/classes/converter.php
converter.is_minimum_version_met
protected static function is_minimum_version_met() { global $CFG; $currentversion = 0; $supportedversion = 0.7; $unoconvbin = \escapeshellarg($CFG->pathtounoconv); $command = "$unoconvbin --version"; exec($command, $output); // If the command execution returned some output, then get the unoconv version. if ($output) { foreach ($output as $response) { if (preg_match('/unoconv (\\d+\\.\\d+)/', $response, $matches)) { $currentversion = (float) $matches[1]; } } if ($currentversion < $supportedversion) { return false; } else { return true; } } return false; }
php
protected static function is_minimum_version_met() { global $CFG; $currentversion = 0; $supportedversion = 0.7; $unoconvbin = \escapeshellarg($CFG->pathtounoconv); $command = "$unoconvbin --version"; exec($command, $output); // If the command execution returned some output, then get the unoconv version. if ($output) { foreach ($output as $response) { if (preg_match('/unoconv (\\d+\\.\\d+)/', $response, $matches)) { $currentversion = (float) $matches[1]; } } if ($currentversion < $supportedversion) { return false; } else { return true; } } return false; }
[ "protected", "static", "function", "is_minimum_version_met", "(", ")", "{", "global", "$", "CFG", ";", "$", "currentversion", "=", "0", ";", "$", "supportedversion", "=", "0.7", ";", "$", "unoconvbin", "=", "\\", "escapeshellarg", "(", "$", "CFG", "->", "pathtounoconv", ")", ";", "$", "command", "=", "\"$unoconvbin --version\"", ";", "exec", "(", "$", "command", ",", "$", "output", ")", ";", "// If the command execution returned some output, then get the unoconv version.", "if", "(", "$", "output", ")", "{", "foreach", "(", "$", "output", "as", "$", "response", ")", "{", "if", "(", "preg_match", "(", "'/unoconv (\\\\d+\\\\.\\\\d+)/'", ",", "$", "response", ",", "$", "matches", ")", ")", "{", "$", "currentversion", "=", "(", "float", ")", "$", "matches", "[", "1", "]", ";", "}", "}", "if", "(", "$", "currentversion", "<", "$", "supportedversion", ")", "{", "return", "false", ";", "}", "else", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Whether the minimum version of unoconv has been met. @return bool
[ "Whether", "the", "minimum", "version", "of", "unoconv", "has", "been", "met", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/files/converter/unoconv/classes/converter.php#L237-L261
212,001
moodle/moodle
files/converter/unoconv/classes/converter.php
converter.is_format_supported
protected static function is_format_supported($format) { $formats = self::fetch_supported_formats(); $format = trim(\core_text::strtolower($format)); return in_array($format, $formats); }
php
protected static function is_format_supported($format) { $formats = self::fetch_supported_formats(); $format = trim(\core_text::strtolower($format)); return in_array($format, $formats); }
[ "protected", "static", "function", "is_format_supported", "(", "$", "format", ")", "{", "$", "formats", "=", "self", "::", "fetch_supported_formats", "(", ")", ";", "$", "format", "=", "trim", "(", "\\", "core_text", "::", "strtolower", "(", "$", "format", ")", ")", ";", "return", "in_array", "(", "$", "format", ",", "$", "formats", ")", ";", "}" ]
Whether the specified file format is supported. @param string $format Whether conversions between this format and another are supported @return bool
[ "Whether", "the", "specified", "file", "format", "is", "supported", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/files/converter/unoconv/classes/converter.php#L319-L324
212,002
moodle/moodle
files/converter/unoconv/classes/converter.php
converter.fetch_supported_formats
protected static function fetch_supported_formats() { global $CFG; if (!isset(self::$formats)) { // Ask unoconv for it's list of supported document formats. $cmd = escapeshellcmd(trim($CFG->pathtounoconv)) . ' --show'; $pipes = array(); $pipesspec = array(2 => array('pipe', 'w')); $proc = proc_open($cmd, $pipesspec, $pipes); $programoutput = stream_get_contents($pipes[2]); fclose($pipes[2]); proc_close($proc); $matches = array(); preg_match_all('/\[\.(.*)\]/', $programoutput, $matches); $formats = $matches[1]; self::$formats = array_unique($formats); } return self::$formats; }
php
protected static function fetch_supported_formats() { global $CFG; if (!isset(self::$formats)) { // Ask unoconv for it's list of supported document formats. $cmd = escapeshellcmd(trim($CFG->pathtounoconv)) . ' --show'; $pipes = array(); $pipesspec = array(2 => array('pipe', 'w')); $proc = proc_open($cmd, $pipesspec, $pipes); $programoutput = stream_get_contents($pipes[2]); fclose($pipes[2]); proc_close($proc); $matches = array(); preg_match_all('/\[\.(.*)\]/', $programoutput, $matches); $formats = $matches[1]; self::$formats = array_unique($formats); } return self::$formats; }
[ "protected", "static", "function", "fetch_supported_formats", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "formats", ")", ")", "{", "// Ask unoconv for it's list of supported document formats.", "$", "cmd", "=", "escapeshellcmd", "(", "trim", "(", "$", "CFG", "->", "pathtounoconv", ")", ")", ".", "' --show'", ";", "$", "pipes", "=", "array", "(", ")", ";", "$", "pipesspec", "=", "array", "(", "2", "=>", "array", "(", "'pipe'", ",", "'w'", ")", ")", ";", "$", "proc", "=", "proc_open", "(", "$", "cmd", ",", "$", "pipesspec", ",", "$", "pipes", ")", ";", "$", "programoutput", "=", "stream_get_contents", "(", "$", "pipes", "[", "2", "]", ")", ";", "fclose", "(", "$", "pipes", "[", "2", "]", ")", ";", "proc_close", "(", "$", "proc", ")", ";", "$", "matches", "=", "array", "(", ")", ";", "preg_match_all", "(", "'/\\[\\.(.*)\\]/'", ",", "$", "programoutput", ",", "$", "matches", ")", ";", "$", "formats", "=", "$", "matches", "[", "1", "]", ";", "self", "::", "$", "formats", "=", "array_unique", "(", "$", "formats", ")", ";", "}", "return", "self", "::", "$", "formats", ";", "}" ]
Fetch the list of supported file formats. @return array
[ "Fetch", "the", "list", "of", "supported", "file", "formats", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/files/converter/unoconv/classes/converter.php#L331-L351
212,003
moodle/moodle
lib/classes/session/redis.php
redis.handler_close
public function handler_close() { try { foreach ($this->locks as $id => $expirytime) { if ($expirytime > $this->time()) { $this->unlock_session($id); } unset($this->locks[$id]); } } catch (RedisException $e) { error_log('Failed talking to redis: '.$e->getMessage()); return false; } return true; }
php
public function handler_close() { try { foreach ($this->locks as $id => $expirytime) { if ($expirytime > $this->time()) { $this->unlock_session($id); } unset($this->locks[$id]); } } catch (RedisException $e) { error_log('Failed talking to redis: '.$e->getMessage()); return false; } return true; }
[ "public", "function", "handler_close", "(", ")", "{", "try", "{", "foreach", "(", "$", "this", "->", "locks", "as", "$", "id", "=>", "$", "expirytime", ")", "{", "if", "(", "$", "expirytime", ">", "$", "this", "->", "time", "(", ")", ")", "{", "$", "this", "->", "unlock_session", "(", "$", "id", ")", ";", "}", "unset", "(", "$", "this", "->", "locks", "[", "$", "id", "]", ")", ";", "}", "}", "catch", "(", "RedisException", "$", "e", ")", "{", "error_log", "(", "'Failed talking to redis: '", ".", "$", "e", "->", "getMessage", "(", ")", ")", ";", "return", "false", ";", "}", "return", "true", ";", "}" ]
Close the session completely. We also remove all locks we may have obtained that aren't expired. @return bool true on success. false on unable to unlock sessions.
[ "Close", "the", "session", "completely", ".", "We", "also", "remove", "all", "locks", "we", "may", "have", "obtained", "that", "aren", "t", "expired", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/session/redis.php#L233-L247
212,004
moodle/moodle
lib/classes/session/redis.php
redis.handler_read
public function handler_read($id) { try { $this->lock_session($id); $sessiondata = $this->connection->get($id); if ($sessiondata === false) { $this->unlock_session($id); return ''; } $this->connection->expire($id, $this->timeout); } catch (RedisException $e) { error_log('Failed talking to redis: '.$e->getMessage()); throw $e; } return $sessiondata; }
php
public function handler_read($id) { try { $this->lock_session($id); $sessiondata = $this->connection->get($id); if ($sessiondata === false) { $this->unlock_session($id); return ''; } $this->connection->expire($id, $this->timeout); } catch (RedisException $e) { error_log('Failed talking to redis: '.$e->getMessage()); throw $e; } return $sessiondata; }
[ "public", "function", "handler_read", "(", "$", "id", ")", "{", "try", "{", "$", "this", "->", "lock_session", "(", "$", "id", ")", ";", "$", "sessiondata", "=", "$", "this", "->", "connection", "->", "get", "(", "$", "id", ")", ";", "if", "(", "$", "sessiondata", "===", "false", ")", "{", "$", "this", "->", "unlock_session", "(", "$", "id", ")", ";", "return", "''", ";", "}", "$", "this", "->", "connection", "->", "expire", "(", "$", "id", ",", "$", "this", "->", "timeout", ")", ";", "}", "catch", "(", "RedisException", "$", "e", ")", "{", "error_log", "(", "'Failed talking to redis: '", ".", "$", "e", "->", "getMessage", "(", ")", ")", ";", "throw", "$", "e", ";", "}", "return", "$", "sessiondata", ";", "}" ]
Read the session data from storage @param string $id The session id to read from storage. @return string The session data for PHP to process. @throws RedisException when we are unable to talk to the Redis server.
[ "Read", "the", "session", "data", "from", "storage" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/session/redis.php#L256-L270
212,005
moodle/moodle
lib/classes/session/redis.php
redis.handler_write
public function handler_write($id, $data) { if (is_null($this->connection)) { // The session has already been closed, don't attempt another write. error_log('Tried to write session: '.$id.' before open or after close.'); return false; } // We do not do locking here because memcached doesn't. Also // PHP does open, read, destroy, write, close. When a session doesn't exist. // There can be race conditions on new sessions racing each other but we can // address that in the future. try { $this->connection->setex($id, $this->timeout, $data); } catch (RedisException $e) { error_log('Failed talking to redis: '.$e->getMessage()); return false; } return true; }
php
public function handler_write($id, $data) { if (is_null($this->connection)) { // The session has already been closed, don't attempt another write. error_log('Tried to write session: '.$id.' before open or after close.'); return false; } // We do not do locking here because memcached doesn't. Also // PHP does open, read, destroy, write, close. When a session doesn't exist. // There can be race conditions on new sessions racing each other but we can // address that in the future. try { $this->connection->setex($id, $this->timeout, $data); } catch (RedisException $e) { error_log('Failed talking to redis: '.$e->getMessage()); return false; } return true; }
[ "public", "function", "handler_write", "(", "$", "id", ",", "$", "data", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "connection", ")", ")", "{", "// The session has already been closed, don't attempt another write.", "error_log", "(", "'Tried to write session: '", ".", "$", "id", ".", "' before open or after close.'", ")", ";", "return", "false", ";", "}", "// We do not do locking here because memcached doesn't. Also", "// PHP does open, read, destroy, write, close. When a session doesn't exist.", "// There can be race conditions on new sessions racing each other but we can", "// address that in the future.", "try", "{", "$", "this", "->", "connection", "->", "setex", "(", "$", "id", ",", "$", "this", "->", "timeout", ",", "$", "data", ")", ";", "}", "catch", "(", "RedisException", "$", "e", ")", "{", "error_log", "(", "'Failed talking to redis: '", ".", "$", "e", "->", "getMessage", "(", ")", ")", ";", "return", "false", ";", "}", "return", "true", ";", "}" ]
Write the serialized session data to our session store. @param string $id session id to write. @param string $data session data @return bool true on write success, false on failure
[ "Write", "the", "serialized", "session", "data", "to", "our", "session", "store", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/session/redis.php#L279-L297
212,006
moodle/moodle
lib/classes/session/redis.php
redis.handler_destroy
public function handler_destroy($id) { try { $this->connection->del($id); $this->unlock_session($id); } catch (RedisException $e) { error_log('Failed talking to redis: '.$e->getMessage()); return false; } return true; }
php
public function handler_destroy($id) { try { $this->connection->del($id); $this->unlock_session($id); } catch (RedisException $e) { error_log('Failed talking to redis: '.$e->getMessage()); return false; } return true; }
[ "public", "function", "handler_destroy", "(", "$", "id", ")", "{", "try", "{", "$", "this", "->", "connection", "->", "del", "(", "$", "id", ")", ";", "$", "this", "->", "unlock_session", "(", "$", "id", ")", ";", "}", "catch", "(", "RedisException", "$", "e", ")", "{", "error_log", "(", "'Failed talking to redis: '", ".", "$", "e", "->", "getMessage", "(", ")", ")", ";", "return", "false", ";", "}", "return", "true", ";", "}" ]
Handle destroying a session. @param string $id the session id to destroy. @return bool true if the session was deleted, false otherwise.
[ "Handle", "destroying", "a", "session", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/session/redis.php#L305-L315
212,007
moodle/moodle
lib/classes/session/redis.php
redis.unlock_session
protected function unlock_session($id) { if (isset($this->locks[$id])) { $this->connection->del($id.".lock"); unset($this->locks[$id]); } }
php
protected function unlock_session($id) { if (isset($this->locks[$id])) { $this->connection->del($id.".lock"); unset($this->locks[$id]); } }
[ "protected", "function", "unlock_session", "(", "$", "id", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "locks", "[", "$", "id", "]", ")", ")", "{", "$", "this", "->", "connection", "->", "del", "(", "$", "id", ".", "\".lock\"", ")", ";", "unset", "(", "$", "this", "->", "locks", "[", "$", "id", "]", ")", ";", "}", "}" ]
Unlock a session. @param string $id Session id to be unlocked.
[ "Unlock", "a", "session", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/session/redis.php#L332-L337
212,008
moodle/moodle
lib/classes/session/redis.php
redis.lock_session
protected function lock_session($id) { $lockkey = $id.".lock"; $haslock = isset($this->locks[$id]) && $this->time() < $this->locks[$id]; $startlocktime = $this->time(); /* To be able to ensure sessions don't write out of order we must obtain an exclusive lock * on the session for the entire time it is open. If another AJAX call, or page is using * the session then we just wait until it finishes before we can open the session. */ while (!$haslock) { $haslock = $this->connection->setnx($lockkey, '1'); if (!$haslock) { usleep(rand(100000, 1000000)); if ($this->time() > $startlocktime + $this->acquiretimeout) { // This is a fatal error, better inform users. // It should not happen very often - all pages that need long time to execute // should close session immediately after access control checks. error_log('Cannot obtain session lock for sid: '.$id.' within '.$this->acquiretimeout. '. It is likely another page has a long session lock, or the session lock was never released.'); throw new exception("Unable to obtain session lock"); } } else { $this->locks[$id] = $this->time() + $this->lockexpire; $this->connection->expire($lockkey, $this->lockexpire); return true; } } }
php
protected function lock_session($id) { $lockkey = $id.".lock"; $haslock = isset($this->locks[$id]) && $this->time() < $this->locks[$id]; $startlocktime = $this->time(); /* To be able to ensure sessions don't write out of order we must obtain an exclusive lock * on the session for the entire time it is open. If another AJAX call, or page is using * the session then we just wait until it finishes before we can open the session. */ while (!$haslock) { $haslock = $this->connection->setnx($lockkey, '1'); if (!$haslock) { usleep(rand(100000, 1000000)); if ($this->time() > $startlocktime + $this->acquiretimeout) { // This is a fatal error, better inform users. // It should not happen very often - all pages that need long time to execute // should close session immediately after access control checks. error_log('Cannot obtain session lock for sid: '.$id.' within '.$this->acquiretimeout. '. It is likely another page has a long session lock, or the session lock was never released.'); throw new exception("Unable to obtain session lock"); } } else { $this->locks[$id] = $this->time() + $this->lockexpire; $this->connection->expire($lockkey, $this->lockexpire); return true; } } }
[ "protected", "function", "lock_session", "(", "$", "id", ")", "{", "$", "lockkey", "=", "$", "id", ".", "\".lock\"", ";", "$", "haslock", "=", "isset", "(", "$", "this", "->", "locks", "[", "$", "id", "]", ")", "&&", "$", "this", "->", "time", "(", ")", "<", "$", "this", "->", "locks", "[", "$", "id", "]", ";", "$", "startlocktime", "=", "$", "this", "->", "time", "(", ")", ";", "/* To be able to ensure sessions don't write out of order we must obtain an exclusive lock\n * on the session for the entire time it is open. If another AJAX call, or page is using\n * the session then we just wait until it finishes before we can open the session.\n */", "while", "(", "!", "$", "haslock", ")", "{", "$", "haslock", "=", "$", "this", "->", "connection", "->", "setnx", "(", "$", "lockkey", ",", "'1'", ")", ";", "if", "(", "!", "$", "haslock", ")", "{", "usleep", "(", "rand", "(", "100000", ",", "1000000", ")", ")", ";", "if", "(", "$", "this", "->", "time", "(", ")", ">", "$", "startlocktime", "+", "$", "this", "->", "acquiretimeout", ")", "{", "// This is a fatal error, better inform users.", "// It should not happen very often - all pages that need long time to execute", "// should close session immediately after access control checks.", "error_log", "(", "'Cannot obtain session lock for sid: '", ".", "$", "id", ".", "' within '", ".", "$", "this", "->", "acquiretimeout", ".", "'. It is likely another page has a long session lock, or the session lock was never released.'", ")", ";", "throw", "new", "exception", "(", "\"Unable to obtain session lock\"", ")", ";", "}", "}", "else", "{", "$", "this", "->", "locks", "[", "$", "id", "]", "=", "$", "this", "->", "time", "(", ")", "+", "$", "this", "->", "lockexpire", ";", "$", "this", "->", "connection", "->", "expire", "(", "$", "lockkey", ",", "$", "this", "->", "lockexpire", ")", ";", "return", "true", ";", "}", "}", "}" ]
Obtain a session lock so we are the only one using it at the moent. @param string $id The session id to lock. @return bool true when session was locked, exception otherwise. @throws exception When we are unable to obtain a session lock.
[ "Obtain", "a", "session", "lock", "so", "we", "are", "the", "only", "one", "using", "it", "at", "the", "moent", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/session/redis.php#L346-L374
212,009
moodle/moodle
backup/util/ui/base_ui.class.php
base_ui.process
public function process() { if ($this->progress >= self::PROGRESS_PROCESSED) { throw new backup_ui_exception('backupuialreadyprocessed'); } $this->progress = self::PROGRESS_PROCESSED; if (optional_param('previous', false, PARAM_BOOL) && $this->stage->get_stage() > $this->get_first_stage_id()) { $this->stage = $this->initialise_stage($this->stage->get_prev_stage(), $this->stage->get_params()); return false; } // Process the stage. $processoutcome = $this->stage->process(); if ($processoutcome !== false) { $this->stage = $this->initialise_stage($this->stage->get_next_stage(), $this->stage->get_params()); } // Process UI event after to check changes are valid. $this->controller->process_ui_event(); return $processoutcome; }
php
public function process() { if ($this->progress >= self::PROGRESS_PROCESSED) { throw new backup_ui_exception('backupuialreadyprocessed'); } $this->progress = self::PROGRESS_PROCESSED; if (optional_param('previous', false, PARAM_BOOL) && $this->stage->get_stage() > $this->get_first_stage_id()) { $this->stage = $this->initialise_stage($this->stage->get_prev_stage(), $this->stage->get_params()); return false; } // Process the stage. $processoutcome = $this->stage->process(); if ($processoutcome !== false) { $this->stage = $this->initialise_stage($this->stage->get_next_stage(), $this->stage->get_params()); } // Process UI event after to check changes are valid. $this->controller->process_ui_event(); return $processoutcome; }
[ "public", "function", "process", "(", ")", "{", "if", "(", "$", "this", "->", "progress", ">=", "self", "::", "PROGRESS_PROCESSED", ")", "{", "throw", "new", "backup_ui_exception", "(", "'backupuialreadyprocessed'", ")", ";", "}", "$", "this", "->", "progress", "=", "self", "::", "PROGRESS_PROCESSED", ";", "if", "(", "optional_param", "(", "'previous'", ",", "false", ",", "PARAM_BOOL", ")", "&&", "$", "this", "->", "stage", "->", "get_stage", "(", ")", ">", "$", "this", "->", "get_first_stage_id", "(", ")", ")", "{", "$", "this", "->", "stage", "=", "$", "this", "->", "initialise_stage", "(", "$", "this", "->", "stage", "->", "get_prev_stage", "(", ")", ",", "$", "this", "->", "stage", "->", "get_params", "(", ")", ")", ";", "return", "false", ";", "}", "// Process the stage.", "$", "processoutcome", "=", "$", "this", "->", "stage", "->", "process", "(", ")", ";", "if", "(", "$", "processoutcome", "!==", "false", ")", "{", "$", "this", "->", "stage", "=", "$", "this", "->", "initialise_stage", "(", "$", "this", "->", "stage", "->", "get_next_stage", "(", ")", ",", "$", "this", "->", "stage", "->", "get_params", "(", ")", ")", ";", "}", "// Process UI event after to check changes are valid.", "$", "this", "->", "controller", "->", "process_ui_event", "(", ")", ";", "return", "$", "processoutcome", ";", "}" ]
This processes the current stage of the backup @throws backup_ui_exception @return bool
[ "This", "processes", "the", "current", "stage", "of", "the", "backup" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/base_ui.class.php#L124-L145
212,010
moodle/moodle
backup/util/ui/base_ui.class.php
base_ui.save_controller
public function save_controller() { if ($this->progress >= self::PROGRESS_SAVED) { throw new base_ui_exception('backupuialreadysaved'); } $this->progress = self::PROGRESS_SAVED; // First enforce dependencies. $this->enforce_dependencies(); // Process UI event after to check any changes are valid. $this->controller->process_ui_event(); // Save the controller. $this->controller->save_controller(); return true; }
php
public function save_controller() { if ($this->progress >= self::PROGRESS_SAVED) { throw new base_ui_exception('backupuialreadysaved'); } $this->progress = self::PROGRESS_SAVED; // First enforce dependencies. $this->enforce_dependencies(); // Process UI event after to check any changes are valid. $this->controller->process_ui_event(); // Save the controller. $this->controller->save_controller(); return true; }
[ "public", "function", "save_controller", "(", ")", "{", "if", "(", "$", "this", "->", "progress", ">=", "self", "::", "PROGRESS_SAVED", ")", "{", "throw", "new", "base_ui_exception", "(", "'backupuialreadysaved'", ")", ";", "}", "$", "this", "->", "progress", "=", "self", "::", "PROGRESS_SAVED", ";", "// First enforce dependencies.", "$", "this", "->", "enforce_dependencies", "(", ")", ";", "// Process UI event after to check any changes are valid.", "$", "this", "->", "controller", "->", "process_ui_event", "(", ")", ";", "// Save the controller.", "$", "this", "->", "controller", "->", "save_controller", "(", ")", ";", "return", "true", ";", "}" ]
Saves the backup controller. Once this has been called nothing else can be changed in the controller. @throws base_ui_exception @return bool
[ "Saves", "the", "backup", "controller", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/base_ui.class.php#L155-L167
212,011
moodle/moodle
backup/util/ui/base_ui.class.php
base_ui.display
public function display(core_backup_renderer $renderer) { if ($this->progress < self::PROGRESS_SAVED) { throw new base_ui_exception('backupsavebeforedisplay'); } return $this->stage->display($renderer); }
php
public function display(core_backup_renderer $renderer) { if ($this->progress < self::PROGRESS_SAVED) { throw new base_ui_exception('backupsavebeforedisplay'); } return $this->stage->display($renderer); }
[ "public", "function", "display", "(", "core_backup_renderer", "$", "renderer", ")", "{", "if", "(", "$", "this", "->", "progress", "<", "self", "::", "PROGRESS_SAVED", ")", "{", "throw", "new", "base_ui_exception", "(", "'backupsavebeforedisplay'", ")", ";", "}", "return", "$", "this", "->", "stage", "->", "display", "(", "$", "renderer", ")", ";", "}" ]
Displays the UI for the backup! @throws base_ui_exception @param core_backup_renderer $renderer @return string HTML code to echo
[ "Displays", "the", "UI", "for", "the", "backup!" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/base_ui.class.php#L176-L181
212,012
moodle/moodle
backup/util/ui/base_ui.class.php
base_ui.enforce_dependencies
protected function enforce_dependencies() { // Get the plan. $plan = $this->controller->get_plan(); // Get the tasks as a var so we can iterate by reference. $tasks = $plan->get_tasks(); $changes = 0; foreach ($tasks as &$task) { // Store as a var so we can iterate by reference. $settings = $task->get_settings(); foreach ($settings as &$setting) { // Get all dependencies for iteration by reference. $dependencies = $setting->get_dependencies(); foreach ($dependencies as &$dependency) { // Enforce each dependency. if ($dependency->enforce()) { $changes++; } } } } // Store the number of settings that changed through enforcement. $this->dependencychanges = $changes; return ($changes > 0); }
php
protected function enforce_dependencies() { // Get the plan. $plan = $this->controller->get_plan(); // Get the tasks as a var so we can iterate by reference. $tasks = $plan->get_tasks(); $changes = 0; foreach ($tasks as &$task) { // Store as a var so we can iterate by reference. $settings = $task->get_settings(); foreach ($settings as &$setting) { // Get all dependencies for iteration by reference. $dependencies = $setting->get_dependencies(); foreach ($dependencies as &$dependency) { // Enforce each dependency. if ($dependency->enforce()) { $changes++; } } } } // Store the number of settings that changed through enforcement. $this->dependencychanges = $changes; return ($changes > 0); }
[ "protected", "function", "enforce_dependencies", "(", ")", "{", "// Get the plan.", "$", "plan", "=", "$", "this", "->", "controller", "->", "get_plan", "(", ")", ";", "// Get the tasks as a var so we can iterate by reference.", "$", "tasks", "=", "$", "plan", "->", "get_tasks", "(", ")", ";", "$", "changes", "=", "0", ";", "foreach", "(", "$", "tasks", "as", "&", "$", "task", ")", "{", "// Store as a var so we can iterate by reference.", "$", "settings", "=", "$", "task", "->", "get_settings", "(", ")", ";", "foreach", "(", "$", "settings", "as", "&", "$", "setting", ")", "{", "// Get all dependencies for iteration by reference.", "$", "dependencies", "=", "$", "setting", "->", "get_dependencies", "(", ")", ";", "foreach", "(", "$", "dependencies", "as", "&", "$", "dependency", ")", "{", "// Enforce each dependency.", "if", "(", "$", "dependency", "->", "enforce", "(", ")", ")", "{", "$", "changes", "++", ";", "}", "}", "}", "}", "// Store the number of settings that changed through enforcement.", "$", "this", "->", "dependencychanges", "=", "$", "changes", ";", "return", "(", "$", "changes", ">", "0", ")", ";", "}" ]
Enforces dependencies on all settings. Call before save @return bool True if dependencies were enforced and changes were made
[ "Enforces", "dependencies", "on", "all", "settings", ".", "Call", "before", "save" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/base_ui.class.php#L225-L248
212,013
moodle/moodle
backup/util/ui/base_ui.class.php
base_ui.get_setting
public function get_setting($name, $default = false) { try { return $this->controller->get_plan()->get_setting($name); } catch (Exception $e) { debugging('Failed to find the setting: '.$name, DEBUG_DEVELOPER); return $default; } }
php
public function get_setting($name, $default = false) { try { return $this->controller->get_plan()->get_setting($name); } catch (Exception $e) { debugging('Failed to find the setting: '.$name, DEBUG_DEVELOPER); return $default; } }
[ "public", "function", "get_setting", "(", "$", "name", ",", "$", "default", "=", "false", ")", "{", "try", "{", "return", "$", "this", "->", "controller", "->", "get_plan", "(", ")", "->", "get_setting", "(", "$", "name", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "debugging", "(", "'Failed to find the setting: '", ".", "$", "name", ",", "DEBUG_DEVELOPER", ")", ";", "return", "$", "default", ";", "}", "}" ]
Gets the requested setting @param string $name @param bool $default @return base_setting
[ "Gets", "the", "requested", "setting" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/base_ui.class.php#L322-L329
212,014
moodle/moodle
lib/classes/rtlcss.php
core_rtlcss.processDeclaration
protected function processDeclaration($node) { $selectors = $node instanceof \Sabberworm\CSS\RuleSet\DeclarationBlock ? $node->getSelectors() : []; foreach ($selectors as $selector) { // The blocks containing .dir-rtl are always accepted as is. if (strpos($selector->getSelector(), '.dir-rtl') !== false) { return; } } return parent::processDeclaration($node); }
php
protected function processDeclaration($node) { $selectors = $node instanceof \Sabberworm\CSS\RuleSet\DeclarationBlock ? $node->getSelectors() : []; foreach ($selectors as $selector) { // The blocks containing .dir-rtl are always accepted as is. if (strpos($selector->getSelector(), '.dir-rtl') !== false) { return; } } return parent::processDeclaration($node); }
[ "protected", "function", "processDeclaration", "(", "$", "node", ")", "{", "$", "selectors", "=", "$", "node", "instanceof", "\\", "Sabberworm", "\\", "CSS", "\\", "RuleSet", "\\", "DeclarationBlock", "?", "$", "node", "->", "getSelectors", "(", ")", ":", "[", "]", ";", "foreach", "(", "$", "selectors", "as", "$", "selector", ")", "{", "// The blocks containing .dir-rtl are always accepted as is.", "if", "(", "strpos", "(", "$", "selector", "->", "getSelector", "(", ")", ",", "'.dir-rtl'", ")", "!==", "false", ")", "{", "return", ";", "}", "}", "return", "parent", "::", "processDeclaration", "(", "$", "node", ")", ";", "}" ]
Process a block declaration. This is overriden in order to provide a backwards compability with the plugins who already defined RTL styles the old-fashioned way. Because we do not need those any more we rename them so that they do not apply. @todo Remove the dir-rtl flipping when dir-rtl is fully deprecated. @param \Sabberworm\CSS\RuleSet\RuleSet $node The object. @return void
[ "Process", "a", "block", "declaration", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/rtlcss.php#L47-L56
212,015
moodle/moodle
admin/tool/monitor/classes/task/check_subscriptions.php
check_subscriptions.is_user_setup
protected function is_user_setup($user) { if (!isset($this->userssetupcache[$user->id])) { $this->userssetupcache[$user->id] = !user_not_fully_set_up($user, true); } return $this->userssetupcache[$user->id]; }
php
protected function is_user_setup($user) { if (!isset($this->userssetupcache[$user->id])) { $this->userssetupcache[$user->id] = !user_not_fully_set_up($user, true); } return $this->userssetupcache[$user->id]; }
[ "protected", "function", "is_user_setup", "(", "$", "user", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "userssetupcache", "[", "$", "user", "->", "id", "]", ")", ")", "{", "$", "this", "->", "userssetupcache", "[", "$", "user", "->", "id", "]", "=", "!", "user_not_fully_set_up", "(", "$", "user", ",", "true", ")", ";", "}", "return", "$", "this", "->", "userssetupcache", "[", "$", "user", "->", "id", "]", ";", "}" ]
Determines whether a user is fully set up, using cached results where possible. @since 3.2.0 @param \stdClass $user the user record. @return bool true if the user is fully set up, false otherwise.
[ "Determines", "whether", "a", "user", "is", "fully", "set", "up", "using", "cached", "results", "where", "possible", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/task/check_subscriptions.php#L200-L205
212,016
moodle/moodle
admin/tool/monitor/classes/task/check_subscriptions.php
check_subscriptions.user_can_access_course
protected function user_can_access_course($user, $course, $capability) { if (!isset($this->courseaccesscache[$course->id][$user->id][$capability])) { $this->courseaccesscache[$course->id][$user->id][$capability] = can_access_course($course, $user, $capability, true); } return $this->courseaccesscache[$course->id][$user->id][$capability]; }
php
protected function user_can_access_course($user, $course, $capability) { if (!isset($this->courseaccesscache[$course->id][$user->id][$capability])) { $this->courseaccesscache[$course->id][$user->id][$capability] = can_access_course($course, $user, $capability, true); } return $this->courseaccesscache[$course->id][$user->id][$capability]; }
[ "protected", "function", "user_can_access_course", "(", "$", "user", ",", "$", "course", ",", "$", "capability", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "courseaccesscache", "[", "$", "course", "->", "id", "]", "[", "$", "user", "->", "id", "]", "[", "$", "capability", "]", ")", ")", "{", "$", "this", "->", "courseaccesscache", "[", "$", "course", "->", "id", "]", "[", "$", "user", "->", "id", "]", "[", "$", "capability", "]", "=", "can_access_course", "(", "$", "course", ",", "$", "user", ",", "$", "capability", ",", "true", ")", ";", "}", "return", "$", "this", "->", "courseaccesscache", "[", "$", "course", "->", "id", "]", "[", "$", "user", "->", "id", "]", "[", "$", "capability", "]", ";", "}" ]
Determines a user's access to a course with a given capability, using cached results where possible. @since 3.2.0 @param \stdClass $user the user record. @param \stdClass $course the course record. @param string $capability the capability to check. @return bool true if the user can access the course with the specified capability, false otherwise.
[ "Determines", "a", "user", "s", "access", "to", "a", "course", "with", "a", "given", "capability", "using", "cached", "results", "where", "possible", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/task/check_subscriptions.php#L216-L221
212,017
moodle/moodle
admin/tool/monitor/classes/task/check_subscriptions.php
check_subscriptions.get_subscription_from_rowdata
protected function get_subscription_from_rowdata($rowdata) { $sub = new \stdClass(); $sub->id = $rowdata->subid; $sub->userid = $rowdata->subuserid; $sub->courseid = $rowdata->subcourseid; $sub->cmid = $rowdata->subcmid; $sub->inactivedate = $rowdata->subinactivedate; return $sub; }
php
protected function get_subscription_from_rowdata($rowdata) { $sub = new \stdClass(); $sub->id = $rowdata->subid; $sub->userid = $rowdata->subuserid; $sub->courseid = $rowdata->subcourseid; $sub->cmid = $rowdata->subcmid; $sub->inactivedate = $rowdata->subinactivedate; return $sub; }
[ "protected", "function", "get_subscription_from_rowdata", "(", "$", "rowdata", ")", "{", "$", "sub", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "sub", "->", "id", "=", "$", "rowdata", "->", "subid", ";", "$", "sub", "->", "userid", "=", "$", "rowdata", "->", "subuserid", ";", "$", "sub", "->", "courseid", "=", "$", "rowdata", "->", "subcourseid", ";", "$", "sub", "->", "cmid", "=", "$", "rowdata", "->", "subcmid", ";", "$", "sub", "->", "inactivedate", "=", "$", "rowdata", "->", "subinactivedate", ";", "return", "$", "sub", ";", "}" ]
Returns a partial subscription record, created from properties of the supplied recordset row object. Intended to return a minimal record for specific use within this class and in subsequent access control calls only. @since 3.2.0 @param \stdClass $rowdata the row object. @return \stdClass a partial subscription record.
[ "Returns", "a", "partial", "subscription", "record", "created", "from", "properties", "of", "the", "supplied", "recordset", "row", "object", ".", "Intended", "to", "return", "a", "minimal", "record", "for", "specific", "use", "within", "this", "class", "and", "in", "subsequent", "access", "control", "calls", "only", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/task/check_subscriptions.php#L231-L239
212,018
moodle/moodle
admin/tool/monitor/classes/task/check_subscriptions.php
check_subscriptions.get_course_from_rowdata
protected function get_course_from_rowdata($rowdata) { $course = new \stdClass(); $course->id = $rowdata->subcourseid; $course->visible = $rowdata->coursevisible; $course->cacherev = $rowdata->coursecacherev; return $course; }
php
protected function get_course_from_rowdata($rowdata) { $course = new \stdClass(); $course->id = $rowdata->subcourseid; $course->visible = $rowdata->coursevisible; $course->cacherev = $rowdata->coursecacherev; return $course; }
[ "protected", "function", "get_course_from_rowdata", "(", "$", "rowdata", ")", "{", "$", "course", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "course", "->", "id", "=", "$", "rowdata", "->", "subcourseid", ";", "$", "course", "->", "visible", "=", "$", "rowdata", "->", "coursevisible", ";", "$", "course", "->", "cacherev", "=", "$", "rowdata", "->", "coursecacherev", ";", "return", "$", "course", ";", "}" ]
Returns a partial course record, created from properties of the supplied recordset row object. Intended to return a minimal record for specific use within this class and in subsequent access control calls only. @since 3.2.0 @param \stdClass $rowdata the row object. @return \stdClass a partial course record.
[ "Returns", "a", "partial", "course", "record", "created", "from", "properties", "of", "the", "supplied", "recordset", "row", "object", ".", "Intended", "to", "return", "a", "minimal", "record", "for", "specific", "use", "within", "this", "class", "and", "in", "subsequent", "access", "control", "calls", "only", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/task/check_subscriptions.php#L249-L255
212,019
moodle/moodle
admin/tool/monitor/classes/task/check_subscriptions.php
check_subscriptions.get_user_from_rowdata
protected function get_user_from_rowdata($rowdata) { $user = new \stdClass(); $user->id = $rowdata->userid; $user->firstname = $rowdata->userfirstname; $user->lastname = $rowdata->userlastname; $user->email = $rowdata->useremail; $user->suspended = $rowdata->usersuspended; return $user; }
php
protected function get_user_from_rowdata($rowdata) { $user = new \stdClass(); $user->id = $rowdata->userid; $user->firstname = $rowdata->userfirstname; $user->lastname = $rowdata->userlastname; $user->email = $rowdata->useremail; $user->suspended = $rowdata->usersuspended; return $user; }
[ "protected", "function", "get_user_from_rowdata", "(", "$", "rowdata", ")", "{", "$", "user", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "user", "->", "id", "=", "$", "rowdata", "->", "userid", ";", "$", "user", "->", "firstname", "=", "$", "rowdata", "->", "userfirstname", ";", "$", "user", "->", "lastname", "=", "$", "rowdata", "->", "userlastname", ";", "$", "user", "->", "email", "=", "$", "rowdata", "->", "useremail", ";", "$", "user", "->", "suspended", "=", "$", "rowdata", "->", "usersuspended", ";", "return", "$", "user", ";", "}" ]
Returns a partial user record, created from properties of the supplied recordset row object. Intended to return a minimal record for specific use within this class and in subsequent access control calls only. @since 3.2.0 @param \stdClass $rowdata the row object. @return \stdClass a partial user record.
[ "Returns", "a", "partial", "user", "record", "created", "from", "properties", "of", "the", "supplied", "recordset", "row", "object", ".", "Intended", "to", "return", "a", "minimal", "record", "for", "specific", "use", "within", "this", "class", "and", "in", "subsequent", "access", "control", "calls", "only", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/task/check_subscriptions.php#L265-L273
212,020
moodle/moodle
mod/assign/classes/task/cron_task.php
cron_task.execute
public function execute() { global $CFG; require_once($CFG->dirroot . '/mod/assign/locallib.php'); \assign::cron(); $plugins = \core_component::get_plugin_list('assignsubmission'); foreach ($plugins as $name => $plugin) { $disabled = get_config('assignsubmission_' . $name, 'disabled'); if (!$disabled) { $class = 'assign_submission_' . $name; require_once($CFG->dirroot . '/mod/assign/submission/' . $name . '/locallib.php'); $class::cron(); } } $plugins = \core_component::get_plugin_list('assignfeedback'); foreach ($plugins as $name => $plugin) { $disabled = get_config('assignfeedback_' . $name, 'disabled'); if (!$disabled) { $class = 'assign_feedback_' . $name; require_once($CFG->dirroot . '/mod/assign/feedback/' . $name . '/locallib.php'); $class::cron(); } } return true; }
php
public function execute() { global $CFG; require_once($CFG->dirroot . '/mod/assign/locallib.php'); \assign::cron(); $plugins = \core_component::get_plugin_list('assignsubmission'); foreach ($plugins as $name => $plugin) { $disabled = get_config('assignsubmission_' . $name, 'disabled'); if (!$disabled) { $class = 'assign_submission_' . $name; require_once($CFG->dirroot . '/mod/assign/submission/' . $name . '/locallib.php'); $class::cron(); } } $plugins = \core_component::get_plugin_list('assignfeedback'); foreach ($plugins as $name => $plugin) { $disabled = get_config('assignfeedback_' . $name, 'disabled'); if (!$disabled) { $class = 'assign_feedback_' . $name; require_once($CFG->dirroot . '/mod/assign/feedback/' . $name . '/locallib.php'); $class::cron(); } } return true; }
[ "public", "function", "execute", "(", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/mod/assign/locallib.php'", ")", ";", "\\", "assign", "::", "cron", "(", ")", ";", "$", "plugins", "=", "\\", "core_component", "::", "get_plugin_list", "(", "'assignsubmission'", ")", ";", "foreach", "(", "$", "plugins", "as", "$", "name", "=>", "$", "plugin", ")", "{", "$", "disabled", "=", "get_config", "(", "'assignsubmission_'", ".", "$", "name", ",", "'disabled'", ")", ";", "if", "(", "!", "$", "disabled", ")", "{", "$", "class", "=", "'assign_submission_'", ".", "$", "name", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/mod/assign/submission/'", ".", "$", "name", ".", "'/locallib.php'", ")", ";", "$", "class", "::", "cron", "(", ")", ";", "}", "}", "$", "plugins", "=", "\\", "core_component", "::", "get_plugin_list", "(", "'assignfeedback'", ")", ";", "foreach", "(", "$", "plugins", "as", "$", "name", "=>", "$", "plugin", ")", "{", "$", "disabled", "=", "get_config", "(", "'assignfeedback_'", ".", "$", "name", ",", "'disabled'", ")", ";", "if", "(", "!", "$", "disabled", ")", "{", "$", "class", "=", "'assign_feedback_'", ".", "$", "name", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/mod/assign/feedback/'", ".", "$", "name", ".", "'/locallib.php'", ")", ";", "$", "class", "::", "cron", "(", ")", ";", "}", "}", "return", "true", ";", "}" ]
Run assignment cron.
[ "Run", "assignment", "cron", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/classes/task/cron_task.php#L40-L68
212,021
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_converter.detect_format
public static function detect_format($tempdir) { global $CFG; $tempdirpath = make_backup_temp_directory($tempdir, false); $filepath = $tempdirpath . '/moodle.xml'; if (file_exists($filepath)) { // looks promising, lets load some information $handle = fopen($filepath, 'r'); $first_chars = fread($handle, 200); fclose($handle); // check if it has the required strings if (strpos($first_chars,'<?xml version="1.0" encoding="UTF-8"?>') !== false and strpos($first_chars,'<MOODLE_BACKUP>') !== false and strpos($first_chars,'<INFO>') !== false) { return backup::FORMAT_MOODLE1; } } return null; }
php
public static function detect_format($tempdir) { global $CFG; $tempdirpath = make_backup_temp_directory($tempdir, false); $filepath = $tempdirpath . '/moodle.xml'; if (file_exists($filepath)) { // looks promising, lets load some information $handle = fopen($filepath, 'r'); $first_chars = fread($handle, 200); fclose($handle); // check if it has the required strings if (strpos($first_chars,'<?xml version="1.0" encoding="UTF-8"?>') !== false and strpos($first_chars,'<MOODLE_BACKUP>') !== false and strpos($first_chars,'<INFO>') !== false) { return backup::FORMAT_MOODLE1; } } return null; }
[ "public", "static", "function", "detect_format", "(", "$", "tempdir", ")", "{", "global", "$", "CFG", ";", "$", "tempdirpath", "=", "make_backup_temp_directory", "(", "$", "tempdir", ",", "false", ")", ";", "$", "filepath", "=", "$", "tempdirpath", ".", "'/moodle.xml'", ";", "if", "(", "file_exists", "(", "$", "filepath", ")", ")", "{", "// looks promising, lets load some information", "$", "handle", "=", "fopen", "(", "$", "filepath", ",", "'r'", ")", ";", "$", "first_chars", "=", "fread", "(", "$", "handle", ",", "200", ")", ";", "fclose", "(", "$", "handle", ")", ";", "// check if it has the required strings", "if", "(", "strpos", "(", "$", "first_chars", ",", "'<?xml version=\"1.0\" encoding=\"UTF-8\"?>'", ")", "!==", "false", "and", "strpos", "(", "$", "first_chars", ",", "'<MOODLE_BACKUP>'", ")", "!==", "false", "and", "strpos", "(", "$", "first_chars", ",", "'<INFO>'", ")", "!==", "false", ")", "{", "return", "backup", "::", "FORMAT_MOODLE1", ";", "}", "}", "return", "null", ";", "}" ]
Detects the Moodle 1.9 format of the backup directory @param string $tempdir the name of the backup directory @return null|string backup::FORMAT_MOODLE1 if the Moodle 1.9 is detected, null otherwise
[ "Detects", "the", "Moodle", "1", ".", "9", "format", "of", "the", "backup", "directory" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L89-L110
212,022
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_converter.init
protected function init() { // ask your mother first before going out playing with toys parent::init(); $this->log('initializing '.$this->get_name().' converter', backup::LOG_INFO); // good boy, prepare XML parser and processor $this->log('setting xml parser', backup::LOG_DEBUG, null, 1); $this->xmlparser = new progressive_parser(); $this->xmlparser->set_file($this->get_tempdir_path() . '/moodle.xml'); $this->log('setting xml processor', backup::LOG_DEBUG, null, 1); $this->xmlprocessor = new moodle1_parser_processor($this); $this->xmlparser->set_processor($this->xmlprocessor); // make sure that MOD and BLOCK paths are visited $this->xmlprocessor->add_path('/MOODLE_BACKUP/COURSE/MODULES/MOD'); $this->xmlprocessor->add_path('/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK'); // register the conversion handlers foreach (moodle1_handlers_factory::get_handlers($this) as $handler) { $this->log('registering handler', backup::LOG_DEBUG, get_class($handler), 1); $this->register_handler($handler, $handler->get_paths()); } }
php
protected function init() { // ask your mother first before going out playing with toys parent::init(); $this->log('initializing '.$this->get_name().' converter', backup::LOG_INFO); // good boy, prepare XML parser and processor $this->log('setting xml parser', backup::LOG_DEBUG, null, 1); $this->xmlparser = new progressive_parser(); $this->xmlparser->set_file($this->get_tempdir_path() . '/moodle.xml'); $this->log('setting xml processor', backup::LOG_DEBUG, null, 1); $this->xmlprocessor = new moodle1_parser_processor($this); $this->xmlparser->set_processor($this->xmlprocessor); // make sure that MOD and BLOCK paths are visited $this->xmlprocessor->add_path('/MOODLE_BACKUP/COURSE/MODULES/MOD'); $this->xmlprocessor->add_path('/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK'); // register the conversion handlers foreach (moodle1_handlers_factory::get_handlers($this) as $handler) { $this->log('registering handler', backup::LOG_DEBUG, get_class($handler), 1); $this->register_handler($handler, $handler->get_paths()); } }
[ "protected", "function", "init", "(", ")", "{", "// ask your mother first before going out playing with toys", "parent", "::", "init", "(", ")", ";", "$", "this", "->", "log", "(", "'initializing '", ".", "$", "this", "->", "get_name", "(", ")", ".", "' converter'", ",", "backup", "::", "LOG_INFO", ")", ";", "// good boy, prepare XML parser and processor", "$", "this", "->", "log", "(", "'setting xml parser'", ",", "backup", "::", "LOG_DEBUG", ",", "null", ",", "1", ")", ";", "$", "this", "->", "xmlparser", "=", "new", "progressive_parser", "(", ")", ";", "$", "this", "->", "xmlparser", "->", "set_file", "(", "$", "this", "->", "get_tempdir_path", "(", ")", ".", "'/moodle.xml'", ")", ";", "$", "this", "->", "log", "(", "'setting xml processor'", ",", "backup", "::", "LOG_DEBUG", ",", "null", ",", "1", ")", ";", "$", "this", "->", "xmlprocessor", "=", "new", "moodle1_parser_processor", "(", "$", "this", ")", ";", "$", "this", "->", "xmlparser", "->", "set_processor", "(", "$", "this", "->", "xmlprocessor", ")", ";", "// make sure that MOD and BLOCK paths are visited", "$", "this", "->", "xmlprocessor", "->", "add_path", "(", "'/MOODLE_BACKUP/COURSE/MODULES/MOD'", ")", ";", "$", "this", "->", "xmlprocessor", "->", "add_path", "(", "'/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK'", ")", ";", "// register the conversion handlers", "foreach", "(", "moodle1_handlers_factory", "::", "get_handlers", "(", "$", "this", ")", "as", "$", "handler", ")", "{", "$", "this", "->", "log", "(", "'registering handler'", ",", "backup", "::", "LOG_DEBUG", ",", "get_class", "(", "$", "handler", ")", ",", "1", ")", ";", "$", "this", "->", "register_handler", "(", "$", "handler", ",", "$", "handler", "->", "get_paths", "(", ")", ")", ";", "}", "}" ]
Initialize the instance if needed, called by the constructor Here we create objects we need before the execution.
[ "Initialize", "the", "instance", "if", "needed", "called", "by", "the", "constructor" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L117-L141
212,023
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_converter.execute
protected function execute() { $this->log('creating the stash storage', backup::LOG_DEBUG); $this->create_stash_storage(); $this->log('parsing moodle.xml starts', backup::LOG_DEBUG); $this->xmlparser->process(); $this->log('parsing moodle.xml done', backup::LOG_DEBUG); $this->log('dropping the stash storage', backup::LOG_DEBUG); $this->drop_stash_storage(); }
php
protected function execute() { $this->log('creating the stash storage', backup::LOG_DEBUG); $this->create_stash_storage(); $this->log('parsing moodle.xml starts', backup::LOG_DEBUG); $this->xmlparser->process(); $this->log('parsing moodle.xml done', backup::LOG_DEBUG); $this->log('dropping the stash storage', backup::LOG_DEBUG); $this->drop_stash_storage(); }
[ "protected", "function", "execute", "(", ")", "{", "$", "this", "->", "log", "(", "'creating the stash storage'", ",", "backup", "::", "LOG_DEBUG", ")", ";", "$", "this", "->", "create_stash_storage", "(", ")", ";", "$", "this", "->", "log", "(", "'parsing moodle.xml starts'", ",", "backup", "::", "LOG_DEBUG", ")", ";", "$", "this", "->", "xmlparser", "->", "process", "(", ")", ";", "$", "this", "->", "log", "(", "'parsing moodle.xml done'", ",", "backup", "::", "LOG_DEBUG", ")", ";", "$", "this", "->", "log", "(", "'dropping the stash storage'", ",", "backup", "::", "LOG_DEBUG", ")", ";", "$", "this", "->", "drop_stash_storage", "(", ")", ";", "}" ]
Converts the contents of the tempdir into the target format in the workdir
[ "Converts", "the", "contents", "of", "the", "tempdir", "into", "the", "target", "format", "in", "the", "workdir" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L146-L156
212,024
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_converter.register_handler
protected function register_handler(moodle1_handler $handler, array $elements) { // first iteration, push them to new array, indexed by name // to detect duplicates in names or paths $names = array(); $paths = array(); foreach($elements as $element) { if (!$element instanceof convert_path) { throw new convert_exception('path_element_wrong_class', get_class($element)); } if (array_key_exists($element->get_name(), $names)) { throw new convert_exception('path_element_name_alreadyexists', $element->get_name()); } if (array_key_exists($element->get_path(), $paths)) { throw new convert_exception('path_element_path_alreadyexists', $element->get_path()); } $names[$element->get_name()] = true; $paths[$element->get_path()] = $element; } // now, for each element not having a processing object yet, assign the handler // if the element is not a memeber of a group foreach($paths as $key => $element) { if (is_null($element->get_processing_object()) and !$this->grouped_parent_exists($element, $paths)) { $paths[$key]->set_processing_object($handler); } // add the element path to the processor $this->xmlprocessor->add_path($element->get_path(), $element->is_grouped()); } // done, store the paths (duplicates by path are discarded) $this->pathelements = array_merge($this->pathelements, $paths); // remove the injected plugin name element from the MOD and BLOCK paths // and register such collapsed path, too foreach ($elements as $element) { $path = $element->get_path(); $path = preg_replace('/^\/MOODLE_BACKUP\/COURSE\/MODULES\/MOD\/(\w+)\//', '/MOODLE_BACKUP/COURSE/MODULES/MOD/', $path); $path = preg_replace('/^\/MOODLE_BACKUP\/COURSE\/BLOCKS\/BLOCK\/(\w+)\//', '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/', $path); if (!empty($path) and $path != $element->get_path()) { $this->xmlprocessor->add_path($path, false); } } }
php
protected function register_handler(moodle1_handler $handler, array $elements) { // first iteration, push them to new array, indexed by name // to detect duplicates in names or paths $names = array(); $paths = array(); foreach($elements as $element) { if (!$element instanceof convert_path) { throw new convert_exception('path_element_wrong_class', get_class($element)); } if (array_key_exists($element->get_name(), $names)) { throw new convert_exception('path_element_name_alreadyexists', $element->get_name()); } if (array_key_exists($element->get_path(), $paths)) { throw new convert_exception('path_element_path_alreadyexists', $element->get_path()); } $names[$element->get_name()] = true; $paths[$element->get_path()] = $element; } // now, for each element not having a processing object yet, assign the handler // if the element is not a memeber of a group foreach($paths as $key => $element) { if (is_null($element->get_processing_object()) and !$this->grouped_parent_exists($element, $paths)) { $paths[$key]->set_processing_object($handler); } // add the element path to the processor $this->xmlprocessor->add_path($element->get_path(), $element->is_grouped()); } // done, store the paths (duplicates by path are discarded) $this->pathelements = array_merge($this->pathelements, $paths); // remove the injected plugin name element from the MOD and BLOCK paths // and register such collapsed path, too foreach ($elements as $element) { $path = $element->get_path(); $path = preg_replace('/^\/MOODLE_BACKUP\/COURSE\/MODULES\/MOD\/(\w+)\//', '/MOODLE_BACKUP/COURSE/MODULES/MOD/', $path); $path = preg_replace('/^\/MOODLE_BACKUP\/COURSE\/BLOCKS\/BLOCK\/(\w+)\//', '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/', $path); if (!empty($path) and $path != $element->get_path()) { $this->xmlprocessor->add_path($path, false); } } }
[ "protected", "function", "register_handler", "(", "moodle1_handler", "$", "handler", ",", "array", "$", "elements", ")", "{", "// first iteration, push them to new array, indexed by name", "// to detect duplicates in names or paths", "$", "names", "=", "array", "(", ")", ";", "$", "paths", "=", "array", "(", ")", ";", "foreach", "(", "$", "elements", "as", "$", "element", ")", "{", "if", "(", "!", "$", "element", "instanceof", "convert_path", ")", "{", "throw", "new", "convert_exception", "(", "'path_element_wrong_class'", ",", "get_class", "(", "$", "element", ")", ")", ";", "}", "if", "(", "array_key_exists", "(", "$", "element", "->", "get_name", "(", ")", ",", "$", "names", ")", ")", "{", "throw", "new", "convert_exception", "(", "'path_element_name_alreadyexists'", ",", "$", "element", "->", "get_name", "(", ")", ")", ";", "}", "if", "(", "array_key_exists", "(", "$", "element", "->", "get_path", "(", ")", ",", "$", "paths", ")", ")", "{", "throw", "new", "convert_exception", "(", "'path_element_path_alreadyexists'", ",", "$", "element", "->", "get_path", "(", ")", ")", ";", "}", "$", "names", "[", "$", "element", "->", "get_name", "(", ")", "]", "=", "true", ";", "$", "paths", "[", "$", "element", "->", "get_path", "(", ")", "]", "=", "$", "element", ";", "}", "// now, for each element not having a processing object yet, assign the handler", "// if the element is not a memeber of a group", "foreach", "(", "$", "paths", "as", "$", "key", "=>", "$", "element", ")", "{", "if", "(", "is_null", "(", "$", "element", "->", "get_processing_object", "(", ")", ")", "and", "!", "$", "this", "->", "grouped_parent_exists", "(", "$", "element", ",", "$", "paths", ")", ")", "{", "$", "paths", "[", "$", "key", "]", "->", "set_processing_object", "(", "$", "handler", ")", ";", "}", "// add the element path to the processor", "$", "this", "->", "xmlprocessor", "->", "add_path", "(", "$", "element", "->", "get_path", "(", ")", ",", "$", "element", "->", "is_grouped", "(", ")", ")", ";", "}", "// done, store the paths (duplicates by path are discarded)", "$", "this", "->", "pathelements", "=", "array_merge", "(", "$", "this", "->", "pathelements", ",", "$", "paths", ")", ";", "// remove the injected plugin name element from the MOD and BLOCK paths", "// and register such collapsed path, too", "foreach", "(", "$", "elements", "as", "$", "element", ")", "{", "$", "path", "=", "$", "element", "->", "get_path", "(", ")", ";", "$", "path", "=", "preg_replace", "(", "'/^\\/MOODLE_BACKUP\\/COURSE\\/MODULES\\/MOD\\/(\\w+)\\//'", ",", "'/MOODLE_BACKUP/COURSE/MODULES/MOD/'", ",", "$", "path", ")", ";", "$", "path", "=", "preg_replace", "(", "'/^\\/MOODLE_BACKUP\\/COURSE\\/BLOCKS\\/BLOCK\\/(\\w+)\\//'", ",", "'/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/'", ",", "$", "path", ")", ";", "if", "(", "!", "empty", "(", "$", "path", ")", "and", "$", "path", "!=", "$", "element", "->", "get_path", "(", ")", ")", "{", "$", "this", "->", "xmlprocessor", "->", "add_path", "(", "$", "path", ",", "false", ")", ";", "}", "}", "}" ]
Register a handler for the given path elements
[ "Register", "a", "handler", "for", "the", "given", "path", "elements" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L161-L204
212,025
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_converter.process_chunk
public function process_chunk($data) { $path = $data['path']; // expand the MOD paths so that they contain the module name if ($path === '/MOODLE_BACKUP/COURSE/MODULES/MOD') { $this->currentmod = strtoupper($data['tags']['MODTYPE']); $path = '/MOODLE_BACKUP/COURSE/MODULES/MOD/' . $this->currentmod; } else if (strpos($path, '/MOODLE_BACKUP/COURSE/MODULES/MOD') === 0) { $path = str_replace('/MOODLE_BACKUP/COURSE/MODULES/MOD', '/MOODLE_BACKUP/COURSE/MODULES/MOD/' . $this->currentmod, $path); } // expand the BLOCK paths so that they contain the module name if ($path === '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK') { $this->currentblock = strtoupper($data['tags']['NAME']); $path = '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/' . $this->currentblock; } else if (strpos($path, '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK') === 0) { $path = str_replace('/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK', '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/' . $this->currentblock, $path); } if ($path !== $data['path']) { if (!array_key_exists($path, $this->pathelements)) { // no handler registered for the transformed MOD or BLOCK path $this->log('no handler attached', backup::LOG_WARNING, $path); return; } else { // pretend as if the original $data contained the tranformed path $data['path'] = $path; } } if (!array_key_exists($data['path'], $this->pathelements)) { // path added to the processor without the handler throw new convert_exception('missing_path_handler', $data['path']); } $element = $this->pathelements[$data['path']]; $object = $element->get_processing_object(); $method = $element->get_processing_method(); $returned = null; // data returned by the processing method, if any if (empty($object)) { throw new convert_exception('missing_processing_object', null, $data['path']); } // release the lock if we aren't anymore within children of it if (!is_null($this->pathlock) and strpos($data['path'], $this->pathlock) === false) { $this->pathlock = null; } // if the path is not locked, apply the element's recipes and dispatch // the cooked tags to the processing method if (is_null($this->pathlock)) { $rawdatatags = $data['tags']; $data['tags'] = $element->apply_recipes($data['tags']); // if the processing method exists, give it a chance to modify data if (method_exists($object, $method)) { $returned = $object->$method($data['tags'], $rawdatatags); } } // if the dispatched method returned SKIP_ALL_CHILDREN, remember the current path // and lock it so that its children are not dispatched if ($returned === self::SKIP_ALL_CHILDREN) { // check we haven't any previous lock if (!is_null($this->pathlock)) { throw new convert_exception('already_locked_path', $data['path']); } // set the lock - nothing below the current path will be dispatched $this->pathlock = $data['path'] . '/'; // if the method has returned any info, set element data to it } else if (!is_null($returned)) { $element->set_tags($returned); // use just the cooked parsed data otherwise } else { $element->set_tags($data['tags']); } }
php
public function process_chunk($data) { $path = $data['path']; // expand the MOD paths so that they contain the module name if ($path === '/MOODLE_BACKUP/COURSE/MODULES/MOD') { $this->currentmod = strtoupper($data['tags']['MODTYPE']); $path = '/MOODLE_BACKUP/COURSE/MODULES/MOD/' . $this->currentmod; } else if (strpos($path, '/MOODLE_BACKUP/COURSE/MODULES/MOD') === 0) { $path = str_replace('/MOODLE_BACKUP/COURSE/MODULES/MOD', '/MOODLE_BACKUP/COURSE/MODULES/MOD/' . $this->currentmod, $path); } // expand the BLOCK paths so that they contain the module name if ($path === '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK') { $this->currentblock = strtoupper($data['tags']['NAME']); $path = '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/' . $this->currentblock; } else if (strpos($path, '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK') === 0) { $path = str_replace('/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK', '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/' . $this->currentblock, $path); } if ($path !== $data['path']) { if (!array_key_exists($path, $this->pathelements)) { // no handler registered for the transformed MOD or BLOCK path $this->log('no handler attached', backup::LOG_WARNING, $path); return; } else { // pretend as if the original $data contained the tranformed path $data['path'] = $path; } } if (!array_key_exists($data['path'], $this->pathelements)) { // path added to the processor without the handler throw new convert_exception('missing_path_handler', $data['path']); } $element = $this->pathelements[$data['path']]; $object = $element->get_processing_object(); $method = $element->get_processing_method(); $returned = null; // data returned by the processing method, if any if (empty($object)) { throw new convert_exception('missing_processing_object', null, $data['path']); } // release the lock if we aren't anymore within children of it if (!is_null($this->pathlock) and strpos($data['path'], $this->pathlock) === false) { $this->pathlock = null; } // if the path is not locked, apply the element's recipes and dispatch // the cooked tags to the processing method if (is_null($this->pathlock)) { $rawdatatags = $data['tags']; $data['tags'] = $element->apply_recipes($data['tags']); // if the processing method exists, give it a chance to modify data if (method_exists($object, $method)) { $returned = $object->$method($data['tags'], $rawdatatags); } } // if the dispatched method returned SKIP_ALL_CHILDREN, remember the current path // and lock it so that its children are not dispatched if ($returned === self::SKIP_ALL_CHILDREN) { // check we haven't any previous lock if (!is_null($this->pathlock)) { throw new convert_exception('already_locked_path', $data['path']); } // set the lock - nothing below the current path will be dispatched $this->pathlock = $data['path'] . '/'; // if the method has returned any info, set element data to it } else if (!is_null($returned)) { $element->set_tags($returned); // use just the cooked parsed data otherwise } else { $element->set_tags($data['tags']); } }
[ "public", "function", "process_chunk", "(", "$", "data", ")", "{", "$", "path", "=", "$", "data", "[", "'path'", "]", ";", "// expand the MOD paths so that they contain the module name", "if", "(", "$", "path", "===", "'/MOODLE_BACKUP/COURSE/MODULES/MOD'", ")", "{", "$", "this", "->", "currentmod", "=", "strtoupper", "(", "$", "data", "[", "'tags'", "]", "[", "'MODTYPE'", "]", ")", ";", "$", "path", "=", "'/MOODLE_BACKUP/COURSE/MODULES/MOD/'", ".", "$", "this", "->", "currentmod", ";", "}", "else", "if", "(", "strpos", "(", "$", "path", ",", "'/MOODLE_BACKUP/COURSE/MODULES/MOD'", ")", "===", "0", ")", "{", "$", "path", "=", "str_replace", "(", "'/MOODLE_BACKUP/COURSE/MODULES/MOD'", ",", "'/MOODLE_BACKUP/COURSE/MODULES/MOD/'", ".", "$", "this", "->", "currentmod", ",", "$", "path", ")", ";", "}", "// expand the BLOCK paths so that they contain the module name", "if", "(", "$", "path", "===", "'/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK'", ")", "{", "$", "this", "->", "currentblock", "=", "strtoupper", "(", "$", "data", "[", "'tags'", "]", "[", "'NAME'", "]", ")", ";", "$", "path", "=", "'/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/'", ".", "$", "this", "->", "currentblock", ";", "}", "else", "if", "(", "strpos", "(", "$", "path", ",", "'/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK'", ")", "===", "0", ")", "{", "$", "path", "=", "str_replace", "(", "'/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK'", ",", "'/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/'", ".", "$", "this", "->", "currentblock", ",", "$", "path", ")", ";", "}", "if", "(", "$", "path", "!==", "$", "data", "[", "'path'", "]", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "path", ",", "$", "this", "->", "pathelements", ")", ")", "{", "// no handler registered for the transformed MOD or BLOCK path", "$", "this", "->", "log", "(", "'no handler attached'", ",", "backup", "::", "LOG_WARNING", ",", "$", "path", ")", ";", "return", ";", "}", "else", "{", "// pretend as if the original $data contained the tranformed path", "$", "data", "[", "'path'", "]", "=", "$", "path", ";", "}", "}", "if", "(", "!", "array_key_exists", "(", "$", "data", "[", "'path'", "]", ",", "$", "this", "->", "pathelements", ")", ")", "{", "// path added to the processor without the handler", "throw", "new", "convert_exception", "(", "'missing_path_handler'", ",", "$", "data", "[", "'path'", "]", ")", ";", "}", "$", "element", "=", "$", "this", "->", "pathelements", "[", "$", "data", "[", "'path'", "]", "]", ";", "$", "object", "=", "$", "element", "->", "get_processing_object", "(", ")", ";", "$", "method", "=", "$", "element", "->", "get_processing_method", "(", ")", ";", "$", "returned", "=", "null", ";", "// data returned by the processing method, if any", "if", "(", "empty", "(", "$", "object", ")", ")", "{", "throw", "new", "convert_exception", "(", "'missing_processing_object'", ",", "null", ",", "$", "data", "[", "'path'", "]", ")", ";", "}", "// release the lock if we aren't anymore within children of it", "if", "(", "!", "is_null", "(", "$", "this", "->", "pathlock", ")", "and", "strpos", "(", "$", "data", "[", "'path'", "]", ",", "$", "this", "->", "pathlock", ")", "===", "false", ")", "{", "$", "this", "->", "pathlock", "=", "null", ";", "}", "// if the path is not locked, apply the element's recipes and dispatch", "// the cooked tags to the processing method", "if", "(", "is_null", "(", "$", "this", "->", "pathlock", ")", ")", "{", "$", "rawdatatags", "=", "$", "data", "[", "'tags'", "]", ";", "$", "data", "[", "'tags'", "]", "=", "$", "element", "->", "apply_recipes", "(", "$", "data", "[", "'tags'", "]", ")", ";", "// if the processing method exists, give it a chance to modify data", "if", "(", "method_exists", "(", "$", "object", ",", "$", "method", ")", ")", "{", "$", "returned", "=", "$", "object", "->", "$", "method", "(", "$", "data", "[", "'tags'", "]", ",", "$", "rawdatatags", ")", ";", "}", "}", "// if the dispatched method returned SKIP_ALL_CHILDREN, remember the current path", "// and lock it so that its children are not dispatched", "if", "(", "$", "returned", "===", "self", "::", "SKIP_ALL_CHILDREN", ")", "{", "// check we haven't any previous lock", "if", "(", "!", "is_null", "(", "$", "this", "->", "pathlock", ")", ")", "{", "throw", "new", "convert_exception", "(", "'already_locked_path'", ",", "$", "data", "[", "'path'", "]", ")", ";", "}", "// set the lock - nothing below the current path will be dispatched", "$", "this", "->", "pathlock", "=", "$", "data", "[", "'path'", "]", ".", "'/'", ";", "// if the method has returned any info, set element data to it", "}", "else", "if", "(", "!", "is_null", "(", "$", "returned", ")", ")", "{", "$", "element", "->", "set_tags", "(", "$", "returned", ")", ";", "// use just the cooked parsed data otherwise", "}", "else", "{", "$", "element", "->", "set_tags", "(", "$", "data", "[", "'tags'", "]", ")", ";", "}", "}" ]
Process the data obtained from the XML parser processor This methods receives one chunk of information from the XML parser processor and dispatches it, following the naming rules. We are expanding the modules and blocks paths here to include the plugin's name. @param array $data
[ "Process", "the", "data", "obtained", "from", "the", "XML", "parser", "processor" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L239-L322
212,026
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_converter.path_start_reached
public function path_start_reached($path) { if ($path === '/MOODLE_BACKUP/COURSE/MODULES/MOD') { $this->currentmod = null; $forbidden = true; } else if (strpos($path, '/MOODLE_BACKUP/COURSE/MODULES/MOD') === 0) { // expand the MOD paths so that they contain the module name $path = str_replace('/MOODLE_BACKUP/COURSE/MODULES/MOD', '/MOODLE_BACKUP/COURSE/MODULES/MOD/' . $this->currentmod, $path); } if ($path === '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK') { $this->currentblock = null; $forbidden = true; } else if (strpos($path, '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK') === 0) { // expand the BLOCK paths so that they contain the module name $path = str_replace('/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK', '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/' . $this->currentblock, $path); } if (empty($this->pathelements[$path])) { return; } $element = $this->pathelements[$path]; $pobject = $element->get_processing_object(); $method = $element->get_start_method(); if (method_exists($pobject, $method)) { if (empty($forbidden)) { $pobject->$method(); } else { // this path is not supported because we do not know the module/block yet throw new coding_exception('Attaching the on-start event listener to the root MOD or BLOCK element is forbidden.'); } } }
php
public function path_start_reached($path) { if ($path === '/MOODLE_BACKUP/COURSE/MODULES/MOD') { $this->currentmod = null; $forbidden = true; } else if (strpos($path, '/MOODLE_BACKUP/COURSE/MODULES/MOD') === 0) { // expand the MOD paths so that they contain the module name $path = str_replace('/MOODLE_BACKUP/COURSE/MODULES/MOD', '/MOODLE_BACKUP/COURSE/MODULES/MOD/' . $this->currentmod, $path); } if ($path === '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK') { $this->currentblock = null; $forbidden = true; } else if (strpos($path, '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK') === 0) { // expand the BLOCK paths so that they contain the module name $path = str_replace('/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK', '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/' . $this->currentblock, $path); } if (empty($this->pathelements[$path])) { return; } $element = $this->pathelements[$path]; $pobject = $element->get_processing_object(); $method = $element->get_start_method(); if (method_exists($pobject, $method)) { if (empty($forbidden)) { $pobject->$method(); } else { // this path is not supported because we do not know the module/block yet throw new coding_exception('Attaching the on-start event listener to the root MOD or BLOCK element is forbidden.'); } } }
[ "public", "function", "path_start_reached", "(", "$", "path", ")", "{", "if", "(", "$", "path", "===", "'/MOODLE_BACKUP/COURSE/MODULES/MOD'", ")", "{", "$", "this", "->", "currentmod", "=", "null", ";", "$", "forbidden", "=", "true", ";", "}", "else", "if", "(", "strpos", "(", "$", "path", ",", "'/MOODLE_BACKUP/COURSE/MODULES/MOD'", ")", "===", "0", ")", "{", "// expand the MOD paths so that they contain the module name", "$", "path", "=", "str_replace", "(", "'/MOODLE_BACKUP/COURSE/MODULES/MOD'", ",", "'/MOODLE_BACKUP/COURSE/MODULES/MOD/'", ".", "$", "this", "->", "currentmod", ",", "$", "path", ")", ";", "}", "if", "(", "$", "path", "===", "'/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK'", ")", "{", "$", "this", "->", "currentblock", "=", "null", ";", "$", "forbidden", "=", "true", ";", "}", "else", "if", "(", "strpos", "(", "$", "path", ",", "'/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK'", ")", "===", "0", ")", "{", "// expand the BLOCK paths so that they contain the module name", "$", "path", "=", "str_replace", "(", "'/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK'", ",", "'/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/'", ".", "$", "this", "->", "currentblock", ",", "$", "path", ")", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "pathelements", "[", "$", "path", "]", ")", ")", "{", "return", ";", "}", "$", "element", "=", "$", "this", "->", "pathelements", "[", "$", "path", "]", ";", "$", "pobject", "=", "$", "element", "->", "get_processing_object", "(", ")", ";", "$", "method", "=", "$", "element", "->", "get_start_method", "(", ")", ";", "if", "(", "method_exists", "(", "$", "pobject", ",", "$", "method", ")", ")", "{", "if", "(", "empty", "(", "$", "forbidden", ")", ")", "{", "$", "pobject", "->", "$", "method", "(", ")", ";", "}", "else", "{", "// this path is not supported because we do not know the module/block yet", "throw", "new", "coding_exception", "(", "'Attaching the on-start event listener to the root MOD or BLOCK element is forbidden.'", ")", ";", "}", "}", "}" ]
Executes operations required at the start of a watched path For MOD and BLOCK paths, this is supported only for the sub-paths, not the root module/block element. For the illustration: You CAN'T attach on_xxx_start() listener to a path like /MOODLE_BACKUP/COURSE/MODULES/MOD/WORKSHOP because the <MOD> must be processed first in {@link self::process_chunk()} where $this->currentmod is set. You CAN attach some on_xxx_start() listener to a path like /MOODLE_BACKUP/COURSE/MODULES/MOD/WORKSHOP/SUBMISSIONS because it is a sub-path under <MOD> and we have $this->currentmod already set when the <SUBMISSIONS> is reached. @param string $path in the original file
[ "Executes", "operations", "required", "at", "the", "start", "of", "a", "watched", "path" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L342-L379
212,027
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_converter.path_end_reached
public function path_end_reached($path) { // expand the MOD paths so that they contain the current module name if ($path === '/MOODLE_BACKUP/COURSE/MODULES/MOD') { $path = '/MOODLE_BACKUP/COURSE/MODULES/MOD/' . $this->currentmod; } else if (strpos($path, '/MOODLE_BACKUP/COURSE/MODULES/MOD') === 0) { $path = str_replace('/MOODLE_BACKUP/COURSE/MODULES/MOD', '/MOODLE_BACKUP/COURSE/MODULES/MOD/' . $this->currentmod, $path); } // expand the BLOCK paths so that they contain the module name if ($path === '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK') { $path = '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/' . $this->currentblock; } else if (strpos($path, '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK') === 0) { $path = str_replace('/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK', '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/' . $this->currentblock, $path); } if (empty($this->pathelements[$path])) { return; } $element = $this->pathelements[$path]; $pobject = $element->get_processing_object(); $method = $element->get_end_method(); $tags = $element->get_tags(); if (method_exists($pobject, $method)) { $pobject->$method($tags); } }
php
public function path_end_reached($path) { // expand the MOD paths so that they contain the current module name if ($path === '/MOODLE_BACKUP/COURSE/MODULES/MOD') { $path = '/MOODLE_BACKUP/COURSE/MODULES/MOD/' . $this->currentmod; } else if (strpos($path, '/MOODLE_BACKUP/COURSE/MODULES/MOD') === 0) { $path = str_replace('/MOODLE_BACKUP/COURSE/MODULES/MOD', '/MOODLE_BACKUP/COURSE/MODULES/MOD/' . $this->currentmod, $path); } // expand the BLOCK paths so that they contain the module name if ($path === '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK') { $path = '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/' . $this->currentblock; } else if (strpos($path, '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK') === 0) { $path = str_replace('/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK', '/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/' . $this->currentblock, $path); } if (empty($this->pathelements[$path])) { return; } $element = $this->pathelements[$path]; $pobject = $element->get_processing_object(); $method = $element->get_end_method(); $tags = $element->get_tags(); if (method_exists($pobject, $method)) { $pobject->$method($tags); } }
[ "public", "function", "path_end_reached", "(", "$", "path", ")", "{", "// expand the MOD paths so that they contain the current module name", "if", "(", "$", "path", "===", "'/MOODLE_BACKUP/COURSE/MODULES/MOD'", ")", "{", "$", "path", "=", "'/MOODLE_BACKUP/COURSE/MODULES/MOD/'", ".", "$", "this", "->", "currentmod", ";", "}", "else", "if", "(", "strpos", "(", "$", "path", ",", "'/MOODLE_BACKUP/COURSE/MODULES/MOD'", ")", "===", "0", ")", "{", "$", "path", "=", "str_replace", "(", "'/MOODLE_BACKUP/COURSE/MODULES/MOD'", ",", "'/MOODLE_BACKUP/COURSE/MODULES/MOD/'", ".", "$", "this", "->", "currentmod", ",", "$", "path", ")", ";", "}", "// expand the BLOCK paths so that they contain the module name", "if", "(", "$", "path", "===", "'/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK'", ")", "{", "$", "path", "=", "'/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/'", ".", "$", "this", "->", "currentblock", ";", "}", "else", "if", "(", "strpos", "(", "$", "path", ",", "'/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK'", ")", "===", "0", ")", "{", "$", "path", "=", "str_replace", "(", "'/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK'", ",", "'/MOODLE_BACKUP/COURSE/BLOCKS/BLOCK/'", ".", "$", "this", "->", "currentblock", ",", "$", "path", ")", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "pathelements", "[", "$", "path", "]", ")", ")", "{", "return", ";", "}", "$", "element", "=", "$", "this", "->", "pathelements", "[", "$", "path", "]", ";", "$", "pobject", "=", "$", "element", "->", "get_processing_object", "(", ")", ";", "$", "method", "=", "$", "element", "->", "get_end_method", "(", ")", ";", "$", "tags", "=", "$", "element", "->", "get_tags", "(", ")", ";", "if", "(", "method_exists", "(", "$", "pobject", ",", "$", "method", ")", ")", "{", "$", "pobject", "->", "$", "method", "(", "$", "tags", ")", ";", "}", "}" ]
Executes operations required at the end of a watched path @param string $path in the original file
[ "Executes", "operations", "required", "at", "the", "end", "of", "a", "watched", "path" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L386-L416
212,028
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_converter.set_stash
public function set_stash($stashname, $info, $itemid = 0) { try { restore_dbops::set_backup_ids_record($this->get_id(), $stashname, $itemid, 0, null, $info); } catch (dml_exception $e) { throw new moodle1_convert_storage_exception('unable_to_restore_stash', null, $e->getMessage()); } }
php
public function set_stash($stashname, $info, $itemid = 0) { try { restore_dbops::set_backup_ids_record($this->get_id(), $stashname, $itemid, 0, null, $info); } catch (dml_exception $e) { throw new moodle1_convert_storage_exception('unable_to_restore_stash', null, $e->getMessage()); } }
[ "public", "function", "set_stash", "(", "$", "stashname", ",", "$", "info", ",", "$", "itemid", "=", "0", ")", "{", "try", "{", "restore_dbops", "::", "set_backup_ids_record", "(", "$", "this", "->", "get_id", "(", ")", ",", "$", "stashname", ",", "$", "itemid", ",", "0", ",", "null", ",", "$", "info", ")", ";", "}", "catch", "(", "dml_exception", "$", "e", ")", "{", "throw", "new", "moodle1_convert_storage_exception", "(", "'unable_to_restore_stash'", ",", "null", ",", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}" ]
Stores some information for later processing This implementation uses backup_ids_temp table to store data. Make sure that the $stashname + $itemid combo is unique. @param string $stashname name of the stash @param mixed $info information to stash @param int $itemid optional id for multiple infos within the same stashname
[ "Stores", "some", "information", "for", "later", "processing" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L446-L453
212,029
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_converter.get_stash_or_default
public function get_stash_or_default($stashname, $itemid = 0, $default = null) { try { return $this->get_stash($stashname, $itemid); } catch (moodle1_convert_empty_storage_exception $e) { return $default; } }
php
public function get_stash_or_default($stashname, $itemid = 0, $default = null) { try { return $this->get_stash($stashname, $itemid); } catch (moodle1_convert_empty_storage_exception $e) { return $default; } }
[ "public", "function", "get_stash_or_default", "(", "$", "stashname", ",", "$", "itemid", "=", "0", ",", "$", "default", "=", "null", ")", "{", "try", "{", "return", "$", "this", "->", "get_stash", "(", "$", "stashname", ",", "$", "itemid", ")", ";", "}", "catch", "(", "moodle1_convert_empty_storage_exception", "$", "e", ")", "{", "return", "$", "default", ";", "}", "}" ]
Restores a given stash or returns the given default if there is no such stash @param string $stashname name of the stash @param int $itemid optional id for multiple infos within the same stashname @param mixed $default information to return if the info has not been stashed previously @return mixed stashed data or the default value
[ "Restores", "a", "given", "stash", "or", "returns", "the", "given", "default", "if", "there", "is", "no", "such", "stash" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L485-L491
212,030
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_converter.get_contextid
public function get_contextid($level, $instance = 0) { $stashname = 'context' . $level; if ($level == CONTEXT_SYSTEM or $level == CONTEXT_COURSE) { $instance = 0; } try { // try the previously stashed id return $this->get_stash($stashname, $instance); } catch (moodle1_convert_empty_storage_exception $e) { // this context level + instance is required for the first time $newid = $this->get_nextid(); $this->set_stash($stashname, $newid, $instance); return $newid; } }
php
public function get_contextid($level, $instance = 0) { $stashname = 'context' . $level; if ($level == CONTEXT_SYSTEM or $level == CONTEXT_COURSE) { $instance = 0; } try { // try the previously stashed id return $this->get_stash($stashname, $instance); } catch (moodle1_convert_empty_storage_exception $e) { // this context level + instance is required for the first time $newid = $this->get_nextid(); $this->set_stash($stashname, $newid, $instance); return $newid; } }
[ "public", "function", "get_contextid", "(", "$", "level", ",", "$", "instance", "=", "0", ")", "{", "$", "stashname", "=", "'context'", ".", "$", "level", ";", "if", "(", "$", "level", "==", "CONTEXT_SYSTEM", "or", "$", "level", "==", "CONTEXT_COURSE", ")", "{", "$", "instance", "=", "0", ";", "}", "try", "{", "// try the previously stashed id", "return", "$", "this", "->", "get_stash", "(", "$", "stashname", ",", "$", "instance", ")", ";", "}", "catch", "(", "moodle1_convert_empty_storage_exception", "$", "e", ")", "{", "// this context level + instance is required for the first time", "$", "newid", "=", "$", "this", "->", "get_nextid", "(", ")", ";", "$", "this", "->", "set_stash", "(", "$", "stashname", ",", "$", "newid", ",", "$", "instance", ")", ";", "return", "$", "newid", ";", "}", "}" ]
Generates an artificial context id Moodle 1.9 backups do not contain any context information. But we need them in Moodle 2.x format so here we generate fictive context id for every given context level + instance combo. CONTEXT_SYSTEM and CONTEXT_COURSE ignore the $instance as they represent a single system or the course being restored. @see context_system::instance() @see context_course::instance() @param int $level the context level, like CONTEXT_COURSE or CONTEXT_MODULE @param int $instance the instance id, for example $course->id for courses or $cm->id for activity modules @return int the context id
[ "Generates", "an", "artificial", "context", "id" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L541-L559
212,031
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_converter.get_file_manager
public function get_file_manager($contextid = null, $component = null, $filearea = null, $itemid = 0, $userid = null) { return new moodle1_file_manager($this, $contextid, $component, $filearea, $itemid, $userid); }
php
public function get_file_manager($contextid = null, $component = null, $filearea = null, $itemid = 0, $userid = null) { return new moodle1_file_manager($this, $contextid, $component, $filearea, $itemid, $userid); }
[ "public", "function", "get_file_manager", "(", "$", "contextid", "=", "null", ",", "$", "component", "=", "null", ",", "$", "filearea", "=", "null", ",", "$", "itemid", "=", "0", ",", "$", "userid", "=", "null", ")", "{", "return", "new", "moodle1_file_manager", "(", "$", "this", ",", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "$", "userid", ")", ";", "}" ]
Creates and returns new instance of the file manager @param int $contextid the default context id of the files being migrated @param string $component the default component name of the files being migrated @param string $filearea the default file area of the files being migrated @param int $itemid the default item id of the files being migrated @param int $userid initial user id of the files being migrated @return moodle1_file_manager
[ "Creates", "and", "returns", "new", "instance", "of", "the", "file", "manager" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L580-L582
212,032
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_converter.migrate_referenced_files
public static function migrate_referenced_files($text, moodle1_file_manager $fileman) { $files = self::find_referenced_files($text); if (!empty($files)) { foreach ($files as $file) { try { $fileman->migrate_file('course_files'.$file, dirname($file)); } catch (moodle1_convert_exception $e) { // file probably does not exist $fileman->log('error migrating file', backup::LOG_WARNING, 'course_files'.$file); } } $text = self::rewrite_filephp_usage($text, $files); } return $text; }
php
public static function migrate_referenced_files($text, moodle1_file_manager $fileman) { $files = self::find_referenced_files($text); if (!empty($files)) { foreach ($files as $file) { try { $fileman->migrate_file('course_files'.$file, dirname($file)); } catch (moodle1_convert_exception $e) { // file probably does not exist $fileman->log('error migrating file', backup::LOG_WARNING, 'course_files'.$file); } } $text = self::rewrite_filephp_usage($text, $files); } return $text; }
[ "public", "static", "function", "migrate_referenced_files", "(", "$", "text", ",", "moodle1_file_manager", "$", "fileman", ")", "{", "$", "files", "=", "self", "::", "find_referenced_files", "(", "$", "text", ")", ";", "if", "(", "!", "empty", "(", "$", "files", ")", ")", "{", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "try", "{", "$", "fileman", "->", "migrate_file", "(", "'course_files'", ".", "$", "file", ",", "dirname", "(", "$", "file", ")", ")", ";", "}", "catch", "(", "moodle1_convert_exception", "$", "e", ")", "{", "// file probably does not exist", "$", "fileman", "->", "log", "(", "'error migrating file'", ",", "backup", "::", "LOG_WARNING", ",", "'course_files'", ".", "$", "file", ")", ";", "}", "}", "$", "text", "=", "self", "::", "rewrite_filephp_usage", "(", "$", "text", ",", "$", "files", ")", ";", "}", "return", "$", "text", ";", "}" ]
Migrates all course files referenced from the hypertext using the given filemanager This is typically used to convert images embedded into the intro fields. @param string $text hypertext containing $@FILEPHP@$ referenced @param moodle1_file_manager $fileman file manager to use for the file migration @return string the original $text with $@FILEPHP@$ references replaced with the new @@PLUGINFILE@@
[ "Migrates", "all", "course", "files", "referenced", "from", "the", "hypertext", "using", "the", "given", "filemanager" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L605-L621
212,033
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_xml_transformer.process
public function process($content) { // the content should be a string. If array or object is given, try our best recursively // but inform the developer if (is_array($content)) { debugging('Moodle1 XML transformer should not process arrays but plain content always', DEBUG_DEVELOPER); foreach($content as $key => $plaincontent) { $content[$key] = $this->process($plaincontent); } return $content; } else if (is_object($content)) { debugging('Moodle1 XML transformer should not process objects but plain content always', DEBUG_DEVELOPER); foreach((array)$content as $key => $plaincontent) { $content[$key] = $this->process($plaincontent); } return (object)$content; } // try to deal with some trivial cases first if (is_null($content)) { return '$@NULL@$'; } else if ($content === '') { return ''; } else if (is_numeric($content)) { return $content; } else if (strlen($content) < 32) { return $content; } return $content; }
php
public function process($content) { // the content should be a string. If array or object is given, try our best recursively // but inform the developer if (is_array($content)) { debugging('Moodle1 XML transformer should not process arrays but plain content always', DEBUG_DEVELOPER); foreach($content as $key => $plaincontent) { $content[$key] = $this->process($plaincontent); } return $content; } else if (is_object($content)) { debugging('Moodle1 XML transformer should not process objects but plain content always', DEBUG_DEVELOPER); foreach((array)$content as $key => $plaincontent) { $content[$key] = $this->process($plaincontent); } return (object)$content; } // try to deal with some trivial cases first if (is_null($content)) { return '$@NULL@$'; } else if ($content === '') { return ''; } else if (is_numeric($content)) { return $content; } else if (strlen($content) < 32) { return $content; } return $content; }
[ "public", "function", "process", "(", "$", "content", ")", "{", "// the content should be a string. If array or object is given, try our best recursively", "// but inform the developer", "if", "(", "is_array", "(", "$", "content", ")", ")", "{", "debugging", "(", "'Moodle1 XML transformer should not process arrays but plain content always'", ",", "DEBUG_DEVELOPER", ")", ";", "foreach", "(", "$", "content", "as", "$", "key", "=>", "$", "plaincontent", ")", "{", "$", "content", "[", "$", "key", "]", "=", "$", "this", "->", "process", "(", "$", "plaincontent", ")", ";", "}", "return", "$", "content", ";", "}", "else", "if", "(", "is_object", "(", "$", "content", ")", ")", "{", "debugging", "(", "'Moodle1 XML transformer should not process objects but plain content always'", ",", "DEBUG_DEVELOPER", ")", ";", "foreach", "(", "(", "array", ")", "$", "content", "as", "$", "key", "=>", "$", "plaincontent", ")", "{", "$", "content", "[", "$", "key", "]", "=", "$", "this", "->", "process", "(", "$", "plaincontent", ")", ";", "}", "return", "(", "object", ")", "$", "content", ";", "}", "// try to deal with some trivial cases first", "if", "(", "is_null", "(", "$", "content", ")", ")", "{", "return", "'$@NULL@$'", ";", "}", "else", "if", "(", "$", "content", "===", "''", ")", "{", "return", "''", ";", "}", "else", "if", "(", "is_numeric", "(", "$", "content", ")", ")", "{", "return", "$", "content", ";", "}", "else", "if", "(", "strlen", "(", "$", "content", ")", "<", "32", ")", "{", "return", "$", "content", ";", "}", "return", "$", "content", ";", "}" ]
Modify the content before it is writter to a file @param string|mixed $content
[ "Modify", "the", "content", "before", "it", "is", "writter", "to", "a", "file" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L787-L821
212,034
moodle/moodle
backup/converter/moodle1/lib.php
convert_path.apply_recipes
public function apply_recipes(array $data) { $cooked = array(); foreach ($data as $name => $value) { // lower case rocks! $name = strtolower($name); if (is_array($value)) { if ($this->is_grouped()) { $value = $this->apply_recipes($value); } else { throw new convert_path_exception('non_grouped_path_with_array_values'); } } // drop legacy fields if (in_array($name, $this->dropfields)) { continue; } // fields renaming if (array_key_exists($name, $this->renamefields)) { $name = $this->renamefields[$name]; } $cooked[$name] = $value; } // adding new fields foreach ($this->newfields as $name => $value) { $cooked[$name] = $value; } return $cooked; }
php
public function apply_recipes(array $data) { $cooked = array(); foreach ($data as $name => $value) { // lower case rocks! $name = strtolower($name); if (is_array($value)) { if ($this->is_grouped()) { $value = $this->apply_recipes($value); } else { throw new convert_path_exception('non_grouped_path_with_array_values'); } } // drop legacy fields if (in_array($name, $this->dropfields)) { continue; } // fields renaming if (array_key_exists($name, $this->renamefields)) { $name = $this->renamefields[$name]; } $cooked[$name] = $value; } // adding new fields foreach ($this->newfields as $name => $value) { $cooked[$name] = $value; } return $cooked; }
[ "public", "function", "apply_recipes", "(", "array", "$", "data", ")", "{", "$", "cooked", "=", "array", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "name", "=>", "$", "value", ")", "{", "// lower case rocks!", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "if", "(", "$", "this", "->", "is_grouped", "(", ")", ")", "{", "$", "value", "=", "$", "this", "->", "apply_recipes", "(", "$", "value", ")", ";", "}", "else", "{", "throw", "new", "convert_path_exception", "(", "'non_grouped_path_with_array_values'", ")", ";", "}", "}", "// drop legacy fields", "if", "(", "in_array", "(", "$", "name", ",", "$", "this", "->", "dropfields", ")", ")", "{", "continue", ";", "}", "// fields renaming", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "renamefields", ")", ")", "{", "$", "name", "=", "$", "this", "->", "renamefields", "[", "$", "name", "]", ";", "}", "$", "cooked", "[", "$", "name", "]", "=", "$", "value", ";", "}", "// adding new fields", "foreach", "(", "$", "this", "->", "newfields", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "cooked", "[", "$", "name", "]", "=", "$", "value", ";", "}", "return", "$", "cooked", ";", "}" ]
Cooks the parsed tags data by applying known recipes Recipes are used for common trivial operations like adding new fields or renaming fields. The handler's processing method receives cooked data. @param array $data the contents of the element @return array
[ "Cooks", "the", "parsed", "tags", "data", "by", "applying", "known", "recipes" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L994-L1029
212,035
moodle/moodle
backup/converter/moodle1/lib.php
convert_path.validate_name
protected function validate_name($name) { // Validate various name constraints, throwing exception if needed if (empty($name)) { throw new convert_path_exception('convert_path_emptyname', $name); } if (preg_replace('/\s/', '', $name) != $name) { throw new convert_path_exception('convert_path_whitespace', $name); } if (preg_replace('/[^\x30-\x39\x41-\x5a\x5f\x61-\x7a]/', '', $name) != $name) { throw new convert_path_exception('convert_path_notasciiname', $name); } }
php
protected function validate_name($name) { // Validate various name constraints, throwing exception if needed if (empty($name)) { throw new convert_path_exception('convert_path_emptyname', $name); } if (preg_replace('/\s/', '', $name) != $name) { throw new convert_path_exception('convert_path_whitespace', $name); } if (preg_replace('/[^\x30-\x39\x41-\x5a\x5f\x61-\x7a]/', '', $name) != $name) { throw new convert_path_exception('convert_path_notasciiname', $name); } }
[ "protected", "function", "validate_name", "(", "$", "name", ")", "{", "// Validate various name constraints, throwing exception if needed", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "throw", "new", "convert_path_exception", "(", "'convert_path_emptyname'", ",", "$", "name", ")", ";", "}", "if", "(", "preg_replace", "(", "'/\\s/'", ",", "''", ",", "$", "name", ")", "!=", "$", "name", ")", "{", "throw", "new", "convert_path_exception", "(", "'convert_path_whitespace'", ",", "$", "name", ")", ";", "}", "if", "(", "preg_replace", "(", "'/[^\\x30-\\x39\\x41-\\x5a\\x5f\\x61-\\x7a]/'", ",", "''", ",", "$", "name", ")", "!=", "$", "name", ")", "{", "throw", "new", "convert_path_exception", "(", "'convert_path_notasciiname'", ",", "$", "name", ")", ";", "}", "}" ]
Makes sure the given name is a valid element name Note it may look as if we used exceptions for code flow control here. That's not the case as we actually validate the code, not the user data. And the code is supposed to be correct. @param string @name the element given name @throws convert_path_exception @return void
[ "Makes", "sure", "the", "given", "name", "is", "a", "valid", "element", "name" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L1101-L1112
212,036
moodle/moodle
backup/converter/moodle1/lib.php
convert_path.validate_pobject
protected function validate_pobject($pobject) { if (!is_object($pobject)) { throw new convert_path_exception('convert_path_no_object', get_class($pobject)); } if (!method_exists($pobject, $this->get_processing_method()) and !method_exists($pobject, $this->get_end_method()) and !method_exists($pobject, $this->get_start_method())) { throw new convert_path_exception('convert_path_missing_method', get_class($pobject)); } }
php
protected function validate_pobject($pobject) { if (!is_object($pobject)) { throw new convert_path_exception('convert_path_no_object', get_class($pobject)); } if (!method_exists($pobject, $this->get_processing_method()) and !method_exists($pobject, $this->get_end_method()) and !method_exists($pobject, $this->get_start_method())) { throw new convert_path_exception('convert_path_missing_method', get_class($pobject)); } }
[ "protected", "function", "validate_pobject", "(", "$", "pobject", ")", "{", "if", "(", "!", "is_object", "(", "$", "pobject", ")", ")", "{", "throw", "new", "convert_path_exception", "(", "'convert_path_no_object'", ",", "get_class", "(", "$", "pobject", ")", ")", ";", "}", "if", "(", "!", "method_exists", "(", "$", "pobject", ",", "$", "this", "->", "get_processing_method", "(", ")", ")", "and", "!", "method_exists", "(", "$", "pobject", ",", "$", "this", "->", "get_end_method", "(", ")", ")", "and", "!", "method_exists", "(", "$", "pobject", ",", "$", "this", "->", "get_start_method", "(", ")", ")", ")", "{", "throw", "new", "convert_path_exception", "(", "'convert_path_missing_method'", ",", "get_class", "(", "$", "pobject", ")", ")", ";", "}", "}" ]
Makes sure that the given object is a valid processing object The processing object must be an object providing at least element's processing method or path-reached-end event listener or path-reached-start listener method. Note it may look as if we used exceptions for code flow control here. That's not the case as we actually validate the code, not the user data. And the code is supposed to be correct. @param object $pobject @throws convert_path_exception @return void
[ "Makes", "sure", "that", "the", "given", "object", "is", "a", "valid", "processing", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L1128-L1137
212,037
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_file_manager.migrate_file
public function migrate_file($sourcepath, $filepath = '/', $filename = null, $sortorder = 0, $timecreated = null, $timemodified = null) { // Normalise Windows paths a bit. $sourcepath = str_replace('\\', '/', $sourcepath); // PARAM_PATH must not be used on full OS path! if ($sourcepath !== clean_param($sourcepath, PARAM_PATH)) { throw new moodle1_convert_exception('file_invalid_path', $sourcepath); } $sourcefullpath = $this->basepath.'/'.$sourcepath; if (!is_readable($sourcefullpath)) { throw new moodle1_convert_exception('file_not_readable', $sourcefullpath); } // sanitize filepath if (empty($filepath)) { $filepath = '/'; } if (substr($filepath, -1) !== '/') { $filepath .= '/'; } $filepath = clean_param($filepath, PARAM_PATH); if (core_text::strlen($filepath) > 255) { throw new moodle1_convert_exception('file_path_longer_than_255_chars'); } if (is_null($filename)) { $filename = basename($sourcefullpath); } $filename = clean_param($filename, PARAM_FILE); if ($filename === '') { throw new moodle1_convert_exception('unsupported_chars_in_filename'); } if (is_null($timecreated)) { $timecreated = filectime($sourcefullpath); } if (is_null($timemodified)) { $timemodified = filemtime($sourcefullpath); } $filerecord = $this->make_file_record(array( 'filepath' => $filepath, 'filename' => $filename, 'sortorder' => $sortorder, 'mimetype' => mimeinfo('type', $sourcefullpath), 'timecreated' => $timecreated, 'timemodified' => $timemodified, )); list($filerecord['contenthash'], $filerecord['filesize'], $newfile) = $this->add_file_to_pool($sourcefullpath); $this->stash_file($filerecord); return $filerecord['id']; }
php
public function migrate_file($sourcepath, $filepath = '/', $filename = null, $sortorder = 0, $timecreated = null, $timemodified = null) { // Normalise Windows paths a bit. $sourcepath = str_replace('\\', '/', $sourcepath); // PARAM_PATH must not be used on full OS path! if ($sourcepath !== clean_param($sourcepath, PARAM_PATH)) { throw new moodle1_convert_exception('file_invalid_path', $sourcepath); } $sourcefullpath = $this->basepath.'/'.$sourcepath; if (!is_readable($sourcefullpath)) { throw new moodle1_convert_exception('file_not_readable', $sourcefullpath); } // sanitize filepath if (empty($filepath)) { $filepath = '/'; } if (substr($filepath, -1) !== '/') { $filepath .= '/'; } $filepath = clean_param($filepath, PARAM_PATH); if (core_text::strlen($filepath) > 255) { throw new moodle1_convert_exception('file_path_longer_than_255_chars'); } if (is_null($filename)) { $filename = basename($sourcefullpath); } $filename = clean_param($filename, PARAM_FILE); if ($filename === '') { throw new moodle1_convert_exception('unsupported_chars_in_filename'); } if (is_null($timecreated)) { $timecreated = filectime($sourcefullpath); } if (is_null($timemodified)) { $timemodified = filemtime($sourcefullpath); } $filerecord = $this->make_file_record(array( 'filepath' => $filepath, 'filename' => $filename, 'sortorder' => $sortorder, 'mimetype' => mimeinfo('type', $sourcefullpath), 'timecreated' => $timecreated, 'timemodified' => $timemodified, )); list($filerecord['contenthash'], $filerecord['filesize'], $newfile) = $this->add_file_to_pool($sourcefullpath); $this->stash_file($filerecord); return $filerecord['id']; }
[ "public", "function", "migrate_file", "(", "$", "sourcepath", ",", "$", "filepath", "=", "'/'", ",", "$", "filename", "=", "null", ",", "$", "sortorder", "=", "0", ",", "$", "timecreated", "=", "null", ",", "$", "timemodified", "=", "null", ")", "{", "// Normalise Windows paths a bit.", "$", "sourcepath", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "sourcepath", ")", ";", "// PARAM_PATH must not be used on full OS path!", "if", "(", "$", "sourcepath", "!==", "clean_param", "(", "$", "sourcepath", ",", "PARAM_PATH", ")", ")", "{", "throw", "new", "moodle1_convert_exception", "(", "'file_invalid_path'", ",", "$", "sourcepath", ")", ";", "}", "$", "sourcefullpath", "=", "$", "this", "->", "basepath", ".", "'/'", ".", "$", "sourcepath", ";", "if", "(", "!", "is_readable", "(", "$", "sourcefullpath", ")", ")", "{", "throw", "new", "moodle1_convert_exception", "(", "'file_not_readable'", ",", "$", "sourcefullpath", ")", ";", "}", "// sanitize filepath", "if", "(", "empty", "(", "$", "filepath", ")", ")", "{", "$", "filepath", "=", "'/'", ";", "}", "if", "(", "substr", "(", "$", "filepath", ",", "-", "1", ")", "!==", "'/'", ")", "{", "$", "filepath", ".=", "'/'", ";", "}", "$", "filepath", "=", "clean_param", "(", "$", "filepath", ",", "PARAM_PATH", ")", ";", "if", "(", "core_text", "::", "strlen", "(", "$", "filepath", ")", ">", "255", ")", "{", "throw", "new", "moodle1_convert_exception", "(", "'file_path_longer_than_255_chars'", ")", ";", "}", "if", "(", "is_null", "(", "$", "filename", ")", ")", "{", "$", "filename", "=", "basename", "(", "$", "sourcefullpath", ")", ";", "}", "$", "filename", "=", "clean_param", "(", "$", "filename", ",", "PARAM_FILE", ")", ";", "if", "(", "$", "filename", "===", "''", ")", "{", "throw", "new", "moodle1_convert_exception", "(", "'unsupported_chars_in_filename'", ")", ";", "}", "if", "(", "is_null", "(", "$", "timecreated", ")", ")", "{", "$", "timecreated", "=", "filectime", "(", "$", "sourcefullpath", ")", ";", "}", "if", "(", "is_null", "(", "$", "timemodified", ")", ")", "{", "$", "timemodified", "=", "filemtime", "(", "$", "sourcefullpath", ")", ";", "}", "$", "filerecord", "=", "$", "this", "->", "make_file_record", "(", "array", "(", "'filepath'", "=>", "$", "filepath", ",", "'filename'", "=>", "$", "filename", ",", "'sortorder'", "=>", "$", "sortorder", ",", "'mimetype'", "=>", "mimeinfo", "(", "'type'", ",", "$", "sourcefullpath", ")", ",", "'timecreated'", "=>", "$", "timecreated", ",", "'timemodified'", "=>", "$", "timemodified", ",", ")", ")", ";", "list", "(", "$", "filerecord", "[", "'contenthash'", "]", ",", "$", "filerecord", "[", "'filesize'", "]", ",", "$", "newfile", ")", "=", "$", "this", "->", "add_file_to_pool", "(", "$", "sourcefullpath", ")", ";", "$", "this", "->", "stash_file", "(", "$", "filerecord", ")", ";", "return", "$", "filerecord", "[", "'id'", "]", ";", "}" ]
Migrates one given file stored on disk @param string $sourcepath the path to the source local file within the backup archive {@example 'moddata/foobar/file.ext'} @param string $filepath the file path of the migrated file, defaults to the root directory '/' {@example '/sub/dir/'} @param string $filename the name of the migrated file, defaults to the same as the source file has @param int $sortorder the sortorder of the file (main files have sortorder set to 1) @param int $timecreated override the timestamp of when the migrated file should appear as created @param int $timemodified override the timestamp of when the migrated file should appear as modified @return int id of the migrated file
[ "Migrates", "one", "given", "file", "stored", "on", "disk" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L1224-L1284
212,038
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_file_manager.migrate_directory
public function migrate_directory($rootpath, $relpath='/') { // Check the trailing slash in the $rootpath if (substr($rootpath, -1) === '/') { debugging('moodle1_file_manager::migrate_directory() expects $rootpath without the trailing slash', DEBUG_DEVELOPER); $rootpath = substr($rootpath, 0, strlen($rootpath) - 1); } if (!file_exists($this->basepath.'/'.$rootpath.$relpath)) { return array(); } $fileids = array(); // make the fake file record for the directory itself $filerecord = $this->make_file_record(array('filepath' => $relpath, 'filename' => '.')); $this->stash_file($filerecord); $fileids[] = $filerecord['id']; $items = new DirectoryIterator($this->basepath.'/'.$rootpath.$relpath); foreach ($items as $item) { if ($item->isDot()) { continue; } if ($item->isLink()) { throw new moodle1_convert_exception('unexpected_symlink'); } if ($item->isFile()) { $fileids[] = $this->migrate_file(substr($item->getPathname(), strlen($this->basepath.'/')), $relpath, $item->getFilename(), 0, $item->getCTime(), $item->getMTime()); } else { $dirname = clean_param($item->getFilename(), PARAM_PATH); if ($dirname === '') { throw new moodle1_convert_exception('unsupported_chars_in_filename'); } // migrate subdirectories recursively $fileids = array_merge($fileids, $this->migrate_directory($rootpath, $relpath.$item->getFilename().'/')); } } return $fileids; }
php
public function migrate_directory($rootpath, $relpath='/') { // Check the trailing slash in the $rootpath if (substr($rootpath, -1) === '/') { debugging('moodle1_file_manager::migrate_directory() expects $rootpath without the trailing slash', DEBUG_DEVELOPER); $rootpath = substr($rootpath, 0, strlen($rootpath) - 1); } if (!file_exists($this->basepath.'/'.$rootpath.$relpath)) { return array(); } $fileids = array(); // make the fake file record for the directory itself $filerecord = $this->make_file_record(array('filepath' => $relpath, 'filename' => '.')); $this->stash_file($filerecord); $fileids[] = $filerecord['id']; $items = new DirectoryIterator($this->basepath.'/'.$rootpath.$relpath); foreach ($items as $item) { if ($item->isDot()) { continue; } if ($item->isLink()) { throw new moodle1_convert_exception('unexpected_symlink'); } if ($item->isFile()) { $fileids[] = $this->migrate_file(substr($item->getPathname(), strlen($this->basepath.'/')), $relpath, $item->getFilename(), 0, $item->getCTime(), $item->getMTime()); } else { $dirname = clean_param($item->getFilename(), PARAM_PATH); if ($dirname === '') { throw new moodle1_convert_exception('unsupported_chars_in_filename'); } // migrate subdirectories recursively $fileids = array_merge($fileids, $this->migrate_directory($rootpath, $relpath.$item->getFilename().'/')); } } return $fileids; }
[ "public", "function", "migrate_directory", "(", "$", "rootpath", ",", "$", "relpath", "=", "'/'", ")", "{", "// Check the trailing slash in the $rootpath", "if", "(", "substr", "(", "$", "rootpath", ",", "-", "1", ")", "===", "'/'", ")", "{", "debugging", "(", "'moodle1_file_manager::migrate_directory() expects $rootpath without the trailing slash'", ",", "DEBUG_DEVELOPER", ")", ";", "$", "rootpath", "=", "substr", "(", "$", "rootpath", ",", "0", ",", "strlen", "(", "$", "rootpath", ")", "-", "1", ")", ";", "}", "if", "(", "!", "file_exists", "(", "$", "this", "->", "basepath", ".", "'/'", ".", "$", "rootpath", ".", "$", "relpath", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "fileids", "=", "array", "(", ")", ";", "// make the fake file record for the directory itself", "$", "filerecord", "=", "$", "this", "->", "make_file_record", "(", "array", "(", "'filepath'", "=>", "$", "relpath", ",", "'filename'", "=>", "'.'", ")", ")", ";", "$", "this", "->", "stash_file", "(", "$", "filerecord", ")", ";", "$", "fileids", "[", "]", "=", "$", "filerecord", "[", "'id'", "]", ";", "$", "items", "=", "new", "DirectoryIterator", "(", "$", "this", "->", "basepath", ".", "'/'", ".", "$", "rootpath", ".", "$", "relpath", ")", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "if", "(", "$", "item", "->", "isDot", "(", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "item", "->", "isLink", "(", ")", ")", "{", "throw", "new", "moodle1_convert_exception", "(", "'unexpected_symlink'", ")", ";", "}", "if", "(", "$", "item", "->", "isFile", "(", ")", ")", "{", "$", "fileids", "[", "]", "=", "$", "this", "->", "migrate_file", "(", "substr", "(", "$", "item", "->", "getPathname", "(", ")", ",", "strlen", "(", "$", "this", "->", "basepath", ".", "'/'", ")", ")", ",", "$", "relpath", ",", "$", "item", "->", "getFilename", "(", ")", ",", "0", ",", "$", "item", "->", "getCTime", "(", ")", ",", "$", "item", "->", "getMTime", "(", ")", ")", ";", "}", "else", "{", "$", "dirname", "=", "clean_param", "(", "$", "item", "->", "getFilename", "(", ")", ",", "PARAM_PATH", ")", ";", "if", "(", "$", "dirname", "===", "''", ")", "{", "throw", "new", "moodle1_convert_exception", "(", "'unsupported_chars_in_filename'", ")", ";", "}", "// migrate subdirectories recursively", "$", "fileids", "=", "array_merge", "(", "$", "fileids", ",", "$", "this", "->", "migrate_directory", "(", "$", "rootpath", ",", "$", "relpath", ".", "$", "item", "->", "getFilename", "(", ")", ".", "'/'", ")", ")", ";", "}", "}", "return", "$", "fileids", ";", "}" ]
Migrates all files in the given directory @param string $rootpath path within the backup archive to the root directory containing the files {@example 'course_files'} @param string $relpath relative path used during the recursion - do not provide when calling this! @return array ids of the migrated files, empty array if the $rootpath not found
[ "Migrates", "all", "files", "in", "the", "given", "directory" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L1293-L1341
212,039
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_file_manager.make_file_record
protected function make_file_record(array $fileinfo) { $defaultrecord = array( 'contenthash' => file_storage::hash_from_string(''), 'contextid' => $this->contextid, 'component' => $this->component, 'filearea' => $this->filearea, 'itemid' => $this->itemid, 'filepath' => null, 'filename' => null, 'filesize' => 0, 'userid' => $this->userid, 'mimetype' => null, 'status' => 0, 'timecreated' => $now = time(), 'timemodified' => $now, 'source' => null, 'author' => null, 'license' => null, 'sortorder' => 0, ); if (!array_key_exists('id', $fileinfo)) { $defaultrecord['id'] = $this->converter->get_nextid(); } // override the default values with the explicit data provided and return return array_merge($defaultrecord, $fileinfo); }
php
protected function make_file_record(array $fileinfo) { $defaultrecord = array( 'contenthash' => file_storage::hash_from_string(''), 'contextid' => $this->contextid, 'component' => $this->component, 'filearea' => $this->filearea, 'itemid' => $this->itemid, 'filepath' => null, 'filename' => null, 'filesize' => 0, 'userid' => $this->userid, 'mimetype' => null, 'status' => 0, 'timecreated' => $now = time(), 'timemodified' => $now, 'source' => null, 'author' => null, 'license' => null, 'sortorder' => 0, ); if (!array_key_exists('id', $fileinfo)) { $defaultrecord['id'] = $this->converter->get_nextid(); } // override the default values with the explicit data provided and return return array_merge($defaultrecord, $fileinfo); }
[ "protected", "function", "make_file_record", "(", "array", "$", "fileinfo", ")", "{", "$", "defaultrecord", "=", "array", "(", "'contenthash'", "=>", "file_storage", "::", "hash_from_string", "(", "''", ")", ",", "'contextid'", "=>", "$", "this", "->", "contextid", ",", "'component'", "=>", "$", "this", "->", "component", ",", "'filearea'", "=>", "$", "this", "->", "filearea", ",", "'itemid'", "=>", "$", "this", "->", "itemid", ",", "'filepath'", "=>", "null", ",", "'filename'", "=>", "null", ",", "'filesize'", "=>", "0", ",", "'userid'", "=>", "$", "this", "->", "userid", ",", "'mimetype'", "=>", "null", ",", "'status'", "=>", "0", ",", "'timecreated'", "=>", "$", "now", "=", "time", "(", ")", ",", "'timemodified'", "=>", "$", "now", ",", "'source'", "=>", "null", ",", "'author'", "=>", "null", ",", "'license'", "=>", "null", ",", "'sortorder'", "=>", "0", ",", ")", ";", "if", "(", "!", "array_key_exists", "(", "'id'", ",", "$", "fileinfo", ")", ")", "{", "$", "defaultrecord", "[", "'id'", "]", "=", "$", "this", "->", "converter", "->", "get_nextid", "(", ")", ";", "}", "// override the default values with the explicit data provided and return", "return", "array_merge", "(", "$", "defaultrecord", ",", "$", "fileinfo", ")", ";", "}" ]
Prepares a fake record from the files table @param array $fileinfo explicit file data @return array
[ "Prepares", "a", "fake", "record", "from", "the", "files", "table" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L1380-L1408
212,040
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_file_manager.add_file_to_pool
protected function add_file_to_pool($pathname) { if (!is_readable($pathname)) { throw new moodle1_convert_exception('file_not_readable'); } $contenthash = file_storage::hash_from_path($pathname); $filesize = filesize($pathname); $hashpath = $this->converter->get_workdir_path().'/files/'.substr($contenthash, 0, 2); $hashfile = "$hashpath/$contenthash"; if (file_exists($hashfile)) { if (filesize($hashfile) !== $filesize) { // congratulations! you have found two files with different size and the same // content hash. or, something were wrong (which is more likely) throw new moodle1_convert_exception('same_hash_different_size'); } $newfile = false; } else { check_dir_exists($hashpath); $newfile = true; if (!copy($pathname, $hashfile)) { throw new moodle1_convert_exception('unable_to_copy_file'); } if (filesize($hashfile) !== $filesize) { throw new moodle1_convert_exception('filesize_different_after_copy'); } } return array($contenthash, $filesize, $newfile); }
php
protected function add_file_to_pool($pathname) { if (!is_readable($pathname)) { throw new moodle1_convert_exception('file_not_readable'); } $contenthash = file_storage::hash_from_path($pathname); $filesize = filesize($pathname); $hashpath = $this->converter->get_workdir_path().'/files/'.substr($contenthash, 0, 2); $hashfile = "$hashpath/$contenthash"; if (file_exists($hashfile)) { if (filesize($hashfile) !== $filesize) { // congratulations! you have found two files with different size and the same // content hash. or, something were wrong (which is more likely) throw new moodle1_convert_exception('same_hash_different_size'); } $newfile = false; } else { check_dir_exists($hashpath); $newfile = true; if (!copy($pathname, $hashfile)) { throw new moodle1_convert_exception('unable_to_copy_file'); } if (filesize($hashfile) !== $filesize) { throw new moodle1_convert_exception('filesize_different_after_copy'); } } return array($contenthash, $filesize, $newfile); }
[ "protected", "function", "add_file_to_pool", "(", "$", "pathname", ")", "{", "if", "(", "!", "is_readable", "(", "$", "pathname", ")", ")", "{", "throw", "new", "moodle1_convert_exception", "(", "'file_not_readable'", ")", ";", "}", "$", "contenthash", "=", "file_storage", "::", "hash_from_path", "(", "$", "pathname", ")", ";", "$", "filesize", "=", "filesize", "(", "$", "pathname", ")", ";", "$", "hashpath", "=", "$", "this", "->", "converter", "->", "get_workdir_path", "(", ")", ".", "'/files/'", ".", "substr", "(", "$", "contenthash", ",", "0", ",", "2", ")", ";", "$", "hashfile", "=", "\"$hashpath/$contenthash\"", ";", "if", "(", "file_exists", "(", "$", "hashfile", ")", ")", "{", "if", "(", "filesize", "(", "$", "hashfile", ")", "!==", "$", "filesize", ")", "{", "// congratulations! you have found two files with different size and the same", "// content hash. or, something were wrong (which is more likely)", "throw", "new", "moodle1_convert_exception", "(", "'same_hash_different_size'", ")", ";", "}", "$", "newfile", "=", "false", ";", "}", "else", "{", "check_dir_exists", "(", "$", "hashpath", ")", ";", "$", "newfile", "=", "true", ";", "if", "(", "!", "copy", "(", "$", "pathname", ",", "$", "hashfile", ")", ")", "{", "throw", "new", "moodle1_convert_exception", "(", "'unable_to_copy_file'", ")", ";", "}", "if", "(", "filesize", "(", "$", "hashfile", ")", "!==", "$", "filesize", ")", "{", "throw", "new", "moodle1_convert_exception", "(", "'filesize_different_after_copy'", ")", ";", "}", "}", "return", "array", "(", "$", "contenthash", ",", "$", "filesize", ",", "$", "newfile", ")", ";", "}" ]
Copies the given file to the pool directory Returns an array containing SHA1 hash of the file contents, the file size and a flag indicating whether the file was actually added to the pool or whether it was already there. @param string $pathname the full path to the file @return array with keys (string)contenthash, (int)filesize, (bool)newfile
[ "Copies", "the", "given", "file", "to", "the", "pool", "directory" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L1420-L1453
212,041
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_file_manager.stash_file
protected function stash_file(array $filerecord) { $this->converter->set_stash('files', $filerecord, $filerecord['id']); $this->fileids[] = $filerecord['id']; }
php
protected function stash_file(array $filerecord) { $this->converter->set_stash('files', $filerecord, $filerecord['id']); $this->fileids[] = $filerecord['id']; }
[ "protected", "function", "stash_file", "(", "array", "$", "filerecord", ")", "{", "$", "this", "->", "converter", "->", "set_stash", "(", "'files'", ",", "$", "filerecord", ",", "$", "filerecord", "[", "'id'", "]", ")", ";", "$", "this", "->", "fileids", "[", "]", "=", "$", "filerecord", "[", "'id'", "]", ";", "}" ]
Stashes the file record into 'files' stash and adds the record id to list of migrated files @param array $filerecord
[ "Stashes", "the", "file", "record", "into", "files", "stash", "and", "adds", "the", "record", "id", "to", "list", "of", "migrated", "files" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L1460-L1463
212,042
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_inforef_manager.add_ref
public function add_ref($item, $id) { $this->validate_item($item); $this->refs[$item][$id] = true; }
php
public function add_ref($item, $id) { $this->validate_item($item); $this->refs[$item][$id] = true; }
[ "public", "function", "add_ref", "(", "$", "item", ",", "$", "id", ")", "{", "$", "this", "->", "validate_item", "(", "$", "item", ")", ";", "$", "this", "->", "refs", "[", "$", "item", "]", "[", "$", "id", "]", "=", "true", ";", "}" ]
Adds a reference @param string $item the name of referenced item (like user, file, scale, outcome or grade_item) @param int $id the value of the reference
[ "Adds", "a", "reference" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L1502-L1505
212,043
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_inforef_manager.add_refs
public function add_refs($item, array $ids) { $this->validate_item($item); foreach ($ids as $id) { $this->refs[$item][$id] = true; } }
php
public function add_refs($item, array $ids) { $this->validate_item($item); foreach ($ids as $id) { $this->refs[$item][$id] = true; } }
[ "public", "function", "add_refs", "(", "$", "item", ",", "array", "$", "ids", ")", "{", "$", "this", "->", "validate_item", "(", "$", "item", ")", ";", "foreach", "(", "$", "ids", "as", "$", "id", ")", "{", "$", "this", "->", "refs", "[", "$", "item", "]", "[", "$", "id", "]", "=", "true", ";", "}", "}" ]
Adds a bulk of references @param string $item the name of referenced item (like user, file, scale, outcome or grade_item) @param array $ids the list of referenced ids
[ "Adds", "a", "bulk", "of", "references" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L1513-L1518
212,044
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_inforef_manager.write_refs
public function write_refs(xml_writer $xmlwriter) { $xmlwriter->begin_tag('inforef'); foreach ($this->refs as $item => $ids) { $xmlwriter->begin_tag($item.'ref'); foreach (array_keys($ids) as $id) { $xmlwriter->full_tag($item, $id); } $xmlwriter->end_tag($item.'ref'); } $xmlwriter->end_tag('inforef'); }
php
public function write_refs(xml_writer $xmlwriter) { $xmlwriter->begin_tag('inforef'); foreach ($this->refs as $item => $ids) { $xmlwriter->begin_tag($item.'ref'); foreach (array_keys($ids) as $id) { $xmlwriter->full_tag($item, $id); } $xmlwriter->end_tag($item.'ref'); } $xmlwriter->end_tag('inforef'); }
[ "public", "function", "write_refs", "(", "xml_writer", "$", "xmlwriter", ")", "{", "$", "xmlwriter", "->", "begin_tag", "(", "'inforef'", ")", ";", "foreach", "(", "$", "this", "->", "refs", "as", "$", "item", "=>", "$", "ids", ")", "{", "$", "xmlwriter", "->", "begin_tag", "(", "$", "item", ".", "'ref'", ")", ";", "foreach", "(", "array_keys", "(", "$", "ids", ")", "as", "$", "id", ")", "{", "$", "xmlwriter", "->", "full_tag", "(", "$", "item", ",", "$", "id", ")", ";", "}", "$", "xmlwriter", "->", "end_tag", "(", "$", "item", ".", "'ref'", ")", ";", "}", "$", "xmlwriter", "->", "end_tag", "(", "'inforef'", ")", ";", "}" ]
Writes the current references using a given opened xml writer @param xml_writer $xmlwriter
[ "Writes", "the", "current", "references", "using", "a", "given", "opened", "xml", "writer" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L1525-L1535
212,045
moodle/moodle
backup/converter/moodle1/lib.php
moodle1_inforef_manager.validate_item
protected function validate_item($item) { $allowed = array( 'user' => true, 'grouping' => true, 'group' => true, 'role' => true, 'file' => true, 'scale' => true, 'outcome' => true, 'grade_item' => true, 'question_category' => true ); if (!isset($allowed[$item])) { throw new coding_exception('Invalid inforef item type'); } }
php
protected function validate_item($item) { $allowed = array( 'user' => true, 'grouping' => true, 'group' => true, 'role' => true, 'file' => true, 'scale' => true, 'outcome' => true, 'grade_item' => true, 'question_category' => true ); if (!isset($allowed[$item])) { throw new coding_exception('Invalid inforef item type'); } }
[ "protected", "function", "validate_item", "(", "$", "item", ")", "{", "$", "allowed", "=", "array", "(", "'user'", "=>", "true", ",", "'grouping'", "=>", "true", ",", "'group'", "=>", "true", ",", "'role'", "=>", "true", ",", "'file'", "=>", "true", ",", "'scale'", "=>", "true", ",", "'outcome'", "=>", "true", ",", "'grade_item'", "=>", "true", ",", "'question_category'", "=>", "true", ")", ";", "if", "(", "!", "isset", "(", "$", "allowed", "[", "$", "item", "]", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid inforef item type'", ")", ";", "}", "}" ]
Makes sure that the given name is a valid citizen of inforef.xml file @see backup_helper::get_inforef_itemnames() @param string $item the name of reference (like user, file, scale, outcome or grade_item) @throws coding_exception
[ "Makes", "sure", "that", "the", "given", "name", "is", "a", "valid", "citizen", "of", "inforef", ".", "xml", "file" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/lib.php#L1544-L1561
212,046
moodle/moodle
admin/tool/installaddon/classes/installfromzip_form.php
tool_installaddon_installfromzip_form.definition
public function definition() { $mform = $this->_form; $installer = $this->_customdata['installer']; $mform->addElement('header', 'general', get_string('installfromzip', 'tool_installaddon')); $mform->addHelpButton('general', 'installfromzip', 'tool_installaddon'); $mform->addElement('filepicker', 'zipfile', get_string('installfromzipfile', 'tool_installaddon'), null, array('accepted_types' => '.zip')); $mform->addHelpButton('zipfile', 'installfromzipfile', 'tool_installaddon'); $mform->addRule('zipfile', null, 'required', null, 'client'); $options = $installer->get_plugin_types_menu(); $mform->addElement('select', 'plugintype', get_string('installfromziptype', 'tool_installaddon'), $options, array('id' => 'tool_installaddon_installfromzip_plugintype')); $mform->addHelpButton('plugintype', 'installfromziptype', 'tool_installaddon'); $mform->setAdvanced('plugintype'); $mform->addElement('static', 'permcheck', '', html_writer::span(get_string('permcheck', 'tool_installaddon'), '', array('id' => 'tool_installaddon_installfromzip_permcheck'))); $mform->setAdvanced('permcheck'); $mform->addElement('text', 'rootdir', get_string('installfromziprootdir', 'tool_installaddon')); $mform->addHelpButton('rootdir', 'installfromziprootdir', 'tool_installaddon'); $mform->setType('rootdir', PARAM_PLUGIN); $mform->setAdvanced('rootdir'); $this->add_action_buttons(false, get_string('installfromzipsubmit', 'tool_installaddon')); }
php
public function definition() { $mform = $this->_form; $installer = $this->_customdata['installer']; $mform->addElement('header', 'general', get_string('installfromzip', 'tool_installaddon')); $mform->addHelpButton('general', 'installfromzip', 'tool_installaddon'); $mform->addElement('filepicker', 'zipfile', get_string('installfromzipfile', 'tool_installaddon'), null, array('accepted_types' => '.zip')); $mform->addHelpButton('zipfile', 'installfromzipfile', 'tool_installaddon'); $mform->addRule('zipfile', null, 'required', null, 'client'); $options = $installer->get_plugin_types_menu(); $mform->addElement('select', 'plugintype', get_string('installfromziptype', 'tool_installaddon'), $options, array('id' => 'tool_installaddon_installfromzip_plugintype')); $mform->addHelpButton('plugintype', 'installfromziptype', 'tool_installaddon'); $mform->setAdvanced('plugintype'); $mform->addElement('static', 'permcheck', '', html_writer::span(get_string('permcheck', 'tool_installaddon'), '', array('id' => 'tool_installaddon_installfromzip_permcheck'))); $mform->setAdvanced('permcheck'); $mform->addElement('text', 'rootdir', get_string('installfromziprootdir', 'tool_installaddon')); $mform->addHelpButton('rootdir', 'installfromziprootdir', 'tool_installaddon'); $mform->setType('rootdir', PARAM_PLUGIN); $mform->setAdvanced('rootdir'); $this->add_action_buttons(false, get_string('installfromzipsubmit', 'tool_installaddon')); }
[ "public", "function", "definition", "(", ")", "{", "$", "mform", "=", "$", "this", "->", "_form", ";", "$", "installer", "=", "$", "this", "->", "_customdata", "[", "'installer'", "]", ";", "$", "mform", "->", "addElement", "(", "'header'", ",", "'general'", ",", "get_string", "(", "'installfromzip'", ",", "'tool_installaddon'", ")", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'general'", ",", "'installfromzip'", ",", "'tool_installaddon'", ")", ";", "$", "mform", "->", "addElement", "(", "'filepicker'", ",", "'zipfile'", ",", "get_string", "(", "'installfromzipfile'", ",", "'tool_installaddon'", ")", ",", "null", ",", "array", "(", "'accepted_types'", "=>", "'.zip'", ")", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'zipfile'", ",", "'installfromzipfile'", ",", "'tool_installaddon'", ")", ";", "$", "mform", "->", "addRule", "(", "'zipfile'", ",", "null", ",", "'required'", ",", "null", ",", "'client'", ")", ";", "$", "options", "=", "$", "installer", "->", "get_plugin_types_menu", "(", ")", ";", "$", "mform", "->", "addElement", "(", "'select'", ",", "'plugintype'", ",", "get_string", "(", "'installfromziptype'", ",", "'tool_installaddon'", ")", ",", "$", "options", ",", "array", "(", "'id'", "=>", "'tool_installaddon_installfromzip_plugintype'", ")", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'plugintype'", ",", "'installfromziptype'", ",", "'tool_installaddon'", ")", ";", "$", "mform", "->", "setAdvanced", "(", "'plugintype'", ")", ";", "$", "mform", "->", "addElement", "(", "'static'", ",", "'permcheck'", ",", "''", ",", "html_writer", "::", "span", "(", "get_string", "(", "'permcheck'", ",", "'tool_installaddon'", ")", ",", "''", ",", "array", "(", "'id'", "=>", "'tool_installaddon_installfromzip_permcheck'", ")", ")", ")", ";", "$", "mform", "->", "setAdvanced", "(", "'permcheck'", ")", ";", "$", "mform", "->", "addElement", "(", "'text'", ",", "'rootdir'", ",", "get_string", "(", "'installfromziprootdir'", ",", "'tool_installaddon'", ")", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'rootdir'", ",", "'installfromziprootdir'", ",", "'tool_installaddon'", ")", ";", "$", "mform", "->", "setType", "(", "'rootdir'", ",", "PARAM_PLUGIN", ")", ";", "$", "mform", "->", "setAdvanced", "(", "'rootdir'", ")", ";", "$", "this", "->", "add_action_buttons", "(", "false", ",", "get_string", "(", "'installfromzipsubmit'", ",", "'tool_installaddon'", ")", ")", ";", "}" ]
Defines the form elements
[ "Defines", "the", "form", "elements" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/installaddon/classes/installfromzip_form.php#L41-L71
212,047
moodle/moodle
admin/tool/installaddon/classes/installfromzip_form.php
tool_installaddon_installfromzip_form.require_explicit_plugintype
public function require_explicit_plugintype() { $mform = $this->_form; $mform->addRule('plugintype', get_string('required'), 'required', null, 'client'); $mform->setAdvanced('plugintype', false); $mform->setAdvanced('permcheck', false); $typedetectionfailed = $mform->createElement('static', 'typedetectionfailed', '', html_writer::span(get_string('typedetectionfailed', 'tool_installaddon'), 'error')); $mform->insertElementBefore($typedetectionfailed, 'permcheck'); }
php
public function require_explicit_plugintype() { $mform = $this->_form; $mform->addRule('plugintype', get_string('required'), 'required', null, 'client'); $mform->setAdvanced('plugintype', false); $mform->setAdvanced('permcheck', false); $typedetectionfailed = $mform->createElement('static', 'typedetectionfailed', '', html_writer::span(get_string('typedetectionfailed', 'tool_installaddon'), 'error')); $mform->insertElementBefore($typedetectionfailed, 'permcheck'); }
[ "public", "function", "require_explicit_plugintype", "(", ")", "{", "$", "mform", "=", "$", "this", "->", "_form", ";", "$", "mform", "->", "addRule", "(", "'plugintype'", ",", "get_string", "(", "'required'", ")", ",", "'required'", ",", "null", ",", "'client'", ")", ";", "$", "mform", "->", "setAdvanced", "(", "'plugintype'", ",", "false", ")", ";", "$", "mform", "->", "setAdvanced", "(", "'permcheck'", ",", "false", ")", ";", "$", "typedetectionfailed", "=", "$", "mform", "->", "createElement", "(", "'static'", ",", "'typedetectionfailed'", ",", "''", ",", "html_writer", "::", "span", "(", "get_string", "(", "'typedetectionfailed'", ",", "'tool_installaddon'", ")", ",", "'error'", ")", ")", ";", "$", "mform", "->", "insertElementBefore", "(", "$", "typedetectionfailed", ",", "'permcheck'", ")", ";", "}" ]
Switch the form to a mode that requires manual selection of the plugin type
[ "Switch", "the", "form", "to", "a", "mode", "that", "requires", "manual", "selection", "of", "the", "plugin", "type" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/installaddon/classes/installfromzip_form.php#L76-L87
212,048
moodle/moodle
admin/tool/installaddon/classes/installfromzip_form.php
tool_installaddon_installfromzip_form.selected_plugintype_mismatch
public function selected_plugintype_mismatch($detected) { $mform = $this->_form; $mform->addRule('plugintype', get_string('required'), 'required', null, 'client'); $mform->setAdvanced('plugintype', false); $mform->setAdvanced('permcheck', false); $mform->insertElementBefore($mform->createElement('static', 'selectedplugintypemismatch', '', html_writer::span(get_string('typedetectionmismatch', 'tool_installaddon', $detected), 'error')), 'permcheck'); }
php
public function selected_plugintype_mismatch($detected) { $mform = $this->_form; $mform->addRule('plugintype', get_string('required'), 'required', null, 'client'); $mform->setAdvanced('plugintype', false); $mform->setAdvanced('permcheck', false); $mform->insertElementBefore($mform->createElement('static', 'selectedplugintypemismatch', '', html_writer::span(get_string('typedetectionmismatch', 'tool_installaddon', $detected), 'error')), 'permcheck'); }
[ "public", "function", "selected_plugintype_mismatch", "(", "$", "detected", ")", "{", "$", "mform", "=", "$", "this", "->", "_form", ";", "$", "mform", "->", "addRule", "(", "'plugintype'", ",", "get_string", "(", "'required'", ")", ",", "'required'", ",", "null", ",", "'client'", ")", ";", "$", "mform", "->", "setAdvanced", "(", "'plugintype'", ",", "false", ")", ";", "$", "mform", "->", "setAdvanced", "(", "'permcheck'", ",", "false", ")", ";", "$", "mform", "->", "insertElementBefore", "(", "$", "mform", "->", "createElement", "(", "'static'", ",", "'selectedplugintypemismatch'", ",", "''", ",", "html_writer", "::", "span", "(", "get_string", "(", "'typedetectionmismatch'", ",", "'tool_installaddon'", ",", "$", "detected", ")", ",", "'error'", ")", ")", ",", "'permcheck'", ")", ";", "}" ]
Warn that the selected plugin type does not match the detected one. @param string $detected detected plugin type
[ "Warn", "that", "the", "selected", "plugin", "type", "does", "not", "match", "the", "detected", "one", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/installaddon/classes/installfromzip_form.php#L94-L102
212,049
moodle/moodle
admin/tool/installaddon/classes/installfromzip_form.php
tool_installaddon_installfromzip_form.validation
public function validation($data, $files) { $pluginman = core_plugin_manager::instance(); $errors = parent::validation($data, $files); if (!empty($data['plugintype'])) { if (!$pluginman->is_plugintype_writable($data['plugintype'])) { $path = $pluginman->get_plugintype_root($data['plugintype']); $errors['plugintype'] = get_string('permcheckresultno', 'tool_installaddon', array('path' => $path)); } } return $errors; }
php
public function validation($data, $files) { $pluginman = core_plugin_manager::instance(); $errors = parent::validation($data, $files); if (!empty($data['plugintype'])) { if (!$pluginman->is_plugintype_writable($data['plugintype'])) { $path = $pluginman->get_plugintype_root($data['plugintype']); $errors['plugintype'] = get_string('permcheckresultno', 'tool_installaddon', array('path' => $path)); } } return $errors; }
[ "public", "function", "validation", "(", "$", "data", ",", "$", "files", ")", "{", "$", "pluginman", "=", "core_plugin_manager", "::", "instance", "(", ")", ";", "$", "errors", "=", "parent", "::", "validation", "(", "$", "data", ",", "$", "files", ")", ";", "if", "(", "!", "empty", "(", "$", "data", "[", "'plugintype'", "]", ")", ")", "{", "if", "(", "!", "$", "pluginman", "->", "is_plugintype_writable", "(", "$", "data", "[", "'plugintype'", "]", ")", ")", "{", "$", "path", "=", "$", "pluginman", "->", "get_plugintype_root", "(", "$", "data", "[", "'plugintype'", "]", ")", ";", "$", "errors", "[", "'plugintype'", "]", "=", "get_string", "(", "'permcheckresultno'", ",", "'tool_installaddon'", ",", "array", "(", "'path'", "=>", "$", "path", ")", ")", ";", "}", "}", "return", "$", "errors", ";", "}" ]
Validate the form fields @param array $data @param array $files @return array (string)field name => (string)validation error text
[ "Validate", "the", "form", "fields" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/installaddon/classes/installfromzip_form.php#L111-L124
212,050
moodle/moodle
mod/assign/classes/privacy/assign_plugin_request_data.php
assign_plugin_request_data.populate_submissions_and_grades
public function populate_submissions_and_grades() { global $DB; if (empty($this->get_userids())) { throw new \coding_exception('Please use set_userids() before calling this method.'); } list($sql, $params) = $DB->get_in_or_equal($this->get_userids(), SQL_PARAMS_NAMED); $params['assign'] = $this->get_assign()->get_instance()->id; $this->submissions = $DB->get_records_select('assign_submission', "assignment = :assign AND userid $sql", $params); $this->grades = $DB->get_records_select('assign_grades', "assignment = :assign AND userid $sql", $params); }
php
public function populate_submissions_and_grades() { global $DB; if (empty($this->get_userids())) { throw new \coding_exception('Please use set_userids() before calling this method.'); } list($sql, $params) = $DB->get_in_or_equal($this->get_userids(), SQL_PARAMS_NAMED); $params['assign'] = $this->get_assign()->get_instance()->id; $this->submissions = $DB->get_records_select('assign_submission', "assignment = :assign AND userid $sql", $params); $this->grades = $DB->get_records_select('assign_grades', "assignment = :assign AND userid $sql", $params); }
[ "public", "function", "populate_submissions_and_grades", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "this", "->", "get_userids", "(", ")", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Please use set_userids() before calling this method.'", ")", ";", "}", "list", "(", "$", "sql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "this", "->", "get_userids", "(", ")", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "params", "[", "'assign'", "]", "=", "$", "this", "->", "get_assign", "(", ")", "->", "get_instance", "(", ")", "->", "id", ";", "$", "this", "->", "submissions", "=", "$", "DB", "->", "get_records_select", "(", "'assign_submission'", ",", "\"assignment = :assign AND userid $sql\"", ",", "$", "params", ")", ";", "$", "this", "->", "grades", "=", "$", "DB", "->", "get_records_select", "(", "'assign_grades'", ",", "\"assignment = :assign AND userid $sql\"", ",", "$", "params", ")", ";", "}" ]
Fetches all of the submissions and grades related to the User IDs provided. Use get_grades, get_submissions etc to retrieve this information.
[ "Fetches", "all", "of", "the", "submissions", "and", "grades", "related", "to", "the", "User", "IDs", "provided", ".", "Use", "get_grades", "get_submissions", "etc", "to", "retrieve", "this", "information", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/classes/privacy/assign_plugin_request_data.php#L194-L205
212,051
moodle/moodle
lib/htmlpurifier/HTMLPurifier/ConfigSchema.php
HTMLPurifier_ConfigSchema.makeFromSerial
public static function makeFromSerial() { $contents = file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema.ser'); $r = unserialize($contents); if (!$r) { $hash = sha1($contents); trigger_error("Unserialization of configuration schema failed, sha1 of file was $hash", E_USER_ERROR); } return $r; }
php
public static function makeFromSerial() { $contents = file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema.ser'); $r = unserialize($contents); if (!$r) { $hash = sha1($contents); trigger_error("Unserialization of configuration schema failed, sha1 of file was $hash", E_USER_ERROR); } return $r; }
[ "public", "static", "function", "makeFromSerial", "(", ")", "{", "$", "contents", "=", "file_get_contents", "(", "HTMLPURIFIER_PREFIX", ".", "'/HTMLPurifier/ConfigSchema/schema.ser'", ")", ";", "$", "r", "=", "unserialize", "(", "$", "contents", ")", ";", "if", "(", "!", "$", "r", ")", "{", "$", "hash", "=", "sha1", "(", "$", "contents", ")", ";", "trigger_error", "(", "\"Unserialization of configuration schema failed, sha1 of file was $hash\"", ",", "E_USER_ERROR", ")", ";", "}", "return", "$", "r", ";", "}" ]
Unserializes the default ConfigSchema. @return HTMLPurifier_ConfigSchema
[ "Unserializes", "the", "default", "ConfigSchema", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/ConfigSchema.php#L69-L78
212,052
moodle/moodle
lib/htmlpurifier/HTMLPurifier/ConfigSchema.php
HTMLPurifier_ConfigSchema.instance
public static function instance($prototype = null) { if ($prototype !== null) { HTMLPurifier_ConfigSchema::$singleton = $prototype; } elseif (HTMLPurifier_ConfigSchema::$singleton === null || $prototype === true) { HTMLPurifier_ConfigSchema::$singleton = HTMLPurifier_ConfigSchema::makeFromSerial(); } return HTMLPurifier_ConfigSchema::$singleton; }
php
public static function instance($prototype = null) { if ($prototype !== null) { HTMLPurifier_ConfigSchema::$singleton = $prototype; } elseif (HTMLPurifier_ConfigSchema::$singleton === null || $prototype === true) { HTMLPurifier_ConfigSchema::$singleton = HTMLPurifier_ConfigSchema::makeFromSerial(); } return HTMLPurifier_ConfigSchema::$singleton; }
[ "public", "static", "function", "instance", "(", "$", "prototype", "=", "null", ")", "{", "if", "(", "$", "prototype", "!==", "null", ")", "{", "HTMLPurifier_ConfigSchema", "::", "$", "singleton", "=", "$", "prototype", ";", "}", "elseif", "(", "HTMLPurifier_ConfigSchema", "::", "$", "singleton", "===", "null", "||", "$", "prototype", "===", "true", ")", "{", "HTMLPurifier_ConfigSchema", "::", "$", "singleton", "=", "HTMLPurifier_ConfigSchema", "::", "makeFromSerial", "(", ")", ";", "}", "return", "HTMLPurifier_ConfigSchema", "::", "$", "singleton", ";", "}" ]
Retrieves an instance of the application-wide configuration definition. @param HTMLPurifier_ConfigSchema $prototype @return HTMLPurifier_ConfigSchema
[ "Retrieves", "an", "instance", "of", "the", "application", "-", "wide", "configuration", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/ConfigSchema.php#L85-L93
212,053
moodle/moodle
lib/htmlpurifier/HTMLPurifier/ConfigSchema.php
HTMLPurifier_ConfigSchema.addValueAliases
public function addValueAliases($key, $aliases) { if (!isset($this->info[$key]->aliases)) { $this->info[$key]->aliases = array(); } foreach ($aliases as $alias => $real) { $this->info[$key]->aliases[$alias] = $real; } }
php
public function addValueAliases($key, $aliases) { if (!isset($this->info[$key]->aliases)) { $this->info[$key]->aliases = array(); } foreach ($aliases as $alias => $real) { $this->info[$key]->aliases[$alias] = $real; } }
[ "public", "function", "addValueAliases", "(", "$", "key", ",", "$", "aliases", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "info", "[", "$", "key", "]", "->", "aliases", ")", ")", "{", "$", "this", "->", "info", "[", "$", "key", "]", "->", "aliases", "=", "array", "(", ")", ";", "}", "foreach", "(", "$", "aliases", "as", "$", "alias", "=>", "$", "real", ")", "{", "$", "this", "->", "info", "[", "$", "key", "]", "->", "aliases", "[", "$", "alias", "]", "=", "$", "real", ";", "}", "}" ]
Defines a directive value alias. Directive value aliases are convenient for developers because it lets them set a directive to several values and get the same result. @param string $key Name of Directive @param array $aliases Hash of aliased values to the real alias
[ "Defines", "a", "directive", "value", "alias", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/ConfigSchema.php#L126-L134
212,054
moodle/moodle
lib/htmlpurifier/HTMLPurifier/ConfigSchema.php
HTMLPurifier_ConfigSchema.addAlias
public function addAlias($key, $new_key) { $obj = new stdClass; $obj->key = $new_key; $obj->isAlias = true; $this->info[$key] = $obj; }
php
public function addAlias($key, $new_key) { $obj = new stdClass; $obj->key = $new_key; $obj->isAlias = true; $this->info[$key] = $obj; }
[ "public", "function", "addAlias", "(", "$", "key", ",", "$", "new_key", ")", "{", "$", "obj", "=", "new", "stdClass", ";", "$", "obj", "->", "key", "=", "$", "new_key", ";", "$", "obj", "->", "isAlias", "=", "true", ";", "$", "this", "->", "info", "[", "$", "key", "]", "=", "$", "obj", ";", "}" ]
Defines a directive alias for backwards compatibility @param string $key Directive that will be aliased @param string $new_key Directive that the alias will be to
[ "Defines", "a", "directive", "alias", "for", "backwards", "compatibility" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/ConfigSchema.php#L153-L159
212,055
moodle/moodle
lib/htmlpurifier/HTMLPurifier/ConfigSchema.php
HTMLPurifier_ConfigSchema.postProcess
public function postProcess() { foreach ($this->info as $key => $v) { if (count((array) $v) == 1) { $this->info[$key] = $v->type; } elseif (count((array) $v) == 2 && isset($v->allow_null)) { $this->info[$key] = -$v->type; } } }
php
public function postProcess() { foreach ($this->info as $key => $v) { if (count((array) $v) == 1) { $this->info[$key] = $v->type; } elseif (count((array) $v) == 2 && isset($v->allow_null)) { $this->info[$key] = -$v->type; } } }
[ "public", "function", "postProcess", "(", ")", "{", "foreach", "(", "$", "this", "->", "info", "as", "$", "key", "=>", "$", "v", ")", "{", "if", "(", "count", "(", "(", "array", ")", "$", "v", ")", "==", "1", ")", "{", "$", "this", "->", "info", "[", "$", "key", "]", "=", "$", "v", "->", "type", ";", "}", "elseif", "(", "count", "(", "(", "array", ")", "$", "v", ")", "==", "2", "&&", "isset", "(", "$", "v", "->", "allow_null", ")", ")", "{", "$", "this", "->", "info", "[", "$", "key", "]", "=", "-", "$", "v", "->", "type", ";", "}", "}", "}" ]
Replaces any stdClass that only has the type property with type integer.
[ "Replaces", "any", "stdClass", "that", "only", "has", "the", "type", "property", "with", "type", "integer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/ConfigSchema.php#L164-L173
212,056
moodle/moodle
blog/classes/external.php
external.validate_access_and_filters
protected static function validate_access_and_filters($rawwsfilters) { global $CFG; if (empty($CFG->enableblogs)) { throw new moodle_exception('blogdisable', 'blog'); } // Init filters. $filterstype = array( 'courseid' => PARAM_INT, 'groupid' => PARAM_INT, 'userid' => PARAM_INT, 'tagid' => PARAM_INT, 'tag' => PARAM_NOTAGS, 'cmid' => PARAM_INT, 'entryid' => PARAM_INT, 'search' => PARAM_RAW ); $filters = array( 'courseid' => null, 'groupid' => null, 'userid' => null, 'tagid' => null, 'tag' => null, 'cmid' => null, 'entryid' => null, 'search' => null ); foreach ($rawwsfilters as $filter) { $name = trim($filter['name']); if (!isset($filterstype[$name])) { throw new moodle_exception('errorinvalidparam', 'webservice', '', $name); } $filters[$name] = clean_param($filter['value'], $filterstype[$name]); } // Do not overwrite here the filters, blog_get_headers and blog_listing will take care of that. list($courseid, $userid) = blog_validate_access($filters['courseid'], $filters['cmid'], $filters['groupid'], $filters['entryid'], $filters['userid']); if ($courseid && $courseid != SITEID) { $context = context_course::instance($courseid); self::validate_context($context); } else { $context = context_system::instance(); if ($CFG->bloglevel == BLOG_GLOBAL_LEVEL) { // Everybody can see anything - no login required unless site is locked down using forcelogin. if ($CFG->forcelogin) { self::validate_context($context); } } else { self::validate_context($context); } } // Courseid and userid may not be the same that the ones in $filters. return array($context, $filters, $courseid, $userid); }
php
protected static function validate_access_and_filters($rawwsfilters) { global $CFG; if (empty($CFG->enableblogs)) { throw new moodle_exception('blogdisable', 'blog'); } // Init filters. $filterstype = array( 'courseid' => PARAM_INT, 'groupid' => PARAM_INT, 'userid' => PARAM_INT, 'tagid' => PARAM_INT, 'tag' => PARAM_NOTAGS, 'cmid' => PARAM_INT, 'entryid' => PARAM_INT, 'search' => PARAM_RAW ); $filters = array( 'courseid' => null, 'groupid' => null, 'userid' => null, 'tagid' => null, 'tag' => null, 'cmid' => null, 'entryid' => null, 'search' => null ); foreach ($rawwsfilters as $filter) { $name = trim($filter['name']); if (!isset($filterstype[$name])) { throw new moodle_exception('errorinvalidparam', 'webservice', '', $name); } $filters[$name] = clean_param($filter['value'], $filterstype[$name]); } // Do not overwrite here the filters, blog_get_headers and blog_listing will take care of that. list($courseid, $userid) = blog_validate_access($filters['courseid'], $filters['cmid'], $filters['groupid'], $filters['entryid'], $filters['userid']); if ($courseid && $courseid != SITEID) { $context = context_course::instance($courseid); self::validate_context($context); } else { $context = context_system::instance(); if ($CFG->bloglevel == BLOG_GLOBAL_LEVEL) { // Everybody can see anything - no login required unless site is locked down using forcelogin. if ($CFG->forcelogin) { self::validate_context($context); } } else { self::validate_context($context); } } // Courseid and userid may not be the same that the ones in $filters. return array($context, $filters, $courseid, $userid); }
[ "protected", "static", "function", "validate_access_and_filters", "(", "$", "rawwsfilters", ")", "{", "global", "$", "CFG", ";", "if", "(", "empty", "(", "$", "CFG", "->", "enableblogs", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'blogdisable'", ",", "'blog'", ")", ";", "}", "// Init filters.", "$", "filterstype", "=", "array", "(", "'courseid'", "=>", "PARAM_INT", ",", "'groupid'", "=>", "PARAM_INT", ",", "'userid'", "=>", "PARAM_INT", ",", "'tagid'", "=>", "PARAM_INT", ",", "'tag'", "=>", "PARAM_NOTAGS", ",", "'cmid'", "=>", "PARAM_INT", ",", "'entryid'", "=>", "PARAM_INT", ",", "'search'", "=>", "PARAM_RAW", ")", ";", "$", "filters", "=", "array", "(", "'courseid'", "=>", "null", ",", "'groupid'", "=>", "null", ",", "'userid'", "=>", "null", ",", "'tagid'", "=>", "null", ",", "'tag'", "=>", "null", ",", "'cmid'", "=>", "null", ",", "'entryid'", "=>", "null", ",", "'search'", "=>", "null", ")", ";", "foreach", "(", "$", "rawwsfilters", "as", "$", "filter", ")", "{", "$", "name", "=", "trim", "(", "$", "filter", "[", "'name'", "]", ")", ";", "if", "(", "!", "isset", "(", "$", "filterstype", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'errorinvalidparam'", ",", "'webservice'", ",", "''", ",", "$", "name", ")", ";", "}", "$", "filters", "[", "$", "name", "]", "=", "clean_param", "(", "$", "filter", "[", "'value'", "]", ",", "$", "filterstype", "[", "$", "name", "]", ")", ";", "}", "// Do not overwrite here the filters, blog_get_headers and blog_listing will take care of that.", "list", "(", "$", "courseid", ",", "$", "userid", ")", "=", "blog_validate_access", "(", "$", "filters", "[", "'courseid'", "]", ",", "$", "filters", "[", "'cmid'", "]", ",", "$", "filters", "[", "'groupid'", "]", ",", "$", "filters", "[", "'entryid'", "]", ",", "$", "filters", "[", "'userid'", "]", ")", ";", "if", "(", "$", "courseid", "&&", "$", "courseid", "!=", "SITEID", ")", "{", "$", "context", "=", "context_course", "::", "instance", "(", "$", "courseid", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "}", "else", "{", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "if", "(", "$", "CFG", "->", "bloglevel", "==", "BLOG_GLOBAL_LEVEL", ")", "{", "// Everybody can see anything - no login required unless site is locked down using forcelogin.", "if", "(", "$", "CFG", "->", "forcelogin", ")", "{", "self", "::", "validate_context", "(", "$", "context", ")", ";", "}", "}", "else", "{", "self", "::", "validate_context", "(", "$", "context", ")", ";", "}", "}", "// Courseid and userid may not be the same that the ones in $filters.", "return", "array", "(", "$", "context", ",", "$", "filters", ",", "$", "courseid", ",", "$", "userid", ")", ";", "}" ]
Validate access to the blog and the filters to apply when listing entries. @param array $rawwsfilters array containing the filters in WS format @return array context, filters to apply and the calculated courseid and user @since Moodle 3.6
[ "Validate", "access", "to", "the", "blog", "and", "the", "filters", "to", "apply", "when", "listing", "entries", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blog/classes/external.php#L58-L115
212,057
moodle/moodle
blog/classes/external.php
external.get_entries
public static function get_entries($filters = array(), $page = 0, $perpage = 10) { global $PAGE; $warnings = array(); $params = self::validate_parameters(self::get_entries_parameters(), array('filters' => $filters, 'page' => $page, 'perpage' => $perpage)); list($context, $filters, $courseid, $userid) = self::validate_access_and_filters($params['filters']); $PAGE->set_context($context); // Needed by internal APIs. $output = $PAGE->get_renderer('core'); // Get filters. $blogheaders = blog_get_headers($filters['courseid'], $filters['groupid'], $filters['userid'], $filters['tagid'], $filters['tag'], $filters['cmid'], $filters['entryid'], $filters['search']); $bloglisting = new \blog_listing($blogheaders['filters']); $page = $params['page']; $limit = empty($params['perpage']) ? get_user_preferences('blogpagesize', 10) : $params['perpage']; $start = $page * $limit; $entries = $bloglisting->get_entries($start, $limit); $totalentries = $bloglisting->count_entries(); $exportedentries = array(); foreach ($entries as $entry) { $exporter = new post_exporter($entry, array('context' => $context)); $exportedentries[] = $exporter->export($output); } return array( 'warnings' => $warnings, 'entries' => $exportedentries, 'totalentries' => $totalentries, ); }
php
public static function get_entries($filters = array(), $page = 0, $perpage = 10) { global $PAGE; $warnings = array(); $params = self::validate_parameters(self::get_entries_parameters(), array('filters' => $filters, 'page' => $page, 'perpage' => $perpage)); list($context, $filters, $courseid, $userid) = self::validate_access_and_filters($params['filters']); $PAGE->set_context($context); // Needed by internal APIs. $output = $PAGE->get_renderer('core'); // Get filters. $blogheaders = blog_get_headers($filters['courseid'], $filters['groupid'], $filters['userid'], $filters['tagid'], $filters['tag'], $filters['cmid'], $filters['entryid'], $filters['search']); $bloglisting = new \blog_listing($blogheaders['filters']); $page = $params['page']; $limit = empty($params['perpage']) ? get_user_preferences('blogpagesize', 10) : $params['perpage']; $start = $page * $limit; $entries = $bloglisting->get_entries($start, $limit); $totalentries = $bloglisting->count_entries(); $exportedentries = array(); foreach ($entries as $entry) { $exporter = new post_exporter($entry, array('context' => $context)); $exportedentries[] = $exporter->export($output); } return array( 'warnings' => $warnings, 'entries' => $exportedentries, 'totalentries' => $totalentries, ); }
[ "public", "static", "function", "get_entries", "(", "$", "filters", "=", "array", "(", ")", ",", "$", "page", "=", "0", ",", "$", "perpage", "=", "10", ")", "{", "global", "$", "PAGE", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_entries_parameters", "(", ")", ",", "array", "(", "'filters'", "=>", "$", "filters", ",", "'page'", "=>", "$", "page", ",", "'perpage'", "=>", "$", "perpage", ")", ")", ";", "list", "(", "$", "context", ",", "$", "filters", ",", "$", "courseid", ",", "$", "userid", ")", "=", "self", "::", "validate_access_and_filters", "(", "$", "params", "[", "'filters'", "]", ")", ";", "$", "PAGE", "->", "set_context", "(", "$", "context", ")", ";", "// Needed by internal APIs.", "$", "output", "=", "$", "PAGE", "->", "get_renderer", "(", "'core'", ")", ";", "// Get filters.", "$", "blogheaders", "=", "blog_get_headers", "(", "$", "filters", "[", "'courseid'", "]", ",", "$", "filters", "[", "'groupid'", "]", ",", "$", "filters", "[", "'userid'", "]", ",", "$", "filters", "[", "'tagid'", "]", ",", "$", "filters", "[", "'tag'", "]", ",", "$", "filters", "[", "'cmid'", "]", ",", "$", "filters", "[", "'entryid'", "]", ",", "$", "filters", "[", "'search'", "]", ")", ";", "$", "bloglisting", "=", "new", "\\", "blog_listing", "(", "$", "blogheaders", "[", "'filters'", "]", ")", ";", "$", "page", "=", "$", "params", "[", "'page'", "]", ";", "$", "limit", "=", "empty", "(", "$", "params", "[", "'perpage'", "]", ")", "?", "get_user_preferences", "(", "'blogpagesize'", ",", "10", ")", ":", "$", "params", "[", "'perpage'", "]", ";", "$", "start", "=", "$", "page", "*", "$", "limit", ";", "$", "entries", "=", "$", "bloglisting", "->", "get_entries", "(", "$", "start", ",", "$", "limit", ")", ";", "$", "totalentries", "=", "$", "bloglisting", "->", "count_entries", "(", ")", ";", "$", "exportedentries", "=", "array", "(", ")", ";", "foreach", "(", "$", "entries", "as", "$", "entry", ")", "{", "$", "exporter", "=", "new", "post_exporter", "(", "$", "entry", ",", "array", "(", "'context'", "=>", "$", "context", ")", ")", ";", "$", "exportedentries", "[", "]", "=", "$", "exporter", "->", "export", "(", "$", "output", ")", ";", "}", "return", "array", "(", "'warnings'", "=>", "$", "warnings", ",", "'entries'", "=>", "$", "exportedentries", ",", "'totalentries'", "=>", "$", "totalentries", ",", ")", ";", "}" ]
Return blog entries. @param array $filters the parameters to filter the blog listing @param int $page the blog page to return @param int $perpage the number of posts to return per page @return array with the blog entries and warnings @since Moodle 3.6
[ "Return", "blog", "entries", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blog/classes/external.php#L160-L193
212,058
moodle/moodle
blog/classes/external.php
external.view_entries
public static function view_entries($filters = array()) { $warnings = array(); $params = self::validate_parameters(self::view_entries_parameters(), array('filters' => $filters)); list($context, $filters, $courseid, $userid) = self::validate_access_and_filters($params['filters']); $eventparams = array( 'other' => array('entryid' => $filters['entryid'], 'tagid' => $filters['tagid'], 'userid' => $userid, 'modid' => $filters['cmid'], 'groupid' => $filters['groupid'], 'search' => $filters['search'] ) ); if (!empty($userid)) { $eventparams['relateduserid'] = $userid; } $eventparams['other']['courseid'] = ($courseid === SITEID) ? 0 : $courseid; $event = \core\event\blog_entries_viewed::create($eventparams); $event->trigger(); return array( 'warnings' => $warnings, 'status' => true, ); }
php
public static function view_entries($filters = array()) { $warnings = array(); $params = self::validate_parameters(self::view_entries_parameters(), array('filters' => $filters)); list($context, $filters, $courseid, $userid) = self::validate_access_and_filters($params['filters']); $eventparams = array( 'other' => array('entryid' => $filters['entryid'], 'tagid' => $filters['tagid'], 'userid' => $userid, 'modid' => $filters['cmid'], 'groupid' => $filters['groupid'], 'search' => $filters['search'] ) ); if (!empty($userid)) { $eventparams['relateduserid'] = $userid; } $eventparams['other']['courseid'] = ($courseid === SITEID) ? 0 : $courseid; $event = \core\event\blog_entries_viewed::create($eventparams); $event->trigger(); return array( 'warnings' => $warnings, 'status' => true, ); }
[ "public", "static", "function", "view_entries", "(", "$", "filters", "=", "array", "(", ")", ")", "{", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "view_entries_parameters", "(", ")", ",", "array", "(", "'filters'", "=>", "$", "filters", ")", ")", ";", "list", "(", "$", "context", ",", "$", "filters", ",", "$", "courseid", ",", "$", "userid", ")", "=", "self", "::", "validate_access_and_filters", "(", "$", "params", "[", "'filters'", "]", ")", ";", "$", "eventparams", "=", "array", "(", "'other'", "=>", "array", "(", "'entryid'", "=>", "$", "filters", "[", "'entryid'", "]", ",", "'tagid'", "=>", "$", "filters", "[", "'tagid'", "]", ",", "'userid'", "=>", "$", "userid", ",", "'modid'", "=>", "$", "filters", "[", "'cmid'", "]", ",", "'groupid'", "=>", "$", "filters", "[", "'groupid'", "]", ",", "'search'", "=>", "$", "filters", "[", "'search'", "]", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "userid", ")", ")", "{", "$", "eventparams", "[", "'relateduserid'", "]", "=", "$", "userid", ";", "}", "$", "eventparams", "[", "'other'", "]", "[", "'courseid'", "]", "=", "(", "$", "courseid", "===", "SITEID", ")", "?", "0", ":", "$", "courseid", ";", "$", "event", "=", "\\", "core", "\\", "event", "\\", "blog_entries_viewed", "::", "create", "(", "$", "eventparams", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "return", "array", "(", "'warnings'", "=>", "$", "warnings", ",", "'status'", "=>", "true", ",", ")", ";", "}" ]
Trigger the blog_entries_viewed event. @param array $filters the parameters used in the filter of get_entries @return array with status result and warnings @since Moodle 3.6
[ "Trigger", "the", "blog_entries_viewed", "event", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blog/classes/external.php#L252-L275
212,059
moodle/moodle
lib/phpexcel/PHPExcel/Writer/OpenDocument/Styles.php
PHPExcel_Writer_OpenDocument_Styles.write
public function write(PHPExcel $pPHPExcel = null) { if (!$pPHPExcel) { $pPHPExcel = $this->getParentWriter()->getPHPExcel(); } $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); } // XML header $objWriter->startDocument('1.0', 'UTF-8'); // Content $objWriter->startElement('office:document-styles'); $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); $objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0'); $objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'); $objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'); $objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'); $objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'); $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); $objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'); $objWriter->writeAttribute('xmlns:presentation', 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0'); $objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'); $objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'); $objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'); $objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML'); $objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0'); $objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0'); $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); $objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer'); $objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc'); $objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events'); $objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report'); $objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2'); $objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml'); $objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); $objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table'); $objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/'); $objWriter->writeAttribute('office:version', '1.2'); $objWriter->writeElement('office:font-face-decls'); $objWriter->writeElement('office:styles'); $objWriter->writeElement('office:automatic-styles'); $objWriter->writeElement('office:master-styles'); $objWriter->endElement(); return $objWriter->getData(); }
php
public function write(PHPExcel $pPHPExcel = null) { if (!$pPHPExcel) { $pPHPExcel = $this->getParentWriter()->getPHPExcel(); } $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); } // XML header $objWriter->startDocument('1.0', 'UTF-8'); // Content $objWriter->startElement('office:document-styles'); $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); $objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0'); $objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'); $objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'); $objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'); $objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'); $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); $objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'); $objWriter->writeAttribute('xmlns:presentation', 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0'); $objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'); $objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'); $objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'); $objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML'); $objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0'); $objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0'); $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); $objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer'); $objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc'); $objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events'); $objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report'); $objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2'); $objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml'); $objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); $objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table'); $objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/'); $objWriter->writeAttribute('office:version', '1.2'); $objWriter->writeElement('office:font-face-decls'); $objWriter->writeElement('office:styles'); $objWriter->writeElement('office:automatic-styles'); $objWriter->writeElement('office:master-styles'); $objWriter->endElement(); return $objWriter->getData(); }
[ "public", "function", "write", "(", "PHPExcel", "$", "pPHPExcel", "=", "null", ")", "{", "if", "(", "!", "$", "pPHPExcel", ")", "{", "$", "pPHPExcel", "=", "$", "this", "->", "getParentWriter", "(", ")", "->", "getPHPExcel", "(", ")", ";", "}", "$", "objWriter", "=", "null", ";", "if", "(", "$", "this", "->", "getParentWriter", "(", ")", "->", "getUseDiskCaching", "(", ")", ")", "{", "$", "objWriter", "=", "new", "PHPExcel_Shared_XMLWriter", "(", "PHPExcel_Shared_XMLWriter", "::", "STORAGE_DISK", ",", "$", "this", "->", "getParentWriter", "(", ")", "->", "getDiskCachingDirectory", "(", ")", ")", ";", "}", "else", "{", "$", "objWriter", "=", "new", "PHPExcel_Shared_XMLWriter", "(", "PHPExcel_Shared_XMLWriter", "::", "STORAGE_MEMORY", ")", ";", "}", "// XML header", "$", "objWriter", "->", "startDocument", "(", "'1.0'", ",", "'UTF-8'", ")", ";", "// Content", "$", "objWriter", "->", "startElement", "(", "'office:document-styles'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:office'", ",", "'urn:oasis:names:tc:opendocument:xmlns:office:1.0'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:style'", ",", "'urn:oasis:names:tc:opendocument:xmlns:style:1.0'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:text'", ",", "'urn:oasis:names:tc:opendocument:xmlns:text:1.0'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:table'", ",", "'urn:oasis:names:tc:opendocument:xmlns:table:1.0'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:draw'", ",", "'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:fo'", ",", "'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:xlink'", ",", "'http://www.w3.org/1999/xlink'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:dc'", ",", "'http://purl.org/dc/elements/1.1/'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:meta'", ",", "'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:number'", ",", "'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:presentation'", ",", "'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:svg'", ",", "'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:chart'", ",", "'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:dr3d'", ",", "'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:math'", ",", "'http://www.w3.org/1998/Math/MathML'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:form'", ",", "'urn:oasis:names:tc:opendocument:xmlns:form:1.0'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:script'", ",", "'urn:oasis:names:tc:opendocument:xmlns:script:1.0'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:ooo'", ",", "'http://openoffice.org/2004/office'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:ooow'", ",", "'http://openoffice.org/2004/writer'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:oooc'", ",", "'http://openoffice.org/2004/calc'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:dom'", ",", "'http://www.w3.org/2001/xml-events'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:rpt'", ",", "'http://openoffice.org/2005/report'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:of'", ",", "'urn:oasis:names:tc:opendocument:xmlns:of:1.2'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:xhtml'", ",", "'http://www.w3.org/1999/xhtml'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:grddl'", ",", "'http://www.w3.org/2003/g/data-view#'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:tableooo'", ",", "'http://openoffice.org/2009/table'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'xmlns:css3t'", ",", "'http://www.w3.org/TR/css3-text/'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'office:version'", ",", "'1.2'", ")", ";", "$", "objWriter", "->", "writeElement", "(", "'office:font-face-decls'", ")", ";", "$", "objWriter", "->", "writeElement", "(", "'office:styles'", ")", ";", "$", "objWriter", "->", "writeElement", "(", "'office:automatic-styles'", ")", ";", "$", "objWriter", "->", "writeElement", "(", "'office:master-styles'", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "return", "$", "objWriter", "->", "getData", "(", ")", ";", "}" ]
Write styles.xml to XML format @param PHPExcel $pPHPExcel @return string XML Output @throws PHPExcel_Writer_Exception
[ "Write", "styles", ".", "xml", "to", "XML", "format" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/OpenDocument/Styles.php#L37-L91
212,060
moodle/moodle
blocks/navigation/renderer.php
block_navigation_renderer.navigation_tree
public function navigation_tree(global_navigation $navigation, $expansionlimit, array $options = array()) { $navigation->add_class('navigation_node'); $navigationattrs = array( 'class' => 'block_tree list', 'role' => 'tree', 'data-ajax-loader' => 'block_navigation/nav_loader'); $content = $this->navigation_node(array($navigation), $navigationattrs, $expansionlimit, $options); if (isset($navigation->id) && !is_numeric($navigation->id) && !empty($content)) { $content = $this->output->box($content, 'block_tree_box', $navigation->id); } return $content; }
php
public function navigation_tree(global_navigation $navigation, $expansionlimit, array $options = array()) { $navigation->add_class('navigation_node'); $navigationattrs = array( 'class' => 'block_tree list', 'role' => 'tree', 'data-ajax-loader' => 'block_navigation/nav_loader'); $content = $this->navigation_node(array($navigation), $navigationattrs, $expansionlimit, $options); if (isset($navigation->id) && !is_numeric($navigation->id) && !empty($content)) { $content = $this->output->box($content, 'block_tree_box', $navigation->id); } return $content; }
[ "public", "function", "navigation_tree", "(", "global_navigation", "$", "navigation", ",", "$", "expansionlimit", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "navigation", "->", "add_class", "(", "'navigation_node'", ")", ";", "$", "navigationattrs", "=", "array", "(", "'class'", "=>", "'block_tree list'", ",", "'role'", "=>", "'tree'", ",", "'data-ajax-loader'", "=>", "'block_navigation/nav_loader'", ")", ";", "$", "content", "=", "$", "this", "->", "navigation_node", "(", "array", "(", "$", "navigation", ")", ",", "$", "navigationattrs", ",", "$", "expansionlimit", ",", "$", "options", ")", ";", "if", "(", "isset", "(", "$", "navigation", "->", "id", ")", "&&", "!", "is_numeric", "(", "$", "navigation", "->", "id", ")", "&&", "!", "empty", "(", "$", "content", ")", ")", "{", "$", "content", "=", "$", "this", "->", "output", "->", "box", "(", "$", "content", ",", "'block_tree_box'", ",", "$", "navigation", "->", "id", ")", ";", "}", "return", "$", "content", ";", "}" ]
Returns the content of the navigation tree. @param global_navigation $navigation @param int $expansionlimit @param array $options @return string $content
[ "Returns", "the", "content", "of", "the", "navigation", "tree", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/navigation/renderer.php#L44-L55
212,061
moodle/moodle
mod/assign/renderable.php
assign_course_index_summary.add_assign_info
public function add_assign_info($cmid, $cmname, $sectionname, $timedue, $submissioninfo, $gradeinfo) { $this->assignments[] = array('cmid'=>$cmid, 'cmname'=>$cmname, 'sectionname'=>$sectionname, 'timedue'=>$timedue, 'submissioninfo'=>$submissioninfo, 'gradeinfo'=>$gradeinfo); }
php
public function add_assign_info($cmid, $cmname, $sectionname, $timedue, $submissioninfo, $gradeinfo) { $this->assignments[] = array('cmid'=>$cmid, 'cmname'=>$cmname, 'sectionname'=>$sectionname, 'timedue'=>$timedue, 'submissioninfo'=>$submissioninfo, 'gradeinfo'=>$gradeinfo); }
[ "public", "function", "add_assign_info", "(", "$", "cmid", ",", "$", "cmname", ",", "$", "sectionname", ",", "$", "timedue", ",", "$", "submissioninfo", ",", "$", "gradeinfo", ")", "{", "$", "this", "->", "assignments", "[", "]", "=", "array", "(", "'cmid'", "=>", "$", "cmid", ",", "'cmname'", "=>", "$", "cmname", ",", "'sectionname'", "=>", "$", "sectionname", ",", "'timedue'", "=>", "$", "timedue", ",", "'submissioninfo'", "=>", "$", "submissioninfo", ",", "'gradeinfo'", "=>", "$", "gradeinfo", ")", ";", "}" ]
Add a row of data to display on the course index page @param int $cmid - The course module id for generating a link @param string $cmname - The course module name for generating a link @param string $sectionname - The name of the course section (only if $usesections is true) @param int $timedue - The due date for the assignment - may be 0 if no duedate @param string $submissioninfo - A string with either the number of submitted assignments, or the status of the current users submission depending on capabilities. @param string $gradeinfo - The current users grade if they have been graded and it is not hidden.
[ "Add", "a", "row", "of", "data", "to", "display", "on", "the", "course", "index", "page" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/renderable.php#L837-L844
212,062
moodle/moodle
mod/assign/renderable.php
assign_files.preprocess
public function preprocess($dir, $filearea, $component) { global $CFG; foreach ($dir['subdirs'] as $subdir) { $this->preprocess($subdir, $filearea, $component); } foreach ($dir['files'] as $file) { $file->portfoliobutton = ''; $file->timemodified = userdate( $file->get_timemodified(), get_string('strftimedatetime', 'langconfig') ); if (!empty($CFG->enableportfolios)) { require_once($CFG->libdir . '/portfoliolib.php'); $button = new portfolio_add_button(); if (has_capability('mod/assign:exportownsubmission', $this->context)) { $portfolioparams = array('cmid' => $this->cm->id, 'fileid' => $file->get_id()); $button->set_callback_options('assign_portfolio_caller', $portfolioparams, 'mod_assign'); $button->set_format_by_file($file); $file->portfoliobutton = $button->to_html(PORTFOLIO_ADD_ICON_LINK); } } $path = '/' . $this->context->id . '/' . $component . '/' . $filearea . '/' . $file->get_itemid() . $file->get_filepath() . $file->get_filename(); $url = file_encode_url("$CFG->wwwroot/pluginfile.php", $path, true); $filename = $file->get_filename(); $file->fileurl = html_writer::link($url, $filename, [ 'target' => '_blank', ]); } }
php
public function preprocess($dir, $filearea, $component) { global $CFG; foreach ($dir['subdirs'] as $subdir) { $this->preprocess($subdir, $filearea, $component); } foreach ($dir['files'] as $file) { $file->portfoliobutton = ''; $file->timemodified = userdate( $file->get_timemodified(), get_string('strftimedatetime', 'langconfig') ); if (!empty($CFG->enableportfolios)) { require_once($CFG->libdir . '/portfoliolib.php'); $button = new portfolio_add_button(); if (has_capability('mod/assign:exportownsubmission', $this->context)) { $portfolioparams = array('cmid' => $this->cm->id, 'fileid' => $file->get_id()); $button->set_callback_options('assign_portfolio_caller', $portfolioparams, 'mod_assign'); $button->set_format_by_file($file); $file->portfoliobutton = $button->to_html(PORTFOLIO_ADD_ICON_LINK); } } $path = '/' . $this->context->id . '/' . $component . '/' . $filearea . '/' . $file->get_itemid() . $file->get_filepath() . $file->get_filename(); $url = file_encode_url("$CFG->wwwroot/pluginfile.php", $path, true); $filename = $file->get_filename(); $file->fileurl = html_writer::link($url, $filename, [ 'target' => '_blank', ]); } }
[ "public", "function", "preprocess", "(", "$", "dir", ",", "$", "filearea", ",", "$", "component", ")", "{", "global", "$", "CFG", ";", "foreach", "(", "$", "dir", "[", "'subdirs'", "]", "as", "$", "subdir", ")", "{", "$", "this", "->", "preprocess", "(", "$", "subdir", ",", "$", "filearea", ",", "$", "component", ")", ";", "}", "foreach", "(", "$", "dir", "[", "'files'", "]", "as", "$", "file", ")", "{", "$", "file", "->", "portfoliobutton", "=", "''", ";", "$", "file", "->", "timemodified", "=", "userdate", "(", "$", "file", "->", "get_timemodified", "(", ")", ",", "get_string", "(", "'strftimedatetime'", ",", "'langconfig'", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "enableportfolios", ")", ")", "{", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/portfoliolib.php'", ")", ";", "$", "button", "=", "new", "portfolio_add_button", "(", ")", ";", "if", "(", "has_capability", "(", "'mod/assign:exportownsubmission'", ",", "$", "this", "->", "context", ")", ")", "{", "$", "portfolioparams", "=", "array", "(", "'cmid'", "=>", "$", "this", "->", "cm", "->", "id", ",", "'fileid'", "=>", "$", "file", "->", "get_id", "(", ")", ")", ";", "$", "button", "->", "set_callback_options", "(", "'assign_portfolio_caller'", ",", "$", "portfolioparams", ",", "'mod_assign'", ")", ";", "$", "button", "->", "set_format_by_file", "(", "$", "file", ")", ";", "$", "file", "->", "portfoliobutton", "=", "$", "button", "->", "to_html", "(", "PORTFOLIO_ADD_ICON_LINK", ")", ";", "}", "}", "$", "path", "=", "'/'", ".", "$", "this", "->", "context", "->", "id", ".", "'/'", ".", "$", "component", ".", "'/'", ".", "$", "filearea", ".", "'/'", ".", "$", "file", "->", "get_itemid", "(", ")", ".", "$", "file", "->", "get_filepath", "(", ")", ".", "$", "file", "->", "get_filename", "(", ")", ";", "$", "url", "=", "file_encode_url", "(", "\"$CFG->wwwroot/pluginfile.php\"", ",", "$", "path", ",", "true", ")", ";", "$", "filename", "=", "$", "file", "->", "get_filename", "(", ")", ";", "$", "file", "->", "fileurl", "=", "html_writer", "::", "link", "(", "$", "url", ",", "$", "filename", ",", "[", "'target'", "=>", "'_blank'", ",", "]", ")", ";", "}", "}" ]
Preprocessing the file list to add the portfolio links if required. @param array $dir @param string $filearea @param string $component @return void
[ "Preprocessing", "the", "file", "list", "to", "add", "the", "portfolio", "links", "if", "required", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/renderable.php#L922-L964
212,063
moodle/moodle
analytics/classes/local/time_splitting/upcoming_periodic.php
upcoming_periodic.get_next_range
protected function get_next_range(\DateTimeImmutable $next) { $start = $next->getTimestamp(); $end = $next->add($this->periodicity())->getTimestamp(); return [ 'start' => $start, 'end' => $end, 'time' => $start ]; }
php
protected function get_next_range(\DateTimeImmutable $next) { $start = $next->getTimestamp(); $end = $next->add($this->periodicity())->getTimestamp(); return [ 'start' => $start, 'end' => $end, 'time' => $start ]; }
[ "protected", "function", "get_next_range", "(", "\\", "DateTimeImmutable", "$", "next", ")", "{", "$", "start", "=", "$", "next", "->", "getTimestamp", "(", ")", ";", "$", "end", "=", "$", "next", "->", "add", "(", "$", "this", "->", "periodicity", "(", ")", ")", "->", "getTimestamp", "(", ")", ";", "return", "[", "'start'", "=>", "$", "start", ",", "'end'", "=>", "$", "end", ",", "'time'", "=>", "$", "start", "]", ";", "}" ]
The next range indicator calculations should be based on upcoming dates. @param \DateTimeImmutable $next @return array
[ "The", "next", "range", "indicator", "calculations", "should", "be", "based", "on", "upcoming", "dates", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/time_splitting/upcoming_periodic.php#L44-L53
212,064
moodle/moodle
analytics/classes/local/time_splitting/upcoming_periodic.php
upcoming_periodic.get_first_start
protected function get_first_start() { global $DB; $cache = \cache::make('core', 'modelfirstanalyses'); $key = $this->modelid . '_' . $this->analysable->get_id(); $firstanalysis = $cache->get($key); if (!empty($firstanalysis)) { return $firstanalysis; } // This analysable has not yet been analysed, the start is therefore now (-1 so ready_to_predict can be executed). return time() - 1; }
php
protected function get_first_start() { global $DB; $cache = \cache::make('core', 'modelfirstanalyses'); $key = $this->modelid . '_' . $this->analysable->get_id(); $firstanalysis = $cache->get($key); if (!empty($firstanalysis)) { return $firstanalysis; } // This analysable has not yet been analysed, the start is therefore now (-1 so ready_to_predict can be executed). return time() - 1; }
[ "protected", "function", "get_first_start", "(", ")", "{", "global", "$", "DB", ";", "$", "cache", "=", "\\", "cache", "::", "make", "(", "'core'", ",", "'modelfirstanalyses'", ")", ";", "$", "key", "=", "$", "this", "->", "modelid", ".", "'_'", ".", "$", "this", "->", "analysable", "->", "get_id", "(", ")", ";", "$", "firstanalysis", "=", "$", "cache", "->", "get", "(", "$", "key", ")", ";", "if", "(", "!", "empty", "(", "$", "firstanalysis", ")", ")", "{", "return", "$", "firstanalysis", ";", "}", "// This analysable has not yet been analysed, the start is therefore now (-1 so ready_to_predict can be executed).", "return", "time", "(", ")", "-", "1", ";", "}" ]
Get the start of the first time range. Overwriten to start generating predictions about upcoming stuff from time(). @return int A timestamp.
[ "Get", "the", "start", "of", "the", "first", "time", "range", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/time_splitting/upcoming_periodic.php#L79-L92
212,065
moodle/moodle
admin/tool/usertours/classes/manager.php
manager.header
protected function header($title = null) { global $OUTPUT; // Print the page heading. echo $OUTPUT->header(); if ($title === null) { $title = get_string('tours', 'tool_usertours'); } echo $OUTPUT->heading($title); }
php
protected function header($title = null) { global $OUTPUT; // Print the page heading. echo $OUTPUT->header(); if ($title === null) { $title = get_string('tours', 'tool_usertours'); } echo $OUTPUT->heading($title); }
[ "protected", "function", "header", "(", "$", "title", "=", "null", ")", "{", "global", "$", "OUTPUT", ";", "// Print the page heading.", "echo", "$", "OUTPUT", "->", "header", "(", ")", ";", "if", "(", "$", "title", "===", "null", ")", "{", "$", "title", "=", "get_string", "(", "'tours'", ",", "'tool_usertours'", ")", ";", "}", "echo", "$", "OUTPUT", "->", "heading", "(", "$", "title", ")", ";", "}" ]
Print out the page header. @param string $title The title to display.
[ "Print", "out", "the", "page", "header", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L207-L218
212,066
moodle/moodle
admin/tool/usertours/classes/manager.php
manager.print_tour_list
protected function print_tour_list() { global $PAGE, $OUTPUT; $this->header(); echo \html_writer::span(get_string('tourlist_explanation', 'tool_usertours')); $table = new table\tour_list(); $tours = helper::get_tours(); foreach ($tours as $tour) { $table->add_data_keyed($table->format_row($tour)); } $table->finish_output(); $actions = [ (object) [ 'link' => helper::get_edit_tour_link(), 'linkproperties' => [], 'img' => 'b/tour-new', 'title' => get_string('newtour', 'tool_usertours'), ], (object) [ 'link' => helper::get_import_tour_link(), 'linkproperties' => [], 'img' => 'b/tour-import', 'title' => get_string('importtour', 'tool_usertours'), ], (object) [ 'link' => new \moodle_url('https://moodle.net/tours'), 'linkproperties' => [ 'target' => '_blank', ], 'img' => 'b/tour-shared', 'title' => get_string('sharedtourslink', 'tool_usertours'), ], ]; echo \html_writer::start_tag('div', [ 'class' => 'tour-actions', ]); echo \html_writer::start_tag('ul'); foreach ($actions as $config) { $action = \html_writer::start_tag('li'); $linkproperties = $config->linkproperties; $linkproperties['href'] = $config->link; $action .= \html_writer::start_tag('a', $linkproperties); $action .= $OUTPUT->pix_icon($config->img, $config->title, 'tool_usertours'); $action .= \html_writer::div($config->title); $action .= \html_writer::end_tag('a'); $action .= \html_writer::end_tag('li'); echo $action; } echo \html_writer::end_tag('ul'); echo \html_writer::end_tag('div'); // JS for Tour management. $PAGE->requires->js_call_amd('tool_usertours/managetours', 'setup'); $this->footer(); }
php
protected function print_tour_list() { global $PAGE, $OUTPUT; $this->header(); echo \html_writer::span(get_string('tourlist_explanation', 'tool_usertours')); $table = new table\tour_list(); $tours = helper::get_tours(); foreach ($tours as $tour) { $table->add_data_keyed($table->format_row($tour)); } $table->finish_output(); $actions = [ (object) [ 'link' => helper::get_edit_tour_link(), 'linkproperties' => [], 'img' => 'b/tour-new', 'title' => get_string('newtour', 'tool_usertours'), ], (object) [ 'link' => helper::get_import_tour_link(), 'linkproperties' => [], 'img' => 'b/tour-import', 'title' => get_string('importtour', 'tool_usertours'), ], (object) [ 'link' => new \moodle_url('https://moodle.net/tours'), 'linkproperties' => [ 'target' => '_blank', ], 'img' => 'b/tour-shared', 'title' => get_string('sharedtourslink', 'tool_usertours'), ], ]; echo \html_writer::start_tag('div', [ 'class' => 'tour-actions', ]); echo \html_writer::start_tag('ul'); foreach ($actions as $config) { $action = \html_writer::start_tag('li'); $linkproperties = $config->linkproperties; $linkproperties['href'] = $config->link; $action .= \html_writer::start_tag('a', $linkproperties); $action .= $OUTPUT->pix_icon($config->img, $config->title, 'tool_usertours'); $action .= \html_writer::div($config->title); $action .= \html_writer::end_tag('a'); $action .= \html_writer::end_tag('li'); echo $action; } echo \html_writer::end_tag('ul'); echo \html_writer::end_tag('div'); // JS for Tour management. $PAGE->requires->js_call_amd('tool_usertours/managetours', 'setup'); $this->footer(); }
[ "protected", "function", "print_tour_list", "(", ")", "{", "global", "$", "PAGE", ",", "$", "OUTPUT", ";", "$", "this", "->", "header", "(", ")", ";", "echo", "\\", "html_writer", "::", "span", "(", "get_string", "(", "'tourlist_explanation'", ",", "'tool_usertours'", ")", ")", ";", "$", "table", "=", "new", "table", "\\", "tour_list", "(", ")", ";", "$", "tours", "=", "helper", "::", "get_tours", "(", ")", ";", "foreach", "(", "$", "tours", "as", "$", "tour", ")", "{", "$", "table", "->", "add_data_keyed", "(", "$", "table", "->", "format_row", "(", "$", "tour", ")", ")", ";", "}", "$", "table", "->", "finish_output", "(", ")", ";", "$", "actions", "=", "[", "(", "object", ")", "[", "'link'", "=>", "helper", "::", "get_edit_tour_link", "(", ")", ",", "'linkproperties'", "=>", "[", "]", ",", "'img'", "=>", "'b/tour-new'", ",", "'title'", "=>", "get_string", "(", "'newtour'", ",", "'tool_usertours'", ")", ",", "]", ",", "(", "object", ")", "[", "'link'", "=>", "helper", "::", "get_import_tour_link", "(", ")", ",", "'linkproperties'", "=>", "[", "]", ",", "'img'", "=>", "'b/tour-import'", ",", "'title'", "=>", "get_string", "(", "'importtour'", ",", "'tool_usertours'", ")", ",", "]", ",", "(", "object", ")", "[", "'link'", "=>", "new", "\\", "moodle_url", "(", "'https://moodle.net/tours'", ")", ",", "'linkproperties'", "=>", "[", "'target'", "=>", "'_blank'", ",", "]", ",", "'img'", "=>", "'b/tour-shared'", ",", "'title'", "=>", "get_string", "(", "'sharedtourslink'", ",", "'tool_usertours'", ")", ",", "]", ",", "]", ";", "echo", "\\", "html_writer", "::", "start_tag", "(", "'div'", ",", "[", "'class'", "=>", "'tour-actions'", ",", "]", ")", ";", "echo", "\\", "html_writer", "::", "start_tag", "(", "'ul'", ")", ";", "foreach", "(", "$", "actions", "as", "$", "config", ")", "{", "$", "action", "=", "\\", "html_writer", "::", "start_tag", "(", "'li'", ")", ";", "$", "linkproperties", "=", "$", "config", "->", "linkproperties", ";", "$", "linkproperties", "[", "'href'", "]", "=", "$", "config", "->", "link", ";", "$", "action", ".=", "\\", "html_writer", "::", "start_tag", "(", "'a'", ",", "$", "linkproperties", ")", ";", "$", "action", ".=", "$", "OUTPUT", "->", "pix_icon", "(", "$", "config", "->", "img", ",", "$", "config", "->", "title", ",", "'tool_usertours'", ")", ";", "$", "action", ".=", "\\", "html_writer", "::", "div", "(", "$", "config", "->", "title", ")", ";", "$", "action", ".=", "\\", "html_writer", "::", "end_tag", "(", "'a'", ")", ";", "$", "action", ".=", "\\", "html_writer", "::", "end_tag", "(", "'li'", ")", ";", "echo", "$", "action", ";", "}", "echo", "\\", "html_writer", "::", "end_tag", "(", "'ul'", ")", ";", "echo", "\\", "html_writer", "::", "end_tag", "(", "'div'", ")", ";", "// JS for Tour management.", "$", "PAGE", "->", "requires", "->", "js_call_amd", "(", "'tool_usertours/managetours'", ",", "'setup'", ")", ";", "$", "this", "->", "footer", "(", ")", ";", "}" ]
Print the the list of tours.
[ "Print", "the", "the", "list", "of", "tours", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L234-L291
212,067
moodle/moodle
admin/tool/usertours/classes/manager.php
manager.get_edit_tour_link
protected function get_edit_tour_link($id = null) { $addlink = helper::get_edit_tour_link($id); return \html_writer::link($addlink, get_string('newtour', 'tool_usertours')); }
php
protected function get_edit_tour_link($id = null) { $addlink = helper::get_edit_tour_link($id); return \html_writer::link($addlink, get_string('newtour', 'tool_usertours')); }
[ "protected", "function", "get_edit_tour_link", "(", "$", "id", "=", "null", ")", "{", "$", "addlink", "=", "helper", "::", "get_edit_tour_link", "(", "$", "id", ")", ";", "return", "\\", "html_writer", "::", "link", "(", "$", "addlink", ",", "get_string", "(", "'newtour'", ",", "'tool_usertours'", ")", ")", ";", "}" ]
Return the edit tour link. @param int $id The ID of the tour @return string
[ "Return", "the", "edit", "tour", "link", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L299-L302
212,068
moodle/moodle
admin/tool/usertours/classes/manager.php
manager.edit_tour
protected function edit_tour($id = null) { global $PAGE; if ($id) { $tour = tour::instance($id); $PAGE->navbar->add($tour->get_name(), $tour->get_edit_link()); } else { $tour = new tour(); $PAGE->navbar->add(get_string('newtour', 'tool_usertours'), $tour->get_edit_link()); } $form = new forms\edittour($tour); if ($form->is_cancelled()) { redirect(helper::get_list_tour_link()); } else if ($data = $form->get_data()) { // Creating a new tour. $tour->set_name($data->name); $tour->set_description($data->description); $tour->set_pathmatch($data->pathmatch); $tour->set_enabled(!empty($data->enabled)); foreach (configuration::get_defaultable_keys() as $key) { $tour->set_config($key, $data->$key); } // Save filter values. foreach (helper::get_all_filters() as $filterclass) { $filterclass::save_filter_values_from_form($tour, $data); } $tour->persist(); redirect(helper::get_list_tour_link()); } else { if (empty($tour)) { $this->header('newtour'); } else { if (!empty($tour->get_config(self::CONFIG_SHIPPED_TOUR))) { notification::add(get_string('modifyshippedtourwarning', 'tool_usertours'), notification::WARNING); } $this->header($tour->get_name()); $data = $tour->prepare_data_for_form(); // Prepare filter values for the form. foreach (helper::get_all_filters() as $filterclass) { $filterclass::prepare_filter_values_for_form($tour, $data); } $form->set_data($data); } $form->display(); $this->footer(); } }
php
protected function edit_tour($id = null) { global $PAGE; if ($id) { $tour = tour::instance($id); $PAGE->navbar->add($tour->get_name(), $tour->get_edit_link()); } else { $tour = new tour(); $PAGE->navbar->add(get_string('newtour', 'tool_usertours'), $tour->get_edit_link()); } $form = new forms\edittour($tour); if ($form->is_cancelled()) { redirect(helper::get_list_tour_link()); } else if ($data = $form->get_data()) { // Creating a new tour. $tour->set_name($data->name); $tour->set_description($data->description); $tour->set_pathmatch($data->pathmatch); $tour->set_enabled(!empty($data->enabled)); foreach (configuration::get_defaultable_keys() as $key) { $tour->set_config($key, $data->$key); } // Save filter values. foreach (helper::get_all_filters() as $filterclass) { $filterclass::save_filter_values_from_form($tour, $data); } $tour->persist(); redirect(helper::get_list_tour_link()); } else { if (empty($tour)) { $this->header('newtour'); } else { if (!empty($tour->get_config(self::CONFIG_SHIPPED_TOUR))) { notification::add(get_string('modifyshippedtourwarning', 'tool_usertours'), notification::WARNING); } $this->header($tour->get_name()); $data = $tour->prepare_data_for_form(); // Prepare filter values for the form. foreach (helper::get_all_filters() as $filterclass) { $filterclass::prepare_filter_values_for_form($tour, $data); } $form->set_data($data); } $form->display(); $this->footer(); } }
[ "protected", "function", "edit_tour", "(", "$", "id", "=", "null", ")", "{", "global", "$", "PAGE", ";", "if", "(", "$", "id", ")", "{", "$", "tour", "=", "tour", "::", "instance", "(", "$", "id", ")", ";", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "tour", "->", "get_name", "(", ")", ",", "$", "tour", "->", "get_edit_link", "(", ")", ")", ";", "}", "else", "{", "$", "tour", "=", "new", "tour", "(", ")", ";", "$", "PAGE", "->", "navbar", "->", "add", "(", "get_string", "(", "'newtour'", ",", "'tool_usertours'", ")", ",", "$", "tour", "->", "get_edit_link", "(", ")", ")", ";", "}", "$", "form", "=", "new", "forms", "\\", "edittour", "(", "$", "tour", ")", ";", "if", "(", "$", "form", "->", "is_cancelled", "(", ")", ")", "{", "redirect", "(", "helper", "::", "get_list_tour_link", "(", ")", ")", ";", "}", "else", "if", "(", "$", "data", "=", "$", "form", "->", "get_data", "(", ")", ")", "{", "// Creating a new tour.", "$", "tour", "->", "set_name", "(", "$", "data", "->", "name", ")", ";", "$", "tour", "->", "set_description", "(", "$", "data", "->", "description", ")", ";", "$", "tour", "->", "set_pathmatch", "(", "$", "data", "->", "pathmatch", ")", ";", "$", "tour", "->", "set_enabled", "(", "!", "empty", "(", "$", "data", "->", "enabled", ")", ")", ";", "foreach", "(", "configuration", "::", "get_defaultable_keys", "(", ")", "as", "$", "key", ")", "{", "$", "tour", "->", "set_config", "(", "$", "key", ",", "$", "data", "->", "$", "key", ")", ";", "}", "// Save filter values.", "foreach", "(", "helper", "::", "get_all_filters", "(", ")", "as", "$", "filterclass", ")", "{", "$", "filterclass", "::", "save_filter_values_from_form", "(", "$", "tour", ",", "$", "data", ")", ";", "}", "$", "tour", "->", "persist", "(", ")", ";", "redirect", "(", "helper", "::", "get_list_tour_link", "(", ")", ")", ";", "}", "else", "{", "if", "(", "empty", "(", "$", "tour", ")", ")", "{", "$", "this", "->", "header", "(", "'newtour'", ")", ";", "}", "else", "{", "if", "(", "!", "empty", "(", "$", "tour", "->", "get_config", "(", "self", "::", "CONFIG_SHIPPED_TOUR", ")", ")", ")", "{", "notification", "::", "add", "(", "get_string", "(", "'modifyshippedtourwarning'", ",", "'tool_usertours'", ")", ",", "notification", "::", "WARNING", ")", ";", "}", "$", "this", "->", "header", "(", "$", "tour", "->", "get_name", "(", ")", ")", ";", "$", "data", "=", "$", "tour", "->", "prepare_data_for_form", "(", ")", ";", "// Prepare filter values for the form.", "foreach", "(", "helper", "::", "get_all_filters", "(", ")", "as", "$", "filterclass", ")", "{", "$", "filterclass", "::", "prepare_filter_values_for_form", "(", "$", "tour", ",", "$", "data", ")", ";", "}", "$", "form", "->", "set_data", "(", "$", "data", ")", ";", "}", "$", "form", "->", "display", "(", ")", ";", "$", "this", "->", "footer", "(", ")", ";", "}", "}" ]
Print the edit tour page. @param int $id The ID of the tour
[ "Print", "the", "edit", "tour", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L328-L383
212,069
moodle/moodle
admin/tool/usertours/classes/manager.php
manager.export_tour
protected function export_tour($id) { $tour = tour::instance($id); // Grab the full data record. $export = $tour->to_record(); // Remove the id. unset($export->id); // Set the version. $export->version = get_config('tool_usertours', 'version'); // Step export. $export->steps = []; foreach ($tour->get_steps() as $step) { $record = $step->to_record(); unset($record->id); unset($record->tourid); $export->steps[] = $record; } $exportstring = json_encode($export); $filename = 'tour_export_' . $tour->get_id() . '_' . time() . '.json'; // Force download. header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT'); header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0'); header('Expires: ' . gmdate('D, d M Y H:i:s', 0) . 'GMT'); header('Pragma: no-cache'); header('Accept-Ranges: none'); header('Content-disposition: attachment; filename=' . $filename); header('Content-length: ' . strlen($exportstring)); header('Content-type: text/calendar; charset=utf-8'); echo $exportstring; die; }
php
protected function export_tour($id) { $tour = tour::instance($id); // Grab the full data record. $export = $tour->to_record(); // Remove the id. unset($export->id); // Set the version. $export->version = get_config('tool_usertours', 'version'); // Step export. $export->steps = []; foreach ($tour->get_steps() as $step) { $record = $step->to_record(); unset($record->id); unset($record->tourid); $export->steps[] = $record; } $exportstring = json_encode($export); $filename = 'tour_export_' . $tour->get_id() . '_' . time() . '.json'; // Force download. header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT'); header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0'); header('Expires: ' . gmdate('D, d M Y H:i:s', 0) . 'GMT'); header('Pragma: no-cache'); header('Accept-Ranges: none'); header('Content-disposition: attachment; filename=' . $filename); header('Content-length: ' . strlen($exportstring)); header('Content-type: text/calendar; charset=utf-8'); echo $exportstring; die; }
[ "protected", "function", "export_tour", "(", "$", "id", ")", "{", "$", "tour", "=", "tour", "::", "instance", "(", "$", "id", ")", ";", "// Grab the full data record.", "$", "export", "=", "$", "tour", "->", "to_record", "(", ")", ";", "// Remove the id.", "unset", "(", "$", "export", "->", "id", ")", ";", "// Set the version.", "$", "export", "->", "version", "=", "get_config", "(", "'tool_usertours'", ",", "'version'", ")", ";", "// Step export.", "$", "export", "->", "steps", "=", "[", "]", ";", "foreach", "(", "$", "tour", "->", "get_steps", "(", ")", "as", "$", "step", ")", "{", "$", "record", "=", "$", "step", "->", "to_record", "(", ")", ";", "unset", "(", "$", "record", "->", "id", ")", ";", "unset", "(", "$", "record", "->", "tourid", ")", ";", "$", "export", "->", "steps", "[", "]", "=", "$", "record", ";", "}", "$", "exportstring", "=", "json_encode", "(", "$", "export", ")", ";", "$", "filename", "=", "'tour_export_'", ".", "$", "tour", "->", "get_id", "(", ")", ".", "'_'", ".", "time", "(", ")", ".", "'.json'", ";", "// Force download.", "header", "(", "'Last-Modified: '", ".", "gmdate", "(", "'D, d M Y H:i:s'", ",", "time", "(", ")", ")", ".", "' GMT'", ")", ";", "header", "(", "'Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0'", ")", ";", "header", "(", "'Expires: '", ".", "gmdate", "(", "'D, d M Y H:i:s'", ",", "0", ")", ".", "'GMT'", ")", ";", "header", "(", "'Pragma: no-cache'", ")", ";", "header", "(", "'Accept-Ranges: none'", ")", ";", "header", "(", "'Content-disposition: attachment; filename='", ".", "$", "filename", ")", ";", "header", "(", "'Content-length: '", ".", "strlen", "(", "$", "exportstring", ")", ")", ";", "header", "(", "'Content-type: text/calendar; charset=utf-8'", ")", ";", "echo", "$", "exportstring", ";", "die", ";", "}" ]
Print the export tour page. @param int $id The ID of the tour
[ "Print", "the", "export", "tour", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L390-L428
212,070
moodle/moodle
admin/tool/usertours/classes/manager.php
manager.import_tour
protected function import_tour() { global $PAGE; $PAGE->navbar->add(get_string('importtour', 'tool_usertours'), helper::get_import_tour_link()); $form = new forms\importtour(); if ($form->is_cancelled()) { redirect(helper::get_list_tour_link()); } else if ($form->get_data()) { // Importing a tour. $tourconfigraw = $form->get_file_content('tourconfig'); $tour = self::import_tour_from_json($tourconfigraw); redirect($tour->get_view_link()); } else { $this->header(); $form->display(); $this->footer(); } }
php
protected function import_tour() { global $PAGE; $PAGE->navbar->add(get_string('importtour', 'tool_usertours'), helper::get_import_tour_link()); $form = new forms\importtour(); if ($form->is_cancelled()) { redirect(helper::get_list_tour_link()); } else if ($form->get_data()) { // Importing a tour. $tourconfigraw = $form->get_file_content('tourconfig'); $tour = self::import_tour_from_json($tourconfigraw); redirect($tour->get_view_link()); } else { $this->header(); $form->display(); $this->footer(); } }
[ "protected", "function", "import_tour", "(", ")", "{", "global", "$", "PAGE", ";", "$", "PAGE", "->", "navbar", "->", "add", "(", "get_string", "(", "'importtour'", ",", "'tool_usertours'", ")", ",", "helper", "::", "get_import_tour_link", "(", ")", ")", ";", "$", "form", "=", "new", "forms", "\\", "importtour", "(", ")", ";", "if", "(", "$", "form", "->", "is_cancelled", "(", ")", ")", "{", "redirect", "(", "helper", "::", "get_list_tour_link", "(", ")", ")", ";", "}", "else", "if", "(", "$", "form", "->", "get_data", "(", ")", ")", "{", "// Importing a tour.", "$", "tourconfigraw", "=", "$", "form", "->", "get_file_content", "(", "'tourconfig'", ")", ";", "$", "tour", "=", "self", "::", "import_tour_from_json", "(", "$", "tourconfigraw", ")", ";", "redirect", "(", "$", "tour", "->", "get_view_link", "(", ")", ")", ";", "}", "else", "{", "$", "this", "->", "header", "(", ")", ";", "$", "form", "->", "display", "(", ")", ";", "$", "this", "->", "footer", "(", ")", ";", "}", "}" ]
Handle tour import.
[ "Handle", "tour", "import", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L433-L452
212,071
moodle/moodle
admin/tool/usertours/classes/manager.php
manager.view_tour
protected function view_tour($tourid) { global $PAGE; $tour = helper::get_tour($tourid); $PAGE->navbar->add($tour->get_name(), $tour->get_view_link()); $this->header($tour->get_name()); echo \html_writer::span(get_string('viewtour_info', 'tool_usertours', [ 'tourname' => $tour->get_name(), 'path' => $tour->get_pathmatch(), ])); echo \html_writer::div(get_string('viewtour_edit', 'tool_usertours', [ 'editlink' => $tour->get_edit_link()->out(), 'resetlink' => $tour->get_reset_link()->out(), ])); $table = new table\step_list($tourid); foreach ($tour->get_steps() as $step) { $table->add_data_keyed($table->format_row($step)); } $table->finish_output(); $this->print_edit_step_link($tourid); // JS for Step management. $PAGE->requires->js_call_amd('tool_usertours/managesteps', 'setup'); $this->footer(); }
php
protected function view_tour($tourid) { global $PAGE; $tour = helper::get_tour($tourid); $PAGE->navbar->add($tour->get_name(), $tour->get_view_link()); $this->header($tour->get_name()); echo \html_writer::span(get_string('viewtour_info', 'tool_usertours', [ 'tourname' => $tour->get_name(), 'path' => $tour->get_pathmatch(), ])); echo \html_writer::div(get_string('viewtour_edit', 'tool_usertours', [ 'editlink' => $tour->get_edit_link()->out(), 'resetlink' => $tour->get_reset_link()->out(), ])); $table = new table\step_list($tourid); foreach ($tour->get_steps() as $step) { $table->add_data_keyed($table->format_row($step)); } $table->finish_output(); $this->print_edit_step_link($tourid); // JS for Step management. $PAGE->requires->js_call_amd('tool_usertours/managesteps', 'setup'); $this->footer(); }
[ "protected", "function", "view_tour", "(", "$", "tourid", ")", "{", "global", "$", "PAGE", ";", "$", "tour", "=", "helper", "::", "get_tour", "(", "$", "tourid", ")", ";", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "tour", "->", "get_name", "(", ")", ",", "$", "tour", "->", "get_view_link", "(", ")", ")", ";", "$", "this", "->", "header", "(", "$", "tour", "->", "get_name", "(", ")", ")", ";", "echo", "\\", "html_writer", "::", "span", "(", "get_string", "(", "'viewtour_info'", ",", "'tool_usertours'", ",", "[", "'tourname'", "=>", "$", "tour", "->", "get_name", "(", ")", ",", "'path'", "=>", "$", "tour", "->", "get_pathmatch", "(", ")", ",", "]", ")", ")", ";", "echo", "\\", "html_writer", "::", "div", "(", "get_string", "(", "'viewtour_edit'", ",", "'tool_usertours'", ",", "[", "'editlink'", "=>", "$", "tour", "->", "get_edit_link", "(", ")", "->", "out", "(", ")", ",", "'resetlink'", "=>", "$", "tour", "->", "get_reset_link", "(", ")", "->", "out", "(", ")", ",", "]", ")", ")", ";", "$", "table", "=", "new", "table", "\\", "step_list", "(", "$", "tourid", ")", ";", "foreach", "(", "$", "tour", "->", "get_steps", "(", ")", "as", "$", "step", ")", "{", "$", "table", "->", "add_data_keyed", "(", "$", "table", "->", "format_row", "(", "$", "step", ")", ")", ";", "}", "$", "table", "->", "finish_output", "(", ")", ";", "$", "this", "->", "print_edit_step_link", "(", "$", "tourid", ")", ";", "// JS for Step management.", "$", "PAGE", "->", "requires", "->", "js_call_amd", "(", "'tool_usertours/managesteps'", ",", "'setup'", ")", ";", "$", "this", "->", "footer", "(", ")", ";", "}" ]
Print the view tour page. @param int $tourid The ID of the tour to display.
[ "Print", "the", "view", "tour", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L459-L487
212,072
moodle/moodle
admin/tool/usertours/classes/manager.php
manager.show_hide_tour
protected function show_hide_tour($tourid, $visibility) { global $DB; require_sesskey(); $tour = $DB->get_record('tool_usertours_tours', array('id' => $tourid)); $tour->enabled = $visibility; $DB->update_record('tool_usertours_tours', $tour); redirect(helper::get_list_tour_link()); }
php
protected function show_hide_tour($tourid, $visibility) { global $DB; require_sesskey(); $tour = $DB->get_record('tool_usertours_tours', array('id' => $tourid)); $tour->enabled = $visibility; $DB->update_record('tool_usertours_tours', $tour); redirect(helper::get_list_tour_link()); }
[ "protected", "function", "show_hide_tour", "(", "$", "tourid", ",", "$", "visibility", ")", "{", "global", "$", "DB", ";", "require_sesskey", "(", ")", ";", "$", "tour", "=", "$", "DB", "->", "get_record", "(", "'tool_usertours_tours'", ",", "array", "(", "'id'", "=>", "$", "tourid", ")", ")", ";", "$", "tour", "->", "enabled", "=", "$", "visibility", ";", "$", "DB", "->", "update_record", "(", "'tool_usertours_tours'", ",", "$", "tour", ")", ";", "redirect", "(", "helper", "::", "get_list_tour_link", "(", ")", ")", ";", "}" ]
Show or Hide the tour. @param int $tourid The ID of the tour to display. @param int $visibility The intended visibility.
[ "Show", "or", "Hide", "the", "tour", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L513-L523
212,073
moodle/moodle
admin/tool/usertours/classes/manager.php
manager.delete_tour
protected function delete_tour($tourid) { require_sesskey(); $tour = tour::instance($tourid); $tour->remove(); redirect(helper::get_list_tour_link()); }
php
protected function delete_tour($tourid) { require_sesskey(); $tour = tour::instance($tourid); $tour->remove(); redirect(helper::get_list_tour_link()); }
[ "protected", "function", "delete_tour", "(", "$", "tourid", ")", "{", "require_sesskey", "(", ")", ";", "$", "tour", "=", "tour", "::", "instance", "(", "$", "tourid", ")", ";", "$", "tour", "->", "remove", "(", ")", ";", "redirect", "(", "helper", "::", "get_list_tour_link", "(", ")", ")", ";", "}" ]
Delete the tour. @param int $tourid The ID of the tour to remove.
[ "Delete", "the", "tour", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L530-L537
212,074
moodle/moodle
admin/tool/usertours/classes/manager.php
manager.reset_tour_for_all
protected function reset_tour_for_all($tourid) { require_sesskey(); $tour = tour::instance($tourid); $tour->mark_major_change(); redirect(helper::get_view_tour_link($tourid), get_string('tour_resetforall', 'tool_usertours')); }
php
protected function reset_tour_for_all($tourid) { require_sesskey(); $tour = tour::instance($tourid); $tour->mark_major_change(); redirect(helper::get_view_tour_link($tourid), get_string('tour_resetforall', 'tool_usertours')); }
[ "protected", "function", "reset_tour_for_all", "(", "$", "tourid", ")", "{", "require_sesskey", "(", ")", ";", "$", "tour", "=", "tour", "::", "instance", "(", "$", "tourid", ")", ";", "$", "tour", "->", "mark_major_change", "(", ")", ";", "redirect", "(", "helper", "::", "get_view_tour_link", "(", "$", "tourid", ")", ",", "get_string", "(", "'tour_resetforall'", ",", "'tool_usertours'", ")", ")", ";", "}" ]
Reset the tour state for all users. @param int $tourid The ID of the tour to remove.
[ "Reset", "the", "tour", "state", "for", "all", "users", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L544-L551
212,075
moodle/moodle
admin/tool/usertours/classes/manager.php
manager.get_current_tour
public static function get_current_tour($reset = false) { global $PAGE; static $tour = false; if ($tour === false || $reset) { $tour = self::get_matching_tours($PAGE->url); } return $tour; }
php
public static function get_current_tour($reset = false) { global $PAGE; static $tour = false; if ($tour === false || $reset) { $tour = self::get_matching_tours($PAGE->url); } return $tour; }
[ "public", "static", "function", "get_current_tour", "(", "$", "reset", "=", "false", ")", "{", "global", "$", "PAGE", ";", "static", "$", "tour", "=", "false", ";", "if", "(", "$", "tour", "===", "false", "||", "$", "reset", ")", "{", "$", "tour", "=", "self", "::", "get_matching_tours", "(", "$", "PAGE", "->", "url", ")", ";", "}", "return", "$", "tour", ";", "}" ]
Get the first tour matching the current page URL. @param bool $reset Forcibly update the current tour @return tour
[ "Get", "the", "first", "tour", "matching", "the", "current", "page", "URL", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L559-L569
212,076
moodle/moodle
admin/tool/usertours/classes/manager.php
manager.get_matching_tours
public static function get_matching_tours(\moodle_url $pageurl) { global $PAGE; $tours = cache::get_matching_tourdata($pageurl); foreach ($tours as $record) { $tour = tour::load_from_record($record); if ($tour->is_enabled() && $tour->matches_all_filters($PAGE->context)) { return $tour; } } return null; }
php
public static function get_matching_tours(\moodle_url $pageurl) { global $PAGE; $tours = cache::get_matching_tourdata($pageurl); foreach ($tours as $record) { $tour = tour::load_from_record($record); if ($tour->is_enabled() && $tour->matches_all_filters($PAGE->context)) { return $tour; } } return null; }
[ "public", "static", "function", "get_matching_tours", "(", "\\", "moodle_url", "$", "pageurl", ")", "{", "global", "$", "PAGE", ";", "$", "tours", "=", "cache", "::", "get_matching_tourdata", "(", "$", "pageurl", ")", ";", "foreach", "(", "$", "tours", "as", "$", "record", ")", "{", "$", "tour", "=", "tour", "::", "load_from_record", "(", "$", "record", ")", ";", "if", "(", "$", "tour", "->", "is_enabled", "(", ")", "&&", "$", "tour", "->", "matches_all_filters", "(", "$", "PAGE", "->", "context", ")", ")", "{", "return", "$", "tour", ";", "}", "}", "return", "null", ";", "}" ]
Get the first tour matching the specified URL. @param moodle_url $pageurl The URL to match. @return tour
[ "Get", "the", "first", "tour", "matching", "the", "specified", "URL", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L577-L590
212,077
moodle/moodle
admin/tool/usertours/classes/manager.php
manager.import_tour_from_json
public static function import_tour_from_json($json) { $tourconfig = json_decode($json); // We do not use this yet - we may do in the future. unset($tourconfig->version); $steps = $tourconfig->steps; unset($tourconfig->steps); $tourconfig->id = null; $tourconfig->sortorder = null; $tour = tour::load_from_record($tourconfig, true); $tour->persist(true); // Ensure that steps are orderered by their sortorder. \core_collator::asort_objects_by_property($steps, 'sortorder', \core_collator::SORT_NUMERIC); foreach ($steps as $stepconfig) { $stepconfig->id = null; $stepconfig->tourid = $tour->get_id(); $step = step::load_from_record($stepconfig, true); $step->persist(true); } return $tour; }
php
public static function import_tour_from_json($json) { $tourconfig = json_decode($json); // We do not use this yet - we may do in the future. unset($tourconfig->version); $steps = $tourconfig->steps; unset($tourconfig->steps); $tourconfig->id = null; $tourconfig->sortorder = null; $tour = tour::load_from_record($tourconfig, true); $tour->persist(true); // Ensure that steps are orderered by their sortorder. \core_collator::asort_objects_by_property($steps, 'sortorder', \core_collator::SORT_NUMERIC); foreach ($steps as $stepconfig) { $stepconfig->id = null; $stepconfig->tourid = $tour->get_id(); $step = step::load_from_record($stepconfig, true); $step->persist(true); } return $tour; }
[ "public", "static", "function", "import_tour_from_json", "(", "$", "json", ")", "{", "$", "tourconfig", "=", "json_decode", "(", "$", "json", ")", ";", "// We do not use this yet - we may do in the future.", "unset", "(", "$", "tourconfig", "->", "version", ")", ";", "$", "steps", "=", "$", "tourconfig", "->", "steps", ";", "unset", "(", "$", "tourconfig", "->", "steps", ")", ";", "$", "tourconfig", "->", "id", "=", "null", ";", "$", "tourconfig", "->", "sortorder", "=", "null", ";", "$", "tour", "=", "tour", "::", "load_from_record", "(", "$", "tourconfig", ",", "true", ")", ";", "$", "tour", "->", "persist", "(", "true", ")", ";", "// Ensure that steps are orderered by their sortorder.", "\\", "core_collator", "::", "asort_objects_by_property", "(", "$", "steps", ",", "'sortorder'", ",", "\\", "core_collator", "::", "SORT_NUMERIC", ")", ";", "foreach", "(", "$", "steps", "as", "$", "stepconfig", ")", "{", "$", "stepconfig", "->", "id", "=", "null", ";", "$", "stepconfig", "->", "tourid", "=", "$", "tour", "->", "get_id", "(", ")", ";", "$", "step", "=", "step", "::", "load_from_record", "(", "$", "stepconfig", ",", "true", ")", ";", "$", "step", "->", "persist", "(", "true", ")", ";", "}", "return", "$", "tour", ";", "}" ]
Import the provided tour JSON. @param string $json The tour configuration. @return tour
[ "Import", "the", "provided", "tour", "JSON", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L598-L623
212,078
moodle/moodle
admin/tool/usertours/classes/manager.php
manager.print_edit_step_link
protected function print_edit_step_link($tourid, $stepid = null) { $addlink = helper::get_edit_step_link($tourid, $stepid); $attributes = []; if (empty($stepid)) { $attributes['class'] = 'createstep'; } echo \html_writer::link($addlink, get_string('newstep', 'tool_usertours'), $attributes); }
php
protected function print_edit_step_link($tourid, $stepid = null) { $addlink = helper::get_edit_step_link($tourid, $stepid); $attributes = []; if (empty($stepid)) { $attributes['class'] = 'createstep'; } echo \html_writer::link($addlink, get_string('newstep', 'tool_usertours'), $attributes); }
[ "protected", "function", "print_edit_step_link", "(", "$", "tourid", ",", "$", "stepid", "=", "null", ")", "{", "$", "addlink", "=", "helper", "::", "get_edit_step_link", "(", "$", "tourid", ",", "$", "stepid", ")", ";", "$", "attributes", "=", "[", "]", ";", "if", "(", "empty", "(", "$", "stepid", ")", ")", "{", "$", "attributes", "[", "'class'", "]", "=", "'createstep'", ";", "}", "echo", "\\", "html_writer", "::", "link", "(", "$", "addlink", ",", "get_string", "(", "'newstep'", ",", "'tool_usertours'", ")", ",", "$", "attributes", ")", ";", "}" ]
Print the edit step link. @param int $tourid The ID of the tour. @param int $stepid The ID of the step. @return string
[ "Print", "the", "edit", "step", "link", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L642-L649
212,079
moodle/moodle
admin/tool/usertours/classes/manager.php
manager.edit_step
protected function edit_step($id) { global $PAGE; if (isset($id)) { $step = step::instance($id); } else { $step = new step(); $step->set_tourid(required_param('tourid', PARAM_INT)); } $tour = $step->get_tour(); if (!empty($tour->get_config(self::CONFIG_SHIPPED_TOUR))) { notification::add(get_string('modifyshippedtourwarning', 'tool_usertours'), notification::WARNING); } $PAGE->navbar->add($tour->get_name(), $tour->get_view_link()); if (isset($id)) { $PAGE->navbar->add($step->get_title(), $step->get_edit_link()); } else { $PAGE->navbar->add(get_string('newstep', 'tool_usertours'), $step->get_edit_link()); } $form = new forms\editstep($step->get_edit_link(), $step); if ($form->is_cancelled()) { redirect($step->get_tour()->get_view_link()); } else if ($data = $form->get_data()) { $step->handle_form_submission($form, $data); $step->get_tour()->reset_step_sortorder(); redirect($step->get_tour()->get_view_link()); } else { if (empty($id)) { $this->header(get_string('newstep', 'tool_usertours')); } else { $this->header(get_string('editstep', 'tool_usertours', $step->get_title())); } $form->set_data($step->prepare_data_for_form()); $form->display(); $this->footer(); } }
php
protected function edit_step($id) { global $PAGE; if (isset($id)) { $step = step::instance($id); } else { $step = new step(); $step->set_tourid(required_param('tourid', PARAM_INT)); } $tour = $step->get_tour(); if (!empty($tour->get_config(self::CONFIG_SHIPPED_TOUR))) { notification::add(get_string('modifyshippedtourwarning', 'tool_usertours'), notification::WARNING); } $PAGE->navbar->add($tour->get_name(), $tour->get_view_link()); if (isset($id)) { $PAGE->navbar->add($step->get_title(), $step->get_edit_link()); } else { $PAGE->navbar->add(get_string('newstep', 'tool_usertours'), $step->get_edit_link()); } $form = new forms\editstep($step->get_edit_link(), $step); if ($form->is_cancelled()) { redirect($step->get_tour()->get_view_link()); } else if ($data = $form->get_data()) { $step->handle_form_submission($form, $data); $step->get_tour()->reset_step_sortorder(); redirect($step->get_tour()->get_view_link()); } else { if (empty($id)) { $this->header(get_string('newstep', 'tool_usertours')); } else { $this->header(get_string('editstep', 'tool_usertours', $step->get_title())); } $form->set_data($step->prepare_data_for_form()); $form->display(); $this->footer(); } }
[ "protected", "function", "edit_step", "(", "$", "id", ")", "{", "global", "$", "PAGE", ";", "if", "(", "isset", "(", "$", "id", ")", ")", "{", "$", "step", "=", "step", "::", "instance", "(", "$", "id", ")", ";", "}", "else", "{", "$", "step", "=", "new", "step", "(", ")", ";", "$", "step", "->", "set_tourid", "(", "required_param", "(", "'tourid'", ",", "PARAM_INT", ")", ")", ";", "}", "$", "tour", "=", "$", "step", "->", "get_tour", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "tour", "->", "get_config", "(", "self", "::", "CONFIG_SHIPPED_TOUR", ")", ")", ")", "{", "notification", "::", "add", "(", "get_string", "(", "'modifyshippedtourwarning'", ",", "'tool_usertours'", ")", ",", "notification", "::", "WARNING", ")", ";", "}", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "tour", "->", "get_name", "(", ")", ",", "$", "tour", "->", "get_view_link", "(", ")", ")", ";", "if", "(", "isset", "(", "$", "id", ")", ")", "{", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "step", "->", "get_title", "(", ")", ",", "$", "step", "->", "get_edit_link", "(", ")", ")", ";", "}", "else", "{", "$", "PAGE", "->", "navbar", "->", "add", "(", "get_string", "(", "'newstep'", ",", "'tool_usertours'", ")", ",", "$", "step", "->", "get_edit_link", "(", ")", ")", ";", "}", "$", "form", "=", "new", "forms", "\\", "editstep", "(", "$", "step", "->", "get_edit_link", "(", ")", ",", "$", "step", ")", ";", "if", "(", "$", "form", "->", "is_cancelled", "(", ")", ")", "{", "redirect", "(", "$", "step", "->", "get_tour", "(", ")", "->", "get_view_link", "(", ")", ")", ";", "}", "else", "if", "(", "$", "data", "=", "$", "form", "->", "get_data", "(", ")", ")", "{", "$", "step", "->", "handle_form_submission", "(", "$", "form", ",", "$", "data", ")", ";", "$", "step", "->", "get_tour", "(", ")", "->", "reset_step_sortorder", "(", ")", ";", "redirect", "(", "$", "step", "->", "get_tour", "(", ")", "->", "get_view_link", "(", ")", ")", ";", "}", "else", "{", "if", "(", "empty", "(", "$", "id", ")", ")", "{", "$", "this", "->", "header", "(", "get_string", "(", "'newstep'", ",", "'tool_usertours'", ")", ")", ";", "}", "else", "{", "$", "this", "->", "header", "(", "get_string", "(", "'editstep'", ",", "'tool_usertours'", ",", "$", "step", "->", "get_title", "(", ")", ")", ")", ";", "}", "$", "form", "->", "set_data", "(", "$", "step", "->", "prepare_data_for_form", "(", ")", ")", ";", "$", "form", "->", "display", "(", ")", ";", "$", "this", "->", "footer", "(", ")", ";", "}", "}" ]
Display the edit step form for the specified step. @param int $id The step to edit.
[ "Display", "the", "edit", "step", "form", "for", "the", "specified", "step", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L656-L697
212,080
moodle/moodle
admin/tool/usertours/classes/manager.php
manager.move_tour
protected function move_tour($id) { require_sesskey(); $direction = required_param('direction', PARAM_INT); $tour = tour::instance($id); self::_move_tour($tour, $direction); redirect(helper::get_list_tour_link()); }
php
protected function move_tour($id) { require_sesskey(); $direction = required_param('direction', PARAM_INT); $tour = tour::instance($id); self::_move_tour($tour, $direction); redirect(helper::get_list_tour_link()); }
[ "protected", "function", "move_tour", "(", "$", "id", ")", "{", "require_sesskey", "(", ")", ";", "$", "direction", "=", "required_param", "(", "'direction'", ",", "PARAM_INT", ")", ";", "$", "tour", "=", "tour", "::", "instance", "(", "$", "id", ")", ";", "self", "::", "_move_tour", "(", "$", "tour", ",", "$", "direction", ")", ";", "redirect", "(", "helper", "::", "get_list_tour_link", "(", ")", ")", ";", "}" ]
Move a tour up or down and redirect once complete. @param int $id The tour to move.
[ "Move", "a", "tour", "up", "or", "down", "and", "redirect", "once", "complete", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L704-L713
212,081
moodle/moodle
admin/tool/usertours/classes/manager.php
manager._move_tour
protected static function _move_tour(tour $tour, $direction) { $currentsortorder = $tour->get_sortorder(); $targetsortorder = $currentsortorder + $direction; $swapwith = helper::get_tour_from_sortorder($targetsortorder); // Set the sort order to something out of the way. $tour->set_sortorder(-1); $tour->persist(); // Swap the two sort orders. $swapwith->set_sortorder($currentsortorder); $swapwith->persist(); $tour->set_sortorder($targetsortorder); $tour->persist(); }
php
protected static function _move_tour(tour $tour, $direction) { $currentsortorder = $tour->get_sortorder(); $targetsortorder = $currentsortorder + $direction; $swapwith = helper::get_tour_from_sortorder($targetsortorder); // Set the sort order to something out of the way. $tour->set_sortorder(-1); $tour->persist(); // Swap the two sort orders. $swapwith->set_sortorder($currentsortorder); $swapwith->persist(); $tour->set_sortorder($targetsortorder); $tour->persist(); }
[ "protected", "static", "function", "_move_tour", "(", "tour", "$", "tour", ",", "$", "direction", ")", "{", "$", "currentsortorder", "=", "$", "tour", "->", "get_sortorder", "(", ")", ";", "$", "targetsortorder", "=", "$", "currentsortorder", "+", "$", "direction", ";", "$", "swapwith", "=", "helper", "::", "get_tour_from_sortorder", "(", "$", "targetsortorder", ")", ";", "// Set the sort order to something out of the way.", "$", "tour", "->", "set_sortorder", "(", "-", "1", ")", ";", "$", "tour", "->", "persist", "(", ")", ";", "// Swap the two sort orders.", "$", "swapwith", "->", "set_sortorder", "(", "$", "currentsortorder", ")", ";", "$", "swapwith", "->", "persist", "(", ")", ";", "$", "tour", "->", "set_sortorder", "(", "$", "targetsortorder", ")", ";", "$", "tour", "->", "persist", "(", ")", ";", "}" ]
Move a tour up or down. @param tour $tour The tour to move. @param int $direction
[ "Move", "a", "tour", "up", "or", "down", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L722-L738
212,082
moodle/moodle
admin/tool/usertours/classes/manager.php
manager.move_step
protected function move_step($id) { require_sesskey(); $direction = required_param('direction', PARAM_INT); $step = step::instance($id); $currentsortorder = $step->get_sortorder(); $targetsortorder = $currentsortorder + $direction; $tour = $step->get_tour(); $swapwith = helper::get_step_from_sortorder($tour->get_id(), $targetsortorder); // Set the sort order to something out of the way. $step->set_sortorder(-1); $step->persist(); // Swap the two sort orders. $swapwith->set_sortorder($currentsortorder); $swapwith->persist(); $step->set_sortorder($targetsortorder); $step->persist(); // Reset the sort order. $tour->reset_step_sortorder(); redirect($tour->get_view_link()); }
php
protected function move_step($id) { require_sesskey(); $direction = required_param('direction', PARAM_INT); $step = step::instance($id); $currentsortorder = $step->get_sortorder(); $targetsortorder = $currentsortorder + $direction; $tour = $step->get_tour(); $swapwith = helper::get_step_from_sortorder($tour->get_id(), $targetsortorder); // Set the sort order to something out of the way. $step->set_sortorder(-1); $step->persist(); // Swap the two sort orders. $swapwith->set_sortorder($currentsortorder); $swapwith->persist(); $step->set_sortorder($targetsortorder); $step->persist(); // Reset the sort order. $tour->reset_step_sortorder(); redirect($tour->get_view_link()); }
[ "protected", "function", "move_step", "(", "$", "id", ")", "{", "require_sesskey", "(", ")", ";", "$", "direction", "=", "required_param", "(", "'direction'", ",", "PARAM_INT", ")", ";", "$", "step", "=", "step", "::", "instance", "(", "$", "id", ")", ";", "$", "currentsortorder", "=", "$", "step", "->", "get_sortorder", "(", ")", ";", "$", "targetsortorder", "=", "$", "currentsortorder", "+", "$", "direction", ";", "$", "tour", "=", "$", "step", "->", "get_tour", "(", ")", ";", "$", "swapwith", "=", "helper", "::", "get_step_from_sortorder", "(", "$", "tour", "->", "get_id", "(", ")", ",", "$", "targetsortorder", ")", ";", "// Set the sort order to something out of the way.", "$", "step", "->", "set_sortorder", "(", "-", "1", ")", ";", "$", "step", "->", "persist", "(", ")", ";", "// Swap the two sort orders.", "$", "swapwith", "->", "set_sortorder", "(", "$", "currentsortorder", ")", ";", "$", "swapwith", "->", "persist", "(", ")", ";", "$", "step", "->", "set_sortorder", "(", "$", "targetsortorder", ")", ";", "$", "step", "->", "persist", "(", ")", ";", "// Reset the sort order.", "$", "tour", "->", "reset_step_sortorder", "(", ")", ";", "redirect", "(", "$", "tour", "->", "get_view_link", "(", ")", ")", ";", "}" ]
Move a step up or down. @param int $id The step to move.
[ "Move", "a", "step", "up", "or", "down", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L745-L771
212,083
moodle/moodle
admin/tool/usertours/classes/manager.php
manager.delete_step
protected function delete_step($stepid) { require_sesskey(); $step = step::instance($stepid); $tour = $step->get_tour(); $step->remove(); redirect($tour->get_view_link()); }
php
protected function delete_step($stepid) { require_sesskey(); $step = step::instance($stepid); $tour = $step->get_tour(); $step->remove(); redirect($tour->get_view_link()); }
[ "protected", "function", "delete_step", "(", "$", "stepid", ")", "{", "require_sesskey", "(", ")", ";", "$", "step", "=", "step", "::", "instance", "(", "$", "stepid", ")", ";", "$", "tour", "=", "$", "step", "->", "get_tour", "(", ")", ";", "$", "step", "->", "remove", "(", ")", ";", "redirect", "(", "$", "tour", "->", "get_view_link", "(", ")", ")", ";", "}" ]
Delete the step. @param int $stepid The ID of the step to remove.
[ "Delete", "the", "step", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L778-L786
212,084
moodle/moodle
admin/tool/usertours/classes/manager.php
manager.update_shipped_tours
public static function update_shipped_tours() { global $DB, $CFG; // A list of tours that are shipped with Moodle. They are in // the format filename => version. The version value needs to // be increased if the tour has been updated. $shippedtours = [ '36_dashboard.json' => 3 ]; // These are tours that we used to ship but don't ship any longer. // We do not remove them, but we do disable them. $unshippedtours = [ 'boost_administrator.json' => 1, 'boost_course_view.json' => 1, ]; if ($CFG->messaging) { $shippedtours['36_messaging.json'] = 3; } else { $unshippedtours['36_messaging.json'] = 3; } $existingtourrecords = $DB->get_recordset('tool_usertours_tours'); // Get all of the existing shipped tours and check if they need to be // updated. foreach ($existingtourrecords as $tourrecord) { $tour = tour::load_from_record($tourrecord); if (!empty($tour->get_config(self::CONFIG_SHIPPED_TOUR))) { $filename = $tour->get_config(self::CONFIG_SHIPPED_FILENAME); $version = $tour->get_config(self::CONFIG_SHIPPED_VERSION); // If we know about this tour (otherwise leave it as is). if (isset($shippedtours[$filename])) { // And the version in the DB is an older version. if ($version < $shippedtours[$filename]) { // Remove the old version because it's been updated // and needs to be recreated. $tour->remove(); } else { // The tour has not been updated so we don't need to // do anything with it. unset($shippedtours[$filename]); } } if (isset($unshippedtours[$filename])) { if ($version <= $unshippedtours[$filename]) { $tour = tour::instance($tour->get_id()); $tour->set_enabled(tour::DISABLED); $tour->persist(); } } } } $existingtourrecords->close(); foreach (array_reverse($shippedtours) as $filename => $version) { $filepath = $CFG->dirroot . "/{$CFG->admin}/tool/usertours/tours/" . $filename; $tourjson = file_get_contents($filepath); $tour = self::import_tour_from_json($tourjson); // Set some additional config data to record that this tour was // added as a shipped tour. $tour->set_config(self::CONFIG_SHIPPED_TOUR, true); $tour->set_config(self::CONFIG_SHIPPED_FILENAME, $filename); $tour->set_config(self::CONFIG_SHIPPED_VERSION, $version); // Bump new tours to the top of the list. while ($tour->get_sortorder() > 0) { self::_move_tour($tour, helper::MOVE_UP); } if (defined('BEHAT_SITE_RUNNING') || (defined('PHPUNIT_TEST') && PHPUNIT_TEST)) { // Disable this tour if this is behat or phpunit. $tour->set_enabled(false); } $tour->persist(); } }
php
public static function update_shipped_tours() { global $DB, $CFG; // A list of tours that are shipped with Moodle. They are in // the format filename => version. The version value needs to // be increased if the tour has been updated. $shippedtours = [ '36_dashboard.json' => 3 ]; // These are tours that we used to ship but don't ship any longer. // We do not remove them, but we do disable them. $unshippedtours = [ 'boost_administrator.json' => 1, 'boost_course_view.json' => 1, ]; if ($CFG->messaging) { $shippedtours['36_messaging.json'] = 3; } else { $unshippedtours['36_messaging.json'] = 3; } $existingtourrecords = $DB->get_recordset('tool_usertours_tours'); // Get all of the existing shipped tours and check if they need to be // updated. foreach ($existingtourrecords as $tourrecord) { $tour = tour::load_from_record($tourrecord); if (!empty($tour->get_config(self::CONFIG_SHIPPED_TOUR))) { $filename = $tour->get_config(self::CONFIG_SHIPPED_FILENAME); $version = $tour->get_config(self::CONFIG_SHIPPED_VERSION); // If we know about this tour (otherwise leave it as is). if (isset($shippedtours[$filename])) { // And the version in the DB is an older version. if ($version < $shippedtours[$filename]) { // Remove the old version because it's been updated // and needs to be recreated. $tour->remove(); } else { // The tour has not been updated so we don't need to // do anything with it. unset($shippedtours[$filename]); } } if (isset($unshippedtours[$filename])) { if ($version <= $unshippedtours[$filename]) { $tour = tour::instance($tour->get_id()); $tour->set_enabled(tour::DISABLED); $tour->persist(); } } } } $existingtourrecords->close(); foreach (array_reverse($shippedtours) as $filename => $version) { $filepath = $CFG->dirroot . "/{$CFG->admin}/tool/usertours/tours/" . $filename; $tourjson = file_get_contents($filepath); $tour = self::import_tour_from_json($tourjson); // Set some additional config data to record that this tour was // added as a shipped tour. $tour->set_config(self::CONFIG_SHIPPED_TOUR, true); $tour->set_config(self::CONFIG_SHIPPED_FILENAME, $filename); $tour->set_config(self::CONFIG_SHIPPED_VERSION, $version); // Bump new tours to the top of the list. while ($tour->get_sortorder() > 0) { self::_move_tour($tour, helper::MOVE_UP); } if (defined('BEHAT_SITE_RUNNING') || (defined('PHPUNIT_TEST') && PHPUNIT_TEST)) { // Disable this tour if this is behat or phpunit. $tour->set_enabled(false); } $tour->persist(); } }
[ "public", "static", "function", "update_shipped_tours", "(", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "// A list of tours that are shipped with Moodle. They are in", "// the format filename => version. The version value needs to", "// be increased if the tour has been updated.", "$", "shippedtours", "=", "[", "'36_dashboard.json'", "=>", "3", "]", ";", "// These are tours that we used to ship but don't ship any longer.", "// We do not remove them, but we do disable them.", "$", "unshippedtours", "=", "[", "'boost_administrator.json'", "=>", "1", ",", "'boost_course_view.json'", "=>", "1", ",", "]", ";", "if", "(", "$", "CFG", "->", "messaging", ")", "{", "$", "shippedtours", "[", "'36_messaging.json'", "]", "=", "3", ";", "}", "else", "{", "$", "unshippedtours", "[", "'36_messaging.json'", "]", "=", "3", ";", "}", "$", "existingtourrecords", "=", "$", "DB", "->", "get_recordset", "(", "'tool_usertours_tours'", ")", ";", "// Get all of the existing shipped tours and check if they need to be", "// updated.", "foreach", "(", "$", "existingtourrecords", "as", "$", "tourrecord", ")", "{", "$", "tour", "=", "tour", "::", "load_from_record", "(", "$", "tourrecord", ")", ";", "if", "(", "!", "empty", "(", "$", "tour", "->", "get_config", "(", "self", "::", "CONFIG_SHIPPED_TOUR", ")", ")", ")", "{", "$", "filename", "=", "$", "tour", "->", "get_config", "(", "self", "::", "CONFIG_SHIPPED_FILENAME", ")", ";", "$", "version", "=", "$", "tour", "->", "get_config", "(", "self", "::", "CONFIG_SHIPPED_VERSION", ")", ";", "// If we know about this tour (otherwise leave it as is).", "if", "(", "isset", "(", "$", "shippedtours", "[", "$", "filename", "]", ")", ")", "{", "// And the version in the DB is an older version.", "if", "(", "$", "version", "<", "$", "shippedtours", "[", "$", "filename", "]", ")", "{", "// Remove the old version because it's been updated", "// and needs to be recreated.", "$", "tour", "->", "remove", "(", ")", ";", "}", "else", "{", "// The tour has not been updated so we don't need to", "// do anything with it.", "unset", "(", "$", "shippedtours", "[", "$", "filename", "]", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "unshippedtours", "[", "$", "filename", "]", ")", ")", "{", "if", "(", "$", "version", "<=", "$", "unshippedtours", "[", "$", "filename", "]", ")", "{", "$", "tour", "=", "tour", "::", "instance", "(", "$", "tour", "->", "get_id", "(", ")", ")", ";", "$", "tour", "->", "set_enabled", "(", "tour", "::", "DISABLED", ")", ";", "$", "tour", "->", "persist", "(", ")", ";", "}", "}", "}", "}", "$", "existingtourrecords", "->", "close", "(", ")", ";", "foreach", "(", "array_reverse", "(", "$", "shippedtours", ")", "as", "$", "filename", "=>", "$", "version", ")", "{", "$", "filepath", "=", "$", "CFG", "->", "dirroot", ".", "\"/{$CFG->admin}/tool/usertours/tours/\"", ".", "$", "filename", ";", "$", "tourjson", "=", "file_get_contents", "(", "$", "filepath", ")", ";", "$", "tour", "=", "self", "::", "import_tour_from_json", "(", "$", "tourjson", ")", ";", "// Set some additional config data to record that this tour was", "// added as a shipped tour.", "$", "tour", "->", "set_config", "(", "self", "::", "CONFIG_SHIPPED_TOUR", ",", "true", ")", ";", "$", "tour", "->", "set_config", "(", "self", "::", "CONFIG_SHIPPED_FILENAME", ",", "$", "filename", ")", ";", "$", "tour", "->", "set_config", "(", "self", "::", "CONFIG_SHIPPED_VERSION", ",", "$", "version", ")", ";", "// Bump new tours to the top of the list.", "while", "(", "$", "tour", "->", "get_sortorder", "(", ")", ">", "0", ")", "{", "self", "::", "_move_tour", "(", "$", "tour", ",", "helper", "::", "MOVE_UP", ")", ";", "}", "if", "(", "defined", "(", "'BEHAT_SITE_RUNNING'", ")", "||", "(", "defined", "(", "'PHPUNIT_TEST'", ")", "&&", "PHPUNIT_TEST", ")", ")", "{", "// Disable this tour if this is behat or phpunit.", "$", "tour", "->", "set_enabled", "(", "false", ")", ";", "}", "$", "tour", "->", "persist", "(", ")", ";", "}", "}" ]
Make sure all of the default tours that are shipped with Moodle are created and up to date with the latest version.
[ "Make", "sure", "all", "of", "the", "default", "tours", "that", "are", "shipped", "with", "Moodle", "are", "created", "and", "up", "to", "date", "with", "the", "latest", "version", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/manager.php#L792-L874
212,085
moodle/moodle
customfield/field/date/classes/data_controller.php
data_controller.instance_form_definition
public function instance_form_definition(\MoodleQuickForm $mform) { $field = $this->get_field(); // Get the current calendar in use - see MDL-18375. $calendartype = \core_calendar\type_factory::get_calendar_instance(); $config = $field->get('configdata'); // Always set the form element to "optional", even when it's required. Otherwise it defaults to the // current date and is easy to miss. $attributes = ['optional' => true]; if (!empty($config['mindate'])) { $attributes['startyear'] = $calendartype->timestamp_to_date_array($config['mindate'])['year']; } if (!empty($config['maxdate'])) { $attributes['stopyear'] = $calendartype->timestamp_to_date_array($config['maxdate'])['year']; } if (empty($config['includetime'])) { $element = 'date_selector'; } else { $element = 'date_time_selector'; } $elementname = $this->get_form_element_name(); $mform->addElement($element, $elementname, $this->get_field()->get_formatted_name(), $attributes); $mform->setType($elementname, PARAM_INT); $mform->setDefault($elementname, time()); if ($field->get_configdata_property('required')) { $mform->addRule($elementname, null, 'required', null, 'client'); } }
php
public function instance_form_definition(\MoodleQuickForm $mform) { $field = $this->get_field(); // Get the current calendar in use - see MDL-18375. $calendartype = \core_calendar\type_factory::get_calendar_instance(); $config = $field->get('configdata'); // Always set the form element to "optional", even when it's required. Otherwise it defaults to the // current date and is easy to miss. $attributes = ['optional' => true]; if (!empty($config['mindate'])) { $attributes['startyear'] = $calendartype->timestamp_to_date_array($config['mindate'])['year']; } if (!empty($config['maxdate'])) { $attributes['stopyear'] = $calendartype->timestamp_to_date_array($config['maxdate'])['year']; } if (empty($config['includetime'])) { $element = 'date_selector'; } else { $element = 'date_time_selector'; } $elementname = $this->get_form_element_name(); $mform->addElement($element, $elementname, $this->get_field()->get_formatted_name(), $attributes); $mform->setType($elementname, PARAM_INT); $mform->setDefault($elementname, time()); if ($field->get_configdata_property('required')) { $mform->addRule($elementname, null, 'required', null, 'client'); } }
[ "public", "function", "instance_form_definition", "(", "\\", "MoodleQuickForm", "$", "mform", ")", "{", "$", "field", "=", "$", "this", "->", "get_field", "(", ")", ";", "// Get the current calendar in use - see MDL-18375.", "$", "calendartype", "=", "\\", "core_calendar", "\\", "type_factory", "::", "get_calendar_instance", "(", ")", ";", "$", "config", "=", "$", "field", "->", "get", "(", "'configdata'", ")", ";", "// Always set the form element to \"optional\", even when it's required. Otherwise it defaults to the", "// current date and is easy to miss.", "$", "attributes", "=", "[", "'optional'", "=>", "true", "]", ";", "if", "(", "!", "empty", "(", "$", "config", "[", "'mindate'", "]", ")", ")", "{", "$", "attributes", "[", "'startyear'", "]", "=", "$", "calendartype", "->", "timestamp_to_date_array", "(", "$", "config", "[", "'mindate'", "]", ")", "[", "'year'", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "config", "[", "'maxdate'", "]", ")", ")", "{", "$", "attributes", "[", "'stopyear'", "]", "=", "$", "calendartype", "->", "timestamp_to_date_array", "(", "$", "config", "[", "'maxdate'", "]", ")", "[", "'year'", "]", ";", "}", "if", "(", "empty", "(", "$", "config", "[", "'includetime'", "]", ")", ")", "{", "$", "element", "=", "'date_selector'", ";", "}", "else", "{", "$", "element", "=", "'date_time_selector'", ";", "}", "$", "elementname", "=", "$", "this", "->", "get_form_element_name", "(", ")", ";", "$", "mform", "->", "addElement", "(", "$", "element", ",", "$", "elementname", ",", "$", "this", "->", "get_field", "(", ")", "->", "get_formatted_name", "(", ")", ",", "$", "attributes", ")", ";", "$", "mform", "->", "setType", "(", "$", "elementname", ",", "PARAM_INT", ")", ";", "$", "mform", "->", "setDefault", "(", "$", "elementname", ",", "time", "(", ")", ")", ";", "if", "(", "$", "field", "->", "get_configdata_property", "(", "'required'", ")", ")", "{", "$", "mform", "->", "addRule", "(", "$", "elementname", ",", "null", ",", "'required'", ",", "null", ",", "'client'", ")", ";", "}", "}" ]
Add fields for editing data of a date field on a context. @param \MoodleQuickForm $mform
[ "Add", "fields", "for", "editing", "data", "of", "a", "date", "field", "on", "a", "context", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/field/date/classes/data_controller.php#L53-L84
212,086
moodle/moodle
lib/lexer.php
ParallelRegex.addPattern
function addPattern($pattern, $label = true) { $count = count($this->_patterns); $this->_patterns[$count] = $pattern; $this->_labels[$count] = $label; $this->_regex = null; }
php
function addPattern($pattern, $label = true) { $count = count($this->_patterns); $this->_patterns[$count] = $pattern; $this->_labels[$count] = $label; $this->_regex = null; }
[ "function", "addPattern", "(", "$", "pattern", ",", "$", "label", "=", "true", ")", "{", "$", "count", "=", "count", "(", "$", "this", "->", "_patterns", ")", ";", "$", "this", "->", "_patterns", "[", "$", "count", "]", "=", "$", "pattern", ";", "$", "this", "->", "_labels", "[", "$", "count", "]", "=", "$", "label", ";", "$", "this", "->", "_regex", "=", "null", ";", "}" ]
Adds a pattern with an optional label. @param string $pattern Perl style regex, but ( and ) lose the usual meaning. @param string $label Label of regex to be returned on a match. @access public
[ "Adds", "a", "pattern", "with", "an", "optional", "label", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lexer.php#L72-L77
212,087
moodle/moodle
lib/lexer.php
ParallelRegex.match
function match($subject, &$match) { if (count($this->_patterns) == 0) { return false; } if (!preg_match($this->_getCompoundedRegex(), $subject, $matches)) { $match = ""; return false; } $match = $matches[0]; for ($i = 1; $i < count($matches); $i++) { if ($matches[$i]) { return $this->_labels[$i - 1]; } } return true; }
php
function match($subject, &$match) { if (count($this->_patterns) == 0) { return false; } if (!preg_match($this->_getCompoundedRegex(), $subject, $matches)) { $match = ""; return false; } $match = $matches[0]; for ($i = 1; $i < count($matches); $i++) { if ($matches[$i]) { return $this->_labels[$i - 1]; } } return true; }
[ "function", "match", "(", "$", "subject", ",", "&", "$", "match", ")", "{", "if", "(", "count", "(", "$", "this", "->", "_patterns", ")", "==", "0", ")", "{", "return", "false", ";", "}", "if", "(", "!", "preg_match", "(", "$", "this", "->", "_getCompoundedRegex", "(", ")", ",", "$", "subject", ",", "$", "matches", ")", ")", "{", "$", "match", "=", "\"\"", ";", "return", "false", ";", "}", "$", "match", "=", "$", "matches", "[", "0", "]", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<", "count", "(", "$", "matches", ")", ";", "$", "i", "++", ")", "{", "if", "(", "$", "matches", "[", "$", "i", "]", ")", "{", "return", "$", "this", "->", "_labels", "[", "$", "i", "-", "1", "]", ";", "}", "}", "return", "true", ";", "}" ]
Attempts to match all patterns at once against a string. @param string $subject String to match against. @param string $match First matched portion of subject. @return bool True on success. @access public
[ "Attempts", "to", "match", "all", "patterns", "at", "once", "against", "a", "string", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lexer.php#L88-L103
212,088
moodle/moodle
lib/lexer.php
Lexer.addPattern
function addPattern($pattern, $mode = "accept") { if (!isset($this->_regexes[$mode])) { $this->_regexes[$mode] = new ParallelRegex($this->_case); } $this->_regexes[$mode]->addPattern($pattern); }
php
function addPattern($pattern, $mode = "accept") { if (!isset($this->_regexes[$mode])) { $this->_regexes[$mode] = new ParallelRegex($this->_case); } $this->_regexes[$mode]->addPattern($pattern); }
[ "function", "addPattern", "(", "$", "pattern", ",", "$", "mode", "=", "\"accept\"", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_regexes", "[", "$", "mode", "]", ")", ")", "{", "$", "this", "->", "_regexes", "[", "$", "mode", "]", "=", "new", "ParallelRegex", "(", "$", "this", "->", "_case", ")", ";", "}", "$", "this", "->", "_regexes", "[", "$", "mode", "]", "->", "addPattern", "(", "$", "pattern", ")", ";", "}" ]
Adds a token search pattern for a particular parsing mode. The pattern does not change the current mode. @param string $pattern Perl style regex, but ( and ) lose the usual meaning. @param string $mode Should only apply this pattern when dealing with this type of input. @access public
[ "Adds", "a", "token", "search", "pattern", "for", "a", "particular", "parsing", "mode", ".", "The", "pattern", "does", "not", "change", "the", "current", "mode", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lexer.php#L255-L260
212,089
moodle/moodle
lib/lexer.php
Lexer.parse
function parse($raw) { if (!isset($this->_parser)) { return false; } $length = strlen($raw); while (is_array($parsed = $this->_reduce($raw))) { list($unmatched, $matched, $mode) = $parsed; if (!$this->_dispatchTokens($unmatched, $matched, $mode)) { return false; } if (strlen($raw) == $length) { return false; } $length = strlen($raw); } if (!$parsed) { return false; } return $this->_invokeParser($raw, LEXER_UNMATCHED); }
php
function parse($raw) { if (!isset($this->_parser)) { return false; } $length = strlen($raw); while (is_array($parsed = $this->_reduce($raw))) { list($unmatched, $matched, $mode) = $parsed; if (!$this->_dispatchTokens($unmatched, $matched, $mode)) { return false; } if (strlen($raw) == $length) { return false; } $length = strlen($raw); } if (!$parsed) { return false; } return $this->_invokeParser($raw, LEXER_UNMATCHED); }
[ "function", "parse", "(", "$", "raw", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_parser", ")", ")", "{", "return", "false", ";", "}", "$", "length", "=", "strlen", "(", "$", "raw", ")", ";", "while", "(", "is_array", "(", "$", "parsed", "=", "$", "this", "->", "_reduce", "(", "$", "raw", ")", ")", ")", "{", "list", "(", "$", "unmatched", ",", "$", "matched", ",", "$", "mode", ")", "=", "$", "parsed", ";", "if", "(", "!", "$", "this", "->", "_dispatchTokens", "(", "$", "unmatched", ",", "$", "matched", ",", "$", "mode", ")", ")", "{", "return", "false", ";", "}", "if", "(", "strlen", "(", "$", "raw", ")", "==", "$", "length", ")", "{", "return", "false", ";", "}", "$", "length", "=", "strlen", "(", "$", "raw", ")", ";", "}", "if", "(", "!", "$", "parsed", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "_invokeParser", "(", "$", "raw", ",", "LEXER_UNMATCHED", ")", ";", "}" ]
Splits the page text into tokens. Will fail if the handlers report an error or if no content is consumed. If successful then each unparsed and parsed token invokes a call to the held listener. @param string $raw Raw HTML text. @return bool True on success, else false. @access public
[ "Splits", "the", "page", "text", "into", "tokens", ".", "Will", "fail", "if", "the", "handlers", "report", "an", "error", "or", "if", "no", "content", "is", "consumed", ".", "If", "successful", "then", "each", "unparsed", "and", "parsed", "token", "invokes", "a", "call", "to", "the", "held", "listener", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lexer.php#L335-L354
212,090
moodle/moodle
lib/lexer.php
Lexer._dispatchTokens
function _dispatchTokens($unmatched, $matched, $mode = false) { if (!$this->_invokeParser($unmatched, LEXER_UNMATCHED)) { return false; } if ($mode === "__exit") { if (!$this->_invokeParser($matched, LEXER_EXIT)) { return false; } return $this->_mode->leave(); } if (strncmp($mode, "_", 1) == 0) { $mode = substr($mode, 1); $this->_mode->enter($mode); if (!$this->_invokeParser($matched, LEXER_SPECIAL)) { return false; } return $this->_mode->leave(); } if (is_string($mode)) { $this->_mode->enter($mode); return $this->_invokeParser($matched, LEXER_ENTER); } return $this->_invokeParser($matched, LEXER_MATCHED); }
php
function _dispatchTokens($unmatched, $matched, $mode = false) { if (!$this->_invokeParser($unmatched, LEXER_UNMATCHED)) { return false; } if ($mode === "__exit") { if (!$this->_invokeParser($matched, LEXER_EXIT)) { return false; } return $this->_mode->leave(); } if (strncmp($mode, "_", 1) == 0) { $mode = substr($mode, 1); $this->_mode->enter($mode); if (!$this->_invokeParser($matched, LEXER_SPECIAL)) { return false; } return $this->_mode->leave(); } if (is_string($mode)) { $this->_mode->enter($mode); return $this->_invokeParser($matched, LEXER_ENTER); } return $this->_invokeParser($matched, LEXER_MATCHED); }
[ "function", "_dispatchTokens", "(", "$", "unmatched", ",", "$", "matched", ",", "$", "mode", "=", "false", ")", "{", "if", "(", "!", "$", "this", "->", "_invokeParser", "(", "$", "unmatched", ",", "LEXER_UNMATCHED", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "mode", "===", "\"__exit\"", ")", "{", "if", "(", "!", "$", "this", "->", "_invokeParser", "(", "$", "matched", ",", "LEXER_EXIT", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "_mode", "->", "leave", "(", ")", ";", "}", "if", "(", "strncmp", "(", "$", "mode", ",", "\"_\"", ",", "1", ")", "==", "0", ")", "{", "$", "mode", "=", "substr", "(", "$", "mode", ",", "1", ")", ";", "$", "this", "->", "_mode", "->", "enter", "(", "$", "mode", ")", ";", "if", "(", "!", "$", "this", "->", "_invokeParser", "(", "$", "matched", ",", "LEXER_SPECIAL", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "_mode", "->", "leave", "(", ")", ";", "}", "if", "(", "is_string", "(", "$", "mode", ")", ")", "{", "$", "this", "->", "_mode", "->", "enter", "(", "$", "mode", ")", ";", "return", "$", "this", "->", "_invokeParser", "(", "$", "matched", ",", "LEXER_ENTER", ")", ";", "}", "return", "$", "this", "->", "_invokeParser", "(", "$", "matched", ",", "LEXER_MATCHED", ")", ";", "}" ]
Sends the matched token and any leading unmatched text to the parser changing the lexer to a new mode if one is listed. @param string $unmatched Unmatched leading portion. @param string $matched Actual token match. @param string $mode Mode after match. The "_exit" mode causes a stack pop. An false mode causes no change. @return bool False if there was any error from the parser. @access private
[ "Sends", "the", "matched", "token", "and", "any", "leading", "unmatched", "text", "to", "the", "parser", "changing", "the", "lexer", "to", "a", "new", "mode", "if", "one", "is", "listed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lexer.php#L369-L392
212,091
moodle/moodle
lib/lexer.php
Lexer._invokeParser
function _invokeParser($content, $is_match) { if (($content === "") || ($content === false)) { return true; } $handler = $this->_mode->getCurrent(); if (isset($this->_mode_handlers[$handler])) { $handler = $this->_mode_handlers[$handler]; } return $this->_parser->$handler($content, $is_match); }
php
function _invokeParser($content, $is_match) { if (($content === "") || ($content === false)) { return true; } $handler = $this->_mode->getCurrent(); if (isset($this->_mode_handlers[$handler])) { $handler = $this->_mode_handlers[$handler]; } return $this->_parser->$handler($content, $is_match); }
[ "function", "_invokeParser", "(", "$", "content", ",", "$", "is_match", ")", "{", "if", "(", "(", "$", "content", "===", "\"\"", ")", "||", "(", "$", "content", "===", "false", ")", ")", "{", "return", "true", ";", "}", "$", "handler", "=", "$", "this", "->", "_mode", "->", "getCurrent", "(", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "_mode_handlers", "[", "$", "handler", "]", ")", ")", "{", "$", "handler", "=", "$", "this", "->", "_mode_handlers", "[", "$", "handler", "]", ";", "}", "return", "$", "this", "->", "_parser", "->", "$", "handler", "(", "$", "content", ",", "$", "is_match", ")", ";", "}" ]
Calls the parser method named after the current mode. Empty content will be ignored. @param string $content Text parsed. @param string $is_match Token is recognised rather than unparsed data. @access private
[ "Calls", "the", "parser", "method", "named", "after", "the", "current", "mode", ".", "Empty", "content", "will", "be", "ignored", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lexer.php#L402-L411
212,092
moodle/moodle
lib/lexer.php
Lexer._reduce
function _reduce(&$raw) { if (!isset($this->_regexes[$this->_mode->getCurrent()])) { return false; } if ($raw === "") { return true; } if ($action = $this->_regexes[$this->_mode->getCurrent()]->match($raw, $match)) { $count = strpos($raw, $match); $unparsed = substr($raw, 0, $count); $raw = substr($raw, $count + strlen($match)); return array($unparsed, $match, $action); } return true; }
php
function _reduce(&$raw) { if (!isset($this->_regexes[$this->_mode->getCurrent()])) { return false; } if ($raw === "") { return true; } if ($action = $this->_regexes[$this->_mode->getCurrent()]->match($raw, $match)) { $count = strpos($raw, $match); $unparsed = substr($raw, 0, $count); $raw = substr($raw, $count + strlen($match)); return array($unparsed, $match, $action); } return true; }
[ "function", "_reduce", "(", "&", "$", "raw", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_regexes", "[", "$", "this", "->", "_mode", "->", "getCurrent", "(", ")", "]", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "raw", "===", "\"\"", ")", "{", "return", "true", ";", "}", "if", "(", "$", "action", "=", "$", "this", "->", "_regexes", "[", "$", "this", "->", "_mode", "->", "getCurrent", "(", ")", "]", "->", "match", "(", "$", "raw", ",", "$", "match", ")", ")", "{", "$", "count", "=", "strpos", "(", "$", "raw", ",", "$", "match", ")", ";", "$", "unparsed", "=", "substr", "(", "$", "raw", ",", "0", ",", "$", "count", ")", ";", "$", "raw", "=", "substr", "(", "$", "raw", ",", "$", "count", "+", "strlen", "(", "$", "match", ")", ")", ";", "return", "array", "(", "$", "unparsed", ",", "$", "match", ",", "$", "action", ")", ";", "}", "return", "true", ";", "}" ]
Tries to match a chunk of text and if successful removes the recognised chunk and any leading unparsed data. Empty strings will not be matched. @param string $raw The subject to parse. This is the content that will be eaten. @return bool|array Three item list of unparsed content followed by the recognised token and finally the action the parser is to take. True if no match, false if there is a parsing error. @access private
[ "Tries", "to", "match", "a", "chunk", "of", "text", "and", "if", "successful", "removes", "the", "recognised", "chunk", "and", "any", "leading", "unparsed", "data", ".", "Empty", "strings", "will", "not", "be", "matched", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lexer.php#L427-L441
212,093
moodle/moodle
grade/grading/form/rubric/backup/moodle2/restore_gradingform_rubric_plugin.class.php
restore_gradingform_rubric_plugin.process_gradingform_rubric_level
public function process_gradingform_rubric_level($data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->criterionid = $this->get_new_parentid('gradingform_rubric_criterion'); $newid = $DB->insert_record('gradingform_rubric_levels', $data); $this->set_mapping('gradingform_rubric_level', $oldid, $newid); }
php
public function process_gradingform_rubric_level($data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->criterionid = $this->get_new_parentid('gradingform_rubric_criterion'); $newid = $DB->insert_record('gradingform_rubric_levels', $data); $this->set_mapping('gradingform_rubric_level', $oldid, $newid); }
[ "public", "function", "process_gradingform_rubric_level", "(", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "(", "object", ")", "$", "data", ";", "$", "oldid", "=", "$", "data", "->", "id", ";", "$", "data", "->", "criterionid", "=", "$", "this", "->", "get_new_parentid", "(", "'gradingform_rubric_criterion'", ")", ";", "$", "newid", "=", "$", "DB", "->", "insert_record", "(", "'gradingform_rubric_levels'", ",", "$", "data", ")", ";", "$", "this", "->", "set_mapping", "(", "'gradingform_rubric_level'", ",", "$", "oldid", ",", "$", "newid", ")", ";", "}" ]
Processes level element data Sets the mapping 'gradingform_rubric_level' to be used later by {@link self::process_gradinform_rubric_filling()} @param stdClass|array $data
[ "Processes", "level", "element", "data" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/rubric/backup/moodle2/restore_gradingform_rubric_plugin.class.php#L96-L105
212,094
moodle/moodle
mod/forum/classes/local/vaults/post_attachment.php
post_attachment.get_attachments_for_posts
public function get_attachments_for_posts(context $context, array $posts) { $itemids = array_map(function($post) { return $post->get_id(); }, $posts); $files = $this->filestorage->get_area_files( $context->id, self::COMPONENT, self::FILE_AREA, $itemids, self::SORT, self::INCLUDE_DIRECTORIES ); $filesbyid = array_reduce($posts, function($carry, $post) { $carry[$post->get_id()] = []; return $carry; }, []); return array_reduce($files, function($carry, $file) { $itemid = $file->get_itemid(); $carry[$itemid] = array_merge($carry[$itemid], [$file]); return $carry; }, $filesbyid); }
php
public function get_attachments_for_posts(context $context, array $posts) { $itemids = array_map(function($post) { return $post->get_id(); }, $posts); $files = $this->filestorage->get_area_files( $context->id, self::COMPONENT, self::FILE_AREA, $itemids, self::SORT, self::INCLUDE_DIRECTORIES ); $filesbyid = array_reduce($posts, function($carry, $post) { $carry[$post->get_id()] = []; return $carry; }, []); return array_reduce($files, function($carry, $file) { $itemid = $file->get_itemid(); $carry[$itemid] = array_merge($carry[$itemid], [$file]); return $carry; }, $filesbyid); }
[ "public", "function", "get_attachments_for_posts", "(", "context", "$", "context", ",", "array", "$", "posts", ")", "{", "$", "itemids", "=", "array_map", "(", "function", "(", "$", "post", ")", "{", "return", "$", "post", "->", "get_id", "(", ")", ";", "}", ",", "$", "posts", ")", ";", "$", "files", "=", "$", "this", "->", "filestorage", "->", "get_area_files", "(", "$", "context", "->", "id", ",", "self", "::", "COMPONENT", ",", "self", "::", "FILE_AREA", ",", "$", "itemids", ",", "self", "::", "SORT", ",", "self", "::", "INCLUDE_DIRECTORIES", ")", ";", "$", "filesbyid", "=", "array_reduce", "(", "$", "posts", ",", "function", "(", "$", "carry", ",", "$", "post", ")", "{", "$", "carry", "[", "$", "post", "->", "get_id", "(", ")", "]", "=", "[", "]", ";", "return", "$", "carry", ";", "}", ",", "[", "]", ")", ";", "return", "array_reduce", "(", "$", "files", ",", "function", "(", "$", "carry", ",", "$", "file", ")", "{", "$", "itemid", "=", "$", "file", "->", "get_itemid", "(", ")", ";", "$", "carry", "[", "$", "itemid", "]", "=", "array_merge", "(", "$", "carry", "[", "$", "itemid", "]", ",", "[", "$", "file", "]", ")", ";", "return", "$", "carry", ";", "}", ",", "$", "filesbyid", ")", ";", "}" ]
Get the attachments for the given posts. The results are indexed by post id. @param context $context The (forum) context that the posts are in @param post_entity[] $posts The list of posts to load attachments for @return array Post attachments indexed by post id
[ "Get", "the", "attachments", "for", "the", "given", "posts", ".", "The", "results", "are", "indexed", "by", "post", "id", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/post_attachment.php#L73-L97
212,095
moodle/moodle
calendar/renderer.php
core_calendar_renderer.add_pretend_calendar_block
public function add_pretend_calendar_block(block_contents $bc, $pos=BLOCK_POS_RIGHT) { $this->page->blocks->add_fake_block($bc, $pos); }
php
public function add_pretend_calendar_block(block_contents $bc, $pos=BLOCK_POS_RIGHT) { $this->page->blocks->add_fake_block($bc, $pos); }
[ "public", "function", "add_pretend_calendar_block", "(", "block_contents", "$", "bc", ",", "$", "pos", "=", "BLOCK_POS_RIGHT", ")", "{", "$", "this", "->", "page", "->", "blocks", "->", "add_fake_block", "(", "$", "bc", ",", "$", "pos", ")", ";", "}" ]
Adds a pretent calendar block @param block_contents $bc @param mixed $pos BLOCK_POS_RIGHT | BLOCK_POS_LEFT
[ "Adds", "a", "pretent", "calendar", "block" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/renderer.php#L114-L116
212,096
moodle/moodle
calendar/renderer.php
core_calendar_renderer.add_event_button
public function add_event_button($courseid, $unused1 = null, $unused2 = null, $unused3 = null, $unused4 = null) { $data = [ 'contextid' => (\context_course::instance($courseid))->id, ]; return $this->render_from_template('core_calendar/add_event_button', $data); }
php
public function add_event_button($courseid, $unused1 = null, $unused2 = null, $unused3 = null, $unused4 = null) { $data = [ 'contextid' => (\context_course::instance($courseid))->id, ]; return $this->render_from_template('core_calendar/add_event_button', $data); }
[ "public", "function", "add_event_button", "(", "$", "courseid", ",", "$", "unused1", "=", "null", ",", "$", "unused2", "=", "null", ",", "$", "unused3", "=", "null", ",", "$", "unused4", "=", "null", ")", "{", "$", "data", "=", "[", "'contextid'", "=>", "(", "\\", "context_course", "::", "instance", "(", "$", "courseid", ")", ")", "->", "id", ",", "]", ";", "return", "$", "this", "->", "render_from_template", "(", "'core_calendar/add_event_button'", ",", "$", "data", ")", ";", "}" ]
Creates a button to add a new event. @param int $courseid @param int $unused1 @param int $unused2 @param int $unused3 @param int $unused4 @return string
[ "Creates", "a", "button", "to", "add", "a", "new", "event", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/renderer.php#L128-L133
212,097
moodle/moodle
calendar/renderer.php
core_calendar_renderer.course_filter_selector
public function course_filter_selector(moodle_url $returnurl, $label = null, $courseid = null) { global $CFG, $DB; if (!isloggedin() or isguestuser()) { return ''; } $contextrecords = []; $courses = calendar_get_default_courses($courseid, 'id, shortname'); if (!empty($courses) && count($courses) > CONTEXT_CACHE_MAX_SIZE) { // We need to pull the context records from the DB to preload them // below. The calendar_get_default_courses code will actually preload // the contexts itself however the context cache is capped to a certain // amount before it starts recycling. Unfortunately that starts to happen // quite a bit if a user has access to a large number of courses (e.g. admin). // So in order to avoid hitting the DB for each context as we loop below we // can load all of the context records and add them to the cache just in time. $courseids = array_map(function($c) { return $c->id; }, $courses); list($insql, $params) = $DB->get_in_or_equal($courseids); $contextsql = "SELECT ctx.instanceid, " . context_helper::get_preload_record_columns_sql('ctx') . " FROM {context} ctx WHERE ctx.contextlevel = ? AND ctx.instanceid $insql"; array_unshift($params, CONTEXT_COURSE); $contextrecords = $DB->get_records_sql($contextsql, $params); } unset($courses[SITEID]); $courseoptions = array(); $courseoptions[SITEID] = get_string('fulllistofcourses'); foreach ($courses as $course) { if (isset($contextrecords[$course->id])) { context_helper::preload_from_record($contextrecords[$course->id]); } $coursecontext = context_course::instance($course->id); $courseoptions[$course->id] = format_string($course->shortname, true, array('context' => $coursecontext)); } if ($courseid) { $selected = $courseid; } else if ($this->page->course->id !== SITEID) { $selected = $this->page->course->id; } else { $selected = ''; } $courseurl = new moodle_url($returnurl); $courseurl->remove_params('course'); if ($label === null) { $label = get_string('listofcourses'); } $select = html_writer::label($label, 'course', false, ['class' => 'mr-1']); $select .= html_writer::select($courseoptions, 'course', $selected, false, ['class' => 'cal_courses_flt']); return $select; }
php
public function course_filter_selector(moodle_url $returnurl, $label = null, $courseid = null) { global $CFG, $DB; if (!isloggedin() or isguestuser()) { return ''; } $contextrecords = []; $courses = calendar_get_default_courses($courseid, 'id, shortname'); if (!empty($courses) && count($courses) > CONTEXT_CACHE_MAX_SIZE) { // We need to pull the context records from the DB to preload them // below. The calendar_get_default_courses code will actually preload // the contexts itself however the context cache is capped to a certain // amount before it starts recycling. Unfortunately that starts to happen // quite a bit if a user has access to a large number of courses (e.g. admin). // So in order to avoid hitting the DB for each context as we loop below we // can load all of the context records and add them to the cache just in time. $courseids = array_map(function($c) { return $c->id; }, $courses); list($insql, $params) = $DB->get_in_or_equal($courseids); $contextsql = "SELECT ctx.instanceid, " . context_helper::get_preload_record_columns_sql('ctx') . " FROM {context} ctx WHERE ctx.contextlevel = ? AND ctx.instanceid $insql"; array_unshift($params, CONTEXT_COURSE); $contextrecords = $DB->get_records_sql($contextsql, $params); } unset($courses[SITEID]); $courseoptions = array(); $courseoptions[SITEID] = get_string('fulllistofcourses'); foreach ($courses as $course) { if (isset($contextrecords[$course->id])) { context_helper::preload_from_record($contextrecords[$course->id]); } $coursecontext = context_course::instance($course->id); $courseoptions[$course->id] = format_string($course->shortname, true, array('context' => $coursecontext)); } if ($courseid) { $selected = $courseid; } else if ($this->page->course->id !== SITEID) { $selected = $this->page->course->id; } else { $selected = ''; } $courseurl = new moodle_url($returnurl); $courseurl->remove_params('course'); if ($label === null) { $label = get_string('listofcourses'); } $select = html_writer::label($label, 'course', false, ['class' => 'mr-1']); $select .= html_writer::select($courseoptions, 'course', $selected, false, ['class' => 'cal_courses_flt']); return $select; }
[ "public", "function", "course_filter_selector", "(", "moodle_url", "$", "returnurl", ",", "$", "label", "=", "null", ",", "$", "courseid", "=", "null", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "if", "(", "!", "isloggedin", "(", ")", "or", "isguestuser", "(", ")", ")", "{", "return", "''", ";", "}", "$", "contextrecords", "=", "[", "]", ";", "$", "courses", "=", "calendar_get_default_courses", "(", "$", "courseid", ",", "'id, shortname'", ")", ";", "if", "(", "!", "empty", "(", "$", "courses", ")", "&&", "count", "(", "$", "courses", ")", ">", "CONTEXT_CACHE_MAX_SIZE", ")", "{", "// We need to pull the context records from the DB to preload them", "// below. The calendar_get_default_courses code will actually preload", "// the contexts itself however the context cache is capped to a certain", "// amount before it starts recycling. Unfortunately that starts to happen", "// quite a bit if a user has access to a large number of courses (e.g. admin).", "// So in order to avoid hitting the DB for each context as we loop below we", "// can load all of the context records and add them to the cache just in time.", "$", "courseids", "=", "array_map", "(", "function", "(", "$", "c", ")", "{", "return", "$", "c", "->", "id", ";", "}", ",", "$", "courses", ")", ";", "list", "(", "$", "insql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "courseids", ")", ";", "$", "contextsql", "=", "\"SELECT ctx.instanceid, \"", ".", "context_helper", "::", "get_preload_record_columns_sql", "(", "'ctx'", ")", ".", "\" FROM {context} ctx WHERE ctx.contextlevel = ? AND ctx.instanceid $insql\"", ";", "array_unshift", "(", "$", "params", ",", "CONTEXT_COURSE", ")", ";", "$", "contextrecords", "=", "$", "DB", "->", "get_records_sql", "(", "$", "contextsql", ",", "$", "params", ")", ";", "}", "unset", "(", "$", "courses", "[", "SITEID", "]", ")", ";", "$", "courseoptions", "=", "array", "(", ")", ";", "$", "courseoptions", "[", "SITEID", "]", "=", "get_string", "(", "'fulllistofcourses'", ")", ";", "foreach", "(", "$", "courses", "as", "$", "course", ")", "{", "if", "(", "isset", "(", "$", "contextrecords", "[", "$", "course", "->", "id", "]", ")", ")", "{", "context_helper", "::", "preload_from_record", "(", "$", "contextrecords", "[", "$", "course", "->", "id", "]", ")", ";", "}", "$", "coursecontext", "=", "context_course", "::", "instance", "(", "$", "course", "->", "id", ")", ";", "$", "courseoptions", "[", "$", "course", "->", "id", "]", "=", "format_string", "(", "$", "course", "->", "shortname", ",", "true", ",", "array", "(", "'context'", "=>", "$", "coursecontext", ")", ")", ";", "}", "if", "(", "$", "courseid", ")", "{", "$", "selected", "=", "$", "courseid", ";", "}", "else", "if", "(", "$", "this", "->", "page", "->", "course", "->", "id", "!==", "SITEID", ")", "{", "$", "selected", "=", "$", "this", "->", "page", "->", "course", "->", "id", ";", "}", "else", "{", "$", "selected", "=", "''", ";", "}", "$", "courseurl", "=", "new", "moodle_url", "(", "$", "returnurl", ")", ";", "$", "courseurl", "->", "remove_params", "(", "'course'", ")", ";", "if", "(", "$", "label", "===", "null", ")", "{", "$", "label", "=", "get_string", "(", "'listofcourses'", ")", ";", "}", "$", "select", "=", "html_writer", "::", "label", "(", "$", "label", ",", "'course'", ",", "false", ",", "[", "'class'", "=>", "'mr-1'", "]", ")", ";", "$", "select", ".=", "html_writer", "::", "select", "(", "$", "courseoptions", ",", "'course'", ",", "$", "selected", ",", "false", ",", "[", "'class'", "=>", "'cal_courses_flt'", "]", ")", ";", "return", "$", "select", ";", "}" ]
Displays a course filter selector @param moodle_url $returnurl The URL that the user should be taken too upon selecting a course. @param string $label The label to use for the course select. @param int $courseid The id of the course to be selected. @return string
[ "Displays", "a", "course", "filter", "selector" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/renderer.php#L245-L303
212,098
moodle/moodle
calendar/renderer.php
core_calendar_renderer.subscription_details
public function subscription_details($unused = null, $subscriptions, $importresults = '') { $table = new html_table(); $table->head = array( get_string('colcalendar', 'calendar'), get_string('collastupdated', 'calendar'), get_string('eventkind', 'calendar'), get_string('colpoll', 'calendar'), get_string('colactions', 'calendar') ); $table->align = array('left', 'left', 'left', 'center'); $table->width = '100%'; $table->data = array(); if (empty($subscriptions)) { $cell = new html_table_cell(get_string('nocalendarsubscriptions', 'calendar')); $cell->colspan = 5; $table->data[] = new html_table_row(array($cell)); } $strnever = new lang_string('never', 'calendar'); foreach ($subscriptions as $sub) { $label = $sub->name; if (!empty($sub->url)) { $label = html_writer::link($sub->url, $label); } if (empty($sub->lastupdated)) { $lastupdated = $strnever->out(); } else { $lastupdated = userdate($sub->lastupdated, get_string('strftimedatetimeshort', 'langconfig')); } $cell = new html_table_cell($this->subscription_action_form($sub)); $cell->colspan = 2; $type = $sub->eventtype . 'events'; $table->data[] = new html_table_row(array( new html_table_cell($label), new html_table_cell($lastupdated), new html_table_cell(get_string($type, 'calendar')), $cell )); } $out = $this->output->box_start('generalbox calendarsubs'); $out .= $importresults; $out .= html_writer::table($table); $out .= $this->output->box_end(); return $out; }
php
public function subscription_details($unused = null, $subscriptions, $importresults = '') { $table = new html_table(); $table->head = array( get_string('colcalendar', 'calendar'), get_string('collastupdated', 'calendar'), get_string('eventkind', 'calendar'), get_string('colpoll', 'calendar'), get_string('colactions', 'calendar') ); $table->align = array('left', 'left', 'left', 'center'); $table->width = '100%'; $table->data = array(); if (empty($subscriptions)) { $cell = new html_table_cell(get_string('nocalendarsubscriptions', 'calendar')); $cell->colspan = 5; $table->data[] = new html_table_row(array($cell)); } $strnever = new lang_string('never', 'calendar'); foreach ($subscriptions as $sub) { $label = $sub->name; if (!empty($sub->url)) { $label = html_writer::link($sub->url, $label); } if (empty($sub->lastupdated)) { $lastupdated = $strnever->out(); } else { $lastupdated = userdate($sub->lastupdated, get_string('strftimedatetimeshort', 'langconfig')); } $cell = new html_table_cell($this->subscription_action_form($sub)); $cell->colspan = 2; $type = $sub->eventtype . 'events'; $table->data[] = new html_table_row(array( new html_table_cell($label), new html_table_cell($lastupdated), new html_table_cell(get_string($type, 'calendar')), $cell )); } $out = $this->output->box_start('generalbox calendarsubs'); $out .= $importresults; $out .= html_writer::table($table); $out .= $this->output->box_end(); return $out; }
[ "public", "function", "subscription_details", "(", "$", "unused", "=", "null", ",", "$", "subscriptions", ",", "$", "importresults", "=", "''", ")", "{", "$", "table", "=", "new", "html_table", "(", ")", ";", "$", "table", "->", "head", "=", "array", "(", "get_string", "(", "'colcalendar'", ",", "'calendar'", ")", ",", "get_string", "(", "'collastupdated'", ",", "'calendar'", ")", ",", "get_string", "(", "'eventkind'", ",", "'calendar'", ")", ",", "get_string", "(", "'colpoll'", ",", "'calendar'", ")", ",", "get_string", "(", "'colactions'", ",", "'calendar'", ")", ")", ";", "$", "table", "->", "align", "=", "array", "(", "'left'", ",", "'left'", ",", "'left'", ",", "'center'", ")", ";", "$", "table", "->", "width", "=", "'100%'", ";", "$", "table", "->", "data", "=", "array", "(", ")", ";", "if", "(", "empty", "(", "$", "subscriptions", ")", ")", "{", "$", "cell", "=", "new", "html_table_cell", "(", "get_string", "(", "'nocalendarsubscriptions'", ",", "'calendar'", ")", ")", ";", "$", "cell", "->", "colspan", "=", "5", ";", "$", "table", "->", "data", "[", "]", "=", "new", "html_table_row", "(", "array", "(", "$", "cell", ")", ")", ";", "}", "$", "strnever", "=", "new", "lang_string", "(", "'never'", ",", "'calendar'", ")", ";", "foreach", "(", "$", "subscriptions", "as", "$", "sub", ")", "{", "$", "label", "=", "$", "sub", "->", "name", ";", "if", "(", "!", "empty", "(", "$", "sub", "->", "url", ")", ")", "{", "$", "label", "=", "html_writer", "::", "link", "(", "$", "sub", "->", "url", ",", "$", "label", ")", ";", "}", "if", "(", "empty", "(", "$", "sub", "->", "lastupdated", ")", ")", "{", "$", "lastupdated", "=", "$", "strnever", "->", "out", "(", ")", ";", "}", "else", "{", "$", "lastupdated", "=", "userdate", "(", "$", "sub", "->", "lastupdated", ",", "get_string", "(", "'strftimedatetimeshort'", ",", "'langconfig'", ")", ")", ";", "}", "$", "cell", "=", "new", "html_table_cell", "(", "$", "this", "->", "subscription_action_form", "(", "$", "sub", ")", ")", ";", "$", "cell", "->", "colspan", "=", "2", ";", "$", "type", "=", "$", "sub", "->", "eventtype", ".", "'events'", ";", "$", "table", "->", "data", "[", "]", "=", "new", "html_table_row", "(", "array", "(", "new", "html_table_cell", "(", "$", "label", ")", ",", "new", "html_table_cell", "(", "$", "lastupdated", ")", ",", "new", "html_table_cell", "(", "get_string", "(", "$", "type", ",", "'calendar'", ")", ")", ",", "$", "cell", ")", ")", ";", "}", "$", "out", "=", "$", "this", "->", "output", "->", "box_start", "(", "'generalbox calendarsubs'", ")", ";", "$", "out", ".=", "$", "importresults", ";", "$", "out", ".=", "html_writer", "::", "table", "(", "$", "table", ")", ";", "$", "out", ".=", "$", "this", "->", "output", "->", "box_end", "(", ")", ";", "return", "$", "out", ";", "}" ]
Renders a table containing information about calendar subscriptions. @param int $unused @param array $subscriptions @param string $importresults @return string
[ "Renders", "a", "table", "containing", "information", "about", "calendar", "subscriptions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/renderer.php#L313-L361
212,099
moodle/moodle
calendar/renderer.php
core_calendar_renderer.subscription_action_form
protected function subscription_action_form($subscription) { // Assemble form for the subscription row. $html = html_writer::start_tag('form', array('action' => new moodle_url('/calendar/managesubscriptions.php'), 'method' => 'post')); if (empty($subscription->url)) { // Don't update an iCal file, which has no URL. $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'pollinterval', 'value' => '0')); } else { // Assemble pollinterval control. $html .= html_writer::start_tag('div', array('style' => 'float:left;')); $html .= html_writer::start_tag('select', array('name' => 'pollinterval', 'class' => 'custom-select')); foreach (calendar_get_pollinterval_choices() as $k => $v) { $attributes = array(); if ($k == $subscription->pollinterval) { $attributes['selected'] = 'selected'; } $attributes['value'] = $k; $html .= html_writer::tag('option', $v, $attributes); } $html .= html_writer::end_tag('select'); $html .= html_writer::end_tag('div'); } $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())); $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'id', 'value' => $subscription->id)); $html .= html_writer::start_tag('div', array('class' => 'btn-group float-right')); if (!empty($subscription->url)) { $html .= html_writer::tag('button', get_string('update'), array('type' => 'submit', 'name' => 'action', 'class' => 'btn btn-secondary', 'value' => CALENDAR_SUBSCRIPTION_UPDATE)); } $html .= html_writer::tag('button', get_string('remove'), array('type' => 'submit', 'name' => 'action', 'class' => 'btn btn-secondary', 'value' => CALENDAR_SUBSCRIPTION_REMOVE)); $html .= html_writer::end_tag('div'); $html .= html_writer::end_tag('form'); return $html; }
php
protected function subscription_action_form($subscription) { // Assemble form for the subscription row. $html = html_writer::start_tag('form', array('action' => new moodle_url('/calendar/managesubscriptions.php'), 'method' => 'post')); if (empty($subscription->url)) { // Don't update an iCal file, which has no URL. $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'pollinterval', 'value' => '0')); } else { // Assemble pollinterval control. $html .= html_writer::start_tag('div', array('style' => 'float:left;')); $html .= html_writer::start_tag('select', array('name' => 'pollinterval', 'class' => 'custom-select')); foreach (calendar_get_pollinterval_choices() as $k => $v) { $attributes = array(); if ($k == $subscription->pollinterval) { $attributes['selected'] = 'selected'; } $attributes['value'] = $k; $html .= html_writer::tag('option', $v, $attributes); } $html .= html_writer::end_tag('select'); $html .= html_writer::end_tag('div'); } $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())); $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'id', 'value' => $subscription->id)); $html .= html_writer::start_tag('div', array('class' => 'btn-group float-right')); if (!empty($subscription->url)) { $html .= html_writer::tag('button', get_string('update'), array('type' => 'submit', 'name' => 'action', 'class' => 'btn btn-secondary', 'value' => CALENDAR_SUBSCRIPTION_UPDATE)); } $html .= html_writer::tag('button', get_string('remove'), array('type' => 'submit', 'name' => 'action', 'class' => 'btn btn-secondary', 'value' => CALENDAR_SUBSCRIPTION_REMOVE)); $html .= html_writer::end_tag('div'); $html .= html_writer::end_tag('form'); return $html; }
[ "protected", "function", "subscription_action_form", "(", "$", "subscription", ")", "{", "// Assemble form for the subscription row.", "$", "html", "=", "html_writer", "::", "start_tag", "(", "'form'", ",", "array", "(", "'action'", "=>", "new", "moodle_url", "(", "'/calendar/managesubscriptions.php'", ")", ",", "'method'", "=>", "'post'", ")", ")", ";", "if", "(", "empty", "(", "$", "subscription", "->", "url", ")", ")", "{", "// Don't update an iCal file, which has no URL.", "$", "html", ".=", "html_writer", "::", "empty_tag", "(", "'input'", ",", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'pollinterval'", ",", "'value'", "=>", "'0'", ")", ")", ";", "}", "else", "{", "// Assemble pollinterval control.", "$", "html", ".=", "html_writer", "::", "start_tag", "(", "'div'", ",", "array", "(", "'style'", "=>", "'float:left;'", ")", ")", ";", "$", "html", ".=", "html_writer", "::", "start_tag", "(", "'select'", ",", "array", "(", "'name'", "=>", "'pollinterval'", ",", "'class'", "=>", "'custom-select'", ")", ")", ";", "foreach", "(", "calendar_get_pollinterval_choices", "(", ")", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "attributes", "=", "array", "(", ")", ";", "if", "(", "$", "k", "==", "$", "subscription", "->", "pollinterval", ")", "{", "$", "attributes", "[", "'selected'", "]", "=", "'selected'", ";", "}", "$", "attributes", "[", "'value'", "]", "=", "$", "k", ";", "$", "html", ".=", "html_writer", "::", "tag", "(", "'option'", ",", "$", "v", ",", "$", "attributes", ")", ";", "}", "$", "html", ".=", "html_writer", "::", "end_tag", "(", "'select'", ")", ";", "$", "html", ".=", "html_writer", "::", "end_tag", "(", "'div'", ")", ";", "}", "$", "html", ".=", "html_writer", "::", "empty_tag", "(", "'input'", ",", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'sesskey'", ",", "'value'", "=>", "sesskey", "(", ")", ")", ")", ";", "$", "html", ".=", "html_writer", "::", "empty_tag", "(", "'input'", ",", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'id'", ",", "'value'", "=>", "$", "subscription", "->", "id", ")", ")", ";", "$", "html", ".=", "html_writer", "::", "start_tag", "(", "'div'", ",", "array", "(", "'class'", "=>", "'btn-group float-right'", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "subscription", "->", "url", ")", ")", "{", "$", "html", ".=", "html_writer", "::", "tag", "(", "'button'", ",", "get_string", "(", "'update'", ")", ",", "array", "(", "'type'", "=>", "'submit'", ",", "'name'", "=>", "'action'", ",", "'class'", "=>", "'btn btn-secondary'", ",", "'value'", "=>", "CALENDAR_SUBSCRIPTION_UPDATE", ")", ")", ";", "}", "$", "html", ".=", "html_writer", "::", "tag", "(", "'button'", ",", "get_string", "(", "'remove'", ")", ",", "array", "(", "'type'", "=>", "'submit'", ",", "'name'", "=>", "'action'", ",", "'class'", "=>", "'btn btn-secondary'", ",", "'value'", "=>", "CALENDAR_SUBSCRIPTION_REMOVE", ")", ")", ";", "$", "html", ".=", "html_writer", "::", "end_tag", "(", "'div'", ")", ";", "$", "html", ".=", "html_writer", "::", "end_tag", "(", "'form'", ")", ";", "return", "$", "html", ";", "}" ]
Creates a form to perform actions on a given subscription. @param stdClass $subscription @return string
[ "Creates", "a", "form", "to", "perform", "actions", "on", "a", "given", "subscription", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/renderer.php#L369-L404