BxMarketFormsEntryHelper.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 Market Market
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Entry forms helper functions
  13. */
  14. class BxMarketFormsEntryHelper extends BxBaseModTextFormsEntryHelper
  15. {
  16. public function __construct($oModule)
  17. {
  18. parent::__construct($oModule);
  19. }
  20. public function onDataAddAfter($iAccountId, $iContentId)
  21. {
  22. $s = parent::onDataAddAfter($iAccountId, $iContentId);
  23. if(!empty($s))
  24. return $s;
  25. $this->associateSubentries($iContentId, bx_get('subentries'));
  26. return '';
  27. }
  28. public function onDataEditAfter($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm)
  29. {
  30. $s = parent::onDataEditAfter($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm);
  31. if(!empty($s))
  32. return $s;
  33. $this->associateSubentries($iContentId, bx_get('subentries'));
  34. return '';
  35. }
  36. public function onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile)
  37. {
  38. $CNF = &$this->_oModule->_oConfig->CNF;
  39. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION_SUBENTRIES']);
  40. if(!$oConnection)
  41. return '';
  42. $oConnection->onDeleteInitiatorAndContent($iContentId);
  43. return '';
  44. }
  45. protected function associateSubentries($iContentId, $aSubentries)
  46. {
  47. $CNF = &$this->_oModule->_oConfig->CNF;
  48. if(empty($aSubentries) || !is_array($aSubentries))
  49. return false;
  50. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION_SUBENTRIES']);
  51. if(!$oConnection)
  52. return false;
  53. $oConnection->onDeleteInitiator((int)$iContentId);
  54. $iProcessed = 0;
  55. foreach($aSubentries as $iSubentry) {
  56. if(!$oConnection->addConnection((int)$iContentId, (int)$iSubentry))
  57. continue;
  58. $iProcessed += 1;
  59. }
  60. return count($aSubentries) == $iProcessed;
  61. }
  62. }
  63. /** @} */