FormField.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /**
  3. * This file is part of PHPWord - A pure PHP library for reading and writing
  4. * word processing documents.
  5. *
  6. * PHPWord is free software distributed under the terms of the GNU Lesser
  7. * General Public License version 3 as published by the Free Software Foundation.
  8. *
  9. * For the full copyright and license information, please read the LICENSE
  10. * file that was distributed with this source code. For the full list of
  11. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
  12. *
  13. * @see https://github.com/PHPOffice/PHPWord
  14. * @copyright 2010-2018 PHPWord contributors
  15. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  16. */
  17. namespace PhpOffice\PhpWord\Element;
  18. /**
  19. * Form field element
  20. *
  21. * @since 0.12.0
  22. * @see http://www.datypic.com/sc/ooxml/t-w_CT_FFData.html
  23. */
  24. class FormField extends Text
  25. {
  26. /**
  27. * Form field type: textinput|checkbox|dropdown
  28. *
  29. * @var string
  30. */
  31. private $type = 'textinput';
  32. /**
  33. * Form field name
  34. *
  35. * @var string|bool|int
  36. */
  37. private $name;
  38. /**
  39. * Default value
  40. *
  41. * - TextInput: string
  42. * - CheckBox: bool
  43. * - DropDown: int Index of entries (zero based)
  44. *
  45. * @var string|bool|int
  46. */
  47. private $default;
  48. /**
  49. * Value
  50. *
  51. * @var string|bool|int
  52. */
  53. private $value;
  54. /**
  55. * Dropdown entries
  56. *
  57. * @var array
  58. */
  59. private $entries = array();
  60. /**
  61. * Create new instance
  62. *
  63. * @param string $type
  64. * @param mixed $fontStyle
  65. * @param mixed $paragraphStyle
  66. */
  67. public function __construct($type, $fontStyle = null, $paragraphStyle = null)
  68. {
  69. parent::__construct(null, $fontStyle, $paragraphStyle);
  70. $this->setType($type);
  71. }
  72. /**
  73. * Get type
  74. *
  75. * @return string
  76. */
  77. public function getType()
  78. {
  79. return $this->type;
  80. }
  81. /**
  82. * Set type
  83. *
  84. * @param string $value
  85. * @return self
  86. */
  87. public function setType($value)
  88. {
  89. $enum = array('textinput', 'checkbox', 'dropdown');
  90. $this->type = $this->setEnumVal($value, $enum, $this->type);
  91. return $this;
  92. }
  93. /**
  94. * Get name
  95. *
  96. * @return string
  97. */
  98. public function getName()
  99. {
  100. return $this->name;
  101. }
  102. /**
  103. * Set name
  104. *
  105. * @param string|bool|int $value
  106. * @return self
  107. */
  108. public function setName($value)
  109. {
  110. $this->name = $value;
  111. return $this;
  112. }
  113. /**
  114. * Get default
  115. *
  116. * @return string|bool|int
  117. */
  118. public function getDefault()
  119. {
  120. return $this->default;
  121. }
  122. /**
  123. * Set default
  124. *
  125. * @param string|bool|int $value
  126. * @return self
  127. */
  128. public function setDefault($value)
  129. {
  130. $this->default = $value;
  131. return $this;
  132. }
  133. /**
  134. * Get value
  135. *
  136. * @return string|bool|int
  137. */
  138. public function getValue()
  139. {
  140. return $this->value;
  141. }
  142. /**
  143. * Set value
  144. *
  145. * @param string|bool|int $value
  146. * @return self
  147. */
  148. public function setValue($value)
  149. {
  150. $this->value = $value;
  151. return $this;
  152. }
  153. /**
  154. * Get entries
  155. *
  156. * @return array
  157. */
  158. public function getEntries()
  159. {
  160. return $this->entries;
  161. }
  162. /**
  163. * Set entries
  164. *
  165. * @param array $value
  166. * @return self
  167. */
  168. public function setEntries($value)
  169. {
  170. $this->entries = $value;
  171. return $this;
  172. }
  173. }