BxBaseModGroupsModule.php 63 KB

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