BxBaseModGroupsModule.php 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222
  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. if($this->_bIsApi){
  468. return [
  469. bx_api_get_block('grid', $oGrid->getCodeAPI())
  470. ];
  471. }
  472. return $oGrid->getCode();
  473. }
  474. public function serviceFans ($iContentId = 0, $bAsArray = false)
  475. {
  476. $CNF = &$this->_oConfig->CNF;
  477. if (!$iContentId)
  478. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  479. if (!$iContentId)
  480. return false;
  481. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  482. if (!$aContentInfo)
  483. return false;
  484. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
  485. return false;
  486. if(!$bAsArray) {
  487. bx_import('BxDolConnection');
  488. $mixedResult = $this->serviceBrowseConnectionsQuick ($oGroupProfile->id(), $CNF['OBJECT_CONNECTIONS'], BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  489. if (!$mixedResult)
  490. return MsgBox(_t('_sys_txt_empty'));
  491. }
  492. else
  493. $mixedResult = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])->getConnectedContent($oGroupProfile->id(), true);
  494. return $mixedResult;
  495. }
  496. public function serviceFansWithoutAdmins ($iContentId = 0, $bAsArray = false)
  497. {
  498. if (!$iContentId)
  499. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  500. if (!$iContentId)
  501. return false;
  502. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  503. if (!$aContentInfo)
  504. return false;
  505. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
  506. return false;
  507. $CNF = &$this->_oConfig->CNF;
  508. $aFans = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])->getConnectedContent($oGroupProfile->id(), true);
  509. if(empty($aFans) || !is_array($aFans))
  510. return false;
  511. $aAdmins = $this->_oDb->getAdmins($oGroupProfile->id());
  512. if(!empty($aAdmins) && is_array($aAdmins))
  513. $aFans = array_diff($aFans, $aAdmins);
  514. $iStart = (int)bx_get('start');
  515. $iLimit = !empty($CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($CNF['PARAM_NUM_CONNECTIONS_QUICK']) : 4;
  516. if(!$iLimit)
  517. $iLimit = 4;
  518. return $this->_serviceBrowseQuick($aFans, $iStart, $iLimit);
  519. }
  520. public function serviceAdmins ($iContentId = 0)
  521. {
  522. $CNF = &$this->_oConfig->CNF;
  523. if(!$iContentId)
  524. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  525. if(!$iContentId)
  526. return false;
  527. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  528. if(!$oGroupProfile)
  529. return false;
  530. $iStart = (int)bx_get('start');
  531. $iLimit = !empty($CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($CNF['PARAM_NUM_CONNECTIONS_QUICK']) : 4;
  532. if(!$iLimit)
  533. $iLimit = 4;
  534. $aProfiles = $this->_oDb->getAdmins($oGroupProfile->id(), $iStart, $iLimit+1);
  535. if(empty($aProfiles) || !is_array($aProfiles))
  536. return false;
  537. return $this->_serviceBrowseQuick($aProfiles, $iStart, $iLimit);
  538. }
  539. public function serviceMembersByRole ($iContentId = 0, $iRole = BX_BASE_MOD_GROUPS_ROLE_COMMON)
  540. {
  541. $CNF = &$this->_oConfig->CNF;
  542. if(!$iContentId)
  543. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  544. if(!$iContentId)
  545. return false;
  546. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  547. if(!$oGroupProfile)
  548. return false;
  549. $iStart = (int)bx_get('start');
  550. $iLimit = !empty($CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($CNF['PARAM_NUM_CONNECTIONS_QUICK']) : 4;
  551. if(!$iLimit)
  552. $iLimit = 4;
  553. $aProfiles = $this->_oDb->getRoles([
  554. 'type' => 'fan_pids_by_group_pid',
  555. 'group_profile_id' => $oGroupProfile->id(),
  556. 'role' => $iRole,
  557. 'start' => $iStart,
  558. 'limit' => $iLimit + 1
  559. ]);
  560. if(empty($aProfiles) || !is_array($aProfiles))
  561. return false;
  562. return $this->_serviceBrowseQuick($aProfiles, $iStart, $iLimit);
  563. }
  564. public function serviceBrowseJoinedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  565. {
  566. if (!$iProfileId)
  567. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  568. if (!$iProfileId)
  569. return '';
  570. return $this->_serviceBrowse ('joined_entries', array('joined_profile' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  571. }
  572. public function serviceBrowseFollowedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  573. {
  574. if (!$iProfileId)
  575. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  576. if (!$iProfileId)
  577. return '';
  578. return $this->_serviceBrowse ('followed_entries', array('followed_profile' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  579. }
  580. public function serviceBrowseCreatedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  581. {
  582. if (!$iProfileId)
  583. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  584. if (!$iProfileId)
  585. return '';
  586. return $this->_serviceBrowse ('created_entries', array('author' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  587. }
  588. public function serviceBrowseRecommendationsFans ($iProfileId = 0, $aParams = [])
  589. {
  590. $CNF = &$this->_oConfig->CNF;
  591. if($this->_bIsApi)
  592. $aParams = bx_api_get_browse_params($aParams, true);
  593. if(!$iProfileId)
  594. $iProfileId = bx_get_logged_profile_id();
  595. if(!$iProfileId)
  596. return '';
  597. $aParams = array_merge([
  598. 'empty_message' => false,
  599. 'start' => 0,
  600. 'per_page' => 0
  601. ], $aParams);
  602. if(($iStartGet = bx_get('start')) !== false)
  603. $aParams['start'] = (int)$iStartGet;
  604. if(($iPerPageGet = bx_get('per_page')) !== false)
  605. $aParams['per_page'] = (int)$iPerPageGet;
  606. $oRecommendation = BxDolRecommendation::getObjectInstance($CNF['OBJECT_RECOMMENDATIONS_FANS']);
  607. if(!$oRecommendation)
  608. return false;
  609. if($this->_bIsApi) {
  610. $aData = $oRecommendation->getCodeAPI($iProfileId, $aParams);
  611. $aData = array_merge($aData, [
  612. 'module' => 'system',
  613. 'unit' => 'mixed',
  614. 'request_url' => '/api.php?r=bx_groups/browse_recommendations_fans&params[]=' . $iProfileId . '&params[]='
  615. ]);
  616. return [bx_api_get_block('browse', $aData)];
  617. }
  618. $sCode = $oRecommendation->getCode($iProfileId, $aParams);
  619. if(!$sCode && $aParams['empty_message'])
  620. $sCode = MsgBox(_t(!empty($aParams['empty_message_text']) ? $aParams['empty_message_text'] : '_Empty'));
  621. return $sCode;
  622. }
  623. public function serviceBrowseMembers ($iProfileId = 0, $aParams = [])
  624. {
  625. $CNF = &$this->_oConfig->CNF;
  626. if(!$iProfileId)
  627. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  628. if(!$iProfileId)
  629. return '';
  630. $oGroupProfile = BxDolProfile::getInstance($iProfileId);
  631. if(!($oGroupProfile))
  632. return '';
  633. return bx_srv('system', 'browse_members', [$oGroupProfile->id(), $CNF['OBJECT_CONNECTIONS'], $aParams], 'TemplServiceProfiles');
  634. }
  635. public function serviceEntityPricing($iProfileId = 0)
  636. {
  637. $CNF = &$this->_oConfig->CNF;
  638. if(!$iProfileId)
  639. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  640. if(!$iProfileId)
  641. return '';
  642. if(!$this->_oConfig->isPaidJoin())
  643. return '';
  644. $oPayments = BxDolPayments::getInstance();
  645. if(!$oPayments->isActive())
  646. return MsgBox(_t('_sys_payments_err_no_payments'));
  647. if($this->checkAllowedUsePaidJoin() !== CHECK_ACTION_RESULT_ALLOWED)
  648. return MsgBox(_t('_Access denied'));
  649. if($this->checkAllowedManageAdmins($iProfileId) !== CHECK_ACTION_RESULT_ALLOWED)
  650. return MsgBox(_t('_Access denied'));
  651. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_PRICES_MANAGE']);
  652. if(!$oGrid)
  653. return '';
  654. $sNote = '';
  655. if(!$oPayments->isAcceptingPayments($this->_iProfileId))
  656. $sNote = MsgBox(_t('_sys_payments_err_not_accept_payments', $oPayments->getDetailsUrl()));
  657. return $sNote . $oGrid->getCode();
  658. }
  659. public function serviceEntityJoin($iProfileId = 0)
  660. {
  661. $CNF = &$this->_oConfig->CNF;
  662. if(!$iProfileId)
  663. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  664. if(!$iProfileId)
  665. return '';
  666. if(!$this->_oConfig->isPaidJoin())
  667. return '';
  668. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_PRICES_VIEW']);
  669. if(!$oGrid)
  670. return '';
  671. return $oGrid->getCode();
  672. }
  673. public function serviceEntityInvite ($iContentId = 0, $bErrorMsg = true)
  674. {
  675. $CNF = &$this->_oConfig->CNF;
  676. if(!isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_INVITE']))
  677. return false;
  678. return $this->_serviceEntityForm ('inviteForm', $iContentId, false, false, $bErrorMsg);
  679. }
  680. /**
  681. * Entry social sharing block
  682. */
  683. public function serviceEntitySocialSharing ($mixedContent = false, $aParams = array())
  684. {
  685. if(!empty($mixedContent)) {
  686. if(!is_array($mixedContent))
  687. $mixedContent = array((int)$mixedContent, array());
  688. }
  689. else {
  690. $mixedContent = $this->_getContent();
  691. if($mixedContent === false)
  692. return false;
  693. }
  694. list($iContentId, $aContentInfo) = $mixedContent;
  695. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  696. if(!$oGroupProfile)
  697. return false;
  698. return parent::serviceEntitySocialSharing(array($iContentId, $aContentInfo), array(
  699. 'title' => $oGroupProfile->getDisplayName()
  700. ));
  701. }
  702. public function serviceIsPricingAvaliable($iProfileId)
  703. {
  704. if(!$this->_oConfig->isPaidJoin())
  705. return false;
  706. if($this->checkAllowedUsePaidJoin() !== CHECK_ACTION_RESULT_ALLOWED)
  707. return false;
  708. if($this->checkAllowedManageAdmins($iProfileId) !== CHECK_ACTION_RESULT_ALLOWED)
  709. return false;
  710. return true;
  711. }
  712. public function serviceIsPaidJoinAvaliable($iGroupProfileId, $iProfileId = 0)
  713. {
  714. return $this->isPaidJoinByProfileForProfile($iGroupProfileId, $iProfileId);
  715. }
  716. public function serviceIsPaidJoinAvaliableByContent($iGroupContentId, $iProfileId = 0)
  717. {
  718. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iGroupContentId, $this->getName());
  719. if(!$oGroupProfile)
  720. return false;
  721. return $this->isPaidJoinByProfileForProfile($oGroupProfile->id(), $iProfileId);
  722. }
  723. public function serviceIsFreeJoinAvaliable($iGroupProfileId, $iProfileId = 0)
  724. {
  725. return !$this->isPaidJoinByProfileForProfile($iGroupProfileId, $iProfileId);
  726. }
  727. public function serviceIsFreeJoinAvaliableByContent($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. /**
  735. * Is Paid Join enabled in the group and whether a profile can use it.
  736. *
  737. * @param type $iGroupProfileId - Group profile ID.
  738. * @param type $iProfileId - Profile ID of the user who wants to join.
  739. * @return boolean
  740. */
  741. public function isPaidJoinByProfileForProfile($iGroupProfileId, $iProfileId = 0)
  742. {
  743. $CNF = &$this->_oConfig->CNF;
  744. if(empty($iProfileId))
  745. $iProfileId = $this->_iProfileId;
  746. if(BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])->isConnected($iProfileId, $iGroupProfileId))
  747. return false;
  748. return $this->isPaidJoinByProfile($iGroupProfileId);
  749. }
  750. /**
  751. * Is Paid Join enabled as is and whether a group has pricing plans added.
  752. *
  753. * @param type $iGroupProfileId - Group profile ID.
  754. * @return boolean
  755. */
  756. public function isPaidJoinByProfile($iGroupProfileId)
  757. {
  758. if(!$this->_oConfig->isPaidJoin())
  759. return false;
  760. $aPrices = $this->_oDb->getPrices(array('type' => 'by_profile_id', 'profile_id' => $iGroupProfileId));
  761. if(empty($aPrices) || !is_array($aPrices))
  762. return false;
  763. return true;
  764. }
  765. /**
  766. * Integration with Payments.
  767. */
  768. public function serviceGetPaymentData()
  769. {
  770. return $this->_aModule;
  771. }
  772. public function serviceGetCartItem($mixedItemId)
  773. {
  774. $CNF = &$this->_oConfig->CNF;
  775. if(!$mixedItemId)
  776. return array();
  777. if(is_numeric($mixedItemId))
  778. $aItem = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => (int)$mixedItemId));
  779. else
  780. $aItem = $this->_oDb->getPrices(array('type' => 'by_name', 'value' => $mixedItemId));
  781. if(empty($aItem) || !is_array($aItem))
  782. return array();
  783. if(!$this->isPaidJoinByProfile($aItem['profile_id']))
  784. return array();
  785. $oGroupProfile = BxDolProfile::getInstance($aItem['profile_id']);
  786. if(!$oGroupProfile)
  787. return array();
  788. $aGroupProfile = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  789. $aRoles = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_ROLES']);
  790. $sTitle = '';
  791. if(!empty($aItem['period']) && !empty($aItem['period_unit']))
  792. $sTitle = _t($CNF['T']['txt_cart_item_title'], $oGroupProfile->getDisplayName(), $aRoles[$aItem['role_id']], $aItem['period'], $aItem['period_unit']);
  793. else
  794. $sTitle = _t($CNF['T']['txt_cart_item_title_lifetime'], $oGroupProfile->getDisplayName(), $aRoles[$aItem['role_id']]);
  795. return array (
  796. 'id' => $aItem['id'],
  797. 'author_id' => $aGroupProfile[$CNF['FIELD_AUTHOR']],
  798. 'name' => $aItem['name'],
  799. 'title' => $sTitle,
  800. 'description' => '',
  801. 'url' => $oGroupProfile->getUrl(),
  802. 'price_single' => $aItem['price'],
  803. 'price_recurring' => $aItem['price'],
  804. 'period_recurring' => $aItem['period'],
  805. 'period_unit_recurring' => $aItem['period_unit'],
  806. 'trial_recurring' => 0
  807. );
  808. }
  809. public function serviceGetCartItems($iSellerId)
  810. {
  811. $CNF = &$this->_oConfig->CNF;
  812. if(empty($iSellerId))
  813. return array();
  814. $sModule = $this->getName();
  815. $aRoles = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_ROLES']);
  816. $aGroups = $this->_oDb->getEntriesBy(array('type' => 'author', 'author' => $iSellerId));
  817. $aResult = array();
  818. foreach($aGroups as $aGroup) {
  819. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aGroup[$CNF['FIELD_ID']], $sModule);
  820. if(!$oGroupProfile)
  821. continue;
  822. $aPrices = $this->_oDb->getPrices(array('type' => 'by_profile_id', 'profile_id' => $oGroupProfile->id()));
  823. if(empty($aPrices) || !is_array($aPrices))
  824. continue;
  825. $sTitle = $oGroupProfile->getDisplayName();
  826. $sUrl = $oGroupProfile->getUrl();
  827. foreach($aPrices as $aPrice)
  828. $aResult[] = array(
  829. 'id' => $aPrice['id'],
  830. 'author_id' => $iSellerId,
  831. 'name' => $aPrice['name'],
  832. 'title' => _t($CNF['T']['txt_cart_item_title'], $sTitle, $aRoles[$aPrice['role_id']], $aPrice['period'], $aPrice['period_unit']),
  833. 'description' => '',
  834. 'url' => $sUrl,
  835. 'price_single' => $aPrice['price'],
  836. 'price_recurring' => $aPrice['price'],
  837. 'period_recurring' => $aPrice['period'],
  838. 'period_unit_recurring' => $aPrice['period_unit']
  839. );
  840. }
  841. return $aResult;
  842. }
  843. public function serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  844. {
  845. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  846. }
  847. public function serviceRegisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  848. {
  849. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  850. }
  851. public function serviceReregisterCartItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  852. {
  853. return $this->_serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder);
  854. }
  855. public function serviceReregisterSubscriptionItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  856. {
  857. return $this->_serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder);
  858. }
  859. public function serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  860. {
  861. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  862. }
  863. public function serviceUnregisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  864. {
  865. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  866. }
  867. public function serviceCancelSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  868. {
  869. return true;
  870. }
  871. protected function _serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  872. {
  873. $CNF = &$this->_oConfig->CNF;
  874. $aItem = $this->serviceGetCartItem($iItemId);
  875. if(empty($aItem) || !is_array($aItem))
  876. return array();
  877. $aItemInfo = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemId));
  878. $mixedPeriod = false;
  879. if((int)$aItemInfo['period'] != 0)
  880. $mixedPeriod = array(
  881. 'period' => (int)$aItemInfo['period'],
  882. 'period_unit' => $aItemInfo['period_unit'],
  883. 'period_reserve' => $CNF['PARAM_RECURRING_RESERVE']
  884. );
  885. if(!$this->setRole($aItemInfo['profile_id'], $iClientId, $aItemInfo['role_id'], $mixedPeriod, $sOrder))
  886. return array();
  887. return $aItem;
  888. }
  889. protected function _serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  890. {
  891. $aItem = $this->serviceGetCartItem($iItemIdNew);
  892. if(empty($aItem) || !is_array($aItem))
  893. return array();
  894. $aItemInfoOld = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemIdOld));
  895. if(empty($aItemInfoOld) || !is_array($aItemInfoOld))
  896. return array();
  897. $aItemInfoNew = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemIdNew));
  898. if(empty($aItemInfoNew) || !is_array($aItemInfoNew))
  899. return array();
  900. if(!$this->unsetRole($aItemInfoOld['profile_id'], $iClientId))
  901. return array();
  902. $aResult = $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemIdNew, 1, $sOrder);
  903. if(empty($aResult) || !is_array($aResult))
  904. return array();
  905. return $aItem;
  906. }
  907. protected function _serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  908. {
  909. $aItemInfo = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemId));
  910. if(empty($aItemInfo) || !is_array($aItemInfo))
  911. return false;
  912. return $this->unsetRole($aItemInfo['profile_id'], $iClientId);
  913. }
  914. public function serviceGetQuestionnaire($sSource, $sObject, $sAction, $iContentProfileId)
  915. {
  916. $CNF = &$this->_oConfig->CNF;
  917. $sMsg = _t('_sys_txt_not_found');
  918. $aContentInfo = $this->_oDb->getContentInfoByProfileId($iContentProfileId);
  919. if(empty($aContentInfo) || !is_array($aContentInfo))
  920. return $this->_bIsApi ? [bx_api_get_msg($sMsg)] : ['code' => 1, 'msg' => $sMsg];
  921. $oForm = null;
  922. if(($oConnection = BxDolConnection::getObjectInstance($sObject)) !== false) {
  923. $oForm = $oConnection->getQuestionnaireForm($sAction, $iContentProfileId, ['request' => [
  924. 's' => $sSource,
  925. ]]);
  926. if($oForm === false)
  927. return $this->_bIsApi ? [bx_api_get_msg($sMsg)] : ['code' => 3, 'msg' => $sMsg];
  928. }
  929. else
  930. return $this->_bIsApi ? [bx_api_get_msg($sMsg)] : ['code' => 2, 'msg' => $sMsg];
  931. $oForm->initChecker();
  932. if($oForm->isSubmittedAndValid()) {
  933. $iProfileId = bx_get_logged_profile_id();
  934. $aQuestions = $this->_oDb->getQuestions(['sample' => 'content_pid', 'content_pid' => $iContentProfileId]);
  935. foreach($aQuestions as $aQuestion)
  936. $this->_oDb->insertAnswer((int)$aQuestion['id'], $iProfileId, $oForm->getCleanValue('question_' . $aQuestion['id']));
  937. return $this->_bIsApi ? [] : ['code' => 0, 'o' => $sObject, 'a' => $sAction, 'cpi' => $iContentProfileId, 'ci' => $aContentInfo[$CNF['FIELD_ID']], 'eval' => $this->_oConfig->getJsObject($sSource) . '.connActionPerformed(oData)'];
  938. }
  939. if($this->_bIsApi)
  940. return [bx_api_get_block('form', $oForm->getCodeAPI(), ['ext' => [
  941. 'name' => $this->_oModule->getName(),
  942. 'request' => ['url' => $oForm->aFormAttrs['action'], 'immutable' => true]]
  943. ])];
  944. bx_import('BxTemplFunctions');
  945. $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oConfig->getHtmlIds('popup_questionnaire'), _t($CNF['T']['popup_title_questionnaire']), $this->_oTemplate->parseHtmlByName('popup_qnr_questionnaire.html', [
  946. 'form_id' => $oForm->getId(),
  947. 'form' => $oForm->getCode(true),
  948. ]));
  949. return ['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => false]]];
  950. }
  951. /**
  952. * Data for Notifications module
  953. */
  954. public function serviceGetNotificationsData()
  955. {
  956. $sModule = $this->_aModule['name'];
  957. $aSettingsTypes = ['follow_member', 'follow_context'];
  958. if($this->serviceActAsProfile())
  959. $aSettingsTypes = ['personal', 'follow_member'];
  960. return [
  961. 'handlers' => [
  962. ['group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'],
  963. ['group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'],
  964. ['group' => $sModule . '_score_up', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteUp', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_up', 'module_class' => 'Module'],
  965. ['group' => $sModule . '_score_down', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteDown', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_down', 'module_class' => 'Module'],
  966. ['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'],
  967. ['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'],
  968. ['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']],
  969. ['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'],
  970. //--- Moderation related: For 'admins'.
  971. ['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'],
  972. ],
  973. 'settings' => [
  974. ['group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => $aSettingsTypes],
  975. ['group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => $aSettingsTypes],
  976. ['group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => $aSettingsTypes],
  977. ['group' => 'fan', 'unit' => $sModule, 'action' => 'fan_added', 'types' => $aSettingsTypes],
  978. ['group' => 'invite', 'unit' => $sModule, 'action' => 'join_invitation_notif', 'types' => ['personal']],
  979. ['group' => 'join', 'unit' => $sModule, 'action' => 'join_request', 'types' => $aSettingsTypes],
  980. ['group' => 'timeline_post', 'unit' => $sModule, 'action' => 'timeline_post_common', 'types' => $aSettingsTypes],
  981. //--- Moderation related: For 'admins'.
  982. ['group' => 'action_required', 'unit' => $sModule, 'action' => 'pending_approval', 'types' => ['personal']],
  983. ],
  984. 'alerts' => [
  985. ['unit' => $sModule, 'action' => 'doVote'],
  986. ['unit' => $sModule, 'action' => 'undoVote'],
  987. ['unit' => $sModule, 'action' => 'doVoteUp'],
  988. ['unit' => $sModule, 'action' => 'doVoteDown'],
  989. ['unit' => $sModule, 'action' => 'fan_added'],
  990. ['unit' => $sModule, 'action' => 'join_invitation_notif'],
  991. ['unit' => $sModule, 'action' => 'join_request'],
  992. ['unit' => $sModule, 'action' => 'timeline_post_common'],
  993. //--- Moderation related: For 'admins'.
  994. ['unit' => $sModule, 'action' => 'pending_approval'],
  995. ]
  996. ];
  997. }
  998. public function serviceGetNotificationsInsertData($oAlert, $aHandler, $aDataItems)
  999. {
  1000. if($oAlert->sAction != 'join_invitation_notif' || empty($aDataItems) || !is_array($aDataItems))
  1001. return $aDataItems;
  1002. foreach($aDataItems as $iIndex => $aDataItem)
  1003. $aDataItems[$iIndex]['object_privacy_view'] = BX_DOL_PG_ALL;
  1004. return $aDataItems;
  1005. }
  1006. /**
  1007. * Notification about new invitation to join the group
  1008. */
  1009. public function serviceGetNotificationsJoinInvitation($aEvent)
  1010. {
  1011. $CNF = &$this->_oConfig->CNF;
  1012. $iContentId = (int)$aEvent['object_id'];
  1013. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  1014. if(!$oGroupProfile)
  1015. return array();
  1016. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1017. if(empty($aContentInfo) || !is_array($aContentInfo))
  1018. return array();
  1019. /*
  1020. * It's essential that 'object_owner_id' contains invited member profile id.
  1021. */
  1022. $oProfile = BxDolProfile::getInstance((int)$aEvent['object_owner_id']);
  1023. if(!$oProfile)
  1024. return array();
  1025. /*
  1026. * Note. Group Profile URL is used for both Entry and Subentry URLs,
  1027. * because Subentry URL has higher display priority and notification
  1028. * should be linked to Group Profile (Group Profile -> Members tab)
  1029. * instead of Personal Profile of invited member.
  1030. */
  1031. $sEntryUrl = bx_absolute_url(str_replace(BX_DOL_URL_ROOT, '', $oGroupProfile->getUrl()), '{bx_url_root}');
  1032. return array(
  1033. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1034. 'entry_url' => $sEntryUrl,
  1035. 'entry_caption' => $oGroupProfile->getDisplayName(),
  1036. 'subentry_sample' => $oProfile->getDisplayName(),
  1037. 'subentry_url' => $sEntryUrl,
  1038. 'lang_key' => $this->_oConfig->CNF['T']['txt_ntfs_join_invitation']
  1039. );
  1040. }
  1041. /**
  1042. * Notification about new member requst in the group
  1043. */
  1044. public function serviceGetNotificationsJoinRequest($aEvent)
  1045. {
  1046. return $this->_serviceGetNotification($aEvent, $this->_oConfig->CNF['T']['txt_ntfs_join_request']);
  1047. }
  1048. /**
  1049. * Notification about new member in the group
  1050. */
  1051. public function serviceGetNotificationsFanAdded($aEvent)
  1052. {
  1053. return $this->_serviceGetNotification($aEvent, $this->_oConfig->CNF['T']['txt_ntfs_fan_added']);
  1054. }
  1055. protected function _serviceGetNotification($aEvent, $sLangKey)
  1056. {
  1057. $CNF = &$this->_oConfig->CNF;
  1058. $iContentId = (int)$aEvent['object_id'];
  1059. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  1060. if(!$oGroupProfile)
  1061. return array();
  1062. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1063. if(empty($aContentInfo) || !is_array($aContentInfo))
  1064. return array();
  1065. $oProfile = BxDolProfile::getInstance((int)$aEvent['subobject_id']);
  1066. if(!$oProfile)
  1067. return array();
  1068. /*
  1069. * Note. Group Profile URL is used for both Entry and Subentry URLs,
  1070. * because Subentry URL has higher display priority and notification
  1071. * should be linked to Group Profile (Group Profile -> Members tab)
  1072. * instead of Personal Profile of a member, who performed an action.
  1073. */
  1074. if(empty($CNF['URL_ENTRY_FANS']))
  1075. $sEntryUrl = bx_absolute_url(str_replace(BX_DOL_URL_ROOT, '', $oGroupProfile->getUrl()), '{bx_url_root}');
  1076. else
  1077. $sEntryUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_ENTRY_FANS'], [
  1078. 'profile_id' => $oGroupProfile->id()
  1079. ]);
  1080. return [
  1081. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1082. 'entry_url' => $sEntryUrl,
  1083. 'entry_caption' => $oGroupProfile->getDisplayName(),
  1084. 'entry_author' => $oGroupProfile->id(),
  1085. 'subentry_sample' => $oProfile->getDisplayName(),
  1086. 'subentry_url' => $sEntryUrl,
  1087. 'lang_key' => $sLangKey
  1088. ];
  1089. }
  1090. /**
  1091. * Data for Timeline module
  1092. */
  1093. public function serviceGetTimelineData()
  1094. {
  1095. $aResult = BxBaseModGeneralModule::serviceGetTimelineData();
  1096. $sModule = $this->_aModule['name'];
  1097. $aResult['handlers'] = array_merge($aResult['handlers'], [
  1098. ['group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'context_cover_changed'],
  1099. ['group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'context_cover_deleted']
  1100. ]);
  1101. $aResult['alerts'] = array_merge($aResult['alerts'], [
  1102. ['unit' => $sModule, 'action' => 'context_cover_changed'],
  1103. ['unit' => $sModule, 'action' => 'context_cover_deleted']
  1104. ]);
  1105. return $aResult;
  1106. }
  1107. /**
  1108. * Entry post for Timeline module
  1109. */
  1110. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  1111. {
  1112. $CNF = &$this->_oConfig->CNF;
  1113. $a = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  1114. if($a === false)
  1115. return false;
  1116. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aEvent['object_id'], $this->getName());
  1117. $a['content']['url'] = $oGroupProfile->getUrl();
  1118. $a['content']['title'] = $oGroupProfile->getDisplayName();
  1119. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  1120. if($oConnection)
  1121. $a['content']['members'] = $oConnection->getConnectedInitiatorsCount($oGroupProfile->id(), true);
  1122. $a['content']['visibility'] = $aEvent['object_privacy_view'];
  1123. if(isset($CNF['FIELD_PUBLISHED'])) {
  1124. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  1125. if($aContentInfo[$CNF['FIELD_PUBLISHED']] > $a['date'])
  1126. $a['date'] = $aContentInfo[$CNF['FIELD_PUBLISHED']];
  1127. }
  1128. return $a;
  1129. }
  1130. // ====== PERMISSION METHODS
  1131. /**
  1132. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1133. */
  1134. public function checkAllowedUsePaidJoin($isPerformAction = false)
  1135. {
  1136. // check ACL
  1137. $aCheck = checkActionModule($this->_iProfileId, 'use paid join', $this->getName(), $isPerformAction);
  1138. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1139. return $aCheck[CHECK_ACTION_MESSAGE];
  1140. return CHECK_ACTION_RESULT_ALLOWED;
  1141. }
  1142. /**
  1143. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1144. */
  1145. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  1146. {
  1147. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  1148. }
  1149. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1150. {
  1151. $CNF = &$this->_oConfig->CNF;
  1152. $iGroupContentId = (int)$aDataEntry[$CNF['FIELD_ID']];
  1153. $bInvited = false;
  1154. if(!empty($CNF['TABLE_INVITES'])) {
  1155. $iGroupProfileId = BxDolProfile::getInstanceByContentAndType($iGroupContentId, $this->getName())->id();
  1156. if(($sKey = bx_get('key')) !== false) {
  1157. $mixedInvited = $this->isInvited($sKey, $iGroupProfileId);
  1158. if($mixedInvited === true)
  1159. $bInvited = true;
  1160. }
  1161. else {
  1162. $mixedInvited = $this->isInvitedByProfileId($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $iGroupProfileId);
  1163. if($mixedInvited === true)
  1164. $bInvited = true;
  1165. }
  1166. }
  1167. if ($this->isFan($iGroupContentId, $iProfileId) || $bInvited)
  1168. return CHECK_ACTION_RESULT_ALLOWED;
  1169. return parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  1170. }
  1171. /**
  1172. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1173. */
  1174. public function checkAllowedCompose(&$aDataEntry, $isPerformAction = false)
  1175. {
  1176. if(!$this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]))
  1177. return _t('_sys_txt_access_denied');
  1178. return parent::checkAllowedCompose ($aDataEntry, $isPerformAction);
  1179. }
  1180. /**
  1181. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1182. */
  1183. public function checkAllowedFanAdd(&$aDataEntry, $isPerformAction = false)
  1184. {
  1185. $mixedResult = $this->_modGroupsCheckAllowedFanAdd($aDataEntry, $isPerformAction);
  1186. // call alert to allow custom checks
  1187. bx_alert('system', 'check_allowed_fan_add', 0, 0, array(
  1188. 'module' => $this->getName(),
  1189. 'content_info' => $aDataEntry,
  1190. 'profile_id' => bx_get_logged_profile_id(),
  1191. 'override_result' => &$mixedResult
  1192. ));
  1193. return $mixedResult;
  1194. }
  1195. public function _modGroupsCheckAllowedFanAdd (&$aDataEntry, $isPerformAction = false)
  1196. {
  1197. if ($this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]) || !isLogged())
  1198. return _t('_sys_txt_access_denied');
  1199. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], true, false);
  1200. }
  1201. /**
  1202. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1203. */
  1204. public function checkAllowedFanRemove (&$aDataEntry, $isPerformAction = false)
  1205. {
  1206. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, true))
  1207. return CHECK_ACTION_RESULT_ALLOWED;
  1208. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, false);
  1209. }
  1210. protected function _checkAllowedActionByFan($sAction, $aDataEntry, $iProfileId = 0)
  1211. {
  1212. $CNF = &$this->_oConfig->CNF;
  1213. $bRoles = $this->_oConfig->isRoles();
  1214. if(empty($iProfileId))
  1215. $iProfileId = bx_get_logged_profile_id();
  1216. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  1217. if(!$oGroupProfile)
  1218. return $sAction == BX_BASE_MOD_GROUPS_ACTION_DELETE ? CHECK_ACTION_RESULT_ALLOWED : _t('_sys_txt_not_found');
  1219. $iGroupProfileId = $oGroupProfile->id();
  1220. if(!$bRoles && $this->_oDb->isAdmin($iGroupProfileId, $iProfileId, $aDataEntry))
  1221. return CHECK_ACTION_RESULT_ALLOWED;
  1222. if($bRoles && $this->isAllowedActionByRole($sAction, $aDataEntry, $iGroupProfileId, $iProfileId))
  1223. return CHECK_ACTION_RESULT_ALLOWED;
  1224. return _t('_sys_txt_access_denied');
  1225. }
  1226. public function isAllowedActionByRole($mAction, $aDataEntry, $iGroupProfileId, $iProfileId)
  1227. {
  1228. $iProfileRole = $this->_oDb->getRole($iGroupProfileId, $iProfileId);
  1229. if (is_array($mAction)) {
  1230. $sAction = $mAction['action'];
  1231. $sActionModule = $mAction['module'];
  1232. } else {
  1233. $sAction = $mAction;
  1234. $sActionModule = $this->getName();
  1235. }
  1236. $bResult = false;
  1237. if($iProfileId)
  1238. $bResult = $this->isAllowedModuleActionByRole($sActionModule, $sAction, $iProfileRole);
  1239. // in case neither of the profile's roles are having permissions set explicitly then fallback to an old way
  1240. if ($bResult === NULL) {
  1241. $bResult = false;
  1242. if($this->isFanByGroupProfileId($iGroupProfileId)) {
  1243. switch ($sAction) {
  1244. case BX_BASE_MOD_GROUPS_ACTION_DELETE:
  1245. case BX_BASE_MOD_GROUPS_ACTION_EDIT:
  1246. case BX_BASE_MOD_GROUPS_ACTION_CHANGE_COVER:
  1247. case BX_BASE_MOD_GROUPS_ACTION_MANAGE_ROLES:
  1248. if($this->isRole($iProfileRole, BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR))
  1249. $bResult = true;
  1250. break;
  1251. case BX_BASE_MOD_GROUPS_ACTION_MANAGE_FANS:
  1252. case BX_BASE_MOD_GROUPS_ACTION_INVITE:
  1253. case BX_BASE_MOD_GROUPS_ACTION_EDIT_CONTENT:
  1254. case BX_BASE_MOD_GROUPS_ACTION_DELETE_CONTENT:
  1255. case BX_BASE_MOD_GROUPS_ACTION_TIMELINE_POST_PIN:
  1256. if($this->isRole($iProfileRole, BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR) || $this->isRole($iProfileRole, BX_BASE_MOD_GROUPS_ROLE_MODERATOR))
  1257. $bResult = true;
  1258. break;
  1259. default:
  1260. $bResult = true;
  1261. }
  1262. }
  1263. }
  1264. // call alert to allow custom checks
  1265. bx_alert('system', 'check_allowed_action_by_role', 0, 0, [
  1266. 'module' => $this->getName(),
  1267. 'multi_roles' => $this->_oConfig->isMultiRoles(),
  1268. 'action' => $sAction,
  1269. 'action_module' => $sActionModule,
  1270. 'content_profile_id' => $iGroupProfileId,
  1271. 'content_info' => $aDataEntry,
  1272. 'profile_id' => $iProfileId,
  1273. 'profile_role' => $iProfileRole,
  1274. 'override_result' => &$bResult
  1275. ]);
  1276. return $bResult;
  1277. }
  1278. public function isAllowedModuleActionByRole($sModule, $sAction, $iProfileRole)
  1279. {
  1280. static $aRoles;
  1281. if (!$aRoles && isset($this->_oConfig->CNF['OBJECT_PRE_LIST_ROLES']) && !empty($this->_oConfig->CNF['OBJECT_PRE_LIST_ROLES']))
  1282. $aRoles = BxBaseFormView::getDataItems($this->_oConfig->CNF['OBJECT_PRE_LIST_ROLES'], true, BX_DATA_VALUES_ALL);
  1283. if ($aRoles) {
  1284. foreach ($aRoles as $iRole => $aRoleData) {
  1285. if ($iRole == 0 && $iProfileRole == 0 || $iRole > 0 && $this->isRole($iProfileRole, $iRole)) {
  1286. $mPermissions = isset($aRoles[$iRole]) && isset($aRoles[$iRole]['Data']) && !empty($aRoles[$iRole]['Data']) ? unserialize($aRoles[$iRole]['Data']) : false;
  1287. if ($mPermissions && isset($mPermissions[$sModule])) {
  1288. return isset($mPermissions[$sModule][$sAction]) && $mPermissions[$sModule][$sAction];
  1289. }
  1290. }
  1291. }
  1292. }
  1293. return NULL;
  1294. }
  1295. public function isAllowedModuleActionByProfile($iContentId, $sPostModule, $sAction, $iProfileId = 0) {
  1296. if (!$iProfileId) $iProfileId = bx_get_logged_profile_id();
  1297. if ($iProfileId && $this->isFan($iContentId, $iProfileId)) {
  1298. $sModuleName = $this->getName();
  1299. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModuleName);
  1300. $aDataEntry = $this->_oDb->getContentInfoById($iContentId);
  1301. $bResult = $this->isAllowedActionByRole(['action' => $sAction, 'module' => $sPostModule], $aDataEntry, $oGroupProfile->id(), $iProfileId);
  1302. if ($bResult === true) return CHECK_ACTION_RESULT_ALLOWED;
  1303. if ($bResult === false) return _t('_sys_txt_access_denied');
  1304. }
  1305. 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.
  1306. }
  1307. public function isRole($iProfileRole, $iRole)
  1308. {
  1309. if(!$this->_oConfig->isMultiRoles())
  1310. return $iProfileRole == $iRole;
  1311. else
  1312. return $iProfileRole & (1 << ($iRole - 1));
  1313. }
  1314. public function serviceIsRole($iProfileRole, $iRole)
  1315. {
  1316. return $this->isRole($iProfileRole, $iRole);
  1317. }
  1318. public function checkAllowedManageFans($mixedDataEntry, $isPerformAction = false)
  1319. {
  1320. $aDataEntry = array();
  1321. if(!is_array($mixedDataEntry)) {
  1322. $oGroupProfile = BxDolProfile::getInstance((int)$mixedDataEntry);
  1323. if($oGroupProfile && $this->getName() == $oGroupProfile->getModule())
  1324. $aDataEntry = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  1325. }
  1326. else
  1327. $aDataEntry = $mixedDataEntry;
  1328. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_MANAGE_FANS, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1329. return CHECK_ACTION_RESULT_ALLOWED;
  1330. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  1331. }
  1332. public function checkAllowedManageAdmins($mixedDataEntry, $isPerformAction = false)
  1333. {
  1334. $aDataEntry = array();
  1335. if(!is_array($mixedDataEntry)) {
  1336. $oGroupProfile = BxDolProfile::getInstance((int)$mixedDataEntry);
  1337. if($oGroupProfile && $this->getName() == $oGroupProfile->getModule())
  1338. $aDataEntry = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  1339. }
  1340. else
  1341. $aDataEntry = $mixedDataEntry;
  1342. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_MANAGE_ROLES, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1343. return CHECK_ACTION_RESULT_ALLOWED;
  1344. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  1345. }
  1346. public function checkAllowedEdit($aDataEntry, $isPerformAction = false)
  1347. {
  1348. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_EDIT, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1349. return CHECK_ACTION_RESULT_ALLOWED;
  1350. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  1351. }
  1352. public function checkAllowedInvite($aDataEntry, $isPerformAction = false)
  1353. {
  1354. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_INVITE, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1355. return CHECK_ACTION_RESULT_ALLOWED;
  1356. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  1357. }
  1358. public function checkAllowedChangeCover($aDataEntry, $isPerformAction = false)
  1359. {
  1360. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_CHANGE_COVER, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1361. return CHECK_ACTION_RESULT_ALLOWED;
  1362. return parent::checkAllowedChangeCover($aDataEntry, $isPerformAction);
  1363. }
  1364. public function checkAllowedDelete(&$aDataEntry, $isPerformAction = false)
  1365. {
  1366. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_DELETE, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1367. return CHECK_ACTION_RESULT_ALLOWED;
  1368. return parent::checkAllowedDelete($aDataEntry, $isPerformAction);
  1369. }
  1370. public function checkAllowedJoin(&$aDataEntry, $isPerformAction = false)
  1371. {
  1372. if (bx_get('key')){
  1373. $sKey = bx_get('key');
  1374. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  1375. $aData = $this->_oDb->getInviteByKey($sKey, $oGroupProfile->id());
  1376. if (isset($aData['invited_profile_id']) && $aData['invited_profile_id'] == bx_get_logged_profile_id()){
  1377. return CHECK_ACTION_RESULT_ALLOWED;
  1378. }
  1379. }
  1380. return _t('_sys_txt_access_denied');
  1381. }
  1382. public function checkAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1383. {
  1384. $mixedResult = $this->_modGroupsCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  1385. // call alert to allow custom checks
  1386. bx_alert('system', 'check_allowed_subscribe_add', 0, 0, array(
  1387. 'module' => $this->getName(),
  1388. 'content_info' => $aDataEntry,
  1389. 'profile_id' => bx_get_logged_profile_id(),
  1390. 'override_result' => &$mixedResult
  1391. ));
  1392. return $mixedResult;
  1393. }
  1394. /**
  1395. * Note. Is mainly needed for internal usage. Access level is 'public' to allow outer calls from alerts.
  1396. */
  1397. public function _modGroupsCheckAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1398. {
  1399. $CNF = &$this->_oConfig->CNF;
  1400. if(!$this->isFan($aDataEntry[$CNF['FIELD_ID']]) && (!isset($CNF['PARAM_SBS_WO_JOIN']) || getParam($CNF['PARAM_SBS_WO_JOIN']) != 'on'))
  1401. return _t('_sys_txt_access_denied');
  1402. return parent::_modProfileCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  1403. }
  1404. /**
  1405. * @deprecated since version 11.0.3 and can be removed in the next version.
  1406. */
  1407. public function _checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  1408. {
  1409. return parent::checkAllowedSubscribeAdd ($aDataEntry, $isPerformAction);
  1410. }
  1411. public function doAudit($iGroupProfileId, $iFanId, $sAction)
  1412. {
  1413. $oProfile = BxDolProfile::getInstance($iFanId);
  1414. $iContentId = $oProfile->getContentId();
  1415. $sModule = $oProfile->getModule();
  1416. $oModule = BxDolModule::getInstance($sModule);
  1417. if (BxDolRequest::serviceExists($sModule, 'act_as_profile') && BxDolService::call($sModule, 'act_as_profile') && $oModule->_oConfig){
  1418. $CNF = $oModule->_oConfig->CNF;
  1419. $aContentInfo = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $iContentId))) : array();
  1420. $AuditParams = array(
  1421. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  1422. 'context_profile_id' => $iGroupProfileId,
  1423. 'context_profile_title' => BxDolProfile::getInstance($iGroupProfileId)->getDisplayName()
  1424. );
  1425. bx_audit(
  1426. $iContentId,
  1427. $sModule,
  1428. $sAction,
  1429. $AuditParams
  1430. );
  1431. }
  1432. }
  1433. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  1434. {
  1435. $sResult = $this->checkAllowedView($aDataEntry);
  1436. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  1437. // if profile view isn't allowed but visibility is in partially visible groups
  1438. // then display buttons to connect (befriend, join) to profile,
  1439. // if other conditions (in parent::_checkAllowedConnect) are met as well
  1440. if (CHECK_ACTION_RESULT_ALLOWED !== $sResult && !in_array($aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']], array_merge($oPrivacy->getPartiallyVisiblePrivacyGroups(), array('s'))))
  1441. return $sResult;
  1442. return parent::_checkAllowedConnect ($aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap);
  1443. }
  1444. // ====== COMMON METHODS
  1445. public function onUpdateImage($iContentId, $sFiledName, $sFiledValue, $iProfileId = 0)
  1446. {
  1447. $CNF = &$this->_oConfig->CNF;
  1448. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1449. $aField2Method = [
  1450. $CNF['FIELD_PICTURE'] => 'picture',
  1451. $CNF['FIELD_COVER'] => 'cover',
  1452. ];
  1453. if(!empty($aField2Method[$sFiledName]))
  1454. bx_alert($this->getName(), 'context_' . $aField2Method[$sFiledName] . '_changed', $iContentId, $iProfileId, $this->_alertParams($aContentInfo));
  1455. }
  1456. protected function _alertParams($aContentInfo)
  1457. {
  1458. $aParams = parent::_alertParams($aContentInfo);
  1459. $CNF = &$this->_oConfig->CNF;
  1460. if(!empty($CNF['FIELD_CF']) && isset($aContentInfo[$CNF['FIELD_CF']]))
  1461. $aParams['cf'] = $aContentInfo[$CNF['FIELD_CF']];
  1462. return $aParams;
  1463. }
  1464. public function alertAfterAdd($aContentInfo)
  1465. {
  1466. $CNF = &$this->_oConfig->CNF;
  1467. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1468. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  1469. $sAction = 'added';
  1470. if(isset($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == BX_BASE_MOD_GENERAL_STATUS_PENDING)
  1471. $sAction = 'deferred';
  1472. $sModule = $this->getName();
  1473. $aParams = $this->_alertParams($aContentInfo);
  1474. bx_alert('system', 'prepare_alert_params', 0, 0, [
  1475. 'unit'=> $sModule,
  1476. 'action' => &$sAction,
  1477. 'object_id' => &$iId,
  1478. 'sender_id' => &$iAuthorId,
  1479. 'extras' => &$aParams
  1480. ]);
  1481. bx_alert($sModule, $sAction, $iId, false, $aParams);
  1482. $this->_processModerationNotifications($aContentInfo);
  1483. }
  1484. public function addFollower ($iProfileId1, $iProfileId2)
  1485. {
  1486. $oConnectionFollow = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  1487. if($oConnectionFollow && !$oConnectionFollow->isConnected($iProfileId1, $iProfileId2)){
  1488. $oConnectionFollow->addConnection($iProfileId1, $iProfileId2);
  1489. return true;
  1490. }
  1491. return false;
  1492. }
  1493. public function isFan ($iContentId, $iProfileId = false)
  1494. {
  1495. $CNF = &$this->_oConfig->CNF;
  1496. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  1497. if($oGroupProfile && isset($CNF['OBJECT_CONNECTIONS']))
  1498. return ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $oGroupProfile->id(), true);
  1499. return false;
  1500. }
  1501. public function isFanByGroupProfileId ($iGroupProfileId, $iProfileId = false)
  1502. {
  1503. $CNF = &$this->_oConfig->CNF;
  1504. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1505. if($oGroupProfile && isset($CNF['OBJECT_CONNECTIONS']))
  1506. return ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $oGroupProfile->id(), true);
  1507. return false;
  1508. }
  1509. public function isInvited ($sKey, $iGroupProfileId)
  1510. {
  1511. $CNF = &$this->_oConfig->CNF;
  1512. $aData = $this->_oDb->getInviteByKey($sKey, $iGroupProfileId);
  1513. if (!isset($aData['invited_profile_id']))
  1514. return _t($CNF['T']['txt_invitation_popup_error_invitation_absent']);
  1515. if ($aData['invited_profile_id'] != bx_get_logged_profile_id())
  1516. return _t($CNF['T']['txt_invitation_popup_error_wrong_user']);
  1517. return true;
  1518. }
  1519. public function isInvitedByProfileId ($iProfileId, $iGroupProfileId)
  1520. {
  1521. $CNF = &$this->_oConfig->CNF;
  1522. $aData = $this->_oDb->getInviteByInvited($iProfileId, $iGroupProfileId);
  1523. if (!isset($aData['invited_profile_id']))
  1524. return _t($CNF['T']['txt_invitation_popup_error_invitation_absent']);
  1525. if ($aData['invited_profile_id'] != bx_get_logged_profile_id())
  1526. return _t($CNF['T']['txt_invitation_popup_error_wrong_user']);
  1527. return true;
  1528. }
  1529. public function serviceIsInvited($iGroupProfileId, $iProfileId = false, $sKey = '')
  1530. {
  1531. if(!$iProfileId)
  1532. $iProfileId = bx_get_logged_profile_id();
  1533. if(empty($sKey) && ($sKey = bx_get('key')) !== false)
  1534. $sKey = bx_process_input($sKey);
  1535. $mixedInvited = false;
  1536. if(!empty($sKey))
  1537. $mixedInvited = $this->isInvited($sKey, $iGroupProfileId);
  1538. else if($iProfileId !== false)
  1539. $mixedInvited = $this->isInvitedByProfileId($iProfileId, $iGroupProfileId);
  1540. return $mixedInvited === true;
  1541. }
  1542. public function serviceIsNotInvited($iGroupProfileId, $iProfileId = false, $sKey = '')
  1543. {
  1544. return !$this->serviceIsInvited($iGroupProfileId, $iProfileId, $sKey);
  1545. }
  1546. public function serviceGetInvitedKey($iGroupProfileId, $iProfileId = false)
  1547. {
  1548. $sKey = '';
  1549. if(($sKey = bx_get('key')) !== false)
  1550. $sKey = bx_process_input($sKey);
  1551. if(!$sKey) {
  1552. if(!$iProfileId)
  1553. $iProfileId = bx_get_logged_profile_id();
  1554. if($iProfileId !== false) {
  1555. $aInvite = $this->_oDb->getInviteByInvited($iProfileId, $iGroupProfileId);
  1556. if(!empty($aInvite) && is_array($aInvite))
  1557. $sKey = $aInvite['key'];
  1558. }
  1559. }
  1560. return $sKey;
  1561. }
  1562. public function getRole($iGroupProfileId, $iFanProfileId)
  1563. {
  1564. if(!$this->isFanByGroupProfileId($iGroupProfileId, $iFanProfileId))
  1565. return false;
  1566. return $this->_oDb->getRole($iGroupProfileId, $iFanProfileId);
  1567. }
  1568. public function setRole($iGroupProfileId, $iFanProfileId, $mixedRole, $mixedPeriod = false, $sOrder = '')
  1569. {
  1570. $CNF = &$this->_oConfig->CNF;
  1571. if(!isset($CNF['OBJECT_CONNECTIONS']))
  1572. return false;
  1573. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  1574. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1575. if(!$oConnection || !$oGroupProfile)
  1576. return false;
  1577. if(!$oConnection->isConnected($iFanProfileId, $iGroupProfileId, true) && !$oConnection->addConnection($iFanProfileId, $iGroupProfileId))
  1578. return false;
  1579. if(!$this->_oDb->setRole($iGroupProfileId, $iFanProfileId, $mixedRole, $mixedPeriod, $sOrder))
  1580. return false;
  1581. $this->onSetRole($iGroupProfileId, $iFanProfileId, $mixedRole);
  1582. return true;
  1583. }
  1584. public function onSetRole($iGroupProfileId, $iFanProfileId, $mixedRole)
  1585. {
  1586. $CNF = &$this->_oConfig->CNF;
  1587. $iProfileId = bx_get_logged_profile_id();
  1588. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1589. $aGroupProfileInfo = $this->_oDb->getContentInfoById((int)$oGroupProfile->getContentId());
  1590. $aRoles = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_ROLES']);
  1591. // notify about admin status
  1592. if(!empty($CNF['EMAIL_FAN_SET_ROLE']) && $iFanProfileId != $iProfileId) {
  1593. $aSetRoles = is_array($mixedRole) ? $mixedRole : [$mixedRole];
  1594. $aRolesNames = [];
  1595. foreach ($aSetRoles as $iRole)
  1596. $aRolesNames[] = $aRoles[(int)$iRole];
  1597. sendMailTemplate($CNF['EMAIL_FAN_SET_ROLE'], 0, $iFanProfileId, array(
  1598. 'EntryUrl' => $oGroupProfile->getUrl(),
  1599. 'EntryTitle' => $oGroupProfile->getDisplayName(),
  1600. 'Role' => implode(', ', $aRolesNames),
  1601. ), BX_EMAIL_NOTIFY);
  1602. }
  1603. bx_alert($this->getName(), 'set_role', $aGroupProfileInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  1604. 'object_author_id' => $iGroupProfileId,
  1605. 'performer_id' => $iProfileId,
  1606. 'fan_id' => $iFanProfileId,
  1607. 'content' => $aGroupProfileInfo,
  1608. 'role' => $mixedRole,
  1609. 'group_profile' => $iGroupProfileId,
  1610. 'profile' => $iProfileId
  1611. ));
  1612. $this->doAudit($iGroupProfileId, $iFanProfileId, '_sys_audit_action_group_role_changed');
  1613. }
  1614. public function unsetRole($iGroupProfileId, $iFanProfileId)
  1615. {
  1616. $CNF = &$this->_oConfig->CNF;
  1617. if(!isset($CNF['OBJECT_CONNECTIONS']))
  1618. return false;
  1619. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  1620. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1621. if(!$oConnection || !$oGroupProfile)
  1622. return false;
  1623. if($oConnection->isConnected($iFanProfileId, $iGroupProfileId, true) && !$oConnection->removeConnection($iFanProfileId, $iGroupProfileId))
  1624. return false;
  1625. $iRole = $this->_oDb->getRole($iGroupProfileId, $iFanProfileId);
  1626. if(!$this->_oDb->unsetRole($iGroupProfileId, $iFanProfileId))
  1627. return false;
  1628. $this->onUnsetRole($iGroupProfileId, $iFanProfileId, $iRole);
  1629. return true;
  1630. }
  1631. public function onUnsetRole($iGroupProfileId, $iFanProfileId, $iRole)
  1632. {
  1633. $CNF = &$this->_oConfig->CNF;
  1634. $iProfileId = bx_get_logged_profile_id();
  1635. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1636. $aGroupProfileInfo = $this->_oDb->getContentInfoById((int)$oGroupProfile->getContentId());
  1637. bx_alert($this->getName(), 'set_role', $aGroupProfileInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  1638. 'object_author_id' => $iGroupProfileId,
  1639. 'performer_id' => $iProfileId,
  1640. 'fan_id' => $iFanProfileId,
  1641. 'content' => $aGroupProfileInfo,
  1642. 'role' => $iRole,
  1643. 'group_profile' => $iGroupProfileId,
  1644. 'profile' => $iProfileId
  1645. ));
  1646. $this->doAudit($iGroupProfileId, $iFanProfileId, '_sys_audit_action_group_role_changed');
  1647. }
  1648. public function getGroupsByFan($iProfileId, $mixedRole = false)
  1649. {
  1650. $CNF = &$this->_oConfig->CNF;
  1651. if(!isset($CNF['OBJECT_CONNECTIONS']))
  1652. return false;
  1653. if($mixedRole === false)
  1654. $mixedRole = BX_BASE_MOD_GROUPS_ROLE_COMMON;
  1655. if(!is_array($mixedRole))
  1656. $mixedRole = [$mixedRole];
  1657. $aResult = [];
  1658. foreach($mixedRole as $iRole) {
  1659. switch($iRole) {
  1660. case BX_BASE_MOD_GROUPS_ROLE_COMMON:
  1661. $aIds = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])->getConnectedContent($iProfileId);
  1662. break;
  1663. default:
  1664. $aIds = $this->_oDb->getRoles([
  1665. 'type' => 'group_pids_by_fan_id',
  1666. 'fan_id' => $iProfileId,
  1667. 'role' => $iRole
  1668. ]);
  1669. }
  1670. $aResult = array_merge($aResult, $aIds);
  1671. }
  1672. return $aResult;
  1673. }
  1674. public function getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfileId, $iInitiatorProfileId = 0)
  1675. {
  1676. $CNF = $this->_oConfig->getCNF();
  1677. $aResult = parent::getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfileId, $iInitiatorProfileId);
  1678. if(!empty($aResult))
  1679. return $aResult;
  1680. $oConnection = BxDolConnection::getObjectInstance($sConnection);
  1681. if(!$oConnection)
  1682. return false;
  1683. if(!$iInitiatorProfileId)
  1684. $iInitiatorProfileId = bx_get_logged_profile_id();
  1685. $aResult = [];
  1686. if($oConnection->isConnectedNotMutual($iInitiatorProfileId, $iContentProfileId))
  1687. $aResult = [
  1688. 'add' => '',
  1689. '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'),
  1690. ];
  1691. else if($oConnection->isConnectedNotMutual($iContentProfileId, $iInitiatorProfileId))
  1692. $aResult = [
  1693. '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'),
  1694. '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'),
  1695. ];
  1696. else if($oConnection->isConnected($iInitiatorProfileId, $iContentProfileId, true))
  1697. $aResult = [
  1698. 'add' => '',
  1699. 'remove' => _t(!empty($CNF['T']['menu_item_title_sm_leave']) ? $CNF['T']['menu_item_title_sm_leave'] : '_sys_menu_item_title_sm_leave'),
  1700. ];
  1701. else
  1702. $aResult = [
  1703. 'add' => _t(!empty($CNF['T']['menu_item_title_sm_join']) ? $CNF['T']['menu_item_title_sm_join'] : '_sys_menu_item_title_sm_join'),
  1704. 'remove' => '',
  1705. ];
  1706. return !empty($sAction) && isset($aResult[$sAction]) ? $aResult[$sAction] : $aResult;
  1707. }
  1708. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1709. {
  1710. $CNF = &$this->_oConfig->CNF;
  1711. $iImageId = 0;
  1712. $sImageMd = $sImageXl = '';
  1713. if(isset($CNF['FIELD_COVER']) && !empty($aContentInfo[$CNF['FIELD_COVER']])) {
  1714. $iImageId = (int)$aContentInfo[$CNF['FIELD_COVER']];
  1715. $sImageMd = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  1716. $sImageXl = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_COVER']);
  1717. }
  1718. if($sImageXl == '' && isset($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']])) {
  1719. $iImageId = (int)$aContentInfo[$CNF['FIELD_PICTURE']];
  1720. $sImageMd = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  1721. $sImageXl = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_COVER']);
  1722. }
  1723. if(empty($sImageXl))
  1724. return [];
  1725. $aImage = [
  1726. 'id' => $iImageId,
  1727. 'url' => $sUrl,
  1728. 'src' => $sImageXl,
  1729. 'src_orig' => $sImageXl
  1730. ];
  1731. if(!empty($sImageMd))
  1732. $aImage['src_medium'] = $sImageMd;
  1733. return [
  1734. $aImage
  1735. ];
  1736. }
  1737. protected function _prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId)
  1738. {
  1739. if (!($oGroupProfile = BxDolProfile::getInstance($iGroupProfileId)))
  1740. return array(0, 0, null);
  1741. if ($oGroupProfile->getModule() == $this->getName()) {
  1742. $iProfileId = $iInitiatorId;
  1743. $iGroupProfileId = $oGroupProfile->id();
  1744. } else {
  1745. $iProfileId = $oGroupProfile->id();
  1746. $iGroupProfileId = $iInitiatorId;
  1747. }
  1748. return array($iProfileId, $iGroupProfileId, $oGroupProfile);
  1749. }
  1750. }
  1751. /** @} */