1
0

BxBaseModGroupsModule.php 66 KB

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