Plugins: Add positioning plugin see #3644
	
		
	
				
					
				
			
							parent
							
								
									b1be4b9bb0
								
							
						
					
					
						commit
						9dff93545c
					
				@ -0,0 +1,10 @@ | 
				
			||||
Positioning | 
				
			||||
=== | 
				
			||||
 | 
				
			||||
This plugin adds a positioning test tool in every course. | 
				
			||||
Positioning tests should be used before and after any course. One initial test should be taken before anything else is used in the course, and a final test (usually a copy of the same test) should be used at the end. A radar-chart will show the differences between the initial test and the final test for each learner. | 
				
			||||
 | 
				
			||||
For a test to be used as initial or final test, it has to match 3 criteria: | 
				
			||||
 - use at least 3 question categories | 
				
			||||
 - use the "radar" type result page | 
				
			||||
 - have only one available attempt | 
				
			||||
@ -0,0 +1 @@ | 
				
			||||
<?php | 
				
			||||
@ -0,0 +1,7 @@ | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
/* For license terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
require_once __DIR__.'/../../main/inc/global.inc.php'; | 
				
			||||
 | 
				
			||||
Positioning::create()->install(); | 
				
			||||
@ -0,0 +1,22 @@ | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
$strings['plugin_title'] = 'Positioning'; | 
				
			||||
$strings['plugin_comment'] = 'Adds positioning tests to the course homepage'; | 
				
			||||
$strings['tool_enable'] = 'Enable plugin'; | 
				
			||||
 | 
				
			||||
$strings['block_course_if_initial_exercise_not_attempted'] = 'Block other course tools'; | 
				
			||||
$strings['block_course_if_initial_exercise_not_attempted_help'] = 'When this option is enabled, if an initial positioning test has been configured, the learner will not be able to use the rest of the course on the course homepage until he/she has completed the initial test.'; | 
				
			||||
 | 
				
			||||
$strings['average_percentage_to_unlock_final_exercise'] = 'End test unlock threshold'; | 
				
			||||
$strings['average_percentage_to_unlock_final_exercise_help'] = 'Learners *must* have an average progress of at least this percentage (e.g. \'75\' for a 75% progress required) in the combined learning paths of this course.'; | 
				
			||||
 | 
				
			||||
$strings['PositioningIntroduction'] = 'Please select one initial test and one final test below. Only tests that match the 3 following criteria will be available for selection: use at least 3 question categories, use the radar report mode *and* have only one possible attempt allowed. Once these are selected, the student will only be able to pass the final test if he/she has completed the average of all learning paths in this course to %S or more.'; | 
				
			||||
$strings['SelectAsInitialTest'] = 'Select as initial test'; | 
				
			||||
$strings['UnselectAsInitialTest'] = 'Unselect as initial test'; | 
				
			||||
$strings['SelectAsFinalTest'] = 'Select as final test'; | 
				
			||||
$strings['UnselectAsFinalTest'] = 'Unselect as final test'; | 
				
			||||
$strings['InviteToTakePositioningTest'] = 'Please take this positioning test before you start. This will help us measure the quality of this course.'; | 
				
			||||
$strings['InitialTest'] = 'Initial test'; | 
				
			||||
$strings['YouMustCompleteAThresholdToTakeFinalTest'] = 'You must complete at least %s of progress on average for all learning paths to unlock the final test.'; | 
				
			||||
$strings['FinalTest'] = 'Final test'; | 
				
			||||
$strings['Positioning'] = 'Positioning'; | 
				
			||||
@ -0,0 +1,5 @@ | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
$strings['plugin_title'] = 'Positionnement'; | 
				
			||||
$strings['plugin_comment'] = ''; | 
				
			||||
$strings['tool_enable'] = 'Activer le plugin'; | 
				
			||||
@ -0,0 +1,5 @@ | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
$strings['plugin_title'] = 'Posicionamiento'; | 
				
			||||
$strings['plugin_comment'] = ''; | 
				
			||||
$strings['tool_enable'] = 'Activar plugin'; | 
				
			||||
@ -0,0 +1,7 @@ | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
require_once __DIR__.'/../../main/inc/global.inc.php'; | 
				
			||||
 | 
				
			||||
$plugin_info = Positioning::create()->get_info(); | 
				
			||||
@ -0,0 +1,232 @@ | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
class Positioning extends Plugin | 
				
			||||
{ | 
				
			||||
    public $isCoursePlugin = true; | 
				
			||||
    public $table; | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * Class constructor. | 
				
			||||
     */ | 
				
			||||
    protected function __construct() | 
				
			||||
    { | 
				
			||||
        parent::__construct( | 
				
			||||
            '1.0', | 
				
			||||
            'Julio Montoya', | 
				
			||||
            [ | 
				
			||||
                'tool_enable' => 'boolean', | 
				
			||||
                'block_course_if_initial_exercise_not_attempted' => 'boolean', | 
				
			||||
                'average_percentage_to_unlock_final_exercise' => 'text', | 
				
			||||
            ] | 
				
			||||
        ); | 
				
			||||
 | 
				
			||||
        $this->table = Database::get_main_table('plugin_positioning_exercise'); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public static function create() | 
				
			||||
    { | 
				
			||||
        static $result = null; | 
				
			||||
 | 
				
			||||
        return $result ? $result : $result = new self(); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public function install() | 
				
			||||
    { | 
				
			||||
        $table = $this->table; | 
				
			||||
 | 
				
			||||
        $sql = 'CREATE TABLE IF NOT EXISTS '.$table.' ( | 
				
			||||
                id INT unsigned NOT NULL auto_increment PRIMARY KEY, | 
				
			||||
                exercise_id INT unsigned NOT NULL, | 
				
			||||
                c_id INT unsigned NOT NULL, | 
				
			||||
                session_id INT unsigned DEFAULT NULL, | 
				
			||||
                is_initial TINYINT(1) NOT NULL, | 
				
			||||
                is_final TINYINT(1) NOT NULL | 
				
			||||
                )'; | 
				
			||||
        Database::query($sql); | 
				
			||||
 | 
				
			||||
        // Installing course settings | 
				
			||||
        $this->install_course_fields_in_all_courses(); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public function uninstall() | 
				
			||||
    { | 
				
			||||
        $table = $this->table; | 
				
			||||
        Database::query("DROP TABLE IF EXISTS $table"); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public function isInitialExercise($exerciseId, $courseId, $sessionId) | 
				
			||||
    { | 
				
			||||
        $data = $this->getPositionData($exerciseId, $courseId, $sessionId); | 
				
			||||
        if ($data && isset($data['is_initial']) && 1 === (int) $data['is_initial']) { | 
				
			||||
            return true; | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        return false; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public function getPositionData($exerciseId, $courseId, $sessionId) | 
				
			||||
    { | 
				
			||||
        $table = $this->table; | 
				
			||||
        $courseId = (int) $courseId; | 
				
			||||
        $sessionId = (int) $sessionId; | 
				
			||||
 | 
				
			||||
        $sql = "SELECT * FROM $table | 
				
			||||
                WHERE | 
				
			||||
                    exercise_id = $exerciseId AND | 
				
			||||
                    c_id = $courseId AND | 
				
			||||
                    session_id = $sessionId | 
				
			||||
                    "; | 
				
			||||
        $result = Database::query($sql); | 
				
			||||
 | 
				
			||||
        if (Database::num_rows($result) > 0) { | 
				
			||||
 | 
				
			||||
            return Database::fetch_array($result, 'ASSOC'); | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        return false; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public function isFinalExercise($exerciseId, $courseId, $sessionId) | 
				
			||||
    { | 
				
			||||
        $data = $this->getPositionData($exerciseId, $courseId, $sessionId); | 
				
			||||
        if ($data && isset($data['is_final']) && 1 === (int) $data['is_final']) { | 
				
			||||
            return true; | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public function setInitialExercise($exerciseId, $courseId, $sessionId) | 
				
			||||
    { | 
				
			||||
        $this->setOption('is_initial', $exerciseId, $courseId, $sessionId); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    private function setOption($field, $exerciseId, $courseId, $sessionId) | 
				
			||||
    { | 
				
			||||
        if (!in_array($field, ['is_initial', 'is_final'], true)) { | 
				
			||||
            return false; | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        $data = $this->getPositionData($exerciseId, $courseId, $sessionId); | 
				
			||||
        $disableField = $field === 'is_initial' ? 'is_final' : 'is_initial'; | 
				
			||||
        if ($data && isset($data['id'])) { | 
				
			||||
            $id = $data['id']; | 
				
			||||
            $sql = "UPDATE $this->table SET | 
				
			||||
                    $field = 1, | 
				
			||||
                    $disableField = 0 | 
				
			||||
                    WHERE id = $id"; | 
				
			||||
            Database::query($sql); | 
				
			||||
 | 
				
			||||
            $sql = "DELETE FROM $this->table | 
				
			||||
                    WHERE $field = 1 AND c_id = $courseId AND session_id = $sessionId AND id <> $id"; | 
				
			||||
            Database::query($sql); | 
				
			||||
 | 
				
			||||
        } else { | 
				
			||||
            $params = [ | 
				
			||||
                'exercise_id' => $exerciseId, | 
				
			||||
                'c_id' => $courseId, | 
				
			||||
                'session_id' => $sessionId, | 
				
			||||
                $field => 1, | 
				
			||||
                $disableField => 0, | 
				
			||||
            ]; | 
				
			||||
            $id = Database::insert($this->table, $params); | 
				
			||||
 | 
				
			||||
            $sql = "DELETE FROM $this->table | 
				
			||||
                    WHERE $field = 1 AND c_id = $courseId AND session_id = $sessionId AND id <> $id"; | 
				
			||||
            Database::query($sql); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public function setFinalExercise($exerciseId, $courseId, $sessionId) | 
				
			||||
    { | 
				
			||||
        $this->setOption('is_final', $exerciseId, $courseId, $sessionId); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public function blockFinalExercise($userId, $exerciseId, $courseId, $sessionId) | 
				
			||||
    { | 
				
			||||
        $initialData = $this->getInitialExercise($courseId, $sessionId); | 
				
			||||
 | 
				
			||||
        if (empty($initialData)) { | 
				
			||||
            return false; | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        if ($initialData && isset($initialData['exercise_id'])) { | 
				
			||||
            // If this is final exercise? | 
				
			||||
            $finalData = $this->getFinalExercise($courseId, $sessionId); | 
				
			||||
            if (!empty($finalData) && $finalData['exercise_id'] && $exerciseId == $finalData['exercise_id']) { | 
				
			||||
                $initialResults = Event::getExerciseResultsByUser( | 
				
			||||
                    $userId, | 
				
			||||
                    $initialData['exercise_id'], | 
				
			||||
                    $courseId, | 
				
			||||
                    $sessionId | 
				
			||||
                ); | 
				
			||||
 | 
				
			||||
                if (empty($initialResults)) { | 
				
			||||
                    return true; | 
				
			||||
                } | 
				
			||||
 | 
				
			||||
                $averageToUnlock = (int) $this->get('average_percentage_to_unlock_final_exercise'); | 
				
			||||
                if (empty($averageToUnlock)) { | 
				
			||||
                    return false; | 
				
			||||
                } | 
				
			||||
 | 
				
			||||
                // Check average | 
				
			||||
                $courseInfo = api_get_course_info_by_id($courseId); | 
				
			||||
                $userAverage = (int) Tracking::getAverageStudentScore($userId, $courseInfo['code'], [], $sessionId); | 
				
			||||
 | 
				
			||||
                if ($userAverage >= $averageToUnlock) { | 
				
			||||
                    return false; | 
				
			||||
                } | 
				
			||||
 | 
				
			||||
                return true; | 
				
			||||
            } else { | 
				
			||||
                return false; | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        return true; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public function getInitialExercise($courseId, $sessionId) | 
				
			||||
    { | 
				
			||||
        return $this->getCourseExercise($courseId, $sessionId, true, false); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    private function getCourseExercise($courseId, $sessionId, $isInitial, $isFinal) | 
				
			||||
    { | 
				
			||||
        $table = $this->table; | 
				
			||||
        $courseId = (int) $courseId; | 
				
			||||
        $sessionId = (int) $sessionId; | 
				
			||||
 | 
				
			||||
        $sql = "SELECT * FROM $table | 
				
			||||
                WHERE | 
				
			||||
                    c_id = $courseId AND | 
				
			||||
                    session_id = $sessionId | 
				
			||||
                    "; | 
				
			||||
 | 
				
			||||
        if ($isInitial) { | 
				
			||||
            $sql .= ' AND is_initial = 1 '; | 
				
			||||
        } else { | 
				
			||||
            $sql .= ' AND is_initial = 0 '; | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        if ($isFinal) { | 
				
			||||
            $sql .= ' AND is_final = 1 '; | 
				
			||||
        } else { | 
				
			||||
            $sql .= ' AND is_final = 0 '; | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        $result = Database::query($sql); | 
				
			||||
 | 
				
			||||
        if (Database::num_rows($result) > 0) { | 
				
			||||
            return Database::fetch_array($result, 'ASSOC'); | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        return false; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public function getFinalExercise($courseId, $sessionId) | 
				
			||||
    { | 
				
			||||
        return $this->getCourseExercise($courseId, $sessionId, false, true); | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,44 @@ | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
require_once __DIR__.'/../../../main/inc/global.inc.php'; | 
				
			||||
 | 
				
			||||
api_protect_admin_script(); | 
				
			||||
 | 
				
			||||
$plugin = Positioning::create(); | 
				
			||||
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null; | 
				
			||||
 | 
				
			||||
switch ($action) { | 
				
			||||
    case 'delete-file': | 
				
			||||
        $path = isset($_REQUEST['path']) ? $_REQUEST['path'] : null; | 
				
			||||
        if (empty($path)) { | 
				
			||||
            echo json_encode(["status" => "false", "message" => $plugin->get_lang('ErrorEmptyPath')]); | 
				
			||||
            exit; | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        if (unlink($path)) { | 
				
			||||
            Display::addFlash($plugin->get_lang("DeletedSuccess"), 'success'); | 
				
			||||
            echo json_encode(["status" => "true"]); | 
				
			||||
        } else { | 
				
			||||
            echo json_encode(["status" => "false", "message" => $plugin->get_lang('ErrorDeleteFile')]); | 
				
			||||
        } | 
				
			||||
        break; | 
				
			||||
    case 'delete-files-list': | 
				
			||||
        $list = isset($_REQUEST['list']) ? $_REQUEST['list'] : []; | 
				
			||||
        if (empty($list)) { | 
				
			||||
            echo json_encode(["status" => "false", "message" => $plugin->get_lang('ErrorEmptyPath')]); | 
				
			||||
            exit; | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        foreach ($list as $value) { | 
				
			||||
            if (empty($value)) { | 
				
			||||
                continue; | 
				
			||||
            } | 
				
			||||
            unlink($value); | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        Display::addFlash($plugin->get_lang("DeletedSuccess"), 'success'); | 
				
			||||
        echo json_encode(["status" => "true"]); | 
				
			||||
        break; | 
				
			||||
} | 
				
			||||
@ -0,0 +1,116 @@ | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
/* For license terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
require_once __DIR__.'/../../main/inc/global.inc.php'; | 
				
			||||
 | 
				
			||||
api_protect_course_script(true); | 
				
			||||
 | 
				
			||||
if (!api_is_allowed_to_edit()) { | 
				
			||||
    // Students are redirected to the start_student.php | 
				
			||||
    api_location(api_get_path(WEB_PLUGIN_PATH).'positioning/start_student.php?'.api_get_cidreq()); | 
				
			||||
} | 
				
			||||
 | 
				
			||||
$plugin = Positioning::create(); | 
				
			||||
if (!$plugin->isEnabled()) { | 
				
			||||
    api_not_allowed(true); | 
				
			||||
} | 
				
			||||
 | 
				
			||||
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; | 
				
			||||
$id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0; | 
				
			||||
$formToString = ''; | 
				
			||||
$currentUrl = api_get_self().'?'.api_get_cidreq(); | 
				
			||||
$courseId = api_get_course_int_id(); | 
				
			||||
$sessionId = api_get_session_id(); | 
				
			||||
 | 
				
			||||
switch ($action) { | 
				
			||||
    case 'set_initial': | 
				
			||||
        Display::addFlash(Display::return_message(get_lang('Updated'))); | 
				
			||||
        $plugin->setInitialExercise($id, $courseId, $sessionId); | 
				
			||||
        api_location($currentUrl); | 
				
			||||
        break; | 
				
			||||
    case 'set_final': | 
				
			||||
        Display::addFlash(Display::return_message(get_lang('Updated'))); | 
				
			||||
        $plugin->setFinalExercise($id, $courseId, $sessionId); | 
				
			||||
        api_location($currentUrl); | 
				
			||||
        break; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
$nameTools = $plugin->get_lang('Positioning'); | 
				
			||||
 | 
				
			||||
$htmlHeadXtra[] = api_get_js('chartjs/Chart.min.js'); | 
				
			||||
$template = new Template($nameTools); | 
				
			||||
$url = $currentUrl.'&'; | 
				
			||||
$actions = function ($row) use ($plugin, $url, $courseId, $sessionId) { | 
				
			||||
    $classInitial = 'btn btn-default'; | 
				
			||||
    if ($plugin->isInitialExercise($row['iid'], $courseId, $sessionId)) { | 
				
			||||
        $classInitial = 'btn btn-primary disabled'; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    $classFinal = 'btn btn-default'; | 
				
			||||
    if ($plugin->isFinalExercise($row['iid'], $courseId, $sessionId)) { | 
				
			||||
        $classFinal = 'btn btn-primary disabled'; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    $actions = Display::url( | 
				
			||||
        $plugin->get_lang('SelectAsInitialTest'), | 
				
			||||
        $url.'&action=set_initial&id='.$row['iid'], | 
				
			||||
        ['class' => $classInitial] | 
				
			||||
    ); | 
				
			||||
    $actions .= Display::url( | 
				
			||||
        $plugin->get_lang('SelectAsFinalTest'), | 
				
			||||
        $url.'&action=set_final&id='.$row['iid'], | 
				
			||||
        ['class' => $classFinal] | 
				
			||||
    ); | 
				
			||||
 | 
				
			||||
    return $actions; | 
				
			||||
}; | 
				
			||||
 | 
				
			||||
$table = Exercise::exerciseGrid( | 
				
			||||
    0, | 
				
			||||
    null, | 
				
			||||
    null, | 
				
			||||
    null, | 
				
			||||
    null, | 
				
			||||
    false, | 
				
			||||
    3, | 
				
			||||
    RESULT_DISABLE_RADAR, | 
				
			||||
    1, | 
				
			||||
    $actions, | 
				
			||||
    true | 
				
			||||
); | 
				
			||||
 | 
				
			||||
$table->headers = []; | 
				
			||||
$table->set_header(0, get_lang('ExerciseName'), false); | 
				
			||||
$table->set_header(1, get_lang('QuantityQuestions'), false); | 
				
			||||
$table->set_header(2, get_lang('Actions'), false); | 
				
			||||
$exerciseList = []; | 
				
			||||
foreach ($table->table_data as &$data) { | 
				
			||||
    $data = [ | 
				
			||||
        $data[1], | 
				
			||||
        $data[2], | 
				
			||||
        $data[3], | 
				
			||||
    ]; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
$initialData = $plugin->getInitialExercise($courseId, $sessionId); | 
				
			||||
$users = CourseManager::get_user_list_from_course_code(api_get_course_id(), $sessionId); | 
				
			||||
$radars = ''; | 
				
			||||
 | 
				
			||||
$initialExerciseTitle = ''; | 
				
			||||
if (!empty($users) && $initialData && $initialData['exercise_id']) { | 
				
			||||
    $users = array_column($users, 'user_id'); | 
				
			||||
    $exerciseId = $initialData['exercise_id']; | 
				
			||||
    $initialExercise = new Exercise(); | 
				
			||||
    $initialExercise->read($exerciseId); | 
				
			||||
    $radars = $initialExercise->getRadarsFromUsers($users, [$initialExercise], $courseId, $sessionId); | 
				
			||||
    $initialExerciseTitle = $initialExercise->get_formated_title(); | 
				
			||||
} | 
				
			||||
 | 
				
			||||
$table->set_form_actions([]); | 
				
			||||
$exercises = $table->return_table(); | 
				
			||||
$template->assign('grid', $exercises); | 
				
			||||
$template->assign('radars', $radars); | 
				
			||||
$template->assign('initial_exercise', $initialExerciseTitle); | 
				
			||||
$template->assign('content', $template->fetch('positioning/view/start.tpl')); | 
				
			||||
$template->display_one_col_template(); | 
				
			||||
@ -0,0 +1,94 @@ | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
/* For license terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
require_once __DIR__.'/../../main/inc/global.inc.php'; | 
				
			||||
 | 
				
			||||
api_protect_course_script(true); | 
				
			||||
 | 
				
			||||
$plugin = Positioning::create(); | 
				
			||||
if (!$plugin->isEnabled()) { | 
				
			||||
    api_not_allowed(true); | 
				
			||||
} | 
				
			||||
 | 
				
			||||
$htmlHeadXtra[] = api_get_js('chartjs/Chart.min.js'); | 
				
			||||
 | 
				
			||||
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; | 
				
			||||
$id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0; | 
				
			||||
$formToString = ''; | 
				
			||||
$currentUrl = api_get_self().'?'.api_get_cidreq(); | 
				
			||||
$courseId = api_get_course_int_id(); | 
				
			||||
$courseCode = api_get_course_id(); | 
				
			||||
$sessionId = api_get_session_id(); | 
				
			||||
$currentUserId = api_get_user_id(); | 
				
			||||
 | 
				
			||||
$initialData = $plugin->getInitialExercise($courseId, $sessionId); | 
				
			||||
$finalData = $plugin->getFinalExercise($courseId, $sessionId); | 
				
			||||
 | 
				
			||||
$initialExerciseTitle = ''; | 
				
			||||
$radar = ''; | 
				
			||||
$initialResults = null; | 
				
			||||
$exercisesToRadar = []; | 
				
			||||
if ($initialData) { | 
				
			||||
    $exerciseId = $initialData['exercise_id']; | 
				
			||||
    $initialExercise = new Exercise(); | 
				
			||||
    $initialExercise->read($exerciseId); | 
				
			||||
    $initialResults = Event::getExerciseResultsByUser( | 
				
			||||
        $currentUserId, | 
				
			||||
        $initialData['exercise_id'], | 
				
			||||
        $courseId, | 
				
			||||
        $sessionId | 
				
			||||
    ); | 
				
			||||
 | 
				
			||||
    $initialExerciseTitle = $initialExercise->get_formated_title(); | 
				
			||||
    if (empty($initialResults)) { | 
				
			||||
        $url = api_get_path(WEB_CODE_PATH).'exercise/overview.php?'.api_get_cidreq().'&exerciseId='.$exerciseId; | 
				
			||||
        $initialExerciseTitle = Display::url($initialExercise->get_formated_title(), $url); | 
				
			||||
    } else { | 
				
			||||
        $exercisesToRadar[] = $initialExercise; | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
 | 
				
			||||
$studentAverage = (int) Tracking::getAverageStudentScore($currentUserId, $courseCode, [], $sessionId); | 
				
			||||
$averageToUnlock = (int) $plugin->get('average_percentage_to_unlock_final_exercise'); | 
				
			||||
 | 
				
			||||
$finalExerciseTitle = ''; | 
				
			||||
if ($finalData) { | 
				
			||||
    $exerciseId = $finalData['exercise_id']; | 
				
			||||
    $finalExercise = new Exercise(); | 
				
			||||
    $finalExercise->read($exerciseId); | 
				
			||||
    $finalResults = Event::getExerciseResultsByUser( | 
				
			||||
        api_get_user_id(), | 
				
			||||
        $initialData['exercise_id'], | 
				
			||||
        $courseId, | 
				
			||||
        $sessionId | 
				
			||||
    ); | 
				
			||||
 | 
				
			||||
    $finalExerciseTitle = $finalExercise->get_formated_title(); | 
				
			||||
    if (!empty($initialResults)) { | 
				
			||||
        if ($studentAverage >= $averageToUnlock) { | 
				
			||||
            $url = api_get_path(WEB_CODE_PATH).'exercise/overview.php?'.api_get_cidreq().'&exerciseId='.$exerciseId; | 
				
			||||
            if (empty($finalResults)) { | 
				
			||||
                $finalExerciseTitle = Display::url($finalExercise->get_formated_title(), $url); | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
        $exercisesToRadar[] = $finalExercise; | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
 | 
				
			||||
$radars = $initialExercise->getRadarsFromUsers([$currentUserId], $exercisesToRadar, $courseId, $sessionId); | 
				
			||||
$nameTools = $plugin->get_lang('Positioning'); | 
				
			||||
 | 
				
			||||
$template = new Template($nameTools); | 
				
			||||
 | 
				
			||||
$template->assign('initial_exercise', $initialExerciseTitle); | 
				
			||||
$template->assign('final_exercise', $finalExerciseTitle); | 
				
			||||
$template->assign( | 
				
			||||
    'average_percentage_to_unlock_final_exercise', | 
				
			||||
    $averageToUnlock | 
				
			||||
); | 
				
			||||
 | 
				
			||||
$template->assign('average', $studentAverage); | 
				
			||||
$template->assign('radars', $radars); | 
				
			||||
$template->assign('content', $template->fetch('positioning/view/start_student.tpl')); | 
				
			||||
$template->display_one_col_template(); | 
				
			||||
@ -0,0 +1,7 @@ | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
/* For license terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
require_once __DIR__.'/../../main/inc/global.inc.php'; | 
				
			||||
 | 
				
			||||
Positioning::create()->uninstall(); | 
				
			||||
@ -0,0 +1,7 @@ | 
				
			||||
 | 
				
			||||
{{ grid }} | 
				
			||||
 | 
				
			||||
{% if radars %} | 
				
			||||
    <h4>{{ "InitialTest"| get_plugin_lang('Positioning') }}: {{ initial_exercise }}</h4> | 
				
			||||
    {{ radars }} | 
				
			||||
{% endif %} | 
				
			||||
@ -0,0 +1,11 @@ | 
				
			||||
<h3>{{ "InviteToTakePositioningTest"| get_plugin_lang('Positioning') }}</h3> | 
				
			||||
 | 
				
			||||
<p>{{ "InitialTest"| get_plugin_lang('Positioning') }}: {{ initial_exercise }}</p> | 
				
			||||
 | 
				
			||||
<h3>{{ "YouMustCompleteAThresholdToTakeFinalTest"| get_plugin_lang('Positioning') | format(average_percentage_to_unlock_final_exercise) }}</h3> | 
				
			||||
 | 
				
			||||
<p>{{ "Average"| get_lang }}: {{ average }}</p> | 
				
			||||
 | 
				
			||||
<p>{{ "FinalTest"| get_plugin_lang('Positioning') }}: {{ final_exercise }}</p> | 
				
			||||
 | 
				
			||||
{{ radars }} | 
				
			||||
					Loading…
					
					
				
		Reference in new issue