1
0

BxBaseModGroupsModule.php 31 KB

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