BxBaseConnectionRelation.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * @see BxBaseConnection
  11. */
  12. class BxBaseConnectionRelation extends BxDolConnectionRelation
  13. {
  14. protected function __construct($aObject)
  15. {
  16. parent::__construct($aObject);
  17. $this->_aT = array_merge($this->_aT, [
  18. 'do_initiator' => '_sys_conn_relations_do_initiator',
  19. 'do_initiator_done' => '_sys_conn_relations_do_initiator_done',
  20. 'do_initiator_undo' => '_sys_conn_relations_do_initiator_undo',
  21. 'counter' => '_sys_conn_relations_counter'
  22. ]);
  23. }
  24. protected function _getActions($iInitiator, $iContent, $aParams = [])
  25. {
  26. $sName = $sTitle = '';
  27. $aActions = [];
  28. if($this->isConnected($iInitiator, $iContent)) {
  29. $sName = 'remove';
  30. $sTitle = $this->_aT['do_initiator_done'];
  31. $aActions = [[
  32. 'name' => 'remove',
  33. 'title' => ($sKey = 'txt_unsubscribe') && !empty($aParams[$sKey]) ? $aParams[$sKey] : $this->_aT['do_initiator_undo']
  34. ], [
  35. /*
  36. * An empty array item to show all items in popup.
  37. * More actions will be added later.
  38. */
  39. ]];
  40. }
  41. else {
  42. $sName = 'add';
  43. $sTitle = $this->_aT['do_initiator'];
  44. $aActions = [];
  45. $aSuggestions = [];
  46. $aRelations = $this->getRelations($iInitiator, $iContent, $aSuggestions);
  47. $bSuggestions = !empty($aSuggestions) && is_array($aSuggestions);
  48. $sJsObject = $this->getJsObjectName($iContent, $aParams);
  49. $sClassHidden = 'bx-menu-add-relation-hidden';
  50. foreach($aRelations as $iId => $aRelation) {
  51. $aActions[] = [
  52. 'id' => 'bx-conn-rl-' . $iId,
  53. 'name' => 'bx-conn-rl-' . $iId,
  54. 'class_add' => $bSuggestions && !in_array($iId, $aSuggestions) ? $sClassHidden : '',
  55. 'title' => _t($aRelation[BX_DATA_VALUES_DEFAULT]),
  56. 'icon' => '',
  57. 'link' => 'javascript:void(0);',
  58. 'onclick' => $sJsObject . ".connect(this, 'add', " . bx_js_string(json_encode(['content' => $iContent, 'relation' => $iId])) . ")"
  59. ];
  60. }
  61. if($bSuggestions)
  62. $aActions[] = [
  63. 'id' => 'see_more',
  64. 'name' => 'see_more',
  65. 'title' => _t('_see_more'),
  66. 'icon' => '',
  67. 'link' => 'javascript:void(0);',
  68. 'onclick' => bx_js_string("$(this).parents('li:first').hide().siblings('." . $sClassHidden . "').removeClass('" . $sClassHidden . "');")
  69. ];
  70. }
  71. return [
  72. 'name' => $sName,
  73. 'title' => $sTitle,
  74. 'items' => $aActions
  75. ];
  76. }
  77. protected function _getActionIconAsIcon($sAction)
  78. {
  79. $sDefault = 'sync';
  80. $aA2I = [
  81. 'add' => $sDefault,
  82. 'remove' => $sDefault
  83. ];
  84. return isset($aA2I[$sAction]) ? $aA2I[$sAction] : $sDefault;
  85. }
  86. protected function _getActionIconAsEmoji($sAction)
  87. {
  88. $sDefault = '🔁';
  89. $aA2I = [
  90. 'add' => $sDefault,
  91. 'remove' => $sDefault
  92. ];
  93. return isset($aA2I[$sAction]) ? $aA2I[$sAction] : $sDefault;
  94. }
  95. protected function _getActionIconAsImage($sAction)
  96. {
  97. $sDefault = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-refresh-cw-icon lucide-refresh-cw"><path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"/><path d="M21 3v5h-5"/><path d="M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"/><path d="M8 16H3v5"/></svg>';
  98. $aA2I = [
  99. 'add' => $sDefault,
  100. 'remove' => $sDefault
  101. ];
  102. return isset($aA2I[$sAction]) ? $aA2I[$sAction] : $sDefault;
  103. }
  104. }