Skip to content

Commit

Permalink
[TASK] Add sort order configuration to plugin
Browse files Browse the repository at this point in the history
Related: #79
  • Loading branch information
extcode committed Apr 22, 2020
1 parent 015a8cf commit 41ec981
Show file tree
Hide file tree
Showing 16 changed files with 540 additions and 15 deletions.
7 changes: 4 additions & 3 deletions Classes/Controller/ActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ public function injectCategoryRepository(CategoryRepository $categoryRepository)
*/
protected function createDemandObjectFromSettings(array $settings) : Demand
{
$demand = $this->objectManager->get(
Demand::class
);
$demand = new Demand();
$this->addCategoriesToDemandObjectFromSettings($demand);
if ($this->settings['orderBy']) {
$demand->setOrderBy($this->settings['orderBy']);
}

$arguments = $this->request->getArguments();

Expand Down
3 changes: 1 addition & 2 deletions Classes/Controller/AddressController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public function injectZipRepository(ZipRepository $zipRepository)

public function searchAction()
{
/** @var AddressSearch $addressSearch */
$addressSearch = $this->objectManager->get(AddressSearch::class);
$addressSearch = new AddressSearch();
if ($this->settings['orderBy']) {
$addressSearch->setOrderBy($this->settings['orderBy']);
if ($this->settings['fallbackOrderBy']) {
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Model/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function getLastName()
* @param string $seperator
* @return string
*/
public function getFullName(string $seperator)
public function getFullName(string $seperator = ' ')
{
return implode($seperator, [$this->getFirstName(), $this->getLastName()]);
}
Expand All @@ -176,7 +176,7 @@ public function getFullName(string $seperator)
* @param string $seperator
* @return string
*/
public function getTitleFullName(string $seperator)
public function getTitleFullName(string $seperator = ' ')
{
$titleFullName = [];
if ($this->getTitle()) {
Expand Down
21 changes: 21 additions & 0 deletions Classes/Domain/Model/Dto/Demand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class Demand
*/
protected $class = '';

/**
* @var string
*/
protected $orderBy = '';

/**
* @return string
*/
Expand Down Expand Up @@ -126,4 +131,20 @@ public function setActionAndClass($action, $class): void
$this->action = $action;
$this->class = $class;
}

/**
* @return string
*/
public function getOrderBy(): string
{
return $this->orderBy;
}

/**
* @param string $orderBy
*/
public function setOrderBy(string $orderBy): void
{
$this->orderBy = $orderBy;
}
}
8 changes: 8 additions & 0 deletions Classes/Domain/Repository/CompanyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public function findDemanded(Demand $demand)
);
}

if (!empty($demand->getOrderBy())) {
$query->setOrderings(
[
$demand->getOrderBy() => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING
]
);
}

return $query->execute();
}

Expand Down
8 changes: 8 additions & 0 deletions Classes/Domain/Repository/ContactRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ public function findDemanded(Demand $demand)
);
}

if (!empty($demand->getOrderBy())) {
$query->setOrderings(
[
$demand->getOrderBy() => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING
]
);
}

return $query->execute();
}

Expand Down
19 changes: 19 additions & 0 deletions Configuration/FlexForms/CompaniesPlugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@
</TCEforms>
</switchableControllerActions>

<settings.orderBy>
<TCEforms>
<label>LLL:EXT:contacts/Resources/Private/Language/locallang_be.xlf:tx_contacts.plugin.companies.action.company.list.orderBy</label>
<config>
<type>select</type>
<items>
<numIndex index="0" type="array">
<numIndex index="0"></numIndex>
<numIndex index="1"></numIndex>
</numIndex>
<numIndex index="2">
<numIndex index="0">LLL:EXT:contacts/Resources/Private/Language/locallang_be.xlf:tx_contacts.plugin.companies.action.company.list.orderBy.name</numIndex>
<numIndex index="1">name</numIndex>
</numIndex>
</items>
</config>
</TCEforms>
</settings.orderBy>

