BxBaseReportsGrid.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. class BxBaseReportsGrid extends BxTemplGrid
  10. {
  11. protected $_sParamsDivider;
  12. protected $_sFilter1Name;
  13. protected $_sFilter1Value;
  14. protected $_aFilter1Values;
  15. protected $sJsObject = 'oBxDolReportsManageTools';
  16. protected $_aReportSystemInfo;
  17. public function __construct($aInfo, $oTemplate = false)
  18. {
  19. parent::__construct($aInfo, $oTemplate);
  20. $this->_sParamsDivider = '#-#';
  21. $this->_sDefaultSortingOrder = 'DESC';
  22. $this->_sFilter1Name = 'filter1';
  23. $this->_aFilter1Values = array(
  24. '' => _t('_report_status_all'),
  25. 0 => _t('_report_status_new'),
  26. 1 => _t('_report_status_check_in'),
  27. 2 => _t('_report_status_check_out'),
  28. );
  29. $sFilter2 = bx_get($this->_sFilter1Name);
  30. if(!empty($sFilter2)) {
  31. $this->_sFilter1Value = bx_process_input($sFilter2);
  32. $this->_aQueryAppend[$this->_sFilter1Name] = $this->_sFilter1Value;
  33. }
  34. $this->_aReportSystemInfo = [];
  35. if(($sObject = bx_get('object')) !== false)
  36. $this->setObject($sObject);
  37. }
  38. public function getCode($isDisplayHeader = true)
  39. {
  40. if(!$this->_aReportSystemInfo)
  41. return '';
  42. return $this->getJsCode() . parent::getCode($isDisplayHeader);
  43. }
  44. public function setObject($sObjectName)
  45. {
  46. $oReport = BxDolReport::getObjectInstance($sObjectName, 0, false);
  47. if(!$oReport->isProcessible())
  48. return;
  49. $this->_aReportSystemInfo = $oReport->getSystemInfo();
  50. $this->_aOptions['table'] = $this->_aReportSystemInfo['table_track'];
  51. $this->_aQueryAppend['object'] = $sObjectName;
  52. }
  53. public function getJsCode()
  54. {
  55. $aParams = array(
  56. 'sObjName' => $this->sJsObject,
  57. 'aHtmlIds' => array(),
  58. 'oRequestParams' => array(),
  59. 'sObjNameGrid' => 'sys_reports_administration'
  60. );
  61. return BxDolTemplate::getInstance()->_wrapInTagJsCode("var " . $this->sJsObject . " = new BxDolReportsManageTools(" . json_encode($aParams) . ");");
  62. }
  63. public function performActionCheckIn()
  64. {
  65. $this->_performActionStatus(BX_DOL_REPORT_STASUS_IN_PROCESS, '_report_comment_check_in');
  66. }
  67. public function performActionCheckOut()
  68. {
  69. $this->_performActionStatus(BX_DOL_REPORT_STASUS_PROCESSED, '_report_comment_check_out');
  70. }
  71. private function _performActionStatus($iStatus, $sCmtsText)
  72. {
  73. $aIds = bx_get('ids');
  74. $iAffected = 0;
  75. $aIdsAffected = array ();
  76. foreach($aIds as $iId) {
  77. $oReport = BxDolReport::getObjectInstance($this->_aReportSystemInfo['name'], $iId, true);
  78. $oReport->changeStatusReport($iStatus, bx_get_logged_profile_id(), _t($sCmtsText));
  79. $aIdsAffected[] = $iId;
  80. $iAffected++;
  81. }
  82. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => $mixedResult));
  83. }
  84. protected function _getCellDate($mixedValue, $sKey, $aField, $aRow)
  85. {
  86. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  87. }
  88. protected function _getCellNotes($mixedValue, $sKey, $aField, $aRow)
  89. {
  90. $mixedValue = '';
  91. if ($this->_aReportSystemInfo['object_comment'] && $this->_aReportSystemInfo['object_comment'] != ''){
  92. $oCmts = BxDolCmts::getObjectInstance($this->_aReportSystemInfo['object_comment'], $aRow['object_id']);
  93. if ($oCmts){
  94. $oModule = BxDolModule::getInstance($this->_aReportSystemInfo['name']);
  95. $mixedValue = BxDolTemplate::getInstance()->parseLink('javascript:', $oCmts->getCommentsCount(), array("onclick" => "bx_get_notes(this, '" . $oModule->_aModule['uri'] . "', '" . $aRow['object_id'] . "')"));
  96. }
  97. }
  98. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  99. }
  100. protected function _getCellComments($mixedValue, $sKey, $aField, $aRow)
  101. {
  102. $mixedValue = '';
  103. if ($this->_aReportSystemInfo['object_comment'] && $this->_aReportSystemInfo['object_comment'] != ''){
  104. $oCmts = BxDolCmts::getObjectInstance($this->_aReportSystemInfo['object_comment'], -$aRow['id']);
  105. if ($oCmts){
  106. $oModule = BxDolModule::getInstance($this->_aReportSystemInfo['name']);
  107. $mixedValue = BxDolTemplate::getInstance()->parseLink('javascript:', $oCmts->getCommentsCount(), array("onclick" => "bx_get_notes(this, '" . $oModule->_aModule['uri'] . "', '" . - $aRow['id'] . "')"));
  108. }
  109. }
  110. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  111. }
  112. protected function _getCellObject ($mixedValue, $sKey, $aField, $aRow)
  113. {
  114. $sTitle = $sUrl = '';
  115. if($this->_aReportSystemInfo['name'] == 'sys_cmts'){
  116. $oCmts = BxDolCmts::getObjectInstanceByUniqId($aRow['object_id']);
  117. if($oCmts) {
  118. $aCmts = $oCmts->getCommentsBy([
  119. 'type' => 'uniq_id',
  120. 'uniq_id' => $aRow['object_id']
  121. ]);
  122. $sTitle = $oCmts->getViewText($aCmts['cmt_id']);
  123. $sUrl = $oCmts->getViewUrl($aCmts['cmt_id']);
  124. }
  125. }
  126. else {
  127. $oContentInfo = BxDolContentInfo::getObjectInstance($this->_aReportSystemInfo['name']);
  128. if($oContentInfo) {
  129. $sTitle = $oContentInfo->getContentTitle($aRow['object_id']);
  130. $sUrl = $oContentInfo->getContentLink($aRow['object_id']);
  131. }
  132. }
  133. if($sTitle == '')
  134. $sTitle = _t('_undefined');
  135. if($sUrl != '')
  136. $sTitle = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  137. 'href' => $sUrl,
  138. 'title' => bx_html_attribute($sTitle),
  139. 'content' => $sTitle
  140. ));
  141. return parent::_getCellDefault($sTitle, $sKey, $aField, $aRow);
  142. }
  143. protected function _getCellAuthor ($mixedValue, $sKey, $aField, $aRow)
  144. {
  145. if ($aRow['author_id'] > 0){
  146. $oProfile = BxDolProfile::getInstance($aRow['author_id']);
  147. if ($oProfile){
  148. $sProfile = $oProfile->getDisplayName();
  149. $mixedValue = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  150. 'href' => $oProfile->getUrl(),
  151. 'title' => $sProfile,
  152. 'content' => $sProfile
  153. ));
  154. }
  155. else{
  156. $mixedValue = $aRow['profile_title'];
  157. }
  158. }
  159. else{
  160. $mixedValue = '';
  161. }
  162. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  163. }
  164. protected function _getCellCheckedBy ($mixedValue, $sKey, $aField, $aRow)
  165. {
  166. if ($aRow['checked_by'] > 0){
  167. $oProfile = BxDolProfile::getInstance($aRow['checked_by']);
  168. if ($oProfile){
  169. $sProfile = $oProfile->getDisplayName();
  170. $mixedValue = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  171. 'href' => $oProfile->getUrl(),
  172. 'title' => $sProfile,
  173. 'content' => $sProfile
  174. ));
  175. }
  176. else{
  177. $mixedValue = $aRow['profile_title'];
  178. }
  179. }
  180. else{
  181. $mixedValue = '';
  182. }
  183. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  184. }
  185. protected function _getCellStatus ($mixedValue, $sKey, $aField, $aRow)
  186. {
  187. return parent::_getCellDefault(_t('_sys_txt_report_status_' . $mixedValue), $sKey, $aField, $aRow);
  188. }
  189. protected function _getActionCheckIn($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  190. {
  191. if($aRow["status"] == BX_DOL_REPORT_STASUS_IN_PROCESS)
  192. return '';
  193. return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  194. }
  195. protected function _getActionCheckOut($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  196. {
  197. if ($aRow["checked_by"] != bx_get_logged_profile_id())
  198. return '';
  199. if($aRow["status"] != BX_DOL_REPORT_STASUS_IN_PROCESS)
  200. return '';
  201. return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  202. }
  203. protected function _getActionAudit($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  204. {
  205. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=dashboard-audit&module=' . $this->_aReportSystemInfo['module_name'] . '&content_id=' . $aRow['object_id']));
  206. $a['attr'] = array_merge($a['attr'], array(
  207. "onclick" => "window.open('" . $sUrl . "','_self');"
  208. ));
  209. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  210. }
  211. protected function _getFilterControls()
  212. {
  213. return $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
  214. }
  215. protected function _getFilterOnChange()
  216. {
  217. return $this->sJsObject . '.onChangeFilter(this)';
  218. }
  219. protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues, $mixedAddSelectOne = true, $bAsArray = false)
  220. {
  221. return parent::_getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues, '_all', $bAsArray);
  222. }
  223. protected function _getDataSql ($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  224. {
  225. $this->_aOptions['source'] = "SELECT * FROM `" . $this->_aReportSystemInfo['table_track'] . "` " . $this->_aOptions['source'];
  226. if(strpos($sFilter, $this->_sParamsDivider) !== false)
  227. list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  228. if(isset($this->_sFilter1Value) && $this->_sFilter1Value !== ''){
  229. $this->_aOptions['source'] .= " AND `status` = " . $this->_sFilter1Value;
  230. }
  231. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  232. }
  233. }
  234. /** @} */