BxBaseDashboardServices.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Services for dashboard objects functionality
  11. * @see BxDolChart
  12. */
  13. class BxBaseDashboardServices extends BxDol
  14. {
  15. public function serviceManageReports()
  16. {
  17. $oMenu = BxDolMenu::getObjectInstance('sys_dashboard_reports');
  18. if(!$oMenu)
  19. return '';
  20. $aSystems = BxDolReport::getSystems();
  21. $sSelected = bx_get('object');
  22. if ($sSelected == ''){
  23. $sSelected = reset($aSystems)['name'];
  24. }
  25. $oGrid = BxDolGrid::getObjectInstance('sys_reports_administration');
  26. $oGrid->setObject($aSystems[$sSelected]['name']);
  27. if(!$oGrid)
  28. return '';
  29. $oTemplate = BxDolTemplate::getInstance();
  30. $oTemplate->addJs(array('BxDolReportsManageTools.js', 'BxDolGrid.js'));
  31. $oTemplate->addCss(array('manage_tools.css'));
  32. $oTemplate->addJsTranslation(array('_sys_grid_search'));
  33. return array(
  34. 'content' =>$oGrid->getCode(),
  35. 'menu' => $oMenu
  36. );
  37. }
  38. public function serviceGetReportsCount($sObjectReposrt, $iStatus)
  39. {
  40. $oReport = BxDolReport::getObjectInstance($sObjectReposrt, 0, false);
  41. $iCount = $oReport->getCountByStatus($iStatus);
  42. if ($iCount > 0)
  43. return $iCount;
  44. return ;
  45. }
  46. public function serviceGetStatBlock()
  47. {
  48. $bEmpty = false;
  49. if (defined('BX_API_PAGE'))
  50. $bEmpty = true;
  51. $aData = [];
  52. $iStartDate = time() - 24*3600*31;
  53. $iProfileId = (int)bx_get_logged_profile_id();
  54. $iV1 = $bEmpty ? 0 : BxDolConnection::getObjectInstance('sys_profiles_friends')->getConnectedContentCount($iProfileId, true);
  55. $iV2 =$bEmpty ? 0 : BxDolConnection::getObjectInstance('sys_profiles_friends')->getConnectedContentCount($iProfileId, true, $iStartDate);
  56. $aData['friends'] = ['title' => 'Friends', 'key' => 'friends', 'type' => 'growth', 'url' =>'/friends', 'current' => $iV1, 'prev' => $iV2, 'growth' => $iV2 > 0 ? round(($iV1 - $iV2)/$iV2*100, 2) : 0];
  57. // echo $iV1.'----'.$iV2;
  58. $iV1 = $bEmpty ? 0 : BxDolConnection::getObjectInstance('sys_profiles_subscriptions')->getConnectedContentCount($iProfileId, false);
  59. $iV2 = $bEmpty ? 0 : BxDolConnection::getObjectInstance('sys_profiles_subscriptions')->getConnectedContentCount($iProfileId, false, $iStartDate);
  60. $aData['followers'] = ['title' =>'Followers', 'key' => 'followers', 'type' => 'growth', 'url' =>'/followers', 'current' => $iV1, 'prev' => $iV2, 'growth' => $iV2 > 0 ? round(($iV1 - $iV2)/$iV2*100 ,2) : 0];
  61. $aModules = bx_srv('system', 'get_modules_by_type', ['content']);
  62. foreach($aModules as $aModule) {
  63. $oModule = BxDolModule::getInstance($aModule['name']);
  64. $CNF = &$oModule->_oConfig->CNF;
  65. $a = $bEmpty ? [] : $oModule->_oDb->getStatByProfile($iProfileId);
  66. $aIcon = explode($CNF['ICON'], ' ');
  67. $aData[$aModule['name']] = array_merge(['key' => $aModule['name'], 'title' => $aModule['title'], 'url' => $CNF['URL_HOME'], 'icon' => $CNF['ICON'], 'type' => 'simple'], $a);
  68. }
  69. $aModules = bx_srv('system', 'get_modules_by_type', ['context']);
  70. foreach($aModules as $aModule) {
  71. $oModule = BxDolModule::getInstance($aModule['name']);
  72. $CNF = &$oModule->_oConfig->CNF;
  73. $a = $bEmpty ? [] : $oModule->_oDb->getStatByProfile($iProfileId);
  74. $aIcon = explode($CNF['ICON'], ' ');
  75. $aContexts = $oModule->_oDb->getEntriesBy(['type' => 'author', 'author' => $iProfileId]);
  76. $iMembers = 0;
  77. if (!$bEmpty){
  78. foreach($aContexts as $aContext) {
  79. $oProfile = BxDolProfile::getInstanceByContentAndType($aContext[$CNF['FIELD_ID']], $aModule['name']);
  80. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  81. if($oConnection){
  82. $iMembers += $oConnection->getConnectedInitiatorsCount($oProfile->id(), true);
  83. }
  84. }
  85. }
  86. $aData[$aModule['name']] = array_merge(['key' => $aModule['name'], 'title' => $aModule['title'], 'url' => $CNF['URL_HOME'], 'icon' => $CNF['ICON'], 'type' => 'simple', 'members' => $iMembers], $a);
  87. }
  88. $bApi = bx_is_api();
  89. if($bApi)
  90. return [bx_api_get_block('dashboard_stat', $aData)];
  91. }
  92. public function serviceManageAudit()
  93. {
  94. return bx_srv('system', 'manage_tools', array(), 'TemplAuditServices');
  95. }
  96. public function serviceManageContent()
  97. {
  98. $oMenu = BxDolMenu::getObjectInstance('sys_dashboard_content');
  99. if(!$oMenu)
  100. return '';
  101. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(['type' => 'modules', 'active' => 1]);
  102. $aModulesList = [];
  103. foreach($aModules as $aModule) {
  104. $oModule = BxDolModule::getInstance($aModule['name']);
  105. if(!$oModule || !($oModule instanceof iBxDolContentInfoService))
  106. continue;
  107. if(empty($oModule->_oConfig->CNF['OBJECT_GRID_ADMINISTRATION']) || !bx_is_srv($aModule['name'], 'manage_tools'))
  108. continue;
  109. $aModulesList[$aModule['uri']] = $aModule;
  110. }
  111. $sSelected = bx_get('module');
  112. if($sSelected == '')
  113. $sSelected = reset($aModulesList)['uri'];
  114. $sContent = '';
  115. if(isset($aModulesList[$sSelected])) {
  116. $sSelectedModule = $aModulesList[$sSelected]['name'];
  117. $aBlock = bx_srv($sSelectedModule, 'manage_tools', array('administration'));
  118. if(!empty($aBlock) && is_array($aBlock))
  119. $sContent = $aBlock['content'];
  120. }
  121. else {
  122. $sSelectedModule = 'system';
  123. $sMethod = '_getManageContent' . bx_gen_method_name($sSelected);
  124. if(method_exists($this, $sMethod))
  125. $sContent = $this->$sMethod();
  126. }
  127. $oMenu->setMenuData($aModulesList);
  128. $oMenu->setSelected($sSelectedModule, $sSelected);
  129. return array(
  130. 'content' => $sContent,
  131. 'menu' => $oMenu
  132. );
  133. }
  134. protected function _getManageContentCmts()
  135. {
  136. $aBlock = bx_srv('system', 'manage_tools', ['administration'], 'TemplCmtsServices');
  137. if(empty($aBlock) || !is_array($aBlock))
  138. return '';
  139. return $aBlock['content'];
  140. }
  141. }
  142. /** @} */