Plugin: ExerciseFocused: Add setting to generate random sampling - refs BT#21074

pull/4900/head
Angel Fernando Quiroz Campos 2 years ago committed by Angel Fernando Quiroz Campos
parent f7fb4f3fac
commit 15924bbcb9
No known key found for this signature in database
GPG Key ID: B284841AE3E562CD
  1. 3
      plugin/exercisefocused/lang/english.php
  2. 57
      plugin/exercisefocused/src/Controller/ReportingController.php
  3. 2
      plugin/exercisefocused/src/ExerciseFocusedPlugin.php
  4. 101
      plugin/exercisefocused/src/Traits/ReportingFilterTrait.php

@ -13,6 +13,8 @@ $strings['outfocused_limit'] = "Maximum number of outfocused allowed";
$strings['outfocused_limit_help'] = "Number of outfocused allowed. After this limit the exercise will be closed.";
$strings['session_field_filters'] = "Session field as filter";
$strings['session_field_filters_help'] = "Extra field names separeted by a comma.";
$strings['percentage_sampling'] = "Percentage of sampling attempts";
$strings['percentage_sampling_help'] = "A percentage of attempts will be selected for random review";
$strings['ReportByAttempts'] = "Exercise focused: Report by attempts";
$strings['YouHaveLeftTheExercise'] = "You have left the exercise";
@ -28,3 +30,4 @@ $strings['Outfocused'] = "Outfocused";
$strings['Return'] = "Return";
$strings['Motive'] = "Motive";
$strings['AlertBeforeLeaving'] = "Before leaving the exercise, consider that this action will be tracked.";
$strings['RandomSampling'] = "Random sampling";

