BxBaseReportsGrid.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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('module_name')){
  35. $this->setModule(bx_get('module_name'));
  36. }
  37. }
  38. public function getCode($isDisplayHeader = true)
  39. {
  40. return $this->getJsCode() . parent::getCode($isDisplayHeader);
  41. }
  42. public function setModule($sModuleName)
  43. {
  44. $oModule = BxDolModule::getInstance($sModuleName);
  45. $CNF = $oModule->_oConfig->CNF;
  46. $oReport = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], -1, false);
  47. $this->_aReportSystemInfo = $oReport->getSystemInfo();
  48. $this->_aOptions['table'] = $this->_aReportSystemInfo['table_track'];
  49. $this->_aQueryAppend['module_name'] = $sModuleName;
  50. }
  51. public function getJsCode()
  52. {
  53. $aParams = array(
  54. 'sObjName' => $this->sJsObject,
  55. 'aHtmlIds' => array(),
  56. 'oRequestParams' => array(),
  57. 'sObjNameGrid' => 'sys_reports_administration'
  58. );
  59. return BxDolTemplate::getInstance()->_wrapInTagJsCode("var " . $this->sJsObject . " = new BxDolReportsManageTools(" . json_encode($aParams) . ");");
  60. }
  61. public function performActionCheckIn()
  62. {
  63. $this->_performActionStatus(BX_DOL_REPORT_STASUS_IN_PROCESS, '_report_comment_check_in');
  64. }
  65. public function performActionCheckOut()
  66. {
  67. $this->_performActionStatus(BX_DOL_REPORT_STASUS_PROCESSED, '_report_comment_check_out');
  68. }
  69. private function _performActionStatus($iStatus, $sCmtsText)
  70. {
  71. $aIds = bx_get('ids');
  72. $oModule = BxDolModule::getInstance($this->_aReportSystemInfo['module_name']);
  73. $CNF = $oModule->_oConfig->CNF;
  74. $iAffected = 0;
  75. $aIdsAffected = array ();
  76. foreach($aIds as $iId) {
  77. $oReport = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $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. $oModule = BxDolModule::getInstance($this->_aReportSystemInfo['module_name']);
  92. $CNF = $oModule->_oConfig->CNF;
  93. if (isset($CNF) && isset($CNF['OBJECT_NOTES'])){
  94. $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_NOTES'], $aRow['object_id']);
  95. $mixedValue = BxDolTemplate::getInstance()->parseLink('javascript:', $oCmts->getCommentsCount(), array("onclick" => "bx_get_notes(this, '" . $oModule->_aModule['uri'] . "', '" . $aRow['object_id'] . "')"));
  96. }
  97. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  98. }
  99. protected function _getCellComments($mixedValue, $sKey, $aField, $aRow)
  100. {
  101. $mixedValue = '';
  102. $oModule = BxDolModule::getInstance($this->_aReportSystemInfo['module_name']);
  103. $CNF = $oModule->_oConfig->CNF;
  104. if (isset($CNF) && isset($CNF['OBJECT_NOTES'])){
  105. $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_NOTES'], -$aRow['id']);
  106. $mixedValue = BxDolTemplate::getInstance()->parseLink('javascript:', $oCmts->getCommentsCount(), array("onclick" => "bx_get_notes(this, '" . $oModule->_aModule['uri'] . "', '" . -$aRow['id'] . "')"));
  107. }
  108. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  109. }
  110. protected function _getCellObject ($mixedValue, $sKey, $aField, $aRow)
  111. {
  112. $mixedValue = '';
  113. $sTitle = bx_srv($this->_aReportSystemInfo['module_name'], 'get_title', array(0 => $aRow['object_id']));
  114. if ($sTitle != ''){
  115. $mixedValue = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  116. 'href' => bx_srv($this->_aReportSystemInfo['module_name'], 'get_link', array(0 => $aRow['object_id'])),
  117. 'title' => $sTitle,
  118. 'content' => $sTitle
  119. ));
  120. }
  121. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  122. }
  123. protected function _getCellAuthor ($mixedValue, $sKey, $aField, $aRow)
  124. {
  125. if ($aRow['author_id'] > 0){
  126. $oProfile = BxDolProfile::getInstance($aRow['author_id']);
  127. if ($oProfile){
  128. $sProfile = $oProfile->getDisplayName();
  129. $mixedValue = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  130. 'href' => $oProfile->getUrl(),
  131. 'title' => $sProfile,
  132. 'content' => $sProfile
  133. ));
  134. }
  135. else{
  136. $mixedValue = $aRow['profile_title'];
  137. }
  138. }
  139. else{
  140. $mixedValue = '';
  141. }
  142. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  143. }
  144. protected function _getCellCheckedBy ($mixedValue, $sKey, $aField, $aRow)
  145. {
  146. if ($aRow['checked_by'] > 0){
  147. $oProfile = BxDolProfile::getInstance($aRow['checked_by']);
  148. if ($oProfile){
  149. $sProfile = $oProfile->getDisplayName();
  150. $mixedValue = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  151. 'href' => $oProfile->getUrl(),
  152. 'title' => $sProfile,
  153. 'content' => $sProfile
  154. ));
  155. }
  156. else{
  157. $mixedValue = $aRow['profile_title'];
  158. }
  159. }
  160. else{
  161. $mixedValue = '';
  162. }
  163. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  164. }
  165. protected function _getCellStatus ($mixedValue, $sKey, $aField, $aRow)
  166. {
  167. return parent::_getCellDefault(_t('_sys_txt_report_status_' . $mixedValue), $sKey, $aField, $aRow);
  168. }
  169. protected function _getActionCheckIn($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  170. {
  171. if($aRow["status"] == BX_DOL_REPORT_STASUS_IN_PROCESS)
  172. return '';
  173. return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  174. }
  175. protected function _getActionCheckOut($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  176. {
  177. if ($aRow["checked_by"] != bx_get_logged_profile_id())
  178. return '';
  179. if($aRow["status"] != BX_DOL_REPORT_STASUS_IN_PROCESS)
  180. return '';
  181. return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  182. }
  183. protected function _getFilterControls()
  184. {
  185. return $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
  186. }
  187. protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues)
  188. {
  189. if(empty($sFilterName) || empty($aFilterValues))
  190. return '';
  191. foreach($aFilterValues as $sKey => $sValue)
  192. $aFilterValues[$sKey] = _t($sValue);
  193. $aInputModules = array(
  194. 'type' => 'select',
  195. 'name' => $sFilterName,
  196. 'attrs' => array(
  197. 'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
  198. 'onChange' => 'javascript:' . $this->sJsObject . '.onChangeFilter(this)'
  199. ),
  200. 'value' => $sFilterValue,
  201. 'values' => array_merge(array('' => 'All'), $aFilterValues)
  202. );
  203. $oForm = new BxTemplFormView(array());
  204. return $oForm->genRow($aInputModules);
  205. }
  206. protected function _getSearchInput()
  207. {
  208. $aInputSearch = array(
  209. 'type' => 'text',
  210. 'name' => 'search',
  211. 'attrs' => array(
  212. 'id' => 'bx-grid-search-' . $this->_sObject,
  213. 'onKeyup' => 'javascript:$(this).off(\'keyup focusout\'); ' . $this->sJsObject . '.onChangeFilter(this)',
  214. 'onBlur' => 'javascript:' . $this->sJsObject . '.onChangeFilter(this)',
  215. )
  216. );
  217. $oForm = new BxTemplFormView(array());
  218. return $oForm->genRow($aInputSearch);
  219. }
  220. protected function _getDataSql ($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  221. {
  222. $this->_aOptions['source'] = "SELECT * FROM `" . $this->_aReportSystemInfo['table_track'] . "` " . $this->_aOptions['source'];
  223. if(strpos($sFilter, $this->_sParamsDivider) !== false)
  224. list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  225. if(isset($this->_sFilter1Value) && $this->_sFilter1Value !== ''){
  226. $this->_aOptions['source'] .= " AND `status` = " . $this->_sFilter1Value;
  227. }
  228. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  229. }
  230. }
  231. /** @} */