BxTasksFormsEntryHelper.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. * @defgroup Tasks Tasks
  6. * @ingroup UnaModules
  7. *
  8. * @{
  9. */
  10. /**
  11. * Entry forms helper functions
  12. */
  13. class BxTasksFormsEntryHelper extends BxBaseModTextFormsEntryHelper
  14. {
  15. public function __construct($oModule)
  16. {
  17. parent::__construct($oModule);
  18. }
  19. public function onDataEditBefore ($iContentId, $aContentInfo, &$aTrackTextFieldsChanges, &$oProfile, &$oForm)
  20. {
  21. parent::onDataEditBefore ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm);
  22. $aTrackTextFieldsChanges = [];
  23. }
  24. public function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm)
  25. {
  26. if($s = parent::onDataEditAfter($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm))
  27. return $s;
  28. if(!($aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId)))
  29. return MsgBox(_t('_sys_txt_error_occured'));
  30. $CNF = &$this->_oModule->_oConfig->CNF;
  31. $aFldLoc2Repo = [
  32. $CNF['FIELD_TITLE'] => 'title',
  33. $CNF['FIELD_TEXT'] => 'body',
  34. $CNF['FIELD_STICKERS'] => 'labels',
  35. $CNF['FIELD_TYPE'] => 'type',
  36. ];
  37. $aFields = [];
  38. if(($aLocFields = $aTrackTextFieldsChanges['changed_fields'] ?? false) && is_array($aLocFields))
  39. foreach($aLocFields as $sLocField)
  40. if(($sRepoField = $aFldLoc2Repo[$sLocField] ?? false)) {
  41. $iContextId = ($iContextId = (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) < 0 ? abs($iContextId) : 0;
  42. switch($sLocField) {
  43. case $CNF['FIELD_STICKERS']:
  44. $aStickers = $this->_oModule->getStickers($aContentInfo[$sLocField], $iContextId);
  45. if($aStickers && is_array($aStickers)) {
  46. $aFields[$sRepoField] = [];
  47. foreach($aStickers as $aSticker)
  48. $aFields[$sRepoField][] = $aSticker['title'];
  49. }
  50. break;
  51. case $CNF['FIELD_TYPE']:
  52. $aFields[$sRepoField] = $this->_oModule->getType($aContentInfo[$sLocField], $iContextId);
  53. break;
  54. default:
  55. $aFields[$sRepoField] = $aContentInfo[$sLocField];
  56. }
  57. }
  58. if($aFields)
  59. $this->_oModule->ghUpdateIssue($aContentInfo, $aFields);
  60. return '';
  61. }
  62. protected function redirectAfterDelete($aContentInfo, $sUrl = '')
  63. {
  64. $CNF = &$this->_oModule->_oConfig->CNF;
  65. if((int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0)
  66. $sUrl = 'page.php?i=' . $CNF['URI_ENTRIES_BY_CONTEXT'] . '&profile_id=' . abs($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  67. return parent::redirectAfterDelete($aContentInfo, $sUrl);
  68. }
  69. public function onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile)
  70. {
  71. $s = parent::onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile);
  72. if(!empty($s))
  73. return $s;
  74. $CNF = &$this->_oModule->_oConfig->CNF;
  75. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTION']);
  76. $oConnection->onDeleteContent($iContentId);
  77. return '';
  78. }
  79. }
  80. /** @} */