1
0

BxBaseModGroupsModule.php 61 KB

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