Internal: Clean up events.lib.php (phpdoc, parameters typing, removing unnecessary conditions)

pull/5235/head
Yannick Warnier 9 months ago
parent e2187b5ca4
commit 835b64e73b
  1. 97
      public/main/inc/lib/events.lib.php

@ -12,17 +12,19 @@ use Chamilo\CoreBundle\Entity\TrackEExercise;
use Chamilo\CoreBundle\Entity\User; use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Framework\Container; use Chamilo\CoreBundle\Framework\Container;
use ChamiloSession as Session; use ChamiloSession as Session;
use Doctrine\ORM\Exception\ORMException;
use Doctrine\ORM\Exception\NotSupported;
/** /**
* Class Event * Class Event
* Functions of this library are used to record informations when some kind * Functions of this library are used to record information when some kind
* of event occur. Each event has his own types of informations then each event * of event occur. Each event has his own types of information then each event
* use its own function. * use its own function.
*/ */
class Event class Event
{ {
/** /**
* Record information for login event when an user identifies himself with username & password * Record information for login event when a user identifies himself with username & password
* @param int $userId * @param int $userId
* *
* @return bool * @return bool
@ -214,7 +216,7 @@ class Event
* *
* @return int * @return int
* *
* @throws \Doctrine\ORM\Exception\NotSupported * @throws NotSupported
* @author Evie Embrechts * @author Evie Embrechts
* @author Sebastien Piraux <piraux_seb@hotmail.com> * @author Sebastien Piraux <piraux_seb@hotmail.com>
*/ */
@ -245,7 +247,7 @@ class Event
* @throws Exception * @throws Exception
* @author Sebastien Piraux <piraux_seb@hotmail.com> * @author Sebastien Piraux <piraux_seb@hotmail.com>
*/ */
public static function event_upload($documentId): int public static function event_upload(int $documentId): int
{ {
if (Session::read('login_as')) { if (Session::read('login_as')) {
return 0; return 0;
@ -255,7 +257,6 @@ class Event
$courseId = api_get_course_int_id(); $courseId = api_get_course_int_id();
$reallyNow = api_get_utc_datetime(); $reallyNow = api_get_utc_datetime();
$userId = api_get_user_id(); $userId = api_get_user_id();
$documentId = (int) $documentId;
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
$sql = "INSERT INTO $table $sql = "INSERT INTO $table
@ -297,7 +298,6 @@ class Event
$reallyNow = api_get_utc_datetime(); $reallyNow = api_get_utc_datetime();
$userId = api_get_user_id(); $userId = api_get_user_id();
$courseId = api_get_course_int_id(); $courseId = api_get_course_int_id();
$linkId = (int) $linkId;
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
$sql = "INSERT INTO ".$table." $sql = "INSERT INTO ".$table."
( links_user_id, ( links_user_id,
@ -323,7 +323,7 @@ class Event
* *
* @param int $exeId * @param int $exeId
* @param int $exoId * @param int $exoId
* @param mixed $score * @param float $score
* @param int $weighting * @param int $weighting
* @param int $sessionId * @param int $sessionId
* @param ?int $learnpathId * @param ?int $learnpathId
@ -361,7 +361,7 @@ class Event
return false; return false;
} }
if (!isset($status) || empty($status)) { if (empty($status)) {
$status = ''; $status = '';
} else { } else {
$status = Database::escape_string($status); $status = Database::escape_string($status);
@ -449,10 +449,6 @@ class Event
) { ) {
global $debug; global $debug;
$questionDuration = (int) $questionDuration; $questionDuration = (int) $questionDuration;
$question_id = (int) $question_id;
$exe_id = (int) $exe_id;
$position = (int) $position;
$course_id = (int) $course_id;
$now = api_get_utc_datetime(); $now = api_get_utc_datetime();
$recordingLog = ('true' === api_get_setting('exercise.quiz_answer_extra_recording')); $recordingLog = ('true' === api_get_setting('exercise.quiz_answer_extra_recording'));
@ -464,10 +460,6 @@ class Event
$user_id = api_get_anonymous_id(); $user_id = api_get_anonymous_id();
} }
} }
// check course_id or get from context
if (empty($course_id)) {
$course_id = api_get_course_int_id();
}
// check session_id or get from context // check session_id or get from context
$session_id = (int) $session_id; $session_id = (int) $session_id;
if (empty($session_id)) { if (empty($session_id)) {
@ -614,20 +606,22 @@ class Event
/** /**
* Record a hotspot spot for this attempt at answering a hotspot question. * Record a hotspot spot for this attempt at answering a hotspot question.
* *
* @param int $exeId * @param Exercise $exercise
* @param int $questionId Question ID * @param int $exeId
* @param int $answerId Answer ID * @param int $questionId Question ID
* @param int $correct * @param int $answerId Answer ID
* @param string $coords Coordinates of this point (e.g. 123;324) * @param int $correct
* @param bool $updateResults * @param string $coords Coordinates of this point (e.g. 123;324)
* @param ?int $exerciseId Deprecated param * @param bool $updateResults
* @param ?int $lpId * @param ?int $exerciseId Deprecated param
* @param ?int $lpItemId * @param ?int $lpId
* @param ?int $lpItemId
* *
* @return int Result of the insert query, or 0 on error * @return int Result of the insert query, or 0 on error
* *
* @throws \Doctrine\DBAL\Exception * @throws \Doctrine\DBAL\Exception
* @uses \Course code and user_id from global scope $_cid and $_user * @throws Exception
* @uses Course code and user_id from global scope $_cid and $_user
*/ */
public static function saveExerciseAttemptHotspot( public static function saveExerciseAttemptHotspot(
Exercise $exercise, Exercise $exercise,
@ -644,7 +638,7 @@ class Event
{ {
$debug = false; $debug = false;
if (false == $updateResults) { if (!$updateResults) {
// Validation in case of fraud with activated control time // Validation in case of fraud with activated control time
if (!ExerciseLib::exercise_time_control_is_valid($exercise, $lpId, $lpItemId)) { if (!ExerciseLib::exercise_time_control_is_valid($exercise, $lpId, $lpItemId)) {
if ($debug) { if ($debug) {
@ -726,7 +720,7 @@ class Event
* *
* @return bool * @return bool
* @assert ('','','') === false * @assert ('','','') === false
* @throws \Doctrine\ORM\Exception\ORMException * @throws ORMException
* @throws Exception * @throws Exception
* @author Yannick Warnier <yannick.warnier@beeznest.com> * @author Yannick Warnier <yannick.warnier@beeznest.com>
* *
@ -976,7 +970,7 @@ class Event
* @return bool * @return bool
* @throws Exception * @throws Exception
* @throws \Doctrine\DBAL\Exception * @throws \Doctrine\DBAL\Exception
* @throws \Doctrine\ORM\Exception\ORMException * @throws ORMException
*/ */
public static function delete_student_lp_events( public static function delete_student_lp_events(
int $user_id, int $user_id,
@ -1108,7 +1102,8 @@ class Event
* @param int $exercise_id * @param int $exercise_id
* @param int $course_id * @param int $course_id
* @param ?int $session_id * @param ?int $session_id
* @throws \Doctrine\ORM\Exception\ORMException * @throws ORMException
* @throws Exception
*/ */
public static function delete_all_incomplete_attempts( public static function delete_all_incomplete_attempts(
int $user_id, int $user_id,
@ -1208,12 +1203,13 @@ class Event
/** /**
* Gets all exercise results (NO Exercises in LPs ) from a given exercise id, course, session. * Gets all exercise results (NO Exercises in LPs ) from a given exercise id, course, session.
* *
* @param int $courseId * @param int $courseId
* @param ?int $session_id * @param ?int $session_id
* @param ?bool $get_count * @param ?bool $get_count
* *
* @return array with the results * @return mixed Array with the results or count if $get_count == true
* @throws \Doctrine\DBAL\Exception * @throws \Doctrine\DBAL\Exception
* @throws Exception
*/ */
public static function get_all_exercise_results_by_course( public static function get_all_exercise_results_by_course(
int $courseId, int $courseId,
@ -1252,12 +1248,13 @@ class Event
/** /**
* Gets all exercise results (NO Exercises in LPs) from a given exercise id, course, session. * Gets all exercise results (NO Exercises in LPs) from a given exercise id, course, session.
* *
* @param int $user_id * @param int $user_id
* @param int $courseId * @param int $courseId
* @param ?int $session_id * @param ?int $session_id
* *
* @return array with the results * @return array with the results
* @throws \Doctrine\DBAL\Exception * @throws \Doctrine\DBAL\Exception
* @throws Exception
*/ */
public static function get_all_exercise_results_by_user( public static function get_all_exercise_results_by_user(
int $user_id, int $user_id,
@ -1298,7 +1295,7 @@ class Event
* Gets exercise results (NO Exercises in LPs) from a given exercise id, course, session. * Gets exercise results (NO Exercises in LPs) from a given exercise id, course, session.
* *
* @param int $exe_id attempt id * @param int $exe_id attempt id
* @param string $status * @param ?string $status
* *
* @return array with the results * @return array with the results
* @throws \Doctrine\DBAL\Exception * @throws \Doctrine\DBAL\Exception
@ -1365,7 +1362,8 @@ class Event
?int $lp_id = 0, ?int $lp_id = 0,
?int $lp_item_id = 0, ?int $lp_item_id = 0,
?string $order = null ?string $order = null
) { ): array
{
$table_track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); $table_track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$tblTrackAttemptQualify = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_QUALIFY); $tblTrackAttemptQualify = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_QUALIFY);
@ -1547,7 +1545,8 @@ class Event
int $courseId, int $courseId,
?int $session_id = 0, ?int $session_id = 0,
?bool $skipLpResults = true ?bool $skipLpResults = true
) { ):array
{
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$sessionCondition = api_get_session_condition($session_id); $sessionCondition = api_get_session_condition($session_id);
@ -1683,11 +1682,10 @@ class Event
exe_id = $exe_id AND exe_id = $exe_id AND
question_id = $question_id question_id = $question_id
ORDER by question_id"; ORDER by question_id";
$sqlres = Database::query($sql); $sqlResult = Database::query($sql);
$comm = strval(Database::result($sqlres, 0, 'teacher_comment')); $comm = strval(Database::result($sqlResult, 0, 'teacher_comment'));
$comm = trim($comm);
return $comm; return trim($comm);
} }
/** /**
@ -1738,7 +1736,7 @@ class Event
$result = Database::query($sql); $result = Database::query($sql);
$attempt = []; $attempt = [];
if (Database::num_rows($result)) { if (Database::num_rows($result)) {
$attempt = Database::fetch_array($result, 'ASSOC'); $attempt = Database::fetch_assoc($result);
} }
return $attempt; return $attempt;
@ -1754,7 +1752,7 @@ class Event
* @param int $courseId The course in which it happened (already contained in exe_id) * @param int $courseId The course in which it happened (already contained in exe_id)
* @param int $session_id The session in which it happened (already contained in exe_id) * @param int $session_id The session in which it happened (already contained in exe_id)
* @param int $question_id The c_quiz_question.iid * @param int $question_id The c_quiz_question.iid
* @throws \Doctrine\ORM\Exception\ORMException * @throws ORMException
* @throws Exception * @throws Exception
*/ */
public static function delete_attempt( public static function delete_attempt(
@ -1794,7 +1792,7 @@ class Event
* @param int $courseId * @param int $courseId
* @param int $question_id * @param int $question_id
* @param ?int $sessionId * @param ?int $sessionId
* @throws \Doctrine\ORM\Exception\ORMException * @throws ORMException
* @throws Exception * @throws Exception
*/ */
public static function delete_attempt_hotspot( public static function delete_attempt_hotspot(
@ -1845,7 +1843,6 @@ class Event
return false; return false;
} }
$sessionId = (int) $sessionId;
if (false === self::isSessionLogNeedToBeSave($sessionId)) { if (false === self::isSessionLogNeedToBeSave($sessionId)) {
return false; return false;
} }
@ -2051,6 +2048,7 @@ class Event
* *
* @return bool true on successful insertion, false otherwise * @return bool true on successful insertion, false otherwise
* @throws \Doctrine\DBAL\Exception * @throws \Doctrine\DBAL\Exception
* @throws Exception
*/ */
public static function eventAddVirtualCourseTime( public static function eventAddVirtualCourseTime(
int $courseId, int $courseId,
@ -2096,7 +2094,6 @@ class Event
Database::insert($platformTrackingTable, $params); Database::insert($platformTrackingTable, $params);
if (Tracking::minimumTimeAvailable($sessionId, $courseId)) { if (Tracking::minimumTimeAvailable($sessionId, $courseId)) {
$workId = (int) $workId;
$uniqueId = time(); $uniqueId = time();
$logInfo = [ $logInfo = [
'c_id' => $courseId, 'c_id' => $courseId,
@ -2325,7 +2322,7 @@ class Event
$now = time(); $now = time();
$questionStart = Session::read('question_start', []); $questionStart = Session::read('question_start', []);
if (!empty($questionStart) && if (!empty($questionStart) &&
isset($questionStart[$questionId]) && !empty($questionStart[$questionId]) !empty($questionStart[$questionId])
) { ) {
$time = $questionStart[$questionId]; $time = $questionStart[$questionId];
} else { } else {
@ -2345,7 +2342,7 @@ class Event
* @param User $subscribedUser * @param User $subscribedUser
* @param CourseEntity $course * @param CourseEntity $course
* @return void * @return void
* @throws \Doctrine\ORM\Exception\ORMException * @throws ORMException
*/ */
public static function logSubscribedUserInCourse( public static function logSubscribedUserInCourse(
User $subscribedUser, User $subscribedUser,
@ -2380,7 +2377,7 @@ class Event
* @param CourseEntity $course * @param CourseEntity $course
* @param SessionEntity $session * @param SessionEntity $session
* @return void * @return void
* @throws \Doctrine\ORM\Exception\ORMException * @throws ORMException
*/ */
public static function logUserSubscribedInCourseSession( public static function logUserSubscribedInCourseSession(
User $userSubscribed, User $userSubscribed,

Loading…
Cancel
Save