BxBaseModGroupsModule.php 62 KB

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