1
0

BxBaseModGroupsModule.php 101 KB

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