BxDolGridSubscriptions.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 BxDolGridSubscriptions extends BxTemplGrid
  11. {
  12. protected $_bOwner = false;
  13. protected $_sObjectConnections = 'sys_profiles_subscriptions';
  14. protected $_oConnection;
  15. public function __construct ($aOptions, $oTemplate = false)
  16. {
  17. parent::__construct ($aOptions, $oTemplate);
  18. $this->_sDefaultSortingOrder = 'DESC';
  19. $this->_oConnection = BxDolConnection::getObjectInstance($this->_sObjectConnections);
  20. if (!$this->_oConnection)
  21. return;
  22. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  23. if (!$iProfileId)
  24. return;
  25. $oProfile = BxDolProfile::getInstance($iProfileId);
  26. if (!$oProfile)
  27. return;
  28. if ($oProfile->id() == bx_get_logged_profile_id())
  29. $this->_bOwner = true;
  30. $aSQLParts = $this->_oConnection->getConnectedContentAsSQLParts('p', 'id', $oProfile->id());
  31. $this->addMarkers(array(
  32. 'profile_id' => $oProfile->id(),
  33. 'join_connections' => $aSQLParts['join']
  34. ));
  35. }
  36. protected function _delete ($mixedId)
  37. {
  38. list($iId, $iViewedId) = $this->_prepareIds();
  39. if(!$this->_oConnection->isConnected($iViewedId, $iId))
  40. return true;
  41. return $this->_oConnection->removeConnection($iViewedId, $iId);
  42. }
  43. protected function _getCellName ($mixedValue, $sKey, $aField, $aRow)
  44. {
  45. $oProfile = BxDolProfile::getInstance($aRow['id']);
  46. if (!$oProfile)
  47. return _t('_sys_txt_error_occured');
  48. return parent::_getCellDefault ($oProfile->getUnit(), $sKey, $aField, $aRow);
  49. }
  50. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  51. {
  52. if (!isLogged() || !$this->_bOwner)
  53. return '';
  54. return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  55. }
  56. protected function _prepareIds ()
  57. {
  58. $iViewedId = bx_get_logged_profile_id();
  59. $iId = 0;
  60. $aIds = bx_get('ids');
  61. if($aIds && is_array($aIds))
  62. $mixedId = array_pop($aIds);
  63. if(strpos($mixedId, ':') !== false) {
  64. list($iId, $iViewedId) = explode (':', $mixedId);
  65. $iId = (int)$iId;
  66. $iViewedId = (int)$iViewedId;
  67. }
  68. else
  69. $iId = (int)$mixedId;
  70. return array($iId, $iViewedId);
  71. }
  72. }
  73. /** @} */