Development Core SettingDb
From Cloudrexx Development Wiki
Description
The SettingDb class contains (mostly static) methods which make it easier to handle settings for all imaginable intentions. The intention is to use this class as a gateway everywhere in Contrexx where the user can make configurations.
Documentation
Note: For Contrexx versions 5 or newer see article Cx\Core\Setting
Methods
- static function changed()
- TRUE, if minimum one of the loaded setting has been changed (updateAll() will check these)
- static function tab_index($tab_index=null)
- Get or set the current tab
- static function init($section, $group=null)
- Activate or load the setting for a specific module (as the case may be constricted on a given group)
- static function flush()
- Reset the content of the class (forces for example the re-initialization at the next getArray())
- static function getValue($name)
- Returns the value for the setting with the given name
- static function set($name, $value)
- Set the value of the setting with the given name
- static function updateAll()
- Stores the loaded settings into the database (only if minimum one change have been done)
- static function update($name)
- Stores one setting (without check!)
- static function add($name, $value, $ord=false, $type='text', $values=, $group=null)
- Adds a new setting to the group
- This method is only used for an installation script for a new module or will be used in update.
- static function delete($name=null, $group=null)
- Deletes the setting with the given name. Only for advanced users!
- static function show(&$objTemplateLocal, $uriBase, $section=, $tab_name=, $prefix='TXT_')
- Shows the settings in the given template object
- static function show_section(&$objTemplateLocal, $section=, $prefix='TXT_')
- Shows the settings for the given group in the given template object
- TODO: the nomenclature is still old. $section should be $group instead.
- static function show_external(&$objTemplateLocal, $tab_name, $content)
- Includes an external site (e.g. MailTemplates) into the SettingDb view (as a new tab)
Examples
SettingDb::init('shop', 'config'); // All configuration settings from the shop are loaded now $limit = SettingDb::getValue('numof_manufacturers_per_page_backend'); [...] // Fix-or-update-on-the-fly $vat_number = SettingDb::getValue('vat_number'); if (is_null($vat_number)) { SettingDb::add('', '12345678', 1, 'text', '', 'config'); } [...] // Integrate MailTemplates into the shop template $objTemplate = null; $result &= SettingDb::show_external( $objTemplate, $_CORELANG['TXT_CORE_MAILTEMPLATES'], MailTemplate::overview('shop', 'config', SettingDb::getValue('numof_mailtemplate_per_page_backend') )->get() ); $result &= SettingDb::show_external( $objTemplate, (empty($_REQUEST['key']) ? $_CORELANG['TXT_CORE_MAILTEMPLATE_ADD'] : $_CORELANG['TXT_CORE_MAILTEMPLATE_EDIT']), MailTemplate::edit('shop')->get() ); self::$objTemplate->addBlock('SHOP_SETTINGS_FILE', 'settings_block', $objTemplate->get()); [...] SettingDb::set('email', trim(strip_tags(contrexx_input2raw($_POST['email'])))); return (SettingDb::updateAll() !== false); // updateAll() returns NULL on a no-op
More examples can be found in the shop since Contrexx version 3.0