BxBaseStudioFormView.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinView Dolphin Studio Representation classes
  7. * @ingroup DolphinStudio
  8. * @{
  9. */
  10. bx_import('BxDolStudioForm');
  11. class BxBaseStudioFormView extends BxDolStudioForm
  12. {
  13. function __construct($aInfo, $oTemplate)
  14. {
  15. parent::__construct($aInfo, $oTemplate);
  16. }
  17. function addCssJs()
  18. {
  19. parent::addCssJs();
  20. $this->oTemplate->addJs(array(
  21. 'forms.js'
  22. ));
  23. }
  24. function genRow(&$aInput)
  25. {
  26. $sRow = '';
  27. switch($aInput['type']) {
  28. case 'image_uploader':
  29. $sRow = $this->genRowImageUploader($aInput);
  30. break;
  31. default:
  32. $sRow = parent::genRow($aInput);
  33. }
  34. return $sRow;
  35. }
  36. function genInput(&$aInput)
  37. {
  38. $sInput = '';
  39. switch($aInput['type']) {
  40. case 'text_translatable':
  41. $sInput = $this->genInputTranslatable($aInput, 'text');
  42. break;
  43. case 'textarea_translatable':
  44. $aInput['html'] = 0;
  45. $sInput = $this->genInputTranslatable($aInput, 'textarea');
  46. break;
  47. default:
  48. $sInput = parent::genInput($aInput);
  49. }
  50. return $sInput;
  51. }
  52. function genRowImageUploader(&$aInput)
  53. {
  54. $aTmplVarsPreview = array(
  55. 'bx_if:show_empty' => array(
  56. 'condition' => true,
  57. 'content' => array()
  58. ),
  59. 'bx_if:show_image' => array(
  60. 'condition' => false,
  61. 'content' => array()
  62. )
  63. );
  64. if(($iId = (int)$aInput['value']) != 0) {
  65. bx_import('BxDolStorage');
  66. $sStorage = isset($aInput['storage_object']) && $aInput['storage_object'] != '' ? $aInput['storage_object'] : BX_DOL_STORAGE_OBJ_IMAGES;
  67. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  68. $sFileUrl = $oStorage->getFileUrlById($iId);
  69. if($sFileUrl !== false) {
  70. $aTmplVarsPreview['bx_if:show_empty']['condition'] = false;
  71. $aTmplVarsPreview['bx_if:show_image'] = array(
  72. 'condition' => true,
  73. 'content' => array(
  74. 'url' => $sFileUrl,
  75. 'bx_if:show_action_delete' => array(
  76. 'condition' => isset($aInput['ajax_action_delete']) && $aInput['ajax_action_delete'] != "",
  77. 'content' => array(
  78. 'action' => $aInput['ajax_action_delete']
  79. )
  80. )
  81. )
  82. );
  83. }
  84. }
  85. $sRow = '';
  86. $aInputPreview = array(
  87. 'type' => 'custom',
  88. 'name' => 'preview',
  89. 'caption' => isset($aInput['caption_preview']) ? $aInput['caption_preview'] : _t('_adm_txt_form_view_iu_preview'),
  90. 'content' => $this->oTemplate->parseHtmlByName('form_view_iu_preview.html', $aTmplVarsPreview)
  91. );
  92. $sRow .= $this->genRow($aInputPreview);
  93. $aInput['type'] = 'file';
  94. $sRow .= $this->genRow($aInput);
  95. return $sRow;
  96. }
  97. function genInputTranslatable(&$aInput, $sType = 'text')
  98. {
  99. $iValueLength = 20;
  100. $sInputIdPrefix = 'bx-form-input-';
  101. $aInputMethod = array('text' => 'genInputStandard', 'textarea' => 'genInputTextarea');
  102. $sInput = '';
  103. $sInputName = $aInput['name'];
  104. $aInputAttrs = isset($aInput['attrs']) && is_array($aInput['attrs']) ? $aInput['attrs'] : array();
  105. bx_import('BxTemplStudioFunctions');
  106. $oFunctions = BxTemplStudioFunctions::getInstance();
  107. bx_import('BxDolStudioLanguagesUtils');
  108. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  109. $sLanguage = $oLanguage->getCurrentLangName(false);
  110. $aLanguages = $oLanguage->getLanguagesInfo();
  111. $aStrings = $oLanguage->getLanguageString($aInput['value']);
  112. $aInput['type'] = 'hidden';
  113. $aInput['attrs'] = array_merge($aInputAttrs, array(
  114. 'id' => $sInputIdPrefix . $aInput['name']
  115. ));
  116. $sInput .= $this->genInputStandard($aInput);
  117. $aTmplVars = array();
  118. foreach($aLanguages as $aLanguage) {
  119. $bLanguage = $aLanguage['name'] == $sLanguage;
  120. $sValue = '';
  121. if(($bValue = key_exists($aLanguage['id'], $aStrings)) === true)
  122. $sValue = $aStrings[$aLanguage['id']]['string'];
  123. else if(isset($aInput['values'][$aLanguage['name']]))
  124. $sValue = $aInput['values'][$aLanguage['name']];
  125. $aInput['type'] = $sType;
  126. $aInput['name'] = $sInputName . '-' . $aLanguage['name'];
  127. $aInput['value'] = $sValue;
  128. $aInput['attrs'] = array_merge($aInputAttrs, array(
  129. 'id' => $sInputIdPrefix . $aInput['name'],
  130. 'style' => !$bLanguage ? 'display:none;' : ''
  131. ));
  132. $sInput .= $this->$aInputMethod[$sType]($aInput);
  133. $aTmplVarValue = array(
  134. 'condition' => $bValue,
  135. 'content' => array(
  136. 'value' => strmaxtextlen($sValue, $iValueLength)
  137. )
  138. );
  139. $aTmplVarMissing = array(
  140. 'condition' => !$bValue || empty($sValue),
  141. 'content' => array()
  142. );
  143. $aTmplVars[] = array(
  144. 'name' => $sInputName,
  145. 'lang_name' => $aLanguage['name'],
  146. 'lang_flag' => $aLanguage['icon'],
  147. 'lang_title' => $aLanguage['title'],
  148. 'bx_if:hide_active' => array(
  149. 'condition' => !$bLanguage,
  150. 'content' => array()
  151. ),
  152. 'bx_if:act_value' => $aTmplVarValue,
  153. 'bx_if:act_missing' => $aTmplVarMissing,
  154. 'bx_if:hide_passive' => array(
  155. 'condition' => $bLanguage,
  156. 'content' => array()
  157. ),
  158. 'bx_if:pas_value' => $aTmplVarValue,
  159. 'bx_if:pas_missing' => $aTmplVarMissing,
  160. );
  161. }
  162. $sPopup = $this->oTemplate->parseHtmlByName('form_view_translator.html', array('bx_repeat:languages' => $aTmplVars));
  163. $sPopup = $oFunctions->transBox('bx-form-field-translator-popup-' . $sInputName, $sPopup, true);
  164. $aLanguage = $oLanguage->getLanguageInfo($sLanguage);
  165. $sControl = $this->oTemplate->parseHtmlByName('form_view_translatable.html', array(
  166. 'flag' => $aLanguage['icon'],
  167. 'title' => $aLanguage['title'],
  168. 'name' => $sInputName,
  169. 'popup' => $sPopup
  170. ));
  171. return $sInput . $sControl;
  172. }
  173. /**
  174. * Generate Reverse Checkbox Set Element
  175. *
  176. * @param array $aInput
  177. * @return string
  178. */
  179. function genInputCheckboxSet(&$aInput)
  180. {
  181. $aInput['value'] = isset($aInput['value']) && $aInput['value'] && is_array($aInput['value']) ? $aInput['value'] : array();
  182. if(!empty($aInput['reverse']))
  183. $aInput['value'] = array_diff(array_keys($aInput['values']), $aInput['value']);
  184. return parent::genInputCheckboxSet($aInput);
  185. }
  186. }
  187. /** @} */