Skip to content

Commit

Permalink
plug-in renamed to slidefinder
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasra Habib committed Nov 30, 2022
1 parent 763a9b2 commit fe8b2a5
Show file tree
Hide file tree
Showing 15 changed files with 331 additions and 67 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

**English version please see below**

Das Plugin wurde entwickelt, um ein Suchfeld für die Textsuche nach Begriffen in Moodle-Büchern mit bildbasierten Folien bereitzustellen. Es erfordert, dass zu jedem Buch ein durchsuchbares PDF (fast) gleichen Namens bereit gestellt wird, dessen Seiten 1:1 zu den Seiten im Buch passen. Das PDF muss im selben Abschnitt wie das Buch liegen. Die Namen von Buch und PDF müssen identisch sein, ausgenommen ist in Klammern spezifizierter Text innerhalb der Namen.
Das Plugin wurde entwickelt, um ein Suchfeld für die Textsuche nach Begriffen in Moodle-Büchern mit bildbasierten Folien bereitzustellen. Es erfordert, dass zu jedem Buch ein durchsuchbares PDF (fast) gleichen Namens bereit gestellt wird, dessen Seiten 1:1 zu den Seiten im Buch passen. Das PDF muss im selben Abschnitt wie das Buch liegen. Die Namen von Buch und PDF müssen identisch sein, ausgenommen ist in Klammern spezifizierter Text innerhalb der Namen.

Das Plugin sucht in allen PDFs nach den Begriffen und zeigt die Resultate als eine Liste von Links an. Durch Klicken auf den gewünschten Link wird die Seite mit der entsprechenden Seitennummer im Buch angezeigt.
Das Plugin sucht in allen PDFs nach den Begriffen und zeigt die Resultate als eine Liste von Links an. Durch Klicken auf den gewünschten Link wird die Seite mit der entsprechenden Seitennummer im Buch angezeigt.

Die Suchfunktion steht zur Verfügung, wenn man einen entsprechenden Block konfiguriert (s.u.). Alternativ kann sie über einen Webservice erreicht werden. Die Konfiguration des Web Service ist ebenfalls unten beschrieben.
Die Suchfunktion steht zur Verfügung, wenn man einen entsprechenden Block konfiguriert (s.u.). Alternativ kann sie über einen Webservice erreicht werden. Die Konfiguration des Web Service ist ebenfalls unten beschrieben.

## English description

The plugin was developed to provide a search field for text search in Moodle books with image-based slides. The plugin requires that a PDF of (almost) the same name is present in the same course section. The pages of the PDF need to correspond 1-1 to the pages in the book. Names of book and PDF need to be identical, except for text specified in brackets inside their names.
The plugin searches all PDFs for the text and then displays the search results as a list of links. Clicking on a link shows the respective page with the corresponding number inside the book.
The plugin was developed to provide a search field for text search in Moodle books with image-based slides. The plugin requires that a PDF of (almost) the same name is present in the same course section. The pages of the PDF need to correspond 1-1 to the pages in the book. Names of book and PDF need to be identical, except for text specified in brackets inside their names.

The plugin searches all PDFs for the text and then displays the search results as a list of links. Clicking on a link shows the respective page with the corresponding number inside the book.


# Usage and API configuration

Expand All @@ -40,13 +40,13 @@ This involves the following steps:
2. Enable protocols: Her, enable the REST protocol if not already enabled.
3. Create a specified user
4. Check user capability: The specified user has to have at least the __webservice/rest:use__ capability.
5. Select a service: Add the "Lecture Reference Finder" to custom services.
6. Add functions: Add the "block_lecture_reference_finder_get_searched_locations" function to the "Lecture Reference Finder" service.
5. Select a service: Add the "Slide Finder" to custom services.
6. Add functions: Add the "block_slidefinder_get_searched_locations" function to the "Slide Finder" service.
7. Select a specified user: Add the web services user as an authorised user.
8. Create a token for a user: Create a token for the web services user.

