BxBaseModTextFormEntry.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. $sInclude = '';
  32. $sInclude .= $this->_oModule->_oTemplate->addCss(array('polls.css'), $bDynamicMode);
  33. $sInclude .= $this->_oModule->_oTemplate->addJs(array('polls.js'), $bDynamicMode);
  34. $sResult .= ($bDynamicMode ? $sInclude : '') . $this->_oModule->_oTemplate->getJsCode('poll');
  35. }
  36. return $sResult;
  37. }
  38. function initChecker ($aValues = array (), $aSpecificValues = array())
  39. {
  40. $CNF = &$this->_oModule->_oConfig->CNF;
  41. $bValues = $aValues && !empty($aValues['id']);
  42. $aContentInfo = $bValues ? $this->_oModule->_oDb->getContentInfoById($aValues['id']) : false;
  43. if (isset($CNF['FIELD_VIDEO']) && isset($this->aInputs[$CNF['FIELD_VIDEO']])) {
  44. if ($bValues)
  45. $this->aInputs[$CNF['FIELD_VIDEO']]['content_id'] = $aValues['id'];
  46. $this->aInputs[$CNF['FIELD_VIDEO']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateVideo, $this->_getVideoGhostTmplVars($aContentInfo));
  47. }
  48. if (isset($CNF['FIELD_FILE']) && isset($this->aInputs[$CNF['FIELD_FILE']])) {
  49. if ($bValues)
  50. $this->aInputs[$CNF['FIELD_FILE']]['content_id'] = $aValues['id'];
  51. $this->aInputs[$CNF['FIELD_FILE']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateFile, $this->_getFileGhostTmplVars($aContentInfo));
  52. }
  53. if (isset($CNF['FIELD_POLL']) && isset($this->aInputs[$CNF['FIELD_POLL']])) {
  54. if ($bValues)
  55. $this->aInputs[$CNF['FIELD_POLL']]['content_id'] = $aValues['id'];
  56. }
  57. parent::initChecker ($aValues, $aSpecificValues);
  58. }
  59. protected function genCustomInputAttachments ($aInput)
  60. {
  61. return '__attachments_menu__';
  62. }
  63. protected function genCustomInputPolls ($aInput)
  64. {
  65. return $this->_oModule->_oTemplate->getPollField(!empty($aInput['content_id']) ? (int)$aInput['content_id'] : 0);
  66. }
  67. public function processPolls ($sFieldPoll, $iContentId = 0)
  68. {
  69. $CNF = &$this->_oModule->_oConfig->CNF;
  70. if (!isset($this->aInputs[$sFieldPoll]))
  71. return true;
  72. $aPollIds = $this->getCleanValue($sFieldPoll);
  73. if(empty($aPollIds) || !is_array($aPollIds))
  74. return true;
  75. $iProfileId = $this->getContentOwnerProfileId($iContentId);
  76. $aPollsDbIds = $this->_oModule->_oDb->getPolls(array('type' => 'content_id_ids', 'content_id' => $iContentId));
  77. //--- Remove deleted
  78. $this->_oModule->_oDb->deletePollsByIds(array_diff($aPollsDbIds, $aPollIds));
  79. //--- Add new
  80. if($iContentId) {
  81. $aPollsAddIds = array_diff($aPollIds, $aPollsDbIds);
  82. foreach($aPollsAddIds as $iPollId)
  83. $this->_oModule->_oDb->updatePolls(array($CNF['FIELD_POLL_CONTENT_ID'] => $iContentId), array($CNF['FIELD_POLL_ID'] => $iPollId, $CNF['FIELD_POLL_CONTENT_ID'] => 0));
  84. }
  85. return true;
  86. }
  87. protected function _getVideoGhostTmplVars($aContentInfo = array())
  88. {
  89. $CNF = &$this->_oModule->_oConfig->CNF;
  90. return array (
  91. 'name' => $this->aInputs[$CNF['FIELD_VIDEO']]['name'],
  92. 'content_id' => (int)$this->aInputs[$CNF['FIELD_VIDEO']]['content_id'],
  93. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : ''
  94. );
  95. }
  96. protected function _getFileGhostTmplVars($aContentInfo = array())
  97. {
  98. $CNF = &$this->_oModule->_oConfig->CNF;
  99. return array (
  100. 'name' => $this->aInputs[$CNF['FIELD_FILE']]['name'],
  101. 'content_id' => (int)$this->aInputs[$CNF['FIELD_FILE']]['content_id'],
  102. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : ''
  103. );
  104. }
  105. }
  106. /** @} */