BxBaseDashboardServices.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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[] = ['title' => 'Friends', 'key' => 'friends', 'type' => 'growth', 'url' =>'/friends', 'current' => $iV1, 'prev' => $iV2, 'growth' => $iV2 > 0 ? round(($iV1 - $iV2)/$iV2*100, 2) : 0];
  57. $iV1 = $bEmpty ? 0 : BxDolConnection::getObjectInstance('sys_profiles_subscriptions')->getConnectedContentCount($iProfileId, false);
  58. $iV2 = $bEmpty ? 0 : BxDolConnection::getObjectInstance('sys_profiles_subscriptions')->getConnectedContentCount($iProfileId, false, $iStartDate);
  59. $aData[] = ['title' =>'Followers', 'key' => 'followers', 'type' => 'growth', 'url' =>'/followers', 'current' => $iV1, 'prev' => $iV2, 'growth' => $iV2 > 0 ? round(($iV1 - $iV2)/$iV2*100 ,2) : 0];
  60. $oPermalink = BxDolPermalinks::getInstance();
  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. if (method_exists($oModule->_oDb, 'getStatByProfile')){
  66. $a = $bEmpty ? [] : $oModule->_oDb->getStatByProfile($iProfileId);
  67. $aIcon = explode($CNF['ICON'], ' ');
  68. $aData[] = array_merge(['key' => $aModule['name'], 'title' => $aModule['title'], 'add_url' => $CNF['URI_ADD_ENTRY'], 'url' => $oPermalink->permalink($CNF['URL_HOME']), 'action' => 'views', 'icon' => $CNF['ICON'], 'type' => 'simple'], $a);
  69. }
  70. }
  71. $aModules = bx_srv('system', 'get_modules_by_type', ['context']);
  72. foreach($aModules as $aModule) {
  73. $oModule = BxDolModule::getInstance($aModule['name']);
  74. $CNF = &$oModule->_oConfig->CNF;
  75. if (method_exists($oModule->_oDb, 'getStatByProfile')){
  76. $a = $bEmpty ? [] : $oModule->_oDb->getStatByProfile($iProfileId);
  77. $aIcon = explode($CNF['ICON'], ' ');
  78. $aContexts = $oModule->_oDb->getEntriesBy(['type' => 'author', 'author' => $iProfileId]);
  79. $iMembers = 0;
  80. if (!$bEmpty){
  81. foreach($aContexts as $aContext) {
  82. $oProfile = BxDolProfile::getInstanceByContentAndType($aContext[$CNF['FIELD_ID']], $aModule['name']);
  83. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  84. if($oConnection){
  85. $iMembers += $oConnection->getConnectedInitiatorsCount($oProfile->id(), true);
  86. }
  87. }
  88. }
  89. $aData[] = array_merge(['key' => $aModule['name'], 'title' => $aModule['title'], 'url' => $oPermalink->permalink($CNF['URL_HOME']), 'add_url' => str_replace('edit-', 'create-',$CNF['URI_EDIT_ENTRY']), 'action' => 'member', 'icon' => $CNF['ICON'], 'type' => 'simple', 'members' => $iMembers], $a);
  90. }
  91. }
  92. $bApi = bx_is_api();
  93. if($bApi){
  94. $oMenu = BxDolMenu::getObjectInstance('sys_account_dashboard_manage_tools');
  95. return [bx_api_get_block('dashboard_stat', ['modules' => $aData, 'manage' => $oMenu->getCodeAPI()])];
  96. }
  97. }
  98. public function serviceManageAudit()
  99. {
  100. return bx_srv('system', 'manage_tools', array(), 'TemplAuditServices');
  101. }
  102. public function serviceManageContent()
  103. {
  104. $oMenu = BxDolMenu::getObjectInstance('sys_dashboard_content');
  105. if(!$oMenu)
  106. return '';
  107. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(['type' => 'modules', 'active' => 1]);
  108. $aModulesList = [];
  109. foreach($aModules as $aModule) {
  110. $oModule = BxDolModule::getInstance($aModule['name']);
  111. if(!$oModule || !($oModule instanceof iBxDolContentInfoService))
  112. continue;
  113. if(empty($oModule->_oConfig->CNF['OBJECT_GRID_ADMINISTRATION']) || !bx_is_srv($aModule['name'], 'manage_tools'))
  114. continue;
  115. $aModulesList[$aModule['uri']] = $aModule;
  116. }
  117. $sSelected = bx_get('module');
  118. if($sSelected == '')
  119. $sSelected = reset($aModulesList)['uri'];
  120. $sContent = '';
  121. if(isset($aModulesList[$sSelected])) {
  122. $sSelectedModule = $aModulesList[$sSelected]['name'];
  123. $aBlock = bx_srv($sSelectedModule, 'manage_tools', array('administration'));
  124. if(!empty($aBlock) && is_array($aBlock))
  125. $sContent = $aBlock['content'];
  126. }
  127. else {
  128. $sSelectedModule = 'system';
  129. $sMethod = '_getManageContent' . bx_gen_method_name($sSelected);
  130. if(method_exists($this, $sMethod))
  131. $sContent = $this->$sMethod();
  132. }
  133. $oMenu->setMenuData($aModulesList);
  134. $oMenu->setSelected($sSelectedModule, $sSelected);
  135. return array(
  136. 'content' => $sContent,
  137. 'menu' => $oMenu
  138. );
  139. }
  140. protected function _getManageContentCmts()
  141. {
  142. $aBlock = bx_srv('system', 'manage_tools', ['administration'], 'TemplCmtsServices');
  143. if(empty($aBlock) || !is_array($aBlock))
  144. return '';
  145. return $aBlock['content'];
  146. }
  147. }
  148. /** @} */