1
0

BxBaseModGroupsModule.php 68 KB

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