BxBaseModProfileFormsEntryHelper.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. /**
  12. * Profile forms helper functions
  13. */
  14. class BxBaseModProfileFormsEntryHelper extends BxBaseModGeneralFormsEntryHelper
  15. {
  16. protected $_bAutoApproval = false;
  17. public function __construct($oModule)
  18. {
  19. parent::__construct($oModule);
  20. $this->setAutoApproval(isset($oModule->_oConfig->CNF['PARAM_AUTOAPPROVAL']) ? (bool)getParam($oModule->_oConfig->CNF['PARAM_AUTOAPPROVAL']) : true);
  21. }
  22. public function isAutoApproval()
  23. {
  24. return $this->_bAutoApproval;
  25. }
  26. public function setAutoApproval($b)
  27. {
  28. return ($this->_bAutoApproval = $b);
  29. }
  30. protected function _getProfileAndContentData ($iContentId)
  31. {
  32. $aContentInfo = array();
  33. $oProfile = false;
  34. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  35. if (!$aContentInfo)
  36. return array (false, false);
  37. $oProfile = BxDolProfile::getInstance($aContentInfo['profile_id']);
  38. if (!$oProfile)
  39. $oProfile = BxDolProfileUndefined::getInstance();
  40. return array ($oProfile, $aContentInfo);
  41. }
  42. public function deleteData ($iContentId, $aContentInfo = false, $oProfile = null, $oForm = null)
  43. {
  44. if (!$aContentInfo)
  45. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  46. // delete profile
  47. $oProfile = BxDolProfile::getInstance($aContentInfo['profile_id']);
  48. if (!$oProfile->delete())
  49. return _t('_sys_txt_error_entry_delete');
  50. return '';
  51. }
  52. public function deleteDataService ($iContentId, $aContentInfo = false, $oProfile = null, $oForm = null)
  53. {
  54. return parent::deleteData ($iContentId, $aContentInfo, $oProfile, $oForm);
  55. }
  56. public function onDataEditBefore ($iContentId, $aContentInfo, &$aTrackTextFieldsChanges)
  57. {
  58. $CNF = &$this->_oModule->_oConfig->CNF;
  59. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  60. $aProfileInfo = $oProfile->getInfo();
  61. if (!$this->isAutoApproval() && BX_PROFILE_STATUS_ACTIVE == $aProfileInfo['status'])
  62. $aTrackTextFieldsChanges = array ();
  63. }
  64. public function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile)
  65. {
  66. if ($s = parent::onDataEditAfter($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile))
  67. return $s;
  68. $CNF = &$this->_oModule->_oConfig->CNF;
  69. $aProfileInfo = $oProfile->getInfo();
  70. // change profile to 'pending' only if profile is 'active'
  71. if (!$this->isAutoApproval() && BX_PROFILE_STATUS_ACTIVE == $aProfileInfo['status'] && !empty($aTrackTextFieldsChanges['changed_fields']))
  72. $oProfile->disapprove(BX_PROFILE_ACTION_AUTO, 0, $this->_oModule->serviceActAsProfile());
  73. // process uploaded files
  74. $oForm = $this->getObjectFormEdit();
  75. $oForm->processFiles($CNF['FIELD_PICTURE'], $iContentId, false);
  76. $oForm = $this->getObjectFormEdit($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_COVER']);
  77. $oForm->processFiles($CNF['FIELD_COVER'], $iContentId, false);
  78. // create an alert
  79. bx_alert($this->_oModule->getName(), 'edited', $aContentInfo[$CNF['FIELD_ID']]);
  80. return '';
  81. }
  82. public function onDataAddAfter ($iAccountId, $iContentId)
  83. {
  84. if ($s = parent::onDataAddAfter($iAccountId, $iContentId))
  85. return $s;
  86. $CNF = &$this->_oModule->_oConfig->CNF;
  87. // add account and content association
  88. $iProfileId = BxDolProfile::add(BX_PROFILE_ACTION_MANUAL, $iAccountId, $iContentId, BX_PROFILE_STATUS_PENDING, $this->_oModule->getName());
  89. $oProfile = BxDolProfile::getInstance($iProfileId);
  90. // approve profile if auto-approval is enabled and profile status is 'pending'
  91. $sStatus = $oProfile->getStatus();
  92. if ($sStatus == BX_PROFILE_STATUS_PENDING && $this->isAutoApproval())
  93. $oProfile->approve(BX_PROFILE_ACTION_AUTO, 0, $this->_oModule->serviceActAsProfile());
  94. // set created profile some default membership
  95. $iAclLevel = !isset($CNF['PARAM_DEFAULT_ACL_LEVEL']) ? MEMBERSHIP_ID_STANDARD :
  96. (isAdmin() ? MEMBERSHIP_ID_ADMINISTRATOR : getParam($CNF['PARAM_DEFAULT_ACL_LEVEL']));
  97. BxDolAcl::getInstance()->setMembership($iProfileId, $iAclLevel, 0, true);
  98. // process uploaded files
  99. $oForm = $this->getObjectFormAdd();
  100. $oForm->processFiles($CNF['FIELD_PICTURE'], $iContentId, true);
  101. $oForm->processFiles($CNF['FIELD_COVER'], $iContentId, true);
  102. // alert
  103. bx_alert($this->_oModule->getName(), 'added', $iContentId);
  104. // switch context to the created profile
  105. if ($this->_oModule->serviceActAsProfile()) {
  106. $oAccount = BxDolAccount::getInstance($iAccountId);
  107. $oAccount->updateProfileContext($iProfileId);
  108. }
  109. return '';
  110. }
  111. }
  112. /** @} */