-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from SE-Stuttgart/dev
Dev
- Loading branch information
Showing
13 changed files
with
994 additions
and
846 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
name: Moodle Plugin CI | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-22.04 | ||
|
||
services: | ||
postgres: | ||
image: postgres:13 | ||
env: | ||
POSTGRES_USER: 'postgres' | ||
POSTGRES_HOST_AUTH_METHOD: 'trust' | ||
ports: | ||
- 5432:5432 | ||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3 | ||
|
||
mariadb: | ||
image: mariadb:10 | ||
env: | ||
MYSQL_USER: 'root' | ||
MYSQL_ALLOW_EMPTY_PASSWORD: "true" | ||
MYSQL_CHARACTER_SET_SERVER: "utf8mb4" | ||
MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci" | ||
ports: | ||
- 3306:3306 | ||
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3 | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php: ['7.4', '8.0', '8.1'] | ||
moodle-branch: ['MOODLE_401_STABLE'] | ||
database: [pgsql, mariadb] | ||
|
||
steps: | ||
- name: Check out repository code | ||
uses: actions/checkout@v3 | ||
with: | ||
path: plugin | ||
|
||
- name: Setup PHP ${{ matrix.php }} | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: ${{ matrix.extensions }} | ||
ini-values: max_input_vars=5000 | ||
# If you are not using code coverage, keep "none". Otherwise, use "pcov" (Moodle 3.10 and up) or "xdebug". | ||
# If you try to use code coverage with "none", it will fallback to phpdbg (which has known problems). | ||
coverage: none | ||
|
||
- name: Initialise moodle-plugin-ci | ||
run: | | ||
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4 | ||
echo $(cd ci/bin; pwd) >> $GITHUB_PATH | ||
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH | ||
sudo locale-gen en_AU.UTF-8 | ||
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV | ||
- name: Install moodle-plugin-ci | ||
run: | | ||
moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 | ||
env: | ||
DB: ${{ matrix.database }} | ||
MOODLE_BRANCH: ${{ matrix.moodle-branch }} | ||
|
||
- name: PHP Lint | ||
if: ${{ always() }} | ||
run: moodle-plugin-ci phplint | ||
|
||
- name: PHP Copy/Paste Detector | ||
continue-on-error: true # This step will show errors but will not fail | ||
if: ${{ always() }} | ||
run: moodle-plugin-ci phpcpd | ||
|
||
- name: PHP Mess Detector | ||
continue-on-error: true # This step will show errors but will not fail | ||
if: ${{ always() }} | ||
run: moodle-plugin-ci phpmd | ||
|
||
- name: Moodle Code Checker | ||
if: ${{ always() }} | ||
run: moodle-plugin-ci phpcs --max-warnings 0 | ||
|
||
- name: Moodle PHPDoc Checker | ||
if: ${{ always() }} | ||
run: moodle-plugin-ci phpdoc --max-warnings 0 | ||
|
||
- name: Validating | ||
if: ${{ always() }} | ||
run: moodle-plugin-ci validate | ||
|
||
- name: Check upgrade savepoints | ||
if: ${{ always() }} | ||
run: moodle-plugin-ci savepoints | ||
|
||
- name: Mustache Lint | ||
if: ${{ always() }} | ||
run: moodle-plugin-ci mustache | ||
|
||
- name: Grunt | ||
if: ${{ always() }} | ||
run: moodle-plugin-ci grunt --max-lint-warnings 0 | ||
|
||
- name: PHPUnit tests | ||
if: ${{ always() }} | ||
run: moodle-plugin-ci phpunit --fail-on-warning | ||
|
||
- name: Behat features | ||
if: ${{ always() }} | ||
run: moodle-plugin-ci behat --profile chrome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,129 +1,141 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Block core and UI | ||
* | ||
* @package block_slidefinder | ||
* @copyright 2022 Universtity of Stuttgart <kasra.habib@iste.uni-stuttgart.de> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once(__DIR__ . '/../../config.php'); | ||
require_once(__DIR__ . '/locallib.php'); | ||
|
||
class block_slidefinder extends block_base | ||
{ | ||
/** | ||
* Set the initial properties for the block | ||
*/ | ||
function init() | ||
{ | ||
$this->blockname = get_class($this); | ||
$this->title = get_string('pluginname', $this->blockname); | ||
} | ||
|
||
/** | ||
* Describe Block Content | ||
*/ | ||
public function get_content() | ||
{ | ||
global $PAGE, $CFG, $DB, $USER; | ||
|
||
|
||
// Context | ||
$systemcontext = context_system::instance(); | ||
$usercontext = context_user::instance($USER->id); | ||
|
||
// Params | ||
$cid = optional_param('id', 0, PARAM_INT); // Do we have a set course id? Or are we on our dashboard (default). | ||
$lrf_cid = optional_param('lrf_cid', $cid, PARAM_INT); // Selected course ID (by our course selection). | ||
$search = optional_param('search', '', PARAM_TEXT); // Searched pattern (search hook). | ||
|
||
$course = null; // Course to search in. | ||
$course_id = 0; // Course ID of searched course. | ||
|
||
$view_course_selection = false; // Are we displaying the course selection? | ||
$view_selected_course = false; // Are we displaying the search field? Did we select a course? Are we allowed to search said course? | ||
// Get Course and CourseID by parameter | ||
if ($course = $DB->get_record('course', array('id' => $lrf_cid))) { | ||
$course_id = $course->id; | ||
$coursecontext = context_course::instance($course->id); | ||
} | ||
|
||
// Renderer needed to use templates | ||
$renderer = $PAGE->get_renderer($this->blockname); | ||
|
||
$view_course_selection = !$cid; | ||
$view_selected_course = $course_id ? block_lrf_enrolled_in($USER->id, $course_id) : false; | ||
|
||
// Main Content (text) and Footer of the block | ||
$text = ''; | ||
$footer = ''; | ||
|
||
|
||
if ($view_course_selection) { | ||
$text .= $renderer->render_from_template('block_slidefinder/lrf_drop_down', [ | ||
'action' => $PAGE->url, | ||
'course_selector_param_name' => 'lrf_cid', | ||
'course_selector_options' => block_lrf_select_course_options($course_id, $USER->id), | ||
]); | ||
} | ||
if ($view_selected_course) { | ||
$text .= $renderer->render_from_template('block_slidefinder/lrf_search', [ | ||
'action' => $PAGE->url, | ||
'cid' => $cid, | ||
'lrf_cid' => $lrf_cid, | ||
'course_selector_param_name' => 'lrf_cid', | ||
'search_term_param_name' => 'search', | ||
'search_term_placeholder' => get_string('search', $this->blockname), | ||
'search_term_label' => get_string('search_term', $this->blockname), | ||
'search_term' => $search, | ||
'chapter_label' => get_string('chapter', $this->blockname), | ||
'content' => base64_encode(json_encode($this->get_pdfs_content_from_course($course))) | ||
]); | ||
} | ||
|
||
$this->content = new stdClass(); | ||
$this->content->text = $text; | ||
$this->content->footer = $footer; | ||
return $this->content; | ||
} | ||
|
||
/** | ||
* Returns the PDFs and their content (splitted in pages) for all eligable PDFs in the given course. | ||
* | ||
* @param mixed $course course to search in. | ||
* | ||
* @return array array of objects each holding one pdf page on content and some metadata | ||
*/ | ||
function get_pdfs_content_from_course($course): array | ||
{ | ||
if ($course == null) return []; | ||
|
||
$chapters = array(); | ||
|
||
$matches = block_lrf_get_all_book_pdf_matches_from_course($course); | ||
|
||
foreach ($matches as $match) { | ||
$chapters = array_merge($chapters, block_lrf_get_content_as_chapters($match)); | ||
} | ||
|
||
return $chapters; | ||
} | ||
} | ||
<?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/>. | ||
|
||
/** | ||
* Block core and UI | ||
* | ||
* @package block_slidefinder | ||
* @copyright 2022 Universtity of Stuttgart <kasra.habib@iste.uni-stuttgart.de> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once(__DIR__ . '/locallib.php'); | ||
|
||
define('BLOCK_SLIDEFINDER_SLIDEFINDER_PARAM', 'slidefinderid'); | ||
|
||
/** | ||
* The slidefinder block class. | ||
* | ||
* Used to create the slidefinder block. Base of all slidefinder block functionality & UI. | ||
*/ | ||
class block_slidefinder extends block_base { | ||
/** | ||
* Set the initial properties for the block | ||
*/ | ||
public function init() { | ||
$this->title = get_string('pluginname', get_class($this)); | ||
} | ||
|
||
/** | ||
* Describe Block Content. | ||
*/ | ||
public function get_content() { | ||
global $OUTPUT, $DB, $USER; | ||
|
||
if ($this->content !== null) { | ||
return $this->content; | ||
} | ||
|
||
// Params. | ||
$cid = optional_param('id', 0, PARAM_INT); // Do we have a set course id? Or are we on our dashboard (default). | ||
$slidefinderid = optional_param(BLOCK_SLIDEFINDER_SLIDEFINDER_PARAM, 0, PARAM_INT); // Selected course ID. | ||
$search = optional_param('search', '', PARAM_TEXT); // Searched pattern (search hook). | ||
|
||
// Main Content (text) and Footer of the block. | ||
$text = ''; | ||
$footer = ''; | ||
|
||
try { | ||
// Get all current params. | ||
$hiddenparams = $_GET; | ||
|
||
// Filter out BLOCK_SLIDEFINDER_SLIDEFINDER_PARAM as a param we use and change. | ||
$hiddenparams = array_filter($hiddenparams, function ($key) { | ||
return $key !== BLOCK_SLIDEFINDER_SLIDEFINDER_PARAM; | ||
}, ARRAY_FILTER_USE_KEY); | ||
|
||
// Restructure (for mustache) the name=>value list into a list of array objects having the name and value attribute. | ||
$hiddenparams = array_map(function ($name, $value) { | ||
return array("name" => $name, "value" => $value); | ||
}, array_keys($hiddenparams), $hiddenparams); | ||
|
||
if ($cid == 0) { // My Moodle Page. | ||
if ($slidefinderid != 0) { | ||
// Course. | ||
if (!$course = $DB->get_record('course', array('id' => $slidefinderid))) { | ||
throw new moodle_exception(get_string('error_course_not_found', 'block_slidefinder')); | ||
} | ||
// Does the user have access to the course? | ||
if (!can_access_course($course)) { | ||
throw new moodle_exception(get_string('error_course_access_denied', 'block_slidefinder')); | ||
} | ||
} else { | ||
$course = null; | ||
} | ||
$text .= $OUTPUT->render_from_template('block_slidefinder/lrf_drop_down', [ | ||
'action' => $this->page->url, | ||
'course_selector_param_name' => BLOCK_SLIDEFINDER_SLIDEFINDER_PARAM, | ||
'course_selector_options' => block_slidefinder_select_course_options($slidefinderid), | ||
'hidden_params' => $hiddenparams | ||
]); | ||
} else { // Course Page. | ||
// Course. | ||
if (!$course = $DB->get_record('course', array('id' => $cid))) { | ||
throw new moodle_exception(get_string('error_course_not_found', 'block_slidefinder')); | ||
} | ||
// Does the user have access to the course? | ||
if (!can_access_course($course)) { | ||
throw new moodle_exception(get_string('error_course_access_denied', 'block_slidefinder')); | ||
} | ||
} | ||
|
||
$data = [[], []]; | ||
if (!is_null($course)) { | ||
$data = block_slidefinder_get_content_as_chapters_for_all_book_pdf_matches_from_course($course->id, $USER->id); | ||
if (!empty($data[1])) { | ||
$footer .= get_string('misconfigured_info', get_class($this)); | ||
foreach ($data[1] as $key => $value) { | ||
$footer .= '<br>'; | ||
$footer .= $value; | ||
} | ||
} | ||
} | ||
|
||
$text .= $OUTPUT->render_from_template('block_slidefinder/lrf_search', [ | ||
'action' => $this->page->url, | ||
'cid' => $slidefinderid, | ||
'course_selector_param_name' => BLOCK_SLIDEFINDER_SLIDEFINDER_PARAM, | ||
'search_term_param_name' => 'search', | ||
'search_term_placeholder' => get_string('search', get_class($this)), | ||
'search_term_label' => get_string('search_term', get_class($this)), | ||
'search_term' => $search, | ||
'chapter_label' => get_string('chapter', get_class($this)), | ||
'content' => base64_encode(json_encode($data[0])), | ||
'hidden_params' => $hiddenparams | ||
]); | ||
} catch (\Throwable $th) { | ||
debugging($th); | ||
$text .= get_string('error_message', get_class($this)); | ||
$footer .= $th; | ||
} | ||
|
||
$this->content = new stdClass(); | ||
$this->content->text = $text; | ||
$this->content->footer = $footer; | ||
return $this->content; | ||
} | ||
} |
Oops, something went wrong.