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.

146 lines
4.6KB

  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, $lang = 'fr')
  63. {
  64. if($lang == 'fr') {
  65. $daysArray = [
  66. 1 => 'Lundi',
  67. 2 => 'Mardi',
  68. 3 => 'Mercredi',
  69. 4 => 'Jeudi',
  70. 5 => 'Vendredi',
  71. 6 => 'Samedi',
  72. 7 => 'Dimanche'
  73. ] ;
  74. }
  75. else {
  76. $daysArray = [
  77. 1 => 'Monday',
  78. 2 => 'Tuesday',
  79. 3 => 'Wednesday',
  80. 4 => 'Thursday',
  81. 5 => 'Friday',
  82. 6 => 'Saturday',
  83. 7 => 'Sunday',
  84. ] ;
  85. }
  86. if(isset($daysArray[$number])) {
  87. return $daysArray[$number] ;
  88. }
  89. return '' ;
  90. }
  91. public function getUnitsListFormatedForType()
  92. {
  93. $choices = [] ;
  94. foreach ($this->unitsArray as $unit=>$unitInfo){
  95. $choices[$unitInfo['wording_unit']] = $unit;
  96. };
  97. return $choices;
  98. }
  99. public function getUnitsList()
  100. {
  101. return $this->unitsArray;
  102. }
  103. public function getUnitProperty($unit, $property)
  104. {
  105. $unitsArray = $this->getUnitsList() ;
  106. if(isset($unitsArray[$unit][$property])) {
  107. return $unitsArray[$unit][$property] ;
  108. }
  109. return false ;
  110. }
  111. public function getUnitWording($unit, $type = 'wording_short')
  112. {
  113. return $this->getUnitProperty($unit, $type) ;
  114. }
  115. public function getUnitRef($unit)
  116. {
  117. return $this->getUnitProperty($unit, 'ref') ;
  118. }
  119. public function getUnitCoefficient($unit)
  120. {
  121. return $this->getUnitProperty($unit, 'coefficient') ;
  122. }
  123. public function getElementByDevAlias($devAlias, $class = PageInterface::class)
  124. {
  125. $class = $this->em->getClassMetadata($class)->getName();
  126. return $this->em->getRepository($class)->findOneByDevAlias($devAlias) ;
  127. }
  128. }