1
0

BxBaseModGroupsModule.php 105 KB

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