BxBaseModGroupsModule.php 85 KB

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