BxBaseModGroupsModule.php 64 KB

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