BxBaseModGroupsModule.php 97 KB

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