<?php

namespace GemBoards\hooks;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
} // if accessed directly, exit


class Dashboard {

	public static function init() {
		$self    = new self();
		$objects = [
			'column',
			'card',
			'board',
			'role',
			'assignee',
			'sprint',
		];
		foreach ( $objects as $object_type ) {
			add_action( "gemboards/$object_type/after/object_save", [ $self, 'clear_cache' ] );
			add_action( "gemboards/$object_type/deleted", [ $self, 'clear_cache' ] );
		}
	}

	public function clear_cache() {
		wp_cache_flush_group( 'gemboards_dashboard_stats' );
		wp_cache_flush_group( 'gemboards_board_analytics' );
	}
}
