BxBaseModProfileFormsEntryHelper.php 4.2 KB

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