<?php

namespace PointRetrait\Controller\backOffice;

use LivraisonParSecteurs\LivraisonParSecteurs;
use LivraisonParSecteurs\Model\LpsAreaQuery;
use PointRetrait\Model\PdrPlacesQuery;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;

/**
 * Class ListController
 * @package PointRetrait\Controller
 */
class ListController extends BaseAdminController
{
    public function viewAction($params = [])
    {
        return $this->render("places-list");
    }


    public function toggleActive($id)
    {
        // Check current user authorization
        if (null !== $response = $this->checkAuth(AdminResources::MODULE, LivraisonParSecteurs::getModuleCode(), AccessManager::UPDATE))
            return $response;

        $place = PdrPlacesQuery::create()->findOneById(($id));
        $place->setActive($place->getActive() ? 0 : 1)->save();

        return $this->render("places-list");
    }
}