BxCnvGrid.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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)
  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. $oModule = BxDolModule::getInstance($this->MODULE);
  80. $CNF = &$oModule->_oConfig->CNF;
  81. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_ADD_ENTRY']);
  82. header('Location:' . $sUrl);
  83. }
  84. protected function _getActionAdd ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  85. {
  86. $oModule = BxDolModule::getInstance($this->MODULE);
  87. $CNF = &$oModule->_oConfig->CNF;
  88. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_ADD_ENTRY']);
  89. $a['attr']['onclick'] = "document.location='$sUrl'";
  90. unset($a['attr']['bx_grid_action_independent']);
  91. return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  92. }
  93. protected function _getCellHeaderWrapper ($sKey, $aField, $sHeader, $sAttr)
  94. {
  95. $sHeader = '<span>' . $sHeader . '</span>';
  96. return parent::_getCellHeaderWrapper ($sKey, $aField, $sHeader, $sAttr);
  97. }
  98. protected function _getCellPreview ($mixedValue, $sKey, $aField, $aRow)
  99. {
  100. return parent::_getCellDefault ('', $sKey, $aField, $aRow);
  101. }
  102. protected function _getCellLastReplyTimestamp ($mixedValue, $sKey, $aField, $aRow)
  103. {
  104. $oModule = BxDolModule::getInstance($this->MODULE);
  105. $s = $oModule->_oTemplate->entryMessagePreviewInGrid ($aRow);
  106. return parent::_getCellDefault ($s, $sKey, $aField, $aRow);
  107. }
  108. protected function _getCellCollaborators ($mixedValue, $sKey, $aField, $aRow)
  109. {
  110. $oModule = BxDolModule::getInstance($this->MODULE);
  111. $s = $oModule->_oTemplate->entryCollaborators ($aRow);
  112. return parent::_getCellDefault ($s, $sKey, $aField, $aRow);
  113. }
  114. protected function _getCellComments ($mixedValue, $sKey, $aField, $aRow)
  115. {
  116. $oModule = BxDolModule::getInstance($this->MODULE);
  117. $s = $oModule->_oTemplate->getMessageLabel ($aRow);
  118. return parent::_getCellDefault ('<div class="bx-cnv-grid-field-messages"><span>' . (1 + $mixedValue) . '</span>' . $s . '</div>', $sKey, $aField, $aRow);
  119. }
  120. protected function _doDelete ($iId, $aParams = array())
  121. {
  122. $oModule = BxDolModule::getInstance($this->MODULE);
  123. if ($sErrorMsg = $oModule->deleteConvo ($iId))
  124. return 0;
  125. return 1;
  126. }
  127. protected function _addJsCss()
  128. {
  129. parent::_addJsCss();
  130. $oModule = BxDolModule::getInstance($this->MODULE);
  131. $oModule->_oTemplate->addJs('main.js');
  132. $oModule->_oTemplate->addCss(array('main-media-tablet.css', 'main-media-desktop.css'));
  133. }
  134. }
  135. /** @} */