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

WIP: api methodto add global discipline #470 #473

parent 0bba8e5c
Branches
No related merge requests found
......@@ -14,3 +14,33 @@ WHERE disciplines.SemesterID = pSemesterID AND
disciplines.ExamType = pExamType
LIMIT 1;
$function$;
CREATE OR REPLACE FUNCTION public.internalbindstudent(pdisciplineid integer, precordbookid integer)
RETURNS integer
LANGUAGE plpgsql
AS $function$
BEGIN
-- bind student
INSERT INTO disciplines_students (DisciplineID, recordbookid, "type") VALUES (pDisciplineID, precordbookid, 'attach')
ON conflict ON CONSTRAINT disciplines_students_recordbookid_disciplineid_key
DO UPDATE set "type" = 'attach';
return 1;
EXCEPTION
when others then RETURN -1;
END
$function$;
CREATE OR REPLACE FUNCTION public.internalunbindstudent(pdisciplineid integer, precordbookid integer)
RETURNS integer
LANGUAGE plpgsql
AS $function$
BEGIN
-- unbind student
update disciplines_students
set "type" = 'detach'
where DisciplineID=pdisciplineid and recordbookid=precordbookid;
return 1;
EXCEPTION
when others then RETURN -1;
END
$function$;
\ No newline at end of file
{
"year": "2018",
"semester": "2",
"groups": [
"year": "2018",
"semester": "2",
"groups": [
{
"faculty": "000001387",
"subject": " ",
"subject": "Иностранный язык",
"externalID": "000021910",
"type": "",
"type": "Зачет",
"teachers": [
{
"id": "F6930CAE2DC449852775EDC953649339430BA297",
"id": "F6930CAE2DC449852775EDC953649339430BA297"
},
{
"id": "45D58A5A2C33C45D02FAAC3829E28A0E6DF19C0E",
"id": "45D58A5A2C33C45D02FAAC3829E28A0E6DF19C0E"
}
],
],
"students": [
{
"id": "-18-0105",
{
"id": "ММ-18-0105",
"planId": "00132035",
"subdivisionId": "000001387",
"subdivisionId": "000001387"
},
{
"id": "-18-0207",
{
"id": "ММ-18-0207",
"planId": "00132035",
"subdivisionId": "000001387",
"subdivisionId": "000001387"
}
],
]
}
]
}
\ No newline at end of file
]
}
......@@ -42,7 +42,7 @@ class Controller_Api_V0_GlobalDiscipline extends Controller_Handler_Api
// TODO: найти предмет по имени или создать новый, получать будем не id а имя предмета
if (!isset($disciplineData->subjectID) && isset($disciplineData->externalID)) {
$disciplineData->subjectID = Model_Subject::withExternalID($disciplineData->externalID, $disciplineData->name, NULL, $facultyID);
$disciplineData->subjectID = Model_Subject::withExternalID($disciplineData->externalID, $disciplineData->subject, NULL, $facultyID);
}
return $disciplineData;
......@@ -56,9 +56,10 @@ class Controller_Api_V0_GlobalDiscipline extends Controller_Handler_Api
}
if (isset($discipline)) {
if (isset($disciplineData->gradeID)) {
$discipline->changeGradeUnsafe($disciplineData->gradeID);
}
// TODO: это здесь делать нужно?
//if (isset($disciplineData->gradeID)) {
// $discipline->changeGradeUnsafe($disciplineData->gradeID);
//}
} else {
if (empty($disciplineData->teacherIDs)) {
throw new InvalidArgumentException('Cannot create discipline without teachers');
......@@ -83,70 +84,78 @@ class Controller_Api_V0_GlobalDiscipline extends Controller_Handler_Api
return (int)$discipline->ID;
}
private function processGroups($groupData, $year, $semesterID, $facultyID)
private function processGroup($groupData, $year, $semesterID)
{
if (!isset($studyPlanData->id) && isset($groupData->faculty)) {
$facultyID = Model_Faculties::getIdByExternalID($data->faculty);
$disciplineIDs = [];
foreach ($studyPlanData->disciplines as &$disciplineData) {
try {
$disciplineData = $this->normalizeDisciplinesData($disciplineData, $facultyID);
$disciplineID = $this->processDiscipline($disciplineData, $studyPlan->ID, $semesterID, $facultyID);
$studyPlan->bindDiscipline($disciplineID);
try {
$disciplineData = $this->normalizeDisciplinesData($groupData, $facultyID)
$disciplineID = $this->processDiscipline($disciplineData, $semesterID, $facultyID);
$disciplineIDs[] = $disciplineID;
} catch (Exception $e) {
Log::instance()->add(Log::WARNING, '{0} {1}: {2}', array(
'{0}' => 'SYNC_DISCIPLINES',
'{0}' => 'SYNC_GLOBAL_DISCIPLINES',
'{1}' => $e->getMessage(),
'{2}' => json_encode($disciplineData),
'{2}' => json_encode($groupData),
));
}
foreach ($groupData->students as &$studentData) {
}
return $disciplineIDs;
}
/**
* @api {put} api/v0/studyPlan Add new study plan(s)
* @apiName Add new study plan
* @apiGroup Study plans
* @apiVersion 0.1.2
* @api {put} api/v0/globalDiscipline Add new study plan(s)
* @apiName Add new global discipline
* @apiGroup Disciplines
* @apiVersion 0.1.3
* @apiParam {String} token Api key
* @apiDescription This method accepts json body
* with list of study plans to add or update.
* each study plan includes list of disciplines inside
* with list of disciplines to add or update.
* each discipline includes list of teachers and students inside
* @apiExample {curl} Example usage:
* curl --header "Content-Type: application/json" \
* --request POST \
* --data '{
* "faculty": "000001387",
* "year": "2018",
* "semester": "1",
* "plans": [
* {
* "externalID": "000133620",
* "disciplines": [
* {
* "externalID": "000145371",
* "name": "Иностранный язык 2 (английский)",
* "type": "Зачет",
* "teachers": [
* {
* "hashSnils": "E043D16D4A36F7C4306B0EDC1C82E0E1D6E5CFF6"
* },
* {
* "hashSnils": "435F6F584A5636D881CF085487157DAEA76FBC8E"
* },
* {
* "hashSnils": "653A81C0F2FD15983C5671A4020CCA545A403426"
* }
* ]
* }
* ]
* "year": "2018",
* "semester": "2",
* "groups": [
* {
* "faculty": "000001387",
* "subject": "Иностранный язык",
* "externalID": "000021910",
* "type": "зачет",
* "teachers": [
* {
* "id": "F6930CAE2DC449852775EDC953649339430BA297",
* },
* {
* "id": "45D58A5A2C33C45D02FAAC3829E28A0E6DF19C0E",
* }
* ],
* "students": [
* {
* "id": "ММ-18-0105",
* "planId": "00132035",
* "subdivisionId": "000001387",
*
* },
* {
* "id": "ММ-18-0207",
* "planId": "00132035",
* "subdivisionId": "000001387",
*
* }
* ],
* }
* ]
* }
* ]
* }' \
* http://grade/~dev_rating/api/v0/studyPlan?token=osw839hfgh9a23hgfh92hasff232f2oasf
* ' \
* http://grade/~dev_rating/api/v0/GlobalDiscipline?token=uie892hf?sD39syh92af9s90sjbh3Dfd9de33s
*/
public function action_put_index()
{
......@@ -157,10 +166,10 @@ class Controller_Api_V0_GlobalDiscipline extends Controller_Handler_Api
$year = (int)$data->year;
$semesterID = (int)Model_Semesters::find($year, (int)$data->semester)->ID;
$facultyID = Model_Faculties::getIdByExternalID($data->faculty);
// $facultyID = Model_Faculties::getIdByExternalID($data->faculty);
foreach ($data->plans as $studyPlanData) {
$res[] = $this->processStudyPlan($studyPlanData, $year, $semesterID, $facultyID);
foreach ($data->groups as $groupData) {
$res[] = $this->processGroup($groupData, $year, $semesterID);
}
} catch (Exception $e) {
$this->badRequestError($e->getMessage());
......
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