BxBaseModGroupsModule.php 107 KB

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