<settings.companyUids>
<TCEforms>
<label>LLL:EXT:contacts/Resources/Private/Language/locallang_db.xlf:tx_contacts_domain_model_company</label>
Expand Down
19 changes: 19 additions & 0 deletions Configuration/FlexForms/ContactsPlugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@
</TCEforms>
</switchableControllerActions>

<settings.orderBy>
<TCEforms>
<label>LLL:EXT:contacts/Resources/Private/Language/locallang_be.xlf:tx_contacts.plugin.contacts.action.contact.list.orderBy</label>
<config>
<type>select</type>
<items>
<numIndex index="0" type="array">
<numIndex index="0"></numIndex>
<numIndex index="1"></numIndex>
</numIndex>
<numIndex index="2">
<numIndex index="0">LLL:EXT:contacts/Resources/Private/Language/locallang_be.xlf:tx_contacts.plugin.contacts.action.contact.list.orderBy.last_name</numIndex>
<numIndex index="1">last_name</numIndex>
</numIndex>
</items>
</config>
</TCEforms>
</settings.orderBy>

<settings.contactUids>
<TCEforms>
<label>LLL:EXT:contacts/Resources/Private/Language/locallang_db.xlf:tx_contacts_domain_model_contact</label>
Expand Down
16 changes: 16 additions & 0 deletions Resources/Private/Language/de.locallang_be.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@
<target>Detailseite</target>
</trans-unit>

<trans-unit id="tx_contacts.plugin.contacts.action.contact.list.orderBy">
<source>Sort Order</source>
<target>Sortierreihenfolge</target>
</trans-unit>
<trans-unit id="tx_contacts.plugin.contacts.action.contact.list.orderBy.last_name">
<source>Last Name</source>
<target>Nachname</target>
</trans-unit>
<trans-unit id="tx_contacts.plugin.contacts.action.contact.list.categories">
<source>Categories</source>
<target>Kategorie</target>
Expand All @@ -96,6 +104,14 @@
<target>mit Unterkategorien</target>
</trans-unit>

<trans-unit id="tx_contacts.plugin.companies.action.company.list.orderBy">
<source>Sort Order</source>
<target>Sortierreihenfolge</target>
</trans-unit>
<trans-unit id="tx_contacts.plugin.companies.action.company.list.orderBy.name">
<source>Name</source>
<target>Name</target>
</trans-unit>
<trans-unit id="tx_contacts.plugin.companies.action.company.list.categories">
<source>Categories</source>
<target>Kategorie</target>
Expand Down
12 changes: 12 additions & 0 deletions Resources/Private/Language/locallang_be.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,25 @@
<source>Detail Page</source>
</trans-unit>

<trans-unit id="tx_contacts.plugin.contacts.action.contact.list.orderBy">
<source>Sort Order</source>
</trans-unit>
<trans-unit id="tx_contacts.plugin.contacts.action.contact.list.orderBy.last_name">
<source>Last Name</source>
</trans-unit>
<trans-unit id="tx_contacts.plugin.contacts.action.contact.list.categories">
<source>Categories</source>
</trans-unit>
<trans-unit id="tx_contacts.plugin.contacts.action.contact.list.subcategories">
<source>with Subcategories</source>
</trans-unit>

<trans-unit id="tx_contacts.plugin.companies.action.company.list.orderBy">
<source>Sort Order</source>
</trans-unit>
<trans-unit id="tx_contacts.plugin.companies.action.company.list.orderBy.name">
<source>Name</source>
</trans-unit>
<trans-unit id="tx_contacts.plugin.companies.action.company.list.categories">
<source>Categories</source>
</trans-unit>
Expand Down
77 changes: 77 additions & 0 deletions Tests/Functional/Fixtures/tx_contacts_domain_model_contact.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<dataset>
<tx_contacts_domain_model_contact>
<uid>1</uid>
<pid>2</pid>
<first_name>Max</first_name>
<last_name>Mustermann</last_name>
<teaser>''</teaser>
<description>''</description>
<meta_description>''</meta_description>
</tx_contacts_domain_model_contact>
<tx_contacts_domain_model_contact>
<uid>2</uid>
<pid>2</pid>
<first_name>Erika</first_name>
<last_name>Mustermann</last_name>
<teaser>''</teaser>
<description>''</description>
<meta_description>''</meta_description>
</tx_contacts_domain_model_contact>

