You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.3KB

  1. <?php
  2. namespace Lc\ShopBundle\Services;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\ShopBundle\Context\PageInterface;
  5. class Utils
  6. {
  7. protected $em ;
  8. protected $unitsArray = [
  9. 'piece' => [
  10. 'unit' => 'piece',
  11. 'wording_unit' => 'la pièce',
  12. 'wording' => 'pièce(s)',
  13. 'wording_short' => 'p.',
  14. 'coefficient' => 1,
  15. 'ref' => 'piece'
  16. ],
  17. 'g' => [
  18. 'unit' => 'g',
  19. 'wording_unit' => 'le g',
  20. 'wording' => 'g',
  21. 'wording_short' => 'g',
  22. 'coefficient' => 1000,
  23. 'ref' => 'kg'
  24. ],
  25. 'kg' => [
  26. 'unit' => 'kg',
  27. 'wording_unit' => 'le kg',
  28. 'wording' => 'kg',
  29. 'wording_short' => 'kg',
  30. 'coefficient' => 1,
  31. 'ref' => 'kg'
  32. ],
  33. 'mL' => [
  34. 'unit' => 'mL',
  35. 'wording_unit' => 'le mL',
  36. 'wording' => 'mL',
  37. 'wording_short' => 'mL',
  38. 'coefficient' => 1000,
  39. 'ref' => 'L'
  40. ],
  41. 'cL' => [
  42. 'unit' => 'cL',
  43. 'wording_unit' => 'le cL',
  44. 'wording' => 'cL',
  45. 'wording_short' => 'cL',
  46. 'coefficient' => 100,
  47. 'ref' => 'L'
  48. ],
  49. 'L' => [
  50. 'unit' => 'L',
  51. 'wording_unit' => 'le litre',
  52. 'wording' => 'L',
  53. 'wording_short' => 'L',
  54. 'coefficient' => 1,
  55. 'ref' => 'L'
  56. ],
  57. ];
  58. public function __construct(EntityManagerInterface $em)
  59. {
  60. $this->em = $em ;
  61. }
  62. public static function getDayByNumber($number)
  63. {
  64. $daysArray = [
  65. 1 => 'Lundi',
  66. 2 => 'Mardi',
  67. 3 => 'Mercredi',
  68. 4 => 'Jeudi',
  69. 5 => 'Vendredi',
  70. 6 => 'Samedi',
  71. 7 => 'Dimanche'
  72. ] ;
  73. if(isset($daysArray[$number])) {
  74. return $daysArray[$number] ;
  75. }
  76. return '' ;
  77. }
  78. public function getUnitsListFormatedForType() {
  79. foreach ($this->unitsArray as $unit=>$unitInfo){
  80. $choices[$unitInfo['wording_unit']] = $unit;
  81. };
  82. return $choices;
  83. }
  84. public function getUnitsList() {
  85. return $this->unitsArray;
  86. }
  87. public function getElementByDevAlias($devAlias, $class = PageInterface::class)
  88. {
  89. $class = $this->em->getClassMetadata($class)->getName();
  90. return $this->em->getRepository($class)->findOneByDevAlias($devAlias) ;
  91. }
  92. }