BxBaseModGroupsModule.php 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440
  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_MMODE_PAID_JOIN', 'paid_join');
  13. define('BX_BASE_MOD_GROUPS_ROLE_COMMON', 0);
  14. define('BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR', 1);
  15. define('BX_BASE_MOD_GROUPS_ROLE_MODERATOR', 2);
  16. define('BX_BASE_MOD_GROUPS_ACTION_EDIT', 'edit');
  17. define('BX_BASE_MOD_GROUPS_ACTION_CHANGE_COVER', 'change_cover');
  18. define('BX_BASE_MOD_GROUPS_ACTION_INVITE', 'invite');
  19. define('BX_BASE_MOD_GROUPS_ACTION_MANAGE_FANS', 'manage_fans');
  20. define('BX_BASE_MOD_GROUPS_ACTION_MANAGE_ROLES', 'manage_roles');
  21. define('BX_BASE_MOD_GROUPS_ACTION_DELETE', 'delete');
  22. define('BX_BASE_MOD_GROUPS_PERIOD_UNIT_DAY', 'day');
  23. define('BX_BASE_MOD_GROUPS_PERIOD_UNIT_WEEK', 'week');
  24. define('BX_BASE_MOD_GROUPS_PERIOD_UNIT_MONTH', 'month');
  25. define('BX_BASE_MOD_GROUPS_PERIOD_UNIT_YEAR', 'year');
  26. /**
  27. * Groups profiles module.
  28. */
  29. class BxBaseModGroupsModule extends BxBaseModProfileModule
  30. {
  31. function __construct(&$aModule)
  32. {
  33. parent::__construct($aModule);
  34. }
  35. /**
  36. * Get possible recipients for start conversation form
  37. */
  38. public function actionAjaxGetInitialMembers ()
  39. {
  40. $sTerm = bx_get('term');
  41. $a = BxDolService::call('system', 'profiles_search', array($sTerm), 'TemplServiceProfiles');
  42. header('Content-Type:text/javascript; charset=utf-8');
  43. echo(json_encode($a));
  44. }
  45. /**
  46. * Process Process Invitation
  47. */
  48. public function actionProcessInvite ($sKey, $iGroupProfileId, $bAccept)
  49. {
  50. $aData = $this->_oDb->getInviteByKey($sKey, $iGroupProfileId);
  51. if (isset($aData['invited_profile_id'])){
  52. $CNF = &$this->_oConfig->CNF;
  53. if (!isset($CNF['OBJECT_CONNECTIONS']) || !($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  54. return '';
  55. $iInvitedProfileId = $aData['invited_profile_id'];
  56. if ($iInvitedProfileId != bx_get_logged_profile_id())
  57. return '';
  58. if ($bAccept){
  59. if($oConnection && !$oConnection->isConnected($iInvitedProfileId, $iGroupProfileId)){
  60. $oConnection->addConnection($iInvitedProfileId, $iGroupProfileId);
  61. $oConnection->addConnection($iGroupProfileId, $iInvitedProfileId);
  62. }
  63. }
  64. $this->_oDb->deleteInviteByKey($sKey, $iGroupProfileId);
  65. }
  66. }
  67. public function serviceGetOptionsMembersMode()
  68. {
  69. $CNF = &$this->_oConfig->CNF;
  70. return array(
  71. array('key' => '', 'value' => _t('_None')),
  72. array('key' => BX_BASE_MOD_GROUPS_MMODE_MULTI_ROLES, 'value' => _t($CNF['T']['option_members_mode_' . BX_BASE_MOD_GROUPS_MMODE_MULTI_ROLES])),
  73. array('key' => BX_BASE_MOD_GROUPS_MMODE_PAID_JOIN, 'value' => _t($CNF['T']['option_members_mode_' . BX_BASE_MOD_GROUPS_MMODE_PAID_JOIN]))
  74. );
  75. }
  76. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  77. {
  78. if(empty($sUnitTemplate))
  79. $sUnitTemplate = 'unit.html';
  80. return parent::serviceGetSearchResultUnit($iContentId, $sUnitTemplate);
  81. }
  82. /**
  83. * @see BxBaseModProfileModule::serviceGetSpaceTitle
  84. */
  85. public function serviceGetSpaceTitle()
  86. {
  87. return _t($this->_oConfig->CNF['T']['txt_sample_single']);
  88. }
  89. /**
  90. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  91. */
  92. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects = false)
  93. {
  94. if (isset($this->_oConfig->CNF['OBJECT_CONNECTIONS'])){
  95. $aConnectionObjects = array($this->_oConfig->CNF['OBJECT_CONNECTIONS'], 'sys_profiles_subscriptions');
  96. return parent::serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects);
  97. }
  98. return parent::serviceGetParticipatingProfiles($iProfileId);
  99. }
  100. /**
  101. * Check if this module entry can be used as profile
  102. */
  103. public function serviceActAsProfile ()
  104. {
  105. return false;
  106. }
  107. /**
  108. * Check if this module is group profile
  109. */
  110. public function serviceIsGroupProfile ()
  111. {
  112. return true;
  113. }
  114. public function serviceIsEnableForContext($iProfileId = 0)
  115. {
  116. $CNF = &$this->_oConfig->CNF;
  117. $sCnfKey = 'ENABLE_FOR_CONTEXT_IN_MODULES';
  118. if(empty($iProfileId) || empty($CNF[$sCnfKey]) || !is_array($CNF[$sCnfKey]))
  119. return false;
  120. if(in_array(BxDolProfile::getInstance($iProfileId)->getModule(), $CNF[$sCnfKey]))
  121. return true;
  122. return false;
  123. }
  124. /**
  125. * check if provided profile is member of the group
  126. */
  127. public function serviceIsFan ($iGroupProfileId, $iProfileId = false)
  128. {
  129. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  130. return $this->isFan($oGroupProfile->getContentId(), $iProfileId);
  131. }
  132. /**
  133. * check if provided profile is admin of the group
  134. */
  135. public function serviceIsAdmin ($iGroupProfileId, $iProfileId = false)
  136. {
  137. if(!$iProfileId)
  138. $iProfileId = bx_get_logged_profile_id();
  139. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  140. $iGroupContentId = $oGroupProfile->getContentId();
  141. if(!$this->isFan($iGroupContentId, $iProfileId))
  142. return false;
  143. $aGroupContentInfo = $this->_oDb->getContentInfoById($iGroupContentId);
  144. return $this->_oDb->isAdmin($iGroupProfileId, $iProfileId, $aGroupContentInfo);
  145. }
  146. public function serviceGetAdminRole($iGroupProfileId, $iProfileId = false)
  147. {
  148. if(!$iProfileId)
  149. $iProfileId = bx_get_logged_profile_id();
  150. if(!$this->serviceIsAdmin($iGroupProfileId, $iProfileId))
  151. return 0;
  152. return $this->_oDb->getRole($iGroupProfileId, $iProfileId);
  153. }
  154. /**
  155. * Delete profile from fans and admins tables
  156. * @param $iProfileId profile id
  157. */
  158. public function serviceDeleteProfileFromFansAndAdmins ($iProfileId)
  159. {
  160. $CNF = &$this->_oConfig->CNF;
  161. $this->_oDb->deleteAdminsByProfileId($iProfileId);
  162. if (isset($CNF['OBJECT_CONNECTIONS']) && ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  163. $oConnection->onDeleteInitiatorAndContent($iProfileId);
  164. }
  165. /**
  166. * Reset group's author for particular group
  167. * @param $iContentId group id
  168. * @return false of error, or number of updated records on success
  169. */
  170. public function serviceReassignEntityAuthor ($iContentId)
  171. {
  172. $aContentInfo = $this->_oDb->getContentInfoById((int)$iContentId);
  173. if (!$aContentInfo)
  174. return false;
  175. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
  176. return false;
  177. $aAdmins = $this->_oDb->getAdmins($oGroupProfile->id());
  178. return $this->_oDb->updateAuthorById($iContentId, $aAdmins ? array_pop($aAdmins) : 0);
  179. }
  180. /**
  181. * Entry actions and social sharing block
  182. */
  183. public function serviceEntityAllActions ($mixedContent = false, $aParams = array())
  184. {
  185. $CNF = &$this->_oConfig->CNF;
  186. if(!empty($mixedContent)) {
  187. if(!is_array($mixedContent))
  188. $mixedContent = array((int)$mixedContent, (method_exists($this->_oDb, 'getContentInfoById')) ? $this->_oDb->getContentInfoById((int)$mixedContent) : array());
  189. }
  190. else {
  191. $mixedContent = $this->_getContent();
  192. if($mixedContent === false)
  193. return false;
  194. }
  195. list($iContentId, $aContentInfo) = $mixedContent;
  196. if(!empty($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]))
  197. $aParams = array_merge(array(
  198. 'entry_thumb' => (int)$aContentInfo[$CNF['FIELD_PICTURE']]
  199. ), $aParams);
  200. return parent::serviceEntityAllActions ($mixedContent, $aParams);
  201. }
  202. /**
  203. * Reset group's author when author profile is deleted
  204. * @param $iProfileId profile id
  205. * @return number of changed items
  206. */
  207. public function serviceReassignEntitiesByAuthor ($iProfileId)
  208. {
  209. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  210. if (!$a)
  211. return 0;
  212. $iCount = 0;
  213. foreach ($a as $aContentInfo)
  214. $iCount += ('' == $this->serviceReassignEntityAuthor($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
  215. return $iCount;
  216. }
  217. public function servicePrepareFields ($aFieldsProfile)
  218. {
  219. $CNF = &$this->_oConfig->CNF;
  220. $aFieldsProfile[$CNF['FIELD_NAME']] = $aFieldsProfile['name'];
  221. $aFieldsProfile[$CNF['FIELD_TEXT']] = isset($aFieldsProfile['description']) ? $aFieldsProfile['description'] : '';
  222. unset($aFieldsProfile['name']);
  223. unset($aFieldsProfile['description']);
  224. return $aFieldsProfile;
  225. }
  226. public function serviceOnRemoveConnection ($iGroupProfileId, $iInitiatorId)
  227. {
  228. $CNF = &$this->_oConfig->CNF;
  229. list ($iProfileId, $iGroupProfileId, $oGroupProfile) = $this->_prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId);
  230. if (!$oGroupProfile)
  231. return false;
  232. $this->_oDb->fromAdmins($iGroupProfileId, $iProfileId);
  233. if ($oConn = BxDolConnection::getObjectInstance('sys_profiles_subscriptions'))
  234. return $oConn->removeConnection($iProfileId, $iGroupProfileId);
  235. return false;
  236. }
  237. public function serviceAddMutualConnection ($iGroupProfileId, $iInitiatorId, $bSendInviteOnly = false)
  238. {
  239. $CNF = &$this->_oConfig->CNF;
  240. list ($iProfileId, $iGroupProfileId, $oGroupProfile) = $this->_prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId);
  241. if (!$oGroupProfile)
  242. return false;
  243. if (!($aContentInfo = $this->_oDb->getContentInfoById((int)BxDolProfile::getInstance($iGroupProfileId)->getContentId())))
  244. return false;
  245. if (!isset($CNF['OBJECT_CONNECTIONS']) || !($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  246. return false;
  247. $sEntryTitle = $aContentInfo[$CNF['FIELD_NAME']];
  248. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  249. // send invitation to the group
  250. if ($bSendInviteOnly && !$oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id()) && !$oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId) && bx_get_logged_profile_id() != $iProfileId) {
  251. bx_alert($this->getName(), 'join_invitation', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, array('content' => $aContentInfo, 'entry_title' => $sEntryTitle, 'entry_url' => $sEntryUrl, 'group_profile' => $iGroupProfileId, 'profile' => $iProfileId, 'notification_subobject_id' => $iProfileId, 'object_author_id' => $iGroupProfileId));
  252. }
  253. // send notification to group's admins that new connection is pending confirmation
  254. elseif (!$bSendInviteOnly && $oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id()) && !$oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId) && $aContentInfo['join_confirmation']) {
  255. bx_alert($this->getName(), 'join_request', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  256. 'object_author_id' => $iGroupProfileId,
  257. 'performer_id' => $iProfileId,
  258. 'content' => $aContentInfo,
  259. 'entry_title' => $sEntryTitle,
  260. 'entry_url' => $sEntryUrl,
  261. 'group_profile' => $iGroupProfileId,
  262. 'profile' => $iProfileId
  263. ));
  264. }
  265. // send notification that join request was accepted
  266. else if (!$bSendInviteOnly && $oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id(), true) && $oGroupProfile->getModule() != $this->getName() && bx_get_logged_profile_id() != $iProfileId) {
  267. bx_alert($this->getName(), 'join_request_accepted', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  268. 'object_author_id' => $iGroupProfileId,
  269. 'performer_id' => $iProfileId,
  270. 'content' => $aContentInfo,
  271. 'entry_title' => $sEntryTitle,
  272. 'entry_url' => $sEntryUrl,
  273. 'group_profile' => $iGroupProfileId,
  274. 'profile' => $iProfileId
  275. ));
  276. }
  277. // new fan was added
  278. if ($oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId, true)) {
  279. // follow group on join
  280. if (BxDolService::call($oGroupProfile->getModule(), 'act_as_profile')){
  281. $this->addFollower($oGroupProfile->id(), (int)$iInitiatorId);
  282. }
  283. else{
  284. $this->addFollower((int)$iInitiatorId, $oGroupProfile->id());
  285. }
  286. bx_alert($this->getName(), 'fan_added', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  287. 'object_author_id' => $iGroupProfileId,
  288. 'performer_id' => $iProfileId,
  289. 'content' => $aContentInfo,
  290. 'entry_title' => $sEntryTitle,
  291. 'entry_url' => $sEntryUrl,
  292. 'group_profile' => $iGroupProfileId,
  293. 'profile' => $iProfileId,
  294. ));
  295. $this->doAudit($iGroupProfileId, $iInitiatorId, '_sys_audit_action_group_join_request_accepted');
  296. return false;
  297. }
  298. // don't automatically add connection (mutual) if group requires manual join confirmation
  299. if ($bSendInviteOnly || $aContentInfo['join_confirmation'])
  300. return false;
  301. // check if connection already exists
  302. if ($oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId, true) || $oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId))
  303. return false;
  304. if (!$oConnection->addConnection($oGroupProfile->id(), (int)$iInitiatorId))
  305. return false;
  306. return true;
  307. }
  308. public function serviceFansTable ()
  309. {
  310. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID_CONNECTIONS']);
  311. if (!$oGrid)
  312. return false;
  313. return $oGrid->getCode();
  314. }
  315. public function serviceInvitesTable ()
  316. {
  317. if (!isset($this->_oConfig->CNF['OBJECT_GRID_INVITES']))
  318. return false;
  319. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID_INVITES']);
  320. if (!$oGrid)
  321. return false;
  322. return $oGrid->getCode();
  323. }
  324. public function serviceFans ($iContentId = 0, $bAsArray = false)
  325. {
  326. if (!$iContentId)
  327. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  328. if (!$iContentId)
  329. return false;
  330. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  331. if (!$aContentInfo)
  332. return false;
  333. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
  334. return false;
  335. if(!$bAsArray) {
  336. bx_import('BxDolConnection');
  337. $mixedResult = $this->serviceBrowseConnectionsQuick ($oGroupProfile->id(), $this->_oConfig->CNF['OBJECT_CONNECTIONS'], BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  338. if (!$mixedResult)
  339. return MsgBox(_t('_sys_txt_empty'));
  340. }
  341. else
  342. $mixedResult = BxDolConnection::getObjectInstance($this->_oConfig->CNF['OBJECT_CONNECTIONS'])->getConnectedContent($oGroupProfile->id(), true);
  343. return $mixedResult;
  344. }
  345. public function serviceFansWithoutAdmins ($iContentId = 0, $bAsArray = false)
  346. {
  347. if (!$iContentId)
  348. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  349. if (!$iContentId)
  350. return false;
  351. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  352. if (!$aContentInfo)
  353. return false;
  354. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
  355. return false;
  356. $CNF = &$this->_oConfig->CNF;
  357. $aFans = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])->getConnectedContent($oGroupProfile->id(), true);
  358. if(empty($aFans) || !is_array($aFans))
  359. return false;
  360. $aAdmins = $this->_oDb->getAdmins($oGroupProfile->id());
  361. if(!empty($aAdmins) && is_array($aAdmins))
  362. $aFans = array_diff($aFans, $aAdmins);
  363. $iStart = (int)bx_get('start');
  364. $iLimit = !empty($CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($CNF['PARAM_NUM_CONNECTIONS_QUICK']) : 4;
  365. if(!$iLimit)
  366. $iLimit = 4;
  367. return $this->_serviceBrowseQuick($aFans, $iStart, $iLimit);
  368. }
  369. public function serviceAdmins ($iContentId = 0)
  370. {
  371. $CNF = &$this->_oConfig->CNF;
  372. if(!$iContentId)
  373. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  374. if(!$iContentId)
  375. return false;
  376. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  377. if(!$oGroupProfile)
  378. return false;
  379. $iStart = (int)bx_get('start');
  380. $iLimit = !empty($CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($CNF['PARAM_NUM_CONNECTIONS_QUICK']) : 4;
  381. if(!$iLimit)
  382. $iLimit = 4;
  383. $aProfiles = $this->_oDb->getAdmins($oGroupProfile->id(), $iStart, $iLimit+1);
  384. if(empty($aProfiles) || !is_array($aProfiles))
  385. return false;
  386. return $this->_serviceBrowseQuick($aProfiles, $iStart, $iLimit);
  387. }
  388. public function serviceBrowseJoinedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  389. {
  390. if (!$iProfileId)
  391. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  392. if (!$iProfileId)
  393. return '';
  394. return $this->_serviceBrowse ('joined_entries', array('joined_profile' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  395. }
  396. public function serviceBrowseCreatedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  397. {
  398. if (!$iProfileId)
  399. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  400. if (!$iProfileId)
  401. return '';
  402. return $this->_serviceBrowse ('created_entries', array('author' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  403. }
  404. public function serviceEntityPricing($iProfileId = 0)
  405. {
  406. $CNF = &$this->_oConfig->CNF;
  407. if(!$iProfileId)
  408. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  409. if(!$iProfileId)
  410. return '';
  411. if(!$this->_oConfig->isPaidJoin())
  412. return '';
  413. if($this->checkAllowedManageAdmins($iProfileId) !== CHECK_ACTION_RESULT_ALLOWED)
  414. return MsgBox(_t('_Access denied'));
  415. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_PRICES_MANAGE']);
  416. if(!$oGrid)
  417. return '';
  418. return $oGrid->getCode();
  419. }
  420. public function serviceEntityJoin($iProfileId = 0)
  421. {
  422. $CNF = &$this->_oConfig->CNF;
  423. if(!$iProfileId)
  424. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  425. if(!$iProfileId)
  426. return '';
  427. if(!$this->_oConfig->isPaidJoin())
  428. return '';
  429. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_PRICES_VIEW']);
  430. if(!$oGrid)
  431. return '';
  432. return $oGrid->getCode();
  433. }
  434. public function serviceEntityInvite ($iContentId = 0, $bErrorMsg = true)
  435. {
  436. if (isset($this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_INVITE']))
  437. return $this->_serviceEntityForm ('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_INVITE'], false, $bErrorMsg);
  438. return false;
  439. }
  440. /**
  441. * Entry social sharing block
  442. */
  443. public function serviceEntitySocialSharing ($mixedContent = false, $aParams = array())
  444. {
  445. if(!empty($mixedContent)) {
  446. if(!is_array($mixedContent))
  447. $mixedContent = array((int)$mixedContent, array());
  448. }
  449. else {
  450. $mixedContent = $this->_getContent();
  451. if($mixedContent === false)
  452. return false;
  453. }
  454. list($iContentId, $aContentInfo) = $mixedContent;
  455. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  456. if(!$oGroupProfile)
  457. return false;
  458. return parent::serviceEntitySocialSharing(array($iContentId, $aContentInfo), array(
  459. 'title' => $oGroupProfile->getDisplayName()
  460. ));
  461. }
  462. public function serviceIsPricingAvaliable($iProfileId)
  463. {
  464. if(!$this->_oConfig->isPaidJoin())
  465. return false;
  466. if($this->checkAllowedManageAdmins($iProfileId) !== CHECK_ACTION_RESULT_ALLOWED)
  467. return false;
  468. return true;
  469. }
  470. public function serviceIsPaidJoinAvaliable($iProfileId)
  471. {
  472. return $this->isPaidJoinByProfile($iProfileId);
  473. }
  474. public function serviceIsPaidJoinAvaliableByContent($iContentId)
  475. {
  476. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  477. if(!$oProfile)
  478. return false;
  479. return $this->isPaidJoinByProfile($oProfile->id());
  480. }
  481. public function serviceIsFreeJoinAvaliable($iProfileId)
  482. {
  483. return !$this->isPaidJoinByProfile($iProfileId);
  484. }
  485. public function serviceIsFreeJoinAvaliableByContent($iContentId)
  486. {
  487. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  488. if(!$oProfile)
  489. return false;
  490. return !$this->isPaidJoinByProfile($oProfile->id());
  491. }
  492. public function isPaidJoinByProfile($iProfileId)
  493. {
  494. if(!$this->_oConfig->isPaidJoin())
  495. return false;
  496. $aPrices = $this->_oDb->getPrices(array('type' => 'by_profile_id', 'profile_id' => $iProfileId));
  497. if(empty($aPrices) || !is_array($aPrices))
  498. return false;
  499. return true;
  500. }
  501. /**
  502. * Integration with Payments.
  503. */
  504. public function serviceGetPaymentData()
  505. {
  506. return $this->_aModule;
  507. }
  508. public function serviceGetCartItem($mixedItemId)
  509. {
  510. $CNF = &$this->_oConfig->CNF;
  511. if(!$mixedItemId)
  512. return array();
  513. if(is_numeric($mixedItemId))
  514. $aItem = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => (int)$mixedItemId));
  515. else
  516. $aItem = $this->_oDb->getPrices(array('type' => 'by_name', 'value' => $mixedItemId));
  517. if(empty($aItem) || !is_array($aItem))
  518. return array();
  519. if(!$this->isPaidJoinByProfile($aItem['profile_id']))
  520. return array();
  521. $oGroupProfile = BxDolProfile::getInstance($aItem['profile_id']);
  522. if(!$oGroupProfile)
  523. return array();
  524. $aGroupProfile = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  525. $aRoles = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_ROLES']);
  526. return array (
  527. 'id' => $aItem['id'],
  528. 'author_id' => $aGroupProfile[$CNF['FIELD_AUTHOR']],
  529. 'name' => $aItem['name'],
  530. 'title' => _t($CNF['T']['txt_cart_item_title'], $oGroupProfile->getDisplayName(), $aRoles[$aItem['role_id']], $aItem['period'], $aItem['period_unit']),
  531. 'description' => '',
  532. 'url' => $oGroupProfile->getUrl(),
  533. 'price_single' => $aItem['price'],
  534. 'price_recurring' => $aItem['price'],
  535. 'period_recurring' => $aItem['period'],
  536. 'period_unit_recurring' => $aItem['period_unit']
  537. );
  538. }
  539. public function serviceGetCartItems($iSellerId)
  540. {
  541. $CNF = &$this->_oConfig->CNF;
  542. if(empty($iSellerId))
  543. return array();
  544. $sModule = $this->getName();
  545. $aRoles = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_ROLES']);
  546. $aGroups = $this->_oDb->getEntriesBy(array('type' => 'author', 'author' => $iSellerId));
  547. $aResult = array();
  548. foreach($aGroups as $aGroup) {
  549. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aGroup[$CNF['FIELD_ID']], $sModule);
  550. if(!$oGroupProfile)
  551. continue;
  552. $aPrices = $this->_oDb->getPrices(array('type' => 'by_profile_id', 'profile_id' => $oGroupProfile->id()));
  553. if(empty($aPrices) || !is_array($aPrices))
  554. continue;
  555. $sTitle = $oGroupProfile->getDisplayName();
  556. $sUrl = $oGroupProfile->getUrl();
  557. foreach($aPrices as $aPrice)
  558. $aResult[] = array(
  559. 'id' => $aPrice['id'],
  560. 'author_id' => $iSellerId,
  561. 'name' => $aPrice['name'],
  562. 'title' => _t($CNF['T']['txt_cart_item_title'], $sTitle, $aRoles[$aPrice['role_id']], $aPrice['period'], $aPrice['period_unit']),
  563. 'description' => '',
  564. 'url' => $sUrl,
  565. 'price_single' => $aPrice['price'],
  566. 'price_recurring' => $aPrice['price'],
  567. 'period_recurring' => $aPrice['period'],
  568. 'period_unit_recurring' => $aPrice['period_unit']
  569. );
  570. }
  571. return $aResult;
  572. }
  573. public function serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  574. {
  575. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  576. }
  577. public function serviceRegisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  578. {
  579. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  580. }
  581. public function serviceReregisterCartItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  582. {
  583. return $this->_serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder);
  584. }
  585. public function serviceReregisterSubscriptionItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  586. {
  587. return $this->_serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder);
  588. }
  589. public function serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  590. {
  591. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  592. }
  593. public function serviceUnregisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  594. {
  595. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  596. }
  597. public function serviceCancelSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  598. {
  599. return true;
  600. }
  601. protected function _serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  602. {
  603. $CNF = &$this->_oConfig->CNF;
  604. $aItem = $this->serviceGetCartItem($iItemId);
  605. if(empty($aItem) || !is_array($aItem))
  606. return array();
  607. $aItemInfo = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemId));
  608. $mixedPeriod = false;
  609. if((int)$aItemInfo['period'] != 0)
  610. $mixedPeriod = array(
  611. 'period' => (int)$aItemInfo['period'],
  612. 'period_unit' => $aItemInfo['period_unit'],
  613. 'period_reserve' => $CNF['PARAM_RECURRING_RESERVE']
  614. );
  615. if(!$this->setRole($aItemInfo['profile_id'], $iClientId, $aItemInfo['role_id'], $mixedPeriod, $sOrder))
  616. return array();
  617. return $aItem;
  618. }
  619. protected function _serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  620. {
  621. $aItem = $this->serviceGetCartItem($iItemIdNew);
  622. if(empty($aItem) || !is_array($aItem))
  623. return array();
  624. $aItemInfoOld = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemIdOld));
  625. if(empty($aItemInfoOld) || !is_array($aItemInfoOld))
  626. return array();
  627. $aItemInfoNew = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemIdNew));
  628. if(empty($aItemInfoNew) || !is_array($aItemInfoNew))
  629. return array();
  630. if(!$this->unsetRole($aItemInfoOld['profile_id'], $iClientId))
  631. return array();
  632. $aResult = $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemIdNew, 1, $sOrder);
  633. if(empty($aResult) || !is_array($aResult))
  634. return array();
  635. return $aItem;
  636. }
  637. protected function _serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  638. {
  639. $aItemInfo = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemId));
  640. if(empty($aItemInfo) || !is_array($aItemInfo))
  641. return false;
  642. return $this->unsetRole($aItemInfo['profile_id'], $iClientId);
  643. }
  644. /**
  645. * Data for Notifications module
  646. */
  647. public function serviceGetNotificationsData()
  648. {
  649. $sModule = $this->_aModule['name'];
  650. $aSettingsTypes = array('follow_member', 'follow_context');
  651. if($this->serviceActAsProfile())
  652. $aSettingsTypes = array('personal', 'follow_member');
  653. return array(
  654. 'handlers' => array(
  655. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  656. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  657. array('group' => $sModule . '_score_up', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteUp', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_up', 'module_class' => 'Module'),
  658. array('group' => $sModule . '_score_down', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteDown', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_down', 'module_class' => 'Module'),
  659. array('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'),
  660. array('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']),
  661. array('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'),
  662. ),
  663. 'settings' => array(
  664. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => $aSettingsTypes),
  665. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => $aSettingsTypes),
  666. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => $aSettingsTypes),
  667. array('group' => 'fan', 'unit' => $sModule, 'action' => 'fan_added', 'types' => $aSettingsTypes),
  668. array('group' => 'join', 'unit' => $sModule, 'action' => 'join_request', 'types' => $aSettingsTypes),
  669. array('group' => 'timeline_post', 'unit' => $sModule, 'action' => 'timeline_post_common', 'types' => $aSettingsTypes)
  670. ),
  671. 'alerts' => array(
  672. array('unit' => $sModule, 'action' => 'doVote'),
  673. array('unit' => $sModule, 'action' => 'undoVote'),
  674. array('unit' => $sModule, 'action' => 'doVoteUp'),
  675. array('unit' => $sModule, 'action' => 'doVoteDown'),
  676. array('unit' => $sModule, 'action' => 'fan_added'),
  677. array('unit' => $sModule, 'action' => 'join_request'),
  678. array('unit' => $sModule, 'action' => 'timeline_post_common'),
  679. )
  680. );
  681. }
  682. /**
  683. * Notification about new member requst in the group
  684. */
  685. public function serviceGetNotificationsJoinRequest($aEvent)
  686. {
  687. return $this->_serviceGetNotification($aEvent, $this->_oConfig->CNF['T']['txt_ntfs_join_request']);
  688. }
  689. /**
  690. * Notification about new member in the group
  691. */
  692. public function serviceGetNotificationsFanAdded($aEvent)
  693. {
  694. return $this->_serviceGetNotification($aEvent, $this->_oConfig->CNF['T']['txt_ntfs_fan_added']);
  695. }
  696. protected function _serviceGetNotification($aEvent, $sLangKey)
  697. {
  698. $CNF = &$this->_oConfig->CNF;
  699. $iContentId = (int)$aEvent['object_id'];
  700. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  701. if(!$oGroupProfile)
  702. return array();
  703. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  704. if(empty($aContentInfo) || !is_array($aContentInfo))
  705. return array();
  706. $oProfile = BxDolProfile::getInstance((int)$aEvent['subobject_id']);
  707. if(!$oProfile)
  708. return array();
  709. /*
  710. * Note. Group Profile URL is used for both Entry and Subentry URLs,
  711. * because Subentry URL has higher display priority and notification
  712. * should be linked to Group Profile (Group Profile -> Members tab)
  713. * instead of Personal Profile of a member, who performed an action.
  714. */
  715. $sEntryUrl = $oGroupProfile->getUrl();
  716. if(!empty($CNF['URL_ENTRY_FANS']))
  717. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_ENTRY_FANS'], array(
  718. 'profile_id' => $oGroupProfile->id()
  719. ));
  720. return array(
  721. 'entry_sample' => $CNF['T']['txt_sample_single'],
  722. 'entry_url' => $sEntryUrl,
  723. 'entry_caption' => $oGroupProfile->getDisplayName(),
  724. 'entry_author' => $oGroupProfile->id(),
  725. 'subentry_sample' => $oProfile->getDisplayName(),
  726. 'subentry_url' => $sEntryUrl,
  727. 'lang_key' => $sLangKey
  728. );
  729. }
  730. /**
  731. * Data for Timeline module
  732. */
  733. public function serviceGetTimelineData()
  734. {
  735. return BxBaseModGeneralModule::serviceGetTimelineData();
  736. }
  737. /**
  738. * Entry post for Timeline module
  739. */
  740. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  741. {
  742. $a = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  743. if($a === false)
  744. return false;
  745. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aEvent['object_id'], $this->getName());
  746. $a['content']['url'] = $oGroupProfile->getUrl();
  747. $a['content']['title'] = $oGroupProfile->getDisplayName();
  748. return $a;
  749. }
  750. // ====== PERMISSION METHODS
  751. /**
  752. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  753. */
  754. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  755. {
  756. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  757. }
  758. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  759. {
  760. $CNF = &$this->_oConfig->CNF;
  761. $bInvited = false;
  762. if(!empty($CNF['TABLE_INVITES']) && bx_get('key')){
  763. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  764. $mixedInvited = $this->isInvited(bx_get('key'), $oGroupProfile->id());
  765. if($mixedInvited === true)
  766. $bInvited = true;
  767. }
  768. if ($this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $iProfileId) || $bInvited)
  769. return CHECK_ACTION_RESULT_ALLOWED;
  770. return parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  771. }
  772. /**
  773. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  774. */
  775. public function checkAllowedCompose(&$aDataEntry, $isPerformAction = false)
  776. {
  777. if(!$this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]))
  778. return _t('_sys_txt_access_denied');
  779. return parent::checkAllowedCompose ($aDataEntry, $isPerformAction);
  780. }
  781. /**
  782. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  783. */
  784. public function checkAllowedFanAdd(&$aDataEntry, $isPerformAction = false)
  785. {
  786. $mixedResult = $this->_modGroupsCheckAllowedFanAdd($aDataEntry, $isPerformAction);
  787. // call alert to allow custom checks
  788. bx_alert('system', 'check_allowed_fan_add', 0, 0, array(
  789. 'module' => $this->getName(),
  790. 'content_info' => $aDataEntry,
  791. 'profile_id' => bx_get_logged_profile_id(),
  792. 'override_result' => &$mixedResult
  793. ));
  794. return $mixedResult;
  795. }
  796. public function _modGroupsCheckAllowedFanAdd (&$aDataEntry, $isPerformAction = false)
  797. {
  798. if ($this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]) || !isLogged())
  799. return _t('_sys_txt_access_denied');
  800. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], true, false);
  801. }
  802. /**
  803. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  804. */
  805. public function checkAllowedFanRemove (&$aDataEntry, $isPerformAction = false)
  806. {
  807. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, true))
  808. return CHECK_ACTION_RESULT_ALLOWED;
  809. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, false);
  810. }
  811. protected function _checkAllowedActionByFan($sAction, $aDataEntry, $iProfileId = 0)
  812. {
  813. $CNF = &$this->_oConfig->CNF;
  814. $bRoles = $this->_oConfig->isRoles();
  815. if(empty($iProfileId))
  816. $iProfileId = bx_get_logged_profile_id();
  817. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  818. if(!$oGroupProfile)
  819. return $sAction == BX_BASE_MOD_GROUPS_ACTION_DELETE ? CHECK_ACTION_RESULT_ALLOWED : _t('_sys_txt_not_found');
  820. $iGroupProfileId = $oGroupProfile->id();
  821. if(!$bRoles && $this->_oDb->isAdmin($iGroupProfileId, $iProfileId, $aDataEntry))
  822. return CHECK_ACTION_RESULT_ALLOWED;
  823. if($bRoles && $this->isAllowedActionByRole($sAction, $aDataEntry, $iGroupProfileId, $iProfileId))
  824. return CHECK_ACTION_RESULT_ALLOWED;
  825. return _t('_sys_txt_access_denied');
  826. }
  827. public function isAllowedActionByRole($sAction, $aDataEntry, $iGroupProfileId, $iProfileId)
  828. {
  829. $bResult = false;
  830. $iProfileRole = $this->_oDb->getRole($iGroupProfileId, $iProfileId);
  831. if(!empty($iProfileRole))
  832. switch($sAction) {
  833. case BX_BASE_MOD_GROUPS_ACTION_MANAGE_ROLES:
  834. if($this->isRole($iProfileRole, BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR))
  835. $bResult = true;
  836. break;
  837. default:
  838. $bResult = true;
  839. }
  840. // call alert to allow custom checks
  841. bx_alert('system', 'check_allowed_action_by_role', 0, 0, array(
  842. 'module' => $this->getName(),
  843. 'multi_roles' => $this->_oConfig->isMultiRoles(),
  844. 'action' => $sAction,
  845. 'content_profile_id' => $iGroupProfileId,
  846. 'content_info' => $aDataEntry,
  847. 'profile_id' => $iProfileId,
  848. 'profile_role' => $iProfileRole,
  849. 'override_result' => &$bResult
  850. ));
  851. return $bResult;
  852. }
  853. public function isRole($iProfileRole, $iRole)
  854. {
  855. if(!$this->_oConfig->isMultiRoles())
  856. return $iProfileRole == $iRole;
  857. else
  858. return $iProfileRole & (1 << ($iRole - 1));
  859. }
  860. public function serviceIsRole($iProfileRole, $iRole)
  861. {
  862. return $this->isRole($iProfileRole, $iRole);
  863. }
  864. public function checkAllowedManageFans($mixedDataEntry, $isPerformAction = false)
  865. {
  866. $aDataEntry = array();
  867. if(!is_array($mixedDataEntry)) {
  868. $oGroupProfile = BxDolProfile::getInstance((int)$mixedDataEntry);
  869. if($oGroupProfile && $this->getName() == $oGroupProfile->getModule())
  870. $aDataEntry = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  871. }
  872. else
  873. $aDataEntry = $mixedDataEntry;
  874. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_MANAGE_FANS, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  875. return CHECK_ACTION_RESULT_ALLOWED;
  876. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  877. }
  878. public function checkAllowedManageAdmins($mixedDataEntry, $isPerformAction = false)
  879. {
  880. $aDataEntry = array();
  881. if(!is_array($mixedDataEntry)) {
  882. $oGroupProfile = BxDolProfile::getInstance((int)$mixedDataEntry);
  883. if($oGroupProfile && $this->getName() == $oGroupProfile->getModule())
  884. $aDataEntry = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  885. }
  886. else
  887. $aDataEntry = $mixedDataEntry;
  888. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_MANAGE_ROLES, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  889. return CHECK_ACTION_RESULT_ALLOWED;
  890. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  891. }
  892. public function checkAllowedEdit($aDataEntry, $isPerformAction = false)
  893. {
  894. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_EDIT, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  895. return CHECK_ACTION_RESULT_ALLOWED;
  896. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  897. }
  898. public function checkAllowedInvite($aDataEntry, $isPerformAction = false)
  899. {
  900. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_INVITE, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  901. return CHECK_ACTION_RESULT_ALLOWED;
  902. return $this->checkAllowedEdit ($aDataEntry, $isPerformAction);
  903. }
  904. public function checkAllowedChangeCover($aDataEntry, $isPerformAction = false)
  905. {
  906. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_CHANGE_COVER, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  907. return CHECK_ACTION_RESULT_ALLOWED;
  908. return parent::checkAllowedChangeCover($aDataEntry, $isPerformAction);
  909. }
  910. public function checkAllowedDelete(&$aDataEntry, $isPerformAction = false)
  911. {
  912. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_DELETE, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  913. return CHECK_ACTION_RESULT_ALLOWED;
  914. return parent::checkAllowedDelete($aDataEntry, $isPerformAction);
  915. }
  916. public function checkAllowedJoin(&$aDataEntry, $isPerformAction = false)
  917. {
  918. if (bx_get('key')){
  919. $sKey = bx_get('key');
  920. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  921. $aData = $this->_oDb->getInviteByKey($sKey, $oGroupProfile->id());
  922. if (isset($aData['invited_profile_id']) && $aData['invited_profile_id'] == bx_get_logged_profile_id()){
  923. return CHECK_ACTION_RESULT_ALLOWED;
  924. }
  925. }
  926. return _t('_sys_txt_access_denied');
  927. }
  928. public function checkAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  929. {
  930. $mixedResult = $this->_modGroupsCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  931. // call alert to allow custom checks
  932. bx_alert('system', 'check_allowed_subscribe_add', 0, 0, array(
  933. 'module' => $this->getName(),
  934. 'content_info' => $aDataEntry,
  935. 'profile_id' => bx_get_logged_profile_id(),
  936. 'override_result' => &$mixedResult
  937. ));
  938. return $mixedResult;
  939. }
  940. /**
  941. * Note. Is mainly needed for internal usage. Access level is 'public' to allow outer calls from alerts.
  942. */
  943. public function _modGroupsCheckAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  944. {
  945. if(!$this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]))
  946. return _t('_sys_txt_access_denied');
  947. return parent::_modProfileCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  948. }
  949. /**
  950. * @deprecated since version 11.0.3 and can be removed in the next version.
  951. */
  952. public function _checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  953. {
  954. return parent::checkAllowedSubscribeAdd ($aDataEntry, $isPerformAction);
  955. }
  956. public function doAudit($iGroupProfileId, $iFanId, $sAction)
  957. {
  958. $oProfile = BxDolProfile::getInstance($iFanId);
  959. $iContentId = $oProfile->getContentId();
  960. $sModule = $oProfile->getModule();
  961. $oModule = BxDolModule::getInstance($sModule);
  962. if (BxDolRequest::serviceExists($sModule, 'act_as_profile') && BxDolService::call($sModule, 'act_as_profile') && $oModule->_oConfig){
  963. $CNF = $oModule->_oConfig->CNF;
  964. $aContentInfo = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $iContentId))) : array();
  965. $AuditParams = array(
  966. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  967. 'context_profile_id' => $iGroupProfileId,
  968. 'context_profile_title' => BxDolProfile::getInstance($iGroupProfileId)->getDisplayName()
  969. );
  970. bx_audit(
  971. $iContentId,
  972. $sModule,
  973. $sAction,
  974. $AuditParams
  975. );
  976. }
  977. }
  978. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  979. {
  980. $sResult = $this->checkAllowedView($aDataEntry);
  981. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  982. // if profile view isn't allowed but visibility is in partially visible groups
  983. // then display buttons to connect (befriend, join) to profile,
  984. // if other conditions (in parent::_checkAllowedConnect) are met as well
  985. if (CHECK_ACTION_RESULT_ALLOWED !== $sResult && !in_array($aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']], array_merge($oPrivacy->getPartiallyVisiblePrivacyGroups(), array('s'))))
  986. return $sResult;
  987. return parent::_checkAllowedConnect ($aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap);
  988. }
  989. public function addFollower ($iProfileId1, $iProfileId2)
  990. {
  991. $oConnectionFollow = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  992. if($oConnectionFollow && !$oConnectionFollow->isConnected($iProfileId1, $iProfileId2)){
  993. $oConnectionFollow->addConnection($iProfileId1, $iProfileId2);
  994. return true;
  995. }
  996. return false;
  997. }
  998. public function isFan ($iContentId, $iProfileId = false)
  999. {
  1000. $CNF = &$this->_oConfig->CNF;
  1001. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  1002. if($oGroupProfile && isset($CNF['OBJECT_CONNECTIONS']))
  1003. return ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $oGroupProfile->id(), true);
  1004. return false;
  1005. }
  1006. public function isFanByGroupProfileId ($iGroupProfileId, $iProfileId = false)
  1007. {
  1008. $CNF = &$this->_oConfig->CNF;
  1009. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1010. if($oGroupProfile && isset($CNF['OBJECT_CONNECTIONS']))
  1011. return ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $oGroupProfile->id(), true);
  1012. return false;
  1013. }
  1014. public function isInvited ($sKey, $iProfileId)
  1015. {
  1016. $CNF = &$this->_oConfig->CNF;
  1017. $aData = $this->_oDb->getInviteByKey($sKey, $iProfileId);
  1018. if (!isset($aData['invited_profile_id']))
  1019. return _t($CNF['T']['txt_invitation_popup_error_invitation_absent']);
  1020. if ($aData['invited_profile_id'] != bx_get_logged_profile_id())
  1021. return _t($CNF['T']['txt_invitation_popup_error_wrong_user']);
  1022. return true;
  1023. }
  1024. public function getRole($iGroupProfileId, $iFanProfileId)
  1025. {
  1026. if(!$this->isFanByGroupProfileId($iGroupProfileId, $iFanProfileId))
  1027. return false;
  1028. return $this->_oDb->getRole($iGroupProfileId, $iFanProfileId);
  1029. }
  1030. public function setRole($iGroupProfileId, $iFanProfileId, $mixedRole, $mixedPeriod = false, $sOrder = '')
  1031. {
  1032. $CNF = &$this->_oConfig->CNF;
  1033. if(!isset($CNF['OBJECT_CONNECTIONS']))
  1034. return false;
  1035. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  1036. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1037. if(!$oConnection || !$oGroupProfile)
  1038. return false;
  1039. if(!$oConnection->isConnected($iFanProfileId, $iGroupProfileId, true) && !($oConnection->addConnection($iFanProfileId, $iGroupProfileId) && $oConnection->addConnection($iGroupProfileId, $iFanProfileId)))
  1040. return false;
  1041. if(!$this->_oDb->setRole($iGroupProfileId, $iFanProfileId, $mixedRole, $mixedPeriod, $sOrder))
  1042. return false;
  1043. $this->onSetRole($iGroupProfileId, $iFanProfileId, $mixedRole);
  1044. return true;
  1045. }
  1046. public function onSetRole($iGroupProfileId, $iFanProfileId, $mixedRole)
  1047. {
  1048. $CNF = &$this->_oConfig->CNF;
  1049. $iProfileId = bx_get_logged_profile_id();
  1050. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1051. $aGroupProfileInfo = $this->_oDb->getContentInfoById((int)$oGroupProfile->getContentId());
  1052. $aRoles = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_ROLES']);
  1053. // notify about admin status
  1054. if(!empty($CNF['EMAIL_FAN_SET_ROLE']) && $iFanProfileId != $iProfileId)
  1055. sendMailTemplate($CNF['EMAIL_FAN_SET_ROLE'], 0, $iFanProfileId, array(
  1056. 'EntryUrl' => $oGroupProfile->getUrl(),
  1057. 'EntryTitle' => $oGroupProfile->getDisplayName(),
  1058. 'Role' => !is_array($mixedRole) ? $aRoles[(int)$mixedRole] : 'TODO: Add List of Roles'
  1059. ), BX_EMAIL_NOTIFY);
  1060. bx_alert($this->getName(), 'set_role', $aGroupProfileInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  1061. 'object_author_id' => $iGroupProfileId,
  1062. 'performer_id' => $iProfileId,
  1063. 'fan_id' => $iFanProfileId,
  1064. 'content' => $aGroupProfileInfo,
  1065. 'role' => $mixedRole,
  1066. 'group_profile' => $iGroupProfileId,
  1067. 'profile' => $iProfileId
  1068. ));
  1069. $this->doAudit($iGroupProfileId, $iFanProfileId, '_sys_audit_action_group_role_changed');
  1070. }
  1071. public function unsetRole($iGroupProfileId, $iFanProfileId)
  1072. {
  1073. $CNF = &$this->_oConfig->CNF;
  1074. if(!isset($CNF['OBJECT_CONNECTIONS']))
  1075. return false;
  1076. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  1077. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1078. if(!$oConnection || !$oGroupProfile)
  1079. return false;
  1080. if($oConnection->isConnected($iFanProfileId, $iGroupProfileId, true) && !$oConnection->removeConnection($iFanProfileId, $iGroupProfileId))
  1081. return false;
  1082. $iRole = $this->_oDb->getRole($iGroupProfileId, $iFanProfileId);
  1083. if(!$this->_oDb->unsetRole($iGroupProfileId, $iFanProfileId))
  1084. return false;
  1085. $this->onUnsetRole($iGroupProfileId, $iFanProfileId, $iRole);
  1086. return true;
  1087. }
  1088. public function onUnsetRole($iGroupProfileId, $iFanProfileId, $iRole)
  1089. {
  1090. $CNF = &$this->_oConfig->CNF;
  1091. $iProfileId = bx_get_logged_profile_id();
  1092. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1093. $aGroupProfileInfo = $this->_oDb->getContentInfoById((int)$oGroupProfile->getContentId());
  1094. bx_alert($this->getName(), 'set_role', $aGroupProfileInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  1095. 'object_author_id' => $iGroupProfileId,
  1096. 'performer_id' => $iProfileId,
  1097. 'fan_id' => $iFanProfileId,
  1098. 'content' => $aGroupProfileInfo,
  1099. 'role' => $iRole,
  1100. 'group_profile' => $iGroupProfileId,
  1101. 'profile' => $iProfileId
  1102. ));
  1103. $this->doAudit($iGroupProfileId, $iFanProfileId, '_sys_audit_action_group_role_changed');
  1104. }
  1105. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1106. {
  1107. $CNF = &$this->_oConfig->CNF;
  1108. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aEvent['object_id'], $this->getName());
  1109. $sSrc = '';
  1110. if(isset($CNF['FIELD_COVER']) && !empty($aContentInfo[$CNF['FIELD_COVER']]))
  1111. $sSrc = $oGroupProfile->getCover();
  1112. if(empty($sSrc) && isset($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]))
  1113. $sSrc = $oGroupProfile->getPicture();
  1114. return empty($sSrc) ? array() : array(
  1115. array('id' => $aContentInfo[$CNF['FIELD_PICTURE']], 'url' => $sUrl, 'src' => $sSrc, 'src_orig' => $sSrc),
  1116. );
  1117. }
  1118. protected function _prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId)
  1119. {
  1120. if (!($oGroupProfile = BxDolProfile::getInstance($iGroupProfileId)))
  1121. return array(0, 0, null);
  1122. if ($oGroupProfile->getModule() == $this->getName()) {
  1123. $iProfileId = $iInitiatorId;
  1124. $iGroupProfileId = $oGroupProfile->id();
  1125. } else {
  1126. $iProfileId = $oGroupProfile->id();
  1127. $iGroupProfileId = $iInitiatorId;
  1128. }
  1129. return array($iProfileId, $iGroupProfileId, $oGroupProfile);
  1130. }
  1131. }
  1132. /** @} */