Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

149 Zeilen
4.9KB

  1. <?php
  2. namespace Lc\ShopBundle\Services;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\ShopBundle\Context\PageInterface;
  5. use Lc\ShopBundle\Context\TaxRateInterface;
  6. use Lc\ShopBundle\Context\UnitInterface;
  7. class Utils
  8. {
  9. protected $em ;
  10. protected $globalParam ;
  11. /*public function getUnitsListFormatedForType()
  12. {
  13. $choices = [] ;
  14. foreach ($this->unitsArray as $unit=>$unitInfo){
  15. $choices[$unitInfo['wording_unit']] = $unit;
  16. };
  17. return $choices;
  18. }
  19. public function getUnitsList()
  20. {
  21. return $this->unitsArray;
  22. }
  23. public function getUnitProperty($unit, $property)
  24. {
  25. $unitsArray = $this->getUnitsList() ;
  26. if(isset($unitsArray[$unit][$property])) {
  27. return $unitsArray[$unit][$property] ;
  28. }
  29. return false ;
  30. }
  31. public function getUnitWording($unit, $type = 'wording_short')
  32. {
  33. return $this->getUnitProperty($unit, $type) ;
  34. }
  35. public function getUnitRef($unit)
  36. {
  37. return $this->getUnitProperty($unit, 'ref') ;
  38. }
  39. public function getUnitCoefficient($unit)
  40. {
  41. return $this->getUnitProperty($unit, 'coefficient') ;
  42. }*/
  43. public function __construct(EntityManagerInterface $em, GlobalParam $globalParam)
  44. {
  45. $this->em = $em ;
  46. $this->globalParam = $globalParam;
  47. }
  48. public function getUnitsList()
  49. {
  50. $unitsList =array();
  51. $units = $this->em->getRepository(UnitInterface::class)->findAll();
  52. foreach ($units as $unit){
  53. $unitsList[$unit->getId()]['unit'] = $unit->getUnit();
  54. $unitsList[$unit->getId()]['wordingUnit'] = $unit->getWordingUnit();
  55. $unitsList[$unit->getId()]['wording'] = $unit->getWording();
  56. $unitsList[$unit->getId()]['wordingShort'] = $unit->getWordingShort();
  57. $unitsList[$unit->getId()]['coefficient'] = $unit->getCoefficient();
  58. $unitsList[$unit->getId()]['unitReference'] = $unit->getUnitReference()->getId();
  59. }
  60. return $unitsList;
  61. }
  62. public function getTaxRatesList()
  63. {
  64. $taxRatesList =array();
  65. $taxRates = $this->em->getRepository(TaxRateInterface::class)->findAll();
  66. foreach ($taxRates as $taxRate){
  67. $taxRatesList[$taxRate->getId()]['title'] = $taxRate->getTitle();
  68. $taxRatesList[$taxRate->getId()]['value'] = $taxRate->getValue();
  69. }
  70. $taxRatesList['default']['title'] = $this->globalParam->getCurrentMerchantTaxRate()->getTitle();
  71. $taxRatesList['default']['value'] = $this->globalParam->getCurrentMerchantTaxRate()->getValue();
  72. return $taxRatesList;
  73. }
  74. public static function getDayByNumber($number, $lang = 'fr')
  75. {
  76. if($lang == 'fr') {
  77. $daysArray = [
  78. 1 => 'Lundi',
  79. 2 => 'Mardi',
  80. 3 => 'Mercredi',
  81. 4 => 'Jeudi',
  82. 5 => 'Vendredi',
  83. 6 => 'Samedi',
  84. 7 => 'Dimanche'
  85. ] ;
  86. }
  87. else {
  88. $daysArray = [
  89. 1 => 'Monday',
  90. 2 => 'Tuesday',
  91. 3 => 'Wednesday',
  92. 4 => 'Thursday',
  93. 5 => 'Friday',
  94. 6 => 'Saturday',
  95. 7 => 'Sunday',
  96. ] ;
  97. }
  98. if(isset($daysArray[$number])) {
  99. return $daysArray[$number] ;
  100. }
  101. return '' ;
  102. }
  103. public function getElementByDevAlias($devAlias, $class = PageInterface::class)
  104. {
  105. $class = $this->em->getClassMetadata($class)->getName();
  106. return $this->em->getRepository($class)->findOneByDevAlias($devAlias) ;
  107. }
  108. public function isServerLocalhost()
  109. {
  110. return in_array($_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1']) ;
  111. }
  112. function limitText($text, $limit) {
  113. if (str_word_count($text, 0) > $limit) {
  114. $words = str_word_count($text, 2);
  115. $pos = array_keys($words);
  116. $text = substr($text, 0, $pos[$limit]) . '...';
  117. }
  118. return $text;
  119. }
  120. }