<tx_contacts_domain_model_contact>
<uid>3</uid>
<pid>3</pid>
<first_name>John</first_name>
<last_name>Doe</last_name>
<teaser>''</teaser>
<description>''</description>
<meta_description>''</meta_description>
</tx_contacts_domain_model_contact>
<tx_contacts_domain_model_contact>
<uid>4</uid>
<pid>3</pid>
<first_name>Jane</first_name>
<last_name>Doe</last_name>
<teaser>''</teaser>
<description>''</description>
<meta_description>''</meta_description>
</tx_contacts_domain_model_contact>

<tx_contacts_domain_model_contact>
<uid>5</uid>
<pid>4</pid>
<first_name>Jean</first_name>
<last_name>Dupont</last_name>
<teaser>''</teaser>
<description>''</description>
<meta_description>''</meta_description>
</tx_contacts_domain_model_contact>
<tx_contacts_domain_model_contact>
<uid>6</uid>
<pid>4</pid>
<first_name>Matti</first_name>
<last_name>Meikäläinen</last_name>
<teaser>''</teaser>
<description>''</description>
<meta_description>''</meta_description>
</tx_contacts_domain_model_contact>
<tx_contacts_domain_model_contact>
<uid>7</uid>
<pid>4</pid>
<first_name>Mario</first_name>
<last_name>Rossi</last_name>
<teaser>''</teaser>
<description>''</description>
<meta_description>''</meta_description>
</tx_contacts_domain_model_contact>
<tx_contacts_domain_model_contact>
<uid>8</uid>
<pid>4</pid>
<first_name>Jan</first_name>
<last_name>Janssen</last_name>
<teaser>''</teaser>
<description>''</description>
<meta_description>''</meta_description>
</tx_contacts_domain_model_contact>
</dataset>
85 changes: 85 additions & 0 deletions Tests/Functional/Repository/CompanyRepositoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace Extcode\Contacts\Tests\Functional\Repository;

/*
* This file is part of the package extcode/contacts.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

use Extcode\Contacts\Domain\Model\Dto\Demand;
use Extcode\Contacts\Domain\Repository\CompanyRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

class CompanyRepositoryTest extends FunctionalTestCase
{

/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
*/
protected $objectManager;

/**
* @var CompanyRepository
*/
protected $companyRepository;

protected $testExtensionsToLoad = [
'typo3conf/ext/contacts'
];

public function setUp(): void
{
parent::setUp();
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->companyRepository = $this->objectManager->get(CompanyRepository::class);

$this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
$this->importDataSet(__DIR__ . '/../Fixtures/tx_contacts_domain_model_company.xml');
}

public function tearDown(): void
{
unset($this->companyRepository);
unset($this->objectManager);
}

/**
* @test
*/
public function findDemandedAndOrderByName(): void
{
$demand = new Demand();
$demand->setOrderBy('name');

$querySettings = $this->companyRepository->createQuery()->getQuerySettings();
$querySettings->setRespectStoragePage(false);
$this->companyRepository->setDefaultQuerySettings($querySettings);
$companies = $this->companyRepository->findDemanded($demand)->toArray();

$this->assertSame(
'Abgeordnetenhaus von Berlin',
$companies[0]->getName()
);
$this->assertSame(
'Bayerischer Landtag',
$companies[1]->getName()
);
$this->assertSame(
'Bremische Bürgerschaft',
$companies[2]->getName()
);
$this->assertSame(
'Landtag von Baden-Württemberg',
$companies[10]->getName()
);
$this->assertSame(
'Thüringer Landtag',
$companies[15]->getName()
);
}
}
Loading

0 comments on commit 41ec981

Please sign in to comment.