BxBaseModGroupsModule.php 84 KB

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