BxBaseModGroupsModule.php 70 KB

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