BxDolGridSubscribedMe.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
  10. class BxDolGridSubscribedMe extends BxTemplGrid
  11. {
  12. protected $_bOwner = false;
  13. protected $_sObjectConnections = 'sys_profiles_subscriptions';
  14. protected $_oConnection;
  15. protected $_sConnectionMethod = 'getConnectedInitiatorsAsSQLParts';
  16. public function __construct ($aOptions, $oTemplate = false)
  17. {
  18. parent::__construct ($aOptions, $oTemplate);
  19. $this->_sDefaultSortingOrder = 'DESC';
  20. $this->_oConnection = BxDolConnection::getObjectInstance($this->_sObjectConnections);
  21. if (!$this->_oConnection)
  22. return;
  23. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  24. if (!$iProfileId)
  25. return;
  26. $oProfile = BxDolProfile::getInstance($iProfileId);
  27. if (!$oProfile)
  28. return;
  29. if ($oProfile->id() == bx_get_logged_profile_id())
  30. $this->_bOwner = true;
  31. $aSQLParts = $this->_oConnection->{$this->_sConnectionMethod}('p', 'id', $oProfile->id());
  32. $this->addMarkers(array(
  33. 'profile_id' => $oProfile->id(),
  34. 'join_connections' => $aSQLParts['join']
  35. ));
  36. }
  37. /**
  38. * 'accept' action handler
  39. */
  40. public function performActionSubscribe()
  41. {
  42. list($iId, $iViewedId) = $this->_prepareIds();
  43. if(!$iId)
  44. return echoJson(array('msg' => _t('_sys_txt_error_occured')));
  45. $a = $this->_oConnection->actionAdd($iId, $iViewedId);
  46. if(!empty($a['err']))
  47. return echoJson(array('msg' => $a['msg']));
  48. return echoJson(array('grid' => $this->getCode(false), 'blink' => $iId));
  49. }
  50. protected function _getCellName ($mixedValue, $sKey, $aField, $aRow)
  51. {
  52. $oProfile = BxDolProfile::getInstance($aRow['id']);
  53. if (!$oProfile)
  54. return _t('_sys_txt_error_occured');
  55. return parent::_getCellDefault ($oProfile->getUnit(), $sKey, $aField, $aRow);
  56. }
  57. protected function _getActionSubscribe ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  58. {
  59. $iViewerId = bx_get_logged_profile_id();
  60. if(!isLogged() || $iViewerId == $aRow['id'] || $this->_oConnection->isConnected($iViewerId, $aRow['id']))
  61. return '';
  62. return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  63. }
  64. protected function _prepareIds ()
  65. {
  66. $iViewedId = bx_get_logged_profile_id();
  67. $iId = 0;
  68. $aIds = bx_get('ids');
  69. if($aIds && is_array($aIds))
  70. $mixedId = array_pop($aIds);
  71. if(strpos($mixedId, ':') !== false) {
  72. list($iId, $iViewedId) = explode (':', $mixedId);
  73. $iId = (int)$iId;
  74. $iViewedId = (int)$iViewedId;
  75. }
  76. else
  77. $iId = (int)$mixedId;
  78. return array($iId, $iViewedId);
  79. }
  80. }
  81. /** @} */