| Conditions | 131 |
| Total Lines | 518 |
| Code Lines | 259 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
| 1 | <?php |
||
| 34 | public static function saveItem( |
||
| 35 | $lp_id, |
||
| 36 | $user_id, |
||
| 37 | $view_id, |
||
| 38 | $item_id, |
||
| 39 | $score = -1.0, |
||
| 40 | $max = -1.0, |
||
| 41 | $min = -1.0, |
||
| 42 | $status = '', |
||
| 43 | $time = 0, |
||
| 44 | $suspend = '', |
||
| 45 | $location = '', |
||
| 46 | $interactions = [], |
||
| 47 | $core_exit = 'none', |
||
| 48 | $sessionId = null, |
||
| 49 | $courseId = null, |
||
| 50 | $lmsFinish = 0, |
||
| 51 | $userNavigatesAway = 0, |
||
| 52 | $statusSignalReceived = 0, |
||
| 53 | $nextItem = 0 |
||
| 54 | ) { |
||
| 55 | $debug = 0; |
||
| 56 | $return = null; |
||
| 57 | $courseCode = api_get_course_id(); |
||
| 58 | if (!empty($courseId)) { |
||
| 59 | $courseInfo = api_get_course_info_by_id($courseId); |
||
| 60 | if ($courseInfo) { |
||
|
|
|||
| 61 | $courseCode = $courseInfo['code']; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | |||
| 65 | if ($debug > 0) { |
||
| 66 | error_log('--------------------------------------'); |
||
| 67 | error_log('SAVE ITEM - lp_ajax_save_item.php'); |
||
| 68 | error_log('--------------------------------------'); |
||
| 69 | error_log("item_id: $item_id - lp_id: $lp_id - user_id: - $user_id - view_id: $view_id - item_id: $item_id"); |
||
| 70 | error_log("SCORE: $score - max:$max - min: $min - status:$status"); |
||
| 71 | error_log("TIME: $time - suspend: $suspend - location: $location - core_exit: $core_exit"); |
||
| 72 | error_log("finish: $lmsFinish - navigatesAway: $userNavigatesAway"); |
||
| 73 | error_log("courseCode: $courseCode"); |
||
| 74 | } |
||
| 75 | |||
| 76 | $myLP = learnpath::getLpFromSession($courseCode, $lp_id, $user_id); |
||
| 77 | |||
| 78 | if (!is_a($myLP, 'learnpath')) { |
||
| 79 | if ($debug) { |
||
| 80 | error_log('mylp variable is not an learnpath object'); |
||
| 81 | } |
||
| 82 | |||
| 83 | return null; |
||
| 84 | } |
||
| 85 | $prerequisitesCheck = $myLP->prerequisites_match($item_id); |
||
| 86 | |||
| 87 | /** @var learnpathItem $myLPI */ |
||
| 88 | if ($myLP->items && isset($myLP->items[$item_id])) { |
||
| 89 | $myLPI = $myLP->items[$item_id]; |
||
| 90 | } |
||
| 91 | |||
| 92 | if (empty($myLPI)) { |
||
| 93 | if ($debug > 0) { |
||
| 94 | error_log("item #$item_id not found in the items array: ".print_r($myLP->items, 1)); |
||
| 95 | } |
||
| 96 | |||
| 97 | return null; |
||
| 98 | } |
||
| 99 | |||
| 100 | // This functions sets the $this->db_item_view_id variable needed in get_status() see BT#5069 |
||
| 101 | $myLPI->set_lp_view($view_id); |
||
| 102 | |||
| 103 | // Launch the prerequisites check and set error if needed |
||
| 104 | if (true !== $prerequisitesCheck) { |
||
| 105 | // If prerequisites were not matched, don't update any item info |
||
| 106 | if ($debug) { |
||
| 107 | error_log("prereq_check failed: ".intval($prerequisitesCheck)); |
||
| 108 | } |
||
| 109 | |||
| 110 | return null; |
||
| 111 | } else { |
||
| 112 | if ($debug > 1) { |
||
| 113 | error_log('Prerequisites are OK'); |
||
| 114 | } |
||
| 115 | |||
| 116 | $logInfo = [ |
||
| 117 | 'tool' => TOOL_LEARNPATH, |
||
| 118 | 'tool_id' => $lp_id, |
||
| 119 | 'tool_id_detail' => $item_id, |
||
| 120 | 'action' => 'view', |
||
| 121 | 'action_details' => $myLP->getCurrentAttempt(), |
||
| 122 | ]; |
||
| 123 | Event::registerLog($logInfo); |
||
| 124 | |||
| 125 | if (isset($max) && -1 != $max) { |
||
| 126 | $myLPI->max_score = $max; |
||
| 127 | $myLPI->set_max_score($max); |
||
| 128 | if ($debug > 1) { |
||
| 129 | error_log("Setting max_score: $max"); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 133 | if (isset($min) && -1 != $min && 'undefined' !== $min) { |
||
| 134 | $myLPI->min_score = $min; |
||
| 135 | if ($debug > 1) { |
||
| 136 | error_log("Setting min_score: $min"); |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 140 | // set_score function used to save the status, but this is not the case anymore |
||
| 141 | if (isset($score) && -1 != $score) { |
||
| 142 | if ($debug > 1) { |
||
| 143 | error_log('Calling set_score('.$score.')'); |
||
| 144 | error_log('set_score changes the status to failed/passed if mastery score is provided'); |
||
| 145 | } |
||
| 146 | $myLPI->set_score($score); |
||
| 147 | if ($debug > 1) { |
||
| 148 | error_log('Done calling set_score '.$myLPI->get_score()); |
||
| 149 | } |
||
| 150 | } else { |
||
| 151 | if ($debug > 1) { |
||
| 152 | error_log('Score not updated'); |
||
| 153 | } |
||
| 154 | } |
||
| 155 | |||
| 156 | $statusIsSet = false; |
||
| 157 | // Default behaviour. |
||
| 158 | if (isset($status) && '' != $status && 'undefined' !== $status) { |
||
| 159 | if ($debug > 1) { |
||
| 160 | error_log('Calling set_status('.$status.')'); |
||
| 161 | } |
||
| 162 | |||
| 163 | $myLPI->set_status($status); |
||
| 164 | $statusIsSet = true; |
||
| 165 | if ($debug > 1) { |
||
| 166 | error_log('Done calling set_status: checking from memory: '.$myLPI->get_status(false)); |
||
| 167 | } |
||
| 168 | } else { |
||
| 169 | if ($debug > 1) { |
||
| 170 | error_log('Status not updated'); |
||
| 171 | } |
||
| 172 | } |
||
| 173 | |||
| 174 | $my_type = $myLPI->get_type(); |
||
| 175 | // Set status to completed for hotpotatoes if score > 80%. |
||
| 176 | if ('hotpotatoes' === $my_type) { |
||
| 177 | if ((empty($status) || 'undefined' === $status || 'not attempted' === $status) && $max > 0) { |
||
| 178 | if (($score / $max) > 0.8) { |
||
| 179 | $myStatus = 'completed'; |
||
| 180 | if ($debug > 1) { |
||
| 181 | error_log('Calling set_status('.$myStatus.') for hotpotatoes'); |
||
| 182 | } |
||
| 183 | $myLPI->set_status($myStatus); |
||
| 184 | $statusIsSet = true; |
||
| 185 | if ($debug > 1) { |
||
| 186 | error_log('Done calling set_status for hotpotatoes - now '.$myLPI->get_status(false)); |
||
| 187 | } |
||
| 188 | } |
||
| 189 | } elseif ('completed' === $status && $max > 0 && ($score / $max) < 0.8) { |
||
| 190 | $myStatus = 'failed'; |
||
| 191 | if ($debug > 1) { |
||
| 192 | error_log('Calling set_status('.$myStatus.') for hotpotatoes'); |
||
| 193 | } |
||
| 194 | $myLPI->set_status($myStatus); |
||
| 195 | $statusIsSet = true; |
||
| 196 | if ($debug > 1) { |
||
| 197 | error_log('Done calling set_status for hotpotatoes - now '.$myLPI->get_status(false)); |
||
| 198 | } |
||
| 199 | } |
||
| 200 | } elseif ('sco' === $my_type) { |
||
| 201 | /* |
||
| 202 | * This is a specific implementation for SCORM 1.2, matching page 26 of SCORM 1.2's RTE |
||
| 203 | * "Normally the SCO determines its own status and passes it to the LMS. |
||
| 204 | * 1) If cmi.core.credit is set to "credit" and there is a mastery |
||
| 205 | * score in the manifest (adlcp:masteryscore), the LMS can change |
||
| 206 | * the status to either passed or failed depending on the |
||
| 207 | * student's score compared to the mastery score. |
||
| 208 | * 2) If there is no mastery score in the manifest |
||
| 209 | * (adlcp:masteryscore), the LMS cannot override SCO |
||
| 210 | * determined status. |
||
| 211 | * 3) If the student is taking the SCO for no-credit, there is no |
||
| 212 | * change to the lesson_status, with one exception. If the |
||
| 213 | * lesson_mode is "browse", the lesson_status may change to |
||
| 214 | * "browsed" even if the cmi.core.credit is set to no-credit. |
||
| 215 | * " |
||
| 216 | * Additionally, the LMS behaviour should be: |
||
| 217 | * If a SCO sets the cmi.core.lesson_status then there is no problem. |
||
| 218 | * However, the SCORM does not force the SCO to set the cmi.core.lesson_status. |
||
| 219 | * There is some additional requirements that must be adhered to |
||
| 220 | * successfully handle these cases: |
||
| 221 | * Upon initial launch |
||
| 222 | * the LMS should set the cmi.core.lesson_status to "not attempted". |
||
| 223 | * Upon receiving the LMSFinish() call or the user navigates away, |
||
| 224 | * the LMS should set the cmi.core.lesson_status for the SCO to "completed". |
||
| 225 | * After setting the cmi.core.lesson_status to "completed", |
||
| 226 | * the LMS should now check to see if a Mastery Score has been |
||
| 227 | * specified in the cmi.student_data.mastery_score, if supported, |
||
| 228 | * or the manifest that the SCO is a member of. |
||
| 229 | * If a Mastery Score is provided and the SCO did set the |
||
| 230 | * cmi.core.score.raw, the LMS shall compare the cmi.core.score.raw |
||
| 231 | * to the Mastery Score and set the cmi.core.lesson_status to |
||
| 232 | * either "passed" or "failed". If no Mastery Score is provided, |
||
| 233 | * the LMS will leave the cmi.core.lesson_status as "completed" |
||
| 234 | */ |
||
| 235 | $masteryScore = $myLPI->get_mastery_score(); |
||
| 236 | if (-1 == $masteryScore || empty($masteryScore)) { |
||
| 237 | $masteryScore = false; |
||
| 238 | } |
||
| 239 | $credit = $myLPI->get_credit(); |
||
| 240 | |||
| 241 | /** |
||
| 242 | * 1) If cmi.core.credit is set to "credit" and there is a mastery |
||
| 243 | * score in the manifest (adlcp:masteryscore), the LMS can change |
||
| 244 | * the status to either passed or failed depending on the |
||
| 245 | * student's score compared to the mastery score. |
||
| 246 | */ |
||
| 247 | if ('credit' === $credit && |
||
| 248 | $masteryScore && |
||
| 249 | (isset($score) && -1 != $score) && |
||
| 250 | !$statusIsSet && !$statusSignalReceived |
||
| 251 | ) { |
||
| 252 | if ($score >= $masteryScore) { |
||
| 253 | $myLPI->set_status('passed'); |
||
| 254 | if ($debug) { |
||
| 255 | error_log('Set status: passed'); |
||
| 256 | } |
||
| 257 | } else { |
||
| 258 | $myLPI->set_status('failed'); |
||
| 259 | if ($debug) { |
||
| 260 | error_log('Set status: failed'); |
||
| 261 | } |
||
| 262 | } |
||
| 263 | $statusIsSet = true; |
||
| 264 | } |
||
| 265 | |||
| 266 | /** |
||
| 267 | * 2) If there is no mastery score in the manifest |
||
| 268 | * (adlcp:masteryscore), the LMS cannot override SCO |
||
| 269 | * determined status. |
||
| 270 | */ |
||
| 271 | if (!$statusIsSet && !$masteryScore && !$statusSignalReceived) { |
||
| 272 | if (!empty($status)) { |
||
| 273 | if ($debug) { |
||
| 274 | error_log("Set status: $status because: statusSignalReceived "); |
||
| 275 | } |
||
| 276 | $myLPI->set_status($status); |
||
| 277 | $statusIsSet = true; |
||
| 278 | } |
||
| 279 | //if no status was set directly, we keep the previous one |
||
| 280 | } |
||
| 281 | |||
| 282 | /** |
||
| 283 | * 3) If the student is taking the SCO for no-credit, there is no |
||
| 284 | * change to the lesson_status, with one exception. If the |
||
| 285 | * lesson_mode is "browse", the lesson_status may change to |
||
| 286 | * "browsed" even if the cmi.core.credit is set to no-credit. |
||
| 287 | */ |
||
| 288 | if (!$statusIsSet && 'no-credit' === $credit && !$statusSignalReceived) { |
||
| 289 | $mode = $myLPI->get_lesson_mode(); |
||
| 290 | if ('browse' === $mode && 'browsed' === $status) { |
||
| 291 | if ($debug) { |
||
| 292 | error_log("Set status: $status because mode browse"); |
||
| 293 | } |
||
| 294 | $myLPI->set_status($status); |
||
| 295 | $statusIsSet = true; |
||
| 296 | } |
||
| 297 | //if no status was set directly, we keep the previous one |
||
| 298 | } |
||
| 299 | |||
| 300 | /** |
||
| 301 | * If a SCO sets the cmi.core.lesson_status then there is no problem. |
||
| 302 | * However, the SCORM does not force the SCO to set the |
||
| 303 | * cmi.core.lesson_status. There is some additional requirements |
||
| 304 | * that must be adhered to successfully handle these cases:. |
||
| 305 | */ |
||
| 306 | if (!$statusIsSet && empty($status) && !$statusSignalReceived) { |
||
| 307 | /** |
||
| 308 | * Upon initial launch the LMS should set the |
||
| 309 | * cmi.core.lesson_status to "not attempted". |
||
| 310 | */ |
||
| 311 | // this case should be handled by LMSInitialize() and xajax_switch_item() |
||
| 312 | /** |
||
| 313 | * Upon receiving the LMSFinish() call or the user navigates |
||
| 314 | * away, the LMS should set the cmi.core.lesson_status for the |
||
| 315 | * SCO to "completed". |
||
| 316 | */ |
||
| 317 | if ($lmsFinish || $userNavigatesAway) { |
||
| 318 | $myStatus = 'completed'; |
||
| 319 | $updateStatus = true; |
||
| 320 | // Do not update status if "score as progress" and $userNavigatesAway |
||
| 321 | // The progress will be saved by the scorm BT#16766. |
||
| 322 | if ($userNavigatesAway && !$lmsFinish && $myLP->getUseScoreAsProgress()) { |
||
| 323 | $updateStatus = false; |
||
| 324 | } |
||
| 325 | |||
| 326 | if ($updateStatus) { |
||
| 327 | /** |
||
| 328 | * After setting the cmi.core.lesson_status to "completed", |
||
| 329 | * the LMS should now check to see if a Mastery Score has been |
||
| 330 | * specified in the cmi.student_data.mastery_score, if supported, |
||
| 331 | * or the manifest that the SCO is a member of. |
||
| 332 | * If a Mastery Score is provided and the SCO did set the |
||
| 333 | * cmi.core.score.raw, the LMS shall compare the cmi.core.score.raw |
||
| 334 | * to the Mastery Score and set the cmi.core.lesson_status to |
||
| 335 | * either "passed" or "failed". If no Mastery Score is provided, |
||
| 336 | * the LMS will leave the cmi.core.lesson_status as "completed”. |
||
| 337 | */ |
||
| 338 | if ($masteryScore && (isset($score) && -1 != $score)) { |
||
| 339 | if ($score >= $masteryScore) { |
||
| 340 | $myStatus = 'passed'; |
||
| 341 | } else { |
||
| 342 | $myStatus = 'failed'; |
||
| 343 | } |
||
| 344 | } |
||
| 345 | if ($debug) { |
||
| 346 | error_log("Set status: $myStatus because lmsFinish || userNavigatesAway"); |
||
| 347 | } |
||
| 348 | $myLPI->set_status($myStatus); |
||
| 349 | $statusIsSet = true; |
||
| 350 | } |
||
| 351 | } |
||
| 352 | } |
||
| 353 | // End of type=='sco' |
||
| 354 | } |
||
| 355 | |||
| 356 | // If no previous condition changed the SCO status, proceed with a |
||
| 357 | // generic behaviour |
||
| 358 | if (!$statusIsSet && !$statusSignalReceived) { |
||
| 359 | // Default behaviour |
||
| 360 | if (isset($status) && '' != $status && 'undefined' !== $status) { |
||
| 361 | if ($debug > 1) { |
||
| 362 | error_log('Calling set_status('.$status.')'); |
||
| 363 | } |
||
| 364 | |||
| 365 | $myLPI->set_status($status); |
||
| 366 | |||
| 367 | if ($debug > 1) { |
||
| 368 | error_log('Done calling set_status: checking from memory: '.$myLPI->get_status(false)); |
||
| 369 | } |
||
| 370 | } else { |
||
| 371 | if ($debug > 1) { |
||
| 372 | error_log("Status not updated"); |
||
| 373 | } |
||
| 374 | } |
||
| 375 | } |
||
| 376 | |||
| 377 | if (isset($time) && '' != $time && 'undefined' !== $time) { |
||
| 378 | // If big integer, then it's a timestamp, otherwise it's normal scorm time. |
||
| 379 | if ($debug > 1) { |
||
| 380 | error_log('Calling set_time('.$time.') '); |
||
| 381 | } |
||
| 382 | if ($time == intval(strval($time)) && $time > 1000000) { |
||
| 383 | if ($debug > 1) { |
||
| 384 | error_log("Time is INT"); |
||
| 385 | } |
||
| 386 | $real_time = time() - $time; |
||
| 387 | if ($debug > 1) { |
||
| 388 | error_log('Calling $real_time '.$real_time.' '); |
||
| 389 | } |
||
| 390 | $myLPI->set_time($real_time, 'int'); |
||
| 391 | } else { |
||
| 392 | if ($debug > 1) { |
||
| 393 | error_log("Time is in SCORM format"); |
||
| 394 | } |
||
| 395 | if ($debug > 1) { |
||
| 396 | error_log('Calling $time '.$time.' '); |
||
| 397 | } |
||
| 398 | $myLPI->set_time($time, 'scorm'); |
||
| 399 | } |
||
| 400 | } else { |
||
| 401 | $myLPI->current_stop_time = time(); |
||
| 402 | } |
||
| 403 | |||
| 404 | if (isset($suspend) && '' != $suspend && 'undefined' !== $suspend) { |
||
| 405 | $myLPI->current_data = $suspend; |
||
| 406 | } |
||
| 407 | |||
| 408 | if (isset($location) && '' != $location && 'undefined' !== $location) { |
||
| 409 | $myLPI->set_lesson_location($location); |
||
| 410 | } |
||
| 411 | |||
| 412 | // Deal with interactions provided in arrays in the following format: |
||
| 413 | // id(0), type(1), time(2), weighting(3), correct_responses(4), student_response(5), result(6), latency(7) |
||
| 414 | if (is_array($interactions) && count($interactions) > 0) { |
||
| 415 | foreach ($interactions as $index => $interaction) { |
||
| 416 | //$mylpi->add_interaction($index,$interactions[$index]); |
||
| 417 | //fix DT#4444 |
||
| 418 | $clean_interaction = str_replace('@.|@', ',', $interactions[$index]); |
||
| 419 | $myLPI->add_interaction($index, $clean_interaction); |
||
| 420 | } |
||
| 421 | } |
||
| 422 | |||
| 423 | if ('undefined' !== $core_exit) { |
||
| 424 | $myLPI->set_core_exit($core_exit); |
||
| 425 | } |
||
| 426 | $myLP->save_item($item_id, false); |
||
| 427 | } |
||
| 428 | |||
| 429 | $myStatusInDB = $myLPI->get_status(true); |
||
| 430 | if ($debug) { |
||
| 431 | error_log("Status in DB: $myStatusInDB"); |
||
| 432 | } |
||
| 433 | |||
| 434 | if ('completed' !== $myStatusInDB && |
||
| 435 | 'passed' !== $myStatusInDB && |
||
| 436 | 'browsed' !== $myStatusInDB && |
||
| 437 | 'failed' !== $myStatusInDB |
||
| 438 | ) { |
||
| 439 | $myStatusInMemory = $myLPI->get_status(false); |
||
| 440 | if ($debug) { |
||
| 441 | error_log("myStatusInMemory: $myStatusInMemory"); |
||
| 442 | } |
||
| 443 | |||
| 444 | if ($myStatusInMemory != $myStatusInDB) { |
||
| 445 | $myStatus = $myStatusInMemory; |
||
| 446 | } else { |
||
| 447 | $myStatus = $myStatusInDB; |
||
| 448 | } |
||
| 449 | } else { |
||
| 450 | $myStatus = $myStatusInDB; |
||
| 451 | } |
||
| 452 | |||
| 453 | $myTotal = $myLP->getTotalItemsCountWithoutDirs(); |
||
| 454 | $myComplete = $myLP->get_complete_items_count(); |
||
| 455 | $myProgressMode = $myLP->get_progress_bar_mode(); |
||
| 456 | $myProgressMode = '' === $myProgressMode ? '%' : $myProgressMode; |
||
| 457 | |||
| 458 | if ($debug > 1) { |
||
| 459 | error_log("mystatus: $myStatus"); |
||
| 460 | error_log("myprogress_mode: $myProgressMode"); |
||
| 461 | error_log("progress: $myComplete / $myTotal"); |
||
| 462 | } |
||
| 463 | |||
| 464 | if ('sco' !== $myLPI->get_type()) { |
||
| 465 | // If this object's JS status has not been updated by the SCORM API, update now. |
||
| 466 | $return .= "olms.lesson_status='".$myStatus."';"; |
||
| 467 | } |
||
| 468 | $return .= "update_toc('".$myStatus."','".$item_id."');"; |
||
| 469 | $update_list = $myLP->get_update_queue(); |
||
| 470 | |||
| 471 | foreach ($update_list as $my_upd_id => $my_upd_status) { |
||
| 472 | if ($my_upd_id != $item_id) { |
||
| 473 | /* Only update the status from other items (i.e. parents and brothers), |
||
| 474 | do not update current as we just did it already. */ |
||
| 475 | $return .= "update_toc('".$my_upd_status."','".$my_upd_id."');"; |
||
| 476 | } |
||
| 477 | } |
||
| 478 | $progressBarSpecial = false; |
||
| 479 | $scoreAsProgressSetting = api_get_configuration_value('lp_score_as_progress_enable'); |
||
| 480 | if (true === $scoreAsProgressSetting) { |
||
| 481 | $scoreAsProgress = $myLP->getUseScoreAsProgress(); |
||
| 482 | if ($scoreAsProgress) { |
||
| 483 | if (isset($score) && -1 != $score) { |
||
| 484 | $score = $myLPI->get_score(); |
||
| 485 | $maxScore = $myLPI->get_max(); |
||
| 486 | $return .= "update_progress_bar('$score', '$maxScore', '$myProgressMode');"; |
||
| 487 | } |
||
| 488 | $progressBarSpecial = true; |
||
| 489 | } |
||
| 490 | } |
||
| 491 | if (!$progressBarSpecial) { |
||
| 492 | $return .= "update_progress_bar('$myComplete', '$myTotal', '$myProgressMode');"; |
||
| 493 | } |
||
| 494 | |||
| 495 | if (!Session::read('login_as')) { |
||
| 496 | // If $_SESSION['login_as'] is set, then the user is an admin logged as the user. |
||
| 497 | $tbl_track_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN); |
||
| 498 | |||
| 499 | $sql = "SELECT login_id, login_date |
||
| 500 | FROM $tbl_track_login |
||
| 501 | WHERE login_user_id= ".api_get_user_id()." |
||
| 502 | ORDER BY login_date DESC |
||
| 503 | LIMIT 0,1"; |
||
| 504 | |||
| 505 | $q_last_connection = Database::query($sql); |
||
| 506 | if (Database::num_rows($q_last_connection) > 0) { |
||
| 507 | $current_time = api_get_utc_datetime(); |
||
| 508 | $row = Database::fetch_array($q_last_connection); |
||
| 509 | $i_id_last_connection = $row['login_id']; |
||
| 510 | $sql = "UPDATE $tbl_track_login |
||
| 511 | SET logout_date='".$current_time."' |
||
| 512 | WHERE login_id = $i_id_last_connection"; |
||
| 513 | Database::query($sql); |
||
| 514 | } |
||
| 515 | } |
||
| 516 | |||
| 517 | if (2 == $myLP->get_type()) { |
||
| 518 | $return .= 'update_stats();'; |
||
| 519 | } |
||
| 520 | |||
| 521 | // To be sure progress is updated. |
||
| 522 | $myLP->save_last($score); |
||
| 523 | |||
| 524 | Session::write('lpobject', serialize($myLP)); |
||
| 525 | Session::write('oLP', $myLP); |
||
| 526 | if ($debug > 0) { |
||
| 527 | error_log("lp_view_session_id :".$myLP->lp_view_session_id); |
||
| 528 | error_log('---------------- lp_ajax_save_item.php : save_item end ----- '); |
||
| 529 | } |
||
| 530 | |||
| 531 | $logInfo = [ |
||
| 532 | 'tool' => TOOL_LEARNPATH, |
||
| 533 | 'tool_id' => $myLP->get_id(), |
||
| 534 | 'action_details' => $myLP->getCurrentAttempt(), |
||
| 535 | 'tool_id_detail' => $myLP->get_current_item_id(), |
||
| 536 | 'action' => 'save_item', |
||
| 537 | ]; |
||
| 538 | Event::registerLog($logInfo); |
||
| 539 | |||
| 540 | $nextItem = (int) $nextItem; |
||
| 541 | if (!empty($nextItem)) { |
||
| 542 | $return .= self::switchItem( |
||
| 543 | $lp_id, |
||
| 544 | $user_id, |
||
| 545 | $view_id, |
||
| 546 | $item_id, |
||
| 547 | $nextItem |
||
| 548 | ); |
||
| 549 | } |
||
| 550 | |||
| 551 | return $return; |
||
| 552 | } |
||
| 818 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.