View file app/Models/Advert.php

File size: 1.63Kb
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. namespace App\Models;
  6.  
  7. use Illuminate\Support\Facades\Cache;
  8.  
  9. /**
  10. * Class Advert
  11. *
  12. * @property int id
  13. * @property string site
  14. * @property string name
  15. * @property string color
  16. * @property int bold
  17. * @property int user_id
  18. * @property int created_at
  19. * @property int deleted_at
  20. */
  21. class Advert extends BaseModel
  22. {
  23. /**
  24. * Indicates if the model should be timestamped.
  25. *
  26. * @var bool
  27. */
  28. public $timestamps = false;
  29.  
  30. /**
  31. * The attributes that aren't mass assignable.
  32. *
  33. * @var array
  34. */
  35. protected $guarded = [];
  36.  
  37. /**
  38. * Кэширует ссылки пользовательской рекламы
  39. *
  40. * @return array Список ссылок
  41. */
  42. public static function statAdverts(): array
  43. {
  44. if (! setting('rekusershow')) {
  45. return [];
  46. }
  47.  
  48. return Cache::remember('adverts', 1800, static function () {
  49. $data = self::query()->where('deleted_at', '>', SITETIME)->get();
  50.  
  51. if ($data->isEmpty()) {
  52. return [];
  53. }
  54.  
  55. $links = [];
  56. foreach ($data as $val) {
  57. $name = check($val->name);
  58.  
  59. if ($val->color) {
  60. $name = '<span style="color:' . $val->color . '">' . $name . '</span>';
  61. }
  62.  
  63. $link = '<a href="' . $val->site . '" target="_blank" rel="nofollow">' . $name . '</a>';
  64.  
  65. if ($val->bold) {
  66. $link = '<b>' . $link . '</b>';
  67. }
  68.  
  69. $links[] = $link;
  70. }
  71.  
  72. return $links;
  73. });
  74. }
  75. }