Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
yotta
/
pictogram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
60
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6fdb9d45
authored
Nov 26, 2017
by
Sebastián Collado Montañez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
new student core grid working
parent
6edd256a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
114 additions
and
34 deletions
sails/roles/database/files/triggers-enrolments-integrity-constraints.sql
sails/roles/database/files/triggers-enrolments-integrity-constraints.sql
View file @
6fdb9d45
-- Integrity constraints for enrolment management
-- Integrity constraints for enrolment management
--
--
DELIMITER
;;
DELIMITER
$$
DROP
TRIGGER
IF
EXISTS
TRG_NEW_STUDENT_MAXENROLMENTS
$$
DROP
TRIGGER
IF
EXISTS
TRG_NEW_STUDENT_MAXENROLMENTS
;;
-- Integrity rule 2: office.current_enrolments updating (adding core)
-- Integrity rule 2: office.current_enrolments updating (adding core)
DROP
TRIGGER
IF
EXISTS
TRG_NEW_STUDENT_UPDATE_ENROLMENTS
;;
DROP
TRIGGER
IF
EXISTS
TRG_NEW_STUDENT_UPDATE_ENROLMENTS
$$
CREATE
TRIGGER
TRG_NEW_STUDENT_UPDATE_ENROLMENTS
CREATE
TRIGGER
TRG_NEW_STUDENT_UPDATE_ENROLMENTS
AFTER
INSERT
ON
student
AFTER
INSERT
ON
student
FOR
EACH
ROW
FOR
EACH
ROW
thisTrigger
:
BEGIN
thisTrigger
:
BEGIN
DECLARE
LID
INT
;
DECLARE
LID
INT
;
IF
((
@
TRIGGER_CHECKS
=
FALSE
)
IF
((
@
TRIGGER_CHECKS
=
FALSE
)
OR
(
@
TRIGGER_AFTER_INSERT_CHECKS
=
FALSE
))
AND
(
USER
()
=
'root@localhost'
)
THEN
OR
(
@
TRIGGER_AFTER_INSERT_CHECKS
=
FALSE
))
LEAVE
thisTrigger
;
AND
(
USER
()
=
'root@localhost'
)
THEN
LEAVE
thisTrigger
;
END
IF
;
END
IF
;
-- Load core collection for student
-- Load core collection for student
INSERT
INTO
grid
(
id_stu
,
id_sup
,
name
)
VALUES
(
NEW
.
id
,
null
,
'new_grid'
);
CALL
student_create_core
(
null
,
new
.
id
);
SET
LID
=
LAST_INSERT_ID
();
END
$$
CALL
grid_create_core
(
LID
,
new
.
id
);
END
;;
DROP
PROCEDURE
IF
EXISTS
active_grid_update
;;
-- Update student active grid
DROP
PROCEDURE
IF
EXISTS
active_grid_update
$$
CREATE
PROCEDURE
active_grid_update
(
IN
_id_stu
INTEGER
)
CREATE
PROCEDURE
active_grid_update
(
IN
_id_stu
INTEGER
)
BEGIN
BEGIN
DECLARE
_id_grid
INTEGER
;
DECLARE
_id_grid
INTEGER
;
SELECT
id
INTO
_id_grid
FROM
grid
WHERE
id_stu
=
_id_stu
LIMIT
1
;
SELECT
id
INTO
_id_grid
FROM
grid
WHERE
id_stu
=
_id_stu
LIMIT
1
;
UPDATE
student
SET
id_active_grid
=
_id_grid
WHERE
id
=
_id_stu
;
UPDATE
student
SET
id_active_grid
=
_id_grid
WHERE
id
=
_id_stu
;
END
;;
END
$$
-- Procedure to add core when new grid is created
DROP
PROCEDURE
IF
EXISTS
grid_create_core
;;
-- Remove old procedure
CREATE
PROCEDURE
grid_create_core
(
IN
id_grid
INTEGER
,
IN
id_stu
INTEGER
)
DROP
PROCEDURE
IF
EXISTS
grid_create_core
$$
BEGIN
-- Procedure to add core when new student is created
-- Load core collection for student
DROP
PROCEDURE
IF
EXISTS
student_create_core
$$
INSERT
INTO
stu_picto
(
id_stu
,
id_pic
,
id_grid
,
attributes
)
CREATE
PROCEDURE
student_create_core
(
IN
_id_sup
int
(
11
),
IN
_id_stu
int
(
11
))
SELECT
id_stu
,
id_pic
,
id_grid
,
concat
(
'{"id_cat":'
,
if
(
id_cat_pic
is
null
,
'null'
,
id_cat_pic
),
',"coord_x":'
,
coord_x
,
BEGIN
',"coord_y":'
,
coord_y
,
',"status":"invisible"'
,
-- Variables
',"highlight":false'
,
DECLARE
_id
INT
;
',"color":'
,
if
(
color
is
null
,
'null'
,
concat
(
'"'
,
color
,
'"'
)),
DECLARE
_id_pic
INT
;
'}'
)
as
attributes
DECLARE
_id_cat_pic
INT
;
FROM
picto_core
P
;
DECLARE
_coord_x
INT
;
END
;;
DECLARE
_coord_y
INT
;
DECLARE
_color
VARCHAR
(
9
);
DECLARE
_grid_name
VARCHAR
(
100
);
DECLARE
_id_grid
INT
;
DECLARE
_attributes
JSON
;
DECLARE
_num_pictos
INT
;
DECLARE
_lang
VARCHAR
(
5
);
DECLARE
LID
INT
;
DECLARE
LID2
INT
;
DECLARE
done
INT
DEFAULT
FALSE
;
DECLARE
cursor_picto_core
CURSOR
FOR
SELECT
id
,
id_pic
,
id_cat_pic
,
coord_x
,
coord_y
,
color
FROM
pictodb
.
picto_core
ORDER
BY
id_cat_pic
IS
NULL
DESC
;
DECLARE
CONTINUE
HANDLER
FOR
NOT
FOUND
SET
done
=
TRUE
;
-- Obtiene el texto según el idioma del supervisor
SELECT
if
(
lang
=
"es-es"
,
'Con categorías'
,
'With categories'
)
AS
lang
INTO
_grid_name
FROM
student
WHERE
id
=
_id_stu
COLLATE
utf8_general_ci
;
-- Crea el tablero principal
INSERT
INTO
grid
(
name
,
active
,
id_stu
)
VALUES
(
_grid_name
,
1
,
_id_stu
);
SET
LID
=
LAST_INSERT_ID
();
-- Recorre todos los picto_core
OPEN
cursor_picto_core
;
read_loop
:
LOOP
FETCH
cursor_picto_core
INTO
_id
,
_id_pic
,
_id_cat_pic
,
_coord_x
,
_coord_y
,
_color
;
-- Control para la finalizacion del bucle
IF
done
THEN
LEAVE
read_loop
;
END
IF
;
-- Genero el JSON de attributes para el pictograma
SET
_attributes
=
JSON_OBJECT
(
'coord_x'
,
_coord_x
,
'coord_y'
,
_coord_y
,
'status'
,
'invisible'
,
'highlight'
,
'false'
,
'color'
,
_color
);
-- El pictograma pertenece al tablero principal
IF
(
_id_cat_pic
IS
NULL
)
THEN
-- Inserta el pictograma en el tablero principal
INSERT
INTO
stu_picto
(
id_stu
,
id_pic
,
attributes
,
id_grid
)
VALUES
(
_id_stu
,
_id_pic
,
_attributes
,
LID
);
-- Cuenta para dicho pictograma el numero de pictogramas hijos
SELECT
count
(
*
)
INTO
_num_pictos
FROM
picto_core
WHERE
id_cat_pic
=
_id_pic
;
-- Si tiene algun picto apuntandole, se crea un tablero nuevo
IF
(
_num_pictos
>
0
)
THEN
-- Selecciona el texto para el tablero hijo
SELECT
CAST
(
lang
AS
CHAR
(
5
))
INTO
_lang
FROM
student
WHERE
id
=
_id_stu
LIMIT
1
;
SELECT
`text`
INTO
_grid_name
FROM
picto_exp
WHERE
id_pic
=
_id_pic
AND
lang
=
_lang
LIMIT
1
;
-- Crea el nuevo tablero hijo
INSERT
INTO
grid
(
name
,
active
,
id_stu
)
VALUES
(
_grid_name
,
0
,
_id_stu
);
SET
LID2
=
LAST_INSERT_ID
();
UPDATE
stu_picto
SET
id_child_grid
=
LID2
WHERE
id_pic
=
_id_pic
AND
id_grid
=
LID
;
END
IF
;
ELSE
-- Inserta los pictogramas correspondientes en el tablero recien creado
SELECT
CAST
(
lang
AS
CHAR
(
5
))
INTO
_lang
FROM
student
WHERE
id
=
_id_stu
LIMIT
1
;
SELECT
`text`
INTO
_grid_name
FROM
picto_exp
WHERE
id_pic
=
_id_cat_pic
AND
lang
=
_lang
LIMIT
1
;
SELECT
id
INTO
_id_grid
FROM
grid
WHERE
name
=
_grid_name
AND
id_stu
=
_id_stu
LIMIT
1
;
INSERT
INTO
stu_picto
(
id_stu
,
id_pic
,
attributes
,
id_grid
)
VALUES
(
_id_stu
,
_id_pic
,
_attributes
,
_id_grid
);
END
IF
;
END
LOOP
;
CLOSE
cursor_picto_core
;
END
$$
-- Integrity rule 3: office.current_enrolments and supervisor assigments updating.
-- Integrity rule 3: office.current_enrolments and supervisor assigments updating.
DROP
TRIGGER
IF
EXISTS
TRG_MODIFY_STUDENT_ENROLMENTS
;;
DROP
TRIGGER
IF
EXISTS
TRG_MODIFY_STUDENT_ENROLMENTS
$$
DELIMITER
;
DELIMITER
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment