| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup Developer Developer
- * @ingroup UnaModules
- *
- * @{
- */
- class BxDevFunctions
- {
- function __construct() {}
- /*
- * Is needed to change fields in "Form's Field" creation form.
- * When the form is inited.
- *
- * @see BxDevFormsField
- */
- public static function changeFormField($aParams, $aInputs, $oDb)
- {
- $aInputs['module']['type'] = 'select';
- $aInputs['module']['values'] = array_merge(array('' => _t('_bx_dev_frm_txt_select_module')), BxDolStudioUtils::getModules());
- $aInputs['module']['value'] = $aParams['module'];
- $aInputs['object']['type'] = 'select';
- $aInputs['object']['value'] = $aParams['object'];
- $aInputs['object']['values'] = array();
- foreach(['caption_system', 'caption'] as $sField)
- if(isset($aInputs[$sField]))
- $aInputs[$sField]['caption'] = _t('_bx_dev_frm_txt_field_title_' . $sField);
- $aForms = array();
- $oDb->getForms(array('type' => 'by_module', 'value' => $aParams['module']), $aForms, false);
- if(!empty($aForms) && is_array($aForms)) {
- foreach($aForms as $aForm)
- $aInputs['object']['values'][$aForm['object']] = _t($aForm['title']);
- asort($aInputs['object']['values']);
- }
- $aInputs['object']['values'] = array_merge(array('' => _t('_bx_dev_frm_txt_select_object')), $aInputs['object']['values']);
- $aInputs['name']['type'] = 'text';
- $sTrlTypePostfix = '_translatable';
- $sTrlCheckFuncPostfix = 'Translatable';
- foreach($aInputs as $sName => $aInput)
- if(isset($aInput['type']) && stripos($aInput['type'], $sTrlTypePostfix) !== false) {
- $aInputs[$sName]['type'] = 'text';
- $aInputs[$sName]['html'] = 0;
- if(isset($aInput['checker']['func']) && stripos($aInput['checker']['func'], $sTrlCheckFuncPostfix) !== false)
- $aInputs[$sName]['checker']['func'] = str_ireplace($sTrlCheckFuncPostfix, '', $aInput['checker']['func']);
- }
- unset($aInputs['required']['attrs']['onchange']);
- unset($aInputs['checker_func']['attrs']['disabled'], $aInputs['checker_func']['tr_attrs']['style']);
- unset($aInputs['checker_error']['attrs']['disabled'], $aInputs['checker_error']['tr_attrs']['style']);
- $aFields = array(
- 'editable' => array(
- 'type' => 'switcher',
- 'name' => 'editable',
- 'caption' => _t('_bx_dev_frm_txt_field_title_editable'),
- 'info' => _t('_bx_dev_frm_txt_field_info_editable'),
- 'value' => '1',
- 'required' => '0',
- 'db' => array (
- 'pass' => 'Int',
- )
- ),
- 'deletable' => array(
- 'type' => 'switcher',
- 'name' => 'deletable',
- 'caption' => _t('_bx_dev_frm_txt_field_title_deletable'),
- 'info' => _t('_bx_dev_frm_txt_field_info_deletable'),
- 'value' => '1',
- 'required' => '0',
- 'db' => array (
- 'pass' => 'Int',
- )
- ),
- );
- $aInputs = BxDolStudioUtils::addInArray($aInputs, 'controls', $aFields, false);
- return $aInputs;
- }
- /*
- * Is needed to change form's array in "Form's Field" add/edit form.
- * It's called just before the form is displayed with "getCode" method.
- *
- * @see BxDevFormsField
- */
- public static function changeForm($sAction, $aForm, $oForm)
- {
- switch($sAction) {
- case 'add':
- break;
- case 'edit':
- if(isset($aForm['inputs']['checker_func'])) {
- if(isset($aForm['inputs']['checker_func']['attrs']['disabled']))
- unset($aForm['inputs']['checker_func']['attrs']['disabled']);
- $sCfValue = $aForm['inputs']['checker_func']['value'];
- if(!empty($sCfValue) && !in_array($sCfValue, $oForm->getCheckFunctions()))
- $aForm['inputs']['checker_func']['info'] = _t('_adm_form_txt_field_checker_func_info_custom');
- }
- break;
- }
- return $aForm;
- }
- public static function serializeString($sValue)
- {
- if(empty($sValue))
- return '';
- $aValue = array();
- @eval("\$aValue = " . $sValue . ";");
- if(empty($aValue) || !is_array($aValue))
- return '';
- return serialize($aValue);
- }
- public static function unserializeString($sValue)
- {
- if(empty($sValue))
- return '';
- $aValue = @unserialize($sValue);
- if(empty($aValue) || !is_array($aValue))
- return '';
- return var_export($aValue, true);
- }
- }
- /** @} */
|