1
0

BxBaseModGroupsModule.php 84 KB

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