Skip to content

Commit

Permalink
Avoid passing non-arrays into count to prevent warnings in PHP8
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinLenord committed Jun 13, 2023
1 parent 8697743 commit 83207eb
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1262,35 +1262,35 @@ public function update_grades_from_tii($cm) {
global $DB;

$submissionids = $this->fetch_updated_paper_ids_from_turnitin($cm);
$return = ($submissionids === false) ? false : true;

if ($submissionids === false || count($submissionids) < 1) {
return false;
}
// Refresh updated submissions.
if (count($submissionids) > 0) {
// Initialise Comms Object.
$turnitincomms = new turnitin_comms();
$turnitincall = $turnitincomms->initialise_api();
$return = true;
// Initialise Comms Object.
$turnitincomms = new turnitin_comms();
$turnitincall = $turnitincomms->initialise_api();

// Process submissions in batches, depending on the max. number of submissions the Turnitin API returns.
$submissionbatches = array_chunk($submissionids, PLAGIARISM_TURNITIN_NUM_RECORDS_RETURN);
// Process submissions in batches, depending on the max. number of submissions the Turnitin API returns.
$submissionbatches = array_chunk($submissionids, PLAGIARISM_TURNITIN_NUM_RECORDS_RETURN);

foreach ($submissionbatches as $submissionsbatch) {
try {
$submission = new TiiSubmission();
$submission->setSubmissionIds($submissionsbatch);

$response = $turnitincall->readSubmissions($submission);
$readsubmissions = $response->getSubmissions();
foreach ($submissionbatches as $submissionsbatch) {
try {
$submission = new TiiSubmission();
$submission->setSubmissionIds($submissionsbatch);

foreach ($readsubmissions as $readsubmission) {
$submissiondata = $DB->get_record('plagiarism_turnitin_files',
array('externalid' => $readsubmission->getSubmissionId()), 'id');
$return = $this->update_submission($cm, $submissiondata->id, $readsubmission);
}
$response = $turnitincall->readSubmissions($submission);
$readsubmissions = $response->getSubmissions();

} catch (Exception $e) {
$turnitincomms->handle_exceptions($e, 'tiisubmissiongeterror', false);
$return = false;
foreach ($readsubmissions as $readsubmission) {
$submissiondata = $DB->get_record('plagiarism_turnitin_files',
array('externalid' => $readsubmission->getSubmissionId()), 'id');
$return = $this->update_submission($cm, $submissiondata->id, $readsubmission);
}

} catch (Exception $e) {
$turnitincomms->handle_exceptions($e, 'tiisubmissiongeterror', false);
$return = false;
}
}

Expand Down Expand Up @@ -1479,7 +1479,7 @@ private function update_grade($cm, $submission, $userid) {
$tiisubmissions = current($tiisubmissions);
}

if (count($tiisubmissions) > 1) {
if (is_array($tiisubmissions) && count($tiisubmissions) > 1) {
$averagegrade = null;
$gradescounted = 0;
foreach ($tiisubmissions as $tiisubmission) {
Expand Down Expand Up @@ -2012,7 +2012,7 @@ public function cron_update_scores() {

$submissions = $DB->get_records_select(
'plagiarism_turnitin_files',
'statuscode = ?
'statuscode = ?
AND ( similarityscore IS NULL OR duedate_report_refresh = 1 )
AND ( orcapable = ? OR orcapable IS NULL ) ',
array('success', 1),
Expand Down

0 comments on commit 83207eb

Please sign in to comment.