Sections.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\Core\UI\Traits;
  3. use ThurData\Servers\KerioEmail\Core\UI\Helpers\ContainerElementsConstants;
  4. /**
  5. * Form Sections Elements related functions
  6. *
  7. * @autor ThurData <info@thurdata.ch>
  8. */
  9. trait Sections
  10. {
  11. protected $sections = [];
  12. public function addSection($section)
  13. {
  14. $this->initSectionsContainer();
  15. $this->addElement($section, ContainerElementsConstants::SECTIONS);
  16. return $this;
  17. }
  18. public function getSection($id)
  19. {
  20. return $this->sections[$id];
  21. }
  22. public function getSections()
  23. {
  24. return $this->sections;
  25. }
  26. protected function initSectionsContainer()
  27. {
  28. if(!$this->elementContainerExists(ContainerElementsConstants::SECTIONS))
  29. {
  30. $this->addNewElementsContainer(ContainerElementsConstants::SECTIONS);
  31. }
  32. }
  33. public function validateSections($request)
  34. {
  35. foreach ($this->sections as $section)
  36. {
  37. $section->validateFields($request);
  38. $section->validateSections($request);
  39. if ($section->getValidationErrors())
  40. {
  41. $this->validationErrors = array_merge($this->validationErrors, $section->getValidationErrors());
  42. }
  43. }
  44. return $this;
  45. }
  46. }