Test it by sending an http GET request to
'http://[yourmoodle]/webservice/rest/server.php?wstoken=[user-token]&wsfunction=block_lecture_reference_finder_get_searched_locations&moodlewsrestformat=json&search_string=[search_string]&course_id=[course_id]&context_length=[context_length]'
'http://[yourmoodle]/webservice/rest/server.php?wstoken=[user-token]&wsfunction=block_slidefinder_get_searched_locations&moodlewsrestformat=json&search_string=[search_string]&course_id=[course_id]&context_length=[context_length]'
where
- yourmoodle: domain of your moodle installation (as developer: probably localhost)
- user-token: token received from moodle for a user which is allowed to use the web service
Expand Down Expand Up @@ -80,7 +80,7 @@ Alternatively, you can run
to complete the installation from the command line.

## Third-party APIs ##
Slide Finder plug-in relies on [pdfparser](https://github.com/smalot/pdfparser) package to extract data from PDF files. Pdfparser is a standalone PHP package under LGPLv3 license (see above: [thirdpartylibs.xml](https://github.com/SE-Stuttgart/kib3_moodleplugin_slidefinder/blob/main/thirdpartylibs.xml) for more details).
Slide Finder plug-in relies on [pdfparser](https://github.com/smalot/pdfparser) package to extract data from PDF files. Pdfparser is a standalone PHP package under LGPLv3 license (see above: [thirdpartylibs.xml](https://github.com/SE-Stuttgart/kib3_moodleplugin_slidefinder/blob/main/thirdpartylibs.xml) for more details).

## License ##

Expand Down
12 changes: 6 additions & 6 deletions block_lecture_reference_finder.php → block_slidefinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Block core and UI
*
* @package block_lecture_reference_finder
* @package block_slidefinder
* @copyright University of Stuttgart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand All @@ -26,7 +26,7 @@
require_once(__DIR__ . '/../../config.php');
require_once(__DIR__ . '/locallib.php');

class block_lecture_reference_finder extends block_base
class block_slidefinder extends block_base
{
/**
* Set the initial properties for the block
Expand Down Expand Up @@ -78,14 +78,14 @@ public function get_content()


if ($view_course_selection) {
$text .= $renderer->render_from_template('block_lecture_reference_finder/lrf_drop_down', [
$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_lecture_reference_finder/lrf_search', [
$text .= $renderer->render_from_template('block_slidefinder/lrf_search', [
'action' => $PAGE->url,
'cid' => $cid,
'lrf_cid' => $lrf_cid,
Expand All @@ -107,9 +107,9 @@ public function get_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
Expand Down
6 changes: 3 additions & 3 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
/**
* Capability definitions for this module.
*
* @package block_lecture_reference_finder
* @package block_slidefinder
* @copyright University of Stuttgart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();

$capabilities = array(

'block/lecture_reference_finder:myaddinstance' => array(
'block/slidefinder:myaddinstance' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
Expand All @@ -34,7 +34,7 @@
'clonepermissionsfrom' => 'moodle/my:manageblocks'
),

'block/lecture_reference_finder:addinstance' => array(
'block/slidefinder:addinstance' => array(
//'riskbitmask' => RISK_PERSONAL,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
Expand Down
10 changes: 5 additions & 5 deletions db/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@
/**
* Describes WebServices
*
* @package block_lecture_reference_finder
* @package block_slidefinder
* @copyright University of Stuttgart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();

$functions = array(
// local_PLUGINNAME_FUNCTIONNAME is the name of the web service function that the client will call.
'block_lecture_reference_finder_get_searched_locations' => array(
'block_slidefinder_get_searched_locations' => array(

//class containing the external function
'classname' => 'block_lecture_reference_finder_external',
'classname' => 'block_slidefinder_external',

//external function name
'methodname' => 'get_searched_locations',

//file containing the class/external function - not required if using namespaced auto-loading classes.
// defaults to the service's externalib.php
'classpath' => 'block/lecture_reference_finder/externallib.php',
'classpath' => 'blocks/slidefinder/externallib.php',

// This documentation will be displayed in the generated API documentation
// This documentation will be displayed in the generated API documentation
// (Administration > Plugins > Webservices > API documentation)
'description' => 'This is a web service for the chatbot from the University of Stuttgart.',

Expand Down
24 changes: 12 additions & 12 deletions externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
/**
* Function for the WebService
*
* @package block_lecture_reference_finder
* @package block_slidefinder
* @copyright University of Stuttgart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();

require_once("$CFG->libdir/externallib.php");

class block_lecture_reference_finder_external extends external_api
class block_slidefinder_external extends external_api
{
/**
* Returns description of method parameter
Expand Down Expand Up @@ -55,11 +55,11 @@ public static function get_searched_locations_parameters()

/**
* Get all occurences, their context and a link to the chapter of $search_string in the eligable $PDF-Book lectures in the given course.
*
*
* @param string $search_string the string to search for
* @param int $course_id id of the course to search in
* @param int $context_length the size of the context snippet on each side of the found @param $seach_string occurences in words
*
*
* @return string json encoded array of arrays holding the 'filename', 'page_number', 'book_chapter_url' and 'context' of each chapter/pdf-page the $search_term was found
* @return string return '' the $course_id was incorrect
*/
Expand Down Expand Up @@ -123,11 +123,11 @@ public static function get_searched_locations_returns()

/**
* Searches for the $search_term in the given $page->content and returns the page with a $page->context context snippet if it was found. returns null if not.
*
*
* @param stdClass $page object that holds the $page->content and gets returned containing the $page->context
* @param string $search_term the string to seach for in the $page->content
* @param int $context_length word count returned as context snippet on each side of the found $search_term
*
*
* @return stdClass|null the given @param $page object with the additional $page->context or null if nothing was found
*/
private static function lrf_search_content($page, $search_term, $context_length)
Expand Down Expand Up @@ -177,11 +177,11 @@ private static function lrf_search_content($page, $search_term, $context_length)

/**
* Alternate function to PHPs substr() to put it more in line with the javascript equivalent. Returns the substring of a given string with start and end index given.
*
*
* @param string $string source string to extract from
* @param int $start the starting index for the extraction
* @param int $end the ending index for the extraction
*
*
* @return string the extracted substring
*/
private static function substring($string, $start, $end)
Expand All @@ -198,11 +198,11 @@ private static function substring($string, $start, $end)

/**
* Alternate function to PHPs stripos() to put it more in line with the javascript equivalent. Left to right search returning the index of the first occurence of the needle in the given haystack starting at index offset.
*
*
* @param string $haystack string to search in
* @param string $needle string to search for
* @param int $offset starting index of right-wards search
*
*
* @return int index of the first occurence found or -1 if nothing was found
*/
private static function indexOf($haystack, $needle, $offset)
Expand All @@ -217,11 +217,11 @@ private static function indexOf($haystack, $needle, $offset)

/**
* Alternate function to PHPs strripos() to put it more in line with the javascript equivalent. Right to left search returning the index of the first occurence of the needle in the given haystack starting at index offset.
*
*
* @param string $haystack string to search in
* @param string $needle string to search for
* @param int $offset starting index of left-wards search
*
*
* @return int index of the first occurence found or -1 if nothing was found
*/
private static function lastIndexOf($haystack, $needle, $offset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
/**
* Language settings german.
*
* @package block_lecture_reference_finder
* @package block_slidefinder
* @copyright University of Stuttgart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();


// Config
$string['pluginname'] = 'Lecture Reference Finder';
$string['pluginname'] = 'Foliensuche';

// Block
$string['search_term'] = 'Gesucht: ';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

/**
* Language settings english.
*
*
* @package block_lecture_reference_finder
* @copyright University of Stuttgart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Expand All @@ -25,7 +25,7 @@


// Config
$string['pluginname'] = 'Lecture Reference Finder';
$string['pluginname'] = 'Slide Finder';

// Block
$string['search_term'] = 'Search Term: ';
Expand Down
22 changes: 11 additions & 11 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Helper functions for the block_lecture_reference_finder Plugin
* Helper functions for the block_slidefinder Plugin
*
* @package block_lecture_reference_finder
* @package block_slidefinder
* @copyright University of Stuttgart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand All @@ -27,9 +27,9 @@

/**
* Return a list of all eligable book-pdf matches in a given course.
*
*
* @param mixed $course course to search in
*
*
* @return array list of matches as objects containing pdf file information and book_id
*/
function block_lrf_get_all_book_pdf_matches_from_course($course)
Expand All @@ -56,15 +56,15 @@ function block_lrf_get_all_book_pdf_matches_from_course($course)
$r->pathnamehash = $file->get_pathnamehash();
$r->filename = $file->get_filename();
$r->section = $resource->section;
$r->resourcename = preg_replace('/\s*\[[^]]*\](?![^[]*\[)/', '', preg_replace('/\s*\([^)]*\)(?![^(]*\()/', '', $resource->name));
$r->resourcename = trim(preg_replace('/\s*\[[^]]*\](?![^[]*\[)/', '', preg_replace('/\s*\([^)]*\)(?![^(]*\()/', '', $resource->name)));
$pdfs[] = $r;
}

// Get all books from course
$sectioned_books = array();
$books = get_all_instances_in_course('book', $course);
foreach ($books as $book) {
$sectioned_books[$book->section][$book->id] = preg_replace('/\s*\[[^]]*\](?![^[]*\[)/', '', preg_replace('/\s*\([^)]*\)(?![^(]*\()/', '', $book->name));
$sectioned_books[$book->section][$book->id] = trim(preg_replace('/\s*\[[^]]*\](?![^[]*\[)/', '', preg_replace('/\s*\([^)]*\)(?![^(]*\()/', '', $book->name)));
}

// Get all book-PDF matches
Expand All @@ -80,9 +80,9 @@ function block_lrf_get_all_book_pdf_matches_from_course($course)

/**
* Return an array of objects each containing the content and some metadata of one PDF page of a given pdf-book match.
*
*
* @param mixed $match an object containing metadata of one pdf-book match.
*
*
* @return array list of objects containing the content and some metadata of one PDF page.
*/
function block_lrf_get_content_as_chapters($match)
Expand Down Expand Up @@ -117,10 +117,10 @@ function block_lrf_get_content_as_chapters($match)

/**
* Create and return an url linking to a specific book chapter.
*
*
* @param int $book_id id of the book
* @param int $pagenum chapter number / pdf page num
*
*
* @return string url linking to the book chapter
*/
function block_lrf_get_book_chapter_url($book_id, $pagenum)
Expand Down Expand Up @@ -181,7 +181,7 @@ function block_lrf_select_course_options(int $selected_course_id, int $user_id)
$courses_html[0] = (object)['id' => $selected_course_id, 'value' => $courses_shown[$selected_course_id]];
unset($courses_shown[$selected_course_id]);
} else {
$courses_html[0] = (object)['id' => 0, 'value' => get_string('select_course', 'block_lecture_reference_finder')];
$courses_html[0] = (object)['id' => 0, 'value' => get_string('select_course', 'block_slidefinder')];
}

foreach ($courses_shown as $key => $value) {
Expand Down
37 changes: 37 additions & 0 deletions pdfparser/.github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "CS"

on:
pull_request:
push:
branches:
- master

jobs:
coding-standards:
name: "CS Fixer & PHPStan"
runs-on: ubuntu-20.04
steps:
-
name: Checkout
uses: actions/checkout@v2
-
env:
COMPOSER_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
name: "Install PHP"
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: "7.4"
tools: "composer:v2"
-
name: Install dependencies with Composer
uses: ramsey/composer-install@v1
-
name: Install dev tools
run: make install-dev-tools
-
name: Run PHP CS Fixer
run: 'make run-php-cs-fixer ARGS="--verbose --dry-run"'
-
name: Run PHPStan
run: 'make run-phpstan ARGS="--no-progress"'
Loading

0 comments on commit fe8b2a5

Please sign in to comment.