Skip to content

Commit

Permalink
[FEATURE] Allow selecting profiles in list plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
codemonkey1988 authored and Riiiad committed Sep 20, 2023
1 parent 28876f0 commit 7100804
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Classes/Domain/Model/Dto/DemandInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ public function getSortByDirection(): string;

public function setSortByDirection(string $sortByDirection): self;

public function setCurrentPage(int $currentPage): void;
public function setCurrentPage(int $currentPage): self;

public function getCurrentPage(): int;

public function setProfileList(string $profileList): self;

public function getProfileList(): string;
}
16 changes: 15 additions & 1 deletion Classes/Domain/Model/Dto/ProfileDemand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class ProfileDemand implements DemandInterface

protected int $currentPage = 1;

protected string $profileList = '';

public function getGroupBy(): string
{
return $this->groupBy;
Expand Down Expand Up @@ -59,8 +61,20 @@ public function getCurrentPage(): int
return $this->currentPage;
}

public function setCurrentPage(int $currentPage): void
public function setCurrentPage(int $currentPage): self
{
$this->currentPage = $currentPage;
return $this;
}

public function getProfileList(): string
{
return $this->profileList;
}

public function setProfileList(string $profileList): self
{
$this->profileList = $profileList;
return $this;
}
}
24 changes: 24 additions & 0 deletions Classes/Domain/Repository/ProfileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Fgtclb\AcademicPersons\Event\ModifyProfileDemandEvent;
use Psr\EventDispatcher\EventDispatcherInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;
Expand Down Expand Up @@ -55,9 +56,32 @@ public function findByDemand(DemandInterface $demand): QueryResultInterface
*/
private function applyDemandForQuery(QueryInterface $query, DemandInterface $demand): void
{
$filters = $this->setFilters($query, $demand);
if ($filters !== null) {
$query->matching($filters);
}
$query->setOrderings($this->getOrderingsFromDemand($demand));
}

/**
* @param QueryInterface<Profile> $query
*/
private function setFilters(QueryInterface $query, DemandInterface $demand): ?ConstraintInterface
{
$filters = [];

if (!empty($demand->getProfileList())) {
$profileUidArray = GeneralUtility::intExplode(',', $demand->getProfileList(), true);
$filters[] = $query->in('uid', $profileUidArray);
}

if (empty($filters)) {
return null;
}

return $query->logicalAnd(...$filters);
}

/**
* @return array<string, string>
*/
Expand Down
17 changes: 17 additions & 0 deletions Configuration/FlexForms/flexform_profile_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@
</config>
</TCEforms>
</settings.paginationEnabled>
<settings.demand.profileList>
<TCEforms>
<label>LLL:EXT:academic_persons/Resources/Private/Language/locallang_be.xlf:flexform.el.profileList.label</label>
<config>
<type>group</type>
<allowed>tx_academicpersons_domain_model_profile</allowed>
<foreign_table>tx_academicpersons_domain_model_profile</foreign_table>
<size>5</size>
<suggestOptions>
<default>
<additionalSearchFields>first_name,middle_name,last_name</additionalSearchFields>
<addWhere>sys_language_uid IN (-1,0)</addWhere>
</default>
</suggestOptions>
</config>
</TCEforms>
</settings.demand.profileList>
</el>
</ROOT>
</sDEF>
Expand Down
1 change: 1 addition & 0 deletions Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugin.tx_academicpersons {
groupBy = {$plugin.tx_academicpersons.demand.groupBy}
sortBy = {$plugin.tx_academicpersons.demand.sortBy}
sortByDirection = {$plugin.tx_academicpersons.demand.sortByDirection}
profileList =
}
pagination {
resultsPerPage = {$plugin.tx_academicpersons.pagination.resultsPerPage}
Expand Down
3 changes: 3 additions & 0 deletions Resources/Private/Language/locallang_be.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
<trans-unit id="flexform.el.paginationEnabled.items.0.label">
<source>Enabled</source>
</trans-unit>
<trans-unit id="flexform.el.profileList.label">
<source>List of profiles</source>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit 7100804

Please sign in to comment.