Your IP : 216.73.217.79


Current Path : /var/www/v3.cesa.co.za/src/CoreBundle/Services/
Upload File :
Current File : /var/www/v3.cesa.co.za/src/CoreBundle/Services/PublicHolidayManager.php

<?php

/*
 * For license information contact otto@igotafrica.com
 */

namespace App\CoreBundle\Services;

use Symfony\Component\DependencyInjection\ContainerInterface;
use App\CoreBundle\Entity\TempValue;

/**
 * Public holiday manager
 *
 * @author Otto Saayman <otto@igotafrica.com>
 * @package CoreBundle
 * @subpackage Public Holiday
 * @version 0.0.1
 */
final class PublicHolidayManager {

    /**
     * Service Container
     * @var object
     */
    private $container = null;

    /**
     * Entity manager
     * @var object
     */
    private $em;

    /**
     * Class construct
     *
     * @param  ContainerInterface $container
     * @param  Logger             $logger
     * @return void
     */
    public function __construct(ContainerInterface $container) {
        $this->setContainer($container);
        $this->setEm($container->get('doctrine')->getManager('default'));

        return;
    }

    /**
     * Get Container
     *
     * @return ContainerInterface $container
     */
    public function getContainer() {
        return $this->container;
    }

    /**
     * Set Container
     *
     * @param  ContainerInterface $container
     * @return void
     */
    public function setContainer($container) {
        $this->container = $container;
    }

    /**
     * Get Entity Manager
     *
     * @return string
     */
    public function getEm() {
        return $this->em;
    }

    /**
     * Set Container
     *
     * @param  string $em
     * @return void
     */
    public function setEm($em) {
        $this->em = $em;
    }

    /**
     * Find a temp value object
     *
     * @param  string $id
     * @return TempValue
     */
    public function getList() {

        $list = $this->getContainer()->get('temp_value.manager')->getTempValue('public_holidays_' . date('Y'), array(), true);

        if (is_array($list) && count($list) > 0) {
            return $list;
        }

        $list = Utils::getURLContent(
                        'https://holidays-by-api-ninjas.p.rapidapi.com/v1/holidays?country=za&year=2023&type=public_holiday',
                        array('header' => array(
                                'X-RapidAPI-Host: holidays-by-api-ninjas.p.rapidapi.com',
                                'X-RapidAPI-Key: d03d12a98amshf742d93fed093e4p1a81cdjsn26c4c58244e6'
                            )
                        )
        );

        $listLive = json_decode($list['content'], true);

        $this->getContainer()->get('temp_value.manager')->setTempValue('public_holidays_' . date('Y'), $listLive, true);
    }

}