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

ADD: group_id in logs_form_export, is_form_outdated query to find new grades...

ADD: group_id in logs_form_export, is_form_outdated query to find new grades after last form export #284
parent fb2c0132
Branches
Tags
No related merge requests found
......@@ -10,6 +10,7 @@ CREATE SEQUENCE seq_logs_form_export
CREATE TABLE logs_form_export (
id integer DEFAULT nextval('seq_logs_form_export'::regclass) NOT NULL,
discipline_id integer NOT NULL,
group_id integer NOT NULL,
account_id integer NOT NULL,
date timestamp(0) without time zone DEFAULT now() NOT NULL
);
......@@ -19,19 +20,29 @@ CREATE INDEX key_logs_form_export ON logs_form_export USING btree (discipline_id
ALTER TABLE ONLY logs_form_export
ADD CONSTRAINT logs_form_export_pkey PRIMARY KEY (id);
CREATE OR REPLACE FUNCTION public.log_form_export(paccountid integer, pdisciplineid integer)
ALTER TABLE ONLY logs_form_export
ADD CONSTRAINT logs_form_export_ibfk_1 FOREIGN KEY (discipline_id) REFERENCES disciplines(id);
ALTER TABLE ONLY logs_form_export
ADD CONSTRAINT logs_form_export_ibfk_2 FOREIGN KEY (group_id) REFERENCES study_groups(id);
ALTER TABLE ONLY logs_form_export
ADD CONSTRAINT logs_form_export_ibfk_3 FOREIGN KEY (account_id) REFERENCES accounts(id);
DROP FUNCTION IF EXISTS public.log_form_export(paccountid integer, pdisciplineid integer, pgroupid integer);
CREATE OR REPLACE FUNCTION public.log_form_export(paccountid integer, pdisciplineid integer, pgroupid integer)
RETURNS integer
LANGUAGE plpgsql
AS $function$
begin
INSERT INTO logs_form_export (discipline_id, account_id) VALUES (pdisciplineid, paccountid);
INSERT INTO logs_form_export (discipline_id, group_id, account_id) VALUES (pdisciplineid, pgroupid, paccountid);
RETURN 0;
END
$function$;
drop function if exists public.get_form_export_date(pdisciplineid integer);
CREATE OR REPLACE FUNCTION public.get_form_export_date(pdisciplineid integer)
RETURNS integer
drop function if exists public.get_form_export_date(pdisciplineid integer, pgroupid integer);
CREATE OR REPLACE FUNCTION public.get_form_export_date(pdisciplineid integer, pgroupid integer)
RETURNS DATE
LANGUAGE plpgsql
AS $function$
DECLARE vLastDate DATE DEFAULT NULL;
......@@ -39,8 +50,41 @@ begin
SELECT logs_form_export.date INTO vLastDate
FROM logs_form_export
WHERE logs_form_export.discipline_id = pdisciplineid
AND logs_form_export.group_id = pgroupid
ORDER BY logs_form_export.date DESC
LIMIT 1;
return vLastDate;
END
$function$;
drop function if exists public.is_form_outdated(pdisciplineid integer, pgroupid integer, psemesterid integer);
CREATE OR REPLACE FUNCTION public.is_form_outdated(pdisciplineid integer, pgroupid integer, psemesterid integer)
RETURNS integer
LANGUAGE plpgsql
AS $function$
DECLARE vLastDate DATE DEFAULT NULL;
vCountNewGrades integer DEFAULT 0;
begin
SELECT logs_form_export.date INTO vLastDate
FROM logs_form_export
WHERE logs_form_export.discipline_id = pdisciplineid
AND logs_form_export.group_id = pgroupid
ORDER BY logs_form_export.date DESC
LIMIT 1;
SELECT count(logs_rating.date) INTO vCountNewGrades FROM
logs_rating JOIN students_groups
ON logs_rating.recordbookid = students_groups.recordbookid
JOIN submodules ON logs_rating.submoduleid = submodules.id
JOIN modules ON submodules.moduleid = modules.id
JOIN disciplines ON modules.disciplineid = disciplines.id
WHERE students_groups.semesterid = psemesterid
AND students_groups.groupid = pgroupid
AND disciplines.id = pdisciplineid
AND logs_rating.date > vLastDate
group by logs_rating.date
ORDER BY logs_rating.date DESC;
return vCountNewGrades;
END
$function$;
\ No newline at end of file
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