1
0

BxBaseModGroupsModule.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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 BaseGroups Base classes for groups modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Groups profiles module.
  13. */
  14. class BxBaseModGroupsModule extends BxBaseModProfileModule
  15. {
  16. function __construct(&$aModule)
  17. {
  18. parent::__construct($aModule);
  19. }
  20. /**
  21. * Get possible recipients for start conversation form
  22. */
  23. public function actionAjaxGetInitialMembers ()
  24. {
  25. $sTerm = bx_get('term');
  26. $a = BxDolService::call('system', 'profiles_search', array($sTerm), 'TemplServiceProfiles');
  27. header('Content-Type:text/javascript; charset=utf-8');
  28. echo(json_encode($a));
  29. }
  30. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  31. {
  32. if(empty($sUnitTemplate))
  33. $sUnitTemplate = 'unit.html';
  34. return parent::serviceGetSearchResultUnit($iContentId, $sUnitTemplate);
  35. }
  36. /**
  37. * @see BxBaseModProfileModule::serviceGetSpaceTitle
  38. */
  39. public function serviceGetSpaceTitle()
  40. {
  41. return _t($this->_oConfig->CNF['T']['txt_sample_single']);
  42. }
  43. /**
  44. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  45. */
  46. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects = false)
  47. {
  48. $aConnectionObjects = array($this->_oConfig->CNF['OBJECT_CONNECTIONS'], 'sys_profiles_subscriptions');
  49. return parent::serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects);
  50. }
  51. /**
  52. * Check if this module entry can be used as profile
  53. */
  54. public function serviceActAsProfile ()
  55. {
  56. return false;
  57. }
  58. /**
  59. * Check if this module is group profile
  60. */
  61. public function serviceIsGroupProfile ()
  62. {
  63. return true;
  64. }
  65. /**
  66. * check if provided profile is member if the group
  67. */
  68. public function serviceIsFan ($iGroupProfileId, $iProfileId = false)
  69. {
  70. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  71. return $this->isFan($oGroupProfile->getContentId(), $iProfileId);
  72. }
  73. /**
  74. * Delete profile from fans and admins tables
  75. * @param $iProfileId profile id
  76. */
  77. public function serviceDeleteProfileFromFansAndAdmins ($iProfileId)
  78. {
  79. $CNF = &$this->_oConfig->CNF;
  80. $this->_oDb->deleteAdminsByProfileId($iProfileId);
  81. if (isset($CNF['OBJECT_CONNECTIONS']) && ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  82. $oConnection->onDeleteInitiatorAndContent($iProfileId);
  83. }
  84. /**
  85. * Reset group's author for particular group
  86. * @param $iContentId group id
  87. * @return false of error, or number of updated records on success
  88. */
  89. public function serviceReassignEntityAuthor ($iContentId)
  90. {
  91. $aContentInfo = $this->_oDb->getContentInfoById((int)$iContentId);
  92. if (!$aContentInfo)
  93. return false;
  94. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
  95. return false;
  96. $aAdmins = $this->_oDb->getAdmins($oGroupProfile->id());
  97. return $this->_oDb->updateAuthorById($iContentId, $aAdmins ? array_pop($aAdmins) : 0);
  98. }
  99. /**
  100. * Reset group's author when author profile is deleted
  101. * @param $iProfileId profile id
  102. * @return number of changed items
  103. */
  104. public function serviceReassignEntitiesByAuthor ($iProfileId)
  105. {
  106. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  107. if (!$a)
  108. return 0;
  109. $iCount = 0;
  110. foreach ($a as $aContentInfo)
  111. $iCount += ('' == $this->serviceReassignEntityAuthor($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
  112. return $iCount;
  113. }
  114. public function servicePrepareFields ($aFieldsProfile)
  115. {
  116. $CNF = &$this->_oConfig->CNF;
  117. $aFieldsProfile[$CNF['FIELD_NAME']] = $aFieldsProfile['name'];
  118. $aFieldsProfile[$CNF['FIELD_TEXT']] = isset($aFieldsProfile['description']) ? $aFieldsProfile['description'] : '';
  119. unset($aFieldsProfile['name']);
  120. unset($aFieldsProfile['description']);
  121. return $aFieldsProfile;
  122. }
  123. public function serviceOnRemoveConnection ($iGroupProfileId, $iInitiatorId)
  124. {
  125. $CNF = &$this->_oConfig->CNF;
  126. list ($iProfileId, $iGroupProfileId, $oGroupProfile) = $this->_prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId);
  127. if (!$oGroupProfile)
  128. return false;
  129. $this->_oDb->fromAdmins($iGroupProfileId, $iProfileId);
  130. if ($oConn = BxDolConnection::getObjectInstance('sys_profiles_subscriptions'))
  131. return $oConn->removeConnection($iProfileId, $iGroupProfileId);
  132. return false;
  133. }
  134. public function serviceAddMutualConnection ($iGroupProfileId, $iInitiatorId, $iIgnoreJoinConfirmation = false)
  135. {
  136. $CNF = &$this->_oConfig->CNF;
  137. list ($iProfileId, $iGroupProfileId, $oGroupProfile) = $this->_prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId);
  138. if (!$oGroupProfile)
  139. return false;
  140. if (!($aContentInfo = $this->_oDb->getContentInfoById((int)BxDolProfile::getInstance($iGroupProfileId)->getContentId())))
  141. return false;
  142. if (!($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  143. return false;
  144. $sEntryTitle = $aContentInfo[$CNF['FIELD_NAME']];
  145. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  146. // send invitation to the group
  147. if ($iIgnoreJoinConfirmation && !$oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id()) && !$oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId) && bx_get_logged_profile_id() != $iProfileId) {
  148. bx_alert($this->getName(), 'join_invitation', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, array('content' => $aContentInfo, 'entry_title' => $sEntryTitle, 'entry_url' => $sEntryUrl, 'group_profile' => $iGroupProfileId, 'profile' => $iProfileId, 'notification_subobject_id' => $iProfileId, 'object_author_id' => $iGroupProfileId));
  149. }
  150. // send notification to group's admins that new connection is pending confirmation
  151. elseif (!$iIgnoreJoinConfirmation && $oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id()) && !$oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId) && $aContentInfo['join_confirmation']) {
  152. bx_alert($this->getName(), 'join_request', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  153. 'object_author_id' => $iGroupProfileId,
  154. 'performer_id' => $iProfileId,
  155. 'content' => $aContentInfo,
  156. 'entry_title' => $sEntryTitle,
  157. 'entry_url' => $sEntryUrl,
  158. 'group_profile' => $iGroupProfileId,
  159. 'profile' => $iProfileId
  160. ));
  161. }
  162. // send notification that join request was accepted
  163. else if (!$iIgnoreJoinConfirmation && $oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id(), true) && $oGroupProfile->getModule() != $this->getName() && bx_get_logged_profile_id() != $iProfileId) {
  164. bx_alert($this->getName(), 'join_request_accepted', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  165. 'object_author_id' => $iGroupProfileId,
  166. 'performer_id' => $iProfileId,
  167. 'content' => $aContentInfo,
  168. 'entry_title' => $sEntryTitle,
  169. 'entry_url' => $sEntryUrl,
  170. 'group_profile' => $iGroupProfileId,
  171. 'profile' => $iProfileId
  172. ));
  173. }
  174. // new fan was added
  175. if ($oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId, true)) {
  176. bx_alert($this->getName(), 'fan_added', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  177. 'object_author_id' => $iGroupProfileId,
  178. 'performer_id' => $iProfileId,
  179. 'content' => $aContentInfo,
  180. 'entry_title' => $sEntryTitle,
  181. 'entry_url' => $sEntryUrl,
  182. 'group_profile' => $iGroupProfileId,
  183. 'profile' => $iProfileId,
  184. ));
  185. return false;
  186. }
  187. // don't automatically add back connection (mutual) if group requires manual join confirmation
  188. if (!$iIgnoreJoinConfirmation && $aContentInfo['join_confirmation'])
  189. return false;
  190. // check if connection already exists
  191. if ($oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId, true) || $oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId))
  192. return false;
  193. if (!$oConnection->addConnection($oGroupProfile->id(), (int)$iInitiatorId))
  194. return false;
  195. return true;
  196. }
  197. public function serviceFansTable ()
  198. {
  199. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID_CONNECTIONS']);
  200. if (!$oGrid)
  201. return false;
  202. return $oGrid->getCode();
  203. }
  204. public function serviceFans ($iContentId = 0, $bAsArray = false)
  205. {
  206. if (!$iContentId)
  207. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  208. if (!$iContentId)
  209. return false;
  210. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  211. if (!$aContentInfo)
  212. return false;
  213. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
  214. return false;
  215. if(!$bAsArray) {
  216. bx_import('BxDolConnection');
  217. $mixedResult = $this->serviceBrowseConnectionsQuick ($oGroupProfile->id(), $this->_oConfig->CNF['OBJECT_CONNECTIONS'], BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  218. if (!$mixedResult)
  219. return MsgBox(_t('_sys_txt_empty'));
  220. }
  221. else
  222. $mixedResult = BxDolConnection::getObjectInstance($this->_oConfig->CNF['OBJECT_CONNECTIONS'])->getConnectedContent($oGroupProfile->id(), true);
  223. return $mixedResult;
  224. }
  225. public function serviceAdmins ($iContentId = 0)
  226. {
  227. $CNF = &$this->_oConfig->CNF;
  228. if(!$iContentId)
  229. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  230. if(!$iContentId)
  231. return false;
  232. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  233. if(!$oGroupProfile)
  234. return false;
  235. $aProfiles = $this->_oDb->getAdmins($oGroupProfile->id());
  236. if(empty($aProfiles) || !is_array($aProfiles))
  237. return false;
  238. $iStart = (int)bx_get('start');
  239. $iLimit = !empty($CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($CNF['PARAM_NUM_CONNECTIONS_QUICK']) : 4;
  240. if(!$iLimit)
  241. $iLimit = 4;
  242. return $this->_serviceBrowseQuick($aProfiles, $iStart, $iLimit);
  243. }
  244. public function serviceBrowseJoinedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  245. {
  246. if (!$iProfileId)
  247. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  248. if (!$iProfileId)
  249. return '';
  250. return $this->_serviceBrowse ('joined_entries', array('joined_profile' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  251. }
  252. public function serviceBrowseCreatedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  253. {
  254. if (!$iProfileId)
  255. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  256. if (!$iProfileId)
  257. return '';
  258. return $this->_serviceBrowse ('created_entries', array('author' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  259. }
  260. public function serviceEntityInvite ($iContentId = 0, $bErrorMsg = true)
  261. {
  262. return $this->_serviceEntityForm ('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_INVITE'], false, $bErrorMsg);
  263. }
  264. /**
  265. * Entry social sharing block
  266. */
  267. public function serviceEntitySocialSharing ($iContentId = 0)
  268. {
  269. if (!$iContentId)
  270. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  271. if (!$iContentId)
  272. return false;
  273. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  274. if (!$aContentInfo)
  275. return false;
  276. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  277. if (!$oGroupProfile)
  278. return false;
  279. $CNF = &$this->_oConfig->CNF;
  280. return $this->_entitySocialSharing ($iContentId, array(
  281. 'id_timeline' => $iContentId,
  282. 'id_thumb' => 0,
  283. 'title' => $oGroupProfile->getDisplayName(),
  284. 'object_storage' => false,
  285. 'object_transcoder' => false,
  286. 'object_vote' => $CNF['OBJECT_VOTES'],
  287. 'object_score' => !empty($CNF['OBJECT_SCORES']) ? $CNF['OBJECT_SCORES'] : '',
  288. 'object_favorite' => $CNF['OBJECT_FAVORITES'],
  289. 'object_feature' => $CNF['OBJECT_FEATURED'],
  290. 'object_report' => $CNF['OBJECT_REPORTS'],
  291. 'uri_view_entry' => $CNF['URI_VIEW_ENTRY']
  292. ));
  293. }
  294. /**
  295. * Data for Notifications module
  296. */
  297. public function serviceGetNotificationsData()
  298. {
  299. $sModule = $this->_aModule['name'];
  300. return array(
  301. 'handlers' => array(
  302. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  303. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  304. array('group' => $sModule . '_fan_added', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'fan_added', 'module_name' => $sModule, 'module_method' => 'get_notifications_fan_added', 'module_class' => 'Module'),
  305. array('group' => $sModule . '_join_request', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'join_request', 'module_name' => $sModule, 'module_method' => 'get_notifications_join_request', 'module_class' => 'Module', 'module_event_privacy' => $this->_oConfig->CNF['OBJECT_PRIVACY_VIEW_NOTIFICATION_EVENT']),
  306. array('group' => $sModule . '_timeline_post_common', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'timeline_post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_timeline_post_common', 'module_class' => 'Module'),
  307. ),
  308. 'alerts' => array(
  309. array('unit' => $sModule, 'action' => 'doVote'),
  310. array('unit' => $sModule, 'action' => 'undoVote'),
  311. array('unit' => $sModule, 'action' => 'fan_added'),
  312. array('unit' => $sModule, 'action' => 'join_request'),
  313. array('unit' => $sModule, 'action' => 'timeline_post_common'),
  314. )
  315. );
  316. }
  317. /**
  318. * Notification about new member requst in the group
  319. */
  320. public function serviceGetNotificationsJoinRequest($aEvent)
  321. {
  322. return $this->_serviceGetNotification($aEvent, $this->_oConfig->CNF['T']['txt_ntfs_join_request']);
  323. }
  324. /**
  325. * Notification about new member in the group
  326. */
  327. public function serviceGetNotificationsFanAdded($aEvent)
  328. {
  329. return $this->_serviceGetNotification($aEvent, $this->_oConfig->CNF['T']['txt_ntfs_fan_added']);
  330. }
  331. protected function _serviceGetNotification($aEvent, $sLangKey)
  332. {
  333. $CNF = &$this->_oConfig->CNF;
  334. $iContentId = (int)$aEvent['object_id'];
  335. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  336. if(!$oGroupProfile)
  337. return array();
  338. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  339. if(empty($aContentInfo) || !is_array($aContentInfo))
  340. return array();
  341. $oProfile = BxDolProfile::getInstance((int)$aEvent['subobject_id']);
  342. if(!$oProfile)
  343. return array();
  344. /*
  345. * Note. Group Profile URL is used for both Entry and Subentry URLs,
  346. * because Subentry URL has higher display priority and notification
  347. * should be linked to Group Profile instead of Personal Profile of
  348. * a member, who performed an action.
  349. */
  350. $sEntryUrl = $sSubentryUrl = $oGroupProfile->getUrl();
  351. return array(
  352. 'entry_sample' => $CNF['T']['txt_sample_single'],
  353. 'entry_url' => $sEntryUrl,
  354. 'entry_caption' => $oGroupProfile->getDisplayName(),
  355. 'entry_author' => $oGroupProfile->id(),
  356. 'subentry_sample' => $oProfile->getDisplayName(),
  357. 'subentry_url' => $sSubentryUrl,
  358. 'lang_key' => $sLangKey
  359. );
  360. }
  361. /**
  362. * Data for Timeline module
  363. */
  364. public function serviceGetTimelineData()
  365. {
  366. return BxBaseModGeneralModule::serviceGetTimelineData();
  367. }
  368. /**
  369. * Entry post for Timeline module
  370. */
  371. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  372. {
  373. $a = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  374. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aEvent['object_id'], $this->getName());
  375. $a['content']['url'] = $oGroupProfile->getUrl();
  376. $a['content']['title'] = $oGroupProfile->getDisplayName();
  377. return $a;
  378. }
  379. /**
  380. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  381. */
  382. public function checkAllowedPost ($aDataEntry, $isPerformAction = false)
  383. {
  384. if ($this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]))
  385. return CHECK_ACTION_RESULT_ALLOWED;
  386. return _t('_sys_txt_access_denied');
  387. }
  388. /**
  389. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  390. */
  391. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  392. {
  393. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  394. }
  395. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  396. {
  397. if ($this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $iProfileId))
  398. return CHECK_ACTION_RESULT_ALLOWED;
  399. return parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  400. }
  401. /**
  402. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  403. */
  404. public function checkAllowedCompose (&$aDataEntry, $isPerformAction = false)
  405. {
  406. if (!$this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]))
  407. return _t('_sys_txt_access_denied');
  408. return parent::checkAllowedCompose ($aDataEntry, $isPerformAction);
  409. }
  410. /**
  411. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  412. */
  413. public function checkAllowedFanAdd (&$aDataEntry, $isPerformAction = false)
  414. {
  415. if ($this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]) || !isLogged())
  416. return _t('_sys_txt_access_denied');
  417. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], true, false);
  418. }
  419. /**
  420. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  421. */
  422. public function checkAllowedFanRemove (&$aDataEntry, $isPerformAction = false)
  423. {
  424. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, true))
  425. return CHECK_ACTION_RESULT_ALLOWED;
  426. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, false);
  427. }
  428. public function checkAllowedManageAdmins ($mixedDataEntry, $isPerformAction = false)
  429. {
  430. if (is_array($mixedDataEntry)) {
  431. $aDataEntry = $mixedDataEntry;
  432. }
  433. else {
  434. $oGroupProfile = BxDolProfile::getInstance((int)$mixedDataEntry);
  435. $aDataEntry = $oGroupProfile && $this->getName() == $oGroupProfile->getModule() ? $this->_oDb->getContentInfoById($oGroupProfile->getContentId()) : array();
  436. }
  437. return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
  438. }
  439. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  440. {
  441. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  442. if ($this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id(), $aDataEntry))
  443. return CHECK_ACTION_RESULT_ALLOWED;
  444. return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
  445. }
  446. public function checkAllowedInvite ($aDataEntry, $isPerformAction = false)
  447. {
  448. return $this->checkAllowedEdit ($aDataEntry, $isPerformAction);
  449. }
  450. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  451. {
  452. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  453. if ($this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id(), $aDataEntry))
  454. return CHECK_ACTION_RESULT_ALLOWED;
  455. return parent::checkAllowedChangeCover ($aDataEntry, $isPerformAction);
  456. }
  457. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  458. {
  459. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  460. if ($oGroupProfile && $this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id(), $aDataEntry))
  461. return CHECK_ACTION_RESULT_ALLOWED;
  462. return parent::checkAllowedDelete ($aDataEntry, $isPerformAction);
  463. }
  464. public function checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  465. {
  466. if (!$this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]))
  467. return _t('_sys_txt_access_denied');
  468. return $this->_checkAllowedSubscribeAdd ($aDataEntry, $isPerformAction);
  469. }
  470. public function _checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  471. {
  472. return parent::checkAllowedSubscribeAdd ($aDataEntry, $isPerformAction);
  473. }
  474. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  475. {
  476. $sResult = $this->checkAllowedView($aDataEntry);
  477. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  478. if (CHECK_ACTION_RESULT_ALLOWED !== $sResult && !$oPrivacy->isPartiallyVisible($aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]))
  479. return $sResult;
  480. return parent::_checkAllowedConnect ($aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap);
  481. }
  482. public function isFan ($iContentId, $iProfileId = false)
  483. {
  484. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  485. return $oGroupProfile && ($oConnection = BxDolConnection::getObjectInstance($this->_oConfig->CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $oGroupProfile->id(), true);
  486. }
  487. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  488. {
  489. $CNF = &$this->_oConfig->CNF;
  490. if(!isset($CNF['FIELD_PICTURE']) || empty($aContentInfo[$CNF['FIELD_PICTURE']]))
  491. return array();
  492. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aEvent['object_id'], $this->getName());
  493. return array(
  494. array('url' => $sUrl, 'src' => $oGroupProfile->getPicture()),
  495. );
  496. }
  497. protected function _prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId)
  498. {
  499. if (!($oGroupProfile = BxDolProfile::getInstance($iGroupProfileId)))
  500. return array(0, 0, null);
  501. if ($oGroupProfile->getModule() == $this->getName()) {
  502. $iProfileId = $iInitiatorId;
  503. $iGroupProfileId = $oGroupProfile->id();
  504. } else {
  505. $iProfileId = $oGroupProfile->id();
  506. $iGroupProfileId = $iInitiatorId;
  507. }
  508. return array($iProfileId, $iGroupProfileId, $oGroupProfile);
  509. }
  510. }
  511. /** @} */