forked from chamilo/chamilo-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'BT20901' into proctoring-dev
- Loading branch information
Showing
14 changed files
with
824 additions
and
0 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,4 @@ | ||
<?php | ||
|
||
/* For licensing terms, see /license.txt */ | ||
|
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,43 @@ | ||
<?php | ||
|
||
/* For licensing terms, see /license.txt */ | ||
|
||
$plugin = ExerciseMonitoringPlugin::create(); | ||
|
||
$_template['show_overview_region'] = $plugin->isEnabled(true) | ||
&& strpos($_SERVER['SCRIPT_NAME'], '/main/exercise/overview.php') !== false; | ||
|
||
$_template['enabled'] = false; | ||
|
||
if ($_template['show_overview_region']) { | ||
$exerciseId = (int) $_GET['exerciseId']; | ||
|
||
$objFieldValue = new ExtraFieldValue('exercise'); | ||
$values = $objFieldValue->get_values_by_handler_and_field_variable($exerciseId, ExerciseMonitoringPlugin::FIELD_SELECTED); | ||
|
||
if ($values && (bool) $values['value']) { | ||
$_template['enabled'] = true; | ||
|
||
$existingExeId = (int) ChamiloSession::read('exe_id'); | ||
} | ||
|
||
$_template['exercise_id'] = $exerciseId; | ||
} | ||
|
||
$_template['show_submit_region'] = $plugin->isEnabled(true) | ||
&& strpos($_SERVER['SCRIPT_NAME'], '/main/exercise/exercise_submit.php') !== false; | ||
|
||
if ($_template['show_submit_region']) { | ||
$exerciseId = (int) $_GET['exerciseId']; | ||
|
||
$objFieldValue = new ExtraFieldValue('exercise'); | ||
$values = $objFieldValue->get_values_by_handler_and_field_variable($exerciseId, ExerciseMonitoringPlugin::FIELD_SELECTED); | ||
|
||
if ($values && (bool) $values['value']) { | ||
$existingExeId = (int) ChamiloSession::read('exe_id'); | ||
|
||
$_template['enabled'] = true; | ||
$_template['exercise_id'] = $exerciseId; | ||
$_template['exe_id'] = $existingExeId; | ||
} | ||
} |
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,5 @@ | ||
<?php | ||
|
||
/* For licensing terms, see /license.txt */ | ||
|
||
ExerciseMonitoringPlugin::create()->install(); |
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,13 @@ | ||
<?php | ||
|
||
/* For licensing terms, see /license.txt */ | ||
|
||
$strings['plugin_title'] = "Exercise monitoring"; | ||
$strings['plugin_comment'] = "Random photo taking mechanism during an exercise"; | ||
|
||
$strings['tool_enable'] = "Enable tool"; | ||
|
||
$strings['ExerciseMonitored'] = "Exercise monitored"; | ||
$strings['Retry'] = "Retry"; | ||
$strings['IdDocumentSnapshot'] = "Snapshot of the ID document"; | ||
$strings['LearnerSnapshot'] = "Snapshot of the student"; |
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,18 @@ | ||
<?php | ||
|
||
/* For license terms, see /license.txt */ | ||
|
||
use Symfony\Component\HttpFoundation\Request as HttpRequest; | ||
|
||
require_once __DIR__.'/../../../main/inc/global.inc.php'; | ||
|
||
api_protect_course_script(); | ||
|
||
$plugin = ExerciseMonitoringPlugin::create(); | ||
$request = HttpRequest::createFromGlobals(); | ||
$em = Database::getManager(); | ||
|
||
$exerciseSubmitController = new ExerciseSubmitController($plugin, $request, $em); | ||
|
||
$response = $exerciseSubmitController(); | ||
$response->send(); |
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,18 @@ | ||
<?php | ||
|
||
/* For license terms, see /license.txt */ | ||
|
||
use Symfony\Component\HttpFoundation\Request as HttpRequest; | ||
|
||
require_once __DIR__.'/../../../main/inc/global.inc.php'; | ||
|
||
api_protect_course_script(); | ||
|
||
$plugin = ExerciseMonitoringPlugin::create(); | ||
$request = HttpRequest::createFromGlobals(); | ||
$em = Database::getManager(); | ||
|
||
$startController = new StartController($plugin, $request, $em); | ||
|
||
$response = $startController(); | ||
$response->send(); |
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,10 @@ | ||
<?php | ||
|
||
/* For licensing terms, see /license.txt */ | ||
|
||
$plugin_info = ExerciseMonitoringPlugin::create()->get_info(); | ||
|
||
$plugin_info['templates'] = [ | ||
'templates/modal.html.twig', | ||
'templates/exercise_submit.html.twig', | ||
]; |
86 changes: 86 additions & 0 deletions
86
plugin/exercisemonitoring/src/Controller/ExerciseSubmitController.php
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,86 @@ | ||
<?php | ||
|
||
/* For license terms, see /license.txt */ | ||
|
||
use Chamilo\CoreBundle\Entity\TrackEExercises; | ||
use Chamilo\CourseBundle\Entity\CQuiz; | ||
use Chamilo\CourseBundle\Entity\CQuizQuestion; | ||
use Chamilo\PluginBundle\ExerciseMonitoring\Entity\Log; | ||
use Doctrine\ORM\EntityManager; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
use Symfony\Component\HttpFoundation\Request as HttpRequest; | ||
use Symfony\Component\HttpFoundation\Response as HttpResponse; | ||
|
||
class ExerciseSubmitController | ||
{ | ||
private $plugin; | ||
private $request; | ||
private $em; | ||
|
||
public function __construct(ExerciseMonitoringPlugin $plugin, HttpRequest $request, EntityManager $em) | ||
{ | ||
$this->plugin = $plugin; | ||
$this->request = $request; | ||
$this->em = $em; | ||
} | ||
|
||
/** | ||
* @throws \Doctrine\ORM\OptimisticLockException | ||
* @throws \Doctrine\ORM\ORMException | ||
* @throws \Doctrine\ORM\TransactionRequiredException | ||
*/ | ||
public function __invoke(): HttpResponse | ||
{ | ||
$userDirName = $this->createDirectory(); | ||
|
||
$existingExeId = (int) ChamiloSession::read('exe_id'); | ||
$imgIddoc = $this->request->files->get('snapshot'); | ||
|
||
$exercise = $this->em->find( | ||
CQuiz::class, | ||
$this->request->request->getInt('exercise_id') | ||
); | ||
$question = $this->em->find( | ||
CQuizQuestion::class, | ||
$this->request->request->getInt('question_id') | ||
); | ||
$trackingExercise = $this->em->find(TrackEExercises::class, $existingExeId); | ||
|
||
if ($imgIddoc) { | ||
$newFilename = uniqid().'_exercise.jpg'; | ||
|
||
$imgIddoc->move($userDirName, $newFilename); | ||
|
||
$log = new Log(); | ||
$log | ||
->setExercise($exercise) | ||
->setExe($trackingExercise) | ||
->setLevel($question->getIid()) | ||
->setImageFilename($newFilename) | ||
; | ||
|
||
$this->em->persist($log); | ||
} | ||
|
||
$this->em->flush(); | ||
|
||
return HttpResponse::create(); | ||
} | ||
|
||
private function createDirectory(): string | ||
{ | ||
$user = api_get_user_entity(api_get_user_id()); | ||
|
||
$pluginDirName = api_get_path(SYS_UPLOAD_PATH).'plugins/exercisemonitoring'; | ||
$userDirName = $pluginDirName.'/'.$user->getId(); | ||
|
||
$fs = new Filesystem(); | ||
$fs->mkdir( | ||
[$pluginDirName, $userDirName], | ||
api_get_permissions_for_new_directories() | ||
); | ||
|
||
return $userDirName; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
plugin/exercisemonitoring/src/Controller/StartController.php
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,87 @@ | ||
<?php | ||
|
||
/* For license terms, see /license.txt */ | ||
|
||
use Chamilo\CourseBundle\Entity\CQuiz; | ||
use Chamilo\PluginBundle\ExerciseMonitoring\Entity\Log; | ||
use Doctrine\ORM\EntityManager; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
use Symfony\Component\HttpFoundation\Request as HttpRequest; | ||
use Symfony\Component\HttpFoundation\Response as HttpResponse; | ||
|
||
class StartController | ||
{ | ||
private $plugin; | ||
private $request; | ||
private $em; | ||
|
||
public function __construct(ExerciseMonitoringPlugin $plugin, HttpRequest $request, EntityManager $em) | ||
{ | ||
$this->plugin = $plugin; | ||
$this->request = $request; | ||
$this->em = $em; | ||
} | ||
|
||
public function __invoke(): HttpResponse | ||
{ | ||
$userDirName = $this->createDirectory(); | ||
|
||
/** @var UploadedFile $imgIddoc */ | ||
$imgIddoc = $this->request->files->get('iddoc'); | ||
/** @var UploadedFile $imgLearner */ | ||
$imgLearner = $this->request->files->get('learner'); | ||
|
||
$exercise = $this->em->find(CQuiz::class, $this->request->request->getInt('exercise_id')); | ||
|
||
if ($imgIddoc) { | ||
$newFilename = uniqid().'_iddoc.jpg'; | ||
|
||
$imgIddoc->move($userDirName, $newFilename); | ||
|
||
$log = new Log(); | ||
$log | ||
->setExercise($exercise) | ||
->setLevel(-1) | ||
->setImageFilename($newFilename) | ||
; | ||
|
||
$this->em->persist($log); | ||
} | ||
|
||
if ($imgLearner) { | ||
$newFilename = uniqid().'_learner.jpg'; | ||
|
||
$imgLearner->move($userDirName, $newFilename); | ||
|
||
$log = new Log(); | ||
$log | ||
->setExercise($exercise) | ||
->setLevel(0) | ||
->setImageFilename($newFilename) | ||
; | ||
|
||
$this->em->persist($log); | ||
} | ||
|
||
$this->em->flush(); | ||
|
||
return HttpResponse::create(); | ||
} | ||
|
||
private function createDirectory(): string | ||
{ | ||
$user = api_get_user_entity(api_get_user_id()); | ||
|
||
$pluginDirName = api_get_path(SYS_UPLOAD_PATH).'plugins/exercisemonitoring'; | ||
$userDirName = $pluginDirName.'/'.$user->getId(); | ||
|
||
$fs = new Filesystem(); | ||
$fs->mkdir( | ||
[$pluginDirName, $userDirName], | ||
api_get_permissions_for_new_directories() | ||
); | ||
|
||
return $userDirName; | ||
} | ||
} |
Oops, something went wrong.