1
0
mirror of https://github.com/PlagiarismCheck/moodle-plagiarism_pchkorg.git synced 2024-12-22 04:10:07 +00:00
moodle-plagiarism_pchkorg/classes/plagiarism_pchkorg_config_model.php

237 lines
6.2 KiB
PHP
Raw Normal View History

<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @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 {
/**
2019-04-05 16:25:06 +00:00
*
* 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,
2022-04-28 12:02:50 +00:00
'name' => 'pchkorg_module_use'
));
$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];
}
/**
*
* Check if plugin show widget to student.
* Result is static.
*
* @param $module
* @return bool
*/
public function show_widget_for_student($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,
'name' => 'pchkorg_student_can_see_widget'
));
$enabled = null;
foreach ($configs as $record) {
switch ($record->name) {
case 'pchkorg_student_can_see_widget':
$enabled = '1' == $record->value;
break;
default:
break;
}
}
$resultmap[$module] = $enabled;
}
return $resultmap[$module];
}
/**
*
* Check if plugin show report to student.
* Result is static.
*
* @param $module
* @return bool
*/
public function show_report_for_student($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,
'name' => 'pchkorg_student_can_see_report'
));
$enabled = null;
foreach ($configs as $record) {
switch ($record->name) {
case 'pchkorg_student_can_see_report':
$enabled = '1' == $record->value;
break;
default:
break;
}
}
$resultmap[$module] = $enabled;
}
return $resultmap[$module];
}
2022-04-28 12:02:50 +00:00
/**
*
2022-05-04 17:20:37 +00:00
* Get value for search setting
2022-04-28 12:02:50 +00:00
*
* @param $module
2022-05-04 17:20:37 +00:00
* @param $name
2022-04-28 12:02:50 +00:00
* @return bool
*/
2022-05-04 17:20:37 +00:00
public function get_filter_for_module($module, $name) {
2022-04-28 12:02:50 +00:00
global $DB;
2022-05-05 14:45:40 +00:00
$configs = $DB->get_records('plagiarism_pchkorg_config', array(
'cm' => $module,
'name' => $name,
));
2022-04-28 12:02:50 +00:00
2022-05-05 14:45:40 +00:00
$value = null;
foreach ($configs as $record) {
if ($record->name === $name) {
$value = $record->value;
break;
2022-04-28 12:02:50 +00:00
}
}
2022-05-05 14:45:40 +00:00
return $value;
2022-04-28 12:02:50 +00:00
}
/**
2019-04-05 16:25:06 +00:00
*
* 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,
));
2022-04-28 12:02:50 +00:00
$resultsmap[$name] = null;
foreach ($records as $record) {
$resultsmap[$name] = $record->value;
break;
}
}
return $resultsmap[$name];
}
/**
2019-04-05 16:25:06 +00:00
*
* 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;
}
}