/module/CandidatosApi/src/CandidatosApi/Model/Candidato.php

https://bitbucket.org/brunobispo/webgoal-vagas-api · PHP · 425 lines · 256 code · 51 blank · 118 comment · 1 complexity · 78c0801e27f9dd393bc51e060dfe5361 MD5 · raw file

  1. <?php
  2. /**
  3. * Entidade Candidato
  4. */
  5. namespace CandidatosApi\Model;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use VagasApi\Model\Vaga;
  8. use VagasApi\Mapper\VagaInterface as VagaMapper;
  9. use Zend\InputFilter\Factory;
  10. use Zend\InputFilter\InputFilter;
  11. use Zend\InputFilter\InputFilterAwareInterface;
  12. use Zend\InputFilter\InputFilterInterface;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. /**
  15. * @ORM\Entity
  16. * @ORM\Table(name="candidato")
  17. */
  18. class Candidato implements InputFilterAwareInterface
  19. {
  20. /**
  21. * @var InputFilterInterface
  22. */
  23. protected $inputFilter;
  24. /**
  25. * Usado para validar as vagas existentes
  26. *
  27. * @var VagaMapper;
  28. */
  29. protected $vagasMapper;
  30. /**
  31. * @ORM\Id
  32. * @ORM\GeneratedValue
  33. * @ORM\Column(type="integer")
  34. * @var int
  35. **/
  36. protected $id;
  37. /**
  38. * @ORM\Column(type="string")
  39. * @var string
  40. */
  41. protected $nome;
  42. /**
  43. * @ORM\Column(type="date")
  44. * @var string
  45. */
  46. protected $nascimento;
  47. /**
  48. * @ORM\ManyToOne(targetEntity="VagasApi\Model\Vaga")
  49. * @var string
  50. */
  51. protected $vaga;
  52. /**
  53. * @ORM\Column(type="text")
  54. * @var string
  55. */
  56. protected $ondeEstudou;
  57. /**
  58. * @ORM\Column(type="text")
  59. * @var string
  60. */
  61. protected $ondeTrabalhou;
  62. /**
  63. * @ORM\Column(type="text")
  64. * @var string
  65. */
  66. protected $experiencia;
  67. /**
  68. * @ORM\Column(type="decimal")
  69. * @var string
  70. */
  71. protected $pretensaoSalarial;
  72. /**
  73. * @ORM\ManyToMany(targetEntity="Conhecimento", inversedBy="candidatos")
  74. * @var Conhecimento[]
  75. */
  76. protected $conhecimentos;
  77. public function __constructor()
  78. {
  79. $this->conhecimentos = ArrayCollection();
  80. }
  81. /**
  82. * @param string $experiencia
  83. */
  84. public function setExperiencia($experiencia)
  85. {
  86. $this->experiencia = $experiencia;
  87. }
  88. /**
  89. * @return string
  90. */
  91. public function getExperiencia()
  92. {
  93. return $this->experiencia;
  94. }
  95. /**
  96. * @param int $id
  97. */
  98. public function setId($id)
  99. {
  100. $this->id = $id;
  101. }
  102. /**
  103. * @return int
  104. */
  105. public function getId()
  106. {
  107. return $this->id;
  108. }
  109. /**
  110. * @param string $nascimento
  111. */
  112. public function setNascimento(\DateTime $nascimento)
  113. {
  114. $this->nascimento = $nascimento;
  115. }
  116. /**
  117. * @return string
  118. */
  119. public function getNascimento()
  120. {
  121. return $this->nascimento;
  122. }
  123. /**
  124. * @param string $nome
  125. */
  126. public function setNome($nome)
  127. {
  128. $this->nome = $nome;
  129. }
  130. /**
  131. * @return string
  132. */
  133. public function getNome()
  134. {
  135. return $this->nome;
  136. }
  137. /**
  138. * @param string $ondeEstudou
  139. */
  140. public function setOndeEstudou($ondeEstudou)
  141. {
  142. $this->ondeEstudou = $ondeEstudou;
  143. }
  144. /**
  145. * @return string
  146. */
  147. public function getOndeEstudou()
  148. {
  149. return $this->ondeEstudou;
  150. }
  151. /**
  152. * @param string $ondeTrabalhou
  153. */
  154. public function setOndeTrabalhou($ondeTrabalhou)
  155. {
  156. $this->ondeTrabalhou = $ondeTrabalhou;
  157. }
  158. /**
  159. * @return string
  160. */
  161. public function getOndeTrabalhou()
  162. {
  163. return $this->ondeTrabalhou;
  164. }
  165. /**
  166. * @param string $pretensaoSalarial
  167. */
  168. public function setPretensaoSalarial($pretensaoSalarial)
  169. {
  170. $this->pretensaoSalarial = $pretensaoSalarial;
  171. }
  172. /**
  173. * @return string
  174. */
  175. public function getPretensaoSalarial()
  176. {
  177. return $this->pretensaoSalarial;
  178. }
  179. /**
  180. * @param string $vaga
  181. */
  182. public function setVaga(Vaga $vaga)
  183. {
  184. $this->vaga = $vaga;
  185. }
  186. /**
  187. * @return string
  188. */
  189. public function getVaga()
  190. {
  191. return $this->vaga;
  192. }
  193. public function toArray()
  194. {
  195. return get_object_vars($this);
  196. }
  197. /**
  198. * Set input filter
  199. *
  200. * @param InputFilterInterface $inputFilter
  201. * @return InputFilterAwareInterface
  202. */
  203. public function setInputFilter(InputFilterInterface $inputFilter)
  204. {
  205. throw new \Exception('Não implementado');
  206. }
  207. /**
  208. * Retrieve input filter
  209. *
  210. * @return InputFilterInterface
  211. */
  212. public function getInputFilter()
  213. {
  214. if (!$this->inputFilter) {
  215. $factory = new Factory();
  216. $inputFilter = new InputFilter();
  217. $inputFilter->add($factory->createInput(array(
  218. 'name' => 'nome',
  219. 'required' => true,
  220. 'validators' => array(
  221. array(
  222. 'name' => 'NotEmpty',
  223. 'options' => array(
  224. 'message' => 'É obrigatório informar seu nome'
  225. ),
  226. ),
  227. array(
  228. 'name' => 'Alpha',
  229. 'options' => array(
  230. 'message' => 'Só é permitido informar letras',
  231. 'allowWhiteSpace' => true
  232. )
  233. ),
  234. ),
  235. 'filters' => array(
  236. array('name' => 'StringTrim')
  237. )
  238. )));
  239. $inputFilter->add($factory->createInput(array(
  240. 'name' => 'nascimento',
  241. 'required' => true,
  242. 'filters' => array(
  243. array('name' => 'Zend\Filter\StringTrim'),
  244. ),
  245. 'validators' => array(
  246. array(
  247. 'name' => 'NotEmpty',
  248. 'options' => array(
  249. 'message' => 'É obrigatório informar seu nome'
  250. )
  251. ),
  252. array(
  253. 'name' => 'date',
  254. 'options' => array(
  255. 'message' => 'Você precisa informar uma data válida'
  256. )
  257. ),
  258. ),
  259. )));
  260. $inputFilter->add($factory->createInput(array(
  261. 'name' => 'ondeEstudou',
  262. 'required' => true,
  263. 'validators' => array(
  264. array(
  265. 'name' => 'NotEmpty',
  266. 'options' => array(
  267. 'message' => 'É obrigatório informar onde estudou'
  268. ),
  269. ),
  270. ),
  271. 'filters' => array(
  272. array('name' => 'StringTrim'),
  273. ),
  274. )));
  275. $inputFilter->add($factory->createInput(array(
  276. 'name' => 'ondeTrabalhou',
  277. 'required' => true,
  278. 'validators' => array(
  279. array(
  280. 'name' => 'NotEmpty',
  281. 'options' => array(
  282. 'message' => 'É obrigatório informar onde trabalhou'
  283. ),
  284. ),
  285. ),
  286. 'filters' => array(
  287. array('name' => 'StringTrim'),
  288. ),
  289. )));
  290. $inputFilter->add($factory->createInput(array(
  291. 'name' => 'experiencia',
  292. 'required' => true,
  293. 'validators' => array(
  294. array(
  295. 'name' => 'NotEmpty',
  296. 'options' => array(
  297. 'message' => 'É obrigatório informar seus conhecimentos'
  298. ),
  299. ),
  300. ),
  301. 'filters' => array(
  302. array('name' => 'StringTrim'),
  303. ),
  304. )));
  305. $inputFilter->add($factory->createInput(array(
  306. 'name' => 'pretensaoSalarial',
  307. 'required' => true,
  308. 'validators' => array(
  309. array(
  310. 'name' => 'NotEmpty',
  311. 'options' => array(
  312. 'message' => 'É obrigatório informar sua pretensão salarial'
  313. ),
  314. 'break_chain_on_failure' => true,
  315. ),
  316. array(
  317. 'name' => 'Float',
  318. 'options' => array(
  319. 'message' => 'Esse não é um valor numérico válido'
  320. )
  321. ),
  322. ),
  323. 'filters' => array(
  324. array(
  325. 'name' => 'PregReplace',
  326. 'options' => array(
  327. 'pattern' => '/\,/',
  328. 'replacement' => '.'
  329. )
  330. ),
  331. array('name' => 'StringTrim'),
  332. array('name' => 'Null')
  333. ),
  334. )));
  335. $vagasIds = array_map(function($entity){ return $entity->getId(); }, $this->getVagasMapper()->findAll());
  336. $inputFilter->add($factory->createInput(array(
  337. 'name' => 'vaga',
  338. 'required' => true,
  339. 'validators' => array(
  340. array(
  341. 'name' => 'NotEmpty',
  342. 'options' => array(
  343. 'message' => 'É obrigatório escolher uma vaga'
  344. ),
  345. 'break_chain_on_failure' => true,
  346. ),
  347. array(
  348. 'name' => 'InArray',
  349. 'options' => array(
  350. 'haystack' => $vagasIds,
  351. 'message' => 'Você precisa informar uma vaga existente'
  352. ),
  353. ),
  354. ),
  355. )));
  356. $this->inputFilter = $inputFilter;
  357. }
  358. return $this->inputFilter;
  359. }
  360. /**
  361. * @param VagaMapper $vagasMapper
  362. */
  363. public function setVagasMapper($vagasMapper)
  364. {
  365. $this->vagasMapper = $vagasMapper;
  366. }
  367. /**
  368. * @return VagaMapper
  369. */
  370. public function getVagasMapper()
  371. {
  372. return $this->vagasMapper;
  373. }
  374. }