Skip to content

Commit a410c28

Browse files
committed
Minor - format code, add validation
1 parent e6d2098 commit a410c28

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

main/inc/lib/AnnouncementManager.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,17 +507,21 @@ public static function getLastAnnouncementOrder($courseInfo)
507507
return 0;
508508
}
509509

510-
$table = Database::get_course_table(TABLE_ANNOUNCEMENT);
510+
if (!isset($courseInfo['real_id'])) {
511+
return false;
512+
}
513+
511514
$courseId = $courseInfo['real_id'];
515+
$table = Database::get_course_table(TABLE_ANNOUNCEMENT);
512516
$sql = "SELECT MAX(display_order)
513517
FROM $table
514518
WHERE c_id = $courseId ";
515-
$res_max = Database::query($sql);
519+
$result = Database::query($sql);
516520

517521
$order = 0;
518-
if (Database::num_rows($res_max)) {
519-
$row_max = Database::fetch_array($res_max);
520-
$order = intval($row_max[0]) + 1;
522+
if (Database::num_rows($result)) {
523+
$row = Database::fetch_array($result);
524+
$order = (int) $row[0] + 1;
521525
}
522526

523527
return $order;
@@ -555,6 +559,10 @@ public static function add_announcement(
555559
return false;
556560
}
557561

562+
if (!isset($courseInfo['real_id'])) {
563+
return false;
564+
}
565+
558566
$courseId = $courseInfo['real_id'];
559567
$tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
560568

0 commit comments

Comments
 (0)