/fsn-site-central/application/Form/Elementrecueilli.php

https://gitlab.com/team_fsn/fsn-php · PHP · 382 lines · 323 code · 51 blank · 8 comment · 19 complexity · 5a01d8d085302defd0134c97c8712682 MD5 · raw file

  1. <?php
  2. class Form_Elementrecueilli extends Yab_Form {
  3. public function __construct(Model_Elementrecueilli $elementrecueilli, Model_Us $us, $mode='add') {
  4. $loader = Yab_Loader::getInstance();
  5. $this->set('method', 'post')->set('name', 'form_elementrecueilli')->set('action', '')->set('role', 'form');
  6. $registry = $loader->getRegistry();
  7. $i18n = $registry->get('i18n');
  8. //recupération de l'emplacement choisi
  9. $emplacement_choisi='';
  10. if ($elementrecueilli->has('emplacement_id')) {
  11. if ($elementrecueilli->get('emplacement_id') != null) {
  12. $emplacement = new Model_Emplacement($elementrecueilli->get('emplacement_id'));
  13. $emplacement_choisi = !$emplacement->has('nom') ? '' : $emplacement->get('nom');
  14. } else if ($elementrecueilli->get('conteneur_id') != null ) {
  15. $conteneur = new Model_Conteneur($elementrecueilli->get('conteneur_id'));
  16. $emplacement_choisi = !$conteneur->has('nom') ? '' : $conteneur->get('nom');
  17. }
  18. }
  19. $this->setElement('us_id', array(
  20. 'type' => 'hidden',
  21. 'id' => 'us_id',
  22. 'label' => $i18n->say('us_id'),
  23. 'value' => $us->get('id'),
  24. 'errors' => array(),
  25. 'readonly' => true,
  26. ));
  27. $this->setElement('us_identification', array(
  28. 'type' => 'text',
  29. 'id' => 'us_identification',
  30. 'label' => $i18n->say('elementrecueilli_us_id'),
  31. 'value' => $us->get('identification'),
  32. 'validators' => array(),
  33. 'errors' => array(),
  34. 'readonly' => true,
  35. 'needed' => true,
  36. ));
  37. $this->setElement('intervenant_id', array(
  38. 'type' => 'select',
  39. 'id' => 'intervenant_id',
  40. 'label' => $i18n->say('intervenant_id'),
  41. 'value' => $elementrecueilli->has('intervenant_id') ? $elementrecueilli->get('intervenant_id') : null,
  42. 'fake_options' => array(null => 'Non déterminé'),
  43. 'options' => $elementrecueilli->getTable('Model_Intervenant')->getAllNoms()->setKey('id')->setValue('nom_complet'),
  44. 'errors' => array(),
  45. 'needed' => false,
  46. ));
  47. $this->setElement('elementisole', array(
  48. 'type' => 'checkbox',
  49. 'id' => 'elementisole',
  50. 'label' => $i18n->say('elementisole'),
  51. 'value' => $elementrecueilli->has('elementisole') ? $elementrecueilli->get('elementisole') : 1,
  52. 'validators' => array('Int', 'NotEmpty'),
  53. 'errors' => array(),
  54. 'needed' => true,
  55. ));
  56. //traitement des différents numéros
  57. $isole=$elementrecueilli->has('elementisole') ? $elementrecueilli->get('elementisole') : 1;
  58. if ($isole==1) {
  59. $other_isole=0;
  60. $sufixe='.';
  61. $other_sufixe='.lot.';
  62. } else {
  63. $other_isole=1;
  64. $sufixe='.lot.';
  65. $other_sufixe='.';
  66. }
  67. $value_identifiant = $elementrecueilli->has('numero') ? $elementrecueilli->get('numero') : $us->get('identification') . $sufixe . $elementrecueilli->getNextSequenceErId($us->get('id'), $isole);
  68. $other_identifiant = $us->get('identification') . $other_sufixe . $elementrecueilli->getNextSequenceErId($us->get('id'), $other_isole);
  69. $this->setElement('numero_isole', array(
  70. 'type' => 'hidden',
  71. 'id' => 'numero_isole',
  72. 'label' => 'Numéo',
  73. 'value' => $isole == 1 ? $value_identifiant : $other_identifiant,
  74. 'validators' => array(),
  75. 'errors' => array(),
  76. 'needed' => true,
  77. 'readonly' => true,
  78. ));
  79. $this->setElement('numero_non_isole', array(
  80. 'type' => 'hidden',
  81. 'id' => 'numero_non_isole',
  82. 'label' => 'Numéo',
  83. 'value' => $isole == 0 ? $value_identifiant : $other_identifiant,
  84. 'validators' => array(),
  85. 'errors' => array(),
  86. 'needed' => true,
  87. 'readonly' => true,
  88. ));
  89. $this->setElement('numero', array(
  90. 'type' => 'text',
  91. 'id' => 'numero',
  92. 'label' => $i18n->say('numero'),
  93. //'value' => $elementrecueilli->has('numero') ? $elementrecueilli->get('numero') : null,
  94. 'value' => $value_identifiant,
  95. 'validators' => array(),
  96. 'errors' => array(),
  97. 'needed' => true,
  98. 'readonly' => true,
  99. ));
  100. $this->setElement('description', array(
  101. 'type' => 'textarea',
  102. 'rows' => '3',
  103. 'id' => 'description',
  104. 'label' => $i18n->say('description'),
  105. 'value' => $elementrecueilli->has('description') ? $elementrecueilli->get('description') : null,
  106. 'validators' => array(),
  107. 'errors' => array(),
  108. 'needed' => false,
  109. ));
  110. $this->setElement('intact', array(
  111. 'type' => 'checkbox',
  112. 'id' => 'intact',
  113. 'class' => 'tribox form-control',
  114. 'label' => $i18n->say('intact'),
  115. 'value' => $elementrecueilli->has('intact') ? $elementrecueilli->get('intact') : 'null',
  116. 'validators' => array(),
  117. 'errors' => array(),
  118. 'needed' => false,
  119. ));
  120. //date_default_timezone_set('UTC'); -- jfb 2016-04-21 correctif fiche mantis 229
  121. $this->setElement('datedecouverte', array(
  122. 'type' => 'text',
  123. 'id' => 'datedecouverte',
  124. 'label' => $i18n->say('datedecouverte'),
  125. 'class' => 'datepicker',
  126. 'value' => $elementrecueilli->has('datedecouverte') ? date('d/m/Y', strtotime($elementrecueilli->get('datedecouverte'))) : date('d/m/Y'),
  127. 'validators' => array(),
  128. 'errors' => array(),
  129. 'needed' => true,
  130. 'readonly' => true,
  131. ));
  132. $this->setElement('elementpoterie_id', array(
  133. 'type' => 'hidden',
  134. 'id' => 'elementpoterie_id',
  135. 'label' => 'elementpoterie_id',
  136. 'value' => $elementrecueilli->has('elementpoterie_id') ? $elementrecueilli->get('elementpoterie_id') : null,
  137. 'errors' => array(),
  138. 'needed' => false,
  139. ));
  140. $this->setElement('precisionfonction', array(
  141. 'type' => 'text',
  142. 'rows' => '3',
  143. 'id' => 'precisionfonction',
  144. 'label' => $i18n->say('precisionfonction'),
  145. 'value' => $elementrecueilli->has('precisionfonction') ? $elementrecueilli->get('precisionfonction') : null,
  146. 'validators' => array(),
  147. 'errors' => array(),
  148. 'needed' => false,
  149. ));
  150. $this->setElement('statut_id', array(
  151. 'type' => 'select',
  152. 'id' => 'statut_id',
  153. 'label' => $i18n->say('statut_id'),
  154. 'value' => $elementrecueilli->has('statut_id') ? $elementrecueilli->get('statut_id') : null,
  155. 'fake_options' => array(null => 'Non déterminé'),
  156. 'options' => $elementrecueilli->getTable('Model_Statut')->fetchAll()->setKey('id')->setValue('statut'),
  157. 'errors' => array(),
  158. 'needed' => false,
  159. ));
  160. $this->setElement('quantite', array(
  161. 'type' => 'text',
  162. 'id' => 'quantite',
  163. 'label' => $i18n->say('quantite'),
  164. 'value' => $elementrecueilli->has('quantite') ? $elementrecueilli->get('quantite') : null,
  165. 'validators' => array('Int'),
  166. 'errors' => array(),
  167. 'needed' => false,
  168. ));
  169. $this->setElement('poids', array(
  170. 'type' => 'text',
  171. 'id' => 'poids',
  172. 'label' => $i18n->say('poids'),
  173. 'value' => $elementrecueilli->has('poids') ? $elementrecueilli->get('poids') : null,
  174. 'validators' => array('Float'),
  175. 'errors' => array(),
  176. 'needed' => false,
  177. ));
  178. $this->setElement('longueur', array(
  179. 'type' => 'text',
  180. 'id' => 'longueur',
  181. 'label' => $i18n->say('longueur'),
  182. 'value' => $elementrecueilli->has('longueur') ? $elementrecueilli->get('longueur') : null,
  183. 'validators' => array('Float'),
  184. 'errors' => array(),
  185. 'needed' => false,
  186. ));
  187. $this->setElement('largeur', array(
  188. 'type' => 'text',
  189. 'id' => 'largeur',
  190. 'label' => $i18n->say('largeur'),
  191. 'value' => $elementrecueilli->has('largeur') ? $elementrecueilli->get('largeur') : null,
  192. 'validators' => array('Float'),
  193. 'errors' => array(),
  194. 'needed' => false,
  195. ));
  196. $this->setElement('hauteur', array(
  197. 'type' => 'text',
  198. 'id' => 'hauteur',
  199. 'label' => $i18n->say('hauteur'),
  200. 'value' => $elementrecueilli->has('hauteur') ? $elementrecueilli->get('hauteur') : null,
  201. 'validators' => array('Float'),
  202. 'errors' => array(),
  203. 'needed' => false,
  204. ));
  205. $this->setElement('diametre', array(
  206. 'type' => 'text',
  207. 'id' => 'diametre',
  208. 'label' => $i18n->say('diametre'),
  209. 'value' => $elementrecueilli->has('diametre') ? $elementrecueilli->get('diametre') : null,
  210. 'validators' => array('Float'),
  211. 'errors' => array(),
  212. 'needed' => false,
  213. ));
  214. $this->setElement('incertitude', array(
  215. 'type' => 'text',
  216. 'id' => 'incertitude',
  217. 'label' => $i18n->say('incertitude'),
  218. 'value' => $elementrecueilli->has('incertitude') ? $elementrecueilli->get('incertitude') : null,
  219. 'validators' => array('Float'),
  220. 'errors' => array(),
  221. 'needed' => false,
  222. ));
  223. $this->setElement('emplacement_id', array(
  224. 'type' => 'hidden',
  225. 'id' => 'emplacement_id',
  226. 'label' => 'Emplacement',
  227. 'value' => $elementrecueilli->has('emplacement_id') ? $elementrecueilli->get('emplacement_id') : null,
  228. 'errors' => array(),
  229. 'needed' => false,
  230. ));
  231. $this->setElement('conteneur_id', array(
  232. 'type' => 'hidden',
  233. 'id' => 'conteneur_id',
  234. 'label' => 'Conteneur',
  235. 'value' => $elementrecueilli->has('conteneur_id') ? $elementrecueilli->get('conteneur_id') : null,
  236. 'errors' => array(),
  237. 'needed' => false,
  238. ));
  239. $this->setElement('emplacement_choisi', array(
  240. 'type' => 'text',
  241. 'id' => 'emplacement_choisi',
  242. 'label' => 'Emplacement choisi',
  243. 'value' => $emplacement_choisi,
  244. 'validators' => array(),
  245. 'errors' => array(),
  246. 'needed' => false,
  247. ));
  248. $this->setElement('fonction_id', array(
  249. 'type' => 'select',
  250. 'id' => 'fonction_id',
  251. 'label' => $i18n->say('fonction_id'),
  252. 'value' => $elementrecueilli->has('fonction_id') ? $elementrecueilli->get('fonction_id') : null,
  253. 'fake_options' => array(null => 'Non déterminé'),
  254. 'options' => $elementrecueilli->getTable('Model_Fonction')->fetchAll()->setKey('id')->setValue('fonction'),
  255. 'errors' => array(),
  256. 'needed' => false,
  257. ));
  258. $this->setElement('classe_id', array(
  259. 'type' => 'select',
  260. 'id' => 'classe_id',
  261. 'label' => $i18n->say('classe_id'),
  262. 'value' => $elementrecueilli->has('classe_id') ? $elementrecueilli->get('classe_id') : null,
  263. 'fake_options' => array(null => 'Non déterminé'),
  264. 'options' => $elementrecueilli->getTable('Model_Classe')->fetchAll()->setKey('id')->setValue('classe'),
  265. 'errors' => array(),
  266. 'needed' => false,
  267. ));
  268. $this->setElement('etat_id', array(
  269. 'type' => 'select',
  270. 'id' => 'etat_id',
  271. 'label' => $i18n->say('etat'),
  272. 'value' => $elementrecueilli->has('etat_id') ? $elementrecueilli->get('etat_id') : null,
  273. 'fake_options' => array(null => 'Non déterminé'),
  274. 'options' => $elementrecueilli->getTable('Model_Etat')->fetchAll()->setKey('id')->setValue('etat'),
  275. 'errors' => array(),
  276. 'needed' => false,
  277. ));
  278. $this->setElement('datationdebreal_certain', array(
  279. 'type' => 'text',
  280. 'id' => 'datationdebreal_certain',
  281. 'label' => $i18n->say('datationdebreal_certain'),
  282. 'value' => $elementrecueilli->has('datationdebreal_certain') ? $elementrecueilli->get('datationdebreal_certain') : null,
  283. 'validators' => array('Int'),
  284. 'errors' => array(),
  285. //'errors' => array('Int', array('Le champ doit correspondre � une ann�e.')),
  286. 'needed' => false,
  287. ));
  288. $this->setElement('datationfinutil_certain', array(
  289. 'type' => 'text',
  290. 'id' => 'datationfinreal_certain',
  291. 'label' => $i18n->say('datationfinutil_certain'),
  292. 'value' => $elementrecueilli->has('datationfinutil_certain') ? $elementrecueilli->get('datationfinutil_certain') : null,
  293. //'validators' => array('Int,GreaterThan(datationdebreal_certain)'),
  294. 'validators' => array('Int', 'GreaterThan' => array('than'=> $this->getElement('datationdebreal_certain')->get('value'))),
  295. //'errors' => array('Int' => 'Le champ doit correspondre � une ann�e.'),
  296. 'needed' => false,
  297. ));
  298. $this->setElement('datationdebreal_estim', array(
  299. 'type' => 'text',
  300. 'id' => 'datationdebreal_estim',
  301. 'label' => $i18n->say('datationdebreal_estim'),
  302. 'value' => $elementrecueilli->has('datationdebreal_estim') ? $elementrecueilli->get('datationdebreal_estim') : null,
  303. 'validators' => array('Int'),
  304. 'errors' => array(),
  305. 'needed' => false,
  306. ));
  307. $this->setElement('datationfinutil_estim', array(
  308. 'type' => 'text',
  309. 'id' => 'datationfinreal_estim',
  310. 'label' => $i18n->say('datationfinutil_estim'),
  311. 'value' => $elementrecueilli->has('datationfinutil_estim') ? $elementrecueilli->get('datationfinutil_estim') : null,
  312. 'validators' => array('Int', 'GreaterThan' => array('than'=> $this->getElement('datationdebreal_estim')->get('value'))),
  313. 'errors' => array(),
  314. 'needed' => false,
  315. ));
  316. //traitements relatifs à la page de visualisation
  317. if($mode == 'show'){
  318. foreach($this->getElements() as $element) {
  319. if ($element->get('type') == 'select' or $element->get('type') == 'checkbox')
  320. $element->set('disabled',true);
  321. else if ($element->get('id') == 'datedecouverte')
  322. $element->set('class', null);
  323. else
  324. $element->set('readonly','readonly');
  325. }
  326. }
  327. }
  328. public function getRessourceType(){
  329. return "ER";
  330. }
  331. }