@ -19,8 +19,10 @@ class ReportingController extends BaseController
{
parent::__invoke();
$exerciseId = $this->request->query->getInt('id');
$exercise = $this->em->find(CQuiz::class, $exerciseId);
$exercise = $this->em->find(
CQuiz::class,
$this->request->query->getInt('id')
);
if (!$exercise) {
throw new Exception();
@ -29,6 +31,36 @@ class ReportingController extends BaseController
$courseCode = api_get_course_id();
$sessionId = api_get_session_id();
$tab1 = $this->generateTabSearch($exercise, $courseCode, $sessionId);
$tab2 = $this->generateTabSampling($exercise);
$content = Display::tabs(
[
$this->plugin->get_lang('ReportByAttempts'),
$this->plugin->get_lang('RandomSampling'),
],
[$tab1, $tab2],
'exercise-focused-tabs',
[],
[],
1
);
$this->setBreadcrumb($exercise->getId());
return $this->renderView(
get_lang('ReportByAttempts'),
$content,
$exercise->getTitle()
);
}
/**
* @throws Exception
*/
private function generateTabSearch(CQuiz $exercise, string $courseCode, int $sessionId): string
{
$form = $this->createForm();
$form->updateAttributes(['action' => api_get_self().'?'.api_get_cidreq().'&id='.$exercise->getId()]);
$form->addHidden('cidReq', $courseCode);
@ -38,27 +70,24 @@ class ReportingController extends BaseController
$form->addHidden('origin', api_get_origin());
$form->addHidden('id', $exercise->getId());
$results = [];
$tableHtml = '';
if ($form->validate()) {
$formValues = $form->exportValues();
$results = $this->findResults($formValues);
}
$table = $this->createTable($results);
$tableHtml = $this->createTable($results)->toHtml();
}
$this->setBreadcrumb($exercise->getId());
return $form->returnForm().$tableHtml;
}
$content = $form->returnForm()
.Display::page_subheader(get_lang('ReportByAttempts'))
.$table->toHtml();
private function generateTabSampling(CQuiz $exercise): string
{
$results = $this->findRandomResults($exercise->getId());
return $this->renderView(
get_lang('ReportByAttempts'),
$content,
$exercise->getTitle()
);
return $this->createTable($results)->toHtml();
}
/**

@ -14,6 +14,7 @@ class ExerciseFocusedPlugin extends Plugin
public const SETTING_ENABLE_OUTFOCUSED_LIMIT = 'enable_outfocused_limit';
public const SETTING_OUTFOCUSED_LIMIT = 'outfocused_limit';
public const SETTING_SESSION_FIELD_FILTERS = 'session_field_filters';
public const SETTING_PERCENTAGE_SAMPLING = 'percentage_sampling';
public const FIELD_SELECTED = 'exercisefocused_selected';
@ -27,6 +28,7 @@ class ExerciseFocusedPlugin extends Plugin
self::SETTING_ENABLE_OUTFOCUSED_LIMIT => 'boolean',
self::SETTING_OUTFOCUSED_LIMIT => 'text',
self::SETTING_SESSION_FIELD_FILTERS => 'text',
self::SETTING_PERCENTAGE_SAMPLING => 'text',
];
parent::__construct(

@ -8,6 +8,7 @@ use Chamilo\CoreBundle\Entity\TrackEExercises;
use Chamilo\CourseBundle\Entity\CQuiz;
use Chamilo\PluginBundle\ExerciseFocused\Entity\Log;
use Chamilo\UserBundle\Entity\User;
use Database;
use Display;
use Doctrine\ORM\Query\Expr\Join;
use Exception;
@ -61,29 +62,6 @@ trait ReportingFilterTrait
return $form;
}
private function getSessionIdFromFormValues(array $formValues, array $fieldVariableList): array
{
$fieldItemIdList = [];
$objFieldValue = new ExtraFieldValue('session');
foreach ($fieldVariableList as $fieldVariable) {
if (!isset($formValues["extra_$fieldVariable"])) {
continue;
}
$itemValue = $objFieldValue->get_item_id_from_field_variable_and_field_value(
$fieldVariable,
$formValues["extra_$fieldVariable"]
);
if ($itemValue) {
$fieldItemIdList[] = (int) $itemValue['item_id'];
}
}
return array_unique($fieldItemIdList);
}
/**
* @throws Exception
*/
@ -161,10 +139,16 @@ trait ReportingFilterTrait
$qb->setParameters($params);
return $this->formatResults(
$qb->getQuery()->getResult()
);
}
protected function formatResults(array $queryResults): array
{
$results = [];
foreach ($qb->getQuery()->getResult() as $value) {
api_get_local_time();
foreach ($queryResults as $value) {
$results[] = [
'id' => $value['exe']->getExeId(),
'quiz_title' => $value['title'],
@ -239,4 +223,71 @@ trait ReportingFilterTrait
return $table;
}
protected function findRandomResults(int $exerciseId): array
{
$percentage = (int) $this->plugin->get(\ExerciseFocusedPlugin::SETTING_PERCENTAGE_SAMPLING);
if (empty($percentage)) {
return [];
}
$cId = api_get_course_int_id();
$sId = api_get_session_id();
$tblTrackExe = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$sessionCondition = api_get_session_condition($sId);
$result = Database::query(
"SELECT exe_id FROM $tblTrackExe
WHERE c_id = $cId
AND exe_exo_id = $exerciseId
$sessionCondition
ORDER BY RAND() LIMIT $percentage"
);
$exeIdList = array_column(
Database::store_result($result),
'exe_id'
);
$qb = $this->em->createQueryBuilder();
$qb
->select('te AS exe, q.title, te.startDate, u.firstname, u.lastname, u.username')
->from(TrackEExercises::class, 'te')
->innerJoin(CQuiz::class, 'q', Join::WITH, 'te.exeExoId = q.iid')
->innerJoin(User::class, 'u', Join::WITH, 'te.exeUserId = u.id')
->andWhere(
$qb->expr()->in('te.exeId', $exeIdList)
)
->addOrderBy('te.startDate');
return $this->formatResults(
$qb->getQuery()->getResult()
);
}
private function getSessionIdFromFormValues(array $formValues, array $fieldVariableList): array
{
$fieldItemIdList = [];
$objFieldValue = new ExtraFieldValue('session');
foreach ($fieldVariableList as $fieldVariable) {
if (!isset($formValues["extra_$fieldVariable"])) {
continue;
}
$itemValue = $objFieldValue->get_item_id_from_field_variable_and_field_value(
$fieldVariable,
$formValues["extra_$fieldVariable"]
);
if ($itemValue) {
$fieldItemIdList[] = (int) $itemValue['item_id'];
}
}
return array_unique($fieldItemIdList);
}
}

Loading…
Cancel
Save