BxBaseModGroupsModule.php 107 KB

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