mirror of https://github.com/FriendsOfTYPO3/tea.git synced 2024-11-10 00:56:12 +01:00

[FEATURE] Add Tea.ownerUid (#860)

This is a pre-patch for adding a CRUD plugin for tea records.

This property contains only the UID of the owner FE user, but not
a relation to a FE user model. This is because we neither have nor
need a FE user model for the purposes of the CRUD plugin.
This commit is contained in:
Oliver Klee 2023-06-21 09:16:13 +02:00 committed by GitHub
parent c71bb82f4e
commit bbe469169b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 156 additions and 6 deletions

View file

@ -25,6 +25,13 @@ class Tea extends AbstractEntity
*/
protected $image;
// Note: We cannot use `@var` for the more specific type annotation here as this confuses the Extbase type mapper.
/**
* @phpstan-var int<0, max>
*/
protected int $ownerUid = 0;
public function getTitle(): string
{
return $this->title;
@ -60,4 +67,20 @@ class Tea extends AbstractEntity
{
$this->image = $image;
}
/**
* @return int<0, max>
*/
public function getOwnerUid(): int
{
return $this->ownerUid;
}
/**
* @param int<0, max> $ownerUid
*/
public function setOwnerUid(int $ownerUid): void
{
$this->ownerUid = $ownerUid;
}
}

View file

@ -7,6 +7,7 @@ namespace TTN\Tea\Domain\Repository\Product;
use TTN\Tea\Domain\Model\Product\Tea;
use TTN\Tea\Domain\Repository\Traits\StoragePageAgnosticTrait;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;
/**
@ -17,4 +18,15 @@ class TeaRepository extends Repository
use StoragePageAgnosticTrait;
protected $defaultOrderings = ['title' => QueryInterface::ORDER_ASCENDING];
/**
* @param positive-int $ownerUid
*/
public function findByOwnerUid(int $ownerUid): QueryResultInterface
{
$query = $this->createQuery();
$query->matching($query->equals('ownerUid', $ownerUid));
return $query->execute();
}
}

View file

@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
return [
\TTN\Tea\Domain\Model\Product\Tea::class => [
'properties' => [
'ownerUid' => ['fieldName' => 'owner'],
],
],
];

View file

