BxDolGridRelatedMe.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 UnaCore UNA Core
  7. * @{
  8. */
  9. class BxDolGridRelatedMe extends BxDolGridConnectionIn
  10. {
  11. public function __construct ($aOptions, $oTemplate = false)
  12. {
  13. parent::__construct ($aOptions, $oTemplate);
  14. $this->_sConnectionObject = 'sys_profiles_relations';
  15. }
  16. public function performActionConfirm()
  17. {
  18. list($iId, $iViewedId) = $this->_prepareIds();
  19. if(!$iId)
  20. return echoJson(array('msg' => _t('_sys_txt_error_occured')));
  21. $a = $this->_oConnection->actionConfirm($iId, $iViewedId);
  22. if (isset($a['err']) && $a['err'])
  23. echoJson(array('msg' => $a['msg']));
  24. else
  25. echoJson(array('grid' => $this->getCode(false), 'blink' => $iId));
  26. }
  27. public function performActionDecline()
  28. {
  29. list($iId, $iViewedId) = $this->_prepareIds();
  30. if(!$iId)
  31. return echoJson(array('msg' => _t('_sys_txt_error_occured')));
  32. $a = $this->_oConnection->actionReject($iId, $iViewedId);
  33. if (isset($a['err']) && $a['err'])
  34. echoJson(array('msg' => $a['msg']));
  35. else
  36. echoJson(array('grid' => $this->getCode(false), 'blink' => $iId));
  37. }
  38. protected function _getCellMutual($mixedValue, $sKey, $aField, $aRow)
  39. {
  40. $mixedValue = _t('_sys_' . ((int)$mixedValue != 1 ? 'un' : '') . 'confirmed');
  41. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  42. }
  43. protected function _getCellRelation($mixedValue, $sKey, $aField, $aRow)
  44. {
  45. return parent::_getCellDefault($this->_oConnection->getRelationTranslation($mixedValue), $sKey, $aField, $aRow);
  46. }
  47. protected function _getActionConfirm($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  48. {
  49. if(!$this->_bOwner || $aRow['mutual'])
  50. return '';
  51. return parent::_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  52. }
  53. protected function _getActionDecline($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  54. {
  55. if(!$this->_bOwner || $aRow['mutual'])
  56. return '';
  57. return parent::_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  58. }
  59. protected function _getActionAdd($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  60. {
  61. if(!isLogged() || (int)$aRow['id'] == $this->_iViewerId)
  62. return '';
  63. if($this->_oConnection->isConnected($this->_iViewerId, $aRow['id']))
  64. return '';
  65. unset($a['attr']['bx_grid_action_single']);
  66. $a['attr']['onclick'] = "javascript: bx_menu_popup('sys_add_relation', window, {}, {profile_id: " . $aRow['id'] . "});";
  67. return parent::_getActionDefault($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  68. }
  69. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  70. {
  71. if (!isLogged() || !$this->_bOwner)
  72. return '';
  73. return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  74. }
  75. protected function _delete ($mixedId)
  76. {
  77. list($iId, $iViewedId) = $this->_prepareIds();
  78. if(!$this->_oConnection->isConnected($iId, $iViewedId))
  79. return true;
  80. return $this->_oConnection->removeConnection($iId, $iViewedId);
  81. }
  82. protected function _getDataSql ($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  83. {
  84. if(!$this->_bOwner)
  85. $this->_aOptions['source'] .= " AND `c`.`mutual`='1'";
  86. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  87. }
  88. }
  89. /** @} */