BxBaseModGroupsModule.php 78 KB

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