BxBaseModTextFormEntry.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. public function __construct($aInfo, $oTemplate = false)
  18. {
  19. parent::__construct($aInfo, $oTemplate);
  20. }
  21. function getCode($bDynamicMode = false)
  22. {
  23. $CNF = &$this->_oModule->_oConfig->CNF;
  24. $sResult = parent::getCode($bDynamicMode);
  25. if(!empty($CNF['OBJECT_MENU_ENTRY_ATTACHMENTS']))
  26. $sResult = $this->_oModule->_oTemplate->parseHtmlByContent($sResult, array(
  27. 'attachments_menu' => BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_ENTRY_ATTACHMENTS'])->getCode()
  28. ));
  29. if(isset($CNF['PARAM_POLL_ENABLED']) && $CNF['PARAM_POLL_ENABLED'] === true) {
  30. $sResult .= $this->_oModule->_oTemplate->getJsCode('poll');
  31. $this->_oModule->_oTemplate->addJs(array('polls.js'));
  32. }
  33. return $sResult;
  34. }
  35. function initChecker ($aValues = array (), $aSpecificValues = array())
  36. {
  37. $CNF = &$this->_oModule->_oConfig->CNF;
  38. $bValues = $aValues && !empty($aValues['id']);
  39. $aContentInfo = $bValues ? $this->_oModule->_oDb->getContentInfoById($aValues['id']) : false;
  40. if (isset($CNF['FIELD_VIDEO']) && isset($this->aInputs[$CNF['FIELD_VIDEO']])) {
  41. if ($bValues)
  42. $this->aInputs[$CNF['FIELD_VIDEO']]['content_id'] = $aValues['id'];
  43. $this->aInputs[$CNF['FIELD_VIDEO']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateVideo, $this->_getVideoGhostTmplVars($aContentInfo));
  44. }
  45. if (isset($CNF['FIELD_POLL']) && isset($this->aInputs[$CNF['FIELD_POLL']])) {
  46. if ($bValues)
  47. $this->aInputs[$CNF['FIELD_POLL']]['content_id'] = $aValues['id'];
  48. }
  49. parent::initChecker ($aValues, $aSpecificValues);
  50. }
  51. protected function genCustomInputAttachments ($aInput)
  52. {
  53. return '__attachments_menu__';
  54. }
  55. protected function genCustomInputPolls ($aInput)
  56. {
  57. $this->_oModule->_oTemplate->addCss(array('polls.css'));
  58. return $this->_oModule->_oTemplate->getPollField(!empty($aInput['content_id']) ? (int)$aInput['content_id'] : 0);
  59. }
  60. public function processPolls ($sFieldPoll, $iContentId = 0)
  61. {
  62. $CNF = &$this->_oModule->_oConfig->CNF;
  63. if (!isset($this->aInputs[$sFieldPoll]))
  64. return true;
  65. $aPollIds = $this->getCleanValue($sFieldPoll);
  66. if(empty($aPollIds) || !is_array($aPollIds))
  67. return true;
  68. $iProfileId = $this->getContentOwnerProfileId($iContentId);
  69. $aPollsDbIds = $this->_oModule->_oDb->getPolls(array('type' => 'content_id_ids', 'content_id' => $iContentId));
  70. //--- Remove deleted
  71. $this->_oModule->_oDb->deletePollsByIds(array_diff($aPollsDbIds, $aPollIds));
  72. //--- Add new
  73. if($iContentId) {
  74. $aPollsAddIds = array_diff($aPollIds, $aPollsDbIds);
  75. foreach($aPollsAddIds as $iPollId)
  76. $this->_oModule->_oDb->updatePolls(array($CNF['FIELD_POLL_CONTENT_ID'] => $iContentId), array($CNF['FIELD_POLL_ID'] => $iPollId, $CNF['FIELD_POLL_CONTENT_ID'] => 0));
  77. }
  78. return true;
  79. }
  80. protected function _getVideoGhostTmplVars($aContentInfo = array())
  81. {
  82. $CNF = &$this->_oModule->_oConfig->CNF;
  83. return array (
  84. 'name' => $this->aInputs[$CNF['FIELD_VIDEO']]['name'],
  85. 'content_id' => (int)$this->aInputs[$CNF['FIELD_VIDEO']]['content_id'],
  86. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : ''
  87. );
  88. }
  89. }
  90. /** @} */