Go to main content

Package sed_dev_util

Package sed_dev_util

2022-05-31 - 3 new functions

  • validate_field()
  • languify()
  • get_languages()

Function validate_field

Return the field type if the given `field` is found for the given `table`

Parameters

  • table (string): A valid table name found in sed_dev_table
  • field (string): A valid field name found in sed_dev_field for the given table name

 

Examples

Take a table ps_patient:

desc ps_patient

Field Type Null Key Default Extra
uid int(11) NO PRI   auto_increment
sn_cdate datetime YES      
sn_mdate datetime YES      
sn_cuid int(11) YES      
sn_muid int(11) YES      
uuid varchar(255) NO MUL    
last_name varchar(255) NO MUL    
middle_name varchar(255) YES      
first_name varchar(255) NO MUL    
nickname varchar(255) YES      
gender varchar(255) YES      
address1 varchar(255) YES      
address2 varchar(255) YES      
city varchar(255) YES      
country varchar(5) YES    

 

field_format = sed_dev_util::validate_field("ps_patient", "last_name");

Result: field_format eq "varchar";

field_format = sed_dev_util::validate_field("ps_patient", "bad_field");

Result: field_format == undefined

Function languify

Returns the original context(s) with the multi lingual fields for the given language

Parameters

  • table (string): A valid table name from sed_dev_table
  • entries (context|array of contexts): A context or an array of context representing an entries of the given table
  • lg (string): A valid language code. Ex: "fr"
  • keep_original (bool): Default to false and will remove any fields suffixed with a language code. Ex "name_en", "name_fr" will be removed and replaced by "name"

Examples

entries = {"name_en": "My module", "name_fr": "Mon module", "version": "2"};
sed_dev_util::languify("sed_mod", entries, "en");

Results: {"name": "My module", "version": "2"}

entries = {"name_en": "My module", "name_fr": "Mon module", "version": "2"};  
sed_dev_util::languify("sed_mod", entries, "en", keep_original: true);

Results: {"name": "My module", "name_en": "My module", "name_fr": "Mon module", "version": "2"}

entries = [ {"name_en": "My module", "name_fr": "Mon module", "version": "2"},
 {"name_en": "My other module", "name_fr": "Mon autre module", "version": "1.2"}
];sed_dev_util::languify("sed_mod", entries, "en");

Results: [{"version":"2","name":"My module"},{"name":"My other module","version":"1.2"}]

Function get_languages

Return an array of lg codes for the given table name

Parameters

  • table (string): A valid `table` name in sed_dev_table

Examples

Using the table ps_patient which is set to use the sed_site_lg table with languages en, fr, and de

table_lgs = sed_dev_util::get_languages("ps_patient");table_lgs;

Results: ["en","fr","de"]

Edit

© 2024 extenso Inc. All rights reserved.