BxBaseModGroupsModule.php 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361
  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 serviceAdmins ($iContentId = 0)
  325. {
  326. $CNF = &$this->_oConfig->CNF;
  327. if(!$iContentId)
  328. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  329. if(!$iContentId)
  330. return false;
  331. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  332. if(!$oGroupProfile)
  333. return false;
  334. $iStart = (int)bx_get('start');
  335. $iLimit = !empty($CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($CNF['PARAM_NUM_CONNECTIONS_QUICK']) : 4;
  336. if(!$iLimit)
  337. $iLimit = 4;
  338. $aProfiles = $this->_oDb->getAdmins($oGroupProfile->id(), $iStart, $iLimit+1);
  339. if(empty($aProfiles) || !is_array($aProfiles))
  340. return false;
  341. return $this->_serviceBrowseQuick($aProfiles, $iStart, $iLimit);
  342. }
  343. public function serviceBrowseJoinedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  344. {
  345. if (!$iProfileId)
  346. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  347. if (!$iProfileId)
  348. return '';
  349. return $this->_serviceBrowse ('joined_entries', array('joined_profile' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  350. }
  351. public function serviceBrowseCreatedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  352. {
  353. if (!$iProfileId)
  354. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  355. if (!$iProfileId)
  356. return '';
  357. return $this->_serviceBrowse ('created_entries', array('author' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  358. }
  359. public function serviceEntityPricing($iProfileId = 0)
  360. {
  361. $CNF = &$this->_oConfig->CNF;
  362. if(!$iProfileId)
  363. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  364. if(!$iProfileId)
  365. return '';
  366. if(!$this->_oConfig->isPaidJoin())
  367. return '';
  368. if($this->checkAllowedManageAdmins($iProfileId) !== CHECK_ACTION_RESULT_ALLOWED)
  369. return MsgBox(_t('_Access denied'));
  370. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_PRICES_MANAGE']);
  371. if(!$oGrid)
  372. return '';
  373. return $oGrid->getCode();
  374. }
  375. public function serviceEntityJoin($iProfileId = 0)
  376. {
  377. $CNF = &$this->_oConfig->CNF;
  378. if(!$iProfileId)
  379. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  380. if(!$iProfileId)
  381. return '';
  382. if(!$this->_oConfig->isPaidJoin())
  383. return '';
  384. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_PRICES_VIEW']);
  385. if(!$oGrid)
  386. return '';
  387. return $oGrid->getCode();
  388. }
  389. public function serviceEntityInvite ($iContentId = 0, $bErrorMsg = true)
  390. {
  391. if (isset($this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_INVITE']))
  392. return $this->_serviceEntityForm ('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_INVITE'], false, $bErrorMsg);
  393. return false;
  394. }
  395. /**
  396. * Entry social sharing block
  397. */
  398. public function serviceEntitySocialSharing ($mixedContent = false, $aParams = array())
  399. {
  400. if(!empty($mixedContent)) {
  401. if(!is_array($mixedContent))
  402. $mixedContent = array((int)$mixedContent, array());
  403. }
  404. else {
  405. $mixedContent = $this->_getContent();
  406. if($mixedContent === false)
  407. return false;
  408. }
  409. list($iContentId, $aContentInfo) = $mixedContent;
  410. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  411. if(!$oGroupProfile)
  412. return false;
  413. return parent::serviceEntitySocialSharing(array($iContentId, $aContentInfo), array(
  414. 'title' => $oGroupProfile->getDisplayName()
  415. ));
  416. }
  417. public function serviceIsPricingAvaliable($iProfileId)
  418. {
  419. if(!$this->_oConfig->isPaidJoin())
  420. return false;
  421. if($this->checkAllowedManageAdmins($iProfileId) !== CHECK_ACTION_RESULT_ALLOWED)
  422. return false;
  423. return true;
  424. }
  425. public function serviceIsPaidJoinAvaliable($iProfileId)
  426. {
  427. return $this->isPaidJoinByProfile($iProfileId);
  428. }
  429. public function serviceIsPaidJoinAvaliableByContent($iContentId)
  430. {
  431. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  432. if(!$oProfile)
  433. return false;
  434. return $this->isPaidJoinByProfile($oProfile->id());
  435. }
  436. public function serviceIsFreeJoinAvaliable($iProfileId)
  437. {
  438. return !$this->isPaidJoinByProfile($iProfileId);
  439. }
  440. public function serviceIsFreeJoinAvaliableByContent($iContentId)
  441. {
  442. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  443. if(!$oProfile)
  444. return false;
  445. return !$this->isPaidJoinByProfile($oProfile->id());
  446. }
  447. public function isPaidJoinByProfile($iProfileId)
  448. {
  449. if(!$this->_oConfig->isPaidJoin())
  450. return false;
  451. $aPrices = $this->_oDb->getPrices(array('type' => 'by_profile_id', 'profile_id' => $iProfileId));
  452. if(empty($aPrices) || !is_array($aPrices))
  453. return false;
  454. return true;
  455. }
  456. /**
  457. * Integration with Payments.
  458. */
  459. public function serviceGetPaymentData()
  460. {
  461. return $this->_aModule;
  462. }
  463. public function serviceGetCartItem($mixedItemId)
  464. {
  465. $CNF = &$this->_oConfig->CNF;
  466. if(!$mixedItemId)
  467. return array();
  468. if(is_numeric($mixedItemId))
  469. $aItem = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => (int)$mixedItemId));
  470. else
  471. $aItem = $this->_oDb->getPrices(array('type' => 'by_name', 'value' => $mixedItemId));
  472. if(empty($aItem) || !is_array($aItem))
  473. return array();
  474. if(!$this->isPaidJoinByProfile($aItem['profile_id']))
  475. return array();
  476. $oGroupProfile = BxDolProfile::getInstance($aItem['profile_id']);
  477. if(!$oGroupProfile)
  478. return array();
  479. $aGroupProfile = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  480. $aRoles = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_ROLES']);
  481. return array (
  482. 'id' => $aItem['id'],
  483. 'author_id' => $aGroupProfile[$CNF['FIELD_AUTHOR']],
  484. 'name' => $aItem['name'],
  485. 'title' => _t($CNF['T']['txt_cart_item_title'], $oGroupProfile->getDisplayName(), $aRoles[$aItem['role_id']], $aItem['period'], $aItem['period_unit']),
  486. 'description' => '',
  487. 'url' => $oGroupProfile->getUrl(),
  488. 'price_single' => $aItem['price'],
  489. 'price_recurring' => $aItem['price'],
  490. 'period_recurring' => $aItem['period'],
  491. 'period_unit_recurring' => $aItem['period_unit']
  492. );
  493. }
  494. public function serviceGetCartItems($iSellerId)
  495. {
  496. $CNF = &$this->_oConfig->CNF;
  497. if(empty($iSellerId))
  498. return array();
  499. $sModule = $this->getName();
  500. $aRoles = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_ROLES']);
  501. $aGroups = $this->_oDb->getEntriesBy(array('type' => 'author', 'author' => $iSellerId));
  502. $aResult = array();
  503. foreach($aGroups as $aGroup) {
  504. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aGroup[$CNF['FIELD_ID']], $sModule);
  505. if(!$oGroupProfile)
  506. continue;
  507. $aPrices = $this->_oDb->getPrices(array('type' => 'by_profile_id', 'profile_id' => $oGroupProfile->id()));
  508. if(empty($aPrices) || !is_array($aPrices))
  509. continue;
  510. $sTitle = $oGroupProfile->getDisplayName();
  511. $sUrl = $oGroupProfile->getUrl();
  512. foreach($aPrices as $aPrice)
  513. $aResult[] = array(
  514. 'id' => $aPrice['id'],
  515. 'author_id' => $iSellerId,
  516. 'name' => $aPrice['name'],
  517. 'title' => _t($CNF['T']['txt_cart_item_title'], $sTitle, $aRoles[$aPrice['role_id']], $aPrice['period'], $aPrice['period_unit']),
  518. 'description' => '',
  519. 'url' => $sUrl,
  520. 'price_single' => $aPrice['price'],
  521. 'price_recurring' => $aPrice['price'],
  522. 'period_recurring' => $aPrice['period'],
  523. 'period_unit_recurring' => $aPrice['period_unit']
  524. );
  525. }
  526. return $aResult;
  527. }
  528. public function serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  529. {
  530. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  531. }
  532. public function serviceRegisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  533. {
  534. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  535. }
  536. public function serviceReregisterCartItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  537. {
  538. return $this->_serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder);
  539. }
  540. public function serviceReregisterSubscriptionItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  541. {
  542. return $this->_serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder);
  543. }
  544. public function serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  545. {
  546. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  547. }
  548. public function serviceUnregisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  549. {
  550. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  551. }
  552. public function serviceCancelSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  553. {
  554. return true;
  555. }
  556. protected function _serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  557. {
  558. $CNF = &$this->_oConfig->CNF;
  559. $aItem = $this->serviceGetCartItem($iItemId);
  560. if(empty($aItem) || !is_array($aItem))
  561. return array();
  562. $aItemInfo = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemId));
  563. $mixedPeriod = false;
  564. if((int)$aItemInfo['period'] != 0)
  565. $mixedPeriod = array(
  566. 'period' => (int)$aItemInfo['period'],
  567. 'period_unit' => $aItemInfo['period_unit'],
  568. 'period_reserve' => $CNF['PARAM_RECURRING_RESERVE']
  569. );
  570. if(!$this->setRole($aItemInfo['profile_id'], $iClientId, $aItemInfo['role_id'], $mixedPeriod, $sOrder))
  571. return array();
  572. return $aItem;
  573. }
  574. protected function _serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  575. {
  576. $aItem = $this->serviceGetCartItem($iItemIdNew);
  577. if(empty($aItem) || !is_array($aItem))
  578. return array();
  579. $aItemInfoOld = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemIdOld));
  580. if(empty($aItemInfoOld) || !is_array($aItemInfoOld))
  581. return array();
  582. $aItemInfoNew = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemIdNew));
  583. if(empty($aItemInfoNew) || !is_array($aItemInfoNew))
  584. return array();
  585. if(!$this->unsetRole($aItemInfoOld['profile_id'], $iClientId))
  586. return array();
  587. $aResult = $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemIdNew, 1, $sOrder);
  588. if(empty($aResult) || !is_array($aResult))
  589. return array();
  590. return $aItem;
  591. }
  592. protected function _serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  593. {
  594. $aItemInfo = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemId));
  595. if(empty($aItemInfo) || !is_array($aItemInfo))
  596. return false;
  597. return $this->unsetRole($aItemInfo['profile_id'], $iClientId);
  598. }
  599. /**
  600. * Data for Notifications module
  601. */
  602. public function serviceGetNotificationsData()
  603. {
  604. $sModule = $this->_aModule['name'];
  605. $aSettingsTypes = array('follow_member', 'follow_context');
  606. if($this->serviceActAsProfile())
  607. $aSettingsTypes = array('personal', 'follow_member');
  608. return array(
  609. 'handlers' => array(
  610. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  611. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  612. 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'),
  613. 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'),
  614. 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'),
  615. 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']),
  616. 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'),
  617. ),
  618. 'settings' => array(
  619. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => $aSettingsTypes),
  620. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => $aSettingsTypes),
  621. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => $aSettingsTypes),
  622. array('group' => 'fan', 'unit' => $sModule, 'action' => 'fan_added', 'types' => $aSettingsTypes),
  623. array('group' => 'join', 'unit' => $sModule, 'action' => 'join_request', 'types' => $aSettingsTypes),
  624. array('group' => 'timeline_post', 'unit' => $sModule, 'action' => 'timeline_post_common', 'types' => $aSettingsTypes)
  625. ),
  626. 'alerts' => array(
  627. array('unit' => $sModule, 'action' => 'doVote'),
  628. array('unit' => $sModule, 'action' => 'undoVote'),
  629. array('unit' => $sModule, 'action' => 'doVoteUp'),
  630. array('unit' => $sModule, 'action' => 'doVoteDown'),
  631. array('unit' => $sModule, 'action' => 'fan_added'),
  632. array('unit' => $sModule, 'action' => 'join_request'),
  633. array('unit' => $sModule, 'action' => 'timeline_post_common'),
  634. )
  635. );
  636. }
  637. /**
  638. * Notification about new member requst in the group
  639. */
  640. public function serviceGetNotificationsJoinRequest($aEvent)
  641. {
  642. return $this->_serviceGetNotification($aEvent, $this->_oConfig->CNF['T']['txt_ntfs_join_request']);
  643. }
  644. /**
  645. * Notification about new member in the group
  646. */
  647. public function serviceGetNotificationsFanAdded($aEvent)
  648. {
  649. return $this->_serviceGetNotification($aEvent, $this->_oConfig->CNF['T']['txt_ntfs_fan_added']);
  650. }
  651. protected function _serviceGetNotification($aEvent, $sLangKey)
  652. {
  653. $CNF = &$this->_oConfig->CNF;
  654. $iContentId = (int)$aEvent['object_id'];
  655. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  656. if(!$oGroupProfile)
  657. return array();
  658. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  659. if(empty($aContentInfo) || !is_array($aContentInfo))
  660. return array();
  661. $oProfile = BxDolProfile::getInstance((int)$aEvent['subobject_id']);
  662. if(!$oProfile)
  663. return array();
  664. /*
  665. * Note. Group Profile URL is used for both Entry and Subentry URLs,
  666. * because Subentry URL has higher display priority and notification
  667. * should be linked to Group Profile (Group Profile -> Members tab)
  668. * instead of Personal Profile of a member, who performed an action.
  669. */
  670. $sEntryUrl = $oGroupProfile->getUrl();
  671. if(!empty($CNF['URL_ENTRY_FANS']))
  672. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_ENTRY_FANS'], array(
  673. 'profile_id' => $oGroupProfile->id()
  674. ));
  675. return array(
  676. 'entry_sample' => $CNF['T']['txt_sample_single'],
  677. 'entry_url' => $sEntryUrl,
  678. 'entry_caption' => $oGroupProfile->getDisplayName(),
  679. 'entry_author' => $oGroupProfile->id(),
  680. 'subentry_sample' => $oProfile->getDisplayName(),
  681. 'subentry_url' => $sEntryUrl,
  682. 'lang_key' => $sLangKey
  683. );
  684. }
  685. /**
  686. * Data for Timeline module
  687. */
  688. public function serviceGetTimelineData()
  689. {
  690. return BxBaseModGeneralModule::serviceGetTimelineData();
  691. }
  692. /**
  693. * Entry post for Timeline module
  694. */
  695. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  696. {
  697. $a = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  698. if($a === false)
  699. return false;
  700. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aEvent['object_id'], $this->getName());
  701. $a['content']['url'] = $oGroupProfile->getUrl();
  702. $a['content']['title'] = $oGroupProfile->getDisplayName();
  703. return $a;
  704. }
  705. // ====== PERMISSION METHODS
  706. /**
  707. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  708. */
  709. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  710. {
  711. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  712. }
  713. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  714. {
  715. $bInvited = false;
  716. if (bx_get('key')){
  717. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  718. $mixedInvited = $this->isInvited(bx_get('key'), $oGroupProfile->id());
  719. if ($mixedInvited === true)
  720. $bInvited = true;
  721. }
  722. if ($this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $iProfileId) || $bInvited)
  723. return CHECK_ACTION_RESULT_ALLOWED;
  724. return parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  725. }
  726. /**
  727. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  728. */
  729. public function checkAllowedCompose(&$aDataEntry, $isPerformAction = false)
  730. {
  731. if(!$this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]))
  732. return _t('_sys_txt_access_denied');
  733. return parent::checkAllowedCompose ($aDataEntry, $isPerformAction);
  734. }
  735. /**
  736. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  737. */
  738. public function checkAllowedFanAdd(&$aDataEntry, $isPerformAction = false)
  739. {
  740. $mixedResult = $this->_modGroupsCheckAllowedFanAdd($aDataEntry, $isPerformAction);
  741. // call alert to allow custom checks
  742. bx_alert('system', 'check_allowed_fan_add', 0, 0, array(
  743. 'module' => $this->getName(),
  744. 'content_info' => $aDataEntry,
  745. 'profile_id' => bx_get_logged_profile_id(),
  746. 'override_result' => &$mixedResult
  747. ));
  748. return $mixedResult;
  749. }
  750. public function _modGroupsCheckAllowedFanAdd (&$aDataEntry, $isPerformAction = false)
  751. {
  752. if ($this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]) || !isLogged())
  753. return _t('_sys_txt_access_denied');
  754. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], true, false);
  755. }
  756. /**
  757. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  758. */
  759. public function checkAllowedFanRemove (&$aDataEntry, $isPerformAction = false)
  760. {
  761. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, true))
  762. return CHECK_ACTION_RESULT_ALLOWED;
  763. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, false);
  764. }
  765. protected function _checkAllowedActionByFan($sAction, $aDataEntry, $iPerformerId = 0)
  766. {
  767. $CNF = &$this->_oConfig->CNF;
  768. $bRoles = $this->_oConfig->isRoles();
  769. if(empty($iPerformerId))
  770. $iPerformerId = bx_get_logged_profile_id();
  771. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  772. $iGroupProfileId = $oGroupProfile->id();
  773. if(!$bRoles && $this->_oDb->isAdmin($iGroupProfileId, $iPerformerId, $aDataEntry))
  774. return CHECK_ACTION_RESULT_ALLOWED;
  775. if($bRoles && $this->isAllowedActionByRole($sAction, $aDataEntry, $iGroupProfileId, $iPerformerId))
  776. return CHECK_ACTION_RESULT_ALLOWED;
  777. return _t('_sys_txt_access_denied');
  778. }
  779. public function isAllowedActionByRole($sAction, $aDataEntry, $iGroupProfileId, $iPerformerId)
  780. {
  781. $bResult = false;
  782. $iRole = $this->_oDb->getRole($iGroupProfileId, $iPerformerId);
  783. if(!empty($iRole))
  784. switch($sAction) {
  785. case BX_BASE_MOD_GROUPS_ACTION_MANAGE_ROLES:
  786. if($iRole == BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR)
  787. $bResult = true;
  788. break;
  789. default:
  790. $bResult = true;
  791. }
  792. // call alert to allow custom checks
  793. bx_alert('system', 'check_allowed_action_by_role', 0, 0, array(
  794. 'module' => $this->getName(),
  795. 'action' => $sAction,
  796. 'content_profile_id' => $iGroupProfileId,
  797. 'content_info' => $aDataEntry,
  798. 'profile_id' => $iPerformerId,
  799. 'profile_role' => $iRole,
  800. 'override_result' => &$bResult
  801. ));
  802. return $bResult;
  803. }
  804. public function checkAllowedManageFans($mixedDataEntry, $isPerformAction = false)
  805. {
  806. $aDataEntry = array();
  807. if(!is_array($mixedDataEntry)) {
  808. $oGroupProfile = BxDolProfile::getInstance((int)$mixedDataEntry);
  809. if($oGroupProfile && $this->getName() == $oGroupProfile->getModule())
  810. $aDataEntry = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  811. }
  812. else
  813. $aDataEntry = $mixedDataEntry;
  814. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_MANAGE_FANS, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  815. return CHECK_ACTION_RESULT_ALLOWED;
  816. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  817. }
  818. public function checkAllowedManageAdmins($mixedDataEntry, $isPerformAction = false)
  819. {
  820. $aDataEntry = array();
  821. if(!is_array($mixedDataEntry)) {
  822. $oGroupProfile = BxDolProfile::getInstance((int)$mixedDataEntry);
  823. if($oGroupProfile && $this->getName() == $oGroupProfile->getModule())
  824. $aDataEntry = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  825. }
  826. else
  827. $aDataEntry = $mixedDataEntry;
  828. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_MANAGE_ROLES, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  829. return CHECK_ACTION_RESULT_ALLOWED;
  830. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  831. }
  832. public function checkAllowedEdit($aDataEntry, $isPerformAction = false)
  833. {
  834. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_EDIT, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  835. return CHECK_ACTION_RESULT_ALLOWED;
  836. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  837. }
  838. public function checkAllowedInvite($aDataEntry, $isPerformAction = false)
  839. {
  840. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_INVITE, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  841. return CHECK_ACTION_RESULT_ALLOWED;
  842. return $this->checkAllowedEdit ($aDataEntry, $isPerformAction);
  843. }
  844. public function checkAllowedChangeCover($aDataEntry, $isPerformAction = false)
  845. {
  846. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_CHANGE_COVER, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  847. return CHECK_ACTION_RESULT_ALLOWED;
  848. return parent::checkAllowedChangeCover($aDataEntry, $isPerformAction);
  849. }
  850. public function checkAllowedDelete(&$aDataEntry, $isPerformAction = false)
  851. {
  852. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_DELETE, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  853. return CHECK_ACTION_RESULT_ALLOWED;
  854. return parent::checkAllowedDelete($aDataEntry, $isPerformAction);
  855. }
  856. public function checkAllowedJoin(&$aDataEntry, $isPerformAction = false)
  857. {
  858. if (bx_get('key')){
  859. $sKey = bx_get('key');
  860. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  861. $aData = $this->_oDb->getInviteByKey($sKey, $oGroupProfile->id());
  862. if (isset($aData['invited_profile_id']) && $aData['invited_profile_id'] == bx_get_logged_profile_id()){
  863. return CHECK_ACTION_RESULT_ALLOWED;
  864. }
  865. }
  866. return _t('_sys_txt_access_denied');
  867. }
  868. public function checkAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  869. {
  870. $mixedResult = $this->_modGroupsCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  871. // call alert to allow custom checks
  872. bx_alert('system', 'check_allowed_subscribe_add', 0, 0, array(
  873. 'module' => $this->getName(),
  874. 'content_info' => $aDataEntry,
  875. 'profile_id' => bx_get_logged_profile_id(),
  876. 'override_result' => &$mixedResult
  877. ));
  878. return $mixedResult;
  879. }
  880. /**
  881. * Note. Is mainly needed for internal usage. Access level is 'public' to allow outer calls from alerts.
  882. */
  883. public function _modGroupsCheckAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  884. {
  885. if(!$this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]))
  886. return _t('_sys_txt_access_denied');
  887. return parent::_modProfileCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  888. }
  889. /**
  890. * @deprecated since version 11.0.3 and can be removed in the next version.
  891. */
  892. public function _checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  893. {
  894. return parent::checkAllowedSubscribeAdd ($aDataEntry, $isPerformAction);
  895. }
  896. public function doAudit($iGroupProfileId, $iFanId, $sAction)
  897. {
  898. $oProfile = BxDolProfile::getInstance($iFanId);
  899. $iContentId = $oProfile->getContentId();
  900. $sModule = $oProfile->getModule();
  901. $oModule = BxDolModule::getInstance($sModule);
  902. if (BxDolRequest::serviceExists($sModule, 'act_as_profile') && BxDolService::call($sModule, 'act_as_profile') && $oModule->_oConfig){
  903. $CNF = $oModule->_oConfig->CNF;
  904. $aContentInfo = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $iContentId))) : array();
  905. $AuditParams = array(
  906. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  907. 'context_profile_id' => $iGroupProfileId,
  908. 'context_profile_title' => BxDolProfile::getInstance($iGroupProfileId)->getDisplayName()
  909. );
  910. bx_audit(
  911. $iContentId,
  912. $sModule,
  913. $sAction,
  914. $AuditParams
  915. );
  916. }
  917. }
  918. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  919. {
  920. $sResult = $this->checkAllowedView($aDataEntry);
  921. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  922. // if profile view isn't allowed but visibility is in partially visible groups
  923. // then display buttons to connect (befriend, join) to profile,
  924. // if other conditions (in parent::_checkAllowedConnect) are met as well
  925. if (CHECK_ACTION_RESULT_ALLOWED !== $sResult && !in_array($aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']], array_merge($oPrivacy->getPartiallyVisiblePrivacyGroups(), array('s'))))
  926. return $sResult;
  927. return parent::_checkAllowedConnect ($aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap);
  928. }
  929. public function addFollower ($iProfileId1, $iProfileId2)
  930. {
  931. $oConnectionFollow = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  932. if($oConnectionFollow && !$oConnectionFollow->isConnected($iProfileId1, $iProfileId2)){
  933. $oConnectionFollow->addConnection($iProfileId1, $iProfileId2);
  934. return true;
  935. }
  936. return false;
  937. }
  938. public function isFan ($iContentId, $iProfileId = false)
  939. {
  940. $CNF = &$this->_oConfig->CNF;
  941. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  942. if($oGroupProfile && isset($CNF['OBJECT_CONNECTIONS']))
  943. return ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $oGroupProfile->id(), true);
  944. return false;
  945. }
  946. public function isFanByGroupProfileId ($iGroupProfileId, $iProfileId = false)
  947. {
  948. $CNF = &$this->_oConfig->CNF;
  949. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  950. if($oGroupProfile && isset($CNF['OBJECT_CONNECTIONS']))
  951. return ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $oGroupProfile->id(), true);
  952. return false;
  953. }
  954. public function isInvited ($sKey, $iProfileId)
  955. {
  956. $CNF = &$this->_oConfig->CNF;
  957. $aData = $this->_oDb->getInviteByKey($sKey, $iProfileId);
  958. if (!isset($aData['invited_profile_id']))
  959. return _t($CNF['T']['txt_invitation_popup_error_invitation_absent']);
  960. if ($aData['invited_profile_id'] != bx_get_logged_profile_id())
  961. return _t($CNF['T']['txt_invitation_popup_error_wrong_user']);
  962. return true;
  963. }
  964. public function getRole($iGroupProfileId, $iFanProfileId)
  965. {
  966. if(!$this->isFanByGroupProfileId($iGroupProfileId, $iFanProfileId))
  967. return false;
  968. return $this->_oDb->getRole($iGroupProfileId, $iFanProfileId);
  969. }
  970. public function setRole($iGroupProfileId, $iFanProfileId, $iRole, $mixedPeriod = false, $sOrder = '')
  971. {
  972. $CNF = &$this->_oConfig->CNF;
  973. if(!isset($CNF['OBJECT_CONNECTIONS']))
  974. return false;
  975. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  976. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  977. if(!$oConnection || !$oGroupProfile)
  978. return false;
  979. if(!$oConnection->isConnected($iFanProfileId, $iGroupProfileId, true) && !($oConnection->addConnection($iFanProfileId, $iGroupProfileId) && $oConnection->addConnection($iGroupProfileId, $iFanProfileId)))
  980. return false;
  981. if(!$this->_oDb->setRole($iGroupProfileId, $iFanProfileId, $iRole, $mixedPeriod, $sOrder))
  982. return false;
  983. $this->onSetRole($iGroupProfileId, $iFanProfileId, $iRole);
  984. return true;
  985. }
  986. public function onSetRole($iGroupProfileId, $iFanProfileId, $iRole)
  987. {
  988. $CNF = &$this->_oConfig->CNF;
  989. $iProfileId = bx_get_logged_profile_id();
  990. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  991. $aGroupProfileInfo = $this->_oDb->getContentInfoById((int)$oGroupProfile->getContentId());
  992. $aRoles = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_ROLES']);
  993. // notify about admin status
  994. if(!empty($CNF['EMAIL_FAN_SET_ROLE']) && $iFanProfileId != $iProfileId)
  995. sendMailTemplate($CNF['EMAIL_FAN_SET_ROLE'], 0, $iFanProfileId, array(
  996. 'EntryUrl' => $oGroupProfile->getUrl(),
  997. 'EntryTitle' => $oGroupProfile->getDisplayName(),
  998. 'Role' => $aRoles[$iRole]
  999. ), BX_EMAIL_NOTIFY);
  1000. bx_alert($this->getName(), 'set_role', $aGroupProfileInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  1001. 'object_author_id' => $iGroupProfileId,
  1002. 'performer_id' => $iProfileId,
  1003. 'fan_id' => $iFanProfileId,
  1004. 'content' => $aGroupProfileInfo,
  1005. 'role' => $iRole,
  1006. 'group_profile' => $iGroupProfileId,
  1007. 'profile' => $iProfileId
  1008. ));
  1009. $this->doAudit($iGroupProfileId, $iFanProfileId, '_sys_audit_action_group_role_changed');
  1010. }
  1011. public function unsetRole($iGroupProfileId, $iFanProfileId)
  1012. {
  1013. $CNF = &$this->_oConfig->CNF;
  1014. if(!isset($CNF['OBJECT_CONNECTIONS']))
  1015. return false;
  1016. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  1017. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1018. if(!$oConnection || !$oGroupProfile)
  1019. return false;
  1020. if($oConnection->isConnected($iFanProfileId, $iGroupProfileId, true) && !$oConnection->removeConnection($iFanProfileId, $iGroupProfileId))
  1021. return false;
  1022. $iRole = $this->_oDb->getRole($iGroupProfileId, $iFanProfileId);
  1023. if(!$this->_oDb->unsetRole($iGroupProfileId, $iFanProfileId))
  1024. return false;
  1025. $this->onUnsetRole($iGroupProfileId, $iFanProfileId, $iRole);
  1026. return true;
  1027. }
  1028. public function onUnsetRole($iGroupProfileId, $iFanProfileId, $iRole)
  1029. {
  1030. $CNF = &$this->_oConfig->CNF;
  1031. $iProfileId = bx_get_logged_profile_id();
  1032. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1033. $aGroupProfileInfo = $this->_oDb->getContentInfoById((int)$oGroupProfile->getContentId());
  1034. bx_alert($this->getName(), 'set_role', $aGroupProfileInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  1035. 'object_author_id' => $iGroupProfileId,
  1036. 'performer_id' => $iProfileId,
  1037. 'fan_id' => $iFanProfileId,
  1038. 'content' => $aGroupProfileInfo,
  1039. 'role' => $iRole,
  1040. 'group_profile' => $iGroupProfileId,
  1041. 'profile' => $iProfileId
  1042. ));
  1043. $this->doAudit($iGroupProfileId, $iFanProfileId, '_sys_audit_action_group_role_changed');
  1044. }
  1045. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1046. {
  1047. $CNF = &$this->_oConfig->CNF;
  1048. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aEvent['object_id'], $this->getName());
  1049. $sSrc = '';
  1050. if(isset($CNF['FIELD_COVER']) && !empty($aContentInfo[$CNF['FIELD_COVER']]))
  1051. $sSrc = $oGroupProfile->getCover();
  1052. if(empty($sSrc) && isset($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]))
  1053. $sSrc = $oGroupProfile->getPicture();
  1054. return empty($sSrc) ? array() : array(
  1055. array('id' => $aContentInfo[$CNF['FIELD_PICTURE']], 'url' => $sUrl, 'src' => $sSrc, 'src_orig' => $sSrc),
  1056. );
  1057. }
  1058. protected function _prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId)
  1059. {
  1060. if (!($oGroupProfile = BxDolProfile::getInstance($iGroupProfileId)))
  1061. return array(0, 0, null);
  1062. if ($oGroupProfile->getModule() == $this->getName()) {
  1063. $iProfileId = $iInitiatorId;
  1064. $iGroupProfileId = $oGroupProfile->id();
  1065. } else {
  1066. $iProfileId = $oGroupProfile->id();
  1067. $iGroupProfileId = $iInitiatorId;
  1068. }
  1069. return array($iProfileId, $iGroupProfileId, $oGroupProfile);
  1070. }
  1071. }
  1072. /** @} */