BxBaseModGroupsModule.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  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. /**
  31. * Process Process Invitation
  32. */
  33. public function actionProcessInvite ($sKey, $iGroupProfileId, $bAccept)
  34. {
  35. $aData = $this->_oDb->getInviteByKey($sKey, $iGroupProfileId);
  36. if (isset($aData['invited_profile_id'])){
  37. $CNF = &$this->_oConfig->CNF;
  38. if (!isset($CNF['OBJECT_CONNECTIONS']) || !($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  39. return '';
  40. $iInvitedProfileId = $aData['invited_profile_id'];
  41. if ($iInvitedProfileId != bx_get_logged_profile_id())
  42. return '';
  43. if ($bAccept){
  44. if($oConnection && !$oConnection->isConnected($iInvitedProfileId, $iGroupProfileId)){
  45. $oConnection->addConnection($iInvitedProfileId, $iGroupProfileId);
  46. $oConnection->addConnection($iGroupProfileId, $iInvitedProfileId);
  47. }
  48. }
  49. $this->_oDb->deleteInviteByKey($sKey, $iGroupProfileId);
  50. }
  51. }
  52. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  53. {
  54. if(empty($sUnitTemplate))
  55. $sUnitTemplate = 'unit.html';
  56. return parent::serviceGetSearchResultUnit($iContentId, $sUnitTemplate);
  57. }
  58. /**
  59. * @see BxBaseModProfileModule::serviceGetSpaceTitle
  60. */
  61. public function serviceGetSpaceTitle()
  62. {
  63. return _t($this->_oConfig->CNF['T']['txt_sample_single']);
  64. }
  65. /**
  66. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  67. */
  68. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects = false)
  69. {
  70. if (isset($this->_oConfig->CNF['OBJECT_CONNECTIONS'])){
  71. $aConnectionObjects = array($this->_oConfig->CNF['OBJECT_CONNECTIONS'], 'sys_profiles_subscriptions');
  72. return parent::serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects);
  73. }
  74. return parent::serviceGetParticipatingProfiles($iProfileId);
  75. }
  76. /**
  77. * Check if this module entry can be used as profile
  78. */
  79. public function serviceActAsProfile ()
  80. {
  81. return false;
  82. }
  83. /**
  84. * Check if this module is group profile
  85. */
  86. public function serviceIsGroupProfile ()
  87. {
  88. return true;
  89. }
  90. /**
  91. * check if provided profile is member of the group
  92. */
  93. public function serviceIsFan ($iGroupProfileId, $iProfileId = false)
  94. {
  95. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  96. return $this->isFan($oGroupProfile->getContentId(), $iProfileId);
  97. }
  98. /**
  99. * check if provided profile is admin of the group
  100. */
  101. public function serviceIsAdmin ($iGroupProfileId, $iProfileId = false)
  102. {
  103. if(!$iProfileId)
  104. $iProfileId = bx_get_logged_profile_id();
  105. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  106. $iGroupContentId = $oGroupProfile->getContentId();
  107. if(!$this->isFan($iGroupContentId, $iProfileId))
  108. return false;
  109. $aGroupContentInfo = $this->_oDb->getContentInfoById($iGroupContentId);
  110. return $this->_oDb->isAdmin($iGroupProfileId, $iProfileId, $aGroupContentInfo);
  111. }
  112. /**
  113. * Delete profile from fans and admins tables
  114. * @param $iProfileId profile id
  115. */
  116. public function serviceDeleteProfileFromFansAndAdmins ($iProfileId)
  117. {
  118. $CNF = &$this->_oConfig->CNF;
  119. $this->_oDb->deleteAdminsByProfileId($iProfileId);
  120. if (isset($CNF['OBJECT_CONNECTIONS']) && ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  121. $oConnection->onDeleteInitiatorAndContent($iProfileId);
  122. }
  123. /**
  124. * Reset group's author for particular group
  125. * @param $iContentId group id
  126. * @return false of error, or number of updated records on success
  127. */
  128. public function serviceReassignEntityAuthor ($iContentId)
  129. {
  130. $aContentInfo = $this->_oDb->getContentInfoById((int)$iContentId);
  131. if (!$aContentInfo)
  132. return false;
  133. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
  134. return false;
  135. $aAdmins = $this->_oDb->getAdmins($oGroupProfile->id());
  136. return $this->_oDb->updateAuthorById($iContentId, $aAdmins ? array_pop($aAdmins) : 0);
  137. }
  138. /**
  139. * Entry actions and social sharing block
  140. */
  141. public function serviceEntityAllActions ($mixedContent = false, $aParams = array())
  142. {
  143. $CNF = &$this->_oConfig->CNF;
  144. if(!empty($mixedContent)) {
  145. if(!is_array($mixedContent))
  146. $mixedContent = array((int)$mixedContent, (method_exists($this->_oDb, 'getContentInfoById')) ? $this->_oDb->getContentInfoById((int)$mixedContent) : array());
  147. }
  148. else {
  149. $mixedContent = $this->_getContent();
  150. if($mixedContent === false)
  151. return false;
  152. }
  153. list($iContentId, $aContentInfo) = $mixedContent;
  154. if(!empty($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]))
  155. $aParams = array_merge(array(
  156. 'entry_thumb' => (int)$aContentInfo[$CNF['FIELD_PICTURE']]
  157. ), $aParams);
  158. return parent::serviceEntityAllActions ($mixedContent, $aParams);
  159. }
  160. /**
  161. * Reset group's author when author profile is deleted
  162. * @param $iProfileId profile id
  163. * @return number of changed items
  164. */
  165. public function serviceReassignEntitiesByAuthor ($iProfileId)
  166. {
  167. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  168. if (!$a)
  169. return 0;
  170. $iCount = 0;
  171. foreach ($a as $aContentInfo)
  172. $iCount += ('' == $this->serviceReassignEntityAuthor($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
  173. return $iCount;
  174. }
  175. public function servicePrepareFields ($aFieldsProfile)
  176. {
  177. $CNF = &$this->_oConfig->CNF;
  178. $aFieldsProfile[$CNF['FIELD_NAME']] = $aFieldsProfile['name'];
  179. $aFieldsProfile[$CNF['FIELD_TEXT']] = isset($aFieldsProfile['description']) ? $aFieldsProfile['description'] : '';
  180. unset($aFieldsProfile['name']);
  181. unset($aFieldsProfile['description']);
  182. return $aFieldsProfile;
  183. }
  184. public function serviceOnRemoveConnection ($iGroupProfileId, $iInitiatorId)
  185. {
  186. $CNF = &$this->_oConfig->CNF;
  187. list ($iProfileId, $iGroupProfileId, $oGroupProfile) = $this->_prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId);
  188. if (!$oGroupProfile)
  189. return false;
  190. $this->_oDb->fromAdmins($iGroupProfileId, $iProfileId);
  191. if ($oConn = BxDolConnection::getObjectInstance('sys_profiles_subscriptions'))
  192. return $oConn->removeConnection($iProfileId, $iGroupProfileId);
  193. return false;
  194. }
  195. public function serviceAddMutualConnection ($iGroupProfileId, $iInitiatorId, $bSendInviteOnly = false)
  196. {
  197. $CNF = &$this->_oConfig->CNF;
  198. list ($iProfileId, $iGroupProfileId, $oGroupProfile) = $this->_prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId);
  199. if (!$oGroupProfile)
  200. return false;
  201. if (!($aContentInfo = $this->_oDb->getContentInfoById((int)BxDolProfile::getInstance($iGroupProfileId)->getContentId())))
  202. return false;
  203. if (!isset($CNF['OBJECT_CONNECTIONS']) || !($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  204. return false;
  205. $sEntryTitle = $aContentInfo[$CNF['FIELD_NAME']];
  206. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  207. // send invitation to the group
  208. if ($bSendInviteOnly && !$oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id()) && !$oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId) && bx_get_logged_profile_id() != $iProfileId) {
  209. 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));
  210. }
  211. // send notification to group's admins that new connection is pending confirmation
  212. elseif (!$bSendInviteOnly && $oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id()) && !$oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId) && $aContentInfo['join_confirmation']) {
  213. bx_alert($this->getName(), 'join_request', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  214. 'object_author_id' => $iGroupProfileId,
  215. 'performer_id' => $iProfileId,
  216. 'content' => $aContentInfo,
  217. 'entry_title' => $sEntryTitle,
  218. 'entry_url' => $sEntryUrl,
  219. 'group_profile' => $iGroupProfileId,
  220. 'profile' => $iProfileId
  221. ));
  222. }
  223. // send notification that join request was accepted
  224. else if (!$bSendInviteOnly && $oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id(), true) && $oGroupProfile->getModule() != $this->getName() && bx_get_logged_profile_id() != $iProfileId) {
  225. bx_alert($this->getName(), 'join_request_accepted', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  226. 'object_author_id' => $iGroupProfileId,
  227. 'performer_id' => $iProfileId,
  228. 'content' => $aContentInfo,
  229. 'entry_title' => $sEntryTitle,
  230. 'entry_url' => $sEntryUrl,
  231. 'group_profile' => $iGroupProfileId,
  232. 'profile' => $iProfileId
  233. ));
  234. }
  235. // new fan was added
  236. if ($oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId, true)) {
  237. // follow group on join
  238. if (BxDolService::call($oGroupProfile->getModule(), 'act_as_profile')){
  239. $this->addFollower($oGroupProfile->id(), (int)$iInitiatorId);
  240. }
  241. else{
  242. $this->addFollower((int)$iInitiatorId, $oGroupProfile->id());
  243. }
  244. bx_alert($this->getName(), 'fan_added', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  245. 'object_author_id' => $iGroupProfileId,
  246. 'performer_id' => $iProfileId,
  247. 'content' => $aContentInfo,
  248. 'entry_title' => $sEntryTitle,
  249. 'entry_url' => $sEntryUrl,
  250. 'group_profile' => $iGroupProfileId,
  251. 'profile' => $iProfileId,
  252. ));
  253. $this->doAudit($iGroupProfileId, $iInitiatorId, '_sys_audit_action_group_join_request_accepted');
  254. return false;
  255. }
  256. // don't automatically add connection (mutual) if group requires manual join confirmation
  257. if ($bSendInviteOnly || $aContentInfo['join_confirmation'])
  258. return false;
  259. // check if connection already exists
  260. if ($oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId, true) || $oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId))
  261. return false;
  262. if (!$oConnection->addConnection($oGroupProfile->id(), (int)$iInitiatorId))
  263. return false;
  264. return true;
  265. }
  266. public function serviceFansTable ()
  267. {
  268. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID_CONNECTIONS']);
  269. if (!$oGrid)
  270. return false;
  271. return $oGrid->getCode();
  272. }
  273. public function serviceInvitesTable ()
  274. {
  275. if (!isset($this->_oConfig->CNF['OBJECT_GRID_INVITES']))
  276. return false;
  277. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID_INVITES']);
  278. if (!$oGrid)
  279. return false;
  280. return $oGrid->getCode();
  281. }
  282. public function serviceFans ($iContentId = 0, $bAsArray = false)
  283. {
  284. if (!$iContentId)
  285. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  286. if (!$iContentId)
  287. return false;
  288. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  289. if (!$aContentInfo)
  290. return false;
  291. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
  292. return false;
  293. if(!$bAsArray) {
  294. bx_import('BxDolConnection');
  295. $mixedResult = $this->serviceBrowseConnectionsQuick ($oGroupProfile->id(), $this->_oConfig->CNF['OBJECT_CONNECTIONS'], BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  296. if (!$mixedResult)
  297. return MsgBox(_t('_sys_txt_empty'));
  298. }
  299. else
  300. $mixedResult = BxDolConnection::getObjectInstance($this->_oConfig->CNF['OBJECT_CONNECTIONS'])->getConnectedContent($oGroupProfile->id(), true);
  301. return $mixedResult;
  302. }
  303. public function serviceAdmins ($iContentId = 0)
  304. {
  305. $CNF = &$this->_oConfig->CNF;
  306. if(!$iContentId)
  307. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  308. if(!$iContentId)
  309. return false;
  310. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  311. if(!$oGroupProfile)
  312. return false;
  313. $iStart = (int)bx_get('start');
  314. $iLimit = !empty($CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($CNF['PARAM_NUM_CONNECTIONS_QUICK']) : 4;
  315. if(!$iLimit)
  316. $iLimit = 4;
  317. $aProfiles = $this->_oDb->getAdmins($oGroupProfile->id(), $iStart, $iLimit+1);
  318. if(empty($aProfiles) || !is_array($aProfiles))
  319. return false;
  320. return $this->_serviceBrowseQuick($aProfiles, $iStart, $iLimit);
  321. }
  322. public function serviceBrowseJoinedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  323. {
  324. if (!$iProfileId)
  325. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  326. if (!$iProfileId)
  327. return '';
  328. return $this->_serviceBrowse ('joined_entries', array('joined_profile' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  329. }
  330. public function serviceBrowseCreatedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  331. {
  332. if (!$iProfileId)
  333. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  334. if (!$iProfileId)
  335. return '';
  336. return $this->_serviceBrowse ('created_entries', array('author' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  337. }
  338. public function serviceEntityInvite ($iContentId = 0, $bErrorMsg = true)
  339. {
  340. if (isset($this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_INVITE']))
  341. return $this->_serviceEntityForm ('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_INVITE'], false, $bErrorMsg);
  342. return false;
  343. }
  344. /**
  345. * Entry social sharing block
  346. */
  347. public function serviceEntitySocialSharing ($mixedContent = false, $aParams = array())
  348. {
  349. if(!empty($mixedContent)) {
  350. if(!is_array($mixedContent))
  351. $mixedContent = array((int)$mixedContent, array());
  352. }
  353. else {
  354. $mixedContent = $this->_getContent();
  355. if($mixedContent === false)
  356. return false;
  357. }
  358. list($iContentId, $aContentInfo) = $mixedContent;
  359. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  360. if(!$oGroupProfile)
  361. return false;
  362. return parent::serviceEntitySocialSharing(array($iContentId, $aContentInfo), array(
  363. 'title' => $oGroupProfile->getDisplayName()
  364. ));
  365. }
  366. /**
  367. * Data for Notifications module
  368. */
  369. public function serviceGetNotificationsData()
  370. {
  371. $sModule = $this->_aModule['name'];
  372. $aSettingsTypes = array('follow_member', 'follow_context');
  373. if($this->serviceActAsProfile())
  374. $aSettingsTypes = array('personal', 'follow_member');
  375. return array(
  376. 'handlers' => array(
  377. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  378. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  379. array('group' => $sModule . '_score_up', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteUp', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_up', 'module_class' => 'Module'),
  380. array('group' => $sModule . '_score_down', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteDown', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_down', 'module_class' => 'Module'),
  381. 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'),
  382. 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']),
  383. 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'),
  384. ),
  385. 'settings' => array(
  386. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => $aSettingsTypes),
  387. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => $aSettingsTypes),
  388. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => $aSettingsTypes),
  389. array('group' => 'fan', 'unit' => $sModule, 'action' => 'fan_added', 'types' => $aSettingsTypes),
  390. array('group' => 'join', 'unit' => $sModule, 'action' => 'join_request', 'types' => $aSettingsTypes),
  391. array('group' => 'timeline_post', 'unit' => $sModule, 'action' => 'timeline_post_common', 'types' => $aSettingsTypes)
  392. ),
  393. 'alerts' => array(
  394. array('unit' => $sModule, 'action' => 'doVote'),
  395. array('unit' => $sModule, 'action' => 'undoVote'),
  396. array('unit' => $sModule, 'action' => 'doVoteUp'),
  397. array('unit' => $sModule, 'action' => 'doVoteDown'),
  398. array('unit' => $sModule, 'action' => 'fan_added'),
  399. array('unit' => $sModule, 'action' => 'join_request'),
  400. array('unit' => $sModule, 'action' => 'timeline_post_common'),
  401. )
  402. );
  403. }
  404. /**
  405. * Notification about new member requst in the group
  406. */
  407. public function serviceGetNotificationsJoinRequest($aEvent)
  408. {
  409. return $this->_serviceGetNotification($aEvent, $this->_oConfig->CNF['T']['txt_ntfs_join_request']);
  410. }
  411. /**
  412. * Notification about new member in the group
  413. */
  414. public function serviceGetNotificationsFanAdded($aEvent)
  415. {
  416. return $this->_serviceGetNotification($aEvent, $this->_oConfig->CNF['T']['txt_ntfs_fan_added']);
  417. }
  418. protected function _serviceGetNotification($aEvent, $sLangKey)
  419. {
  420. $CNF = &$this->_oConfig->CNF;
  421. $iContentId = (int)$aEvent['object_id'];
  422. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  423. if(!$oGroupProfile)
  424. return array();
  425. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  426. if(empty($aContentInfo) || !is_array($aContentInfo))
  427. return array();
  428. $oProfile = BxDolProfile::getInstance((int)$aEvent['subobject_id']);
  429. if(!$oProfile)
  430. return array();
  431. /*
  432. * Note. Group Profile URL is used for both Entry and Subentry URLs,
  433. * because Subentry URL has higher display priority and notification
  434. * should be linked to Group Profile (Group Profile -> Members tab)
  435. * instead of Personal Profile of a member, who performed an action.
  436. */
  437. $sEntryUrl = $oGroupProfile->getUrl();
  438. if(!empty($CNF['URL_ENTRY_FANS']))
  439. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_ENTRY_FANS'], array(
  440. 'profile_id' => $oGroupProfile->id()
  441. ));
  442. return array(
  443. 'entry_sample' => $CNF['T']['txt_sample_single'],
  444. 'entry_url' => $sEntryUrl,
  445. 'entry_caption' => $oGroupProfile->getDisplayName(),
  446. 'entry_author' => $oGroupProfile->id(),
  447. 'subentry_sample' => $oProfile->getDisplayName(),
  448. 'subentry_url' => $sEntryUrl,
  449. 'lang_key' => $sLangKey
  450. );
  451. }
  452. /**
  453. * Data for Timeline module
  454. */
  455. public function serviceGetTimelineData()
  456. {
  457. return BxBaseModGeneralModule::serviceGetTimelineData();
  458. }
  459. /**
  460. * Entry post for Timeline module
  461. */
  462. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  463. {
  464. $a = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  465. if($a === false)
  466. return false;
  467. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aEvent['object_id'], $this->getName());
  468. $a['content']['url'] = $oGroupProfile->getUrl();
  469. $a['content']['title'] = $oGroupProfile->getDisplayName();
  470. return $a;
  471. }
  472. // ====== PERMISSION METHODS
  473. /**
  474. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  475. */
  476. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  477. {
  478. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  479. }
  480. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  481. {
  482. $bInvited = false;
  483. if (bx_get('key')){
  484. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  485. $mixedInvited = $this->isInvited(bx_get('key'), $oGroupProfile->id());
  486. if ($mixedInvited === true)
  487. $bInvited = true;
  488. }
  489. if ($this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $iProfileId) || $bInvited)
  490. return CHECK_ACTION_RESULT_ALLOWED;
  491. return parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  492. }
  493. /**
  494. * @deprecated since version 11.0.1 use BxBaseModGroupsModule::checkAllowedCompose instead
  495. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  496. */
  497. public function checkAllowedCompose(&$aDataEntry, $isPerformAction = false)
  498. {
  499. return $this->checkAllowedContact($aDataEntry, $isPerformAction);
  500. }
  501. /**
  502. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  503. */
  504. public function checkAllowedContact($aDataEntry, $isPerformAction = false)
  505. {
  506. if(!$this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]))
  507. return _t('_sys_txt_access_denied');
  508. return parent::checkAllowedContact($aDataEntry, $isPerformAction);
  509. }
  510. /**
  511. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  512. */
  513. public function checkAllowedFanAdd (&$aDataEntry, $isPerformAction = false)
  514. {
  515. if ($this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]) || !isLogged())
  516. return _t('_sys_txt_access_denied');
  517. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], true, false);
  518. }
  519. /**
  520. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  521. */
  522. public function checkAllowedFanRemove (&$aDataEntry, $isPerformAction = false)
  523. {
  524. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, true))
  525. return CHECK_ACTION_RESULT_ALLOWED;
  526. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, false);
  527. }
  528. public function checkAllowedManageAdmins ($mixedDataEntry, $isPerformAction = false)
  529. {
  530. if (is_array($mixedDataEntry)) {
  531. $aDataEntry = $mixedDataEntry;
  532. }
  533. else {
  534. $oGroupProfile = BxDolProfile::getInstance((int)$mixedDataEntry);
  535. $aDataEntry = $oGroupProfile && $this->getName() == $oGroupProfile->getModule() ? $this->_oDb->getContentInfoById($oGroupProfile->getContentId()) : array();
  536. }
  537. return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
  538. }
  539. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  540. {
  541. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  542. if ($this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id(), $aDataEntry))
  543. return CHECK_ACTION_RESULT_ALLOWED;
  544. return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
  545. }
  546. public function checkAllowedInvite ($aDataEntry, $isPerformAction = false)
  547. {
  548. return $this->checkAllowedEdit ($aDataEntry, $isPerformAction);
  549. }
  550. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  551. {
  552. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  553. if ($this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id(), $aDataEntry))
  554. return CHECK_ACTION_RESULT_ALLOWED;
  555. return parent::checkAllowedChangeCover ($aDataEntry, $isPerformAction);
  556. }
  557. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  558. {
  559. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  560. if ($oGroupProfile && $this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id(), $aDataEntry))
  561. return CHECK_ACTION_RESULT_ALLOWED;
  562. return parent::checkAllowedDelete ($aDataEntry, $isPerformAction);
  563. }
  564. public function checkAllowedJoin(&$aDataEntry, $isPerformAction = false)
  565. {
  566. if (bx_get('key')){
  567. $sKey = bx_get('key');
  568. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  569. $aData = $this->_oDb->getInviteByKey($sKey, $oGroupProfile->id());
  570. if (isset($aData['invited_profile_id']) && $aData['invited_profile_id'] == bx_get_logged_profile_id()){
  571. return CHECK_ACTION_RESULT_ALLOWED;
  572. }
  573. }
  574. return _t('_sys_txt_access_denied');
  575. }
  576. public function checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  577. {
  578. if (!$this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]))
  579. return _t('_sys_txt_access_denied');
  580. return $this->_checkAllowedSubscribeAdd ($aDataEntry, $isPerformAction);
  581. }
  582. public function _checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  583. {
  584. return parent::checkAllowedSubscribeAdd ($aDataEntry, $isPerformAction);
  585. }
  586. public function doAudit($iGroupProfileId, $iFanId, $sAction)
  587. {
  588. $oProfile = BxDolProfile::getInstance($iFanId);
  589. $iContentId = $oProfile->getContentId();
  590. $sModule = $oProfile->getModule();
  591. $oModule = BxDolModule::getInstance($sModule);
  592. if (BxDolRequest::serviceExists($sModule, 'act_as_profile') && BxDolService::call($sModule, 'act_as_profile') && $oModule->_oConfig){
  593. $CNF = $oModule->_oConfig->CNF;
  594. $aContentInfo = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $iContentId))) : array();
  595. $AuditParams = array(
  596. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  597. 'context_profile_id' => $iGroupProfileId,
  598. 'context_profile_title' => BxDolProfile::getInstance($iGroupProfileId)->getDisplayName()
  599. );
  600. bx_audit(
  601. $iContentId,
  602. $sModule,
  603. $sAction,
  604. $AuditParams
  605. );
  606. }
  607. }
  608. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  609. {
  610. $sResult = $this->checkAllowedView($aDataEntry);
  611. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  612. // if profile view isn't allowed but visibility is in partially visible groups
  613. // then display buttons to connect (befriend, join) to profile,
  614. // if other conditions (in parent::_checkAllowedConnect) are met as well
  615. if (CHECK_ACTION_RESULT_ALLOWED !== $sResult && !in_array($aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']], array_merge($oPrivacy->getPartiallyVisiblePrivacyGroups(), array('s'))))
  616. return $sResult;
  617. return parent::_checkAllowedConnect ($aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap);
  618. }
  619. public function addFollower ($iProfileId1, $iProfileId2)
  620. {
  621. $oConnectionFollow = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  622. if($oConnectionFollow && !$oConnectionFollow->isConnected($iProfileId1, $iProfileId2)){
  623. $oConnectionFollow->addConnection($iProfileId1, $iProfileId2);
  624. return true;
  625. }
  626. return false;
  627. }
  628. public function isFan ($iContentId, $iProfileId = false)
  629. {
  630. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  631. if (isset($this->_oConfig->CNF['OBJECT_CONNECTIONS']))
  632. return $oGroupProfile && ($oConnection = BxDolConnection::getObjectInstance($this->_oConfig->CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $oGroupProfile->id(), true);
  633. return false;
  634. }
  635. public function isInvited ($sKey, $iProfileId)
  636. {
  637. $CNF = &$this->_oConfig->CNF;
  638. $aData = $this->_oDb->getInviteByKey($sKey, $iProfileId);
  639. if (!isset($aData['invited_profile_id']))
  640. return _t($CNF['T']['txt_invitation_popup_error_invitation_absent']);
  641. if ($aData['invited_profile_id'] != bx_get_logged_profile_id())
  642. return _t($CNF['T']['txt_invitation_popup_error_wrong_user']);
  643. return true;
  644. }
  645. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  646. {
  647. $CNF = &$this->_oConfig->CNF;
  648. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aEvent['object_id'], $this->getName());
  649. $sSrc = '';
  650. if(isset($CNF['FIELD_COVER']) && !empty($aContentInfo[$CNF['FIELD_COVER']]))
  651. $sSrc = $oGroupProfile->getCover();
  652. if(empty($sSrc) && isset($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]))
  653. $sSrc = $oGroupProfile->getPicture();
  654. return empty($sSrc) ? array() : array(
  655. array('id' => $aContentInfo[$CNF['FIELD_PICTURE']], 'url' => $sUrl, 'src' => $sSrc, 'src_orig' => $sSrc),
  656. );
  657. }
  658. protected function _prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId)
  659. {
  660. if (!($oGroupProfile = BxDolProfile::getInstance($iGroupProfileId)))
  661. return array(0, 0, null);
  662. if ($oGroupProfile->getModule() == $this->getName()) {
  663. $iProfileId = $iInitiatorId;
  664. $iGroupProfileId = $oGroupProfile->id();
  665. } else {
  666. $iProfileId = $oGroupProfile->id();
  667. $iGroupProfileId = $iInitiatorId;
  668. }
  669. return array($iProfileId, $iGroupProfileId, $oGroupProfile);
  670. }
  671. }
  672. /** @} */