moodle-filter_bibleversesnwt/filter.php

62 lines
2.1 KiB
PHP
Raw Normal View History

2023-05-26 15:21:13 +02: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/>.
/**
* Filter main class for the filter_pluginname plugin.
*
* @package filter_pluginname
* @copyright Year, You Name <your@email.address>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use filter_bibleversesnwt\bible;
class filter_bibleversesnwt extends moodle_text_filter {
private $courseconfig;
private $adminconfig;
public function setup($page, $context) {
$page->requires->js_call_amd('filter_bibleversesnwt/filter_bibleversesnwt','init', []);
}
private function fetch_prop($prop,$default){
global $COURSE;
if ($this->localconfig && !empty($this->localconfig)) {
$this->courseconfig = $this->localconfig;
}
if (!$this->courseconfig) {
$this->courseconfig = filter_get_local_config('bibleversesnwt', context_course::instance($COURSE->id)->id);
}
if ($this->courseconfig && isset($this->courseconfig[$prop])) {
return $this->courseconfig[$prop];
} else {
if(!$this->adminconfig) {
$this->adminconfig =get_config('filter_bibleversesnwt');
}
return isset($this->adminconfig->{$prop}) ? $this->adminconfig->{$prop} : $default;
}
}
2023-05-26 15:21:13 +02:00
function filter($text, array $options = []) {
// Return the modified text.
$lang = $this->fetch_prop('biblelang','nl');
$bible = new bible($lang);
2023-05-26 15:21:13 +02:00
return $bible->parse($text);
}
}