BxBaseConnectionRelation.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. //TODO: Continue from here. Copy actions (relation types: mom, dad, etc) from menu into actions list.
  25. protected function _getActions($iInitiator, $iContent, $aParams = [])
  26. {
  27. $sName = $sTitle = '';
  28. $aActions = [];
  29. if($this->isConnected($iInitiator, $iContent)) {
  30. $sName = 'remove';
  31. $sTitle = $this->_aT['do_initiator_done'];
  32. $aActions = [[
  33. 'name' => 'remove',
  34. 'title' => ($sKey = 'txt_unsubscribe') && !empty($aParams[$sKey]) ? $aParams[$sKey] : $this->_aT['do_initiator_undo']
  35. ], [
  36. /*
  37. * An empty array item to show all items in popup.
  38. * More actions will be added later.
  39. */
  40. ]];
  41. }
  42. else {
  43. $sName = 'add';
  44. $sTitle = $this->_aT['do_initiator'];
  45. $aActions = [];
  46. $aSuggestions = [];
  47. $aRelations = $this->getRelations($iInitiator, $iContent, $aSuggestions);
  48. $bSuggestions = !empty($aSuggestions) && is_array($aSuggestions);
  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' => "bx_conn_action(this, '" . $this->_sObject . "', '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. //TODO: Get emoji similar to
  87. protected function _getActionIconAsEmoji($sAction)
  88. {
  89. $sDefault = '';
  90. $aA2I = [
  91. 'add' => $sDefault,
  92. 'remove' => $sDefault
  93. ];
  94. return isset($aA2I[$sAction]) ? $aA2I[$sAction] : $sDefault;
  95. }
  96. protected function _getActionIconAsImage($sAction)
  97. {
  98. $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>';
  99. $aA2I = [
  100. 'add' => $sDefault,
  101. 'remove' => $sDefault
  102. ];
  103. return isset($aA2I[$sAction]) ? $aA2I[$sAction] : $sDefault;
  104. }
  105. }