Admin
3 weeks ago
Builder
3 weeks ago
Customizer
3 weeks ago
Exceptions
3 weeks ago
Helpers
3 weeks ago
Integrations
3 weeks ago
Migrations
3 weeks ago
ReviewAlerts
3 weeks ago
Services
3 weeks ago
Settings
3 weeks ago
Support
3 weeks ago
Traits
3 weeks ago
Utils
3 weeks ago
AuthorizationStatusCheck.php
3 weeks ago
BusinessDataCache.php
3 weeks ago
Clear_Cache.php
3 weeks ago
Container.php
3 weeks ago
DisplayElements.php
3 weeks ago
Email_Notification.php
3 weeks ago
Error_Reporter.php
3 weeks ago
Feed.php
3 weeks ago
FeedCache.php
3 weeks ago
FeedCacheUpdater.php
3 weeks ago
FeedDisplay.php
3 weeks ago
Feed_Locator.php
3 weeks ago
Parser.php
3 weeks ago
PostAggregator.php
3 weeks ago
RemoteRequest.php
3 weeks ago
SBR_Education.php
3 weeks ago
SBR_Schema_Service.php
3 weeks ago
SBR_Settings.php
3 weeks ago
ServiceContainer.php
3 weeks ago
SinglePostCache.php
3 weeks ago
TemplateRenderer.php
3 weeks ago
Tooltip_Wizard.php
3 weeks ago
Util.php
3 weeks ago
BusinessDataCache.php
50 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class BusinessDataCache |
| 5 | * |
| 6 | * @since 1.0 |
| 7 | */ |
| 8 | |
| 9 | namespace SmashBalloon\Reviews\Common; |
| 10 | |
| 11 | class BusinessDataCache { |
| 12 | public const CACHE_KEY = 'sbr_business_cache'; |
| 13 | |
| 14 | private $business_cache; |
| 15 | |
| 16 | public function __construct() |
| 17 | { |
| 18 | $raw_cache = get_option(self::CACHE_KEY, '{}'); |
| 19 | |
| 20 | $this->business_cache = json_decode($raw_cache, true); |
| 21 | } |
| 22 | |
| 23 | public function get_data($provider, $business_id) |
| 24 | { |
| 25 | if (! empty($this->business_cache[ $provider ][ $business_id ])) { |
| 26 | return $this->business_cache[ $provider ][ $business_id ]; |
| 27 | } |
| 28 | |
| 29 | return array(); |
| 30 | } |
| 31 | |
| 32 | public function update_single_datum($provider, $business_id, $data_key, $data_value) |
| 33 | { |
| 34 | if (empty($this->business_cache[ $provider ][ $business_id ])) { |
| 35 | return false; |
| 36 | } |
| 37 | $this->business_cache[ $provider ][ $business_id ][ $data_key ] = $data_value; |
| 38 | |
| 39 | return update_option(self::CACHE_KEY, wp_json_encode($this->business_cache), false); |
| 40 | } |
| 41 | |
| 42 | public function update_data($provider, $business_id, $data) |
| 43 | { |
| 44 | $this->business_cache[ $provider ][ $business_id ] = $data; |
| 45 | |
| 46 | return update_option(self::CACHE_KEY, wp_json_encode($this->business_cache), false); |
| 47 | } |
| 48 | |
| 49 | } |
| 50 |