<?php
/**
 * MetaTagSet AdminList
 *
 * @author Visual Media
 */

namespace VisualM\TagManagerBundle\AdminList;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Translation\TranslatorInterface;
use VisualM\TagManagerBundle\Model\MetaTagSetManager;
use VisualM\ManagementBundle\AdminList\AdminList;
use VisualM\ManagementBundle\AdminList\Column\Action\Action;
use VisualM\ManagementBundle\AdminList\Column\ActionsColumn;
use VisualM\ManagementBundle\AdminList\Column\PlainValueColumn;
use VisualM\ManagementBundle\AdminList\PaginationConfiguration;
use VisualM\ManagementBundle\AdminList\Param\QueryParamProvider;
use VisualM\ManagementBundle\AdminList\ParamConfiguration;
use VisualM\ManagementBundle\AdminList\TableConfiguration;
use VisualM\ManagementBundle\AdminList\Column\BooleanColumn;

/**
 * MetaTagSet AdminList
 *
 * @author Visual Media
 */
class MetaTagSetAdminList extends AdminList
{

    /**
     * Constructor
     *
     * @param Request                  $request         Current Request
     * @param MetaTagSetManager        $manager         Model Manager
     * @param TranslatorInterface      $translator      Translator
     * @param SecurityContextInterface $securityContext Security Context
     */
    public function __construct(Request $request, MetaTagSetManager $manager, TranslatorInterface $translator, SecurityContextInterface $securityContext)
    {
        $actions = array();
        if ($securityContext->isGranted('ROLE_PERM_EDIT_META_TAG_SET')) {
            $actions[] = new Action('manage_meta_tag_set_edit', 'id', $translator->trans('meta_tag_set.action.edit', array(), 'backend'), 'btn btn-sm btn-primary', 'edit');

            if ($securityContext->isGranted('ROLE_PERM_DELETE_META_TAG_SET')) {
                $actions[] = new Action('manage_meta_tag_set_delete', 'id', $translator->trans('meta_tag_set.action.delete.label', [], 'backend'), 'btn btn-sm btn-danger', 'trash', array(
                    'data-confirm' => $translator->trans('meta_tag_set.action.delete.confirm', [], 'backend'),
                    'data-method' => 'POST'
                ));
            }

        }
        
        parent::__construct(
            $request, 
            $manager, 
            new PaginationConfiguration(15, 7), 
            new TableConfiguration(
                array(
                    new PlainValueColumn('naam', $translator->trans('meta_tag_set.header.naam', [], 'backend'), true),
                    new BooleanColumn('kiesbaar', $translator->trans('meta_tag_set.header.kiesbaar', [], 'backend'), true, 'label label-success', 'label label-danger'),
                    new Column\ContentTypesColumn('contentTypes', $translator->trans('meta_tag_set.header.content_types', [], 'backend')),
                    new ActionsColumn('id', $translator->trans('meta_tag_set.header.actions', [], 'backend'), $actions)
                ), 
                'naam',
                'ASC'
            ), 
            new ParamConfiguration(array(
                new QueryParamProvider('page'),
                new QueryParamProvider('orderBy', $request->getSession(), 'metaTagSetOrderBy'),
                new QueryParamProvider('orderDir', $request->getSession(), 'metaTagSetOrderDir'),
                new QueryParamProvider('search')
            ))
        );
    }

    /**
     * {@inheritDoc}
     */
    public function getRowClass($item)
    {
        if ($item->getId() == $this->Request->getSession()->get('meta_tag_set.lastEdit')) {
            return 'last-edit';
        } else {
            return '';
        }
    }

}
