1
0

BxBaseModProfileInstaller.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModProfileInstaller extends BxBaseModGeneralInstaller
  12. {
  13. protected $_sParamRelations;
  14. protected $_sParamDefaultProfileType;
  15. function __construct($aConfig)
  16. {
  17. parent::__construct($aConfig);
  18. $this->_sParamRelations = 'sys_relations';
  19. $this->_sParamDefaultProfileType = 'sys_account_default_profile_type';
  20. }
  21. function enable($aParams)
  22. {
  23. $aResult = parent::enable($aParams);
  24. if(BxDolService::call($this->_aConfig['name'], 'act_as_profile') !== true)
  25. return $aResult;
  26. if($aResult['result'] && getParam($this->_sParamDefaultProfileType) == '')
  27. setParam($this->_sParamDefaultProfileType, $this->_aConfig['name']);
  28. return $aResult;
  29. }
  30. function disable($aParams)
  31. {
  32. $aResult = parent::disable($aParams);
  33. if(BxDolService::call($this->_aConfig['name'], 'act_as_profile') !== true)
  34. return $aResult;
  35. $sName = $this->_aConfig['name'];
  36. if($aResult['result'] && getParam($this->_sParamDefaultProfileType) == $sName)
  37. setParam($this->_sParamDefaultProfileType, '');
  38. if($aResult['result']) {
  39. $sDiv = ',';
  40. $sRelations = getParam($this->_sParamRelations);
  41. if(!empty($sRelations) && strpos($sRelations, $sName) !== false) {
  42. $aRelations = explode($sDiv, $sRelations);
  43. foreach($aRelations as $iIndex => $sValue)
  44. if(strpos($sValue, $sName) !== false)
  45. unset($aRelations[$iIndex]);
  46. setParam($this->_sParamRelations, implode($sDiv, $aRelations));
  47. }
  48. }
  49. if ($aResult['result']) { // disabling was successful
  50. // TODO: switch accounts context which active profiles belong to this module
  51. }
  52. return $aResult;
  53. }
  54. }
  55. /** @} */