Skip to content

Commit

Permalink
Merge f13cdac into b47d0c5
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Jul 6, 2020
2 parents b47d0c5 + f13cdac commit 08be0cc
Show file tree
Hide file tree
Showing 21 changed files with 575 additions and 35 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/documentation.yaml
@@ -1,3 +1,7 @@
# DO NOT EDIT THIS FILE!
#
# It's auto-generated by sonata-project/dev-kit package.

on:
push:
paths:
Expand Down Expand Up @@ -31,7 +35,7 @@ jobs:
run: sudo apt-get install python-dev build-essential

- name: "Cache pip"
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('docs/requirements.txt') }}
Expand Down
24 changes: 24 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,30 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [3.12.1](https://github.com/sonata-project/SonataClassificationBundle/compare/3.12.0...3.12.1) - 2020-06-21
### Fixed
- [[#539](https://github.com/sonata-project/SonataClassificationBundle/pull/539)]
Fix mysql database schema ([@wbloszyk](https://github.com/wbloszyk))

### Removed
- [[#539](https://github.com/sonata-project/SonataClassificationBundle/pull/539)]
Remove support for mssql database ([@wbloszyk](https://github.com/wbloszyk))

## [3.12.0](https://github.com/sonata-project/SonataClassificationBundle/compare/3.11.1...3.12.0) - 2020-06-19
### Added
- Added `CategoryFilter` for admin lists
- Added `CollectionFilter` for admin lists

### Fixed
- fixed database schema to work with mssql

### Changed
- Make admin bundle optional

### Removed
- SonataCoreBundle dependencies
- Support for Symfony < 4.3

## [3.11.1](https://github.com/sonata-project/SonataClassificationBundle/compare/3.11.0...3.11.1) - 2020-03-24
### Fixed
- Fix Lexer query error in managers
Expand Down
39 changes: 22 additions & 17 deletions composer.json
Expand Up @@ -21,34 +21,39 @@
}
],
"require": {
"php": "^7.1",
"php": "^7.2",
"cocur/slugify": "^2.0 || ^3.0 || ^4.0",
"sonata-project/admin-bundle": "^3.31",
"sonata-project/core-bundle": "^3.14",
"sonata-project/datagrid-bundle": "^2.3",
"sonata-project/datagrid-bundle": "^2.3 || ^3.0",
"sonata-project/doctrine-extensions": "^1.6.0",
"sonata-project/doctrine-orm-admin-bundle": "^3.4",
"sonata-project/easy-extends-bundle": "^2.5",
"symfony/config": "^3.4 || ^4.2",
"symfony/console": "^3.4 || ^4.2",
"symfony/dependency-injection": "^3.4 || ^4.2",
"symfony/form": "^3.4 || ^4.2",
"symfony/http-foundation": "^3.4 || ^4.2",
"symfony/http-kernel": "^3.4 || ^4.2",
"symfony/options-resolver": "^3.4 || ^4.2",
"twig/twig": "^1.35 || ^2.0"
"sonata-project/form-extensions": "^0.1.1 || ^1.4",
"symfony/config": "^4.3",
"symfony/console": "^4.3",
"symfony/dependency-injection": "^4.3",
"symfony/form": "^4.3",
"symfony/http-foundation": "^4.3",
"symfony/http-kernel": "^4.3",
"symfony/options-resolver": "^4.3",
"twig/twig": "^2.12.1"
},
"conflict": {
"doctrine/mongodb-odm": "<2.0",
"friendsofsymfony/rest-bundle": "<2.1 || >=3.0",
"jms/serializer": "<0.13",
"sonata-project/block-bundle": "<3.14 || >=4.0"
"sonata-project/admin-bundle": "<3.59",
"sonata-project/block-bundle": "<3.14 || >=4.0",
"sonata-project/core-bundle": "<3.20",
"sonata-project/doctrine-orm-admin-bundle": "<3.4",
"sonata-project/media-bundle": "<3.17 || >=4.0"
},
"require-dev": {
"doctrine/mongodb-odm": "^2.0",
"friendsofsymfony/rest-bundle": "^2.1",
"jms/serializer-bundle": "^1.0 || ^2.0",
"sonata-project/block-bundle": "^3.16.1",
"friendsofsymfony/rest-bundle": "^2.3",
"jms/serializer-bundle": "^2.0 || ^3.0",
"sonata-project/admin-bundle": "^3.59",
"sonata-project/block-bundle": "^3.18",
"sonata-project/doctrine-orm-admin-bundle": "^3.4",
"sonata-project/media-bundle": "^3.20",
"symfony/phpunit-bridge": "^5.0"
},
"suggest": {
Expand Down
5 changes: 4 additions & 1 deletion docs/requirements.txt
@@ -1,3 +1,6 @@
Sphinx!=1.8.0
# DO NOT EDIT THIS FILE!
#
# It's auto-generated by sonata-project/dev-kit package.
Sphinx==1.8.5
git+https://github.com/fabpot/sphinx-php.git
sphinx_rtd_theme
125 changes: 125 additions & 0 deletions src/Admin/Filter/CategoryFilter.php
@@ -0,0 +1,125 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\ClassificationBundle\Admin\Filter;

use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\AdminBundle\Form\Type\Filter\DefaultType;
use Sonata\ClassificationBundle\Model\CategoryInterface;
use Sonata\ClassificationBundle\Model\CategoryManagerInterface;
use Sonata\DoctrineORMAdminBundle\Filter\Filter;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

final class CategoryFilter extends Filter
{
/**
* @var CategoryManagerInterface
*/
private $categoryManager;

public function __construct(CategoryManagerInterface $categoryManager)
{
$this->categoryManager = $categoryManager;
}

public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data): void
{
if (null === $data || !\is_array($data) || !\array_key_exists('value', $data)) {
return;
}

if (null !== $data['value']) {
$queryBuilder
->andWhere(sprintf('%s.%s = :category', $alias, $field))
->setParameter('category', $data['value'])
;
}

$this->active = null !== $data['value'];
}

public function getDefaultOptions(): array
{
return [
'context' => null,
];
}

public function getFieldType(): string
{
return $this->getOption('field_type', ChoiceType::class);
}

public function getFieldOptions(): array
{
return $this->getOption('choices', [
'choices' => $this->getChoices(),
'choice_translation_domain' => false,
]);
}

public function getRenderSettings(): array
{
return [DefaultType::class, [
'field_type' => $this->getFieldType(),
'field_options' => $this->getFieldOptions(),
'label' => $this->getLabel(),
]];
}

protected function association(ProxyQueryInterface $queryBuilder, $data): array
{
$alias = $queryBuilder->entityJoin($this->getParentAssociationMappings());
$part = strrchr('.'.$this->getFieldName(), '.');
$fieldName = substr(false === $part ? $this->getFieldType() : $part, 1);

return [$alias, $fieldName];
}

/**
* @return array<string, int>
*/
private function getChoices(): array
{
$context = $this->getOption('context');

if (null === $context) {
$categories = $this->categoryManager->getAllRootCategories();
} else {
$categories = $this->categoryManager->getRootCategoriesForContext($context);
}

$choices = [];

foreach ($categories as $category) {
$choices[sprintf('%s (%s)', $category->getName(), $category->getContext()->getId())] = $category->getId();

$this->visitChild($category, $choices);
}

return $choices;
}

private function visitChild(CategoryInterface $category, array &$choices, int $level = 2): void
{
if (0 === \count($category->getChildren())) {
return;
}

foreach ($category->getChildren() as $child) {
$choices[sprintf('%s %s', str_repeat('-', 1 * $level), (string) $child)] = $child->getId();

$this->visitChild($child, $choices, $level + 1);
}
}
}
109 changes: 109 additions & 0 deletions src/Admin/Filter/CollectionFilter.php
@@ -0,0 +1,109 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\ClassificationBundle\Admin\Filter;

use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\AdminBundle\Form\Type\Filter\DefaultType;
use Sonata\ClassificationBundle\Model\CollectionManagerInterface;
use Sonata\DoctrineORMAdminBundle\Filter\Filter;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

final class CollectionFilter extends Filter
{
/**
* @var CollectionManagerInterface
*/
private $collectionManager;

public function __construct(CollectionManagerInterface $collectionManager)
{
$this->collectionManager = $collectionManager;
}

public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data): void
{
if (null === $data || !\is_array($data) || !\array_key_exists('value', $data)) {
return;
}

if ($data['value']) {
$queryBuilder
->andWhere(sprintf('%s.%s = :collection', $alias, $field))
->setParameter('collection', $data['value'])
;
}

$this->active = null !== $data['value'];
}

public function getDefaultOptions(): array
{
return [
'context' => null,
];
}

public function getFieldType(): string
{
return $this->getOption('field_type', ChoiceType::class);
}

public function getFieldOptions(): array
{
return $this->getOption('choices', [
'choices' => $this->getChoices(),
'choice_translation_domain' => false,
]);
}

public function getRenderSettings(): array
{
return [DefaultType::class, [
'field_type' => $this->getFieldType(),
'field_options' => $this->getFieldOptions(),
'label' => $this->getLabel(),
]];
}

protected function association(ProxyQueryInterface $queryBuilder, $data): array
{
$alias = $queryBuilder->entityJoin($this->getParentAssociationMappings());
$part = strrchr('.'.$this->getFieldName(), '.');
$fieldName = substr(false === $part ? $this->getFieldType() : $part, 1);

return [$alias, $fieldName];
}

/**
* @return array<string, int>
*/
private function getChoices(): array
{
$context = $this->getOption('context');

if (null === $context) {
$collections = $this->collectionManager->findAll();
} else {
$collections = $this->collectionManager->getByContext($context);
}

$choices = [];

foreach ($collections as $collection) {
$choices[(string) $collection] = $collection->getId();
}

return $choices;
}
}
2 changes: 1 addition & 1 deletion src/Controller/Api/CategoryController.php
Expand Up @@ -19,9 +19,9 @@
use FOS\RestBundle\Request\ParamFetcherInterface;
use FOS\RestBundle\View\View as FOSRestView;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Sonata\ClassificationBundle\Form\FormHelper;
use Sonata\ClassificationBundle\Model\CategoryInterface;
use Sonata\ClassificationBundle\Model\CategoryManagerInterface;
use Sonata\CoreBundle\Form\FormHelper;
use Sonata\DatagridBundle\Pager\PagerInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Api/CollectionController.php
Expand Up @@ -19,9 +19,9 @@
use FOS\RestBundle\Request\ParamFetcherInterface;
use FOS\RestBundle\View\View as FOSRestView;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Sonata\ClassificationBundle\Form\FormHelper;
use Sonata\ClassificationBundle\Model\CollectionInterface;
use Sonata\ClassificationBundle\Model\CollectionManagerInterface;
use Sonata\CoreBundle\Form\FormHelper;
use Sonata\DatagridBundle\Pager\PagerInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Api/ContextController.php
Expand Up @@ -19,9 +19,9 @@
use FOS\RestBundle\Request\ParamFetcherInterface;
use FOS\RestBundle\View\View as FOSRestView;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Sonata\ClassificationBundle\Form\FormHelper;
use Sonata\ClassificationBundle\Model\ContextInterface;
use Sonata\ClassificationBundle\Model\ContextManagerInterface;
use Sonata\CoreBundle\Form\FormHelper;
use Sonata\DatagridBundle\Pager\PagerInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Api/TagController.php
Expand Up @@ -19,9 +19,9 @@
use FOS\RestBundle\Request\ParamFetcherInterface;
use FOS\RestBundle\View\View as FOSRestView;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Sonata\ClassificationBundle\Form\FormHelper;
use Sonata\ClassificationBundle\Model\TagInterface;
use Sonata\ClassificationBundle\Model\TagManagerInterface;
use Sonata\CoreBundle\Form\FormHelper;
use Sonata\DatagridBundle\Pager\PagerInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
Expand Down

0 comments on commit 08be0cc

Please sign in to comment.