BxSpacesModule.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. * @defdroup Spaces Spaces
  7. * @indroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Spaces profiles module.
  13. */
  14. define('BX_SPS_LEVELS_LIMIT', 1);
  15. class BxSpacesModule extends BxBaseModGroupsModule
  16. {
  17. function __construct(&$aModule)
  18. {
  19. parent::__construct($aModule);
  20. $this->_aSearchableNamesExcept[] = $this->_oConfig->CNF['FIELD_JOIN_CONFIRMATION'];
  21. }
  22. public function serviceGetSafeServices()
  23. {
  24. $a = parent::serviceGetSafeServices();
  25. return array_merge($a, array (
  26. 'BrowseTopLevel' => '',
  27. ));
  28. }
  29. public function serviceEntityDelete ($iContentId = 0)
  30. {
  31. $iContentId = $this->_getContent($iContentId, false);
  32. if($iContentId === false)
  33. return false;
  34. $iCount = $this->_oDb->getCountEntriesByParent($iContentId);
  35. if($iCount > 0 && ($sMsg = '_bx_spaces_err_delete_child_presend'))
  36. return !$this->_bIsApi ? MsgBox(_t($sMsg)) : [bx_api_get_msg($sMsg)];
  37. $mixedResult = $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  38. if(!$this->_bIsApi)
  39. return $mixedResult;
  40. $aResult = [];
  41. if(is_a($mixedResult, 'BxTemplFormView'))
  42. $aResult = bx_api_get_block('form', $mixedResult->getCodeAPI(), ['ext' => ['name' => $this->getName(), 'request' => ['url' => '/api.php?r=' . $this->_aModule['name'] . '/entity_delete&params[]=' . $iContentId . '&params[]=' . $mixedResult->aParams['display'], 'immutable' => true]]]);
  43. else
  44. $aResult = $mixedResult;
  45. return [
  46. $aResult
  47. ];
  48. }
  49. public function serviceEntityParent ($iContentId = 0, $aParams = [])
  50. {
  51. return $this->_serviceTemplateFuncEx ('entryParent', $iContentId, $aParams);
  52. }
  53. public function serviceEntityChilds ($iContentId = 0, $aParams = [])
  54. {
  55. return $this->_serviceTemplateFuncEx ('entryChilds', $iContentId, $aParams);
  56. }
  57. public function serviceBrowseTopLevel ($bDisplayEmptyMsg = false)
  58. {
  59. return $this->_serviceBrowse ('top_level', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  60. }
  61. /**
  62. * Get possible recipients for start conversation form
  63. */
  64. public function actionAjaxGetParentSpace ()
  65. {
  66. $sTerm = bx_get('term');
  67. $iContentId = bx_get('id');
  68. $a = $this->getListSpacesForParent($sTerm, $iContentId, 10);
  69. header('Content-Type:text/javascript; charset=utf-8');
  70. echo(json_encode($a));
  71. }
  72. public function getListSpacesForParent ($sTerm, $iContentId, $iLimit)
  73. {
  74. $CNF = &$this->_oConfig->CNF;
  75. if (!isLogged())
  76. return false;
  77. $iLevelsLimit = BX_SPS_LEVELS_LIMIT;
  78. if(getParam($CNF['PARAM_MULTILEVEL_HIERARCHY']) == 'on')
  79. $iLevelsLimit = 0;
  80. $aRv = array();
  81. $aTmp = $this->_oDb->searchByTermForParentSpace(bx_get_logged_profile_id(), $iContentId, $iLevelsLimit, $sTerm, $iLimit);
  82. foreach ($aTmp as $aSpace) {
  83. $oProfile = BxDolProfile::getInstance($aSpace['profile_id']);
  84. $aRv[] = array (
  85. 'label' => $this->serviceProfileName($aSpace['content_id']),
  86. 'value' => $aSpace['profile_id'],
  87. 'url' => $oProfile->getUrl(),
  88. 'thumb' => $oProfile->getThumb(),
  89. 'unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  90. );
  91. }
  92. return $aRv;
  93. }
  94. public function _modGroupsCheckAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  95. {
  96. return parent::_modProfileCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  97. }
  98. }
  99. /** @} */