BxBaseReportsGrid.php 9.9 KB

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