2019-01-17 16:51:22 +00:00
|
|
|
<?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/>.
|
|
|
|
|
2019-02-06 13:38:23 +00:00
|
|
|
/**
|
|
|
|
* @package plagiarism_pchkorg
|
|
|
|
* @category plagiarism
|
|
|
|
* @copyright PlagiarismCheck.org, https://plagiarismcheck.org/
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2019-01-17 16:51:22 +00:00
|
|
|
defined('MOODLE_INTERNAL') || die();
|
|
|
|
|
2019-02-06 13:38:23 +00:00
|
|
|
/**
|
|
|
|
* Class plagiarism_pchkorg_config_model
|
|
|
|
*/
|
2019-01-17 16:51:22 +00:00
|
|
|
class plagiarism_pchkorg_config_model {
|
|
|
|
|
2019-02-06 13:38:23 +00:00
|
|
|
/**
|
2019-04-05 16:25:06 +00:00
|
|
|
*
|
|
|
|
* Check if plugin is enable for some specific module.
|
|
|
|
* Result is static.
|
|
|
|
*
|
2019-02-06 13:38:23 +00:00
|
|
|
* @param $module
|
|
|
|
* @return bool
|
|
|
|
*/
|
2019-01-17 16:51:22 +00:00
|
|
|
public function is_enabled_for_module($module) {
|
2019-02-28 13:17:56 +00:00
|
|
|
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'
|
2019-02-28 13:17:56 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
$enabled = false;
|
|
|
|
foreach ($configs as $record) {
|
|
|
|
switch ($record->name) {
|
|
|
|
case 'pchkorg_module_use':
|
|
|
|
$enabled = '1' == $record->value;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-01-17 16:51:22 +00:00
|
|
|
}
|
2019-02-28 13:17:56 +00:00
|
|
|
|
|
|
|
$resultmap[$module] = $enabled;
|
2019-01-17 16:51:22 +00:00
|
|
|
}
|
|
|
|
|
2019-02-28 13:17:56 +00:00
|
|
|
return $resultmap[$module];
|
2019-01-17 16:51:22 +00:00
|
|
|
}
|
|
|
|
|
2022-07-22 07:20:38 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* 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-02-06 13:38:23 +00:00
|
|
|
/**
|
2019-04-05 16:25:06 +00:00
|
|
|
*
|
|
|
|
* Save plugin settings.
|
|
|
|
*
|
2019-02-06 13:38:23 +00:00
|
|
|
* @param $name
|
|
|
|
* @param $value
|
|
|
|
*/
|
2019-01-17 16:51:22 +00:00
|
|
|
public function set_system_config($name, $value) {
|
2019-02-28 13:17:56 +00:00
|
|
|
global $DB;
|
|
|
|
|
|
|
|
$DB->delete_records('plagiarism_pchkorg_config', array(
|
2019-01-17 16:51:22 +00:00
|
|
|
'cm' => 0,
|
|
|
|
'name' => $name,
|
|
|
|
));
|
|
|
|
|
|
|
|
$record = new \stdClass();
|
|
|
|
$record->cn = 0;
|
|
|
|
$record->name = $name;
|
|
|
|
$record->value = $value;
|
|
|
|
|
2019-02-28 13:17:56 +00:00
|
|
|
$DB->insert_record('plagiarism_pchkorg_config', $record);
|
2019-01-17 16:51:22 +00:00
|
|
|
}
|
|
|
|
|
2019-02-06 13:38:23 +00:00
|
|
|
/**
|
|
|
|
* @param $name
|
|
|
|
* @return |null
|
|
|
|
*/
|
2019-01-17 16:51:22 +00:00
|
|
|
public function get_system_config($name) {
|
2019-02-28 13:17:56 +00:00
|
|
|
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;
|
2019-02-28 13:17:56 +00:00
|
|
|
foreach ($records as $record) {
|
|
|
|
$resultsmap[$name] = $record->value;
|
|
|
|
break;
|
|
|
|
}
|
2019-01-17 16:51:22 +00:00
|
|
|
}
|
|
|
|
|
2019-02-28 13:17:56 +00:00
|
|
|
return $resultsmap[$name];
|
2019-01-17 16:51:22 +00:00
|
|
|
}
|
|
|
|
|
2019-02-06 13:38:23 +00:00
|
|
|
/**
|
2019-04-05 16:25:06 +00:00
|
|
|
*
|
|
|
|
* Fetch all plugin settings as array.
|
|
|
|
* Result is static.
|
|
|
|
*
|
2019-02-06 13:38:23 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2019-01-17 16:51:22 +00:00
|
|
|
public function get_all_system_config() {
|
2019-02-28 13:17:56 +00:00
|
|
|
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;
|
|
|
|
}
|
2019-01-17 16:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $map;
|
|
|
|
}
|
|
|
|
}
|