Source of file FlexiFormConfig.php
Size: 2,039 Bytes - Last Modified: 2021-12-24T06:34:15+00:00
/var/www/docs.ssmods.com/process/src/code/model/FlexiFormConfig.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 | <?php class FlexiFormConfig extends DataObject { private static $db = array( 'FlexiFormID' => 'Int', 'FlexiFormClass' => 'Varchar', 'InitializedFields' => 'Boolean', 'FormIdentifier' => 'Varchar' ); private static $has_one = array( 'Handler' => 'FlexiFormHandler' ); private static $has_many = array( 'HandlerSettings' => 'FlexiFormHandlerSetting' ); public function getFlexi() { return DataObject::get_by_id($this->FlexiFormClass, $this->FlexiFormID); } /** * Shorthand fetching of settings via $flexi->FlexiConf('Setting.<name>') * @see DataObject::relField() */ public function relField($fieldName) { if (strpos($fieldName, '.') !== false) { $relations = explode('.', $fieldName); if ($relations[0] == 'Setting') { return $this->HandlerSettings() ->filter('Setting', $relations[1]) ->first(); } } return parent::relField($fieldName); } public function updateHandlerSettings(Array $settings) { foreach ($settings as $component => $value) { if ($setting = $this->relField("Setting.$component")) { $setting->Value = $value; $setting->write(); } } } protected function onBeforeWrite() { if ($this->exists() && $this->isChanged('HandlerID')) { foreach ($this->HandlerSettings()->filter('HandlerID:not', $this->HandlerID) as $item) { // remove on HasManyList only orphans item. Actually delete it. $item->delete(); } } return parent::onBeforeWrite(); } protected function onBeforeDelete() { foreach ($this->HandlerSettings() as $item) { // remove on HasManyList only orphans item. Actually delete it. $item->delete(); } return parent::onBeforeDelete(); } } |