@ -21,7 +21,7 @@ $tca = [
'types' => [
'1' => ['showitem' => '
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
title, description, image,
title, description, image, owner,
--div--;LLL:EXT:tea/Resources/Private/Language/locallang_db.xlf:tx_tea_domain_model_product_tea.tabs.access,
--palette--;;access,
'],
@ -133,8 +133,23 @@ $tca = [
'foreign_table' => 'fe_groups',
],
],
'owner' => [
'exclude' => true,
'l10n_mode' => 'exclude',
'label' => 'LLL:EXT:tea/Resources/Private/Language/locallang_db.xlf:tx_tea_domain_model_product_tea.owner',
'config' => [
'type' => 'group',
'allowed' => 'fe_users',
'default' => 0,
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
'hideSuggest' => true,
],
],
],
];
$typo3Version = new \TYPO3\CMS\Core\Information\Typo3Version();
if ($typo3Version->getMajorVersion() < 12) {
$tca = array_replace_recursive(

View file

@ -23,6 +23,10 @@
<source>Image</source>
<target>Bild</target>
</trans-unit>
<trans-unit id="tx_tea_domain_model_product_tea.owner">
<source>Website user who created this record</source>
<target>Website-Benutzer, der diesen Datensatz erstellt hat</target>
</trans-unit>
<trans-unit id="tx_tea_domain_model_product_tea.fe_group">
<source>Usergroup Access Rights</source>
<target>Zugriffsrechte für Benutzergruppen</target>

View file

@ -18,6 +18,9 @@
<trans-unit id="tx_tea_domain_model_product_tea.image">
<source>Image</source>
</trans-unit>
<trans-unit id="tx_tea_domain_model_product_tea.owner">
<source>Website user who created this record</source>
</trans-unit>
<trans-unit id="tx_tea_domain_model_product_tea.fe_group">
<source>Usergroup Access Rights</source>
</trans-unit>

View file

@ -1,8 +1,8 @@
"tx_tea_domain_model_product_tea"
,"uid","pid","title","description","image"
,"1","1","Earl Grey","Fresh and hot.",0
,"2","1","Assam","Dark and strong.",0
,"3","1","Gunpowder","Bitter and very green.",1
,"uid","pid","title","description","image","owner"
,"1","1","Earl Grey","Fresh and hot.",0,2
,"2","1","Assam","Dark and strong.",0,0
,"3","1","Gunpowder","Bitter and very green.",1,0
"sys_file_reference"
,"uid","pid","uid_foreign","tablenames","fieldname"
,"1","1","3","tx_tea_domain_model_product_tea","image"

Can't render this file because it has a wrong number of fields in line 2.

View file

@ -0,0 +1,3 @@
"tx_tea_domain_model_product_tea"
,"uid","pid","title","owner"
,"1","1","Earl Grey",1
Can't render this file because it has a wrong number of fields in line 2.

View file

@ -0,0 +1,3 @@
"tx_tea_domain_model_product_tea"
,"uid","pid","title","owner"
,"1","1","Earl Grey",0
Can't render this file because it has a wrong number of fields in line 2.

View file

@ -0,0 +1,4 @@
"tx_tea_domain_model_product_tea"
,"uid","pid","title","owner"
,"1","1","Earl Grey",1
,"2","1","Assam",1
Can't render this file because it has a wrong number of fields in line 2.

View file

@ -93,6 +93,7 @@ final class TeaRepositoryTest extends FunctionalTestCase
self::assertSame('Earl Grey', $model->getTitle());
self::assertSame('Fresh and hot.', $model->getDescription());
self::assertSame(2, $model->getOwnerUid());
}
/**
@ -133,4 +134,53 @@ final class TeaRepositoryTest extends FunctionalTestCase
self::assertIsArray($databaseRow);
self::assertSame($title, $databaseRow['title']);
}
/**
* @test
*/
public function findByOwnerUidFindsTeaWithTheGivenOwnerUid(): void
{
$this->importCSVDataSet(__DIR__ . '/../Fixtures/Product/TeaWithOwner.csv');
$result = $this->subject->findByOwnerUid(1);
self::assertCount(1, $result);
}
/**
* @test
*/
public function findByOwnerUidFindsIgnoresTeaWithNonMatchingOwnerUid(): void
{
$this->importCSVDataSet(__DIR__ . '/../Fixtures/Product/TeaWithOwner.csv');
$result = $this->subject->findByOwnerUid(2);
self::assertCount(0, $result);
}
/**
* @test
*/
public function findByOwnerUidFindsIgnoresTeaWithZeroOwnerUid(): void
{
$this->importCSVDataSet(__DIR__ . '/../Fixtures/Product/TeaWithoutOwner.csv');
$result = $this->subject->findByOwnerUid(1);
self::assertCount(0, $result);
}
/**
* @test
*/
public function findByOwnerUidSortsByTitleInAscendingOrder(): void
{
$this->importCSVDataSet(__DIR__ . '/../Fixtures/Product/TwoTeasWithOwner.csv');
$result = $this->subject->findByOwnerUid(1);
$result->rewind();
self::assertSame(2, $result->current()->getUid());
}
}

View file

@ -87,4 +87,23 @@ final class TeaTest extends UnitTestCase
self::assertSame($model, $this->subject->getImage());
}
/**
* @test
*/
public function getOwnerUidInitiallyReturnsZero(): void
{
self::assertSame(0, $this->subject->getOwnerUid());
}
/**
* @test
*/
public function setOwnerUidSetsOwnerUid(): void
{
$value = 123456;
$this->subject->setOwnerUid($value);
self::assertSame($value, $this->subject->getOwnerUid());
}
}

View file

@ -1,5 +1,8 @@
CREATE TABLE tx_tea_domain_model_product_tea (
title varchar(255) DEFAULT '' NOT NULL,
description varchar(2000) DEFAULT '' NOT NULL,
image int(11) unsigned DEFAULT '0' NOT NULL
image int(11) unsigned DEFAULT '0' NOT NULL,
owner int(11) unsigned DEFAULT '0' NOT NULL,
KEY owner (owner)
);