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:
Emmanuel BENOîT 2012-06-29 17:31:14 +02:00
parent 8f2fd29c71
commit a6562052d3
2 changed files with 53 additions and 7 deletions

View file

@ -24,7 +24,17 @@ CREATE TABLE events.event_definitions(
CHECK( evdef_priority BETWEEN 0 AND 4 ) , CHECK( evdef_priority BETWEEN 0 AND 4 ) ,
/* Whether the priority for this type of event may be adjusted */ /* 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 /* 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 CREATE UNIQUE INDEX idx_evdef_adjustables
ON events.event_definitions( evdef_id , evdef_adjustable ); 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; GRANT SELECT ON events.event_definitions TO :dbuser;

View file

@ -24,6 +24,11 @@ CREATE TYPE events.evdef_create_result AS ENUM(
* initial creation function and event field definition functions. * initial creation function and event field definition functions.
*/ */
'BAD_ID' , '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 /* Duplicate event or field identifier found. This value is returned by
* the finalisation function, with its "_fld" set to NULL if the duplicate * 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 * _prio The event type's default priority
* _adj Whether the player may adjust the priority for this type * _adj Whether the player may adjust the priority for this type
* of events. * 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: * Returns:
* ??? An error code: OK or BAD_ID * ??? An error code: OK or BAD_ID
* (see events.evdef_create_result) * (see events.evdef_create_result)
*/ */
DROP FUNCTION IF EXISTS events.evdef_start( TEXT , INT , BOOLEAN ); DROP FUNCTION IF EXISTS events.evdef_start( TEXT , INT , BOOLEAN , TEXT );
CREATE FUNCTION events.evdef_start( _id TEXT , _prio INT , _adj BOOLEAN ) CREATE FUNCTION events.evdef_start(
_id TEXT ,
_prio INT ,
_adj BOOLEAN ,
_i18n TEXT )
RETURNS events.evdef_create_result RETURNS events.evdef_create_result
LANGUAGE PLPGSQL LANGUAGE PLPGSQL
STRICT VOLATILE SECURITY DEFINER STRICT VOLATILE SECURITY DEFINER
AS $evdef_start$ AS $evdef_start$
DECLARE
_name_id INT;
_template_id INT;
BEGIN BEGIN
CREATE TEMPORARY TABLE evdef_temp( CREATE TEMPORARY TABLE evdef_temp(
evdef_id TEXT , evdef_id TEXT ,
@ -77,20 +94,28 @@ BEGIN
IF LENGTH( _id ) < 2 OR LENGTH( _id ) > 48 IF LENGTH( _id ) < 2 OR LENGTH( _id ) > 48
OR NOT _id ~ '^[a-z\-]+$' OR NOT _id ~ '^[a-z\-]+$'
THEN THEN
RETURN 'BAD_ID'::events.evdef_create_result; RETURN 'BAD_ID';
END IF; 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 ) INSERT INTO evdef_temp( evdef_id , evfld_typespec )
VALUES( _id , _prio::TEXT || ' , ' || _adj::TEXT ); VALUES( _id , _prio::TEXT || ' , ' || _adj::TEXT );
RETURN 'OK'::events.evdef_create_result; RETURN 'OK';
END; END;
$evdef_start$; $evdef_start$;
REVOKE EXECUTE REVOKE EXECUTE
ON FUNCTION events.evdef_start( TEXT , INT , BOOLEAN ) ON FUNCTION events.evdef_start( TEXT , INT , BOOLEAN , TEXT )
FROM PUBLIC; FROM PUBLIC;
GRANT EXECUTE GRANT EXECUTE
ON FUNCTION events.evdef_start( TEXT , INT , BOOLEAN ) ON FUNCTION events.evdef_start( TEXT , INT , BOOLEAN , TEXT )
TO :dbuser; TO :dbuser;