BxCoursesFormsEntryHelper.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 Courses Courses
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Group profile forms functions
  13. */
  14. class BxCoursesFormsEntryHelper extends BxBaseModGroupsFormsEntryHelper
  15. {
  16. public function __construct($oModule)
  17. {
  18. parent::__construct($oModule);
  19. }
  20. public function onDataAddAfter($iAccountId, $iContentId)
  21. {
  22. if($s = parent::onDataAddAfter($iAccountId, $iContentId))
  23. return $s;
  24. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oModule->_oConfig->getName());
  25. if(!$oGroupProfile)
  26. return '';
  27. $iAdminProfileId = bx_get_logged_profile_id();
  28. $aInitialProfiles = bx_get('initial_members');
  29. if(!is_array($aInitialProfiles) || !in_array($iAdminProfileId, $aInitialProfiles))
  30. $this->makeAuthorAdmin($oGroupProfile, array($iAdminProfileId));
  31. return '';
  32. }
  33. public function onDataDeleteAfter($iContentId, $aContentInfo, $oProfile)
  34. {
  35. if($s = parent::onDataDeleteAfter($iContentId, $aContentInfo, $oProfile))
  36. return $s;
  37. $aDataItems = $this->_oModule->_oDb->getContentData([
  38. 'sample' => 'entry_id',
  39. 'entry_id' => $iContentId
  40. ]);
  41. if(!empty($aDataItems) && is_array($aDataItems))
  42. foreach($aDataItems as $aDataItem)
  43. if(($sMethod = 'delete_entity') && bx_is_srv($aDataItem['content_type'], $sMethod))
  44. bx_srv($aDataItem['content_type'], $sMethod, [$aDataItem['content_id']]);
  45. $this->_oModule->_oDb->deleteContentDataWithTracks($iContentId);
  46. $this->_oModule->_oDb->deleteContentNodesWithTracks($iContentId);
  47. $this->_oModule->_oDb->deleteContentStructureNode(['entry_id' => $iContentId]);
  48. return '';
  49. }
  50. }
  51. /** @} */