AdminShadowFilterService.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Services;
  3. use App\Models\AdminShadowFilter;
  4. use Cache;
  5. class AdminShadowFilterService
  6. {
  7. const CACHE_KEY = 'pf:services:asfs:';
  8. public static function queryFilter($name = 'hide_from_public_feeds')
  9. {
  10. return AdminShadowFilter::whereItemType('App\Profile')
  11. ->whereActive(1)
  12. ->where('hide_from_public_feeds', true)
  13. ->pluck('item_id')
  14. ->toArray();
  15. }
  16. public static function getHideFromPublicFeedsList($refresh = false)
  17. {
  18. $key = self::CACHE_KEY . 'list:hide_from_public_feeds';
  19. if($refresh) {
  20. Cache::forget($key);
  21. }
  22. return Cache::remember($key, 86400, function() {
  23. return AdminShadowFilter::whereItemType('App\Profile')
  24. ->whereActive(1)
  25. ->where('hide_from_public_feeds', true)
  26. ->pluck('item_id')
  27. ->toArray();
  28. });
  29. }
  30. public static function canAddToPublicFeedByProfileId($profileId)
  31. {
  32. return !in_array($profileId, self::getHideFromPublicFeedsList());
  33. }
  34. public static function refresh()
  35. {
  36. $keys = [
  37. self::CACHE_KEY . 'list:hide_from_public_feeds'
  38. ];
  39. foreach($keys as $key) {
  40. Cache::forget($key);
  41. }
  42. }
  43. }