BxDirFormEntry.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Directory Directory
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Create/Edit entry form
  13. */
  14. class BxDirFormEntry extends BxBaseModTextFormEntry
  15. {
  16. protected $_sGhostTemplateCover = 'form_ghost_template_cover.html';
  17. public function __construct($aInfo, $oTemplate = false)
  18. {
  19. $this->MODULE = 'bx_directory';
  20. parent::__construct($aInfo, $oTemplate);
  21. $CNF = &$this->_oModule->_oConfig->CNF;
  22. $iCategory = 0;
  23. if(bx_get('category') !== false)
  24. $iCategory = (int)bx_get('category');
  25. $this->_initCategoryFields($iCategory);
  26. if(isset($CNF['FIELD_COVER']) && isset($this->aInputs[$CNF['FIELD_COVER']])) {
  27. if($this->_oModule->checkAllowedSetThumb() === CHECK_ACTION_RESULT_ALLOWED) {
  28. $this->aInputs[$CNF['FIELD_COVER']]['storage_object'] = $CNF['OBJECT_STORAGE'];
  29. $this->aInputs[$CNF['FIELD_COVER']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_COVER']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_COVER']]['value']) : $CNF['OBJECT_UPLOADERS'];
  30. $this->aInputs[$CNF['FIELD_COVER']]['upload_buttons_titles'] = array(
  31. 'Simple' => _t('_bx_directory_form_entry_input_covers_uploader_simple_title'),
  32. 'HTML5' => _t('_bx_directory_form_entry_input_covers_uploader_html5_title')
  33. );
  34. $this->aInputs[$CNF['FIELD_COVER']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'];
  35. $this->aInputs[$CNF['FIELD_COVER']]['storage_private'] = 0;
  36. $this->aInputs[$CNF['FIELD_COVER']]['multiple'] = false;
  37. $this->aInputs[$CNF['FIELD_COVER']]['content_id'] = 0;
  38. $this->aInputs[$CNF['FIELD_COVER']]['ghost_template'] = '';
  39. }
  40. else
  41. unset($this->aInputs[$CNF['FIELD_COVER']]);
  42. }
  43. if(isset($CNF['FIELD_PHOTO']) && isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
  44. $this->aInputs[$CNF['FIELD_PHOTO']]['storage_object'] = $CNF['OBJECT_STORAGE_PHOTOS'];
  45. $this->aInputs[$CNF['FIELD_PHOTO']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_PHOTO']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_PHOTO']]['value']) : $CNF['OBJECT_UPLOADERS'];
  46. $this->aInputs[$CNF['FIELD_PHOTO']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS'];
  47. $this->aInputs[$CNF['FIELD_PHOTO']]['storage_private'] = 0;
  48. $this->aInputs[$CNF['FIELD_PHOTO']]['multiple'] = true;
  49. $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = 0;
  50. $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = '';
  51. $this->aInputs[$CNF['FIELD_PHOTO']]['tr_attrs'] = array('class'=> 'bx-base-text-attachment-item');
  52. }
  53. if(isset($this->aInputs[$CNF['FIELD_VIDEO']])) {
  54. $this->aInputs[$CNF['FIELD_VIDEO']]['storage_object'] = $CNF['OBJECT_STORAGE_VIDEOS'];
  55. $this->aInputs[$CNF['FIELD_VIDEO']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_VIDEO']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_VIDEO']]['value']) : $CNF['OBJECT_UPLOADERS'];
  56. $this->aInputs[$CNF['FIELD_VIDEO']]['images_transcoder'] = $CNF['OBJECT_VIDEOS_TRANSCODERS']['poster_preview'];
  57. $this->aInputs[$CNF['FIELD_VIDEO']]['storage_private'] = 0;
  58. $this->aInputs[$CNF['FIELD_VIDEO']]['multiple'] = true;
  59. $this->aInputs[$CNF['FIELD_VIDEO']]['content_id'] = 0;
  60. $this->aInputs[$CNF['FIELD_VIDEO']]['ghost_template'] = '';
  61. $this->aInputs[$CNF['FIELD_VIDEO']]['tr_attrs'] = array('class'=> 'bx-base-text-attachment-item');
  62. }
  63. if (isset($CNF['FIELD_FILE']) && isset($this->aInputs[$CNF['FIELD_FILE']])) {
  64. $this->aInputs[$CNF['FIELD_FILE']]['storage_object'] = $CNF['OBJECT_STORAGE_FILES'];
  65. $this->aInputs[$CNF['FIELD_FILE']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_FILE']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_FILE']]['value']) : $CNF['OBJECT_UPLOADERS'];
  66. $this->aInputs[$CNF['FIELD_FILE']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES'];
  67. $this->aInputs[$CNF['FIELD_FILE']]['storage_private'] = 0;
  68. $this->aInputs[$CNF['FIELD_FILE']]['multiple'] = true;
  69. $this->aInputs[$CNF['FIELD_FILE']]['content_id'] = 0;
  70. $this->aInputs[$CNF['FIELD_FILE']]['ghost_template'] = '';
  71. $this->aInputs[$CNF['FIELD_FILE']]['tr_attrs'] = array('class'=> 'bx-base-text-attachment-item');
  72. }
  73. if(isset($this->aInputs[$CNF['FIELD_POLL']])) {
  74. $this->aInputs[$CNF['FIELD_POLL']]['tr_attrs'] = array('class'=> 'bx-base-text-attachment-item');
  75. }
  76. }
  77. function getCode($bDynamicMode = false)
  78. {
  79. $this->_oModule->_oTemplate->addJs('entry.js');
  80. return $this->_oModule->_oTemplate->getJsCode('entry') . parent::getCode($bDynamicMode);
  81. }
  82. function initChecker ($aValues = array (), $aSpecificValues = array())
  83. {
  84. $CNF = &$this->_oModule->_oConfig->CNF;
  85. $bValues = $aValues && !empty($aValues['id']);
  86. $aContentInfo = $bValues ? $this->_oModule->_oDb->getContentInfoById($aValues['id']) : false;
  87. $this->_initCategoryFields($aContentInfo[$CNF['FIELD_CATEGORY']]);
  88. if(isset($CNF['FIELD_COVER']) && isset($this->aInputs[$CNF['FIELD_COVER']])) {
  89. if($bValues)
  90. $this->aInputs[$CNF['FIELD_COVER']]['content_id'] = $aValues['id'];
  91. $this->aInputs[$CNF['FIELD_COVER']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateCover, $this->_getCoverGhostTmplVars($aContentInfo));
  92. }
  93. parent::initChecker ($aValues, $aSpecificValues);
  94. }
  95. public function insert ($aValsToAdd = array(), $isIgnore = false)
  96. {
  97. $CNF = &$this->_oModule->_oConfig->CNF;
  98. $iContentId = parent::insert ($aValsToAdd, $isIgnore);
  99. if(!empty($iContentId))
  100. $this->processFiles($CNF['FIELD_COVER'], $iContentId, true);
  101. return $iContentId;
  102. }
  103. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  104. {
  105. $CNF = &$this->_oModule->_oConfig->CNF;
  106. $iResult = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  107. $this->processFiles($CNF['FIELD_COVER'], $iContentId, false);
  108. return $iResult;
  109. }
  110. protected function _getCoverGhostTmplVars($aContentInfo = array())
  111. {
  112. $CNF = &$this->_oModule->_oConfig->CNF;
  113. return array (
  114. 'name' => $this->aInputs[$CNF['FIELD_COVER']]['name'],
  115. 'content_id' => $this->aInputs[$CNF['FIELD_COVER']]['content_id'],
  116. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
  117. 'thumb_id' => isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : 0,
  118. 'name_thumb' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : ''
  119. );
  120. }
  121. protected function _getPhotoGhostTmplVars($aContentInfo = array())
  122. {
  123. $CNF = &$this->_oModule->_oConfig->CNF;
  124. return array (
  125. 'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'],
  126. 'content_id' => (int)$this->aInputs[$CNF['FIELD_PHOTO']]['content_id'],
  127. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : ''
  128. );
  129. }
  130. protected function _initCategoryFields($iCategory)
  131. {
  132. $CNF = &$this->_oModule->_oConfig->CNF;
  133. if(isset($CNF['FIELD_CATEGORY']) && isset($this->aInputs[$CNF['FIELD_CATEGORY']]) && $iCategory != 0) {
  134. $this->aInputs[$CNF['FIELD_CATEGORY']]['value'] = $iCategory;
  135. }
  136. if(isset($CNF['FIELD_CATEGORY_VIEW']) && isset($this->aInputs[$CNF['FIELD_CATEGORY_VIEW']]) && $iCategory != 0) {
  137. $aCategory = $this->_oModule->_oDb->getCategories(array('type' => 'id', 'id' => $iCategory));
  138. $this->aInputs[$CNF['FIELD_CATEGORY_VIEW']]['value'] = !empty($aCategory['title']) ? _t($aCategory['title']) : '';
  139. }
  140. if(isset($CNF['FIELD_CATEGORY_SELECT']) && isset($this->aInputs[$CNF['FIELD_CATEGORY_SELECT']])) {
  141. $this->aInputs[$CNF['FIELD_CATEGORY_SELECT']]['values'] = $this->_oModule->serviceGetCategoryOptions(0, true);
  142. }
  143. }
  144. }
  145. /** @} */