1
0

BxBaseModTextFormEntry.php 4.2 KB

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