BxBaseDashboardServices.php 7.9 KB

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