BxBaseReportsGrid.php 11 KB

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