mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-06 02:59:29 +00:00
Compare commits
2 commits
023d38d170
...
36e1fcfbed
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
36e1fcfbed | ||
|
|
1925a71f30 |
4 changed files with 79 additions and 5 deletions
|
|
@ -22,24 +22,41 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Services\InfoProviderSystem\DTOs;
|
||||
|
||||
use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
|
||||
|
||||
/**
|
||||
* Represents a mapping between a part field and the info providers that should search in that field.
|
||||
*/
|
||||
readonly class BulkSearchFieldMappingDTO
|
||||
{
|
||||
/** @var string[] $providers Array of provider keys to search with (e.g., ['digikey', 'farnell']) */
|
||||
public array $providers;
|
||||
|
||||
/**
|
||||
* @param string $field The field to search in (e.g., 'mpn', 'name', or supplier-specific fields like 'digikey_spn')
|
||||
* @param string[] $providers Array of provider keys to search with (e.g., ['digikey', 'farnell'])
|
||||
* @param string[]|InfoProviderInterface[] $providers Array of provider keys to search with (e.g., ['digikey', 'farnell'])
|
||||
* @param int $priority Priority for this field mapping (1-10, lower numbers = higher priority)
|
||||
*/
|
||||
public function __construct(
|
||||
public string $field,
|
||||
public array $providers,
|
||||
array $providers = [],
|
||||
public int $priority = 1
|
||||
) {
|
||||
if ($priority < 1 || $priority > 10) {
|
||||
throw new \InvalidArgumentException('Priority must be between 1 and 10');
|
||||
}
|
||||
|
||||
//Ensure that providers are provided as keys
|
||||
foreach ($providers as &$provider) {
|
||||
if ($provider instanceof InfoProviderInterface) {
|
||||
$provider = $provider->getProviderKey();
|
||||
}
|
||||
if (!is_string($provider)) {
|
||||
throw new \InvalidArgumentException('Providers must be provided as strings or InfoProviderInterface instances');
|
||||
}
|
||||
}
|
||||
unset($provider);
|
||||
$this->providers = $providers;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ use Symfony\Component\Translation\TranslatableMessage as TM;
|
|||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[Settings(label: new TM("settings.misc.ipn_suggest"))]
|
||||
#[SettingsIcon("fa-list")]
|
||||
#[SettingsIcon("fa-arrow-up-1-9")]
|
||||
class IpnSuggestSettings
|
||||
{
|
||||
use SettingsTrait;
|
||||
|
|
@ -91,14 +91,14 @@ class IpnSuggestSettings
|
|||
description: new TM("settings.misc.ipn_suggest.numberSeparator.help"),
|
||||
options: ['type' => StringType::class],
|
||||
)]
|
||||
public ?string $numberSeparator = '-';
|
||||
public string $numberSeparator = '-';
|
||||
|
||||
#[SettingsParameter(
|
||||
label: new TM("settings.misc.ipn_suggest.categorySeparator"),
|
||||
description: new TM("settings.misc.ipn_suggest.categorySeparator.help"),
|
||||
options: ['type' => StringType::class],
|
||||
)]
|
||||
public ?string $categorySeparator = '-';
|
||||
public string $categorySeparator = '-';
|
||||
|
||||
#[SettingsParameter(
|
||||
label: new TM("settings.misc.ipn_suggest.globalPrefix"),
|
||||
|
|
|
|||
|
|
@ -26,6 +26,15 @@ use PHPUnit\Framework\TestCase;
|
|||
class BulkSearchFieldMappingDTOTest extends TestCase
|
||||
{
|
||||
|
||||
public function testProviderInstanceNormalization(): void
|
||||
{
|
||||
$mockProvider = $this->createMock(\App\Services\InfoProviderSystem\Providers\InfoProviderInterface::class);
|
||||
$mockProvider->method('getProviderKey')->willReturn('mock_provider');
|
||||
|
||||
$fieldMapping = new BulkSearchFieldMappingDTO(field: 'mpn', providers: ['provider1', $mockProvider], priority: 5);
|
||||
$this->assertSame(['provider1', 'mock_provider'], $fieldMapping->providers);
|
||||
}
|
||||
|
||||
public function testIsSupplierPartNumberField(): void
|
||||
{
|
||||
$fieldMapping = new BulkSearchFieldMappingDTO(field: 'reichelt_spn', providers: ['provider1'], priority: 1);
|
||||
|
|
|
|||
|
|
@ -14484,5 +14484,53 @@ Please note that this system is currently experimental, and the synonyms defined
|
|||
<target>The global IPN prefix, common across all parts</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="WlKvQeB" name="settings.misc.ipn_suggest.fallbackPrefix">
|
||||
<segment>
|
||||
<source>settings.misc.ipn_suggest.fallbackPrefix</source>
|
||||
<target>Fallback prefix</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="Fr8hXdE" name="settings.misc.ipn_suggest.fallbackPrefix.help">
|
||||
<segment>
|
||||
<source>settings.misc.ipn_suggest.fallbackPrefix.help</source>
|
||||
<target>The IPN prefix that should be used, if a category has no prefix defined.</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="_p9cMpI" name="settings.misc.ipn_suggest.numberSeparator">
|
||||
<segment>
|
||||
<source>settings.misc.ipn_suggest.numberSeparator</source>
|
||||
<target>Number separator</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="CqfzuM6" name="settings.misc.ipn_suggest.numberSeparator.help">
|
||||
<segment>
|
||||
<source>settings.misc.ipn_suggest.numberSeparator.help</source>
|
||||
<target>The separator character used to separate the IPN number from the prefix.</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="PisGfwB" name="settings.misc.ipn_suggest.categorySeparator">
|
||||
<segment>
|
||||
<source>settings.misc.ipn_suggest.categorySeparator</source>
|
||||
<target>Category separator</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="jlNd0CI" name="settings.misc.ipn_suggest.categorySeparator.help">
|
||||
<segment>
|
||||
<source>settings.misc.ipn_suggest.categorySeparator.help</source>
|
||||
<target>The separator character used to separate different levels of category prefixes.</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="MkiJuRK" name="settings.misc.ipn_suggest.globalPrefix">
|
||||
<segment>
|
||||
<source>settings.misc.ipn_suggest.globalPrefix</source>
|
||||
<target>Global prefix</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="Akh9iFg" name="settings.misc.ipn_suggest.globalPrefix.help">
|
||||
<segment>
|
||||
<source>settings.misc.ipn_suggest.globalPrefix.help</source>
|
||||
<target>If enabled, an option for to generate IPN with this global prefix, shared across parts in all categories.</target>
|
||||
</segment>
|
||||
</unit>
|
||||
</file>
|
||||
</xliff>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue