diff --git a/Classes/Domain/Model/Product/Tea.php b/Classes/Domain/Model/Product/Tea.php index 69134eb..93ee208 100644 --- a/Classes/Domain/Model/Product/Tea.php +++ b/Classes/Domain/Model/Product/Tea.php @@ -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; + } } diff --git a/Classes/Domain/Repository/Product/TeaRepository.php b/Classes/Domain/Repository/Product/TeaRepository.php index 08dff16..e2ba4b7 100644 --- a/Classes/Domain/Repository/Product/TeaRepository.php +++ b/Classes/Domain/Repository/Product/TeaRepository.php @@ -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(); + } } diff --git a/Configuration/Extbase/Persistence/Classes.php b/Configuration/Extbase/Persistence/Classes.php new file mode 100644 index 0000000..6b92623 --- /dev/null +++ b/Configuration/Extbase/Persistence/Classes.php @@ -0,0 +1,11 @@ + [ + 'properties' => [ + 'ownerUid' => ['fieldName' => 'owner'], + ], + ], +]; diff --git a/Configuration/TCA/tx_tea_domain_model_product_tea.php b/Configuration/TCA/tx_tea_domain_model_product_tea.php index d5d9b7c..d3db950 100644 --- a/Configuration/TCA/tx_tea_domain_model_product_tea.php +++ b/Configuration/TCA/tx_tea_domain_model_product_tea.php @@ -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( diff --git a/Resources/Private/Language/de.locallang_db.xlf b/Resources/Private/Language/de.locallang_db.xlf index 1c2e058..0750c98 100644 --- a/Resources/Private/Language/de.locallang_db.xlf +++ b/Resources/Private/Language/de.locallang_db.xlf @@ -23,6 +23,10 @@ Image Bild + + Website user who created this record + Website-Benutzer, der diesen Datensatz erstellt hat + Usergroup Access Rights Zugriffsrechte für Benutzergruppen diff --git a/Resources/Private/Language/locallang_db.xlf b/Resources/Private/Language/locallang_db.xlf index 9187161..1068b6e 100644 --- a/Resources/Private/Language/locallang_db.xlf +++ b/Resources/Private/Language/locallang_db.xlf @@ -18,6 +18,9 @@ Image + + Website user who created this record + Usergroup Access Rights diff --git a/Tests/Functional/Domain/Repository/Fixtures/Product/Tea.csv b/Tests/Functional/Domain/Repository/Fixtures/Product/Tea.csv index bc01acf..e22d8a5 100644 --- a/Tests/Functional/Domain/Repository/Fixtures/Product/Tea.csv +++ b/Tests/Functional/Domain/Repository/Fixtures/Product/Tea.csv @@ -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" diff --git a/Tests/Functional/Domain/Repository/Fixtures/Product/TeaWithOwner.csv b/Tests/Functional/Domain/Repository/Fixtures/Product/TeaWithOwner.csv new file mode 100644 index 0000000..ebd1252 --- /dev/null +++ b/Tests/Functional/Domain/Repository/Fixtures/Product/TeaWithOwner.csv @@ -0,0 +1,3 @@ +"tx_tea_domain_model_product_tea" +,"uid","pid","title","owner" +,"1","1","Earl Grey",1 diff --git a/Tests/Functional/Domain/Repository/Fixtures/Product/TeaWithoutOwner.csv b/Tests/Functional/Domain/Repository/Fixtures/Product/TeaWithoutOwner.csv new file mode 100644 index 0000000..cf648db --- /dev/null +++ b/Tests/Functional/Domain/Repository/Fixtures/Product/TeaWithoutOwner.csv @@ -0,0 +1,3 @@ +"tx_tea_domain_model_product_tea" +,"uid","pid","title","owner" +,"1","1","Earl Grey",0 diff --git a/Tests/Functional/Domain/Repository/Fixtures/Product/TwoTeasWithOwner.csv b/Tests/Functional/Domain/Repository/Fixtures/Product/TwoTeasWithOwner.csv new file mode 100644 index 0000000..f6bc8a3 --- /dev/null +++ b/Tests/Functional/Domain/Repository/Fixtures/Product/TwoTeasWithOwner.csv @@ -0,0 +1,4 @@ +"tx_tea_domain_model_product_tea" +,"uid","pid","title","owner" +,"1","1","Earl Grey",1 +,"2","1","Assam",1 diff --git a/Tests/Functional/Domain/Repository/Product/TeaRepositoryTest.php b/Tests/Functional/Domain/Repository/Product/TeaRepositoryTest.php index d771e7c..5db48eb 100644 --- a/Tests/Functional/Domain/Repository/Product/TeaRepositoryTest.php +++ b/Tests/Functional/Domain/Repository/Product/TeaRepositoryTest.php @@ -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()); + } } diff --git a/Tests/Unit/Domain/Model/Product/TeaTest.php b/Tests/Unit/Domain/Model/Product/TeaTest.php index 1a10f64..72e5bf8 100644 --- a/Tests/Unit/Domain/Model/Product/TeaTest.php +++ b/Tests/Unit/Domain/Model/Product/TeaTest.php @@ -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()); + } } diff --git a/ext_tables.sql b/ext_tables.sql index 37399eb..d013de3 100644 --- a/ext_tables.sql +++ b/ext_tables.sql @@ -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) );