From a53956895b1f2b499d2cf8cfc5cca4a00ad6774a Mon Sep 17 00:00:00 2001 From: Roman Steinberg <roman.accs@gmail.com> Date: Fri, 20 Oct 2017 09:32:56 +0300 Subject: [PATCH] FIX: Model_Plan::withExternalID calls fixed --- .../application/classes/Controller/Api/V0/Student.php | 8 +++++--- .../application/classes/Controller/Api/V0/StudyPlan.php | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/~dev_rating/application/classes/Controller/Api/V0/Student.php b/~dev_rating/application/classes/Controller/Api/V0/Student.php index 343c25d5b..2ed58f3cf 100644 --- a/~dev_rating/application/classes/Controller/Api/V0/Student.php +++ b/~dev_rating/application/classes/Controller/Api/V0/Student.php @@ -71,10 +71,11 @@ class Controller_Api_V0_Student extends Controller_Handler_Api { if (!isset($recordBookData->planID)) { if (isset($recordBookData->planExternalID)) { - $recordBookData->planID = Model_Plan::withExternalID($recordBookData->planExternalID)->ID; - if ($recordBookData->planID == -1) { + $studyPlan = Model_Plan::withExternalID($recordBookData->planExternalID); + if (is_null($studyPlan)) { throw new InvalidArgumentException('RecordBook: plan not found'); } + $recordBookData->planID = $studyPlan->ID; } else { throw new InvalidArgumentException('RecordBook: no plan ids'); } @@ -188,7 +189,8 @@ class Controller_Api_V0_Student extends Controller_Handler_Api { } if (!isset($studentData->id) || ($studentData->id == -1)) { - $foundList = Model_Students::searchStudentsByName([$studentData->firstName, $studentData->secondName, $studentData->lastName], $facultyID); + $foundList = Model_Students::searchStudentsByName([$studentData->firstName, + $studentData->secondName, $studentData->lastName], $facultyID); $foundSet = []; foreach ($foundList as $item) { if (!in_array($item['ID'], $foundSet)) { diff --git a/~dev_rating/application/classes/Controller/Api/V0/StudyPlan.php b/~dev_rating/application/classes/Controller/Api/V0/StudyPlan.php index 7cf5899b0..9973ceee9 100644 --- a/~dev_rating/application/classes/Controller/Api/V0/StudyPlan.php +++ b/~dev_rating/application/classes/Controller/Api/V0/StudyPlan.php @@ -83,7 +83,7 @@ class Controller_Api_V0_StudyPlan extends Controller_Handler_Api { private function processStudyPlan($studyPlanData, $year, $semesterID, $facultyID) { if (!isset($studyPlanData->id) && isset($studyPlanData->externalID)) { $studyPlan = Model_Plan::withExternalID($studyPlanData->externalID); - if (!isset($studyPlan)) { + if (!is_null($studyPlan)) { $studyPlan = Model_Plan::make() ->externalID($studyPlanData->externalID) ->year($year) -- GitLab