Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. <?php
  2. namespace NominaEntity;
  3. use DoctrineCommonCollectionsArrayCollection;
  4.  
  5. use DoctrineORMMapping as ORM;
  6. use ZendFormAnnotation;
  7. use NominaEntityEmpleadosDetalles;
  8.  
  9.  
  10. /**
  11. * Empleado
  12. *
  13. * @ORMTable(name="empleado")
  14. * @ORMEntity
  15. * @AnnotationHydrator("ZendStdlibHydratorObjectProperty")
  16. * @AnnotationName("EmpleadoForm")
  17. */
  18. class Empleado
  19. {
  20. /**
  21. * @var integer
  22. *
  23. * @ORMColumn(name="id", type="integer", nullable=false)
  24. * @ORMId
  25. * @ORMGeneratedValue(strategy="IDENTITY")
  26. */
  27. private $id;
  28.  
  29. /**
  30. * @var string
  31. *
  32. * @ORMColumn(name="nombre", type="string", length=255, nullable=false)
  33. * @AnnotationType("ZendFormElementText")
  34. * @AnnotationRequired({"required":"true"})
  35. * @AnnotationFilter({"name":"StripTags"})
  36. * @AnnotationOptions({"label":"Nombre"})
  37. * @AnnotationAttributes({"class":"form-control"})
  38. * @AnnotationValidator({"name":"NotEmpty","options":{"messages":{"isEmpty":"no debe estar vacio"}}})
  39. */
  40. private $nombre;
  41.  
  42. /**
  43. * @var EmpleadosDetalles $detalles
  44. * @ORMOneToMany(targetEntity="NominaEntityEmpleadosDetalles", mappedBy="empleado", cascade={"persist"})
  45. * @AnnotationComposedObject("NominaEntityEmpleadosDetalles")
  46. */
  47. private $detalles;
  48.  
  49. /**
  50. * @AnnotationType("ZendFormElementSubmit")
  51. * @AnnotationAttributes({"value":"Procesar"})
  52. * @AnnotationAttributes({"class":"btn btn-primary"})
  53. */
  54. public $submit;
  55.  
  56. public function __construct() {
  57. $this->detalles = new ArrayCollection();
  58. }
  59.  
  60. public function getDetalles() {
  61. return $this->detalles;
  62. }
  63.  
  64. /**
  65. * Set nombre
  66. *
  67. * @param string $nombre
  68. * @return Empleado
  69. */
  70. public function setNombre($nombre)
  71. {
  72. $this->nombre = $nombre;
  73.  
  74. return $this;
  75. }
  76.  
  77. /**
  78. * Get nombre
  79. *
  80. * @return string
  81. */
  82. public function getNombre()
  83. {
  84. return $this->nombre;
  85. }
  86. }
  87.  
  88. <?php
  89. namespace NominaEntity;
  90.  
  91. use DoctrineORMMapping as ORM;
  92. use ZendFormAnnotation;
  93. /**
  94. * EmpleadosDetalles
  95. *
  96. * @ORMTable(name="empleadosDetalles", indexes={@ORMIndex(name="fk_empleado", columns={"idEmpleado"})})
  97. * @ORMEntity
  98. * @AnnotationHydrator("ZendStdlibHydratorObjectProperty")
  99. * @AnnotationName("EmpleadoDetallesForm")
  100. */
  101. class EmpleadosDetalles
  102. {
  103. /**
  104. * @var integer
  105. *
  106. * @ORMColumn(name="id", type="integer", nullable=false)
  107. * @ORMId
  108. * @ORMGeneratedValue(strategy="IDENTITY")
  109. */
  110. private $id;
  111.  
  112. /**
  113. * @var string
  114. *
  115. * @ORMColumn(name="salario", type="int", nullable=false)
  116. * @AnnotationType("ZendFormElementText")
  117. * @AnnotationRequired({"required":"true"})
  118. * @AnnotationFilter({"name":"StripTags"})
  119. * @AnnotationOptions({"label":"Salario"})
  120. * @AnnotationAttributes({"class":"form-control"})
  121. * @AnnotationValidator({"name":"NotEmpty","options":{"messages":{"isEmpty":"no debe estar vacio"}}})
  122. */
  123. private $salario = '0';
  124.  
  125. /**
  126. * @var string
  127. *
  128. * @ORMColumn(name="numero", type="string", length=20, nullable=true)
  129. * @AnnotationType("ZendFormElementText")
  130. * @AnnotationRequired({"required":"true"})
  131. * @AnnotationFilter({"name":"StripTags"})
  132. * @AnnotationOptions({"label":"Numero"})
  133. * @AnnotationAttributes({"class":"form-control"})
  134. * @AnnotationValidator({"name":"NotEmpty","options":{"messages":{"isEmpty":"no debe estar vacio"}}})
  135. */
  136. private $numero;
  137.  
  138.  
  139. /**
  140. * @ORMColumn(name="idEmpleado", type="integer", length=11, nullable=false)
  141. */
  142. private $idEmpleado;
  143.  
  144. /**
  145. * @ORMManyToOne(targetEntity="NominaEntityEmpleado", inversedBy="detalles")
  146. * @ORMJoinColumns({
  147. * @ORMJoinColumn(name="idEmpleado", referencedColumnName="id")
  148. * })
  149. */
  150. protected $empleado;
  151.  
  152. /**
  153. * Set salario
  154. *
  155. * @param integer $salario
  156. * @return EmpleadosDetalles
  157. */
  158. public function setSalario($salario)
  159. {
  160. $this->salario = $salario;
  161.  
  162. return $this;
  163. }
  164.  
  165. /**
  166. * Get salario
  167. *
  168. * @return integer
  169. */
  170. public function getSalario()
  171. {
  172. return $this->salario;
  173. }
  174.  
  175. /**
  176. * Set numero
  177. *
  178. * @param string $numero
  179. * @return EmpleadosDetalles
  180. */
  181. public function setNumero($numero)
  182. {
  183. $this->numero = $numero;
  184.  
  185. return $this;
  186. }
  187.  
  188. /**
  189. * Get numero
  190. *
  191. * @return string
  192. */
  193. public function getNumero()
  194. {
  195. return $this->numero;
  196. }
  197.  
  198.  
  199. public function setEmpleado(Empleado $empleado)
  200. {
  201. $this->empleado = $empleado;
  202. return $this;
  203. }
  204.  
  205. public function getEmpleado()
  206. {
  207. return $this->empleado;
  208. }
  209.  
  210. }
  211.  
  212. public function addAction() {
  213. $view = new ViewModel();
  214. $empleado = new Empleado();
  215.  
  216. $entityManager = $this->entityManager();
  217. $builder = new DoctrineAnnotationBuilder($entityManager);
  218. $form = $builder->createForm($empleado);
  219.  
  220. $request = $this->getRequest();
  221. if ($request->isPost()) {
  222. $form->bind($empleado);
  223. $form->setHydrator(new DoctrineHydrator($entityManager,'NominaEntityEmpleado'));
  224. $form->setValidationGroup('nombre');
  225. $form->setData($request->getPost());
  226. if ($form->isValid()) {
  227. $entityManager->persist($empleado);
  228. $entityManager->flush();
  229. $this->redirect()->toRoute('empleado');
  230. } else {
  231. $view->messages = $form->getMessages();
  232. }
  233. }
  234. $view->form = $form;
  235. return $view;
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement