BxBaseModGroupsModule.php 25 KB

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