BxBaseModGroupsModule.php 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840
  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. define('BX_BASE_MOD_GROUPS_MMODE_MULTI_ROLES', 'multi_roles');
  12. define('BX_BASE_MOD_GROUPS_ROLE_COMMON', 0);
  13. define('BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR', 1);
  14. define('BX_BASE_MOD_GROUPS_ROLE_MODERATOR', 2);
  15. define('BX_BASE_MOD_GROUPS_ACTION_EDIT', 'edit');
  16. define('BX_BASE_MOD_GROUPS_ACTION_CHANGE_COVER', 'change_cover');
  17. define('BX_BASE_MOD_GROUPS_ACTION_INVITE', 'invite');
  18. define('BX_BASE_MOD_GROUPS_ACTION_MANAGE_FANS', 'manage_fans');
  19. define('BX_BASE_MOD_GROUPS_ACTION_MANAGE_ROLES', 'manage_roles');
  20. define('BX_BASE_MOD_GROUPS_ACTION_DELETE', 'delete');
  21. define('BX_BASE_MOD_GROUPS_ACTION_EDIT_CONTENT', 'edit_any');
  22. define('BX_BASE_MOD_GROUPS_ACTION_DELETE_CONTENT', 'delete_any');
  23. define('BX_BASE_MOD_GROUPS_ACTION_TIMELINE_POST_PIN', 'pin'); //for timeline posts only
  24. define('BX_BASE_MOD_GROUPS_PERIOD_UNIT_DAY', 'day');
  25. define('BX_BASE_MOD_GROUPS_PERIOD_UNIT_WEEK', 'week');
  26. define('BX_BASE_MOD_GROUPS_PERIOD_UNIT_MONTH', 'month');
  27. define('BX_BASE_MOD_GROUPS_PERIOD_UNIT_YEAR', 'year');
  28. /**
  29. * Groups profiles module.
  30. */
  31. class BxBaseModGroupsModule extends BxBaseModProfileModule
  32. {
  33. function __construct(&$aModule)
  34. {
  35. parent::__construct($aModule);
  36. $CNF = &$this->_oConfig->CNF;
  37. if(isset($CNF['FIELD_PUBLISHED']))
  38. $this->_aSearchableNamesExcept = array_merge($this->_aSearchableNamesExcept, array(
  39. $CNF['FIELD_PUBLISHED'],
  40. ));
  41. }
  42. /**
  43. * Get possible recipients for start conversation form
  44. */
  45. public function actionAjaxGetInitialMembers ()
  46. {
  47. $sTerm = bx_get('term');
  48. $a = BxDolService::call('system', 'profiles_search', array($sTerm), 'TemplServiceProfiles');
  49. header('Content-Type:text/javascript; charset=utf-8');
  50. echo(json_encode($a));
  51. }
  52. /**
  53. * Process Process Invitation
  54. */
  55. public function actionProcessInvite ($sKey, $iGroupProfileId, $bAccept)
  56. {
  57. $aData = $this->_oDb->getInviteByKey($sKey, $iGroupProfileId);
  58. if (isset($aData['invited_profile_id'])){
  59. $CNF = &$this->_oConfig->CNF;
  60. if (!isset($CNF['OBJECT_CONNECTIONS']) || !($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  61. return '';
  62. $iInvitedProfileId = $aData['invited_profile_id'];
  63. if ($iInvitedProfileId != bx_get_logged_profile_id())
  64. return '';
  65. if ($bAccept){
  66. if($oConnection && !$oConnection->isConnected($iInvitedProfileId, $iGroupProfileId)){
  67. $oConnection->addConnection($iInvitedProfileId, $iGroupProfileId);
  68. $oConnection->addConnection($iGroupProfileId, $iInvitedProfileId);
  69. }
  70. }
  71. $this->_oDb->deleteInviteByKey($sKey, $iGroupProfileId);
  72. }
  73. }
  74. public function actionCheckName()
  75. {
  76. $CNF = &$this->_oConfig->CNF;
  77. $sName = bx_process_input(bx_get('name'));
  78. if(empty($sName))
  79. return echoJson(array());
  80. $sResult = '';
  81. $iId = (int)bx_get('id');
  82. if(!empty($iId)) {
  83. $aPrice = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iId));
  84. if(strcmp($sName, $aPrice[$CNF['FIELD_PRICE_NAME']]) == 0)
  85. $sResult = $sName;
  86. }
  87. echoJson(array(
  88. 'name' => !empty($sResult) ? $sResult : $this->_oConfig->getPriceName($sName)
  89. ));
  90. }
  91. public function serviceManageTools($sType = 'common')
  92. {
  93. $sResult = parent::serviceManageTools($sType);
  94. if(!empty($sResult))
  95. $this->_oTemplate->addJsSystem(['modules/base/groups/js/|manage_tools.js']);
  96. return $sResult;
  97. }
  98. public function serviceGetOptionsMembersMode()
  99. {
  100. $CNF = &$this->_oConfig->CNF;
  101. return array(
  102. array('key' => '', 'value' => _t('_None')),
  103. array('key' => BX_BASE_MOD_GROUPS_MMODE_MULTI_ROLES, 'value' => _t($CNF['T']['option_members_mode_' . BX_BASE_MOD_GROUPS_MMODE_MULTI_ROLES])),
  104. );
  105. }
  106. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  107. {
  108. if(empty($sUnitTemplate))
  109. $sUnitTemplate = 'unit.html';
  110. return parent::serviceGetSearchResultUnit($iContentId, $sUnitTemplate);
  111. }
  112. /**
  113. * @see BxBaseModProfileModule::serviceGetSpaceTitle
  114. */
  115. public function serviceGetSpaceTitle()
  116. {
  117. return _t($this->_oConfig->CNF['T']['txt_sample_single']);
  118. }
  119. /**
  120. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  121. */
  122. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects = false)
  123. {
  124. if (isset($this->_oConfig->CNF['OBJECT_CONNECTIONS'])){
  125. $aConnectionObjects = array($this->_oConfig->CNF['OBJECT_CONNECTIONS'], 'sys_profiles_subscriptions');
  126. return parent::serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects);
  127. }
  128. return parent::serviceGetParticipatingProfiles($iProfileId);
  129. }
  130. /**
  131. * Check if this module entry can be used as profile
  132. */
  133. public function serviceActAsProfile ()
  134. {
  135. return false;
  136. }
  137. /**
  138. * Check if this module is group profile
  139. */
  140. public function serviceIsGroupProfile ()
  141. {
  142. return true;
  143. }
  144. public function serviceIsEnableForContext($iProfileId = 0)
  145. {
  146. $CNF = &$this->_oConfig->CNF;
  147. $sCnfKey = 'ENABLE_FOR_CONTEXT_IN_MODULES';
  148. if(empty($iProfileId) || empty($CNF[$sCnfKey]) || !is_array($CNF[$sCnfKey]))
  149. return false;
  150. if(in_array(BxDolProfile::getInstance($iProfileId)->getModule(), $CNF[$sCnfKey]))
  151. return true;
  152. return false;
  153. }
  154. /**
  155. * check if provided profile is member of the group
  156. */
  157. public function serviceIsFan ($iGroupProfileId, $iProfileId = false)
  158. {
  159. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  160. return $this->isFan($oGroupProfile->getContentId(), $iProfileId);
  161. }
  162. /**
  163. * check if provided profile is admin of the group
  164. */
  165. public function serviceIsAdmin ($iGroupProfileId, $iProfileId = false)
  166. {
  167. if(!$iProfileId)
  168. $iProfileId = bx_get_logged_profile_id();
  169. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  170. $iGroupContentId = $oGroupProfile->getContentId();
  171. if(!$this->isFan($iGroupContentId, $iProfileId))
  172. return false;
  173. $aGroupContentInfo = $this->_oDb->getContentInfoById($iGroupContentId);
  174. return $this->_oDb->isAdmin($iGroupProfileId, $iProfileId, $aGroupContentInfo);
  175. }
  176. public function serviceGetAdminRole($iGroupProfileId, $iProfileId = false)
  177. {
  178. if(!$iProfileId)
  179. $iProfileId = bx_get_logged_profile_id();
  180. if(!$this->serviceIsAdmin($iGroupProfileId, $iProfileId))
  181. return 0;
  182. return $this->_oDb->getRole($iGroupProfileId, $iProfileId);
  183. }
  184. /*
  185. * Get context (group) advanced members who can perform the specified action.
  186. * If 'Roles' are disabled for the context then all context admins are returned.
  187. */
  188. public function serviceGetAdminsByAction($iGroupProfileId, $mixedAction)
  189. {
  190. $aGroupContentInfo = $this->_oDb->getContentInfoByProfileId($iGroupProfileId);
  191. if(empty($aGroupContentInfo) || !is_array($aGroupContentInfo))
  192. return [];
  193. $aAdmins = $this->_oDb->getAdmins($iGroupProfileId);
  194. if(!$this->_oConfig->isRoles())
  195. return $aAdmins;
  196. if(!is_array($mixedAction))
  197. $mixedAction = [$mixedAction];
  198. $aResult = [];
  199. foreach($mixedAction as $sAction)
  200. foreach($aAdmins as $iAdminProfileId)
  201. if(!in_array($iAdminProfileId, $aResult) && $this->isAllowedActionByRole($sAction, $aGroupContentInfo, $iGroupProfileId, $iAdminProfileId))
  202. $aResult[] = $iAdminProfileId;
  203. return $aResult;
  204. }
  205. public function serviceGetAdminsToManageContent($iGroupProfileId)
  206. {
  207. return $this->serviceGetAdminsByAction($iGroupProfileId, [
  208. BX_BASE_MOD_GROUPS_ACTION_EDIT_CONTENT,
  209. BX_BASE_MOD_GROUPS_ACTION_DELETE_CONTENT
  210. ]);
  211. }
  212. /**
  213. * Delete profile from fans and admins tables
  214. * @param $iProfileId profile id
  215. */
  216. public function serviceDeleteProfileFromFansAndAdmins ($iProfileId)
  217. {
  218. $CNF = &$this->_oConfig->CNF;
  219. $this->_oDb->deleteAdminsByProfileId($iProfileId);
  220. if (isset($CNF['OBJECT_CONNECTIONS']) && ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  221. $oConnection->onDeleteInitiatorAndContent($iProfileId);
  222. }
  223. /**
  224. * Reset group's author for particular group
  225. * @param $iContentId group id
  226. * @parem $iAuthorId new author profile ID
  227. * @return false of error, or number of updated records on success
  228. */
  229. public function serviceReassignEntityAuthor ($iContentId, $iAuthorId = 0)
  230. {
  231. $aContentInfo = $this->_oDb->getContentInfoById((int)$iContentId);
  232. if (!$aContentInfo)
  233. return false;
  234. if (empty($iAuthorId)) {
  235. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  236. if (!$oGroupProfile)
  237. return false;
  238. $aAdmins = $this->_oDb->getAdmins($oGroupProfile->id());
  239. if($aAdmins)
  240. $iAuthorId = array_pop($aAdmins);
  241. }
  242. return $this->_oDb->updateAuthorById($iContentId, $iAuthorId);
  243. }
  244. /**
  245. * Entry actions and social sharing block
  246. */
  247. public function serviceEntityAllActions ($mixedContent = false, $aParams = array())
  248. {
  249. $CNF = &$this->_oConfig->CNF;
  250. if(!empty($mixedContent)) {
  251. if(!is_array($mixedContent))
  252. $mixedContent = array((int)$mixedContent, (method_exists($this->_oDb, 'getContentInfoById')) ? $this->_oDb->getContentInfoById((int)$mixedContent) : array());
  253. }
  254. else {
  255. $mixedContent = $this->_getContent();
  256. if($mixedContent === false)
  257. return false;
  258. }
  259. list($iContentId, $aContentInfo) = $mixedContent;
  260. if(!empty($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]))
  261. $aParams = array_merge(array(
  262. 'entry_thumb' => (int)$aContentInfo[$CNF['FIELD_PICTURE']]
  263. ), $aParams);
  264. return parent::serviceEntityAllActions ($mixedContent, $aParams);
  265. }
  266. /**
  267. * Reset group's author when author profile is deleted
  268. * @param $iProfileId author profile id
  269. * @param $iAuthorId new author profile id
  270. * @return number of changed items
  271. */
  272. public function serviceReassignEntitiesByAuthor ($iProfileId, $iAuthorId = 0)
  273. {
  274. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  275. if (!$a)
  276. return 0;
  277. $iCount = 0;
  278. foreach ($a as $aContentInfo)
  279. $iCount += ('' == $this->serviceReassignEntityAuthor($aContentInfo[$this->_oConfig->CNF['FIELD_ID']], $iAuthorId) ? 1 : 0);
  280. return $iCount;
  281. }
  282. public function servicePrepareFields ($aFieldsProfile)
  283. {
  284. $CNF = &$this->_oConfig->CNF;
  285. $aFieldsProfile[$CNF['FIELD_NAME']] = $aFieldsProfile['name'];
  286. $aFieldsProfile[$CNF['FIELD_TEXT']] = isset($aFieldsProfile['description']) ? $aFieldsProfile['description'] : '';
  287. unset($aFieldsProfile['name']);
  288. unset($aFieldsProfile['description']);
  289. return $aFieldsProfile;
  290. }
  291. public function serviceOnRemoveConnection ($iGroupProfileId, $iInitiatorId)
  292. {
  293. $CNF = &$this->_oConfig->CNF;
  294. list ($iProfileId, $iGroupProfileId, $oGroupProfile) = $this->_prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId);
  295. if (!$oGroupProfile)
  296. return false;
  297. $this->_oDb->fromAdmins($iGroupProfileId, $iProfileId);
  298. if ($oConn = BxDolConnection::getObjectInstance('sys_profiles_subscriptions'))
  299. return $oConn->removeConnection($iProfileId, $iGroupProfileId);
  300. return false;
  301. }
  302. public function serviceAddMutualConnection ($iGroupProfileId, $iInitiatorId, $bSendInviteOnly = false)
  303. {
  304. $CNF = &$this->_oConfig->CNF;
  305. list ($iProfileId, $iGroupProfileId, $oGroupProfile) = $this->_prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId);
  306. if (!$oGroupProfile)
  307. return false;
  308. if (!($aContentInfo = $this->_oDb->getContentInfoById((int)BxDolProfile::getInstance($iGroupProfileId)->getContentId())))
  309. return false;
  310. if (!isset($CNF['OBJECT_CONNECTIONS']) || !($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  311. return false;
  312. $sEntryTitle = $aContentInfo[$CNF['FIELD_NAME']];
  313. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  314. // send invitation to the group
  315. $sModule = $this->getName();
  316. if ($bSendInviteOnly && !$oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id()) && !$oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId) && bx_get_logged_profile_id() != $iProfileId) {
  317. bx_alert($sModule, 'join_invitation', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  318. 'content' => $aContentInfo,
  319. 'entry_title' => $sEntryTitle,
  320. 'entry_url' => $sEntryUrl,
  321. 'group_profile' => $iGroupProfileId,
  322. 'profile' => $iProfileId,
  323. 'notification_subobject_id' => $iProfileId,
  324. 'object_author_id' => $iGroupProfileId
  325. ));
  326. /**
  327. * 'Invitation Received' alert for Notifications module.
  328. * Note. It's essential to use Recipient ($iInitiatorId) in 'object_author_id' parameter.
  329. * In this case notification will be received by Recipient profile.
  330. */
  331. bx_alert($sModule, 'join_invitation_notif', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  332. 'object_author_id' => $iInitiatorId,
  333. 'privacy_view' => isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) ? $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] : 3,
  334. ));
  335. }
  336. // send notification to group's admins that new connection is pending confirmation
  337. elseif (!$bSendInviteOnly && $oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id()) && !$oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId) && $aContentInfo['join_confirmation']) {
  338. bx_alert($this->getName(), 'join_request', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  339. 'object_author_id' => $iGroupProfileId,
  340. 'performer_id' => $iProfileId,
  341. 'content' => $aContentInfo,
  342. 'entry_title' => $sEntryTitle,
  343. 'entry_url' => $sEntryUrl,
  344. 'group_profile' => $iGroupProfileId,
  345. 'profile' => $iProfileId
  346. ));
  347. }
  348. // send notification that join request was accepted
  349. else if (!$bSendInviteOnly && $oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id(), true) && $oGroupProfile->getModule() != $this->getName() && bx_get_logged_profile_id() != $iProfileId) {
  350. bx_alert($this->getName(), 'join_request_accepted', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  351. 'object_author_id' => $iGroupProfileId,
  352. 'performer_id' => $iProfileId,
  353. 'content' => $aContentInfo,
  354. 'entry_title' => $sEntryTitle,
  355. 'entry_url' => $sEntryUrl,
  356. 'group_profile' => $iGroupProfileId,
  357. 'profile' => $iProfileId
  358. ));
  359. }
  360. // new fan was added
  361. if ($oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId, true)) {
  362. // follow group on join
  363. if (BxDolService::call($oGroupProfile->getModule(), 'act_as_profile')){
  364. $this->addFollower($oGroupProfile->id(), (int)$iInitiatorId);
  365. }
  366. else{
  367. $this->addFollower((int)$iInitiatorId, $oGroupProfile->id());
  368. }
  369. bx_alert($this->getName(), 'fan_added', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  370. 'object_author_id' => $iGroupProfileId,
  371. 'performer_id' => $iProfileId,
  372. 'content' => $aContentInfo,
  373. 'entry_title' => $sEntryTitle,
  374. 'entry_url' => $sEntryUrl,
  375. 'group_profile' => $iGroupProfileId,
  376. 'profile' => $iProfileId,
  377. ));
  378. $this->doAudit($iGroupProfileId, $iInitiatorId, '_sys_audit_action_group_join_request_accepted');
  379. return false;
  380. }
  381. // don't automatically add connection (mutual) if group requires manual join confirmation
  382. if ($bSendInviteOnly || $aContentInfo['join_confirmation'])
  383. return false;
  384. // check if connection already exists
  385. if ($oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId, true) || $oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId))
  386. return false;
  387. if (!$oConnection->addConnection($oGroupProfile->id(), (int)$iInitiatorId))
  388. return false;
  389. return true;
  390. }
  391. public function serviceFansTable ()
  392. {
  393. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID_CONNECTIONS']);
  394. if (!$oGrid)
  395. return false;
  396. return $oGrid->getCode();
  397. }
  398. public function serviceInvitesTable ()
  399. {
  400. if (!isset($this->_oConfig->CNF['OBJECT_GRID_INVITES']))
  401. return false;
  402. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID_INVITES']);
  403. if (!$oGrid)
  404. return false;
  405. return $oGrid->getCode();
  406. }
  407. public function serviceFans ($iContentId = 0, $bAsArray = false)
  408. {
  409. if (!$iContentId)
  410. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  411. if (!$iContentId)
  412. return false;
  413. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  414. if (!$aContentInfo)
  415. return false;
  416. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
  417. return false;
  418. if(!$bAsArray) {
  419. bx_import('BxDolConnection');
  420. $mixedResult = $this->serviceBrowseConnectionsQuick ($oGroupProfile->id(), $this->_oConfig->CNF['OBJECT_CONNECTIONS'], BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  421. if (!$mixedResult)
  422. return MsgBox(_t('_sys_txt_empty'));
  423. }
  424. else
  425. $mixedResult = BxDolConnection::getObjectInstance($this->_oConfig->CNF['OBJECT_CONNECTIONS'])->getConnectedContent($oGroupProfile->id(), true);
  426. return $mixedResult;
  427. }
  428. public function serviceFansWithoutAdmins ($iContentId = 0, $bAsArray = false)
  429. {
  430. if (!$iContentId)
  431. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  432. if (!$iContentId)
  433. return false;
  434. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  435. if (!$aContentInfo)
  436. return false;
  437. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
  438. return false;
  439. $CNF = &$this->_oConfig->CNF;
  440. $aFans = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])->getConnectedContent($oGroupProfile->id(), true);
  441. if(empty($aFans) || !is_array($aFans))
  442. return false;
  443. $aAdmins = $this->_oDb->getAdmins($oGroupProfile->id());
  444. if(!empty($aAdmins) && is_array($aAdmins))
  445. $aFans = array_diff($aFans, $aAdmins);
  446. $iStart = (int)bx_get('start');
  447. $iLimit = !empty($CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($CNF['PARAM_NUM_CONNECTIONS_QUICK']) : 4;
  448. if(!$iLimit)
  449. $iLimit = 4;
  450. return $this->_serviceBrowseQuick($aFans, $iStart, $iLimit);
  451. }
  452. public function serviceAdmins ($iContentId = 0)
  453. {
  454. $CNF = &$this->_oConfig->CNF;
  455. if(!$iContentId)
  456. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  457. if(!$iContentId)
  458. return false;
  459. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  460. if(!$oGroupProfile)
  461. return false;
  462. $iStart = (int)bx_get('start');
  463. $iLimit = !empty($CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($CNF['PARAM_NUM_CONNECTIONS_QUICK']) : 4;
  464. if(!$iLimit)
  465. $iLimit = 4;
  466. $aProfiles = $this->_oDb->getAdmins($oGroupProfile->id(), $iStart, $iLimit+1);
  467. if(empty($aProfiles) || !is_array($aProfiles))
  468. return false;
  469. return $this->_serviceBrowseQuick($aProfiles, $iStart, $iLimit);
  470. }
  471. public function serviceBrowseJoinedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  472. {
  473. if (!$iProfileId)
  474. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  475. if (!$iProfileId)
  476. return '';
  477. return $this->_serviceBrowse ('joined_entries', array('joined_profile' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  478. }
  479. public function serviceBrowseCreatedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  480. {
  481. if (!$iProfileId)
  482. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  483. if (!$iProfileId)
  484. return '';
  485. return $this->_serviceBrowse ('created_entries', array('author' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  486. }
  487. public function serviceEntityPricing($iProfileId = 0)
  488. {
  489. $CNF = &$this->_oConfig->CNF;
  490. if(!$iProfileId)
  491. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  492. if(!$iProfileId)
  493. return '';
  494. if(!$this->_oConfig->isPaidJoin())
  495. return '';
  496. if($this->checkAllowedUsePaidJoin() !== CHECK_ACTION_RESULT_ALLOWED)
  497. return MsgBox(_t('_Access denied'));
  498. if($this->checkAllowedManageAdmins($iProfileId) !== CHECK_ACTION_RESULT_ALLOWED)
  499. return MsgBox(_t('_Access denied'));
  500. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_PRICES_MANAGE']);
  501. if(!$oGrid)
  502. return '';
  503. return $oGrid->getCode();
  504. }
  505. public function serviceEntityJoin($iProfileId = 0)
  506. {
  507. $CNF = &$this->_oConfig->CNF;
  508. if(!$iProfileId)
  509. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  510. if(!$iProfileId)
  511. return '';
  512. if(!$this->_oConfig->isPaidJoin())
  513. return '';
  514. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_PRICES_VIEW']);
  515. if(!$oGrid)
  516. return '';
  517. return $oGrid->getCode();
  518. }
  519. public function serviceEntityInvite ($iContentId = 0, $bErrorMsg = true)
  520. {
  521. if (isset($this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_INVITE']))
  522. return $this->_serviceEntityForm ('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_INVITE'], false, $bErrorMsg);
  523. return false;
  524. }
  525. /**
  526. * Entry social sharing block
  527. */
  528. public function serviceEntitySocialSharing ($mixedContent = false, $aParams = array())
  529. {
  530. if(!empty($mixedContent)) {
  531. if(!is_array($mixedContent))
  532. $mixedContent = array((int)$mixedContent, array());
  533. }
  534. else {
  535. $mixedContent = $this->_getContent();
  536. if($mixedContent === false)
  537. return false;
  538. }
  539. list($iContentId, $aContentInfo) = $mixedContent;
  540. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  541. if(!$oGroupProfile)
  542. return false;
  543. return parent::serviceEntitySocialSharing(array($iContentId, $aContentInfo), array(
  544. 'title' => $oGroupProfile->getDisplayName()
  545. ));
  546. }
  547. public function serviceIsPricingAvaliable($iProfileId)
  548. {
  549. if(!$this->_oConfig->isPaidJoin())
  550. return false;
  551. if($this->checkAllowedUsePaidJoin() !== CHECK_ACTION_RESULT_ALLOWED)
  552. return false;
  553. if($this->checkAllowedManageAdmins($iProfileId) !== CHECK_ACTION_RESULT_ALLOWED)
  554. return false;
  555. return true;
  556. }
  557. public function serviceIsPaidJoinAvaliable($iGroupProfileId, $iProfileId = 0)
  558. {
  559. return $this->isPaidJoinByProfileForProfile($iGroupProfileId, $iProfileId);
  560. }
  561. public function serviceIsPaidJoinAvaliableByContent($iGroupContentId, $iProfileId = 0)
  562. {
  563. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iGroupContentId, $this->getName());
  564. if(!$oGroupProfile)
  565. return false;
  566. return $this->isPaidJoinByProfileForProfile($oGroupProfile->id(), $iProfileId);
  567. }
  568. public function serviceIsFreeJoinAvaliable($iGroupProfileId, $iProfileId = 0)
  569. {
  570. return !$this->isPaidJoinByProfileForProfile($iGroupProfileId, $iProfileId);
  571. }
  572. public function serviceIsFreeJoinAvaliableByContent($iGroupContentId, $iProfileId = 0)
  573. {
  574. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iGroupContentId, $this->getName());
  575. if(!$oGroupProfile)
  576. return false;
  577. return !$this->isPaidJoinByProfileForProfile($oGroupProfile->id(), $iProfileId);
  578. }
  579. /**
  580. * Is Paid Join enabled in the group and whether a profile can use it.
  581. *
  582. * @param type $iGroupProfileId - Group profile ID.
  583. * @param type $iProfileId - Profile ID of the user who wants to join.
  584. * @return boolean
  585. */
  586. public function isPaidJoinByProfileForProfile($iGroupProfileId, $iProfileId = 0)
  587. {
  588. $CNF = &$this->_oConfig->CNF;
  589. if(empty($iProfileId))
  590. $iProfileId = $this->_iProfileId;
  591. if(BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])->isConnected($iProfileId, $iGroupProfileId))
  592. return false;
  593. return $this->isPaidJoinByProfile($iGroupProfileId);
  594. }
  595. /**
  596. * Is Paid Join enabled as is and whether a group has pricing plans added.
  597. *
  598. * @param type $iGroupProfileId - Group profile ID.
  599. * @return boolean
  600. */
  601. public function isPaidJoinByProfile($iGroupProfileId)
  602. {
  603. if(!$this->_oConfig->isPaidJoin())
  604. return false;
  605. $aPrices = $this->_oDb->getPrices(array('type' => 'by_profile_id', 'profile_id' => $iGroupProfileId));
  606. if(empty($aPrices) || !is_array($aPrices))
  607. return false;
  608. return true;
  609. }
  610. /**
  611. * Integration with Payments.
  612. */
  613. public function serviceGetPaymentData()
  614. {
  615. return $this->_aModule;
  616. }
  617. public function serviceGetCartItem($mixedItemId)
  618. {
  619. $CNF = &$this->_oConfig->CNF;
  620. if(!$mixedItemId)
  621. return array();
  622. if(is_numeric($mixedItemId))
  623. $aItem = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => (int)$mixedItemId));
  624. else
  625. $aItem = $this->_oDb->getPrices(array('type' => 'by_name', 'value' => $mixedItemId));
  626. if(empty($aItem) || !is_array($aItem))
  627. return array();
  628. if(!$this->isPaidJoinByProfile($aItem['profile_id']))
  629. return array();
  630. $oGroupProfile = BxDolProfile::getInstance($aItem['profile_id']);
  631. if(!$oGroupProfile)
  632. return array();
  633. $aGroupProfile = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  634. $aRoles = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_ROLES']);
  635. return array (
  636. 'id' => $aItem['id'],
  637. 'author_id' => $aGroupProfile[$CNF['FIELD_AUTHOR']],
  638. 'name' => $aItem['name'],
  639. 'title' => _t($CNF['T']['txt_cart_item_title'], $oGroupProfile->getDisplayName(), $aRoles[$aItem['role_id']], $aItem['period'], $aItem['period_unit']),
  640. 'description' => '',
  641. 'url' => $oGroupProfile->getUrl(),
  642. 'price_single' => $aItem['price'],
  643. 'price_recurring' => $aItem['price'],
  644. 'period_recurring' => $aItem['period'],
  645. 'period_unit_recurring' => $aItem['period_unit'],
  646. 'trial_recurring' => 0
  647. );
  648. }
  649. public function serviceGetCartItems($iSellerId)
  650. {
  651. $CNF = &$this->_oConfig->CNF;
  652. if(empty($iSellerId))
  653. return array();
  654. $sModule = $this->getName();
  655. $aRoles = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_ROLES']);
  656. $aGroups = $this->_oDb->getEntriesBy(array('type' => 'author', 'author' => $iSellerId));
  657. $aResult = array();
  658. foreach($aGroups as $aGroup) {
  659. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aGroup[$CNF['FIELD_ID']], $sModule);
  660. if(!$oGroupProfile)
  661. continue;
  662. $aPrices = $this->_oDb->getPrices(array('type' => 'by_profile_id', 'profile_id' => $oGroupProfile->id()));
  663. if(empty($aPrices) || !is_array($aPrices))
  664. continue;
  665. $sTitle = $oGroupProfile->getDisplayName();
  666. $sUrl = $oGroupProfile->getUrl();
  667. foreach($aPrices as $aPrice)
  668. $aResult[] = array(
  669. 'id' => $aPrice['id'],
  670. 'author_id' => $iSellerId,
  671. 'name' => $aPrice['name'],
  672. 'title' => _t($CNF['T']['txt_cart_item_title'], $sTitle, $aRoles[$aPrice['role_id']], $aPrice['period'], $aPrice['period_unit']),
  673. 'description' => '',
  674. 'url' => $sUrl,
  675. 'price_single' => $aPrice['price'],
  676. 'price_recurring' => $aPrice['price'],
  677. 'period_recurring' => $aPrice['period'],
  678. 'period_unit_recurring' => $aPrice['period_unit']
  679. );
  680. }
  681. return $aResult;
  682. }
  683. public function serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  684. {
  685. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  686. }
  687. public function serviceRegisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  688. {
  689. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  690. }
  691. public function serviceReregisterCartItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  692. {
  693. return $this->_serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder);
  694. }
  695. public function serviceReregisterSubscriptionItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  696. {
  697. return $this->_serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder);
  698. }
  699. public function serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  700. {
  701. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  702. }
  703. public function serviceUnregisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  704. {
  705. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  706. }
  707. public function serviceCancelSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  708. {
  709. return true;
  710. }
  711. protected function _serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  712. {
  713. $CNF = &$this->_oConfig->CNF;
  714. $aItem = $this->serviceGetCartItem($iItemId);
  715. if(empty($aItem) || !is_array($aItem))
  716. return array();
  717. $aItemInfo = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemId));
  718. $mixedPeriod = false;
  719. if((int)$aItemInfo['period'] != 0)
  720. $mixedPeriod = array(
  721. 'period' => (int)$aItemInfo['period'],
  722. 'period_unit' => $aItemInfo['period_unit'],
  723. 'period_reserve' => $CNF['PARAM_RECURRING_RESERVE']
  724. );
  725. if(!$this->setRole($aItemInfo['profile_id'], $iClientId, $aItemInfo['role_id'], $mixedPeriod, $sOrder))
  726. return array();
  727. return $aItem;
  728. }
  729. protected function _serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  730. {
  731. $aItem = $this->serviceGetCartItem($iItemIdNew);
  732. if(empty($aItem) || !is_array($aItem))
  733. return array();
  734. $aItemInfoOld = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemIdOld));
  735. if(empty($aItemInfoOld) || !is_array($aItemInfoOld))
  736. return array();
  737. $aItemInfoNew = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemIdNew));
  738. if(empty($aItemInfoNew) || !is_array($aItemInfoNew))
  739. return array();
  740. if(!$this->unsetRole($aItemInfoOld['profile_id'], $iClientId))
  741. return array();
  742. $aResult = $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemIdNew, 1, $sOrder);
  743. if(empty($aResult) || !is_array($aResult))
  744. return array();
  745. return $aItem;
  746. }
  747. protected function _serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  748. {
  749. $aItemInfo = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemId));
  750. if(empty($aItemInfo) || !is_array($aItemInfo))
  751. return false;
  752. return $this->unsetRole($aItemInfo['profile_id'], $iClientId);
  753. }
  754. /**
  755. * Data for Notifications module
  756. */
  757. public function serviceGetNotificationsData()
  758. {
  759. $sModule = $this->_aModule['name'];
  760. $aSettingsTypes = array('follow_member', 'follow_context');
  761. if($this->serviceActAsProfile())
  762. $aSettingsTypes = array('personal', 'follow_member');
  763. return array(
  764. 'handlers' => array(
  765. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  766. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  767. 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'),
  768. 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'),
  769. 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'),
  770. array('group' => $sModule . '_join_invitation', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'join_invitation_notif', 'module_name' => $sModule, 'module_method' => 'get_notifications_join_invitation', 'module_class' => 'Module'),
  771. 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']),
  772. 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'),
  773. ),
  774. 'settings' => array(
  775. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => $aSettingsTypes),
  776. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => $aSettingsTypes),
  777. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => $aSettingsTypes),
  778. array('group' => 'fan', 'unit' => $sModule, 'action' => 'fan_added', 'types' => $aSettingsTypes),
  779. array('group' => 'invite', 'unit' => $sModule, 'action' => 'join_invitation_notif', 'types' => array('personal')),
  780. array('group' => 'join', 'unit' => $sModule, 'action' => 'join_request', 'types' => $aSettingsTypes),
  781. array('group' => 'timeline_post', 'unit' => $sModule, 'action' => 'timeline_post_common', 'types' => $aSettingsTypes)
  782. ),
  783. 'alerts' => array(
  784. array('unit' => $sModule, 'action' => 'doVote'),
  785. array('unit' => $sModule, 'action' => 'undoVote'),
  786. array('unit' => $sModule, 'action' => 'doVoteUp'),
  787. array('unit' => $sModule, 'action' => 'doVoteDown'),
  788. array('unit' => $sModule, 'action' => 'fan_added'),
  789. array('unit' => $sModule, 'action' => 'join_invitation_notif'),
  790. array('unit' => $sModule, 'action' => 'join_request'),
  791. array('unit' => $sModule, 'action' => 'timeline_post_common'),
  792. )
  793. );
  794. }
  795. /**
  796. * Notification about new invitation to join the group
  797. */
  798. public function serviceGetNotificationsJoinInvitation($aEvent)
  799. {
  800. $CNF = &$this->_oConfig->CNF;
  801. $iContentId = (int)$aEvent['object_id'];
  802. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  803. if(!$oGroupProfile)
  804. return array();
  805. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  806. if(empty($aContentInfo) || !is_array($aContentInfo))
  807. return array();
  808. /*
  809. * It's essential that 'object_owner_id' contains invited member profile id.
  810. */
  811. $oProfile = BxDolProfile::getInstance((int)$aEvent['object_owner_id']);
  812. if(!$oProfile)
  813. return array();
  814. /*
  815. * Note. Group Profile URL is used for both Entry and Subentry URLs,
  816. * because Subentry URL has higher display priority and notification
  817. * should be linked to Group Profile (Group Profile -> Members tab)
  818. * instead of Personal Profile of invited member.
  819. */
  820. $sEntryUrl = $oGroupProfile->getUrl();
  821. return array(
  822. 'entry_sample' => $CNF['T']['txt_sample_single'],
  823. 'entry_url' => $sEntryUrl,
  824. 'entry_caption' => $oGroupProfile->getDisplayName(),
  825. 'subentry_sample' => $oProfile->getDisplayName(),
  826. 'subentry_url' => $sEntryUrl,
  827. 'lang_key' => $this->_oConfig->CNF['T']['txt_ntfs_join_invitation']
  828. );
  829. }
  830. /**
  831. * Notification about new member requst in the group
  832. */
  833. public function serviceGetNotificationsJoinRequest($aEvent)
  834. {
  835. return $this->_serviceGetNotification($aEvent, $this->_oConfig->CNF['T']['txt_ntfs_join_request']);
  836. }
  837. /**
  838. * Notification about new member in the group
  839. */
  840. public function serviceGetNotificationsFanAdded($aEvent)
  841. {
  842. return $this->_serviceGetNotification($aEvent, $this->_oConfig->CNF['T']['txt_ntfs_fan_added']);
  843. }
  844. protected function _serviceGetNotification($aEvent, $sLangKey)
  845. {
  846. $CNF = &$this->_oConfig->CNF;
  847. $iContentId = (int)$aEvent['object_id'];
  848. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  849. if(!$oGroupProfile)
  850. return array();
  851. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  852. if(empty($aContentInfo) || !is_array($aContentInfo))
  853. return array();
  854. $oProfile = BxDolProfile::getInstance((int)$aEvent['subobject_id']);
  855. if(!$oProfile)
  856. return array();
  857. /*
  858. * Note. Group Profile URL is used for both Entry and Subentry URLs,
  859. * because Subentry URL has higher display priority and notification
  860. * should be linked to Group Profile (Group Profile -> Members tab)
  861. * instead of Personal Profile of a member, who performed an action.
  862. */
  863. $sEntryUrl = $oGroupProfile->getUrl();
  864. if(!empty($CNF['URL_ENTRY_FANS']))
  865. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_ENTRY_FANS'], array(
  866. 'profile_id' => $oGroupProfile->id()
  867. ));
  868. return array(
  869. 'entry_sample' => $CNF['T']['txt_sample_single'],
  870. 'entry_url' => $sEntryUrl,
  871. 'entry_caption' => $oGroupProfile->getDisplayName(),
  872. 'entry_author' => $oGroupProfile->id(),
  873. 'subentry_sample' => $oProfile->getDisplayName(),
  874. 'subentry_url' => $sEntryUrl,
  875. 'lang_key' => $sLangKey
  876. );
  877. }
  878. /**
  879. * Data for Timeline module
  880. */
  881. public function serviceGetTimelineData()
  882. {
  883. return BxBaseModGeneralModule::serviceGetTimelineData();
  884. }
  885. /**
  886. * Entry post for Timeline module
  887. */
  888. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  889. {
  890. $CNF = &$this->_oConfig->CNF;
  891. $a = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  892. if($a === false)
  893. return false;
  894. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aEvent['object_id'], $this->getName());
  895. $a['content']['url'] = $oGroupProfile->getUrl();
  896. $a['content']['title'] = $oGroupProfile->getDisplayName();
  897. if(isset($CNF['FIELD_PUBLISHED'])) {
  898. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  899. if($aContentInfo[$CNF['FIELD_PUBLISHED']] > $a['date'])
  900. $a['date'] = $aContentInfo[$CNF['FIELD_PUBLISHED']];
  901. }
  902. return $a;
  903. }
  904. // ====== PERMISSION METHODS
  905. /**
  906. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  907. */
  908. public function checkAllowedUsePaidJoin($isPerformAction = false)
  909. {
  910. // check ACL
  911. $aCheck = checkActionModule($this->_iProfileId, 'use paid join', $this->getName(), $isPerformAction);
  912. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  913. return $aCheck[CHECK_ACTION_MESSAGE];
  914. return CHECK_ACTION_RESULT_ALLOWED;
  915. }
  916. /**
  917. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  918. */
  919. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  920. {
  921. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  922. }
  923. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  924. {
  925. $CNF = &$this->_oConfig->CNF;
  926. $bInvited = false;
  927. if(!empty($CNF['TABLE_INVITES']) && bx_get('key')){
  928. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  929. $mixedInvited = $this->isInvited(bx_get('key'), $oGroupProfile->id());
  930. if($mixedInvited === true)
  931. $bInvited = true;
  932. }
  933. if ($this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $iProfileId) || $bInvited)
  934. return CHECK_ACTION_RESULT_ALLOWED;
  935. return parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  936. }
  937. /**
  938. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  939. */
  940. public function checkAllowedCompose(&$aDataEntry, $isPerformAction = false)
  941. {
  942. if(!$this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]))
  943. return _t('_sys_txt_access_denied');
  944. return parent::checkAllowedCompose ($aDataEntry, $isPerformAction);
  945. }
  946. /**
  947. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  948. */
  949. public function checkAllowedFanAdd(&$aDataEntry, $isPerformAction = false)
  950. {
  951. $mixedResult = $this->_modGroupsCheckAllowedFanAdd($aDataEntry, $isPerformAction);
  952. // call alert to allow custom checks
  953. bx_alert('system', 'check_allowed_fan_add', 0, 0, array(
  954. 'module' => $this->getName(),
  955. 'content_info' => $aDataEntry,
  956. 'profile_id' => bx_get_logged_profile_id(),
  957. 'override_result' => &$mixedResult
  958. ));
  959. return $mixedResult;
  960. }
  961. public function _modGroupsCheckAllowedFanAdd (&$aDataEntry, $isPerformAction = false)
  962. {
  963. if ($this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]) || !isLogged())
  964. return _t('_sys_txt_access_denied');
  965. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], true, false);
  966. }
  967. /**
  968. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  969. */
  970. public function checkAllowedFanRemove (&$aDataEntry, $isPerformAction = false)
  971. {
  972. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, true))
  973. return CHECK_ACTION_RESULT_ALLOWED;
  974. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, false);
  975. }
  976. protected function _checkAllowedActionByFan($sAction, $aDataEntry, $iProfileId = 0)
  977. {
  978. $CNF = &$this->_oConfig->CNF;
  979. $bRoles = $this->_oConfig->isRoles();
  980. if(empty($iProfileId))
  981. $iProfileId = bx_get_logged_profile_id();
  982. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  983. if(!$oGroupProfile)
  984. return $sAction == BX_BASE_MOD_GROUPS_ACTION_DELETE ? CHECK_ACTION_RESULT_ALLOWED : _t('_sys_txt_not_found');
  985. $iGroupProfileId = $oGroupProfile->id();
  986. if(!$bRoles && $this->_oDb->isAdmin($iGroupProfileId, $iProfileId, $aDataEntry))
  987. return CHECK_ACTION_RESULT_ALLOWED;
  988. if($bRoles && $this->isAllowedActionByRole($sAction, $aDataEntry, $iGroupProfileId, $iProfileId))
  989. return CHECK_ACTION_RESULT_ALLOWED;
  990. return _t('_sys_txt_access_denied');
  991. }
  992. public function isAllowedActionByRole($mAction, $aDataEntry, $iGroupProfileId, $iProfileId)
  993. {
  994. $iProfileRole = $this->_oDb->getRole($iGroupProfileId, $iProfileId);
  995. if (is_array($mAction)) {
  996. $sAction = $mAction['action'];
  997. $sActionModule = $mAction['module'];
  998. } else {
  999. $sAction = $mAction;
  1000. $sActionModule = $this->getName();
  1001. }
  1002. $bResult = false;
  1003. if($iProfileId)
  1004. $bResult = $this->isAllowedModuleActionByRole($sActionModule, $sAction, $iProfileRole);
  1005. // in case neither of the profile's roles are having permissions set explicitly then fallback to an old way
  1006. if ($bResult === NULL) {
  1007. $bResult = false;
  1008. if($this->isFanByGroupProfileId($iGroupProfileId)) {
  1009. switch ($sAction) {
  1010. case BX_BASE_MOD_GROUPS_ACTION_DELETE:
  1011. case BX_BASE_MOD_GROUPS_ACTION_EDIT:
  1012. case BX_BASE_MOD_GROUPS_ACTION_CHANGE_COVER:
  1013. case BX_BASE_MOD_GROUPS_ACTION_MANAGE_ROLES:
  1014. if($this->isRole($iProfileRole, BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR))
  1015. $bResult = true;
  1016. break;
  1017. case BX_BASE_MOD_GROUPS_ACTION_MANAGE_FANS:
  1018. case BX_BASE_MOD_GROUPS_ACTION_INVITE:
  1019. case BX_BASE_MOD_GROUPS_ACTION_EDIT_CONTENT:
  1020. case BX_BASE_MOD_GROUPS_ACTION_DELETE_CONTENT:
  1021. case BX_BASE_MOD_GROUPS_ACTION_TIMELINE_POST_PIN:
  1022. if($this->isRole($iProfileRole, BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR) || $this->isRole($iProfileRole, BX_BASE_MOD_GROUPS_ROLE_MODERATOR))
  1023. $bResult = true;
  1024. break;
  1025. default:
  1026. $bResult = true;
  1027. }
  1028. }
  1029. }
  1030. // call alert to allow custom checks
  1031. bx_alert('system', 'check_allowed_action_by_role', 0, 0, [
  1032. 'module' => $this->getName(),
  1033. 'multi_roles' => $this->_oConfig->isMultiRoles(),
  1034. 'action' => $sAction,
  1035. 'action_module' => $sActionModule,
  1036. 'content_profile_id' => $iGroupProfileId,
  1037. 'content_info' => $aDataEntry,
  1038. 'profile_id' => $iProfileId,
  1039. 'profile_role' => $iProfileRole,
  1040. 'override_result' => &$bResult
  1041. ]);
  1042. return $bResult;
  1043. }
  1044. public function isAllowedModuleActionByRole($sModule, $sAction, $iProfileRole)
  1045. {
  1046. static $aRoles;
  1047. if (!$aRoles && isset($this->_oConfig->CNF['OBJECT_PRE_LIST_ROLES']) && !empty($this->_oConfig->CNF['OBJECT_PRE_LIST_ROLES']))
  1048. $aRoles = BxBaseFormView::getDataItems($this->_oConfig->CNF['OBJECT_PRE_LIST_ROLES'], true, BX_DATA_VALUES_ALL);
  1049. if ($aRoles) {
  1050. foreach ($aRoles as $iRole => $aRoleData) {
  1051. if ($iRole == 0 && $iProfileRole == 0 || $iRole > 0 && $this->isRole($iProfileRole, $iRole)) {
  1052. $mPermissions = isset($aRoles[$iRole]) && isset($aRoles[$iRole]['Data']) && !empty($aRoles[$iRole]['Data']) ? unserialize($aRoles[$iRole]['Data']) : false;
  1053. if ($mPermissions && isset($mPermissions[$sModule])) {
  1054. return isset($mPermissions[$sModule][$sAction]) && $mPermissions[$sModule][$sAction];
  1055. }
  1056. }
  1057. }
  1058. }
  1059. return NULL;
  1060. }
  1061. public function isAllowedModuleActionByProfile($iContentId, $sPostModule, $sAction, $iProfileId = 0) {
  1062. if (!$iProfileId) $iProfileId = bx_get_logged_profile_id();
  1063. if ($iProfileId && $this->isFan($iContentId, $iProfileId)) {
  1064. $sModuleName = $this->getName();
  1065. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModuleName);
  1066. $aDataEntry = $this->_oDb->getContentInfoById($iContentId);
  1067. $bResult = $this->isAllowedActionByRole(['action' => $sAction, 'module' => $sPostModule], $aDataEntry, $oGroupProfile->id(), $iProfileId);
  1068. if ($bResult === true) return CHECK_ACTION_RESULT_ALLOWED;
  1069. if ($bResult === false) return _t('_sys_txt_access_denied');
  1070. }
  1071. return NULL; //undefined, because the profile is either not a fan or his role is not having permissions defined. So process the default way then.
  1072. }
  1073. public function isRole($iProfileRole, $iRole)
  1074. {
  1075. if(!$this->_oConfig->isMultiRoles())
  1076. return $iProfileRole == $iRole;
  1077. else
  1078. return $iProfileRole & (1 << ($iRole - 1));
  1079. }
  1080. public function serviceIsRole($iProfileRole, $iRole)
  1081. {
  1082. return $this->isRole($iProfileRole, $iRole);
  1083. }
  1084. public function checkAllowedManageFans($mixedDataEntry, $isPerformAction = false)
  1085. {
  1086. $aDataEntry = array();
  1087. if(!is_array($mixedDataEntry)) {
  1088. $oGroupProfile = BxDolProfile::getInstance((int)$mixedDataEntry);
  1089. if($oGroupProfile && $this->getName() == $oGroupProfile->getModule())
  1090. $aDataEntry = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  1091. }
  1092. else
  1093. $aDataEntry = $mixedDataEntry;
  1094. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_MANAGE_FANS, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1095. return CHECK_ACTION_RESULT_ALLOWED;
  1096. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  1097. }
  1098. public function checkAllowedManageAdmins($mixedDataEntry, $isPerformAction = false)
  1099. {
  1100. $aDataEntry = array();
  1101. if(!is_array($mixedDataEntry)) {
  1102. $oGroupProfile = BxDolProfile::getInstance((int)$mixedDataEntry);
  1103. if($oGroupProfile && $this->getName() == $oGroupProfile->getModule())
  1104. $aDataEntry = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  1105. }
  1106. else
  1107. $aDataEntry = $mixedDataEntry;
  1108. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_MANAGE_ROLES, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1109. return CHECK_ACTION_RESULT_ALLOWED;
  1110. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  1111. }
  1112. public function checkAllowedEdit($aDataEntry, $isPerformAction = false)
  1113. {
  1114. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_EDIT, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1115. return CHECK_ACTION_RESULT_ALLOWED;
  1116. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  1117. }
  1118. public function checkAllowedInvite($aDataEntry, $isPerformAction = false)
  1119. {
  1120. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_INVITE, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1121. return CHECK_ACTION_RESULT_ALLOWED;
  1122. return $this->checkAllowedEdit ($aDataEntry, $isPerformAction);
  1123. }
  1124. public function checkAllowedChangeCover($aDataEntry, $isPerformAction = false)
  1125. {
  1126. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_CHANGE_COVER, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1127. return CHECK_ACTION_RESULT_ALLOWED;
  1128. return parent::checkAllowedChangeCover($aDataEntry, $isPerformAction);
  1129. }
  1130. public function checkAllowedDelete(&$aDataEntry, $isPerformAction = false)
  1131. {
  1132. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_DELETE, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1133. return CHECK_ACTION_RESULT_ALLOWED;
  1134. return parent::checkAllowedDelete($aDataEntry, $isPerformAction);
  1135. }
  1136. public function checkAllowedJoin(&$aDataEntry, $isPerformAction = false)
  1137. {
  1138. if (bx_get('key')){
  1139. $sKey = bx_get('key');
  1140. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  1141. $aData = $this->_oDb->getInviteByKey($sKey, $oGroupProfile->id());
  1142. if (isset($aData['invited_profile_id']) && $aData['invited_profile_id'] == bx_get_logged_profile_id()){
  1143. return CHECK_ACTION_RESULT_ALLOWED;
  1144. }
  1145. }
  1146. return _t('_sys_txt_access_denied');
  1147. }
  1148. public function checkAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1149. {
  1150. $mixedResult = $this->_modGroupsCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  1151. // call alert to allow custom checks
  1152. bx_alert('system', 'check_allowed_subscribe_add', 0, 0, array(
  1153. 'module' => $this->getName(),
  1154. 'content_info' => $aDataEntry,
  1155. 'profile_id' => bx_get_logged_profile_id(),
  1156. 'override_result' => &$mixedResult
  1157. ));
  1158. return $mixedResult;
  1159. }
  1160. /**
  1161. * Note. Is mainly needed for internal usage. Access level is 'public' to allow outer calls from alerts.
  1162. */
  1163. public function _modGroupsCheckAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1164. {
  1165. $CNF = &$this->_oConfig->CNF;
  1166. if(!$this->isFan($aDataEntry[$CNF['FIELD_ID']]) && (!isset($CNF['PARAM_SBS_WO_JOIN']) || getParam($CNF['PARAM_SBS_WO_JOIN']) != 'on'))
  1167. return _t('_sys_txt_access_denied');
  1168. return parent::_modProfileCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  1169. }
  1170. /**
  1171. * @deprecated since version 11.0.3 and can be removed in the next version.
  1172. */
  1173. public function _checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  1174. {
  1175. return parent::checkAllowedSubscribeAdd ($aDataEntry, $isPerformAction);
  1176. }
  1177. public function doAudit($iGroupProfileId, $iFanId, $sAction)
  1178. {
  1179. $oProfile = BxDolProfile::getInstance($iFanId);
  1180. $iContentId = $oProfile->getContentId();
  1181. $sModule = $oProfile->getModule();
  1182. $oModule = BxDolModule::getInstance($sModule);
  1183. if (BxDolRequest::serviceExists($sModule, 'act_as_profile') && BxDolService::call($sModule, 'act_as_profile') && $oModule->_oConfig){
  1184. $CNF = $oModule->_oConfig->CNF;
  1185. $aContentInfo = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $iContentId))) : array();
  1186. $AuditParams = array(
  1187. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  1188. 'context_profile_id' => $iGroupProfileId,
  1189. 'context_profile_title' => BxDolProfile::getInstance($iGroupProfileId)->getDisplayName()
  1190. );
  1191. bx_audit(
  1192. $iContentId,
  1193. $sModule,
  1194. $sAction,
  1195. $AuditParams
  1196. );
  1197. }
  1198. }
  1199. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  1200. {
  1201. $sResult = $this->checkAllowedView($aDataEntry);
  1202. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  1203. // if profile view isn't allowed but visibility is in partially visible groups
  1204. // then display buttons to connect (befriend, join) to profile,
  1205. // if other conditions (in parent::_checkAllowedConnect) are met as well
  1206. if (CHECK_ACTION_RESULT_ALLOWED !== $sResult && !in_array($aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']], array_merge($oPrivacy->getPartiallyVisiblePrivacyGroups(), array('s'))))
  1207. return $sResult;
  1208. return parent::_checkAllowedConnect ($aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap);
  1209. }
  1210. // ====== COMMON METHODS
  1211. protected function _alertParams($aContentInfo)
  1212. {
  1213. $aParams = parent::_alertParams($aContentInfo);
  1214. $CNF = &$this->_oConfig->CNF;
  1215. if(!empty($CNF['FIELD_CF']) && isset($aContentInfo[$CNF['FIELD_CF']]))
  1216. $aParams['cf'] = $aContentInfo[$CNF['FIELD_CF']];
  1217. return $aParams;
  1218. }
  1219. public function alertAfterAdd($aContentInfo)
  1220. {
  1221. $CNF = &$this->_oConfig->CNF;
  1222. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1223. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  1224. $sAction = 'added';
  1225. if(isset($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == BX_BASE_MOD_GENERAL_STATUS_PENDING)
  1226. $sAction = 'deferred';
  1227. $sModule = $this->getName();
  1228. $aParams = $this->_alertParams($aContentInfo);
  1229. bx_alert('system', 'prepare_alert_params', 0, 0, [
  1230. 'unit'=> $sModule,
  1231. 'action' => &$sAction,
  1232. 'object_id' => &$iId,
  1233. 'sender_id' => &$iAuthorId,
  1234. 'extras' => &$aParams
  1235. ]);
  1236. bx_alert($sModule, $sAction, $iId, false, $aParams);
  1237. $this->_processModerationNotifications($aContentInfo);
  1238. }
  1239. public function addFollower ($iProfileId1, $iProfileId2)
  1240. {
  1241. $oConnectionFollow = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  1242. if($oConnectionFollow && !$oConnectionFollow->isConnected($iProfileId1, $iProfileId2)){
  1243. $oConnectionFollow->addConnection($iProfileId1, $iProfileId2);
  1244. return true;
  1245. }
  1246. return false;
  1247. }
  1248. public function isFan ($iContentId, $iProfileId = false)
  1249. {
  1250. $CNF = &$this->_oConfig->CNF;
  1251. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  1252. if($oGroupProfile && isset($CNF['OBJECT_CONNECTIONS']))
  1253. return ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $oGroupProfile->id(), true);
  1254. return false;
  1255. }
  1256. public function isFanByGroupProfileId ($iGroupProfileId, $iProfileId = false)
  1257. {
  1258. $CNF = &$this->_oConfig->CNF;
  1259. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1260. if($oGroupProfile && isset($CNF['OBJECT_CONNECTIONS']))
  1261. return ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $oGroupProfile->id(), true);
  1262. return false;
  1263. }
  1264. public function isInvited ($sKey, $iGroupProfileId)
  1265. {
  1266. $CNF = &$this->_oConfig->CNF;
  1267. $aData = $this->_oDb->getInviteByKey($sKey, $iGroupProfileId);
  1268. if (!isset($aData['invited_profile_id']))
  1269. return _t($CNF['T']['txt_invitation_popup_error_invitation_absent']);
  1270. if ($aData['invited_profile_id'] != bx_get_logged_profile_id())
  1271. return _t($CNF['T']['txt_invitation_popup_error_wrong_user']);
  1272. return true;
  1273. }
  1274. public function isInvitedByProfileId ($iProfileId, $iGroupProfileId)
  1275. {
  1276. $CNF = &$this->_oConfig->CNF;
  1277. $aData = $this->_oDb->getInviteByInvited($iProfileId, $iGroupProfileId);
  1278. if (!isset($aData['invited_profile_id']))
  1279. return _t($CNF['T']['txt_invitation_popup_error_invitation_absent']);
  1280. if ($aData['invited_profile_id'] != bx_get_logged_profile_id())
  1281. return _t($CNF['T']['txt_invitation_popup_error_wrong_user']);
  1282. return true;
  1283. }
  1284. public function serviceIsInvited($iGroupProfileId, $iProfileId = false, $sKey = '')
  1285. {
  1286. if(!$iProfileId)
  1287. $iProfileId = bx_get_logged_profile_id();
  1288. if(empty($sKey) && ($sKey = bx_get('key')) !== false)
  1289. $sKey = bx_process_input($sKey);
  1290. $mixedInvited = false;
  1291. if(!empty($sKey))
  1292. $mixedInvited = $this->isInvited($sKey, $iGroupProfileId);
  1293. else if($iProfileId !== false)
  1294. $mixedInvited = $this->isInvitedByProfileId($iProfileId, $iGroupProfileId);
  1295. return $mixedInvited === true;
  1296. }
  1297. public function serviceIsNotInvited($iGroupProfileId, $iProfileId = false, $sKey = '')
  1298. {
  1299. return !$this->serviceIsInvited($iGroupProfileId, $iProfileId, $sKey);
  1300. }
  1301. public function serviceGetInvitedKey($iGroupProfileId, $iProfileId = false)
  1302. {
  1303. $sKey = '';
  1304. if(($sKey = bx_get('key')) !== false)
  1305. $sKey = bx_process_input($sKey);
  1306. if(!$sKey) {
  1307. if(!$iProfileId)
  1308. $iProfileId = bx_get_logged_profile_id();
  1309. if($iProfileId !== false) {
  1310. $aInvite = $this->_oDb->getInviteByInvited($iProfileId, $iGroupProfileId);
  1311. if(!empty($aInvite) && is_array($aInvite))
  1312. $sKey = $aInvite['key'];
  1313. }
  1314. }
  1315. return $sKey;
  1316. }
  1317. public function getRole($iGroupProfileId, $iFanProfileId)
  1318. {
  1319. if(!$this->isFanByGroupProfileId($iGroupProfileId, $iFanProfileId))
  1320. return false;
  1321. return $this->_oDb->getRole($iGroupProfileId, $iFanProfileId);
  1322. }
  1323. public function setRole($iGroupProfileId, $iFanProfileId, $mixedRole, $mixedPeriod = false, $sOrder = '')
  1324. {
  1325. $CNF = &$this->_oConfig->CNF;
  1326. if(!isset($CNF['OBJECT_CONNECTIONS']))
  1327. return false;
  1328. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  1329. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1330. if(!$oConnection || !$oGroupProfile)
  1331. return false;
  1332. if(!$oConnection->isConnected($iFanProfileId, $iGroupProfileId, true) && !($oConnection->addConnection($iFanProfileId, $iGroupProfileId) && $oConnection->addConnection($iGroupProfileId, $iFanProfileId)))
  1333. return false;
  1334. if(!$this->_oDb->setRole($iGroupProfileId, $iFanProfileId, $mixedRole, $mixedPeriod, $sOrder))
  1335. return false;
  1336. $this->onSetRole($iGroupProfileId, $iFanProfileId, $mixedRole);
  1337. return true;
  1338. }
  1339. public function onSetRole($iGroupProfileId, $iFanProfileId, $mixedRole)
  1340. {
  1341. $CNF = &$this->_oConfig->CNF;
  1342. $iProfileId = bx_get_logged_profile_id();
  1343. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1344. $aGroupProfileInfo = $this->_oDb->getContentInfoById((int)$oGroupProfile->getContentId());
  1345. $aRoles = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_ROLES']);
  1346. // notify about admin status
  1347. if(!empty($CNF['EMAIL_FAN_SET_ROLE']) && $iFanProfileId != $iProfileId) {
  1348. $aSetRoles = is_array($mixedRole) ? $mixedRole : [$mixedRole];
  1349. $aRolesNames = [];
  1350. foreach ($aSetRoles as $iRole)
  1351. $aRolesNames[] = $aRoles[(int)$iRole];
  1352. sendMailTemplate($CNF['EMAIL_FAN_SET_ROLE'], 0, $iFanProfileId, array(
  1353. 'EntryUrl' => $oGroupProfile->getUrl(),
  1354. 'EntryTitle' => $oGroupProfile->getDisplayName(),
  1355. 'Role' => implode(', ', $aRolesNames),
  1356. ), BX_EMAIL_NOTIFY);
  1357. }
  1358. bx_alert($this->getName(), 'set_role', $aGroupProfileInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  1359. 'object_author_id' => $iGroupProfileId,
  1360. 'performer_id' => $iProfileId,
  1361. 'fan_id' => $iFanProfileId,
  1362. 'content' => $aGroupProfileInfo,
  1363. 'role' => $mixedRole,
  1364. 'group_profile' => $iGroupProfileId,
  1365. 'profile' => $iProfileId
  1366. ));
  1367. $this->doAudit($iGroupProfileId, $iFanProfileId, '_sys_audit_action_group_role_changed');
  1368. }
  1369. public function unsetRole($iGroupProfileId, $iFanProfileId)
  1370. {
  1371. $CNF = &$this->_oConfig->CNF;
  1372. if(!isset($CNF['OBJECT_CONNECTIONS']))
  1373. return false;
  1374. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  1375. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1376. if(!$oConnection || !$oGroupProfile)
  1377. return false;
  1378. if($oConnection->isConnected($iFanProfileId, $iGroupProfileId, true) && !$oConnection->removeConnection($iFanProfileId, $iGroupProfileId))
  1379. return false;
  1380. $iRole = $this->_oDb->getRole($iGroupProfileId, $iFanProfileId);
  1381. if(!$this->_oDb->unsetRole($iGroupProfileId, $iFanProfileId))
  1382. return false;
  1383. $this->onUnsetRole($iGroupProfileId, $iFanProfileId, $iRole);
  1384. return true;
  1385. }
  1386. public function onUnsetRole($iGroupProfileId, $iFanProfileId, $iRole)
  1387. {
  1388. $CNF = &$this->_oConfig->CNF;
  1389. $iProfileId = bx_get_logged_profile_id();
  1390. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1391. $aGroupProfileInfo = $this->_oDb->getContentInfoById((int)$oGroupProfile->getContentId());
  1392. bx_alert($this->getName(), 'set_role', $aGroupProfileInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  1393. 'object_author_id' => $iGroupProfileId,
  1394. 'performer_id' => $iProfileId,
  1395. 'fan_id' => $iFanProfileId,
  1396. 'content' => $aGroupProfileInfo,
  1397. 'role' => $iRole,
  1398. 'group_profile' => $iGroupProfileId,
  1399. 'profile' => $iProfileId
  1400. ));
  1401. $this->doAudit($iGroupProfileId, $iFanProfileId, '_sys_audit_action_group_role_changed');
  1402. }
  1403. public function getGroupsByFan($iProfileId, $mixedRole = false)
  1404. {
  1405. $CNF = &$this->_oConfig->CNF;
  1406. if(!isset($CNF['OBJECT_CONNECTIONS']))
  1407. return false;
  1408. if($mixedRole === false)
  1409. $mixedRole = BX_BASE_MOD_GROUPS_ROLE_COMMON;
  1410. if(!is_array($mixedRole))
  1411. $mixedRole = [$mixedRole];
  1412. $aResult = [];
  1413. foreach($mixedRole as $iRole) {
  1414. switch($iRole) {
  1415. case BX_BASE_MOD_GROUPS_ROLE_COMMON:
  1416. $aIds = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])->getConnectedContent($iProfileId);
  1417. break;
  1418. default:
  1419. $aIds = $this->_oDb->getRoles([
  1420. 'type' => 'group_pids_by_fan_id',
  1421. 'fan_id' => $iProfileId,
  1422. 'role' => $iRole
  1423. ]);
  1424. }
  1425. $aResult = array_merge($aResult, $aIds);
  1426. }
  1427. return $aResult;
  1428. }
  1429. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1430. {
  1431. $CNF = &$this->_oConfig->CNF;
  1432. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aEvent['object_id'], $this->getName());
  1433. $sSrc = '';
  1434. if(isset($CNF['FIELD_COVER']) && !empty($aContentInfo[$CNF['FIELD_COVER']]))
  1435. $sSrc = $oGroupProfile->getCover();
  1436. if(empty($sSrc) && isset($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]))
  1437. $sSrc = $oGroupProfile->getPicture();
  1438. return empty($sSrc) ? array() : array(
  1439. array('id' => $aContentInfo[$CNF['FIELD_PICTURE']], 'url' => $sUrl, 'src' => $sSrc, 'src_orig' => $sSrc),
  1440. );
  1441. }
  1442. protected function _prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId)
  1443. {
  1444. if (!($oGroupProfile = BxDolProfile::getInstance($iGroupProfileId)))
  1445. return array(0, 0, null);
  1446. if ($oGroupProfile->getModule() == $this->getName()) {
  1447. $iProfileId = $iInitiatorId;
  1448. $iGroupProfileId = $oGroupProfile->id();
  1449. } else {
  1450. $iProfileId = $oGroupProfile->id();
  1451. $iGroupProfileId = $iInitiatorId;
  1452. }
  1453. return array($iProfileId, $iGroupProfileId, $oGroupProfile);
  1454. }
  1455. }
  1456. /** @} */