1
0

BxBaseModGroupsModule.php 99 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511
  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. /**
  1405. * @hooks
  1406. * @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
  1407. * - $unit_name - equals `system`
  1408. * - $action - equals `check_allowed_action_by_role`
  1409. * - $object_id - not used
  1410. * - $sender_id - not used
  1411. * - $extra_params - array of additional params with the following array keys:
  1412. * - `module` - [string] module name
  1413. * - `multi_roles` - [boolean] whether multi roles are enabled in context or not
  1414. * - `action` - [string] action to be checked
  1415. * - `action_module` - [string] module name which the action belongs to
  1416. * - `content_profile_id` - [int] context profile id
  1417. * - `content_info` - [array] context info array as key&value pairs
  1418. * - `profile_id` - [int] profile id to be checked the availability of the action to
  1419. * - `profile_role` - [int] profile role in the context
  1420. * - `override_result` - [boolean] by ref, check action result, can be overridden in hook processing.
  1421. * @hook @ref hook-system-check_allowed_action_by_role
  1422. */
  1423. bx_alert('system', 'check_allowed_action_by_role', 0, 0, [
  1424. 'module' => $this->getName(),
  1425. 'multi_roles' => $this->_oConfig->isMultiRoles(),
  1426. 'action' => $sAction,
  1427. 'action_module' => $sActionModule,
  1428. 'content_profile_id' => $iGroupProfileId,
  1429. 'content_info' => $aDataEntry,
  1430. 'profile_id' => $iProfileId,
  1431. 'profile_role' => $iProfileRole,
  1432. 'override_result' => &$bResult
  1433. ]);
  1434. return $bResult;
  1435. }
  1436. public function isAllowedModuleActionByRole($sModule, $sAction, $iProfileRole)
  1437. {
  1438. static $aRoles;
  1439. if (!$aRoles && isset($this->_oConfig->CNF['OBJECT_PRE_LIST_ROLES']) && !empty($this->_oConfig->CNF['OBJECT_PRE_LIST_ROLES']))
  1440. $aRoles = BxBaseFormView::getDataItems($this->_oConfig->CNF['OBJECT_PRE_LIST_ROLES'], true, BX_DATA_VALUES_ALL);
  1441. if ($aRoles) {
  1442. foreach ($aRoles as $iRole => $aRoleData) {
  1443. if ($iRole == 0 && $iProfileRole == 0 || $iRole > 0 && $this->isRole($iProfileRole, $iRole)) {
  1444. $mPermissions = isset($aRoles[$iRole]) && isset($aRoles[$iRole]['Data']) && !empty($aRoles[$iRole]['Data']) ? unserialize($aRoles[$iRole]['Data']) : false;
  1445. if ($mPermissions && isset($mPermissions[$sModule])) {
  1446. return isset($mPermissions[$sModule][$sAction]) && $mPermissions[$sModule][$sAction];
  1447. }
  1448. }
  1449. }
  1450. }
  1451. return NULL;
  1452. }
  1453. public function isAllowedModuleActionByProfile($iContentId, $sPostModule, $sAction, $iProfileId = 0) {
  1454. if (!$iProfileId) $iProfileId = bx_get_logged_profile_id();
  1455. if ($iProfileId && $this->isFan($iContentId, $iProfileId)) {
  1456. $sModuleName = $this->getName();
  1457. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModuleName);
  1458. $aDataEntry = $this->_oDb->getContentInfoById($iContentId);
  1459. $bResult = $this->isAllowedActionByRole(['action' => $sAction, 'module' => $sPostModule], $aDataEntry, $oGroupProfile->id(), $iProfileId);
  1460. if ($bResult === true) return CHECK_ACTION_RESULT_ALLOWED;
  1461. if ($bResult === false) return _t('_sys_txt_access_denied');
  1462. }
  1463. 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.
  1464. }
  1465. public function isRole($iProfileRole, $iRole)
  1466. {
  1467. if(!$this->_oConfig->isMultiRoles())
  1468. return $iProfileRole == $iRole;
  1469. else
  1470. return $iProfileRole & (1 << ($iRole - 1));
  1471. }
  1472. public function serviceIsRole($iProfileRole, $iRole)
  1473. {
  1474. return $this->isRole($iProfileRole, $iRole);
  1475. }
  1476. public function checkAllowedManageFans($mixedDataEntry, $isPerformAction = false)
  1477. {
  1478. $aDataEntry = array();
  1479. if(!is_array($mixedDataEntry)) {
  1480. $oGroupProfile = BxDolProfile::getInstance((int)$mixedDataEntry);
  1481. if($oGroupProfile && $this->getName() == $oGroupProfile->getModule())
  1482. $aDataEntry = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  1483. }
  1484. else
  1485. $aDataEntry = $mixedDataEntry;
  1486. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_MANAGE_FANS, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1487. return CHECK_ACTION_RESULT_ALLOWED;
  1488. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  1489. }
  1490. public function checkAllowedManageAdmins($mixedDataEntry, $isPerformAction = false)
  1491. {
  1492. $aDataEntry = array();
  1493. if(!is_array($mixedDataEntry)) {
  1494. $oGroupProfile = BxDolProfile::getInstance((int)$mixedDataEntry);
  1495. if($oGroupProfile && $this->getName() == $oGroupProfile->getModule())
  1496. $aDataEntry = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  1497. }
  1498. else
  1499. $aDataEntry = $mixedDataEntry;
  1500. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_MANAGE_ROLES, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1501. return CHECK_ACTION_RESULT_ALLOWED;
  1502. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  1503. }
  1504. public function checkAllowedEdit($aDataEntry, $isPerformAction = false)
  1505. {
  1506. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_EDIT, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1507. return CHECK_ACTION_RESULT_ALLOWED;
  1508. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  1509. }
  1510. public function checkAllowedInvite($aDataEntry, $isPerformAction = false)
  1511. {
  1512. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_INVITE, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1513. return CHECK_ACTION_RESULT_ALLOWED;
  1514. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  1515. }
  1516. public function checkAllowedChangeCover($aDataEntry, $isPerformAction = false)
  1517. {
  1518. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_CHANGE_COVER, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1519. return CHECK_ACTION_RESULT_ALLOWED;
  1520. return parent::checkAllowedChangeCover($aDataEntry, $isPerformAction);
  1521. }
  1522. public function checkAllowedDelete(&$aDataEntry, $isPerformAction = false)
  1523. {
  1524. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_DELETE, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1525. return CHECK_ACTION_RESULT_ALLOWED;
  1526. return parent::checkAllowedDelete($aDataEntry, $isPerformAction);
  1527. }
  1528. public function checkAllowedJoin(&$aDataEntry, $isPerformAction = false)
  1529. {
  1530. if (bx_get('key')){
  1531. $sKey = bx_get('key');
  1532. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  1533. $aData = $this->_oDb->getInviteByKey($sKey, $oGroupProfile->id());
  1534. if (isset($aData['invited_profile_id']) && $aData['invited_profile_id'] == bx_get_logged_profile_id()){
  1535. return CHECK_ACTION_RESULT_ALLOWED;
  1536. }
  1537. }
  1538. return _t('_sys_txt_access_denied');
  1539. }
  1540. public function checkAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1541. {
  1542. $mixedResult = $this->_modGroupsCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  1543. /**
  1544. * @hooks
  1545. * @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
  1546. * - $unit_name - equals `system`
  1547. * - $action - equals `check_allowed_subscribe_add`
  1548. * - $object_id - not used
  1549. * - $sender_id - not used
  1550. * - $extra_params - array of additional params with the following array keys:
  1551. * - `module` - [string] module name
  1552. * - `content_info` - [array] context info array as key&value pairs
  1553. * - `profile_id` - [int] currently logged in profile id to be checked the availability of the action to
  1554. * - `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
  1555. * @hook @ref hook-system-check_allowed_subscribe_add
  1556. */
  1557. bx_alert('system', 'check_allowed_subscribe_add', 0, 0, [
  1558. 'module' => $this->getName(),
  1559. 'content_info' => $aDataEntry,
  1560. 'profile_id' => bx_get_logged_profile_id(),
  1561. 'override_result' => &$mixedResult
  1562. ]);
  1563. return $mixedResult;
  1564. }
  1565. /**
  1566. * Note. Is mainly needed for internal usage. Access level is 'public' to allow outer calls from alerts.
  1567. */
  1568. public function _modGroupsCheckAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1569. {
  1570. $CNF = &$this->_oConfig->CNF;
  1571. if(!$this->isFan($aDataEntry[$CNF['FIELD_ID']]) && (!isset($CNF['PARAM_SBS_WO_JOIN']) || getParam($CNF['PARAM_SBS_WO_JOIN']) != 'on'))
  1572. return _t('_sys_txt_access_denied');
  1573. return parent::_modProfileCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  1574. }
  1575. /**
  1576. * @deprecated since version 11.0.3 and can be removed in the next version.
  1577. */
  1578. public function _checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  1579. {
  1580. return parent::checkAllowedSubscribeAdd ($aDataEntry, $isPerformAction);
  1581. }
  1582. public function doAudit($iGroupProfileId, $iFanId, $sAction)
  1583. {
  1584. $oProfile = BxDolProfile::getInstance($iFanId);
  1585. $iContentId = $oProfile->getContentId();
  1586. $sModule = $oProfile->getModule();
  1587. $oModule = BxDolModule::getInstance($sModule);
  1588. if (BxDolRequest::serviceExists($sModule, 'act_as_profile') && BxDolService::call($sModule, 'act_as_profile') && $oModule->_oConfig){
  1589. $CNF = $oModule->_oConfig->CNF;
  1590. $aContentInfo = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $iContentId))) : array();
  1591. $AuditParams = array(
  1592. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  1593. 'context_profile_id' => $iGroupProfileId,
  1594. 'context_profile_title' => BxDolProfile::getInstance($iGroupProfileId)->getDisplayName()
  1595. );
  1596. bx_audit(
  1597. $iContentId,
  1598. $sModule,
  1599. $sAction,
  1600. $AuditParams
  1601. );
  1602. }
  1603. }
  1604. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  1605. {
  1606. $sResult = $this->checkAllowedView($aDataEntry);
  1607. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  1608. // when context is in another context
  1609. if ($aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0 && getParam('sys_check_fan_in_parent_context')) {
  1610. $oParent = BxDolProfile::getInstance(abs($aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]));
  1611. $oModule = $oParent ? BxDolModule::getInstance($oParent->getModule()) : null;
  1612. if ($oModule && method_exists($oModule, 'isFan') && !$oModule->isFan($oParent->getContentId()))
  1613. return _t('_sys_txt_access_denied');
  1614. }
  1615. // if profile view isn't allowed but visibility is in partially visible groups
  1616. // then display buttons to connect (befriend, join) to profile,
  1617. // if other conditions (in parent::_checkAllowedConnect) are met as well
  1618. if (CHECK_ACTION_RESULT_ALLOWED !== $sResult && !in_array($aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']], array_merge($oPrivacy->getPartiallyVisiblePrivacyGroups(), array('s'))))
  1619. return $sResult;
  1620. return parent::_checkAllowedConnect ($aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap);
  1621. }
  1622. // ====== COMMON METHODS
  1623. public function onUpdateImage($iContentId, $sFiledName, $sFiledValue, $iProfileId = 0)
  1624. {
  1625. $CNF = &$this->_oConfig->CNF;
  1626. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1627. $aField2Method = [
  1628. $CNF['FIELD_PICTURE'] => 'picture',
  1629. $CNF['FIELD_COVER'] => 'cover',
  1630. ];
  1631. if(!empty($aField2Method[$sFiledName]))
  1632. /**
  1633. * @hooks
  1634. * @hookdef hook-bx_base_groups-context_picture_changed '{module_name}', 'context_picture_changed' - hook after context picture was changed
  1635. * - $unit_name - module name
  1636. * - $action - equals `context_picture_changed`
  1637. * - $object_id - context id
  1638. * - $sender_id - profile id who performed the action
  1639. * - $extra_params - array of additional params with the following array keys:
  1640. * - `status` - [string] context status
  1641. * - `status_admin` - [string] context admin status
  1642. * - `privacy_view` - [int] or [string] privacy for view context action, @see BxDolPrivacy
  1643. * - `cf` - [int] context's audience filter value
  1644. * @hook @ref hook-bx_base_groups-context_picture_changed
  1645. */
  1646. /**
  1647. * @hooks
  1648. * @hookdef hook-bx_base_groups-context_cover_changed '{module_name}', 'context_cover_changed' - hook after context cover was changed
  1649. * It's equivalent to @ref hook-bx_base_groups-context_picture_changed
  1650. * @hook @ref hook-bx_base_groups-context_cover_changed
  1651. */
  1652. bx_alert($this->getName(), 'context_' . $aField2Method[$sFiledName] . '_changed', $iContentId, $iProfileId, $this->_alertParams($aContentInfo));
  1653. }
  1654. protected function _alertParams($aContentInfo)
  1655. {
  1656. $aParams = parent::_alertParams($aContentInfo);
  1657. $CNF = &$this->_oConfig->CNF;
  1658. if(!empty($CNF['FIELD_CF']) && isset($aContentInfo[$CNF['FIELD_CF']]))
  1659. $aParams['cf'] = $aContentInfo[$CNF['FIELD_CF']];
  1660. return $aParams;
  1661. }
  1662. public function alertAfterAdd($aContentInfo)
  1663. {
  1664. $CNF = &$this->_oConfig->CNF;
  1665. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1666. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  1667. $sAction = 'added';
  1668. if(isset($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == BX_BASE_MOD_GENERAL_STATUS_PENDING)
  1669. $sAction = 'deferred';
  1670. $sModule = $this->getName();
  1671. $aParams = $this->_alertParams($aContentInfo);
  1672. /**
  1673. * @hooks
  1674. * @hookdef hook-system-prepare_alert_params 'system', 'prepare_alert_params' - hook to override alert (hook) params
  1675. * - $unit_name - equals `system`
  1676. * - $action - equals `prepare_alert_params`
  1677. * - $object_id - not used
  1678. * - $sender_id - not used
  1679. * - $extra_params - array of additional params with the following array keys:
  1680. * - `unit` - [string] unit name
  1681. * - `action` - [string] by ref, action, can be overridden in hook processing
  1682. * - `object_id` - [int] by ref, object id, can be overridden in hook processing
  1683. * - `sender_id` - [int] by ref, action performer profile id, can be overridden in hook processing
  1684. * - `extras` - [array] by ref, extra params array as key&value pairs, can be overridden in hook processing
  1685. * @hook @ref hook-system-prepare_alert_params
  1686. */
  1687. bx_alert('system', 'prepare_alert_params', 0, 0, [
  1688. 'unit'=> $sModule,
  1689. 'action' => &$sAction,
  1690. 'object_id' => &$iId,
  1691. 'sender_id' => &$iAuthorId,
  1692. 'extras' => &$aParams
  1693. ]);
  1694. /**
  1695. * @hooks
  1696. * @hookdef hook-bx_base_groups-added '{module_name}', 'added' - hook after context was added (published)
  1697. * - $unit_name - module name
  1698. * - $action - equals `added`
  1699. * - $object_id - context id
  1700. * - $sender_id - not used
  1701. * - $extra_params - array of additional params with the following array keys:
  1702. * - `status` - [string] context status
  1703. * - `status_admin` - [string] context admin status
  1704. * - `privacy_view` - [int] or [string] privacy for view context action, @see BxDolPrivacy
  1705. * - `cf` - [int] context's audience filter value
  1706. * @hook @ref hook-bx_base_groups-added
  1707. */
  1708. /**
  1709. * @hooks
  1710. * @hookdef hook-bx_base_groups-deferred '{module_name}', 'deferred' - hook after context was added with pending approval status
  1711. * It's equivalent to @ref hook-bx_base_groups-added
  1712. * @hook @ref hook-bx_base_groups-deferred
  1713. */
  1714. bx_alert($sModule, $sAction, $iId, false, $aParams);
  1715. $this->_processModerationNotifications($aContentInfo);
  1716. }
  1717. public function addFollower ($iProfileId1, $iProfileId2)
  1718. {
  1719. $oConnectionFollow = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  1720. if($oConnectionFollow && !$oConnectionFollow->isConnected($iProfileId1, $iProfileId2)){
  1721. $oConnectionFollow->addConnection($iProfileId1, $iProfileId2);
  1722. return true;
  1723. }
  1724. return false;
  1725. }
  1726. public function isFan ($iContentId, $iProfileId = false)
  1727. {
  1728. $CNF = &$this->_oConfig->CNF;
  1729. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  1730. if($oGroupProfile && isset($CNF['OBJECT_CONNECTIONS']))
  1731. return ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $oGroupProfile->id(), true);
  1732. return false;
  1733. }
  1734. public function isFanByGroupProfileId ($iGroupProfileId, $iProfileId = false)
  1735. {
  1736. $CNF = &$this->_oConfig->CNF;
  1737. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1738. if($oGroupProfile && isset($CNF['OBJECT_CONNECTIONS']))
  1739. return ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $oGroupProfile->id(), true);
  1740. return false;
  1741. }
  1742. public function isInvited ($sKey, $iGroupProfileId)
  1743. {
  1744. $CNF = &$this->_oConfig->CNF;
  1745. $aData = $this->_oDb->getInviteByKey($sKey, $iGroupProfileId);
  1746. if (!isset($aData['invited_profile_id']))
  1747. return _t($CNF['T']['txt_invitation_popup_error_invitation_absent']);
  1748. if ($aData['invited_profile_id'] != bx_get_logged_profile_id())
  1749. return _t($CNF['T']['txt_invitation_popup_error_wrong_user']);
  1750. return true;
  1751. }
  1752. public function isInvitedByProfileId ($iProfileId, $iGroupProfileId)
  1753. {
  1754. $CNF = &$this->_oConfig->CNF;
  1755. $aData = $this->_oDb->getInviteByInvited($iProfileId, $iGroupProfileId);
  1756. if (!isset($aData['invited_profile_id']))
  1757. return _t($CNF['T']['txt_invitation_popup_error_invitation_absent']);
  1758. if ($aData['invited_profile_id'] != bx_get_logged_profile_id())
  1759. return _t($CNF['T']['txt_invitation_popup_error_wrong_user']);
  1760. return true;
  1761. }
  1762. public function serviceIsInvited($iGroupProfileId, $iProfileId = false, $sKey = '')
  1763. {
  1764. if(!$iProfileId)
  1765. $iProfileId = bx_get_logged_profile_id();
  1766. if(empty($sKey) && ($sKey = bx_get('key')) !== false)
  1767. $sKey = bx_process_input($sKey);
  1768. $mixedInvited = false;
  1769. if(!empty($sKey))
  1770. $mixedInvited = $this->isInvited($sKey, $iGroupProfileId);
  1771. else if($iProfileId !== false)
  1772. $mixedInvited = $this->isInvitedByProfileId($iProfileId, $iGroupProfileId);
  1773. return $mixedInvited === true;
  1774. }
  1775. public function serviceIsNotInvited($iGroupProfileId, $iProfileId = false, $sKey = '')
  1776. {
  1777. return !$this->serviceIsInvited($iGroupProfileId, $iProfileId, $sKey);
  1778. }
  1779. public function serviceGetInvitedKey($iGroupProfileId, $iProfileId = false)
  1780. {
  1781. $sKey = '';
  1782. if(($sKey = bx_get('key')) !== false)
  1783. $sKey = bx_process_input($sKey);
  1784. if(!$sKey) {
  1785. if(!$iProfileId)
  1786. $iProfileId = bx_get_logged_profile_id();
  1787. if($iProfileId !== false) {
  1788. $aInvite = $this->_oDb->getInviteByInvited($iProfileId, $iGroupProfileId);
  1789. if(!empty($aInvite) && is_array($aInvite))
  1790. $sKey = $aInvite['key'];
  1791. }
  1792. }
  1793. return $sKey;
  1794. }
  1795. public function getRole($iGroupProfileId, $iFanProfileId)
  1796. {
  1797. if(!$this->isFanByGroupProfileId($iGroupProfileId, $iFanProfileId))
  1798. return false;
  1799. return $this->_oDb->getRole($iGroupProfileId, $iFanProfileId);
  1800. }
  1801. public function setRole($iGroupProfileId, $iFanProfileId, $mixedRole, $mixedPeriod = false, $sOrder = '')
  1802. {
  1803. $CNF = &$this->_oConfig->CNF;
  1804. if(!isset($CNF['OBJECT_CONNECTIONS']))
  1805. return false;
  1806. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  1807. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1808. if(!$oConnection || !$oGroupProfile)
  1809. return false;
  1810. if(!$oConnection->isConnected($iFanProfileId, $iGroupProfileId, true) && !$oConnection->addConnection($iFanProfileId, $iGroupProfileId))
  1811. return false;
  1812. if(!$this->_oDb->setRole($iGroupProfileId, $iFanProfileId, $mixedRole, $mixedPeriod, $sOrder))
  1813. return false;
  1814. $this->onSetRole($iGroupProfileId, $iFanProfileId, $mixedRole);
  1815. return true;
  1816. }
  1817. public function onSetRole($iGroupProfileId, $iFanProfileId, $mixedRole)
  1818. {
  1819. $CNF = &$this->_oConfig->CNF;
  1820. $iProfileId = bx_get_logged_profile_id();
  1821. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1822. $aGroupProfileInfo = $this->_oDb->getContentInfoById((int)$oGroupProfile->getContentId());
  1823. $aRoles = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_ROLES']);
  1824. // notify about admin status
  1825. if(!empty($CNF['EMAIL_FAN_SET_ROLE']) && $iFanProfileId != $iProfileId) {
  1826. $aSetRoles = is_array($mixedRole) ? $mixedRole : [$mixedRole];
  1827. $aRolesNames = [];
  1828. foreach ($aSetRoles as $iRole)
  1829. $aRolesNames[] = $aRoles[(int)$iRole];
  1830. sendMailTemplate($CNF['EMAIL_FAN_SET_ROLE'], 0, $iFanProfileId, array(
  1831. 'EntryUrl' => $oGroupProfile->getUrl(),
  1832. 'EntryTitle' => $oGroupProfile->getDisplayName(),
  1833. 'Role' => implode(', ', $aRolesNames),
  1834. ), BX_EMAIL_NOTIFY);
  1835. }
  1836. /**
  1837. * @hooks
  1838. * @hookdef hook-bx_base_groups-set_role '{module_name}', 'set_role' - hook after 'set role' action was applied to context member
  1839. * - $unit_name - module name
  1840. * - $action - equals `set_role`
  1841. * - $object_id - context id
  1842. * - $sender_id - context profile id
  1843. * - $extra_params - array of additional params with the following array keys:
  1844. * - `object_author_id` - [int] context profile id
  1845. * - `performer_id` - [int] performer profile id
  1846. * - `fan_id` - [int] context member profile id
  1847. * - `content` - [array] context info array as key&value pairs
  1848. * - `role` - [int] or [array] role or an array of roles to be set
  1849. * - `group_profile` - [int] context profile id
  1850. * - `profile` - [int] performer profile id
  1851. * @hook @ref hook-bx_base_groups-set_role
  1852. */
  1853. bx_alert($this->getName(), 'set_role', $aGroupProfileInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  1854. 'object_author_id' => $iGroupProfileId,
  1855. 'performer_id' => $iProfileId,
  1856. 'fan_id' => $iFanProfileId,
  1857. 'content' => $aGroupProfileInfo,
  1858. 'role' => $mixedRole,
  1859. 'group_profile' => $iGroupProfileId,
  1860. 'profile' => $iProfileId
  1861. ));
  1862. $this->doAudit($iGroupProfileId, $iFanProfileId, '_sys_audit_action_group_role_changed');
  1863. }
  1864. public function unsetRole($iGroupProfileId, $iFanProfileId)
  1865. {
  1866. $CNF = &$this->_oConfig->CNF;
  1867. if(!isset($CNF['OBJECT_CONNECTIONS']))
  1868. return false;
  1869. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  1870. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1871. if(!$oConnection || !$oGroupProfile)
  1872. return false;
  1873. if($oConnection->isConnected($iFanProfileId, $iGroupProfileId, true) && !$oConnection->removeConnection($iFanProfileId, $iGroupProfileId))
  1874. return false;
  1875. $iRole = $this->_oDb->getRole($iGroupProfileId, $iFanProfileId);
  1876. if(!$this->_oDb->unsetRole($iGroupProfileId, $iFanProfileId))
  1877. return false;
  1878. $this->onUnsetRole($iGroupProfileId, $iFanProfileId, $iRole);
  1879. return true;
  1880. }
  1881. public function onUnsetRole($iGroupProfileId, $iFanProfileId, $iRole)
  1882. {
  1883. $CNF = &$this->_oConfig->CNF;
  1884. $iProfileId = bx_get_logged_profile_id();
  1885. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1886. $aGroupProfileInfo = $this->_oDb->getContentInfoById((int)$oGroupProfile->getContentId());
  1887. /**
  1888. * @hooks
  1889. * @hookdef hook-bx_base_groups-set_role '{module_name}', 'set_role' - hook after 'set role' action was applied to context member
  1890. * - $unit_name - module name
  1891. * - $action - equals `set_role`
  1892. * - $object_id - context id
  1893. * - $sender_id - context profile id
  1894. * - $extra_params - array of additional params with the following array keys:
  1895. * - `object_author_id` - [int] context profile id
  1896. * - `performer_id` - [int] performer profile id
  1897. * - `fan_id` - [int] context member profile id
  1898. * - `content` - [array] context info array as key&value pairs
  1899. * - `role` - [int] or [array] role or an array of roles to be set
  1900. * - `group_profile` - [int] context profile id
  1901. * - `profile` - [int] performer profile id
  1902. * @hook @ref hook-bx_base_groups-set_role
  1903. */
  1904. bx_alert($this->getName(), 'set_role', $aGroupProfileInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  1905. 'object_author_id' => $iGroupProfileId,
  1906. 'performer_id' => $iProfileId,
  1907. 'fan_id' => $iFanProfileId,
  1908. 'content' => $aGroupProfileInfo,
  1909. 'role' => $iRole,
  1910. 'group_profile' => $iGroupProfileId,
  1911. 'profile' => $iProfileId
  1912. ));
  1913. $this->doAudit($iGroupProfileId, $iFanProfileId, '_sys_audit_action_group_role_changed');
  1914. }
  1915. public function getGroupsByFan($iProfileId, $mixedRole = false)
  1916. {
  1917. $CNF = &$this->_oConfig->CNF;
  1918. if(!isset($CNF['OBJECT_CONNECTIONS']))
  1919. return false;
  1920. if($mixedRole === false)
  1921. $mixedRole = BX_BASE_MOD_GROUPS_ROLE_COMMON;
  1922. if(!is_array($mixedRole))
  1923. $mixedRole = [$mixedRole];
  1924. $aResult = [];
  1925. foreach($mixedRole as $iRole) {
  1926. switch($iRole) {
  1927. case BX_BASE_MOD_GROUPS_ROLE_COMMON:
  1928. $aIds = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])->getConnectedContent($iProfileId);
  1929. break;
  1930. default:
  1931. $aIds = $this->_oDb->getRoles([
  1932. 'type' => 'group_pids_by_fan_id',
  1933. 'fan_id' => $iProfileId,
  1934. 'role' => $iRole
  1935. ]);
  1936. }
  1937. $aResult = array_merge($aResult, $aIds);
  1938. }
  1939. return $aResult;
  1940. }
  1941. public function getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfileId, $iInitiatorProfileId = 0)
  1942. {
  1943. $CNF = $this->_oConfig->getCNF();
  1944. $aResult = parent::getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfileId, $iInitiatorProfileId);
  1945. if(!empty($aResult))
  1946. return $aResult;
  1947. $oConnection = BxDolConnection::getObjectInstance($sConnection);
  1948. if(!$oConnection)
  1949. return false;
  1950. if(!$iInitiatorProfileId)
  1951. $iInitiatorProfileId = bx_get_logged_profile_id();
  1952. $aResult = [];
  1953. if($oConnection->isConnectedNotMutual($iInitiatorProfileId, $iContentProfileId))
  1954. $aResult = [
  1955. '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'),
  1956. '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'),
  1957. ];
  1958. else if($oConnection->isConnectedNotMutual($iContentProfileId, $iInitiatorProfileId))
  1959. $aResult = [
  1960. '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'),
  1961. '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'),
  1962. ];
  1963. else if($oConnection->isConnected($iInitiatorProfileId, $iContentProfileId, true))
  1964. $aResult = [
  1965. 'add' => '',
  1966. 'remove' => _t(!empty($CNF['T']['menu_item_title_sm_leave']) ? $CNF['T']['menu_item_title_sm_leave'] : '_sys_menu_item_title_sm_leave'),
  1967. ];
  1968. else
  1969. $aResult = [
  1970. 'add' => _t(!empty($CNF['T']['menu_item_title_sm_join']) ? $CNF['T']['menu_item_title_sm_join'] : '_sys_menu_item_title_sm_join'),
  1971. 'remove' => '',
  1972. ];
  1973. return !empty($sAction) && isset($aResult[$sAction]) ? $aResult[$sAction] : $aResult;
  1974. }
  1975. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1976. {
  1977. $CNF = &$this->_oConfig->CNF;
  1978. $iImageId = 0;
  1979. $sImageMd = $sImageXl = '';
  1980. if(isset($CNF['FIELD_COVER']) && !empty($aContentInfo[$CNF['FIELD_COVER']])) {
  1981. $iImageId = (int)$aContentInfo[$CNF['FIELD_COVER']];
  1982. $sImageMd = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  1983. $sImageXl = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_COVER']);
  1984. }
  1985. if($sImageXl == '' && isset($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']])) {
  1986. $iImageId = (int)$aContentInfo[$CNF['FIELD_PICTURE']];
  1987. $sImageMd = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  1988. $sImageXl = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_COVER']);
  1989. }
  1990. if(empty($sImageXl))
  1991. return [];
  1992. $aImage = [
  1993. 'id' => $iImageId,
  1994. 'url' => $sUrl,
  1995. 'src' => $sImageXl,
  1996. 'src_orig' => $sImageXl
  1997. ];
  1998. if(!empty($sImageMd))
  1999. $aImage['src_medium'] = $sImageMd;
  2000. return [
  2001. $aImage
  2002. ];
  2003. }
  2004. protected function _prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId)
  2005. {
  2006. if (!($oGroupProfile = BxDolProfile::getInstance($iGroupProfileId)))
  2007. return array(0, 0, null);
  2008. if ($oGroupProfile->getModule() == $this->getName()) {
  2009. $iProfileId = $iInitiatorId;
  2010. $iGroupProfileId = $oGroupProfile->id();
  2011. } else {
  2012. $iProfileId = $oGroupProfile->id();
  2013. $iGroupProfileId = $iInitiatorId;
  2014. }
  2015. return array($iProfileId, $iGroupProfileId, $oGroupProfile);
  2016. }
  2017. }
  2018. /** @} */