BxBaseModGroupsModule.php 23 KB

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