Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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