upgrade
This commit is contained in:
15
plugin/exercise_signature/README.md
Normal file
15
plugin/exercise_signature/README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Exercises signature
|
||||
|
||||
This plugin allows the teacher to check a box in any exercise configuration to request a signature from the user at the end of the exercise attempt.
|
||||
|
||||
A modal window, a bit like a mini-whiteboard, will then appear to students asking them to sign. The signature can be done through the mouse (unpractical), through a touch device (ideal with tablets) or through a touch-sensitive laptop screen.
|
||||
|
||||
Teachers will see the signature when they review the attempt details.
|
||||
|
||||
## Installation
|
||||
|
||||
This plugin creates extra fields for exercises automatically.
|
||||
|
||||
Signatures are saved as a drawing in the database.
|
||||
|
||||
Uninstalling this plugin will remove the extra fields, so all signatures will disappear (instantly) if you uninstall this. Consider using the "disable" option inside the plugin configuration instead.
|
||||
1
plugin/exercise_signature/index.php
Normal file
1
plugin/exercise_signature/index.php
Normal file
@@ -0,0 +1 @@
|
||||
<?php
|
||||
9
plugin/exercise_signature/install.php
Normal file
9
plugin/exercise_signature/install.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
if (!api_is_platform_admin()) {
|
||||
exit('You must have admin permissions to install plugins');
|
||||
}
|
||||
|
||||
ExerciseSignaturePlugin::create()->install();
|
||||
12
plugin/exercise_signature/lang/english.php
Normal file
12
plugin/exercise_signature/lang/english.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
/* License: see /license.txt */
|
||||
|
||||
// Needed in order to show the plugin title
|
||||
$strings['plugin_title'] = "Exercise signature";
|
||||
$strings['plugin_comment'] = "Add the possibility for teachers to ask for a signature at the end of any exam attempt. The signature request is made through a modal window with a whiteboard-style area that works in touch mode, and teachers can later check (manually) the signature attached to the attempt.";
|
||||
$strings['tool_enable'] = 'Tool enabled';
|
||||
$strings['ProvideASignatureFirst'] = 'Please provide a signature first';
|
||||
$strings['Sign'] = 'Sign';
|
||||
$strings['SignatureActivated'] = 'Signature activated';
|
||||
$strings['SignatureMandatory'] = 'Signature mandatory';
|
||||
12
plugin/exercise_signature/lang/french.php
Normal file
12
plugin/exercise_signature/lang/french.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
/* License: see /license.txt */
|
||||
|
||||
// Needed in order to show the plugin title
|
||||
$strings['plugin_title'] = "Exercice signature";
|
||||
$strings['plugin_comment'] = "Ajoute la possibilité pour l'enseignant de demander une signature en fin d'examen. La signature est possible au travers d'une fenêtre modale de type tableau blanc qui fonctionne en mode 'touch'. L'enseignant peut ensuite visualiser la signature associée à chaque tentative.";
|
||||
$strings['tool_enable'] = 'Activer le plugin';
|
||||
$strings['Sign'] = 'Signer';
|
||||
$strings['ProvideASignatureFirst'] = "Veuillez d'abord fournir une signature";
|
||||
$strings['SignatureActivated'] = 'Signature activée';
|
||||
$strings['SignatureMandatory'] = 'Signature obligatoire';
|
||||
11
plugin/exercise_signature/lang/spanish.php
Normal file
11
plugin/exercise_signature/lang/spanish.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
/* License: see /license.txt */
|
||||
|
||||
// Needed in order to show the plugin title
|
||||
$strings['plugin_title'] = "Exercise signature";
|
||||
$strings['plugin_comment'] = "Agrega la posiblidad para los profesores de solicitar una firma al fin de cada intento de examen. La firma se hace a través de una ventana modal tipo pizarra blanca que funciona en modo 'touch'. El profesor puede luego revisar la firma asociada con cada intento.";
|
||||
$strings['tool_enable'] = 'Activar plugin';
|
||||
$strings['Sign'] = 'Firmar';
|
||||
$strings['ProvideASignatureFirst'] = "Primero ingrese una firma";
|
||||
$strings['SignatureActivated'] = 'Firma activada';
|
||||
206
plugin/exercise_signature/lib/ExerciseSignature.php
Normal file
206
plugin/exercise_signature/lib/ExerciseSignature.php
Normal file
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
class ExerciseSignaturePlugin extends Plugin
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'0.1',
|
||||
'Julio Montoya',
|
||||
[
|
||||
'tool_enable' => 'boolean',
|
||||
]
|
||||
);
|
||||
$this->isAdminPlugin = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
static $instance = null;
|
||||
|
||||
return $instance ? $instance : $instance = new self();
|
||||
}
|
||||
|
||||
public static function exerciseHasSignatureActivated(Exercise $exercise)
|
||||
{
|
||||
if (empty($exercise->iid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ('true' === api_get_plugin_setting('exercise_signature', 'tool_enable')) {
|
||||
$extraFieldValue = new ExtraFieldValue('exercise');
|
||||
$result = $extraFieldValue->get_values_by_handler_and_field_variable($exercise->iid, 'signature_activated');
|
||||
if ($result && isset($result['value']) && 1 === (int) $result['value']) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function saveSignature($userId, $trackInfo, $file)
|
||||
{
|
||||
if (false === self::validateSignatureAccess($userId, $trackInfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$signature = self::getSignature($userId, $trackInfo);
|
||||
if (false !== $signature) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($file)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$params = [
|
||||
'item_id' => $trackInfo['exe_id'],
|
||||
'extra_signature' => $file,
|
||||
];
|
||||
$extraFieldValue = new ExtraFieldValue('track_exercise');
|
||||
$extraFieldValue->saveFieldValues(
|
||||
$params,
|
||||
true
|
||||
);
|
||||
|
||||
$signature = self::getSignature($userId, $trackInfo);
|
||||
if (false !== $signature) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function validateSignatureAccess($userId, $trackInfo)
|
||||
{
|
||||
$userId = (int) $userId;
|
||||
if (isset($trackInfo['exe_id']) && isset($trackInfo['exe_user_id']) &&
|
||||
!empty($trackInfo['exe_id']) && !empty($trackInfo['exe_user_id']) &&
|
||||
$trackInfo['status'] !== 'incomplete'
|
||||
) {
|
||||
if ($userId === (int) $trackInfo['exe_user_id']) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getSignature($userId, $trackInfo)
|
||||
{
|
||||
if (false === self::validateSignatureAccess($userId, $trackInfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$extraFieldValue = new ExtraFieldValue('track_exercise');
|
||||
$result = $extraFieldValue->get_values_by_handler_and_field_variable($trackInfo['exe_id'], 'signature');
|
||||
|
||||
if ($result && isset($result['value']) && !empty($result['value'])) {
|
||||
return $result['value'];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plugin Name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return 'exercise_signature';
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates this plugin's related tables in the internal database.
|
||||
* Installs course fields in all courses.
|
||||
*/
|
||||
public function install()
|
||||
{
|
||||
$extraField = new ExtraField('exercise');
|
||||
$extraFieldHandler = $extraField->get_handler_field_info_by_field_variable('signature_activated');
|
||||
$exists = $extraFieldHandler !== false;
|
||||
|
||||
if (!$exists) {
|
||||
$extraField->save(
|
||||
[
|
||||
'field_type' => 13, // checkbox yes/no
|
||||
'variable' => 'signature_activated',
|
||||
'display_text' => get_plugin_lang('SignatureActivated', 'ExerciseSignaturePlugin'),
|
||||
'default_value' => null,
|
||||
'field_order' => null,
|
||||
'visible_to_self' => 1,
|
||||
'changeable' => 1,
|
||||
'filter' => null,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$extraFieldHandler = $extraField->get_handler_field_info_by_field_variable('signature_mandatory');
|
||||
$exists = $extraFieldHandler !== false;
|
||||
|
||||
if (!$exists) {
|
||||
$extraField->save(
|
||||
[
|
||||
'field_type' => 13, // checkbox yes/no
|
||||
'variable' => 'signature_mandatory',
|
||||
'display_text' => get_plugin_lang('SignatureMandatory', 'ExerciseSignaturePlugin'),
|
||||
'default_value' => null,
|
||||
'field_order' => null,
|
||||
'visible_to_self' => 1,
|
||||
'changeable' => 1,
|
||||
'filter' => null,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$extraField = new ExtraField('track_exercise');
|
||||
$extraFieldHandler = $extraField->get_handler_field_info_by_field_variable('signature');
|
||||
$exists = $extraFieldHandler !== false;
|
||||
|
||||
if (!$exists) {
|
||||
$extraField->save(
|
||||
[
|
||||
'field_type' => 2, // textarea
|
||||
'variable' => 'signature',
|
||||
'display_text' => get_plugin_lang('Signature', 'ExerciseSignaturePlugin'),
|
||||
'default_value' => null,
|
||||
'field_order' => null,
|
||||
'visible_to_self' => 1,
|
||||
'changeable' => 1,
|
||||
'filter' => null,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$table = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
|
||||
$sql = "ALTER TABLE $table MODIFY COLUMN value LONGTEXT null;";
|
||||
Database::query($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops this plugins' related tables from the internal database.
|
||||
* Uninstalls course fields in all courses().
|
||||
*/
|
||||
public function uninstall()
|
||||
{
|
||||
$extraField = new ExtraField('track_exercise');
|
||||
$fieldInfo = $extraField->get_handler_field_info_by_field_variable('signature_activated');
|
||||
|
||||
if ($fieldInfo) {
|
||||
$extraField->delete($fieldInfo['id']);
|
||||
}
|
||||
|
||||
$extraField = new ExtraField('exercise');
|
||||
$fieldInfo = $extraField->get_handler_field_info_by_field_variable('signature');
|
||||
if ($fieldInfo) {
|
||||
$extraField->delete($fieldInfo['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
5
plugin/exercise_signature/plugin.php
Normal file
5
plugin/exercise_signature/plugin.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
$plugin_info = ExerciseSignaturePlugin::create()->get_info();
|
||||
9
plugin/exercise_signature/uninstall.php
Normal file
9
plugin/exercise_signature/uninstall.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
if (!api_is_platform_admin()) {
|
||||
exit('You must have admin permissions to uninstall plugins');
|
||||
}
|
||||
|
||||
ExerciseSignaturePlugin::create()->uninstall();
|
||||
Reference in New Issue
Block a user