1
0

BxBaseModGroupsModule.php 85 KB

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