BxBaseModGroupsModule.php 72 KB

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