BxCnvGrid.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 Convos Convos
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
  12. class BxCnvGrid extends BxBaseModGeneralGridAdministration
  13. {
  14. protected $MODULE;
  15. protected $_sFilter1Name;
  16. protected $_sFilter1Value;
  17. protected $_aFilter1Values;
  18. public function __construct ($aOptions, $oTemplate = false)
  19. {
  20. $this->MODULE = 'bx_convos';
  21. parent::__construct ($aOptions, $oTemplate);
  22. $this->_sDefaultSortingOrder = 'DESC';
  23. if ($iFolderId = (int)bx_get('folder_id'))
  24. $this->addMarkers(array(
  25. 'folder_id' => $iFolderId,
  26. 'profile_id' => bx_get_logged_profile_id(),
  27. ));
  28. $this->_sFilter1Name = 'filter1';
  29. $this->_aFilter1Values = array(
  30. '' => _t('_bx_cnv_grid_filter_item_title_adm_all'),
  31. 'unread' => _t('_bx_cnv_grid_filter_item_title_adm_unread'),
  32. );
  33. $sFilter1 = bx_get($this->_sFilter1Name);
  34. if(!empty($sFilter1)) {
  35. $this->_sFilter1Value = bx_process_input($sFilter1);
  36. $this->_aQueryAppend['filter1'] = $this->_sFilter1Value;
  37. }
  38. $this->_sManageType = BX_DOL_MANAGE_TOOLS_COMMON;
  39. }
  40. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  41. {
  42. if(strpos($sFilter, $this->_sParamsDivider) !== false)
  43. list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  44. if(!empty($this->_sFilter1Value)){
  45. $CNF = &$this->_oModule->_oConfig->CNF;
  46. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" WHERE `c`.`comments` > `f`.`read_comments` ");
  47. }
  48. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  49. }
  50. //--- Layout methods ---//
  51. protected function _getFilterControls()
  52. {
  53. parent::_getFilterControls();
  54. return $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
  55. }
  56. protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues, $bAddSelectOne = true)
  57. {
  58. if(empty($sFilterName) || empty($aFilterValues))
  59. return '';
  60. $CNF = &$this->_oModule->_oConfig->CNF;
  61. $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
  62. foreach($aFilterValues as $sKey => $sValue)
  63. $aFilterValues[$sKey] = _t($sValue);
  64. $aInputModules = array(
  65. 'type' => 'select',
  66. 'name' => $sFilterName,
  67. 'attrs' => array(
  68. 'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
  69. 'onChange' => 'javascript:' . $sJsObject . '.onChangeFilter(this)'
  70. ),
  71. 'value' => $sFilterValue,
  72. 'values' => $aFilterValues
  73. );
  74. $oForm = new BxTemplFormView(array());
  75. return $oForm->genRow($aInputModules);
  76. }
  77. public function performActionCompose()
  78. {
  79. $CNF = &$this->_oModule->_oConfig->CNF;
  80. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_ADD_ENTRY']);
  81. header('Location:' . $sUrl);
  82. }
  83. protected function _getActionAdd ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  84. {
  85. $CNF = &$this->_oModule->_oConfig->CNF;
  86. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_ADD_ENTRY']);
  87. $a['attr']['onclick'] = "document.location='$sUrl'";
  88. unset($a['attr']['bx_grid_action_independent']);
  89. return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  90. }
  91. protected function _getCellHeaderWrapper ($sKey, $aField, $sHeader, $sAttr)
  92. {
  93. $sHeader = '<span>' . $sHeader . '</span>';
  94. return parent::_getCellHeaderWrapper ($sKey, $aField, $sHeader, $sAttr);
  95. }
  96. protected function _getCellPreview ($mixedValue, $sKey, $aField, $aRow)
  97. {
  98. return parent::_getCellDefault ('', $sKey, $aField, $aRow);
  99. }
  100. protected function _getCellLastReplyTimestamp ($mixedValue, $sKey, $aField, $aRow)
  101. {
  102. $s = $this->_oModule->_oTemplate->entryMessagePreviewInGrid ($aRow);
  103. return parent::_getCellDefault ($s, $sKey, $aField, $aRow);
  104. }
  105. protected function _getCellCollaborators ($mixedValue, $sKey, $aField, $aRow)
  106. {
  107. $s = $this->_oModule->_oTemplate->entryCollaborators ($aRow);
  108. return parent::_getCellDefault ($s, $sKey, $aField, $aRow);
  109. }
  110. protected function _getCellComments ($mixedValue, $sKey, $aField, $aRow)
  111. {
  112. $s = $this->_oModule->_oTemplate->getMessageLabel(1 + $mixedValue, $aRow);
  113. return parent::_getCellDefault ($s, $sKey, $aField, $aRow);
  114. }
  115. protected function _doDelete ($iId, $aParams = array())
  116. {
  117. if ($sErrorMsg = $this->_oModule->deleteConvo ($iId))
  118. return 0;
  119. return 1;
  120. }
  121. protected function _addJsCss()
  122. {
  123. parent::_addJsCss();
  124. $this->_oModule->_oTemplate->addJs('main.js');
  125. $this->_oModule->_oTemplate->addCss(array('main-media-tablet.css', 'main-media-desktop.css'));
  126. }
  127. }
  128. /** @} */