Skip to content
Snippets Groups Projects
Commit 45d44892 authored by Anton Bagliy's avatar Anton Bagliy
Browse files

WIP: api method to add global discipline #470 #473

parent 318dd150
Branches
No related merge requests found
CREATE OR REPLACE FUNCTION public.discipline_find_by_subject(psemesterid integer, psubjectid integer, pexamtype exam_credit_grading_credit)
RETURNS SETOF integer
LANGUAGE sql
-- ищет межфакультетские дисциплины по семестру, ведущему факультету, предмету и типу
-- межфакультетскими считает все дисциплины, которые не связаны с учебными планами
CREATE OR REPLACE FUNCTION public.discipline_find_global(psemesterid integer, psubjectid integer, pexamtype exam_credit_grading_credit, pfacultyid integer)
RETURNS SETOF integer
LANGUAGE sql
AS $function$
--select public.discipline_find_by_subject(
--select public.discipline_find_by_subject(
-- :psemesterid, -- put the psemesterid parameter value instead of 'psemesterid' (int4)
-- :psubjectid, -- put the psubjectid parameter value instead of 'psubjectid' (int4)
-- :pexamtype -- put the pexamtype parameter value instead of 'pexamtype' (exam_credit_grading_credit)
......@@ -10,11 +12,14 @@ AS $function$
SELECT disciplines.ID
FROM disciplines
WHERE disciplines.SemesterID = pSemesterID AND
disciplines.SubjectID = pSubjectID AND
disciplines.ExamType = pExamType
LIMIT 1;
disciplines.SubjectID = pSubjectID AND
disciplines.ExamType = pExamType AND
disciplines.FacultyID = pfacultyid AND
NOT EXISTS (SELECT disciplines_study_plans.id from disciplines_study_plans WHERE disciplines_study_plans.DisciplineID = disciplines.ID)
LIMIT 1;
$function$;
CREATE OR REPLACE FUNCTION public.internalbindstudent(pdisciplineid integer, precordbookid integer)
RETURNS integer
LANGUAGE plpgsql
......
......@@ -52,7 +52,7 @@ class Controller_Api_V0_GlobalDiscipline extends Controller_Handler_Api
{
// TODO: всегда можно будет найти только одну межф. дисциплину по этому предмету?
if (isset($disciplineData->subjectID)) {
$discipline = Model_Discipline::find_by_subject($semesterID, $disciplineData->subjectID, $disciplineData->type);
$discipline = Model_Discipline::find_global($semesterID, $disciplineData->subjectID, $disciplineData->type, $facultyID);
}
if (isset($discipline)) {
......@@ -86,7 +86,7 @@ class Controller_Api_V0_GlobalDiscipline extends Controller_Handler_Api
private function processGroup($groupData, $year, $semesterID)
{
$facultyID = Model_Faculties::getIdByExternalID($data->faculty);
$facultyID = Model_Faculties::getIdByExternalID($groupData->faculty);
$disciplineIDs = [];
try {
......
......@@ -212,17 +212,20 @@ class Model_Discipline extends Model_Container
])->execute();
}
public static function find_by_subject($semesterID, $subjectID, $type) {
$sql = 'SELECT * FROM Discipline_Find_By_Subject(:semesterID, :subjectID, :type) AS "ID"';
// ищет межфакультетские дисциплины по семестру, ведущему факультету, предмету и типу
// межфакультетскими считает все дисциплины, которые не связаны с учебными планами
public static function find_global($semesterID, $subjectID, $type, $facultyID) {
$sql = 'SELECT * FROM Discipline_Find_Global(:semesterID, :subjectID, :type, :facultyID) AS "ID"';
$data = DB::query(Database::SELECT, $sql)
->parameters([
':semesterID' => $semesterID,
':subjectID' => $subjectID,
':type' => $type,
':facultyID' => $facultyID
])->execute();
$cnt = count($data);
if ($cnt > 1) {
throw new Database_Exception('There are '.$cnt.' disciplines were found, but only one was expected!');
throw new Database_Exception('There are '.$cnt.' global disciplines found, but only one was expected!');
}
elseif ($cnt == 1) {
return Model_Discipline::load($data[0]['ID']);
......@@ -242,7 +245,7 @@ class Model_Discipline extends Model_Container
])->execute();
$cnt = count($data);
if ($cnt > 1) {
throw new Database_Exception('There are '.$cnt.' disciplines were found, but only one was expected!');
throw new Database_Exception('There are '.$cnt.' disciplines found, but only one was expected!');
}
elseif ($cnt == 1) {
return Model_Discipline::load($data[0]['ID']);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment