BxBaseModGroupsModule.php 65 KB

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