BxBaseModProfileFormsEntryHelper.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup BaseProfile Base classes for profile modules
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxBaseModGeneralFormsEntryHelper');
  12. bx_import('BxDolProfile');
  13. /**
  14. * Profile forms helper functions
  15. */
  16. class BxBaseModProfileFormsEntryHelper extends BxBaseModGeneralFormsEntryHelper
  17. {
  18. public function __construct($oModule)
  19. {
  20. parent::__construct($oModule);
  21. }
  22. protected function _getProfileAndContentData ($iContentId)
  23. {
  24. $CNF = &$this->_oModule->_oConfig->CNF;
  25. $aContentInfo = array();
  26. $oProfile = false;
  27. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  28. if (!$aContentInfo)
  29. return array (false, false);
  30. $oProfile = BxDolProfile::getInstance($aContentInfo['profile_id']);
  31. if (!$oProfile) {
  32. bx_import('BxDolProfileUndefined');
  33. $oProfile = BxDolProfileUndefined::getInstance();
  34. }
  35. return array ($oProfile, $aContentInfo);
  36. }
  37. protected function onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile)
  38. {
  39. // delete profile
  40. if (!$oProfile->delete($aContentInfo['profile_id']))
  41. return MsgBox(_t('_sys_txt_error_entry_delete'));
  42. return '';
  43. }
  44. protected function onDataEditBefore ($iContentId, $aContentInfo, &$aTrackTextFieldsChanges)
  45. {
  46. $CNF = &$this->_oModule->_oConfig->CNF;
  47. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  48. $aProfileInfo = $oProfile->getInfo();
  49. $isAutoApprove = getParam($CNF['PARAM_AUTOAPPROVAL']) ? true : false;
  50. if (!$isAutoApprove && BX_PROFILE_STATUS_ACTIVE == $aProfileInfo['status'])
  51. $aTrackTextFieldsChanges = array ();
  52. }
  53. protected function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile)
  54. {
  55. $CNF = &$this->_oModule->_oConfig->CNF;
  56. $aProfileInfo = $oProfile->getInfo();
  57. // change profile to 'pending' only if profile is 'active'
  58. $isAutoApprove = getParam($CNF['PARAM_AUTOAPPROVAL']) ? true : false;
  59. if (!$isAutoApprove && BX_PROFILE_STATUS_ACTIVE == $aProfileInfo['status'] && !empty($aTrackTextFieldsChanges['changed_fields']))
  60. $oProfile->disapprove(BX_PROFILE_ACTION_AUTO);
  61. // create an alert
  62. bx_alert($this->_oModule->getName(), 'edited', $aContentInfo[$CNF['FIELD_ID']]);
  63. }
  64. protected function onDataAddAfter ($iContentId)
  65. {
  66. $CNF = &$this->_oModule->_oConfig->CNF;
  67. // add account and content association
  68. $iProfileId = BxDolProfile::add(BX_PROFILE_ACTION_MANUAL, getLoggedId(), $iContentId, BX_PROFILE_STATUS_PENDING, $this->_oModule->getName());
  69. $oProfile = BxDolProfile::getInstance($iProfileId);
  70. // approve profile if auto-approval is enabled and profile status is 'pending'
  71. $sStatus = $oProfile->getStatus();
  72. $isAutoApprove = getParam($CNF['PARAM_AUTOAPPROVAL']) ? true : false;
  73. if ($sStatus == BX_PROFILE_STATUS_PENDING && $isAutoApprove)
  74. $oProfile->approve(BX_PROFILE_ACTION_AUTO);
  75. // set created profile some default membership
  76. bx_import('BxDolAcl');
  77. $iAclLevel = getParam($CNF['PARAM_DEFAULT_ACL_LEVEL']);
  78. BxDolAcl::getInstance()->setMembership($iProfileId, $iAclLevel, 0, true);
  79. // alert
  80. bx_alert($this->_oModule->getName(), 'added', $iContentId);
  81. // switch context to the created profile
  82. bx_import('BxDolAccount');
  83. $oAccount = BxDolAccount::getInstance();
  84. $oAccount->updateProfileContext($iProfileId);
  85. return '';
  86. }
  87. }
  88. /** @} */