Event definitions - missing I18N properties
Added the display name and template I18N properties to event definitions. Modified events.evdef_start() accordingly.
This commit is contained in:
parent
8f2fd29c71
commit
a6562052d3
2 changed files with 53 additions and 7 deletions
|
@ -24,7 +24,17 @@ CREATE TABLE events.event_definitions(
|
|||
CHECK( evdef_priority BETWEEN 0 AND 4 ) ,
|
||||
|
||||
/* Whether the priority for this type of event may be adjusted */
|
||||
evdef_adjustable BOOLEAN NOT NULL
|
||||
evdef_adjustable BOOLEAN NOT NULL ,
|
||||
|
||||
/* Internationalised string that contains the name of the event type;
|
||||
* used when displaying priority settings.
|
||||
*/
|
||||
evdef_name_id INT NOT NULL ,
|
||||
|
||||
/* Internationalised string that contains the template to use when
|
||||
* generating the output for a single event.
|
||||
*/
|
||||
evdef_template_id INT NOT NULL
|
||||
);
|
||||
|
||||
/* Unique index allowing the custom priorities table to reference only
|
||||
|
@ -32,6 +42,17 @@ CREATE TABLE events.event_definitions(
|
|||
*/
|
||||
CREATE UNIQUE INDEX idx_evdef_adjustables
|
||||
ON events.event_definitions( evdef_id , evdef_adjustable );
|
||||
/* Foreign key indexes */
|
||||
CREATE UNIQUE INDEX idx_evdef_name
|
||||
ON events.event_definitions( evdef_name_id );
|
||||
CREATE UNIQUE INDEX idx_evdef_template
|
||||
ON events.event_definitions( evdef_template_id );
|
||||
|
||||
ALTER TABLE events.event_definitions
|
||||
ADD CONSTRAINT fk_evdef_name
|
||||
FOREIGN KEY ( evdef_name_id ) REFERENCES defs.strings ,
|
||||
ADD CONSTRAINT fk_evdef_template
|
||||
FOREIGN KEY ( evdef_template_id ) REFERENCES defs.strings;
|
||||
|
||||
GRANT SELECT ON events.event_definitions TO :dbuser;
|
||||
|
||||
|
|
|
@ -24,6 +24,11 @@ CREATE TYPE events.evdef_create_result AS ENUM(
|
|||
* initial creation function and event field definition functions.
|
||||
*/
|
||||
'BAD_ID' ,
|
||||
|
||||
/* An internationalised string (either an event type's name or template)
|
||||
* could not be found.
|
||||
*/
|
||||
'BAD_STRINGS' ,
|
||||
|
||||
/* Duplicate event or field identifier found. This value is returned by
|
||||
* the finalisation function, with its "_fld" set to NULL if the duplicate
|
||||
|
@ -56,17 +61,29 @@ CREATE TYPE events.evdef_create_result AS ENUM(
|
|||
* _prio The event type's default priority
|
||||
* _adj Whether the player may adjust the priority for this type
|
||||
* of events.
|
||||
* _i18n The "base" of the I18N strings identifiers; the function
|
||||
* will attempt to use "<_i18n>Name" as the name's
|
||||
* identifier and "<_i18n>Template" as the template's.
|
||||
*
|
||||
* Returns:
|
||||
* ??? An error code: OK or BAD_ID
|
||||
* (see events.evdef_create_result)
|
||||
*/
|
||||
DROP FUNCTION IF EXISTS events.evdef_start( TEXT , INT , BOOLEAN );
|
||||
CREATE FUNCTION events.evdef_start( _id TEXT , _prio INT , _adj BOOLEAN )
|
||||
DROP FUNCTION IF EXISTS events.evdef_start( TEXT , INT , BOOLEAN , TEXT );
|
||||
CREATE FUNCTION events.evdef_start(
|
||||
_id TEXT ,
|
||||
_prio INT ,
|
||||
_adj BOOLEAN ,
|
||||
_i18n TEXT )
|
||||
RETURNS events.evdef_create_result
|
||||
LANGUAGE PLPGSQL
|
||||
STRICT VOLATILE SECURITY DEFINER
|
||||
AS $evdef_start$
|
||||
|
||||
DECLARE
|
||||
_name_id INT;
|
||||
_template_id INT;
|
||||
|
||||
BEGIN
|
||||
CREATE TEMPORARY TABLE evdef_temp(
|
||||
evdef_id TEXT ,
|
||||
|
@ -77,20 +94,28 @@ BEGIN
|
|||
IF LENGTH( _id ) < 2 OR LENGTH( _id ) > 48
|
||||
OR NOT _id ~ '^[a-z\-]+$'
|
||||
THEN
|
||||
RETURN 'BAD_ID'::events.evdef_create_result;
|
||||
RETURN 'BAD_ID';
|
||||
END IF;
|
||||
|
||||
SELECT INTO _name_id id FROM defs.strings
|
||||
WHERE name = _i18n || 'Name';
|
||||
SELECT INTO _template_id id FROM defs.strings
|
||||
WHERE name = _i18n || 'Template';
|
||||
IF _name_id IS NULL OR _template_id IS NULL THEN
|
||||
RETURN 'BAD_STRINGS';
|
||||
END IF;
|
||||
|
||||
INSERT INTO evdef_temp( evdef_id , evfld_typespec )
|
||||
VALUES( _id , _prio::TEXT || ' , ' || _adj::TEXT );
|
||||
RETURN 'OK'::events.evdef_create_result;
|
||||
RETURN 'OK';
|
||||
END;
|
||||
$evdef_start$;
|
||||
|
||||
REVOKE EXECUTE
|
||||
ON FUNCTION events.evdef_start( TEXT , INT , BOOLEAN )
|
||||
ON FUNCTION events.evdef_start( TEXT , INT , BOOLEAN , TEXT )
|
||||
FROM PUBLIC;
|
||||
GRANT EXECUTE
|
||||
ON FUNCTION events.evdef_start( TEXT , INT , BOOLEAN )
|
||||
ON FUNCTION events.evdef_start( TEXT , INT , BOOLEAN , TEXT )
|
||||
TO :dbuser;
|
||||
|
||||
|
||||
|
|
Reference in a new issue