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

ADD: attach disciplines without teachers to first dean #316

parent c0ddb369
Branches
No related merge requests found
drop function if exists public.faculty_getdeans(pfacultyid integer);
CREATE OR REPLACE FUNCTION public.faculty_getdeans(pfacultyid integer)
RETURNS TABLE("FullName" character varying, "AccountID" integer, "TeacherID" integer)
LANGUAGE plpgsql
AS $function$
begin
return query
select GetUserFullNameByAccountID(accounts.ID) as "FullName",
accounts.id as "AccountID",
teachers.id as "TeacherID"
from accounts
join teachers on teachers.accountid = accounts.id
where teachers.facultyid = pfacultyid and accounts.userroleid = 4;
END;
$function$;
......@@ -19,9 +19,9 @@ class Controller_Api_V0_StudyPlan extends Controller_Handler_Api
}
}
if (empty($disciplineData->teacherIDs)) {
throw new InvalidArgumentException('Discipline without teachers');
}
//if (empty($disciplineData->teacherIDs)) {
// throw new InvalidArgumentException('Discipline without teachers');
//}
switch ($disciplineData->type) {
case 'Экзамен':
......@@ -59,7 +59,8 @@ class Controller_Api_V0_StudyPlan extends Controller_Handler_Api
}
} else {
if (empty($disciplineData->teacherIDs)) {
throw new InvalidArgumentException('Cannot create discipline without teachers');
// throw new InvalidArgumentException('Cannot create discipline without teachers');
$disciplineData->teacherIDs[0] = Model_Faculty::with($facultyID)->getDefaultTeacher();
}
$discipline = Model_Discipline::make()
......
......@@ -110,6 +110,17 @@ class Model_Faculty extends Model
->execute()->as_array();
}
public function getDefaultTeacher() {
$sql = 'SELECT * FROM faculty_getdeans(:faculty)';
$deans = DB::query(Database::SELECT, $sql)
->param(':faculty', $this->ID)
->execute()->as_array();
if (sizeof($deans) === 0) {
throw new InvalidArgumentException('Faculty has no deans!');
}
return $deans[0]["TeacherID"];
}
// todo: implement json_serialize
}
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