1
0

BxBaseModTextFormEntry.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 BaseText Base classes for text modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Create/Edit entry form
  13. */
  14. class BxBaseModTextFormEntry extends BxBaseModGeneralFormEntry
  15. {
  16. protected $_sGhostTemplateVideo = 'form_ghost_template_video.html';
  17. protected $_sGhostTemplateFile = 'form_ghost_template_file.html';
  18. public function __construct($aInfo, $oTemplate = false)
  19. {
  20. parent::__construct($aInfo, $oTemplate);
  21. }
  22. function getCode($bDynamicMode = false)
  23. {
  24. $CNF = &$this->_oModule->_oConfig->CNF;
  25. $sResult = parent::getCode($bDynamicMode);
  26. if(!empty($CNF['OBJECT_MENU_ENTRY_ATTACHMENTS']))
  27. $sResult = $this->_oModule->_oTemplate->parseHtmlByContent($sResult, array(
  28. 'attachments_menu' => BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_ENTRY_ATTACHMENTS'])->getCode()
  29. ));
  30. if(isset($CNF['PARAM_POLL_ENABLED']) && $CNF['PARAM_POLL_ENABLED'] === true) {
  31. $sResult .= $this->_oModule->_oTemplate->getJsCode('poll');
  32. $this->_oModule->_oTemplate->addJs(array('polls.js'));
  33. }
  34. return $sResult;
  35. }
  36. function initChecker ($aValues = array (), $aSpecificValues = array())
  37. {
  38. $CNF = &$this->_oModule->_oConfig->CNF;
  39. $bValues = $aValues && !empty($aValues['id']);
  40. $aContentInfo = $bValues ? $this->_oModule->_oDb->getContentInfoById($aValues['id']) : false;
  41. if (isset($CNF['FIELD_VIDEO']) && isset($this->aInputs[$CNF['FIELD_VIDEO']])) {
  42. if ($bValues)
  43. $this->aInputs[$CNF['FIELD_VIDEO']]['content_id'] = $aValues['id'];
  44. $this->aInputs[$CNF['FIELD_VIDEO']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateVideo, $this->_getVideoGhostTmplVars($aContentInfo));
  45. }
  46. if (isset($CNF['FIELD_FILE']) && isset($this->aInputs[$CNF['FIELD_FILE']])) {
  47. if ($bValues)
  48. $this->aInputs[$CNF['FIELD_FILE']]['content_id'] = $aValues['id'];
  49. $this->aInputs[$CNF['FIELD_FILE']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateFile, $this->_getFileGhostTmplVars($aContentInfo));
  50. }
  51. if (isset($CNF['FIELD_POLL']) && isset($this->aInputs[$CNF['FIELD_POLL']])) {
  52. if ($bValues)
  53. $this->aInputs[$CNF['FIELD_POLL']]['content_id'] = $aValues['id'];
  54. }
  55. parent::initChecker ($aValues, $aSpecificValues);
  56. }
  57. protected function genCustomInputAttachments ($aInput)
  58. {
  59. return '__attachments_menu__';
  60. }
  61. protected function genCustomInputPolls ($aInput)
  62. {
  63. $this->_oModule->_oTemplate->addCss(array('polls.css'));
  64. return $this->_oModule->_oTemplate->getPollField(!empty($aInput['content_id']) ? (int)$aInput['content_id'] : 0);
  65. }
  66. public function processPolls ($sFieldPoll, $iContentId = 0)
  67. {
  68. $CNF = &$this->_oModule->_oConfig->CNF;
  69. if (!isset($this->aInputs[$sFieldPoll]))
  70. return true;
  71. $aPollIds = $this->getCleanValue($sFieldPoll);
  72. if(empty($aPollIds) || !is_array($aPollIds))
  73. return true;
  74. $iProfileId = $this->getContentOwnerProfileId($iContentId);
  75. $aPollsDbIds = $this->_oModule->_oDb->getPolls(array('type' => 'content_id_ids', 'content_id' => $iContentId));
  76. //--- Remove deleted
  77. $this->_oModule->_oDb->deletePollsByIds(array_diff($aPollsDbIds, $aPollIds));
  78. //--- Add new
  79. if($iContentId) {
  80. $aPollsAddIds = array_diff($aPollIds, $aPollsDbIds);
  81. foreach($aPollsAddIds as $iPollId)
  82. $this->_oModule->_oDb->updatePolls(array($CNF['FIELD_POLL_CONTENT_ID'] => $iContentId), array($CNF['FIELD_POLL_ID'] => $iPollId, $CNF['FIELD_POLL_CONTENT_ID'] => 0));
  83. }
  84. return true;
  85. }
  86. protected function _getPhotoGhostTmplVars($aContentInfo = array())
  87. {
  88. $CNF = &$this->_oModule->_oConfig->CNF;
  89. return array (
  90. 'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'],
  91. 'content_id' => (int)$this->aInputs[$CNF['FIELD_PHOTO']]['content_id'],
  92. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : ''
  93. );
  94. }
  95. protected function _getVideoGhostTmplVars($aContentInfo = array())
  96. {
  97. $CNF = &$this->_oModule->_oConfig->CNF;
  98. return array (
  99. 'name' => $this->aInputs[$CNF['FIELD_VIDEO']]['name'],
  100. 'content_id' => (int)$this->aInputs[$CNF['FIELD_VIDEO']]['content_id'],
  101. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : ''
  102. );
  103. }
  104. protected function _getFileGhostTmplVars($aContentInfo = array())
  105. {
  106. $CNF = &$this->_oModule->_oConfig->CNF;
  107. return array (
  108. 'name' => $this->aInputs[$CNF['FIELD_FILE']]['name'],
  109. 'content_id' => (int)$this->aInputs[$CNF['FIELD_FILE']]['content_id'],
  110. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : ''
  111. );
  112. }
  113. }
  114. /** @} */