1
0

BxBaseModGroupsModule.php 101 KB

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