linkedsetfield.class.inc.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. // Copyright (C) 2010-2016 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. namespace Combodo\iTop\Form\Field;
  19. use \Combodo\iTop\Form\Field\Field;
  20. /**
  21. * Description of LinkedSetField
  22. *
  23. * @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
  24. */
  25. class LinkedSetField extends Field
  26. {
  27. const DEFAULT_INDIRECT = false;
  28. const DEFAULT_DISPLAY_OPENED = false;
  29. protected $sTargetClass;
  30. protected $sExtKeyToRemote;
  31. protected $bIndirect;
  32. protected $bDisplayOpened;
  33. protected $aAttributesToDisplay;
  34. protected $sSearchEndpoint;
  35. protected $sInformationEndpoint;
  36. public function __construct($sId, \Closure $onFinalizeCallback = null)
  37. {
  38. $this->sTargetClass = null;
  39. $this->sExtKeyToRemote = null;
  40. $this->bIndirect = static::DEFAULT_INDIRECT;
  41. $this->bDisplayOpened = static::DEFAULT_DISPLAY_OPENED;
  42. $this->aAttributesToDisplay = array();
  43. $this->sSearchEndpoint = null;
  44. $this->sInformationEndpoint = null;
  45. parent::__construct($sId, $onFinalizeCallback);
  46. }
  47. /**
  48. *
  49. * @return string
  50. */
  51. public function GetTargetClass()
  52. {
  53. return $this->sTargetClass;
  54. }
  55. /**
  56. *
  57. * @param string $sTargetClass
  58. * @return \Combodo\iTop\Form\Field\LinkedSetField
  59. */
  60. public function SetTargetClass($sTargetClass)
  61. {
  62. $this->sTargetClass = $sTargetClass;
  63. return $sTargetClass;
  64. }
  65. /**
  66. *
  67. * @return string
  68. */
  69. public function GetExtKeyToRemote()
  70. {
  71. return $this->sExtKeyToRemote;
  72. }
  73. /**
  74. *
  75. * @param string $sExtKeyToRemote
  76. * @return \Combodo\iTop\Form\Field\LinkedSetField
  77. */
  78. public function SetExtKeyToRemote($sExtKeyToRemote)
  79. {
  80. $this->sExtKeyToRemote = $sExtKeyToRemote;
  81. return $sExtKeyToRemote;
  82. }
  83. /**
  84. *
  85. * @return boolean
  86. */
  87. public function IsIndirect()
  88. {
  89. return $this->bIndirect;
  90. }
  91. /**
  92. *
  93. * @param boolean $bIndirect
  94. * @return \Combodo\iTop\Form\Field\LinkedSetField
  95. */
  96. public function SetIndirect($bIndirect)
  97. {
  98. $this->bIndirect = $bIndirect;
  99. return $this;
  100. }
  101. /**
  102. * Returns if the field should be displayed opened on initialization
  103. *
  104. * @return boolean
  105. */
  106. public function GetDisplayOpened()
  107. {
  108. return $this->bDisplayOpened;
  109. }
  110. /**
  111. * Sets if the field should be displayed opened on initialization
  112. *
  113. * @param $bDisplayOpened
  114. * @return \Combodo\iTop\Form\Field\LinkedSetField
  115. */
  116. public function SetDisplayOpened($bDisplayOpened)
  117. {
  118. $this->bDisplayOpened = $bDisplayOpened;
  119. return $this;
  120. }
  121. /**
  122. * Returns a hash array of attributes to be displayed in the linkedset in the form $sAttCode => $sAttLabel
  123. *
  124. * @param $bAttCodesOnly If set to true, will return only the attcodes
  125. * @return array
  126. */
  127. public function GetAttributesToDisplay($bAttCodesOnly = false)
  128. {
  129. return ($bAttCodesOnly) ? array_keys($this->aAttributesToDisplay) : $this->aAttributesToDisplay;
  130. }
  131. /**
  132. *
  133. * @param array $aAttCodes
  134. * @return \Combodo\iTop\Form\Field\LinkedSetField
  135. */
  136. public function SetAttributesToDisplay(array $aAttributesToDisplay)
  137. {
  138. $this->aAttributesToDisplay = $aAttributesToDisplay;
  139. return $this;
  140. }
  141. public function GetSearchEndpoint()
  142. {
  143. return $this->sSearchEndpoint;
  144. }
  145. public function SetSearchEndpoint($sSearchEndpoint)
  146. {
  147. $this->sSearchEndpoint = $sSearchEndpoint;
  148. return $this;
  149. }
  150. public function GetInformationEndpoint()
  151. {
  152. return $this->sInformationEndpoint;
  153. }
  154. public function SetInformationEndpoint($sInformationEndpoint)
  155. {
  156. $this->sInformationEndpoint = $sInformationEndpoint;
  157. return $this;
  158. }
  159. }