1
0

BxBaseModProfileFormsEntryHelper.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. $aContentInfo = array();
  25. $oProfile = false;
  26. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  27. if (!$aContentInfo)
  28. return array (false, false);
  29. $oProfile = BxDolProfile::getInstance($aContentInfo['profile_id']);
  30. if (!$oProfile) {
  31. bx_import('BxDolProfileUndefined');
  32. $oProfile = BxDolProfileUndefined::getInstance();
  33. }
  34. return array ($oProfile, $aContentInfo);
  35. }
  36. protected function onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile)
  37. {
  38. // delete profile
  39. if (!$oProfile->delete($aContentInfo['profile_id']))
  40. return MsgBox(_t('_sys_txt_error_entry_delete'));
  41. return '';
  42. }
  43. protected function onDataEditBefore ($iContentId, $aContentInfo, &$aTrackTextFieldsChanges)
  44. {
  45. $CNF = &$this->_oModule->_oConfig->CNF;
  46. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  47. $aProfileInfo = $oProfile->getInfo();
  48. $isAutoApprove = getParam($CNF['PARAM_AUTOAPPROVAL']) ? true : false;
  49. if (!$isAutoApprove && BX_PROFILE_STATUS_ACTIVE == $aProfileInfo['status'])
  50. $aTrackTextFieldsChanges = array ();
  51. }
  52. protected function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile)
  53. {
  54. $CNF = &$this->_oModule->_oConfig->CNF;
  55. $aProfileInfo = $oProfile->getInfo();
  56. // change profile to 'pending' only if profile is 'active'
  57. $isAutoApprove = getParam($CNF['PARAM_AUTOAPPROVAL']) ? true : false;
  58. if (!$isAutoApprove && BX_PROFILE_STATUS_ACTIVE == $aProfileInfo['status'] && !empty($aTrackTextFieldsChanges['changed_fields']))
  59. $oProfile->disapprove(BX_PROFILE_ACTION_AUTO);
  60. // create an alert
  61. bx_alert($this->_oModule->getName(), 'edited', $aContentInfo[$CNF['FIELD_ID']]);
  62. }
  63. protected function onDataAddAfter ($iContentId)
  64. {
  65. $CNF = &$this->_oModule->_oConfig->CNF;
  66. // add account and content association
  67. $iProfileId = BxDolProfile::add(BX_PROFILE_ACTION_MANUAL, getLoggedId(), $iContentId, BX_PROFILE_STATUS_PENDING, $this->_oModule->getName());
  68. $oProfile = BxDolProfile::getInstance($iProfileId);
  69. // approve profile if auto-approval is enabled and profile status is 'pending'
  70. $sStatus = $oProfile->getStatus();
  71. $isAutoApprove = getParam($CNF['PARAM_AUTOAPPROVAL']) ? true : false;
  72. if ($sStatus == BX_PROFILE_STATUS_PENDING && $isAutoApprove)
  73. $oProfile->approve(BX_PROFILE_ACTION_AUTO);
  74. // set created profile some default membership
  75. bx_import('BxDolAcl');
  76. $iAclLevel = getParam($CNF['PARAM_DEFAULT_ACL_LEVEL']);
  77. BxDolAcl::getInstance()->setMembership($iProfileId, $iAclLevel, 0, true);
  78. // alert
  79. bx_alert($this->_oModule->getName(), 'added', $iContentId);
  80. // switch context to the created profile
  81. bx_import('BxDolAccount');
  82. $oAccount = BxDolAccount::getInstance();
  83. $oAccount->updateProfileContext($iProfileId);
  84. return '';
  85. }
  86. }
  87. /** @} */