BxBaseModGroupsModule.php 84 KB

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