BxBaseDashboardServices.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 = '';
  22. if(($_sSelected = bx_get('object')) !== false)
  23. $sSelected = bx_process_input($_sSelected);
  24. if(!$sSelected)
  25. $sSelected = reset($aSystems)['name'];
  26. $oGrid = BxDolGrid::getObjectInstance('sys_reports_administration');
  27. $oGrid->setObject($aSystems[$sSelected]['name']);
  28. if(!$oGrid)
  29. return '';
  30. $oTemplate = BxDolTemplate::getInstance();
  31. $oTemplate->addJs(['BxDolReportsManageTools.js', 'BxDolGrid.js']);
  32. $oTemplate->addCss(['manage_tools.css']);
  33. $oTemplate->addJsTranslation(['_sys_grid_search']);
  34. return [
  35. 'content' =>$oGrid->getCode(),
  36. 'menu' => $oMenu
  37. ];
  38. }
  39. public function serviceGetReportsCount($sObjectReposrt, $iStatus)
  40. {
  41. $oReport = BxDolReport::getObjectInstance($sObjectReposrt, 0, false);
  42. $iCount = $oReport->getCountByStatus($iStatus);
  43. if ($iCount > 0)
  44. return $iCount;
  45. return ;
  46. }
  47. public function serviceGetStatBlock()
  48. {
  49. $bEmpty = false;
  50. if (defined('BX_API_PAGE'))
  51. $bEmpty = true;
  52. $aData = [];
  53. $iStartDate = time() - 24*3600*31;
  54. $iProfileId = (int)bx_get_logged_profile_id();
  55. $iV1 = $bEmpty ? 0 : BxDolConnection::getObjectInstance('sys_profiles_friends')->getConnectedContentCount($iProfileId, true);
  56. $iV2 =$bEmpty ? 0 : BxDolConnection::getObjectInstance('sys_profiles_friends')->getConnectedContentCount($iProfileId, true, $iStartDate);
  57. $aData[] = ['title' => 'Friends', 'key' => 'friends', 'type' => 'growth', 'url' =>'/friends', 'current' => $iV1, 'prev' => $iV2, 'growth' => $iV2 > 0 ? round(($iV1 - $iV2)/$iV2*100, 2) : 0];
  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[] = ['title' =>'Followers', 'key' => 'followers', 'type' => 'growth', 'url' =>'/followers', 'current' => $iV1, 'prev' => $iV2, 'growth' => $iV2 > 0 ? round(($iV1 - $iV2)/$iV2*100 ,2) : 0];
  61. $oPermalink = BxDolPermalinks::getInstance();
  62. $aModules = bx_srv('system', 'get_modules_by_type', ['content']);
  63. foreach($aModules as $aModule) {
  64. $oModule = BxDolModule::getInstance($aModule['name']);
  65. $CNF = &$oModule->_oConfig->CNF;
  66. if(method_exists($oModule->_oDb, 'getStatByProfile')) {
  67. $a = $bEmpty ? [] : $oModule->_oDb->getStatByProfile($iProfileId);
  68. $aData[] = array_merge([
  69. 'key' => $aModule['name'],
  70. 'title' => $aModule['title'],
  71. 'add_url' => !empty($CNF['URI_ADD_ENTRY']) ? $CNF['URI_ADD_ENTRY'] : '',
  72. 'url' => !empty($CNF['URL_MANAGE_COMMON']) ? $oPermalink->permalink($CNF['URL_MANAGE_COMMON']) : '',
  73. 'action' => 'views',
  74. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  75. 'type' => 'simple'
  76. ], $a);
  77. }
  78. }
  79. $aModules = bx_srv('system', 'get_modules_by_type', ['context']);
  80. foreach($aModules as $aModule) {
  81. $oModule = BxDolModule::getInstance($aModule['name']);
  82. $CNF = &$oModule->_oConfig->CNF;
  83. if (method_exists($oModule->_oDb, 'getStatByProfile')){
  84. $a = $bEmpty ? [] : $oModule->_oDb->getStatByProfile($iProfileId);
  85. $iMembers = 0;
  86. if(!$bEmpty && isset($CNF['OBJECT_CONNECTIONS']) && ($sConnection = $CNF['OBJECT_CONNECTIONS'])) {
  87. $aContexts = $oModule->_oDb->getEntriesBy(['type' => 'author', 'author' => $iProfileId]);
  88. foreach($aContexts as $aContext)
  89. if(($oProfile = BxDolProfile::getInstanceByContentAndType($aContext[$CNF['FIELD_ID']], $aModule['name'])) !== false && ($oConnection = BxDolConnection::getObjectInstance($sConnection)) !== false)
  90. $iMembers += $oConnection->getConnectedInitiatorsCount($oProfile->id(), true);
  91. }
  92. $aData[] = array_merge([
  93. 'key' => $aModule['name'],
  94. 'title' => ($_sTitle = '_' . $aModule['name']) && ($sTitle = _t($_sTitle)) && $_sTitle != $sTitle ? $sTitle : $aModule['title'],
  95. 'url' => $oPermalink->permalink($CNF['URL_MANAGE_COMMON']),
  96. 'add_url' => str_replace('edit-', 'create-',$CNF['URI_EDIT_ENTRY']),
  97. 'action' => 'member',
  98. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  99. 'type' => 'simple',
  100. 'members' => $iMembers
  101. ], $a);
  102. }
  103. }
  104. $bApi = bx_is_api();
  105. if($bApi){
  106. $oMenu = BxDolMenu::getObjectInstance('sys_account_dashboard_manage_tools');
  107. return [bx_api_get_block('dashboard_stat', ['modules' => $aData, 'manage' => $oMenu->getCodeAPI()])];
  108. }
  109. }
  110. public function serviceManageAudit()
  111. {
  112. return bx_srv('system', 'manage_tools', array(), 'TemplAuditServices');
  113. }
  114. public function serviceManageContent()
  115. {
  116. $oMenu = BxDolMenu::getObjectInstance('sys_dashboard_content');
  117. if(!$oMenu)
  118. return '';
  119. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(['type' => 'modules', 'active' => 1]);
  120. $aModulesList = [];
  121. foreach($aModules as $aModule) {
  122. $oModule = BxDolModule::getInstance($aModule['name']);
  123. if(!$oModule || !($oModule instanceof iBxDolContentInfoService))
  124. continue;
  125. if(empty($oModule->_oConfig->CNF['OBJECT_GRID_ADMINISTRATION']) || !bx_is_srv($aModule['name'], 'manage_tools'))
  126. continue;
  127. $aModulesList[$aModule['uri']] = $aModule;
  128. }
  129. $sSelected = bx_get('module');
  130. if($sSelected == '')
  131. $sSelected = reset($aModulesList)['uri'];
  132. $sContent = '';
  133. if(isset($aModulesList[$sSelected])) {
  134. $sSelectedModule = $aModulesList[$sSelected]['name'];
  135. $aBlock = bx_srv($sSelectedModule, 'manage_tools', array('administration'));
  136. if(!empty($aBlock) && is_array($aBlock))
  137. $sContent = $aBlock['content'];
  138. }
  139. else {
  140. $sSelectedModule = 'system';
  141. $sMethod = '_getManageContent' . bx_gen_method_name($sSelected);
  142. if(method_exists($this, $sMethod))
  143. $sContent = $this->$sMethod();
  144. }
  145. $oMenu->setMenuData($aModulesList);
  146. $oMenu->setSelected($sSelectedModule, $sSelected);
  147. return array(
  148. 'content' => $sContent,
  149. 'menu' => $oMenu
  150. );
  151. }
  152. protected function _getManageContentCmts()
  153. {
  154. $aBlock = bx_srv('system', 'manage_tools', ['administration'], 'TemplCmtsServices');
  155. if(empty($aBlock) || !is_array($aBlock))
  156. return '';
  157. return $aBlock['content'];
  158. }
  159. }
  160. /** @} */