1
0

BxBaseModGroupsModule.php 53 KB

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