. /** * @package plagiarism_pchkorg * @category plagiarism * @copyright PlagiarismCheck.org, https://plagiarismcheck.org/ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); /** * Class plagiarism_pchkorg_config_model */ class plagiarism_pchkorg_config_model { /** * * Check if plugin is enable for some specific module. * Result is static. * * @param $module * @return bool */ public function is_enabled_for_module($module) { global $DB; static $resultmap = array(); // This will be called only once per module. if (!array_key_exists($module, $resultmap)) { $configs = $DB->get_records('plagiarism_pchkorg_config', array( 'cm' => $module, )); $enabled = false; foreach ($configs as $record) { switch ($record->name) { case 'pchkorg_module_use': $enabled = '1' == $record->value; break; default: break; } } $resultmap[$module] = $enabled; } return $resultmap[$module]; } /** * * Save plugin settings. * * @param $name * @param $value */ public function set_system_config($name, $value) { global $DB; $DB->delete_records('plagiarism_pchkorg_config', array( 'cm' => 0, 'name' => $name, )); $record = new \stdClass(); $record->cn = 0; $record->name = $name; $record->value = $value; $DB->insert_record('plagiarism_pchkorg_config', $record); } /** * @param $name * @return |null */ public function get_system_config($name) { global $DB; // SQL query will be called only one per one setting name. static $resultsmap = array(); if (!array_key_exists($name, $resultsmap)) { $records = $DB->get_records('plagiarism_pchkorg_config', array( 'cm' => 0, 'name' => $name, )); foreach ($records as $record) { $resultsmap[$name] = $record->value; break; } } return $resultsmap[$name]; } /** * * Fetch all plugin settings as array. * Result is static. * * @return array */ public function get_all_system_config() { global $DB; static $map = array(); if (empty($map)) { $records = $DB->get_records('plagiarism_pchkorg_config', array( 'cm' => 0, )); foreach ($records as $record) { $map[$record->name] = $record->value; } } return $map; } }