BxBaseModGroupsModule.php 69 KB

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