BxBaseModGroupsModule.php 83 KB

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