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.

690 lines
29KB

  1. <?php
  2. namespace Lc\ShopBundle\Services;
  3. use Cocur\Slugify\Slugify;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use EasyCorp\Bundle\EasyAdminBundle\Configuration\ConfigManager;
  6. use Geocoder\Model\Coordinates;
  7. use Geocoder\Provider\Addok\Addok;
  8. use Geocoder\Provider\GoogleMaps\GoogleMaps;
  9. use Geocoder\Provider\Nominatim\Nominatim;
  10. use Geocoder\Query\GeocodeQuery;
  11. use Geocoder\Query\ReverseQuery;
  12. use Lc\ShopBundle\Context\ImageInterface;
  13. use Lc\ShopBundle\Context\MerchantUtilsInterface;
  14. use Lc\ShopBundle\Context\PageInterface;
  15. use Lc\ShopBundle\Context\PointSaleInterface;
  16. use Lc\ShopBundle\Context\ProductFamilyInterface;
  17. use Lc\ShopBundle\Context\ProductFamilyUtilsInterface;
  18. use Lc\ShopBundle\Context\ReminderInterface;
  19. use Lc\ShopBundle\Context\TaxRateInterface;
  20. use Lc\ShopBundle\Context\UnitInterface;
  21. use Lc\ShopBundle\Context\UserInterface;
  22. use Lc\ShopBundle\Context\UserPointSaleInterface;
  23. use Liip\ImagineBundle\Imagine\Cache\CacheManager;
  24. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  25. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  26. use Symfony\Component\Form\FormBuilderInterface;
  27. use Symfony\Component\HttpClient\HttplugClient;
  28. use Symfony\Component\HttpFoundation\ParameterBag;
  29. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  30. use Symfony\Component\Validator\Constraints\EqualTo;
  31. use Symfony\Component\Validator\Constraints\NotNull;
  32. use Symfony\Contracts\Translation\TranslatorInterface;
  33. class Utils
  34. {
  35. protected $em;
  36. protected $parameterBag;
  37. protected $merchantUtils;
  38. protected $session;
  39. protected $translator;
  40. protected $configManager;
  41. const MEAN_PAYMENT_CREDIT_CARD = 'cb';
  42. const MEAN_PAYMENT_CHEQUE = 'cheque';
  43. const MEAN_PAYMENT_CREDIT = 'credit';
  44. const MEAN_PAYMENT_TRANSFER = 'transfer';
  45. const MEAN_PAYMENT_CASH = 'cash';
  46. const MEAN_PAYMENT_GIFT = 'transfer-gift';
  47. public function __construct(EntityManagerInterface $em, ParameterBagInterface $parameterBag, SessionInterface $session, TranslatorInterface $translator, ConfigManager $configManager, CacheManager $liipCacheHelper)
  48. {
  49. $this->em = $em;
  50. $this->parameterBag = $parameterBag;
  51. $this->session = $session;
  52. $this->translator = $translator;
  53. $this->configManager = $configManager;
  54. $this->liipCacheHelper = $liipCacheHelper;
  55. }
  56. public function getElementByDevAlias($devAlias, $class = PageInterface::class)
  57. {
  58. $class = $this->em->getClassMetadata($class)->getName();
  59. return $this->em->getRepository($class)->findOneByDevAlias($devAlias);
  60. }
  61. public function isServerLocalhost()
  62. {
  63. return in_array($_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1']);
  64. }
  65. public function getCookieDomain()
  66. {
  67. return ($this->isServerLocalhost()) ? null : $this->parameterBag->get('app.cookie_domain_distant');
  68. }
  69. public function limitText($text, $limit)
  70. {
  71. $text = strip_tags($text);
  72. if (str_word_count($text, 0) > $limit) {
  73. $words = str_word_count($text, 2);
  74. $pos = array_keys($words);
  75. $text = substr($text, 0, $pos[$limit]) . '...';
  76. }
  77. return $text;
  78. }
  79. public function limitTextByLength($text, $length, $append = '...')
  80. {
  81. if(strlen($text) > $length) {
  82. $text = substr($text, 0, $length) . $append ;
  83. }
  84. return $text ;
  85. }
  86. function truncateHtml($text, $length = 100, $ending = '...', $exact = false, $considerHtml = true)
  87. {
  88. if ($considerHtml) {
  89. // if the plain text is shorter than the maximum length, return the whole text
  90. if (strlen(preg_replace('/<.*?>/', '', $text)) <= $length) {
  91. return $text;
  92. }
  93. // splits all html-tags to scanable lines
  94. preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER);
  95. $total_length = strlen($ending);
  96. $open_tags = array();
  97. $truncate = '';
  98. foreach ($lines as $line_matchings) {
  99. // if there is any html-tag in this line, handle it and add it (uncounted) to the output
  100. if (!empty($line_matchings[1])) {
  101. // if it's an "empty element" with or without xhtml-conform closing slash
  102. if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $line_matchings[1])) {
  103. // do nothing
  104. // if tag is a closing tag
  105. } else if (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $line_matchings[1], $tag_matchings)) {
  106. // delete tag from $open_tags list
  107. $pos = array_search($tag_matchings[1], $open_tags);
  108. if ($pos !== false) {
  109. unset($open_tags[$pos]);
  110. }
  111. // if tag is an opening tag
  112. } else if (preg_match('/^<\s*([^\s>!]+).*?>$/s', $line_matchings[1], $tag_matchings)) {
  113. // add tag to the beginning of $open_tags list
  114. array_unshift($open_tags, strtolower($tag_matchings[1]));
  115. }
  116. // add html-tag to $truncate'd text
  117. $truncate .= $line_matchings[1];
  118. }
  119. // calculate the length of the plain text part of the line; handle entities as one character
  120. $content_length = strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', $line_matchings[2]));
  121. if ($total_length + $content_length > $length) {
  122. // the number of characters which are left
  123. $left = $length - $total_length;
  124. $entities_length = 0;
  125. // search for html entities
  126. if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', $line_matchings[2], $entities, PREG_OFFSET_CAPTURE)) {
  127. // calculate the real length of all entities in the legal range
  128. foreach ($entities[0] as $entity) {
  129. if ($entity[1] + 1 - $entities_length <= $left) {
  130. $left--;
  131. $entities_length += strlen($entity[0]);
  132. } else {
  133. // no more characters left
  134. break;
  135. }
  136. }
  137. }
  138. $truncate .= substr($line_matchings[2], 0, $left + $entities_length);
  139. // maximum lenght is reached, so get off the loop
  140. break;
  141. } else {
  142. $truncate .= $line_matchings[2];
  143. $total_length += $content_length;
  144. }
  145. // if the maximum length is reached, get off the loop
  146. if ($total_length >= $length) {
  147. break;
  148. }
  149. }
  150. } else {
  151. if (strlen($text) <= $length) {
  152. return $text;
  153. } else {
  154. $truncate = substr($text, 0, $length - strlen($ending));
  155. }
  156. }
  157. // if the words shouldn't be cut in the middle...
  158. if (!$exact) {
  159. // ...search the last occurance of a space...
  160. $spacepos = strrpos($truncate, ' ');
  161. if (isset($spacepos)) {
  162. // ...and cut the text in this position
  163. $truncate = substr($truncate, 0, $spacepos);
  164. }
  165. }
  166. // add the defined ending to the text
  167. $truncate .= $ending;
  168. if ($considerHtml) {
  169. // close all unclosed html-tags
  170. foreach ($open_tags as $tag) {
  171. $truncate .= '</' . $tag . '>';
  172. }
  173. }
  174. return $truncate;
  175. }
  176. function stripAccents($stripAccents)
  177. {
  178. return strtr($stripAccents,'àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ','aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
  179. }
  180. function cleanStringToCompare($string)
  181. {
  182. return $this->stripAccents(trim(strtolower($string))) ;
  183. }
  184. public function isBot()
  185. {
  186. if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT'])) {
  187. return TRUE;
  188. } else {
  189. return FALSE;
  190. }
  191. }
  192. public function slugify($string)
  193. {
  194. $slugify = new Slugify();
  195. return $slugify->slugify($string);
  196. }
  197. public function getUnitsList()
  198. {
  199. $unitsList = array();
  200. $units = $this->em->getRepository(UnitInterface::class)->findAll();
  201. foreach ($units as $unit) {
  202. $unitsList[$unit->getId()]['unit'] = $unit->getUnit();
  203. $unitsList[$unit->getId()]['wordingUnit'] = $unit->getWordingUnit();
  204. $unitsList[$unit->getId()]['wording'] = $unit->getWording();
  205. $unitsList[$unit->getId()]['wordingShort'] = $unit->getWordingShort();
  206. $unitsList[$unit->getId()]['coefficient'] = $unit->getCoefficient();
  207. $unitsList[$unit->getId()]['unitReference'] = $unit->getUnitReference()->getId();
  208. }
  209. return $unitsList;
  210. }
  211. public function isUserLinkedToPointSale(UserInterface $user, PointSaleInterface $pointSale)
  212. {
  213. foreach ($user->getUserPointSales() as $userPointSale) {
  214. if ($userPointSale->getPointSale()->getId() == $pointSale->getId()) {
  215. return true;
  216. }
  217. }
  218. return false;
  219. }
  220. public function linkUserToPointSale(UserInterface $user, PointSaleInterface $pointSale)
  221. {
  222. if (!$this->isUserLinkedToPointSale($user, $pointSale)) {
  223. $userPointSaleClass = $this->em->getClassMetadata(UserPointSaleInterface::class)->getName();
  224. $userPointSale = new $userPointSaleClass;
  225. $userPointSale->setUser($user);
  226. $userPointSale->setPointSale($pointSale);
  227. $this->em->persist($userPointSale);
  228. $this->em->flush();
  229. }
  230. }
  231. function callCitiesApi($method, $url, $data = false)
  232. {
  233. $url = 'https://geo.api.gouv.fr/' . $url;
  234. $curl = curl_init();
  235. switch ($method) {
  236. case "POST":
  237. curl_setopt($curl, CURLOPT_POST, 1);
  238. if ($data)
  239. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  240. break;
  241. case "PUT":
  242. curl_setopt($curl, CURLOPT_PUT, 1);
  243. break;
  244. default:
  245. if ($data)
  246. $url = sprintf("%s?%s", $url, http_build_query($data));
  247. }
  248. // Optional Authentication:
  249. curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  250. curl_setopt($curl, CURLOPT_USERPWD, "username:password");
  251. curl_setopt($curl, CURLOPT_URL, $url);
  252. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  253. $result = curl_exec($curl);
  254. curl_close($curl);
  255. return $result;
  256. }
  257. public function getGeocoderProvider()
  258. {
  259. $provider = false ;
  260. $symfonyClient = new HttplugClient();
  261. $configGeocoderProvider = $this->parameterBag->get('geocoder.provider') ;
  262. /* API du gouvernement */
  263. if($configGeocoderProvider == 'addok') {
  264. $provider = new Addok($symfonyClient, 'https://api-adresse.data.gouv.fr') ;
  265. }
  266. /* Google Maps */
  267. elseif($configGeocoderProvider == 'googlemaps') {
  268. $provider = new GoogleMaps($symfonyClient, null, $this->parameterBag->get('geocoder.api_key')) ;
  269. }
  270. /* Nominatim : OpenStreetMap */
  271. elseif($configGeocoderProvider == 'nominatim') {
  272. $provider = Nominatim::withOpenStreetMapServer($symfonyClient, 'Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion');
  273. }
  274. if(!$provider) {
  275. throw new \ErrorException('Aucun provider (geocoding) défini') ;
  276. }
  277. return $provider ;
  278. }
  279. public function callAddressApi($query)
  280. {
  281. $provider = $this->getGeocoderProvider() ;;
  282. $query = GeocodeQuery::create($query)->withData('type', 'housenumber');
  283. $results = $provider->geocodeQuery($query);
  284. $resultsToReturn = array();
  285. foreach($results as $result) {
  286. if ($result->getStreetNumber() && strlen($result->getStreetNumber()) > 0) {
  287. $resultsToReturn[] = $result;
  288. }
  289. }
  290. return $resultsToReturn;
  291. }
  292. public function callReverseAddressApi($latitude, $longitude)
  293. {
  294. $provider = $this->getGeocoderProvider() ;;
  295. $query = ReverseQuery::create(new Coordinates($latitude, $longitude));
  296. $results = $provider->reverseQuery($query);
  297. return $results->all() ;
  298. }
  299. public function getZipByCity($city, $code = null)
  300. {
  301. $zip = null;
  302. $paramsSearch = [
  303. 'nom' => $city,
  304. 'fields' => 'nom,codesPostaux'
  305. ];
  306. if ($code != null && $code != 0) {
  307. $paramsSearch['code'] = $code;
  308. }
  309. $returnCitiesSearchZip = json_decode($this->callCitiesApi('get', 'communes', $paramsSearch));
  310. if ($returnCitiesSearchZip) {
  311. foreach ($returnCitiesSearchZip as $citySearchZip) {
  312. if (strtolower(trim($city)) == strtolower(trim($citySearchZip->nom))) {
  313. $zip = $citySearchZip->codesPostaux[0];
  314. }
  315. }
  316. }
  317. return $zip;
  318. }
  319. public function date($format, $timestamp)
  320. {
  321. setlocale(LC_TIME, 'fr_FR.UTF8', 'fr.UTF8', 'fr_FR.UTF-8', 'fr.UTF-8');
  322. return strftime($format, $timestamp);
  323. }
  324. public function getNextDay($day)
  325. {
  326. return new \DateTime('next ' . $day);
  327. }
  328. public function getNextDayByNumber($number)
  329. {
  330. return $this->getNextDay($this->getDayByNumber($number, 'en'));
  331. }
  332. public static function getDayByNumber($number, $lang = 'fr')
  333. {
  334. if ($lang == 'fr') {
  335. $daysArray = [
  336. 1 => 'Lundi',
  337. 2 => 'Mardi',
  338. 3 => 'Mercredi',
  339. 4 => 'Jeudi',
  340. 5 => 'Vendredi',
  341. 6 => 'Samedi',
  342. 7 => 'Dimanche'
  343. ];
  344. } else {
  345. $daysArray = [
  346. 1 => 'Monday',
  347. 2 => 'Tuesday',
  348. 3 => 'Wednesday',
  349. 4 => 'Thursday',
  350. 5 => 'Friday',
  351. 6 => 'Saturday',
  352. 7 => 'Sunday',
  353. ];
  354. }
  355. if (isset($daysArray[$number])) {
  356. return $daysArray[$number];
  357. }
  358. return '';
  359. }
  360. public function addFlash($success, $message, $extraMessages = array(), $params = array(), $domain = 'lcshop')
  361. {
  362. $message = $this->translator->trans($message, $params, $domain);
  363. if (count($extraMessages)) {
  364. $message .= '<ul>';
  365. foreach ($extraMessages as $extraMessage) {
  366. $message .= '<li> <i>' . $this->translator->trans($extraMessage, array(), $domain) . '</i></li>';
  367. }
  368. $message .= '</ul>';
  369. }
  370. $this->session->getFlashBag()->add($success, $message);
  371. }
  372. public function getFlashMessages()
  373. {
  374. return $this->session->getFlashBag()->all();
  375. }
  376. function camelCase($str)
  377. {
  378. $i = array("-", "_");
  379. $str = preg_replace('/([a-z])([A-Z])/', "\\1 \\2", $str);
  380. $str = preg_replace('@[^a-zA-Z0-9\-_ ]+@', '', $str);
  381. $str = str_replace($i, ' ', $str);
  382. $str = str_replace(' ', '', ucwords(strtolower($str)));
  383. $str = strtolower(substr($str, 0, 1)) . substr($str, 1);
  384. return $str;
  385. }
  386. function snakeCase($str)
  387. {
  388. $str = preg_replace('/([a-z])([A-Z])/', "\\1_\\2", $str);
  389. $str = strtolower($str);
  390. return $str;
  391. }
  392. public function csvEscape($str)
  393. {
  394. return str_replace(array("\r", "\n"), ' ', $str);
  395. }
  396. public function getRemindersByUser($user)
  397. {
  398. $reminderRepo = $this->em->getRepository(ReminderInterface::class);
  399. $reminders = $reminderRepo->findByUser($user);
  400. $entitiesRepo = array();
  401. $entitiesConfig = array();
  402. if (count($reminders) > 0) {
  403. foreach ($reminders as $reminder) {
  404. if ($reminder->getEntityName()) {
  405. if (!isset($entitiesConfig[$reminder->getEntityName()])) {
  406. $entitiesConfig[$reminder->getEntityName()] = $this->configManager->getEntityConfig($reminder->getEntityName());
  407. }
  408. if ($reminder->getEntityAction() == 'edit' || $reminder->getEntityAction() == 'show') {
  409. if (!isset($entitiesRepo[$reminder->getEntityName()])) {
  410. $entitiesRepo[$reminder->getEntityName()] = $this->em->getRepository($entitiesConfig[$reminder->getEntityName()]['class']);
  411. }
  412. if ($reminder->getEntityId()) {
  413. $reminder->relatedPage = $entitiesRepo[$reminder->getEntityName()]->find($reminder->getEntityId())->__toString();
  414. }
  415. } else {
  416. $reminder->relatedPage = 'Liste de ' . $entitiesConfig[$reminder->getEntityName()]['label'];
  417. }
  418. }
  419. }
  420. }
  421. return $reminders;
  422. }
  423. public function removeDir($dir)
  424. {
  425. $files = array_diff(scandir($dir), array('.', '..'));
  426. foreach ($files as $file) {
  427. (is_dir("$dir/$file")) ? $this->removeDir("$dir/$file") : unlink("$dir/$file");
  428. }
  429. return rmdir($dir);
  430. }
  431. function folderToZip($folder, &$zipFile, $subfolder = null)
  432. {
  433. if ($zipFile == null) {
  434. // no resource given, exit
  435. return false;
  436. }
  437. // we check if $folder has a slash at its end, if not, we append one
  438. $tabFolder = str_split($folder);
  439. $tabSubFolder = str_split($subfolder);
  440. $folder .= end($tabFolder) == "/" ? "" : "/";
  441. $subfolder .= end($tabSubFolder) == "/" ? "" : "/";
  442. // we start by going through all files in $folder
  443. $handle = opendir($folder);
  444. while ($f = readdir($handle)) {
  445. if ($f != "." && $f != "..") {
  446. if (is_file($folder . $f)) {
  447. // if we find a file, store it
  448. // if we have a subfolder, store it there
  449. if ($subfolder != null)
  450. $zipFile->addFile($folder . $f, $subfolder . $f);
  451. else
  452. $zipFile->addFile($folder . $f);
  453. } elseif (is_dir($folder . $f)) {
  454. // if we find a folder, create a folder in the zip
  455. $zipFile->addEmptyDir($f);
  456. // and call the function again
  457. folderToZip($folder . $f, $zipFile, $f);
  458. }
  459. }
  460. }
  461. }
  462. public function lcLiip($path, $thumb = 'tile', $default = 'default.jpg')
  463. {
  464. if (substr($path, 0, 1) === '/') $path = substr($path, 1);
  465. if ($path) {
  466. $fileManagerFolder = substr($this->getFileManagerFolder(), 1) ;
  467. if (strpos($path, $fileManagerFolder) === false) {
  468. $path = $fileManagerFolder . '/' . $path;
  469. }
  470. if (file_exists($path)) {
  471. return $this->liipCacheHelper->getBrowserPath($path, $thumb);
  472. }
  473. }
  474. return $this->liipCacheHelper->getBrowserPath($this->getFileManagerFolder() . '/' . $default, $thumb);
  475. }
  476. /**
  477. * Retourne le chemin vers le dossier d'uploads de responsiveFilemanager
  478. *
  479. * @return string
  480. */
  481. public function getFileManagerFolder()
  482. {
  483. return $this->parameterBag->get('app.path.images');
  484. }
  485. public function addCaptchaType(FormBuilderInterface $builder)
  486. {
  487. $builder->add('specialField', HiddenType::class, [
  488. 'data' => 0,
  489. 'mapped' => false,
  490. 'attr' => [
  491. 'class' => 'special-field'
  492. ],
  493. 'constraints' => [
  494. new NotNull(),
  495. new EqualTo(['value' => $this->parameterBag->get('app.captcha_value'), 'message' => 'Valeur incorrecte'])
  496. ],
  497. ]);
  498. }
  499. public function urlEncryptData($datas){
  500. $key = 'secretToken';
  501. foreach ($datas as $data) {
  502. $key .= $data;
  503. }
  504. return md5($key);
  505. }
  506. public function getFilterPropertyClean($fieldName){
  507. return str_replace('.', '_', $fieldName);
  508. }
  509. public function getFilterPropertyInit($fieldName){
  510. return str_replace('_', '.', $fieldName);
  511. }
  512. public function hasFilterAssociation($fieldName, $needle="."){
  513. return strpos($fieldName, $needle);
  514. }
  515. public function getFilterWithoutAssociationAlias($fieldName, $needle = '.'){
  516. return substr($fieldName, strpos($fieldName, $needle)+1);
  517. }
  518. public function getFilterAssociationAlias($fieldName, $needle = '.'){
  519. return substr($fieldName, 0, strpos($fieldName, $needle));
  520. }
  521. public function round($price, $precision = 2)
  522. {
  523. return round((($price * 100)) / 100, $precision);
  524. }
  525. public function formatPhoneNumber($phone)
  526. {
  527. $phone = preg_replace('`[^0-9]`', '', $phone);
  528. if(strlen($phone) == 10) {
  529. $phone = '+33'.substr($phone, 1, 9) ;
  530. }
  531. elseif(strlen($phone) == 11 && substr($phone, 0, 2) == '33') {
  532. $phone = '+'.$phone ;
  533. }
  534. return $phone ;
  535. }
  536. public function getMetaTitle($entity)
  537. {
  538. if($entity) {
  539. if(method_exists($entity, 'getMetaTitle')) {
  540. return $entity->getMetaTitle() ;
  541. }
  542. elseif(method_exists($entity, 'getTitle')) {
  543. return $entity->getTitle() ;
  544. }
  545. }
  546. return '' ;
  547. }
  548. public function getMetaDescription($entity)
  549. {
  550. if($entity) {
  551. if(method_exists($entity, 'getMetaDescription')) {
  552. return $entity->getMetaDescription() ;
  553. }
  554. elseif(method_exists($entity, 'getDescription')) {
  555. return $entity->getDescription() ;
  556. }
  557. }
  558. return '' ;
  559. }
  560. public function getOpenGraphTitle($entity)
  561. {
  562. if($entity) {
  563. if(method_exists($entity, 'getOpenGraphTitle')) {
  564. return $entity->getOpenGraphTitle() ;
  565. }
  566. elseif(method_exists($entity, 'getTitle')) {
  567. return $entity->getTitle() ;
  568. }
  569. }
  570. return '' ;
  571. }
  572. public function getOpenGraphDescription($entity)
  573. {
  574. if($entity) {
  575. if(method_exists($entity, 'getOpenGraphDescription')) {
  576. return $entity->getOpenGraphDescription() ;
  577. }
  578. elseif(method_exists($entity, 'getDescription')) {
  579. return $entity->getDescription() ;
  580. }
  581. }
  582. return '' ;
  583. }
  584. public function getOpenGraphImage($entity)
  585. {
  586. if($entity) {
  587. if(method_exists($entity, 'getOpenGraphImage')) {
  588. return $entity->getOpenGraphImage() ;
  589. }
  590. elseif(method_exists($entity, 'getImage')) {
  591. return $entity->getImage() ;
  592. }
  593. }
  594. return '' ;
  595. }
  596. }