<?php

namespace ModulesGarden\HostingQuotaNotifications\App\UI\LoggerManager\Providers;

use ModulesGarden\HostingQuotaNotifications\Core\UI\Interfaces\AdminArea;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\Forms\DataProviders\BaseModelDataProvider;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\ResponseTemplates;

/**
 * CategoryDataProvider
 *
 * @author Artur Pilch <artur.pi@modulesgarden.com>
 */
class LoggerDataProvider extends BaseModelDataProvider implements AdminArea
{
    
    public function __construct()
    {
        parent::__construct('\ModulesGarden\HostingQuotaNotifications\Core\Models\Logger\Model');
    }

    public function delete()
    {
        
        if ($this->formData['id'])
        {
            parent::delete();
            
            return (new ResponseTemplates\HtmlDataJsonResponse())->setMessageAndTranslate('loggerDeletedSuccesfully');           
        }
        
        if ($this->requestObj->get('massActions', []))
        {
            foreach ($this->requestObj->get('massActions', []) as $tldId)
            {
                $this->model->where('id', $tldId)->delete();      
            }
            
            return (new ResponseTemplates\HtmlDataJsonResponse())->setMessageAndTranslate('loggersDeletedSuccesfully');  
        }
    }
    
    public function deleteall()
    {
        $this->model->truncate();
        
        return (new ResponseTemplates\HtmlDataJsonResponse())->setMessageAndTranslate('loggersDeletedSuccesfully');  
    }
}
