BxBaseMenuAddRelation.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. * Menu to add relation between profiles.
  11. */
  12. class BxBaseMenuAddRelation extends BxTemplMenu
  13. {
  14. protected $_sPreList;
  15. protected $_sConnection;
  16. protected $_iInitiator;
  17. protected $_iContent;
  18. public function __construct ($aObject, $oTemplate)
  19. {
  20. parent::__construct ($aObject, $oTemplate);
  21. $this->_sPreList = 'sys_relations';
  22. $this->_sConnection = 'sys_profiles_relations';
  23. $this->_iInitiator = bx_get_logged_profile_id();
  24. $this->_iContent = 0;
  25. }
  26. public function getMenuItems ()
  27. {
  28. $this->loadData();
  29. return parent::getMenuItems();
  30. }
  31. protected function _getMenuItem ($a)
  32. {
  33. $aResult = parent::_getMenuItem($a);
  34. if(empty($aResult) || !is_array($aResult))
  35. return $aResult;
  36. if(!empty($a['class']))
  37. $aResult['class_add'] .= ' ' . $a['class'];
  38. return $aResult;
  39. }
  40. protected function loadData()
  41. {
  42. $sClassHidden = 'bx-menu-add-relation-hidden';
  43. if(bx_get('profile_id') !== false)
  44. $this->_iContent = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  45. $oRelation = BxDolConnection::getObjectInstance($this->_sConnection);
  46. $aRelations = BxDolFormQuery::getDataItems($this->_sPreList, false, BX_DATA_VALUES_ALL);
  47. $aSuggest = array();
  48. $bSuggest = $oRelation->isConnected($this->_iContent, $this->_iInitiator);
  49. if($bSuggest) {
  50. $iRelation = $oRelation->getRelation($this->_iContent, $this->_iInitiator);
  51. if(!empty($iRelation) && !empty($aRelations[$iRelation]['Data']))
  52. $aSuggest = unserialize($aRelations[$iRelation]['Data']);
  53. }
  54. $aItems = array();
  55. foreach($aRelations as $iId => $aRelation) {
  56. $aItems[] = array(
  57. 'id' => $iId,
  58. 'name' => $iId,
  59. 'class' => $bSuggest && !in_array($iId, $aSuggest) ? $sClassHidden : '',
  60. 'title' => _t($aRelation[BX_DATA_VALUES_DEFAULT]),
  61. 'icon' => '',
  62. 'link' => 'javascript:void(0);',
  63. 'onclick' => "bx_conn_action(this, '" . $this->_sConnection . "', 'add', " . bx_js_string(json_encode(array('content' => $this->_iContent, 'relation' => $iId))) . ")"
  64. );
  65. }
  66. if($bSuggest && !empty($aSuggest))
  67. $aItems[] = array(
  68. 'id' => 'see_more',
  69. 'name' => 'see_more',
  70. 'class' => '',
  71. 'title' => _t('_see_more'),
  72. 'icon' => '',
  73. 'link' => 'javascript:void(0);',
  74. 'onclick' => bx_js_string("$(this).parents('li:first').hide().siblings('." . $sClassHidden . "').removeClass('" . $sClassHidden . "');")
  75. );
  76. $this->_aObject['menu_items'] = $aItems;
  77. }
  78. }
  79. /** @} */