BxBaseModGroupsModule.php 101 KB

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