1
0

BxBaseModGroupsModule.php 101 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseGroups Base classes for groups modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_BASE_MOD_GROUPS_MMODE_MULTI_ROLES', 'multi_roles');
  12. define('BX_BASE_MOD_GROUPS_ROLE_COMMON', 0);
  13. define('BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR', 1);
  14. define('BX_BASE_MOD_GROUPS_ROLE_MODERATOR', 2);
  15. define('BX_BASE_MOD_GROUPS_ACTION_EDIT', 'edit');
  16. define('BX_BASE_MOD_GROUPS_ACTION_CHANGE_SETTINGS', 'change_settings');
  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_ACTION_TIMELINE_POST_PIN', 'pin'); //for timeline posts only
  25. define('BX_BASE_MOD_GROUPS_PERIOD_UNIT_DAY', 'day');
  26. define('BX_BASE_MOD_GROUPS_PERIOD_UNIT_WEEK', 'week');
  27. define('BX_BASE_MOD_GROUPS_PERIOD_UNIT_MONTH', 'month');
  28. define('BX_BASE_MOD_GROUPS_PERIOD_UNIT_YEAR', 'year');
  29. /**
  30. * Groups profiles module.
  31. */
  32. class BxBaseModGroupsModule extends BxBaseModProfileModule
  33. {
  34. function __construct(&$aModule)
  35. {
  36. parent::__construct($aModule);
  37. $CNF = &$this->_oConfig->CNF;
  38. if(isset($CNF['FIELD_PUBLISHED']))
  39. $this->_aSearchableNamesExcept = array_merge($this->_aSearchableNamesExcept, array(
  40. $CNF['FIELD_PUBLISHED'],
  41. ));
  42. }
  43. /**
  44. * Get possible recipients for start conversation form
  45. */
  46. public function actionAjaxGetInitialMembers ()
  47. {
  48. $sTerm = bx_get('term');
  49. $a = BxDolService::call('system', 'profiles_search', [$sTerm, ['module' => $this->_oConfig->getName()]], 'TemplServiceProfiles');
  50. header('Content-Type:text/javascript; charset=utf-8');
  51. echo(json_encode($a));
  52. }
  53. public function serviceGetInitialMembers ($sParams)
  54. {
  55. $aOptions = json_decode($sParams, true);
  56. if (!$sParams || !isset($aOptions['term']))
  57. return [];
  58. $a = BxDolService::call('system', 'profiles_search', [$aOptions['term'], ['module' => $this->_oConfig->getName()]], 'TemplServiceProfiles');
  59. return $a;
  60. }
  61. /**
  62. * Process Process Invitation
  63. */
  64. public function actionProcessInvite ($sKey, $iGroupProfileId, $bAccept)
  65. {
  66. $aData = $this->_oDb->getInviteByKey($sKey, $iGroupProfileId);
  67. if (isset($aData['invited_profile_id'])){
  68. $CNF = &$this->_oConfig->CNF;
  69. if (!isset($CNF['OBJECT_CONNECTIONS']) || !($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  70. return '';
  71. $iInvitedProfileId = $aData['invited_profile_id'];
  72. if ($iInvitedProfileId != bx_get_logged_profile_id())
  73. return '';
  74. if ($bAccept){
  75. if($oConnection && !$oConnection->isConnected($iInvitedProfileId, $iGroupProfileId)){
  76. $oConnection->addConnection($iInvitedProfileId, $iGroupProfileId);
  77. $oConnection->addConnection($iGroupProfileId, $iInvitedProfileId);
  78. }
  79. }
  80. $this->_oDb->deleteInviteByKey($sKey, $iGroupProfileId);
  81. }
  82. }
  83. public function actionCheckName()
  84. {
  85. $CNF = &$this->_oConfig->CNF;
  86. $sName = bx_process_input(bx_get('name'));
  87. if(empty($sName))
  88. return echoJson(array());
  89. $sResult = '';
  90. $iId = (int)bx_get('id');
  91. if(!empty($iId)) {
  92. $aPrice = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iId));
  93. if(strcmp($sName, $aPrice[$CNF['FIELD_PRICE_NAME']]) == 0)
  94. $sResult = $sName;
  95. }
  96. echoJson(array(
  97. 'name' => !empty($sResult) ? $sResult : $this->_oConfig->getPriceName($sName)
  98. ));
  99. }
  100. public function actionGetQuestionnaire()
  101. {
  102. $sSource = '';
  103. if(($sSource = bx_get('s')) !== false)
  104. $sSource = bx_process_url_param($sSource);
  105. $sObject = '';
  106. if(($sObject = bx_get('o')) !== false)
  107. $sObject = bx_process_url_param($sObject);
  108. $sAction = '';
  109. if(($sAction = bx_get('a')) !== false)
  110. $sAction = bx_process_url_param($sAction);
  111. $iContentProfileId = 0;
  112. if(($iContentProfileId = bx_get('cpi')) !== false)
  113. $iContentProfileId = (int)$iContentProfileId;
  114. echoJson($this->serviceGetQuestionnaire($sSource, $sObject, $sAction, $iContentProfileId));
  115. }
  116. public function serviceManageTools($sType = 'common')
  117. {
  118. $this->_oTemplate->addJs(['modules/base/groups/js/|manage_tools.js']);
  119. return parent::serviceManageTools($sType);
  120. }
  121. public function decodeDataAPI($aData, $aParams = [])
  122. {
  123. $CNF = $this->_oConfig->CNF;
  124. $aResult = parent::decodeDataAPI($aData, $aParams);
  125. if(isset($aParams['template']) && $aParams['template'] == 'unit_wo_info')
  126. return $aResult;
  127. if(getParam('sys_api_conn_in_prof_units') == 'on' && ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])) !== false) {
  128. $oProfile = BxDolProfile::getInstanceByContentAndType($aData[$CNF['FIELD_ID']], $this->_aModule['name']);
  129. $aResult['members_count'] = $oConnection->getConnectedInitiatorsCount($oProfile->id(), false);
  130. $aResult['members_list'] = $oConnection->getConnectedListAPI($oProfile->id(), false, BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  131. }
  132. return array_merge($aResult, [
  133. 'author_data' => BxDolProfile::getData($aData[$CNF['FIELD_AUTHOR']]),
  134. 'visibility' => $aData[$CNF['FIELD_ALLOW_VIEW_TO']]
  135. ]);
  136. }
  137. public function serviceGetMenuAddonManageTools()
  138. {
  139. $CNF = &$this->_oConfig->CNF;
  140. $aResult = parent::serviceGetMenuAddonManageTools();
  141. if(!empty($CNF['FIELD_STATUS_ADMIN']))
  142. $aResult['counter1_value'] = $this->_oDb->getEntriesNumByParams([[
  143. 'key' => $CNF['FIELD_STATUS_ADMIN'],
  144. 'value' => BX_BASE_MOD_GENERAL_STATUS_PENDING,
  145. 'operator' => '='
  146. ]]);
  147. return $aResult;
  148. }
  149. public function serviceGetOptionsMembersMode()
  150. {
  151. $CNF = &$this->_oConfig->CNF;
  152. return array(
  153. array('key' => '', 'value' => _t('_None')),
  154. array('key' => BX_BASE_MOD_GROUPS_MMODE_MULTI_ROLES, 'value' => _t($CNF['T']['option_members_mode_' . BX_BASE_MOD_GROUPS_MMODE_MULTI_ROLES])),
  155. );
  156. }
  157. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  158. {
  159. if(empty($sUnitTemplate))
  160. $sUnitTemplate = 'unit.html';
  161. return parent::serviceGetSearchResultUnit($iContentId, $sUnitTemplate);
  162. }
  163. /**
  164. * @see BxBaseModProfileModule::serviceGetSpaceTitle
  165. */
  166. public function serviceGetSpaceTitle()
  167. {
  168. return _t($this->_oConfig->CNF['T']['txt_sample_single']);
  169. }
  170. /**
  171. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  172. */
  173. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects = false)
  174. {
  175. if (isset($this->_oConfig->CNF['OBJECT_CONNECTIONS'])){
  176. $aConnectionObjects = array($this->_oConfig->CNF['OBJECT_CONNECTIONS'], 'sys_profiles_subscriptions');
  177. return parent::serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects);
  178. }
  179. return parent::serviceGetParticipatingProfiles($iProfileId);
  180. }
  181. public function serviceGetSafeServices()
  182. {
  183. return array_merge(parent::serviceGetSafeServices(), [
  184. 'GetQuestionnaire' => '',
  185. 'GetInitialMembers' => '',
  186. 'EntityInvite' => '',
  187. ]);
  188. }
  189. /**
  190. * Check if this module entry can be used as profile
  191. */
  192. public function serviceActAsProfile ()
  193. {
  194. return false;
  195. }
  196. /**
  197. * Check if this module is group profile
  198. */
  199. public function serviceIsGroupProfile ()
  200. {
  201. return true;
  202. }
  203. public function serviceIsEnableForContext($iProfileId = 0)
  204. {
  205. $CNF = &$this->_oConfig->CNF;
  206. $bRet = true;
  207. $sCnfKey = 'ENABLE_FOR_CONTEXT_IN_MODULES';
  208. if(empty($iProfileId) || empty($CNF[$sCnfKey]) || !is_array($CNF[$sCnfKey]))
  209. $bRet = false;
  210. if($bRet && !($oProfile = BxDolProfile::getInstance($iProfileId)))
  211. $bRet = false;
  212. if($bRet && !in_array($oProfile->getModule(), $CNF[$sCnfKey]))
  213. $bRet = false;
  214. bx_alert($this->getName(), 'is_enabled_for_context', $iProfileId, false, [
  215. 'cnf' => $CNF,
  216. 'module' => $this,
  217. 'context_profile' => $oProfile,
  218. 'result' => &$bRet
  219. ]);
  220. return $bRet;
  221. }
  222. /**
  223. * check if provided profile is member of the group
  224. */
  225. public function serviceIsFan ($iGroupProfileId, $iProfileId = false)
  226. {
  227. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  228. return $oGroupProfile !== false && $this->isFan($oGroupProfile->getContentId(), $iProfileId);
  229. }
  230. /**
  231. * check if provided profile is admin of the group
  232. */
  233. public function serviceIsAdmin ($iGroupProfileId, $iProfileId = false)
  234. {
  235. if(!$iProfileId)
  236. $iProfileId = bx_get_logged_profile_id();
  237. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  238. if(!$oGroupProfile)
  239. return false;
  240. $iGroupContentId = $oGroupProfile->getContentId();
  241. if(!$this->isFan($iGroupContentId, $iProfileId))
  242. return false;
  243. $aGroupContentInfo = $this->_oDb->getContentInfoById($iGroupContentId);
  244. return $this->_oDb->isAdmin($iGroupProfileId, $iProfileId, $aGroupContentInfo);
  245. }
  246. public function serviceGetAdminRole($iGroupProfileId, $iProfileId = false)
  247. {
  248. if(!$iProfileId)
  249. $iProfileId = bx_get_logged_profile_id();
  250. if(!$this->serviceIsAdmin($iGroupProfileId, $iProfileId))
  251. return 0;
  252. return $this->_oDb->getRole($iGroupProfileId, $iProfileId);
  253. }
  254. /*
  255. * Get context (group) advanced members who can perform the specified action.
  256. * If 'Roles' are disabled for the context then all context admins are returned.
  257. */
  258. public function serviceGetAdminsByAction($iGroupProfileId, $mixedAction)
  259. {
  260. if(!$this->_oConfig->isAdmins())
  261. return [];
  262. $aGroupContentInfo = $this->_oDb->getContentInfoByProfileId($iGroupProfileId);
  263. if(empty($aGroupContentInfo) || !is_array($aGroupContentInfo))
  264. return [];
  265. $aAdmins = $this->_oDb->getAdmins($iGroupProfileId);
  266. if(!$this->_oConfig->isRoles())
  267. return $aAdmins;
  268. if(!is_array($mixedAction))
  269. $mixedAction = [$mixedAction];
  270. $aResult = [];
  271. foreach($mixedAction as $sAction)
  272. foreach($aAdmins as $iAdminProfileId)
  273. if(!in_array($iAdminProfileId, $aResult) && $this->isAllowedActionByRole($sAction, $aGroupContentInfo, $iGroupProfileId, $iAdminProfileId))
  274. $aResult[] = $iAdminProfileId;
  275. return $aResult;
  276. }
  277. public function serviceGetAdminsToManageContent($iGroupProfileId)
  278. {
  279. return $this->serviceGetAdminsByAction($iGroupProfileId, [
  280. BX_BASE_MOD_GROUPS_ACTION_EDIT_CONTENT,
  281. BX_BASE_MOD_GROUPS_ACTION_DELETE_CONTENT
  282. ]);
  283. }
  284. /**
  285. * Delete profile from fans and admins tables
  286. * @param $iProfileId profile id
  287. */
  288. public function serviceDeleteProfileFromFansAndAdmins ($iProfileId)
  289. {
  290. $CNF = &$this->_oConfig->CNF;
  291. $this->_oDb->deleteAdminsByProfileId($iProfileId);
  292. if (isset($CNF['OBJECT_CONNECTIONS']) && ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  293. $oConnection->onDeleteInitiatorAndContent($iProfileId);
  294. }
  295. /**
  296. * Reset group's author for particular group
  297. * @param $iContentId group id
  298. * @parem $iAuthorId new author profile ID
  299. * @return false of error, or number of updated records on success
  300. */
  301. public function serviceReassignEntityAuthor ($iContentId, $iAuthorId = 0)
  302. {
  303. $aContentInfo = $this->_oDb->getContentInfoById((int)$iContentId);
  304. if (!$aContentInfo)
  305. return false;
  306. if (empty($iAuthorId)) {
  307. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  308. if (!$oGroupProfile)
  309. return false;
  310. $aAdmins = $this->_oDb->getAdmins($oGroupProfile->id());
  311. if($aAdmins)
  312. $iAuthorId = array_pop($aAdmins);
  313. }
  314. return $this->_oDb->updateAuthorById($iContentId, $iAuthorId);
  315. }
  316. /**
  317. * Entry actions and social sharing block
  318. */
  319. public function serviceEntityAllActions ($mixedContent = false, $aParams = array())
  320. {
  321. $CNF = &$this->_oConfig->CNF;
  322. if(!empty($mixedContent)) {
  323. if(!is_array($mixedContent))
  324. $mixedContent = array((int)$mixedContent, (method_exists($this->_oDb, 'getContentInfoById')) ? $this->_oDb->getContentInfoById((int)$mixedContent) : array());
  325. }
  326. else {
  327. $mixedContent = $this->_getContent();
  328. if($mixedContent === false)
  329. return false;
  330. }
  331. list($iContentId, $aContentInfo) = $mixedContent;
  332. if(!empty($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]))
  333. $aParams = array_merge(array(
  334. 'entry_thumb' => (int)$aContentInfo[$CNF['FIELD_PICTURE']]
  335. ), $aParams);
  336. return parent::serviceEntityAllActions ($mixedContent, $aParams);
  337. }
  338. /**
  339. * Reset group's author when author profile is deleted
  340. * @param $iProfileId author profile id
  341. * @param $iAuthorId new author profile id
  342. * @return number of changed items
  343. */
  344. public function serviceReassignEntitiesByAuthor ($iProfileId, $iAuthorId = 0)
  345. {
  346. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  347. if (!$a)
  348. return 0;
  349. $iCount = 0;
  350. foreach ($a as $aContentInfo)
  351. $iCount += ('' == $this->serviceReassignEntityAuthor($aContentInfo[$this->_oConfig->CNF['FIELD_ID']], $iAuthorId) ? 1 : 0);
  352. return $iCount;
  353. }
  354. public function servicePrepareFields ($aFieldsProfile)
  355. {
  356. $CNF = &$this->_oConfig->CNF;
  357. $aFieldsProfile[$CNF['FIELD_NAME']] = $aFieldsProfile['name'];
  358. $aFieldsProfile[$CNF['FIELD_TEXT']] = isset($aFieldsProfile['description']) ? $aFieldsProfile['description'] : '';
  359. unset($aFieldsProfile['name']);
  360. unset($aFieldsProfile['description']);
  361. return $aFieldsProfile;
  362. }
  363. public function serviceOnRemoveConnection ($iGroupProfileId, $iInitiatorId)
  364. {
  365. $CNF = &$this->_oConfig->CNF;
  366. list ($iProfileId, $iGroupProfileId, $oGroupProfile) = $this->_prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId);
  367. if (!$oGroupProfile)
  368. return false;
  369. $this->_oDb->fromAdmins($iGroupProfileId, $iProfileId);
  370. if ($oConn = BxDolConnection::getObjectInstance('sys_profiles_subscriptions'))
  371. return $oConn->removeConnection($iProfileId, $iGroupProfileId);
  372. return false;
  373. }
  374. public function serviceAddMutualConnection ($iGroupProfileId, $iInitiatorId, $bSendInviteOnly = false)
  375. {
  376. $CNF = &$this->_oConfig->CNF;
  377. list ($iProfileId, $iGroupProfileId, $oGroupProfile) = $this->_prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId);
  378. if (!$oGroupProfile)
  379. return false;
  380. if (!($aContentInfo = $this->_oDb->getContentInfoById((int)BxDolProfile::getInstance($iGroupProfileId)->getContentId())))
  381. return false;
  382. if (!isset($CNF['OBJECT_CONNECTIONS']) || !($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  383. return false;
  384. $sEntryTitle = $aContentInfo[$CNF['FIELD_NAME']];
  385. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]));
  386. // send invitation to the group
  387. $sModule = $this->getName();
  388. if ($bSendInviteOnly && !$oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id()) && !$oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId) && bx_get_logged_profile_id() != $iProfileId) {
  389. /**
  390. * @hooks
  391. * @hookdef hook-bx_base_groups-join_invitation '{module_name}', 'join_invitation' - hook before adding (sending) new join to context invitation
  392. * - $unit_name - module name
  393. * - $action - equals `join_invitation`
  394. * - $object_id - context id
  395. * - $sender_id - context profile id
  396. * - $extra_params - array of additional params with the following array keys:
  397. * - `content` - [array] context info array as key&value pairs
  398. * - `entry_title` - [string] context title
  399. * - `entry_url` - [string] context URL
  400. * - `group_profile` - [int] context profile id
  401. * - `profile` - [int] profile id who was invited
  402. * - `notification_subobject_id` - [int] profile id who was invited
  403. * - `object_author_id` - [int] context profile id
  404. * @hook @ref hook-bx_base_groups-join_invitation
  405. */
  406. bx_alert($sModule, 'join_invitation', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, [
  407. 'content' => $aContentInfo,
  408. 'entry_title' => $sEntryTitle,
  409. 'entry_url' => $sEntryUrl,
  410. 'group_profile' => $iGroupProfileId,
  411. 'profile' => $iProfileId,
  412. 'notification_subobject_id' => $iProfileId,
  413. 'object_author_id' => $iGroupProfileId
  414. ]);
  415. /**
  416. * 'Invitation Received' alert for Notifications module.
  417. * Note. It's essential to use Recipient ($iInitiatorId) in 'object_author_id' parameter.
  418. * In this case notification will be received by Recipient profile.
  419. */
  420. /**
  421. * @hooks
  422. * @hookdef hook-bx_base_groups-join_invitation_notif '{module_name}', 'join_invitation_notif' - hook before adding new join to context invitation. Is needed for Notifications module.
  423. * - $unit_name - module name
  424. * - $action - equals `join_invitation_notif`
  425. * - $object_id - context id
  426. * - $sender_id - context profile id
  427. * - $extra_params - array of additional params with the following array keys:
  428. * - `object_author_id` - [int] profile id who was invited
  429. * - `privacy_view` - [int] or [string] privacy for view context action, @see BxDolPrivacy
  430. * @hook @ref hook-bx_base_groups-join_invitation_notif
  431. */
  432. bx_alert($sModule, 'join_invitation_notif', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, [
  433. 'object_author_id' => $iInitiatorId,
  434. 'privacy_view' => isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) ? $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] : 3,
  435. ]);
  436. }
  437. // send notification to group's admins that new connection is pending confirmation
  438. elseif (!$bSendInviteOnly && $oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id()) && !$oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId) && $aContentInfo['join_confirmation']) {
  439. /**
  440. * @hooks
  441. * @hookdef hook-bx_base_groups-join_request '{module_name}', 'join_request' - hook before adding new join to context request
  442. * - $unit_name - module name
  443. * - $action - equals `join_request`
  444. * - $object_id - context id
  445. * - $sender_id - context profile id
  446. * - $extra_params - array of additional params with the following array keys:
  447. * - `object_author_id` - [int] context profile id
  448. * - `performer_id` - [int] profile id who wants to join
  449. * - `content` - [array] context info array as key&value pairs
  450. * - `entry_title` - [string] context title
  451. * - `entry_url` - [string] context URL
  452. * - `group_profile` - [int] context profile id
  453. * - `profile` - [int] profile id who wants to join
  454. * @hook @ref hook-bx_base_groups-join_request
  455. */
  456. bx_alert($this->getName(), 'join_request', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, [
  457. 'object_author_id' => $iGroupProfileId,
  458. 'performer_id' => $iProfileId,
  459. 'content' => $aContentInfo,
  460. 'entry_title' => $sEntryTitle,
  461. 'entry_url' => $sEntryUrl,
  462. 'group_profile' => $iGroupProfileId,
  463. 'profile' => $iProfileId
  464. ]);
  465. }
  466. // send notification that join request was accepted
  467. else if (!$bSendInviteOnly && $oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id(), true) && $oGroupProfile->getModule() != $this->getName() && bx_get_logged_profile_id() != $iProfileId) {
  468. /**
  469. * @hooks
  470. * @hookdef hook-bx_base_groups-join_request_accepted '{module_name}', 'join_request_accepted' - hook before accepting join to context request
  471. * It's equivalent to @ref hook-bx_base_groups-join_request
  472. * @hook @ref hook-bx_base_groups-join_request_accepted
  473. */
  474. bx_alert($this->getName(), 'join_request_accepted', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, [
  475. 'object_author_id' => $iGroupProfileId,
  476. 'performer_id' => $iProfileId,
  477. 'content' => $aContentInfo,
  478. 'entry_title' => $sEntryTitle,
  479. 'entry_url' => $sEntryUrl,
  480. 'group_profile' => $iGroupProfileId,
  481. 'profile' => $iProfileId
  482. ]);
  483. }
  484. // new fan was added
  485. if ($oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId, true)) {
  486. // follow group on join
  487. if (BxDolService::call($oGroupProfile->getModule(), 'act_as_profile')){
  488. $this->addFollower($oGroupProfile->id(), (int)$iInitiatorId);
  489. }
  490. else{
  491. $this->addFollower((int)$iInitiatorId, $oGroupProfile->id());
  492. }
  493. /**
  494. * @hooks
  495. * @hookdef hook-bx_base_groups-fan_added '{module_name}', 'fan_added' - hook before adding (registering) new context member
  496. * It's equivalent to @ref hook-bx_base_groups-join_request
  497. * @hook @ref hook-bx_base_groups-fan_added
  498. */
  499. bx_alert($this->getName(), 'fan_added', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, [
  500. 'object_author_id' => $iGroupProfileId,
  501. 'performer_id' => $iProfileId,
  502. 'content' => $aContentInfo,
  503. 'entry_title' => $sEntryTitle,
  504. 'entry_url' => $sEntryUrl,
  505. 'group_profile' => $iGroupProfileId,
  506. 'profile' => $iProfileId,
  507. ]);
  508. $this->doAudit($iGroupProfileId, $iInitiatorId, '_sys_audit_action_group_join_request_accepted');
  509. return false;
  510. }
  511. // don't automatically add connection (mutual) if group requires manual join confirmation
  512. if ($bSendInviteOnly || $aContentInfo['join_confirmation'])
  513. return false;
  514. // check if connection already exists
  515. if ($oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId, true) || $oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId))
  516. return false;
  517. if (!$oConnection->addConnection($oGroupProfile->id(), (int)$iInitiatorId))
  518. return false;
  519. return true;
  520. }
  521. public function serviceFansTable ()
  522. {
  523. $CNF = &$this->_oConfig->CNF;
  524. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_CONNECTIONS']);
  525. if(!$oGrid)
  526. return false;
  527. if($this->_bIsApi){
  528. return [
  529. bx_api_get_block('grid', $oGrid->getCodeAPI())
  530. ];
  531. }
  532. return $oGrid->getCode();
  533. }
  534. public function serviceInvitesTable ()
  535. {
  536. $CNF = &$this->_oConfig->CNF;
  537. if(!isset($CNF['OBJECT_GRID_INVITES']))
  538. return false;
  539. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_INVITES']);
  540. if(!$oGrid)
  541. return false;
  542. if($this->_bIsApi)
  543. return [
  544. bx_api_get_block('grid', $oGrid->getCodeAPI())
  545. ];
  546. return $oGrid->getCode();
  547. }
  548. public function serviceBansTable ()
  549. {
  550. $CNF = &$this->_oConfig->CNF;
  551. if(!isset($CNF['OBJECT_GRID_BANS']))
  552. return false;
  553. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_BANS']);
  554. if(!$oGrid)
  555. return false;
  556. if($this->_bIsApi)
  557. return [
  558. bx_api_get_block('grid', $oGrid->getCodeAPI())
  559. ];
  560. return $oGrid->getCode();
  561. }
  562. public function serviceFans ($iContentId = 0, $bAsArray = false)
  563. {
  564. $CNF = &$this->_oConfig->CNF;
  565. if (!$iContentId)
  566. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  567. if (!$iContentId)
  568. return false;
  569. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  570. if (!$aContentInfo)
  571. return false;
  572. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
  573. return false;
  574. if(!$bAsArray) {
  575. bx_import('BxDolConnection');
  576. $mixedResult = $this->serviceBrowseConnectionsQuick ($oGroupProfile->id(), $CNF['OBJECT_CONNECTIONS'], BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  577. if (!$mixedResult)
  578. return MsgBox(_t('_sys_txt_empty'));
  579. }
  580. else
  581. $mixedResult = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])->getConnectedContent($oGroupProfile->id(), true);
  582. return $mixedResult;
  583. }
  584. public function serviceFansWithoutAdmins ($iContentId = 0, $bAsArray = false)
  585. {
  586. if (!$iContentId)
  587. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  588. if (!$iContentId)
  589. return false;
  590. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  591. if (!$aContentInfo)
  592. return false;
  593. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
  594. return false;
  595. $CNF = &$this->_oConfig->CNF;
  596. $aFans = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])->getConnectedContent($oGroupProfile->id(), true);
  597. if(empty($aFans) || !is_array($aFans))
  598. return false;
  599. $aAdmins = $this->_oDb->getAdmins($oGroupProfile->id());
  600. if(!empty($aAdmins) && is_array($aAdmins))
  601. $aFans = array_diff($aFans, $aAdmins);
  602. $iStart = (int)bx_get('start');
  603. $iLimit = !empty($CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($CNF['PARAM_NUM_CONNECTIONS_QUICK']) : 4;
  604. if(!$iLimit)
  605. $iLimit = 4;
  606. return $this->_serviceBrowseQuick($aFans, $iStart, $iLimit);
  607. }
  608. public function serviceAdmins ($iContentId = 0)
  609. {
  610. $CNF = &$this->_oConfig->CNF;
  611. if(!$iContentId)
  612. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  613. if(!$iContentId)
  614. return false;
  615. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  616. if(!$oGroupProfile)
  617. return false;
  618. $iStart = (int)bx_get('start');
  619. $iLimit = !empty($CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($CNF['PARAM_NUM_CONNECTIONS_QUICK']) : 4;
  620. if(!$iLimit)
  621. $iLimit = 4;
  622. $aProfiles = $this->_oDb->getAdmins($oGroupProfile->id(), $iStart, $iLimit+1);
  623. if(empty($aProfiles) || !is_array($aProfiles))
  624. return false;
  625. return $this->_serviceBrowseQuick($aProfiles, $iStart, $iLimit);
  626. }
  627. public function serviceMembersByRole ($iContentId = 0, $iRole = BX_BASE_MOD_GROUPS_ROLE_COMMON)
  628. {
  629. $CNF = &$this->_oConfig->CNF;
  630. if(!$iContentId)
  631. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  632. if(!$iContentId)
  633. return false;
  634. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  635. if(!$oGroupProfile)
  636. return false;
  637. $iStart = (int)bx_get('start');
  638. $iLimit = !empty($CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($CNF['PARAM_NUM_CONNECTIONS_QUICK']) : 4;
  639. if(!$iLimit)
  640. $iLimit = 4;
  641. $aProfiles = $this->_oDb->getRoles([
  642. 'type' => 'fan_pids_by_group_pid',
  643. 'group_profile_id' => $oGroupProfile->id(),
  644. 'role' => $iRole,
  645. 'start' => $iStart,
  646. 'limit' => $iLimit + 1
  647. ]);
  648. if(empty($aProfiles) || !is_array($aProfiles))
  649. return false;
  650. return $this->_serviceBrowseQuick($aProfiles, $iStart, $iLimit);
  651. }
  652. public function serviceBrowseJoinedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  653. {
  654. if (!$iProfileId)
  655. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  656. if (!$iProfileId)
  657. return '';
  658. return $this->_serviceBrowse ('joined_entries', array('joined_profile' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  659. }
  660. public function serviceBrowseFollowedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  661. {
  662. if (!$iProfileId)
  663. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  664. if (!$iProfileId)
  665. return '';
  666. return $this->_serviceBrowse ('followed_entries', array('followed_profile' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  667. }
  668. public function serviceBrowseCreatedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  669. {
  670. if (!$iProfileId)
  671. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  672. if (!$iProfileId)
  673. return '';
  674. return $this->_serviceBrowse ('created_entries', array('author' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  675. }
  676. public function serviceBrowseRecommendationsFans ($iProfileId = 0, $aParams = [])
  677. {
  678. $CNF = &$this->_oConfig->CNF;
  679. if($this->_bIsApi)
  680. $aParams = bx_api_get_browse_params($aParams, true);
  681. if(!$iProfileId)
  682. $iProfileId = bx_get_logged_profile_id();
  683. if(!$iProfileId)
  684. return '';
  685. $aParams = array_merge([
  686. 'empty_message' => false,
  687. 'start' => 0,
  688. 'per_page' => 0
  689. ], $aParams);
  690. if(($iStartGet = bx_get('start')) !== false)
  691. $aParams['start'] = (int)$iStartGet;
  692. if(($iPerPageGet = bx_get('per_page')) !== false)
  693. $aParams['per_page'] = (int)$iPerPageGet;
  694. $oRecommendation = BxDolRecommendation::getObjectInstance($CNF['OBJECT_RECOMMENDATIONS_FANS']);
  695. if(!$oRecommendation)
  696. return false;
  697. if($this->_bIsApi) {
  698. $aData = $oRecommendation->getCodeAPI($iProfileId, $aParams);
  699. $aData = array_merge($aData, [
  700. 'module' => 'system',
  701. 'unit' => 'mixed',
  702. 'request_url' => '/api.php?r=bx_groups/browse_recommendations_fans&params[]=' . $iProfileId . '&params[]='
  703. ]);
  704. return [bx_api_get_block('browse', $aData)];
  705. }
  706. $sCode = $oRecommendation->getCode($iProfileId, $aParams);
  707. if(!$sCode && $aParams['empty_message'])
  708. $sCode = MsgBox(_t(!empty($aParams['empty_message_text']) ? $aParams['empty_message_text'] : '_Empty'));
  709. return $sCode;
  710. }
  711. public function serviceBrowseMembers ($iProfileId = 0, $aParams = [])
  712. {
  713. $CNF = &$this->_oConfig->CNF;
  714. if(!$iProfileId)
  715. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  716. if(!$iProfileId)
  717. return '';
  718. $oGroupProfile = BxDolProfile::getInstance($iProfileId);
  719. if(!($oGroupProfile))
  720. return '';
  721. return bx_srv('system', 'browse_members', [$oGroupProfile->id(), $CNF['OBJECT_CONNECTIONS'], $aParams], 'TemplServiceProfiles');
  722. }
  723. public function serviceEntityEditQuestionnaire($iProfileId = 0)
  724. {
  725. $CNF = &$this->_oConfig->CNF;
  726. if(!$iProfileId)
  727. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  728. if(!$iProfileId)
  729. return '';
  730. $aProfileInfo = BxDolProfileQuery::getInstance()->getInfoById($iProfileId);
  731. if(empty($aProfileInfo) || !is_array($aProfileInfo))
  732. return '';
  733. $aContentInfo = $this->_oDb->getContentInfoById($aProfileInfo['content_id']);
  734. if(empty($aContentInfo) || !is_array($aContentInfo))
  735. return '';
  736. if($this->checkAllowedEdit($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
  737. return MsgBox(_t('_Access denied'));
  738. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_QUESTIONS_MANAGE']);
  739. if(!$oGrid)
  740. return '';
  741. if($this->_bIsApi){
  742. return [
  743. bx_api_get_block('grid', $oGrid->getCodeAPI())
  744. ];
  745. }
  746. return $oGrid->getCode();
  747. }
  748. public function serviceEntityPricing($iProfileId = 0)
  749. {
  750. $CNF = &$this->_oConfig->CNF;
  751. if(!$iProfileId)
  752. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  753. if(!$iProfileId)
  754. return '';
  755. if(!$this->_oConfig->isPaidJoin())
  756. return '';
  757. $oPayments = BxDolPayments::getInstance();
  758. if(!$oPayments->isActive())
  759. return MsgBox(_t('_sys_payments_err_no_payments'));
  760. if($this->checkAllowedUsePaidJoin() !== CHECK_ACTION_RESULT_ALLOWED)
  761. return MsgBox(_t('_Access denied'));
  762. if($this->checkAllowedManageAdmins($iProfileId) !== CHECK_ACTION_RESULT_ALLOWED)
  763. return MsgBox(_t('_Access denied'));
  764. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_PRICES_MANAGE']);
  765. if(!$oGrid)
  766. return '';
  767. $sNote = '';
  768. if(!$oPayments->isAcceptingPayments($this->_iProfileId))
  769. $sNote = MsgBox(_t('_sys_payments_err_not_accept_payments', $oPayments->getDetailsUrl()));
  770. return $sNote . $oGrid->getCode();
  771. }
  772. public function serviceEntityJoin($iProfileId = 0)
  773. {
  774. $CNF = &$this->_oConfig->CNF;
  775. if(!$iProfileId)
  776. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  777. if(!$iProfileId)
  778. return '';
  779. if(!$this->_oConfig->isPaidJoin())
  780. return '';
  781. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_PRICES_VIEW']);
  782. if(!$oGrid)
  783. return '';
  784. return $oGrid->getCode();
  785. }
  786. public function serviceEntityInvite ($iContentId = 0, $bErrorMsg = true)
  787. {
  788. $CNF = &$this->_oConfig->CNF;
  789. if(!isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_INVITE']))
  790. return false;
  791. return $this->_serviceEntityForm ('inviteForm', $iContentId, false, false, $bErrorMsg);
  792. }
  793. /**
  794. * Entry social sharing block
  795. */
  796. public function serviceEntitySocialSharing ($mixedContent = false, $aParams = array())
  797. {
  798. if(!empty($mixedContent)) {
  799. if(!is_array($mixedContent))
  800. $mixedContent = array((int)$mixedContent, array());
  801. }
  802. else {
  803. $mixedContent = $this->_getContent();
  804. if($mixedContent === false)
  805. return false;
  806. }
  807. list($iContentId, $aContentInfo) = $mixedContent;
  808. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  809. if(!$oGroupProfile)
  810. return false;
  811. return parent::serviceEntitySocialSharing(array($iContentId, $aContentInfo), array(
  812. 'title' => $oGroupProfile->getDisplayName()
  813. ));
  814. }
  815. public function serviceIsPricingAvaliable($iProfileId)
  816. {
  817. if(!$this->_oConfig->isPaidJoin())
  818. return false;
  819. if($this->checkAllowedUsePaidJoin() !== CHECK_ACTION_RESULT_ALLOWED)
  820. return false;
  821. if($this->checkAllowedManageAdmins($iProfileId) !== CHECK_ACTION_RESULT_ALLOWED)
  822. return false;
  823. return true;
  824. }
  825. public function serviceIsPaidJoinAvaliable($iGroupProfileId, $iProfileId = 0)
  826. {
  827. return $this->isPaidJoinByProfileForProfile($iGroupProfileId, $iProfileId);
  828. }
  829. public function serviceIsPaidJoinAvaliableByContent($iGroupContentId, $iProfileId = 0)
  830. {
  831. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iGroupContentId, $this->getName());
  832. if(!$oGroupProfile)
  833. return false;
  834. return $this->isPaidJoinByProfileForProfile($oGroupProfile->id(), $iProfileId);
  835. }
  836. public function serviceIsFreeJoinAvaliable($iGroupProfileId, $iProfileId = 0)
  837. {
  838. return !$this->isPaidJoinByProfileForProfile($iGroupProfileId, $iProfileId);
  839. }
  840. public function serviceIsFreeJoinAvaliableByContent($iGroupContentId, $iProfileId = 0)
  841. {
  842. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iGroupContentId, $this->getName());
  843. if(!$oGroupProfile)
  844. return false;
  845. return !$this->isPaidJoinByProfileForProfile($oGroupProfile->id(), $iProfileId);
  846. }
  847. /**
  848. * Is Paid Join enabled in the group and whether a profile can use it.
  849. *
  850. * @param type $iGroupProfileId - Group profile ID.
  851. * @param type $iProfileId - Profile ID of the user who wants to join.
  852. * @return boolean
  853. */
  854. public function isPaidJoinByProfileForProfile($iGroupProfileId, $iProfileId = 0)
  855. {
  856. $CNF = &$this->_oConfig->CNF;
  857. if(empty($iProfileId))
  858. $iProfileId = $this->_iProfileId;
  859. if(BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])->isConnected($iProfileId, $iGroupProfileId))
  860. return false;
  861. return $this->isPaidJoinByProfile($iGroupProfileId);
  862. }
  863. /**
  864. * Is Paid Join enabled as is and whether a group has pricing plans added.
  865. *
  866. * @param type $iGroupProfileId - Group profile ID.
  867. * @return boolean
  868. */
  869. public function isPaidJoinByProfile($iGroupProfileId)
  870. {
  871. if(!$this->_oConfig->isPaidJoin())
  872. return false;
  873. $aPrices = $this->_oDb->getPrices(array('type' => 'by_profile_id', 'profile_id' => $iGroupProfileId));
  874. if(empty($aPrices) || !is_array($aPrices))
  875. return false;
  876. return true;
  877. }
  878. /**
  879. * Integration with Payments.
  880. */
  881. public function serviceGetPaymentData()
  882. {
  883. return $this->_aModule;
  884. }
  885. public function serviceGetCartItem($mixedItemId)
  886. {
  887. $CNF = &$this->_oConfig->CNF;
  888. if(!$mixedItemId)
  889. return array();
  890. if(is_numeric($mixedItemId))
  891. $aItem = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => (int)$mixedItemId));
  892. else
  893. $aItem = $this->_oDb->getPrices(array('type' => 'by_name', 'value' => $mixedItemId));
  894. if(empty($aItem) || !is_array($aItem))
  895. return array();
  896. if(!$this->isPaidJoinByProfile($aItem['profile_id']))
  897. return array();
  898. $oGroupProfile = BxDolProfile::getInstance($aItem['profile_id']);
  899. if(!$oGroupProfile)
  900. return array();
  901. $aGroupProfile = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  902. $aRoles = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_ROLES']);
  903. $sTitle = '';
  904. if(!empty($aItem['period']) && !empty($aItem['period_unit']))
  905. $sTitle = _t($CNF['T']['txt_cart_item_title'], $oGroupProfile->getDisplayName(), $aRoles[$aItem['role_id']], $aItem['period'], $aItem['period_unit']);
  906. else
  907. $sTitle = _t($CNF['T']['txt_cart_item_title_lifetime'], $oGroupProfile->getDisplayName(), $aRoles[$aItem['role_id']]);
  908. return array (
  909. 'id' => $aItem['id'],
  910. 'author_id' => $aGroupProfile[$CNF['FIELD_AUTHOR']],
  911. 'name' => $aItem['name'],
  912. 'title' => $sTitle,
  913. 'description' => '',
  914. 'url' => $oGroupProfile->getUrl(),
  915. 'price_single' => $aItem['price'],
  916. 'price_recurring' => $aItem['price'],
  917. 'period_recurring' => $aItem['period'],
  918. 'period_unit_recurring' => $aItem['period_unit'],
  919. 'trial_recurring' => 0
  920. );
  921. }
  922. public function serviceGetCartItems($iSellerId)
  923. {
  924. $CNF = &$this->_oConfig->CNF;
  925. if(empty($iSellerId))
  926. return array();
  927. $sModule = $this->getName();
  928. $aRoles = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_ROLES']);
  929. $aGroups = $this->_oDb->getEntriesBy(array('type' => 'author', 'author' => $iSellerId));
  930. $aResult = array();
  931. foreach($aGroups as $aGroup) {
  932. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aGroup[$CNF['FIELD_ID']], $sModule);
  933. if(!$oGroupProfile)
  934. continue;
  935. $aPrices = $this->_oDb->getPrices(array('type' => 'by_profile_id', 'profile_id' => $oGroupProfile->id()));
  936. if(empty($aPrices) || !is_array($aPrices))
  937. continue;
  938. $sTitle = $oGroupProfile->getDisplayName();
  939. $sUrl = $oGroupProfile->getUrl();
  940. foreach($aPrices as $aPrice)
  941. $aResult[] = array(
  942. 'id' => $aPrice['id'],
  943. 'author_id' => $iSellerId,
  944. 'name' => $aPrice['name'],
  945. 'title' => _t($CNF['T']['txt_cart_item_title'], $sTitle, $aRoles[$aPrice['role_id']], $aPrice['period'], $aPrice['period_unit']),
  946. 'description' => '',
  947. 'url' => $sUrl,
  948. 'price_single' => $aPrice['price'],
  949. 'price_recurring' => $aPrice['price'],
  950. 'period_recurring' => $aPrice['period'],
  951. 'period_unit_recurring' => $aPrice['period_unit']
  952. );
  953. }
  954. return $aResult;
  955. }
  956. public function serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  957. {
  958. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  959. }
  960. public function serviceRegisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  961. {
  962. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  963. }
  964. public function serviceReregisterCartItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  965. {
  966. return $this->_serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder);
  967. }
  968. public function serviceReregisterSubscriptionItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  969. {
  970. return $this->_serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder);
  971. }
  972. public function serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  973. {
  974. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  975. }
  976. public function serviceUnregisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  977. {
  978. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  979. }
  980. public function serviceCancelSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  981. {
  982. return true;
  983. }
  984. protected function _serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  985. {
  986. $CNF = &$this->_oConfig->CNF;
  987. $aItem = $this->serviceGetCartItem($iItemId);
  988. if(empty($aItem) || !is_array($aItem))
  989. return array();
  990. $aItemInfo = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemId));
  991. $mixedPeriod = false;
  992. if((int)$aItemInfo['period'] != 0)
  993. $mixedPeriod = array(
  994. 'period' => (int)$aItemInfo['period'],
  995. 'period_unit' => $aItemInfo['period_unit'],
  996. 'period_reserve' => $CNF['PARAM_RECURRING_RESERVE']
  997. );
  998. if(!$this->setRole($aItemInfo['profile_id'], $iClientId, $aItemInfo['role_id'], $mixedPeriod, $sOrder))
  999. return array();
  1000. return $aItem;
  1001. }
  1002. protected function _serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  1003. {
  1004. $aItem = $this->serviceGetCartItem($iItemIdNew);
  1005. if(empty($aItem) || !is_array($aItem))
  1006. return array();
  1007. $aItemInfoOld = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemIdOld));
  1008. if(empty($aItemInfoOld) || !is_array($aItemInfoOld))
  1009. return array();
  1010. $aItemInfoNew = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemIdNew));
  1011. if(empty($aItemInfoNew) || !is_array($aItemInfoNew))
  1012. return array();
  1013. if(!$this->unsetRole($aItemInfoOld['profile_id'], $iClientId))
  1014. return array();
  1015. $aResult = $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemIdNew, 1, $sOrder);
  1016. if(empty($aResult) || !is_array($aResult))
  1017. return array();
  1018. return $aItem;
  1019. }
  1020. protected function _serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  1021. {
  1022. $aItemInfo = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemId));
  1023. if(empty($aItemInfo) || !is_array($aItemInfo))
  1024. return false;
  1025. return $this->unsetRole($aItemInfo['profile_id'], $iClientId);
  1026. }
  1027. public function serviceGetQuestionnaire($sSource, $sObject, $sAction, $iContentProfileId)
  1028. {
  1029. $CNF = &$this->_oConfig->CNF;
  1030. $sMsg = _t('_sys_txt_not_found');
  1031. $aContentInfo = $this->_oDb->getContentInfoByProfileId($iContentProfileId);
  1032. if(empty($aContentInfo) || !is_array($aContentInfo))
  1033. return $this->_bIsApi ? [bx_api_get_msg($sMsg)] : ['code' => 1, 'msg' => $sMsg];
  1034. $oForm = null;
  1035. if(($oConnection = BxDolConnection::getObjectInstance($sObject)) !== false) {
  1036. $oForm = $oConnection->getQuestionnaireForm($sAction, $iContentProfileId, ['request' => [
  1037. 's' => $sSource,
  1038. ]]);
  1039. if($oForm === false)
  1040. return $this->_bIsApi ? [bx_api_get_msg($sMsg)] : ['code' => 3, 'msg' => $sMsg];
  1041. }
  1042. else
  1043. return $this->_bIsApi ? [bx_api_get_msg($sMsg)] : ['code' => 2, 'msg' => $sMsg];
  1044. $oForm->initChecker();
  1045. if($oForm->isSubmittedAndValid()) {
  1046. $iProfileId = bx_get_logged_profile_id();
  1047. $aQuestions = $this->_oDb->getQuestions(['sample' => 'content_pid', 'content_pid' => $iContentProfileId]);
  1048. foreach($aQuestions as $aQuestion)
  1049. $this->_oDb->insertAnswer((int)$aQuestion['id'], $iProfileId, $oForm->getCleanValue('question_' . $aQuestion['id']));
  1050. return $this->_bIsApi ? [] : ['code' => 0, 'o' => $sObject, 'a' => $sAction, 'cpi' => $iContentProfileId, 'ci' => $aContentInfo[$CNF['FIELD_ID']], 'eval' => $this->_oConfig->getJsObject($sSource) . '.connActionPerformed(oData)'];
  1051. }
  1052. if($this->_bIsApi)
  1053. return [bx_api_get_block('form', $oForm->getCodeAPI(), ['ext' => [
  1054. 'name' => $this->_oModule->getName(),
  1055. 'request' => ['url' => $oForm->aFormAttrs['action'], 'immutable' => true]]
  1056. ])];
  1057. bx_import('BxTemplFunctions');
  1058. $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oConfig->getHtmlIds('popup_questionnaire'), _t($CNF['T']['popup_title_questionnaire']), $this->_oTemplate->parseHtmlByName('popup_qnr_questionnaire.html', [
  1059. 'form_id' => $oForm->getId(),
  1060. 'form' => $oForm->getCode(true),
  1061. ]));
  1062. return ['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => false]]];
  1063. }
  1064. /**
  1065. * Data for Notifications module
  1066. */
  1067. public function serviceGetNotificationsData()
  1068. {
  1069. $sModule = $this->_aModule['name'];
  1070. $aSettingsTypes = ['follow_member', 'follow_context'];
  1071. if($this->serviceActAsProfile())
  1072. $aSettingsTypes = ['personal', 'follow_member'];
  1073. return [
  1074. 'handlers' => [
  1075. ['group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'],
  1076. ['group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'],
  1077. ['group' => $sModule . '_score_up', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteUp', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_up', 'module_class' => 'Module'],
  1078. ['group' => $sModule . '_score_down', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteDown', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_down', 'module_class' => 'Module'],
  1079. ['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'],
  1080. ['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'],
  1081. ['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']],
  1082. ['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'],
  1083. //--- Moderation related: For 'admins'.
  1084. ['group' => $sModule . '_object_pending_approval', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'pending_approval', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_pending_approval', 'module_class' => 'Module'],
  1085. ],
  1086. 'settings' => [
  1087. ['group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => $aSettingsTypes],
  1088. ['group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => $aSettingsTypes],
  1089. ['group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => $aSettingsTypes],
  1090. ['group' => 'fan', 'unit' => $sModule, 'action' => 'fan_added', 'types' => $aSettingsTypes],
  1091. ['group' => 'invite', 'unit' => $sModule, 'action' => 'join_invitation_notif', 'types' => ['personal']],
  1092. ['group' => 'join', 'unit' => $sModule, 'action' => 'join_request', 'types' => $aSettingsTypes],
  1093. ['group' => 'timeline_post', 'unit' => $sModule, 'action' => 'timeline_post_common', 'types' => $aSettingsTypes],
  1094. //--- Moderation related: For 'admins'.
  1095. ['group' => 'action_required', 'unit' => $sModule, 'action' => 'pending_approval', 'types' => ['personal']],
  1096. ],
  1097. 'alerts' => [
  1098. ['unit' => $sModule, 'action' => 'doVote'],
  1099. ['unit' => $sModule, 'action' => 'undoVote'],
  1100. ['unit' => $sModule, 'action' => 'doVoteUp'],
  1101. ['unit' => $sModule, 'action' => 'doVoteDown'],
  1102. ['unit' => $sModule, 'action' => 'fan_added'],
  1103. ['unit' => $sModule, 'action' => 'join_invitation_notif'],
  1104. ['unit' => $sModule, 'action' => 'join_request'],
  1105. ['unit' => $sModule, 'action' => 'timeline_post_common'],
  1106. //--- Moderation related: For 'admins'.
  1107. ['unit' => $sModule, 'action' => 'pending_approval'],
  1108. ]
  1109. ];
  1110. }
  1111. public function serviceGetNotificationsInsertData($oAlert, $aHandler, $aDataItems)
  1112. {
  1113. if($oAlert->sAction != 'join_invitation_notif' || empty($aDataItems) || !is_array($aDataItems))
  1114. return $aDataItems;
  1115. foreach($aDataItems as $iIndex => $aDataItem)
  1116. $aDataItems[$iIndex]['object_privacy_view'] = BX_DOL_PG_ALL;
  1117. return $aDataItems;
  1118. }
  1119. /**
  1120. * Notification about new invitation to join the group
  1121. */
  1122. public function serviceGetNotificationsJoinInvitation($aEvent)
  1123. {
  1124. $CNF = &$this->_oConfig->CNF;
  1125. $iContentId = (int)$aEvent['object_id'];
  1126. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  1127. if(!$oGroupProfile)
  1128. return array();
  1129. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1130. if(empty($aContentInfo) || !is_array($aContentInfo))
  1131. return array();
  1132. /*
  1133. * It's essential that 'object_owner_id' contains invited member profile id.
  1134. */
  1135. $oProfile = BxDolProfile::getInstance((int)$aEvent['object_owner_id']);
  1136. if(!$oProfile)
  1137. return array();
  1138. /*
  1139. * Note. Group Profile URL is used for both Entry and Subentry URLs,
  1140. * because Subentry URL has higher display priority and notification
  1141. * should be linked to Group Profile (Group Profile -> Members tab)
  1142. * instead of Personal Profile of invited member.
  1143. */
  1144. $sEntryUrl = bx_absolute_url(str_replace(BX_DOL_URL_ROOT, '', $oGroupProfile->getUrl()), '{bx_url_root}');
  1145. return array(
  1146. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1147. 'entry_url' => $sEntryUrl,
  1148. 'entry_caption' => $oGroupProfile->getDisplayName(),
  1149. 'subentry_sample' => $oProfile->getDisplayName(),
  1150. 'subentry_url' => $sEntryUrl,
  1151. 'lang_key' => $this->_oConfig->CNF['T']['txt_ntfs_join_invitation']
  1152. );
  1153. }
  1154. /**
  1155. * Notification about new member requst in the group
  1156. */
  1157. public function serviceGetNotificationsJoinRequest($aEvent)
  1158. {
  1159. return $this->_serviceGetNotification($aEvent, 'join_request', $this->_oConfig->CNF['T']['txt_ntfs_join_request']);
  1160. }
  1161. /**
  1162. * Notification about new member in the group
  1163. */
  1164. public function serviceGetNotificationsFanAdded($aEvent)
  1165. {
  1166. return $this->_serviceGetNotification($aEvent, 'fan_added', $this->_oConfig->CNF['T']['txt_ntfs_fan_added']);
  1167. }
  1168. protected function _serviceGetNotification($aEvent, $sType, $sLangKey)
  1169. {
  1170. $CNF = &$this->_oConfig->CNF;
  1171. $iContentId = (int)$aEvent['object_id'];
  1172. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  1173. if(!$oGroupProfile)
  1174. return array();
  1175. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1176. if(empty($aContentInfo) || !is_array($aContentInfo))
  1177. return array();
  1178. $oProfile = BxDolProfile::getInstance((int)$aEvent['subobject_id']);
  1179. if(!$oProfile)
  1180. return array();
  1181. $iGroupProfileId = $oGroupProfile->id();
  1182. /*
  1183. * Note. Group Profile URL is used for both Entry and Subentry URLs,
  1184. * because Subentry URL has higher display priority and notification
  1185. * should be linked to Group Profile (Group Profile -> Members tab or Manage page)
  1186. * instead of Personal Profile of a member, who performed an action.
  1187. */
  1188. if($sType == 'join_request' && !empty($CNF['URL_ENTRY_MANAGE']))
  1189. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($CNF['URL_ENTRY_MANAGE'], [
  1190. 'profile_id' => $iGroupProfileId
  1191. ]), '{bx_url_root}');
  1192. else if(!empty($CNF['URL_ENTRY_FANS']))
  1193. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($CNF['URL_ENTRY_FANS'], [
  1194. 'profile_id' => $iGroupProfileId
  1195. ]), '{bx_url_root}');
  1196. else
  1197. $sEntryUrl = bx_absolute_url(str_replace(BX_DOL_URL_ROOT, '', $oGroupProfile->getUrl()), '{bx_url_root}');
  1198. return [
  1199. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1200. 'entry_url' => $sEntryUrl,
  1201. 'entry_caption' => $oGroupProfile->getDisplayName(),
  1202. 'entry_author' => $iGroupProfileId,
  1203. 'subentry_sample' => $oProfile->getDisplayName(),
  1204. 'subentry_url' => $sEntryUrl,
  1205. 'lang_key' => $sLangKey
  1206. ];
  1207. }
  1208. /**
  1209. * Data for Reputation module
  1210. */
  1211. public function serviceGetReputationData()
  1212. {
  1213. $aResult = parent::serviceGetReputationData();
  1214. $sModule = $this->_aModule['name'];
  1215. if(!empty($aResult['handlers']) && is_array($aResult['handlers']))
  1216. foreach($aResult['handlers'] as $iKey => $aHandler)
  1217. if(in_array($aHandler['group'], [$sModule . '_comment', $sModule . '_reaction']))
  1218. unset($aResult['handlers'][$iKey]);
  1219. if(!empty($aResult['alerts']) && is_array($aResult['alerts']))
  1220. foreach($aResult['alerts'] as $iKey => $aAlert)
  1221. if($aAlert['unit'] == $sModule . '_reactions' || in_array($aAlert['action'], ['commentPost', 'commentRemoved']))
  1222. unset($aResult['alerts'][$iKey]);
  1223. return $aResult;
  1224. }
  1225. /**
  1226. * Data for Timeline module
  1227. */
  1228. public function serviceGetTimelineData()
  1229. {
  1230. $aResult = BxBaseModGeneralModule::serviceGetTimelineData();
  1231. $sModule = $this->_aModule['name'];
  1232. $aResult['handlers'] = array_merge($aResult['handlers'], [
  1233. ['group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'context_cover_changed'],
  1234. ['group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'context_cover_deleted']
  1235. ]);
  1236. $aResult['alerts'] = array_merge($aResult['alerts'], [
  1237. ['unit' => $sModule, 'action' => 'context_cover_changed'],
  1238. ['unit' => $sModule, 'action' => 'context_cover_deleted']
  1239. ]);
  1240. return $aResult;
  1241. }
  1242. /**
  1243. * Entry post for Timeline module
  1244. */
  1245. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  1246. {
  1247. $CNF = &$this->_oConfig->CNF;
  1248. $a = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  1249. if($a === false)
  1250. return false;
  1251. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aEvent['object_id'], $this->getName());
  1252. $a['content']['url'] = $oGroupProfile->getUrl();
  1253. $a['content']['title'] = $oGroupProfile->getDisplayName();
  1254. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  1255. if($oConnection)
  1256. $a['content']['members'] = $oConnection->getConnectedInitiatorsCount($oGroupProfile->id(), true);
  1257. if(isset($aEvent['object_privacy_view']))
  1258. $a['content']['visibility'] = $aEvent['object_privacy_view'];
  1259. if(isset($CNF['FIELD_PUBLISHED'])) {
  1260. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  1261. if($aContentInfo[$CNF['FIELD_PUBLISHED']] > $a['date'])
  1262. $a['date'] = $aContentInfo[$CNF['FIELD_PUBLISHED']];
  1263. }
  1264. return $a;
  1265. }
  1266. // ====== PERMISSION METHODS
  1267. /**
  1268. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1269. */
  1270. public function checkAllowedUsePaidJoin($isPerformAction = false)
  1271. {
  1272. // check ACL
  1273. $aCheck = checkActionModule($this->_iProfileId, 'use paid join', $this->getName(), $isPerformAction);
  1274. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1275. return $aCheck[CHECK_ACTION_MESSAGE];
  1276. return CHECK_ACTION_RESULT_ALLOWED;
  1277. }
  1278. /**
  1279. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1280. */
  1281. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  1282. {
  1283. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  1284. }
  1285. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1286. {
  1287. $CNF = &$this->_oConfig->CNF;
  1288. $iGroupContentId = (int)$aDataEntry[$CNF['FIELD_ID']];
  1289. $bInvited = false;
  1290. if(!empty($CNF['TABLE_INVITES'])) {
  1291. $iGroupProfileId = BxDolProfile::getInstanceByContentAndType($iGroupContentId, $this->getName())->id();
  1292. if(($sKey = bx_get('key')) !== false) {
  1293. $mixedInvited = $this->isInvited($sKey, $iGroupProfileId);
  1294. if($mixedInvited === true)
  1295. $bInvited = true;
  1296. }
  1297. else {
  1298. $mixedInvited = $this->isInvitedByProfileId($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $iGroupProfileId);
  1299. if($mixedInvited === true)
  1300. $bInvited = true;
  1301. }
  1302. }
  1303. if ($this->isFan($iGroupContentId, $iProfileId) || $bInvited)
  1304. return CHECK_ACTION_RESULT_ALLOWED;
  1305. return parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  1306. }
  1307. /**
  1308. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1309. */
  1310. public function checkAllowedCompose(&$aDataEntry, $isPerformAction = false)
  1311. {
  1312. if(!$this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]))
  1313. return _t('_sys_txt_access_denied');
  1314. return parent::checkAllowedCompose ($aDataEntry, $isPerformAction);
  1315. }
  1316. /**
  1317. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1318. */
  1319. public function checkAllowedFanAdd(&$aDataEntry, $isPerformAction = false)
  1320. {
  1321. $mixedResult = $this->_modGroupsCheckAllowedFanAdd($aDataEntry, $isPerformAction);
  1322. /**
  1323. * @hooks
  1324. * @hookdef hook-system-check_allowed_fan_add 'system', 'check_allowed_fan_add' - hook to override the result of checking whether 'fan add' to context action is allowed or not to currently logged in user
  1325. * - $unit_name - equals `system`
  1326. * - $action - equals `check_allowed_fan_add`
  1327. * - $object_id - not used
  1328. * - $sender_id - not used
  1329. * - $extra_params - array of additional params with the following array keys:
  1330. * - `module` - [string] module name
  1331. * - `content_info` - [array] context info array as key&value pairs
  1332. * - `profile_id` - [int] currently logged in profile id to be checked the availability of the action to
  1333. * - `override_result` - [string] or [int] by ref, check action result, can be overridden in hook processing. Return string with an error if action isn't allowed or CHECK_ACTION_RESULT_ALLOWED, @see BxDolAcl
  1334. * @hook @ref hook-system-check_allowed_fan_add
  1335. */
  1336. bx_alert('system', 'check_allowed_fan_add', 0, 0, [
  1337. 'module' => $this->getName(),
  1338. 'content_info' => $aDataEntry,
  1339. 'profile_id' => bx_get_logged_profile_id(),
  1340. 'override_result' => &$mixedResult
  1341. ]);
  1342. return $mixedResult;
  1343. }
  1344. public function _modGroupsCheckAllowedFanAdd (&$aDataEntry, $isPerformAction = false)
  1345. {
  1346. if ($this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]) || !isLogged())
  1347. return _t('_sys_txt_access_denied');
  1348. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, false);
  1349. }
  1350. /**
  1351. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1352. */
  1353. public function checkAllowedFanRemove (&$aDataEntry, $isPerformAction = false)
  1354. {
  1355. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, true))
  1356. return CHECK_ACTION_RESULT_ALLOWED;
  1357. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, false);
  1358. }
  1359. protected function _checkAllowedActionByFan($sAction, $aDataEntry, $iProfileId = 0)
  1360. {
  1361. $CNF = &$this->_oConfig->CNF;
  1362. $bRoles = $this->_oConfig->isRoles();
  1363. if(empty($iProfileId))
  1364. $iProfileId = bx_get_logged_profile_id();
  1365. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  1366. if(!$oGroupProfile)
  1367. return $sAction == BX_BASE_MOD_GROUPS_ACTION_DELETE ? CHECK_ACTION_RESULT_ALLOWED : _t('_sys_txt_not_found');
  1368. $iGroupProfileId = $oGroupProfile->id();
  1369. if(!$bRoles && $this->_oDb->isAdmin($iGroupProfileId, $iProfileId, $aDataEntry))
  1370. return CHECK_ACTION_RESULT_ALLOWED;
  1371. if($bRoles && $this->isAllowedActionByRole($sAction, $aDataEntry, $iGroupProfileId, $iProfileId))
  1372. return CHECK_ACTION_RESULT_ALLOWED;
  1373. return _t('_sys_txt_access_denied');
  1374. }
  1375. public function isAllowedActionByRole($mAction, $aDataEntry, $iGroupProfileId, $iProfileId)
  1376. {
  1377. $iProfileRole = $this->_oDb->getRole($iGroupProfileId, $iProfileId);
  1378. if (is_array($mAction)) {
  1379. $sAction = $mAction['action'];
  1380. $sActionModule = $mAction['module'];
  1381. } else {
  1382. $sAction = $mAction;
  1383. $sActionModule = $this->getName();
  1384. }
  1385. $bResult = false;
  1386. if($iProfileId)
  1387. $bResult = $this->isAllowedModuleActionByRole($sActionModule, $sAction, $iProfileRole);
  1388. // in case neither of the profile's roles are having permissions set explicitly then fallback to an old way
  1389. if ($bResult === NULL) {
  1390. $bResult = false;
  1391. if($this->isFanByGroupProfileId($iGroupProfileId)) {
  1392. switch ($sAction) {
  1393. case BX_BASE_MOD_GROUPS_ACTION_DELETE:
  1394. case BX_BASE_MOD_GROUPS_ACTION_EDIT:
  1395. case BX_BASE_MOD_GROUPS_ACTION_CHANGE_SETTINGS:
  1396. case BX_BASE_MOD_GROUPS_ACTION_CHANGE_COVER:
  1397. case BX_BASE_MOD_GROUPS_ACTION_MANAGE_ROLES:
  1398. if($this->isRole($iProfileRole, BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR))
  1399. $bResult = true;
  1400. break;
  1401. case BX_BASE_MOD_GROUPS_ACTION_MANAGE_FANS:
  1402. case BX_BASE_MOD_GROUPS_ACTION_INVITE:
  1403. case BX_BASE_MOD_GROUPS_ACTION_EDIT_CONTENT:
  1404. case BX_BASE_MOD_GROUPS_ACTION_DELETE_CONTENT:
  1405. case BX_BASE_MOD_GROUPS_ACTION_TIMELINE_POST_PIN:
  1406. if($this->isRole($iProfileRole, BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR) || $this->isRole($iProfileRole, BX_BASE_MOD_GROUPS_ROLE_MODERATOR))
  1407. $bResult = true;
  1408. break;
  1409. default:
  1410. $bResult = true;
  1411. }
  1412. }
  1413. }
  1414. // in case current user is not allowed to edit/delete this group then
  1415. // if it is a subgroup inside a context then give to the admin roles of a parent context the ability to edit/delete that subgroup.
  1416. if (
  1417. !$bResult &&
  1418. ($sAction == BX_BASE_MOD_GROUPS_ACTION_EDIT || $sAction == BX_BASE_MOD_GROUPS_ACTION_DELETE) &&
  1419. isset($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) &&
  1420. $this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO'] &&
  1421. isset($aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]) &&
  1422. $aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0)
  1423. {
  1424. $iParentContextProfileId = -$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']];
  1425. $oParentContext = BxDolProfile::getInstance($iParentContextProfileId);
  1426. if ($oParentContext) {
  1427. $sCheckAction = $sAction == BX_BASE_MOD_GROUPS_ACTION_EDIT ? BX_BASE_MOD_GROUPS_ACTION_EDIT_CONTENT : BX_BASE_MOD_GROUPS_ACTION_DELETE_CONTENT;
  1428. $aParentDataEntry = bx_srv($oParentContext->getModule(), 'get_info', [$oParentContext->getContentId(), false]);
  1429. return $this->isAllowedActionByRole(['action' => $sCheckAction, 'module' => $oParentContext->getModule()], $aParentDataEntry, $iParentContextProfileId, $iProfileId);
  1430. }
  1431. }
  1432. /**
  1433. * @hooks
  1434. * @hookdef hook-system-check_allowed_action_by_role 'system', 'check_allowed_action_by_role' - hook to override the result of checking whether an action is allowed or not to context member by his role in the context
  1435. * - $unit_name - equals `system`
  1436. * - $action - equals `check_allowed_action_by_role`
  1437. * - $object_id - not used
  1438. * - $sender_id - not used
  1439. * - $extra_params - array of additional params with the following array keys:
  1440. * - `module` - [string] module name
  1441. * - `multi_roles` - [boolean] whether multi roles are enabled in context or not
  1442. * - `action` - [string] action to be checked
  1443. * - `action_module` - [string] module name which the action belongs to
  1444. * - `content_profile_id` - [int] context profile id
  1445. * - `content_info` - [array] context info array as key&value pairs
  1446. * - `profile_id` - [int] profile id to be checked the availability of the action to
  1447. * - `profile_role` - [int] profile role in the context
  1448. * - `override_result` - [boolean] by ref, check action result, can be overridden in hook processing.
  1449. * @hook @ref hook-system-check_allowed_action_by_role
  1450. */
  1451. bx_alert('system', 'check_allowed_action_by_role', 0, 0, [
  1452. 'module' => $this->getName(),
  1453. 'multi_roles' => $this->_oConfig->isMultiRoles(),
  1454. 'action' => $sAction,
  1455. 'action_module' => $sActionModule,
  1456. 'content_profile_id' => $iGroupProfileId,
  1457. 'content_info' => $aDataEntry,
  1458. 'profile_id' => $iProfileId,
  1459. 'profile_role' => $iProfileRole,
  1460. 'override_result' => &$bResult
  1461. ]);
  1462. return $bResult;
  1463. }
  1464. public function isAllowedModuleActionByRole($sModule, $sAction, $iProfileRole)
  1465. {
  1466. static $aRoles;
  1467. if (!$aRoles && isset($this->_oConfig->CNF['OBJECT_PRE_LIST_ROLES']) && !empty($this->_oConfig->CNF['OBJECT_PRE_LIST_ROLES']))
  1468. $aRoles = BxBaseFormView::getDataItems($this->_oConfig->CNF['OBJECT_PRE_LIST_ROLES'], true, BX_DATA_VALUES_ALL);
  1469. if ($aRoles) {
  1470. foreach ($aRoles as $iRole => $aRoleData) {
  1471. if ($iRole == 0 && $iProfileRole == 0 || $iRole > 0 && $this->isRole($iProfileRole, $iRole)) {
  1472. $mPermissions = isset($aRoles[$iRole]) && isset($aRoles[$iRole]['Data']) && !empty($aRoles[$iRole]['Data']) ? unserialize($aRoles[$iRole]['Data']) : false;
  1473. if ($mPermissions && isset($mPermissions[$sModule])) {
  1474. return isset($mPermissions[$sModule][$sAction]) && $mPermissions[$sModule][$sAction];
  1475. }
  1476. }
  1477. }
  1478. }
  1479. return NULL;
  1480. }
  1481. public function isAllowedModuleActionByProfile($iContentId, $sPostModule, $sAction, $iProfileId = 0) {
  1482. if (!$iProfileId) $iProfileId = bx_get_logged_profile_id();
  1483. if ($iProfileId && $this->isFan($iContentId, $iProfileId)) {
  1484. $sModuleName = $this->getName();
  1485. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModuleName);
  1486. $aDataEntry = $this->_oDb->getContentInfoById($iContentId);
  1487. $bResult = $this->isAllowedActionByRole(['action' => $sAction, 'module' => $sPostModule], $aDataEntry, $oGroupProfile->id(), $iProfileId);
  1488. if ($bResult === true) return CHECK_ACTION_RESULT_ALLOWED;
  1489. if ($bResult === false) return _t('_sys_txt_access_denied');
  1490. }
  1491. 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.
  1492. }
  1493. public function isRole($iProfileRole, $iRole)
  1494. {
  1495. if(!$this->_oConfig->isMultiRoles())
  1496. return $iProfileRole == $iRole;
  1497. else
  1498. return $iProfileRole & (1 << ($iRole - 1));
  1499. }
  1500. public function serviceIsRole($iProfileRole, $iRole)
  1501. {
  1502. return $this->isRole($iProfileRole, $iRole);
  1503. }
  1504. public function checkAllowedManageFans($mixedDataEntry, $isPerformAction = false)
  1505. {
  1506. $aDataEntry = array();
  1507. if(!is_array($mixedDataEntry)) {
  1508. $oGroupProfile = BxDolProfile::getInstance((int)$mixedDataEntry);
  1509. if($oGroupProfile && $this->getName() == $oGroupProfile->getModule())
  1510. $aDataEntry = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  1511. }
  1512. else
  1513. $aDataEntry = $mixedDataEntry;
  1514. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_MANAGE_FANS, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1515. return CHECK_ACTION_RESULT_ALLOWED;
  1516. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  1517. }
  1518. public function checkAllowedManageAdmins($mixedDataEntry, $isPerformAction = false)
  1519. {
  1520. $aDataEntry = array();
  1521. if(!is_array($mixedDataEntry)) {
  1522. $oGroupProfile = BxDolProfile::getInstance((int)$mixedDataEntry);
  1523. if($oGroupProfile && $this->getName() == $oGroupProfile->getModule())
  1524. $aDataEntry = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  1525. }
  1526. else
  1527. $aDataEntry = $mixedDataEntry;
  1528. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_MANAGE_ROLES, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1529. return CHECK_ACTION_RESULT_ALLOWED;
  1530. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  1531. }
  1532. public function checkAllowedEdit($aDataEntry, $isPerformAction = false)
  1533. {
  1534. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_EDIT, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1535. return CHECK_ACTION_RESULT_ALLOWED;
  1536. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  1537. }
  1538. public function checkAllowedInvite($aDataEntry, $isPerformAction = false)
  1539. {
  1540. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_INVITE, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1541. return CHECK_ACTION_RESULT_ALLOWED;
  1542. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  1543. }
  1544. public function checkAllowedChangeCover($aDataEntry, $isPerformAction = false)
  1545. {
  1546. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_CHANGE_COVER, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1547. return CHECK_ACTION_RESULT_ALLOWED;
  1548. return parent::checkAllowedChangeCover($aDataEntry, $isPerformAction);
  1549. }
  1550. public function checkAllowedChangeSettings($aDataEntry, $isPerformAction = false)
  1551. {
  1552. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_CHANGE_SETTINGS, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1553. return CHECK_ACTION_RESULT_ALLOWED;
  1554. return parent::checkAllowedChangeSettings($aDataEntry, $isPerformAction);
  1555. }
  1556. public function checkAllowedDelete(&$aDataEntry, $isPerformAction = false)
  1557. {
  1558. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_DELETE, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1559. return CHECK_ACTION_RESULT_ALLOWED;
  1560. return parent::checkAllowedDelete($aDataEntry, $isPerformAction);
  1561. }
  1562. public function checkAllowedJoin(&$aDataEntry, $isPerformAction = false)
  1563. {
  1564. if (bx_get('key')){
  1565. $sKey = bx_get('key');
  1566. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  1567. $aData = $this->_oDb->getInviteByKey($sKey, $oGroupProfile->id());
  1568. if (isset($aData['invited_profile_id']) && $aData['invited_profile_id'] == bx_get_logged_profile_id()){
  1569. return CHECK_ACTION_RESULT_ALLOWED;
  1570. }
  1571. }
  1572. return _t('_sys_txt_access_denied');
  1573. }
  1574. public function checkAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1575. {
  1576. $mixedResult = $this->_modGroupsCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  1577. /**
  1578. * @hooks
  1579. * @hookdef hook-system-check_allowed_subscribe_add 'system', 'check_allowed_subscribe_add' - hook to override the result of checking whether currently logged in user can subscribe (follow) the context or not
  1580. * - $unit_name - equals `system`
  1581. * - $action - equals `check_allowed_subscribe_add`
  1582. * - $object_id - not used
  1583. * - $sender_id - not used
  1584. * - $extra_params - array of additional params with the following array keys:
  1585. * - `module` - [string] module name
  1586. * - `content_info` - [array] context info array as key&value pairs
  1587. * - `profile_id` - [int] currently logged in profile id to be checked the availability of the action to
  1588. * - `override_result` - [string] or [int] by ref, check action result, can be overridden in hook processing. Return string with an error if action isn't allowed or CHECK_ACTION_RESULT_ALLOWED, @see BxDolAcl
  1589. * @hook @ref hook-system-check_allowed_subscribe_add
  1590. */
  1591. bx_alert('system', 'check_allowed_subscribe_add', 0, 0, [
  1592. 'module' => $this->getName(),
  1593. 'content_info' => $aDataEntry,
  1594. 'profile_id' => bx_get_logged_profile_id(),
  1595. 'override_result' => &$mixedResult
  1596. ]);
  1597. return $mixedResult;
  1598. }
  1599. /**
  1600. * Note. Is mainly needed for internal usage. Access level is 'public' to allow outer calls from alerts.
  1601. */
  1602. public function _modGroupsCheckAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1603. {
  1604. $CNF = &$this->_oConfig->CNF;
  1605. if(!$this->isFan($aDataEntry[$CNF['FIELD_ID']]) && (!isset($CNF['PARAM_SBS_WO_JOIN']) || getParam($CNF['PARAM_SBS_WO_JOIN']) != 'on'))
  1606. return _t('_sys_txt_access_denied');
  1607. return parent::_modProfileCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  1608. }
  1609. /**
  1610. * @deprecated since version 11.0.3 and can be removed in the next version.
  1611. */
  1612. public function _checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  1613. {
  1614. return parent::checkAllowedSubscribeAdd ($aDataEntry, $isPerformAction);
  1615. }
  1616. public function doAudit($iGroupProfileId, $iFanId, $sAction)
  1617. {
  1618. $oProfile = BxDolProfile::getInstance($iFanId);
  1619. $iContentId = $oProfile->getContentId();
  1620. $sModule = $oProfile->getModule();
  1621. $oModule = BxDolModule::getInstance($sModule);
  1622. if (BxDolRequest::serviceExists($sModule, 'act_as_profile') && BxDolService::call($sModule, 'act_as_profile') && $oModule->_oConfig){
  1623. $CNF = $oModule->_oConfig->CNF;
  1624. $aContentInfo = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $iContentId))) : array();
  1625. $AuditParams = array(
  1626. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  1627. 'context_profile_id' => $iGroupProfileId,
  1628. 'context_profile_title' => BxDolProfile::getInstance($iGroupProfileId)->getDisplayName()
  1629. );
  1630. bx_audit(
  1631. $iContentId,
  1632. $sModule,
  1633. $sAction,
  1634. $AuditParams
  1635. );
  1636. }
  1637. }
  1638. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  1639. {
  1640. $sResult = $this->checkAllowedView($aDataEntry);
  1641. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  1642. // when context is in another context
  1643. if ($aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0 && getParam('sys_check_fan_in_parent_context')) {
  1644. $oParent = BxDolProfile::getInstance(abs($aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]));
  1645. $oModule = $oParent ? BxDolModule::getInstance($oParent->getModule()) : null;
  1646. if ($oModule && method_exists($oModule, 'isFan') && !$oModule->isFan($oParent->getContentId()))
  1647. return _t('_sys_txt_access_denied');
  1648. }
  1649. // if profile view isn't allowed but visibility is in partially visible groups
  1650. // then display buttons to connect (befriend, join) to profile,
  1651. // if other conditions (in parent::_checkAllowedConnect) are met as well
  1652. if (CHECK_ACTION_RESULT_ALLOWED !== $sResult && !in_array($aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']], array_merge($oPrivacy->getPartiallyVisiblePrivacyGroups(), array('s'))))
  1653. return $sResult;
  1654. return parent::_checkAllowedConnect ($aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap);
  1655. }
  1656. // ====== COMMON METHODS
  1657. public function onUpdateImage($iContentId, $sFiledName, $sFiledValue, $iProfileId = 0)
  1658. {
  1659. $CNF = &$this->_oConfig->CNF;
  1660. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1661. $aField2Method = [
  1662. $CNF['FIELD_PICTURE'] => 'picture',
  1663. $CNF['FIELD_COVER'] => 'cover',
  1664. ];
  1665. if(!empty($aField2Method[$sFiledName]))
  1666. /**
  1667. * @hooks
  1668. * @hookdef hook-bx_base_groups-context_picture_changed '{module_name}', 'context_picture_changed' - hook after context picture was changed
  1669. * - $unit_name - module name
  1670. * - $action - equals `context_picture_changed`
  1671. * - $object_id - context id
  1672. * - $sender_id - profile id who performed the action
  1673. * - $extra_params - array of additional params with the following array keys:
  1674. * - `status` - [string] context status
  1675. * - `status_admin` - [string] context admin status
  1676. * - `privacy_view` - [int] or [string] privacy for view context action, @see BxDolPrivacy
  1677. * - `cf` - [int] context's audience filter value
  1678. * @hook @ref hook-bx_base_groups-context_picture_changed
  1679. */
  1680. /**
  1681. * @hooks
  1682. * @hookdef hook-bx_base_groups-context_cover_changed '{module_name}', 'context_cover_changed' - hook after context cover was changed
  1683. * It's equivalent to @ref hook-bx_base_groups-context_picture_changed
  1684. * @hook @ref hook-bx_base_groups-context_cover_changed
  1685. */
  1686. bx_alert($this->getName(), 'context_' . $aField2Method[$sFiledName] . '_changed', $iContentId, $iProfileId, $this->_alertParams($aContentInfo));
  1687. }
  1688. protected function _alertParams($aContentInfo)
  1689. {
  1690. $aParams = parent::_alertParams($aContentInfo);
  1691. $CNF = &$this->_oConfig->CNF;
  1692. if(!empty($CNF['FIELD_CF']) && isset($aContentInfo[$CNF['FIELD_CF']]))
  1693. $aParams['cf'] = $aContentInfo[$CNF['FIELD_CF']];
  1694. return $aParams;
  1695. }
  1696. public function alertAfterAdd($aContentInfo)
  1697. {
  1698. $CNF = &$this->_oConfig->CNF;
  1699. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1700. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  1701. $sAction = 'added';
  1702. if(isset($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == BX_BASE_MOD_GENERAL_STATUS_PENDING)
  1703. $sAction = 'deferred';
  1704. $sModule = $this->getName();
  1705. $aParams = $this->_alertParams($aContentInfo);
  1706. /**
  1707. * @hooks
  1708. * @hookdef hook-system-prepare_alert_params 'system', 'prepare_alert_params' - hook to override alert (hook) params
  1709. * - $unit_name - equals `system`
  1710. * - $action - equals `prepare_alert_params`
  1711. * - $object_id - not used
  1712. * - $sender_id - not used
  1713. * - $extra_params - array of additional params with the following array keys:
  1714. * - `unit` - [string] unit name
  1715. * - `action` - [string] by ref, action, can be overridden in hook processing
  1716. * - `object_id` - [int] by ref, object id, can be overridden in hook processing
  1717. * - `sender_id` - [int] by ref, action performer profile id, can be overridden in hook processing
  1718. * - `extras` - [array] by ref, extra params array as key&value pairs, can be overridden in hook processing
  1719. * @hook @ref hook-system-prepare_alert_params
  1720. */
  1721. bx_alert('system', 'prepare_alert_params', 0, 0, [
  1722. 'unit'=> $sModule,
  1723. 'action' => &$sAction,
  1724. 'object_id' => &$iId,
  1725. 'sender_id' => &$iAuthorId,
  1726. 'extras' => &$aParams
  1727. ]);
  1728. /**
  1729. * @hooks
  1730. * @hookdef hook-bx_base_groups-added '{module_name}', 'added' - hook after context was added (published)
  1731. * - $unit_name - module name
  1732. * - $action - equals `added`
  1733. * - $object_id - context id
  1734. * - $sender_id - not used
  1735. * - $extra_params - array of additional params with the following array keys:
  1736. * - `status` - [string] context status
  1737. * - `status_admin` - [string] context admin status
  1738. * - `privacy_view` - [int] or [string] privacy for view context action, @see BxDolPrivacy
  1739. * - `cf` - [int] context's audience filter value
  1740. * @hook @ref hook-bx_base_groups-added
  1741. */
  1742. /**
  1743. * @hooks
  1744. * @hookdef hook-bx_base_groups-deferred '{module_name}', 'deferred' - hook after context was added with pending approval status
  1745. * It's equivalent to @ref hook-bx_base_groups-added
  1746. * @hook @ref hook-bx_base_groups-deferred
  1747. */
  1748. bx_alert($sModule, $sAction, $iId, false, $aParams);
  1749. $this->_processModerationNotifications($aContentInfo);
  1750. }
  1751. public function addFollower ($iProfileId1, $iProfileId2)
  1752. {
  1753. $oConnectionFollow = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  1754. if($oConnectionFollow && !$oConnectionFollow->isConnected($iProfileId1, $iProfileId2)){
  1755. $oConnectionFollow->addConnection($iProfileId1, $iProfileId2);
  1756. return true;
  1757. }
  1758. return false;
  1759. }
  1760. public function isFan ($iContentId, $iProfileId = false)
  1761. {
  1762. $CNF = &$this->_oConfig->CNF;
  1763. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  1764. if($oGroupProfile && isset($CNF['OBJECT_CONNECTIONS']))
  1765. return ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $oGroupProfile->id(), true);
  1766. return false;
  1767. }
  1768. public function isFanByGroupProfileId ($iGroupProfileId, $iProfileId = false)
  1769. {
  1770. $CNF = &$this->_oConfig->CNF;
  1771. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1772. if($oGroupProfile && isset($CNF['OBJECT_CONNECTIONS']))
  1773. return ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $oGroupProfile->id(), true);
  1774. return false;
  1775. }
  1776. public function isInvited ($sKey, $iGroupProfileId)
  1777. {
  1778. $CNF = &$this->_oConfig->CNF;
  1779. $aData = $this->_oDb->getInviteByKey($sKey, $iGroupProfileId);
  1780. if (!isset($aData['invited_profile_id']))
  1781. return _t($CNF['T']['txt_invitation_popup_error_invitation_absent']);
  1782. if ($aData['invited_profile_id'] != bx_get_logged_profile_id())
  1783. return _t($CNF['T']['txt_invitation_popup_error_wrong_user']);
  1784. return true;
  1785. }
  1786. public function isInvitedByProfileId ($iProfileId, $iGroupProfileId)
  1787. {
  1788. $CNF = &$this->_oConfig->CNF;
  1789. $aData = $this->_oDb->getInviteByInvited($iProfileId, $iGroupProfileId);
  1790. if (!isset($aData['invited_profile_id']))
  1791. return _t($CNF['T']['txt_invitation_popup_error_invitation_absent']);
  1792. if ($aData['invited_profile_id'] != bx_get_logged_profile_id())
  1793. return _t($CNF['T']['txt_invitation_popup_error_wrong_user']);
  1794. return true;
  1795. }
  1796. public function serviceIsInvited($iGroupProfileId, $iProfileId = false, $sKey = '')
  1797. {
  1798. if(!$iProfileId)
  1799. $iProfileId = bx_get_logged_profile_id();
  1800. if(empty($sKey) && ($sKey = bx_get('key')) !== false)
  1801. $sKey = bx_process_input($sKey);
  1802. $mixedInvited = false;
  1803. if(!empty($sKey))
  1804. $mixedInvited = $this->isInvited($sKey, $iGroupProfileId);
  1805. else if($iProfileId !== false)
  1806. $mixedInvited = $this->isInvitedByProfileId($iProfileId, $iGroupProfileId);
  1807. return $mixedInvited === true;
  1808. }
  1809. public function serviceIsNotInvited($iGroupProfileId, $iProfileId = false, $sKey = '')
  1810. {
  1811. return !$this->serviceIsInvited($iGroupProfileId, $iProfileId, $sKey);
  1812. }
  1813. public function serviceGetInvitedKey($iGroupProfileId, $iProfileId = false)
  1814. {
  1815. $sKey = '';
  1816. if(($sKey = bx_get('key')) !== false)
  1817. $sKey = bx_process_input($sKey);
  1818. if(!$sKey) {
  1819. if(!$iProfileId)
  1820. $iProfileId = bx_get_logged_profile_id();
  1821. if($iProfileId !== false) {
  1822. $aInvite = $this->_oDb->getInviteByInvited($iProfileId, $iGroupProfileId);
  1823. if(!empty($aInvite) && is_array($aInvite))
  1824. $sKey = $aInvite['key'];
  1825. }
  1826. }
  1827. return $sKey;
  1828. }
  1829. public function getRole($iGroupProfileId, $iFanProfileId)
  1830. {
  1831. if(!$this->isFanByGroupProfileId($iGroupProfileId, $iFanProfileId))
  1832. return false;
  1833. return $this->_oDb->getRole($iGroupProfileId, $iFanProfileId);
  1834. }
  1835. public function setRole($iGroupProfileId, $iFanProfileId, $mixedRole, $mixedPeriod = false, $sOrder = '')
  1836. {
  1837. $CNF = &$this->_oConfig->CNF;
  1838. if(!isset($CNF['OBJECT_CONNECTIONS']))
  1839. return false;
  1840. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  1841. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1842. if(!$oConnection || !$oGroupProfile)
  1843. return false;
  1844. if(!$oConnection->isConnected($iFanProfileId, $iGroupProfileId, true) && !$oConnection->addConnection($iFanProfileId, $iGroupProfileId))
  1845. return false;
  1846. if(!$this->_oDb->setRole($iGroupProfileId, $iFanProfileId, $mixedRole, $mixedPeriod, $sOrder))
  1847. return false;
  1848. $this->onSetRole($iGroupProfileId, $iFanProfileId, $mixedRole);
  1849. return true;
  1850. }
  1851. public function onSetRole($iGroupProfileId, $iFanProfileId, $mixedRole)
  1852. {
  1853. $CNF = &$this->_oConfig->CNF;
  1854. $iProfileId = bx_get_logged_profile_id();
  1855. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1856. $aGroupProfileInfo = $this->_oDb->getContentInfoById((int)$oGroupProfile->getContentId());
  1857. $aRoles = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_ROLES']);
  1858. // notify about admin status
  1859. if(!empty($CNF['EMAIL_FAN_SET_ROLE']) && $iFanProfileId != $iProfileId) {
  1860. $aSetRoles = is_array($mixedRole) ? $mixedRole : [$mixedRole];
  1861. $aRolesNames = [];
  1862. foreach ($aSetRoles as $iRole)
  1863. $aRolesNames[] = $aRoles[(int)$iRole];
  1864. sendMailTemplate($CNF['EMAIL_FAN_SET_ROLE'], 0, $iFanProfileId, array(
  1865. 'EntryUrl' => $oGroupProfile->getUrl(),
  1866. 'EntryTitle' => $oGroupProfile->getDisplayName(),
  1867. 'Role' => implode(', ', $aRolesNames),
  1868. ), BX_EMAIL_NOTIFY);
  1869. }
  1870. /**
  1871. * @hooks
  1872. * @hookdef hook-bx_base_groups-set_role '{module_name}', 'set_role' - hook after 'set role' action was applied to context member
  1873. * - $unit_name - module name
  1874. * - $action - equals `set_role`
  1875. * - $object_id - context id
  1876. * - $sender_id - context profile id
  1877. * - $extra_params - array of additional params with the following array keys:
  1878. * - `object_author_id` - [int] context profile id
  1879. * - `performer_id` - [int] performer profile id
  1880. * - `fan_id` - [int] context member profile id
  1881. * - `content` - [array] context info array as key&value pairs
  1882. * - `role` - [int] or [array] role or an array of roles to be set
  1883. * - `group_profile` - [int] context profile id
  1884. * - `profile` - [int] performer profile id
  1885. * @hook @ref hook-bx_base_groups-set_role
  1886. */
  1887. bx_alert($this->getName(), 'set_role', $aGroupProfileInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  1888. 'object_author_id' => $iGroupProfileId,
  1889. 'performer_id' => $iProfileId,
  1890. 'fan_id' => $iFanProfileId,
  1891. 'content' => $aGroupProfileInfo,
  1892. 'role' => $mixedRole,
  1893. 'group_profile' => $iGroupProfileId,
  1894. 'profile' => $iProfileId
  1895. ));
  1896. $this->doAudit($iGroupProfileId, $iFanProfileId, '_sys_audit_action_group_role_changed');
  1897. }
  1898. public function unsetRole($iGroupProfileId, $iFanProfileId)
  1899. {
  1900. $CNF = &$this->_oConfig->CNF;
  1901. if(!isset($CNF['OBJECT_CONNECTIONS']))
  1902. return false;
  1903. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  1904. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1905. if(!$oConnection || !$oGroupProfile)
  1906. return false;
  1907. if($oConnection->isConnected($iFanProfileId, $iGroupProfileId, true) && !$oConnection->removeConnection($iFanProfileId, $iGroupProfileId))
  1908. return false;
  1909. $iRole = $this->_oDb->getRole($iGroupProfileId, $iFanProfileId);
  1910. if(!$this->_oDb->unsetRole($iGroupProfileId, $iFanProfileId))
  1911. return false;
  1912. $this->onUnsetRole($iGroupProfileId, $iFanProfileId, $iRole);
  1913. return true;
  1914. }
  1915. public function onUnsetRole($iGroupProfileId, $iFanProfileId, $iRole)
  1916. {
  1917. $CNF = &$this->_oConfig->CNF;
  1918. $iProfileId = bx_get_logged_profile_id();
  1919. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1920. $aGroupProfileInfo = $this->_oDb->getContentInfoById((int)$oGroupProfile->getContentId());
  1921. /**
  1922. * @hooks
  1923. * @hookdef hook-bx_base_groups-set_role '{module_name}', 'set_role' - hook after 'set role' action was applied to context member
  1924. * - $unit_name - module name
  1925. * - $action - equals `set_role`
  1926. * - $object_id - context id
  1927. * - $sender_id - context profile id
  1928. * - $extra_params - array of additional params with the following array keys:
  1929. * - `object_author_id` - [int] context profile id
  1930. * - `performer_id` - [int] performer profile id
  1931. * - `fan_id` - [int] context member profile id
  1932. * - `content` - [array] context info array as key&value pairs
  1933. * - `role` - [int] or [array] role or an array of roles to be set
  1934. * - `group_profile` - [int] context profile id
  1935. * - `profile` - [int] performer profile id
  1936. * @hook @ref hook-bx_base_groups-set_role
  1937. */
  1938. bx_alert($this->getName(), 'set_role', $aGroupProfileInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  1939. 'object_author_id' => $iGroupProfileId,
  1940. 'performer_id' => $iProfileId,
  1941. 'fan_id' => $iFanProfileId,
  1942. 'content' => $aGroupProfileInfo,
  1943. 'role' => $iRole,
  1944. 'group_profile' => $iGroupProfileId,
  1945. 'profile' => $iProfileId
  1946. ));
  1947. $this->doAudit($iGroupProfileId, $iFanProfileId, '_sys_audit_action_group_role_changed');
  1948. }
  1949. public function getGroupsByFan($iProfileId, $mixedRole = false)
  1950. {
  1951. $CNF = &$this->_oConfig->CNF;
  1952. if(!isset($CNF['OBJECT_CONNECTIONS']))
  1953. return false;
  1954. if($mixedRole === false)
  1955. $mixedRole = BX_BASE_MOD_GROUPS_ROLE_COMMON;
  1956. if(!is_array($mixedRole))
  1957. $mixedRole = [$mixedRole];
  1958. $aResult = [];
  1959. foreach($mixedRole as $iRole) {
  1960. switch($iRole) {
  1961. case BX_BASE_MOD_GROUPS_ROLE_COMMON:
  1962. $aIds = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])->getConnectedContent($iProfileId);
  1963. break;
  1964. default:
  1965. $aIds = $this->_oDb->getRoles([
  1966. 'type' => 'group_pids_by_fan_id',
  1967. 'fan_id' => $iProfileId,
  1968. 'role' => $iRole
  1969. ]);
  1970. }
  1971. $aResult = array_merge($aResult, $aIds);
  1972. }
  1973. return $aResult;
  1974. }
  1975. public function getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfileId, $iInitiatorProfileId = 0)
  1976. {
  1977. $CNF = $this->_oConfig->getCNF();
  1978. $aResult = parent::getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfileId, $iInitiatorProfileId);
  1979. if(!empty($aResult))
  1980. return $aResult;
  1981. $oConnection = BxDolConnection::getObjectInstance($sConnection);
  1982. if(!$oConnection)
  1983. return false;
  1984. if(!$iInitiatorProfileId)
  1985. $iInitiatorProfileId = bx_get_logged_profile_id();
  1986. $aResult = [];
  1987. if($oConnection->isConnectedNotMutual($iInitiatorProfileId, $iContentProfileId))
  1988. $aResult = [
  1989. 'add' => _t(!empty($CNF['T']['menu_item_title_sm_join_requested']) ? $CNF['T']['menu_item_title_sm_join_requested'] : '_sys_menu_item_title_sm_join_requested'),
  1990. 'remove' => _t(!empty($CNF['T']['menu_item_title_sm_leave_cancel']) ? $CNF['T']['menu_item_title_sm_leave_cancel'] : '_sys_menu_item_title_sm_leave_cancel'),
  1991. ];
  1992. else if($oConnection->isConnectedNotMutual($iContentProfileId, $iInitiatorProfileId))
  1993. $aResult = [
  1994. 'add' => _t(!empty($CNF['T']['menu_item_title_sm_join_confirm']) ? $CNF['T']['menu_item_title_sm_join_confirm'] : '_sys_menu_item_title_sm_join_confirm'),
  1995. 'remove' => _t(!empty($CNF['T']['menu_item_title_sm_leave_reject']) ? $CNF['T']['menu_item_title_sm_leave_reject'] : '_sys_menu_item_title_sm_leave_reject'),
  1996. ];
  1997. else if($oConnection->isConnected($iInitiatorProfileId, $iContentProfileId, true))
  1998. $aResult = [
  1999. 'add' => '',
  2000. 'remove' => _t(!empty($CNF['T']['menu_item_title_sm_leave']) ? $CNF['T']['menu_item_title_sm_leave'] : '_sys_menu_item_title_sm_leave'),
  2001. ];
  2002. else
  2003. $aResult = [
  2004. 'add' => _t(!empty($CNF['T']['menu_item_title_sm_join']) ? $CNF['T']['menu_item_title_sm_join'] : '_sys_menu_item_title_sm_join'),
  2005. 'remove' => '',
  2006. ];
  2007. return !empty($sAction) && isset($aResult[$sAction]) ? $aResult[$sAction] : $aResult;
  2008. }
  2009. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2010. {
  2011. $CNF = &$this->_oConfig->CNF;
  2012. $iImageId = 0;
  2013. $sImageMd = $sImageXl = '';
  2014. if(isset($CNF['FIELD_COVER']) && !empty($aContentInfo[$CNF['FIELD_COVER']])) {
  2015. $iImageId = (int)$aContentInfo[$CNF['FIELD_COVER']];
  2016. $sImageMd = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  2017. $sImageXl = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_COVER']);
  2018. }
  2019. if($sImageXl == '' && isset($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']])) {
  2020. $iImageId = (int)$aContentInfo[$CNF['FIELD_PICTURE']];
  2021. $sImageMd = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  2022. $sImageXl = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_COVER']);
  2023. }
  2024. if(empty($sImageXl))
  2025. return [];
  2026. $aImage = [
  2027. 'id' => $iImageId,
  2028. 'url' => $sUrl,
  2029. 'src' => $sImageXl,
  2030. 'src_orig' => $sImageXl
  2031. ];
  2032. if(!empty($sImageMd))
  2033. $aImage['src_medium'] = $sImageMd;
  2034. return [
  2035. $aImage
  2036. ];
  2037. }
  2038. protected function _prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId)
  2039. {
  2040. if (!($oGroupProfile = BxDolProfile::getInstance($iGroupProfileId)))
  2041. return array(0, 0, null);
  2042. if ($oGroupProfile->getModule() == $this->getName()) {
  2043. $iProfileId = $iInitiatorId;
  2044. $iGroupProfileId = $oGroupProfile->id();
  2045. } else {
  2046. $iProfileId = $oGroupProfile->id();
  2047. $iGroupProfileId = $iInitiatorId;
  2048. }
  2049. return array($iProfileId, $iGroupProfileId, $oGroupProfile);
  2050. }
  2051. }
  2052. /** @} */