BxBaseModGroupsModule.php 26 KB

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