Compare commits

..

6 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
e12bf570f9 Use --no-install with require and run separate install command
Co-authored-by: jbtronics <5410681+jbtronics@users.noreply.github.com>
2025-12-07 14:39:43 +00:00
copilot-swe-agent[bot]
562e4772cd Add --no-dev flag to composer require to prevent dev packages installation
Co-authored-by: jbtronics <5410681+jbtronics@users.noreply.github.com>
2025-12-07 14:30:56 +00:00
copilot-swe-agent[bot]
0444d4e505 Add documentation for installing mailer packages in email.md
Co-authored-by: jbtronics <5410681+jbtronics@users.noreply.github.com>
2025-12-07 14:15:47 +00:00
copilot-swe-agent[bot]
354d201476 Add shellcheck disable comment for intentional word splitting
Co-authored-by: jbtronics <5410681+jbtronics@users.noreply.github.com>
2025-12-07 13:25:31 +00:00
copilot-swe-agent[bot]
43996160c0 Add COMPOSER_EXTRA_PACKAGES environment variable support for Docker containers
Co-authored-by: jbtronics <5410681+jbtronics@users.noreply.github.com>
2025-12-07 13:23:49 +00:00
copilot-swe-agent[bot]
18aa531c75 Initial plan 2025-12-07 13:20:50 +00:00
39 changed files with 3881 additions and 5211 deletions

View File

@@ -1,193 +0,0 @@
# Entity Inheritance Hierarchy Decomposition
## Overview
This refactoring decomposes the deep entity inheritance hierarchy into a more flexible trait-based architecture. This provides better code reusability, composition, and maintainability.
## Architecture Diagram
### Before (Deep Inheritance):
```
AbstractDBElement (ID logic)
└─ AbstractNamedDBElement (name + timestamps)
└─ AttachmentContainingDBElement (attachments)
└─ AbstractStructuralDBElement (tree/hierarchy + parameters)
├─ AbstractPartsContainingDBElement
│ ├─ Category
│ ├─ Footprint
│ ├─ StorageLocation
│ └─ AbstractCompany (company fields)
│ ├─ Manufacturer
│ └─ Supplier
```
### After (Trait Composition):
```
Traits: Interfaces:
- DBElementTrait - DBElementInterface
- NamedElementTrait - NamedElementInterface
- TimestampTrait - TimeStampableInterface
- AttachmentsTrait - HasAttachmentsInterface
- MasterAttachmentTrait - HasMasterAttachmentInterface
- StructuralElementTrait - StructuralElementInterface
- ParametersTrait - HasParametersInterface
- CompanyTrait - CompanyInterface
Class Hierarchy (now uses traits):
AbstractDBElement (uses DBElementTrait, implements DBElementInterface)
└─ AbstractNamedDBElement (uses NamedElementTrait + TimestampTrait)
└─ AttachmentContainingDBElement (uses AttachmentsTrait + MasterAttachmentTrait)
└─ AbstractStructuralDBElement (uses StructuralElementTrait + ParametersTrait)
├─ AbstractPartsContainingDBElement
│ ├─ Category (gets all traits via inheritance)
│ ├─ Footprint (gets all traits via inheritance)
│ └─ AbstractCompany (uses CompanyTrait)
│ ├─ Manufacturer
│ └─ Supplier
```
## Changes Made
### New Traits Created
1. **DBElementTrait** (`src/Entity/Base/DBElementTrait.php`)
- Provides basic database element functionality with an ID
- Includes `getID()` method and clone helper
- Extracted from `AbstractDBElement`
2. **NamedElementTrait** (`src/Entity/Base/NamedElementTrait.php`)
- Provides named element functionality (name property and methods)
- Includes `getName()`, `setName()`, and `__toString()` methods
- Extracted from `AbstractNamedDBElement`
3. **AttachmentsTrait** (`src/Entity/Base/AttachmentsTrait.php`)
- Provides attachments collection functionality
- Includes methods for adding, removing, and getting attachments
- Includes clone helper for deep cloning attachments
- Extracted from `AttachmentContainingDBElement`
4. **StructuralElementTrait** (`src/Entity/Base/StructuralElementTrait.php`)
- Provides tree/hierarchy functionality for structural elements
- Includes parent/child relationships, path calculations, level tracking
- Includes methods like `isRoot()`, `isChildOf()`, `getFullPath()`, etc.
- Extracted from `AbstractStructuralDBElement`
5. **CompanyTrait** (`src/Entity/Base/CompanyTrait.php`)
- Provides company-specific fields (address, phone, email, website, etc.)
- Includes getters and setters for all company fields
- Extracted from `AbstractCompany`
### New Interfaces Created
1. **DBElementInterface** (`src/Entity/Contracts/DBElementInterface.php`)
- Interface for entities with a database ID
- Defines `getID()` method
2. **StructuralElementInterface** (`src/Entity/Contracts/StructuralElementInterface.php`)
- Interface for structural/hierarchical elements
- Defines methods for tree navigation and hierarchy
3. **CompanyInterface** (`src/Entity/Contracts/CompanyInterface.php`)
- Interface for company entities
- Defines basic company information accessors
4. **HasParametersInterface** (`src/Entity/Contracts/HasParametersInterface.php`)
- Interface for entities that have parameters
- Defines `getParameters()` method
### Refactored Classes
1. **AbstractDBElement**
- Now uses `DBElementTrait`
- Implements `DBElementInterface`
- Simplified to just use the trait instead of duplicating code
2. **AbstractNamedDBElement**
- Now uses `NamedElementTrait` in addition to existing `TimestampTrait`
- Cleaner implementation with trait composition
3. **AttachmentContainingDBElement**
- Now uses `AttachmentsTrait` and `MasterAttachmentTrait`
- Simplified constructor and clone methods
4. **AbstractStructuralDBElement**
- Now uses `StructuralElementTrait` and `ParametersTrait`
- Implements `StructuralElementInterface` and `HasParametersInterface`
- Much cleaner with most functionality extracted to trait
5. **AbstractCompany**
- Now uses `CompanyTrait`
- Implements `CompanyInterface`
- Significantly simplified from ~260 lines to ~20 lines
## Benefits
### 1. **Better Code Reusability**
- Traits can be reused in different contexts without requiring inheritance
- Easier to mix and match functionality
### 2. **Improved Maintainability**
- Each trait focuses on a single concern (SRP - Single Responsibility Principle)
- Easier to locate and modify specific functionality
- Reduced code duplication
### 3. **More Flexible Architecture**
- Entities can now compose functionality as needed
- Not locked into a rigid inheritance hierarchy
- Easier to add new functionality without modifying base classes
### 4. **Better Testability**
- Traits can be tested independently
- Easier to mock specific functionality
### 5. **Clearer Contracts**
- Interfaces make dependencies explicit
- Better IDE support and type hinting
## Migration Path
This refactoring is backward compatible - all existing entities continue to work as before. The changes are internal to the base classes and do not affect the public API.
### For New Entities
New entities can now:
1. Use traits directly without deep inheritance
2. Mix and match functionality as needed
3. Implement only the interfaces they need
Example:
```php
class MyCustomEntity extends AbstractDBElement implements NamedElementInterface
{
use NamedElementTrait;
// Custom functionality
}
```
## Technical Details
### Trait Usage Pattern
All traits follow this pattern:
1. Declare properties with appropriate Doctrine/validation annotations
2. Provide initialization methods (e.g., `initializeAttachments()`)
3. Provide business logic methods
4. Provide clone helpers for deep cloning when needed
### Interface Contracts
All interfaces define the minimal contract required for that functionality:
- DBElementInterface: requires `getID()`
- NamedElementInterface: requires `getName()`
- StructuralElementInterface: requires hierarchy methods
- CompanyInterface: requires company info accessors
- HasParametersInterface: requires `getParameters()`
## Future Improvements
Potential future enhancements:
1. Extract more functionality from remaining abstract classes
2. Create more granular traits for specific features
3. Add trait-specific unit tests
4. Consider creating trait-based mixins for common entity patterns

View File

@@ -1,141 +0,0 @@
# Entity Inheritance Hierarchy Refactoring - Implementation Summary
## Task Completed
Successfully decomposed the deep entity inheritance hierarchy into traits and interfaces for better architecture.
## Changes Overview
### Files Modified (5)
1. `src/Entity/Base/AbstractDBElement.php` - Now uses DBElementTrait
2. `src/Entity/Base/AbstractNamedDBElement.php` - Now uses NamedElementTrait
3. `src/Entity/Attachments/AttachmentContainingDBElement.php` - Now uses AttachmentsTrait
4. `src/Entity/Base/AbstractStructuralDBElement.php` - Now uses StructuralElementTrait
5. `src/Entity/Base/AbstractCompany.php` - Now uses CompanyTrait
### New Traits Created (5)
1. `src/Entity/Base/DBElementTrait.php` - ID management functionality
2. `src/Entity/Base/NamedElementTrait.php` - Name property and methods
3. `src/Entity/Base/AttachmentsTrait.php` - Attachment collection management
4. `src/Entity/Base/StructuralElementTrait.php` - Tree/hierarchy functionality
5. `src/Entity/Base/CompanyTrait.php` - Company-specific fields
### New Interfaces Created (4)
1. `src/Entity/Contracts/DBElementInterface.php` - Contract for DB entities
2. `src/Entity/Contracts/StructuralElementInterface.php` - Contract for hierarchical entities
3. `src/Entity/Contracts/CompanyInterface.php` - Contract for company entities
4. `src/Entity/Contracts/HasParametersInterface.php` - Contract for parametrized entities
### Documentation Added (2)
1. `ENTITY_REFACTORING.md` - Comprehensive documentation with architecture diagrams
2. `IMPLEMENTATION_SUMMARY.md` - This file
## Impact Analysis
### Code Metrics
- **Lines Added**: 1,291 (traits, interfaces, documentation)
- **Lines Removed**: 740 (from base classes)
- **Net Change**: +551 lines
- **Code Reduction in Base Classes**: ~1000 lines moved to reusable traits
### Affected Classes
All entities that extend from the modified base classes now benefit from the trait-based architecture:
- Category, Footprint, StorageLocation, MeasurementUnit, PartCustomState
- Manufacturer, Supplier
- And all other entities in the inheritance chain
### Breaking Changes
**None** - This is a backward-compatible refactoring. All public APIs remain unchanged.
## Benefits Achieved
### 1. Improved Code Reusability
- Traits can be mixed and matched in different combinations
- No longer locked into rigid inheritance hierarchy
- Easier to create new entity types with specific functionality
### 2. Better Maintainability
- Each trait has a single, well-defined responsibility
- Easier to locate and modify specific functionality
- Reduced code duplication across the codebase
### 3. Enhanced Flexibility
- Future entities can compose functionality as needed
- Can add new traits without modifying existing class hierarchy
- Supports multiple inheritance patterns via trait composition
### 4. Clearer Contracts
- Interfaces make dependencies and capabilities explicit
- Better IDE support and auto-completion
- Improved static analysis capabilities
### 5. Preserved Backward Compatibility
- All existing entities continue to work unchanged
- No modifications required to controllers, services, or repositories
- Database schema remains the same
## Testing Notes
### Validation Performed
- ✅ PHP syntax validation on all modified files
- ✅ Verified all traits can be loaded
- ✅ Code review feedback addressed
- ✅ Documentation completeness checked
### Recommended Testing
Before merging, the following tests should be run:
1. Full PHPUnit test suite
2. Static analysis (PHPStan level 5)
3. Integration tests for entities
4. Database migration tests
## Code Review Feedback Addressed
All code review comments were addressed:
1. ✅ Fixed typo: "addres" → "address"
2. ✅ Removed unnecessary comma in docstrings
3. ✅ Fixed nullable return type documentation
4. ✅ Fixed inconsistent nullable string initialization
5. ✅ Replaced isset() with direct null comparison
6. ✅ Documented trait dependencies (MasterAttachmentTrait)
7. ✅ Fixed grammar: "a most top element" → "the topmost element"
## Future Enhancements
Potential improvements for future iterations:
1. Extract more granular traits for specific features
2. Create trait-specific unit tests
3. Consider extracting validation logic into traits
4. Add more interfaces for fine-grained contracts
5. Create documentation for custom entity development
## Migration Guide for Developers
### Using Traits in New Entities
```php
// Example: Creating a new entity with specific traits
use App\Entity\Base\DBElementTrait;
use App\Entity\Base\NamedElementTrait;
use App\Entity\Contracts\DBElementInterface;
use App\Entity\Contracts\NamedElementInterface;
class MyEntity implements DBElementInterface, NamedElementInterface
{
use DBElementTrait;
use NamedElementTrait;
// Custom functionality here
}
```
### Trait Dependencies
Some traits have dependencies on other traits or methods:
- **StructuralElementTrait** requires `getName()` and `getID()` methods
- **AttachmentsTrait** works best with `MasterAttachmentTrait`
Refer to trait documentation for specific requirements.
## Conclusion
This refactoring successfully modernizes the entity architecture while maintaining full backward compatibility. The trait-based approach provides better code organization, reusability, and maintainability for the Part-DB project.

View File

@@ -1 +1 @@
2.3.0
2.2.1

1400
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
framework:
default_locale: 'en'
# Just enable the locales we need for performance reasons.
enabled_locale: '%partdb.locale_menu%'
enabled_locale: ['en', 'de', 'it', 'fr', 'ru', 'ja', 'cs', 'da', 'zh', 'pl']
translator:
default_path: '%kernel.project_dir%/translations'
fallbacks:

File diff suppressed because it is too large Load Diff

View File

@@ -33,8 +33,8 @@ services:
App\:
resource: '../src/'
exclude:
- '../src/Entity/'
- '../src/Helpers/'
- '../src/DataFixtures/'
- '../src/Doctrine/Purger/'
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
@@ -274,12 +274,21 @@ services:
tags:
- { name: monolog.processor }
App\Doctrine\Purger\ResetAutoIncrementPurgerFactory:
tags:
- { name: 'doctrine.fixtures.purger_factory', alias: 'reset_autoincrement_purger' }
when@test: &test
services:
App\DataFixtures\:
resource: '../src/DataFixtures/'
autoconfigure: true
autowire: true
App\Doctrine\Purger\:
resource: '../src/Doctrine/Purger/'
App\Doctrine\Purger\ResetAutoIncrementPurgerFactory:
tags:
- { name: 'doctrine.fixtures.purger_factory', alias: 'reset_autoincrement_purger' }
# Decorate the doctrine fixtures load command to use our custom purger by default
doctrine.fixtures_load_command.custom:
decorates: doctrine.fixtures_load_command
@@ -288,3 +297,6 @@ when@test: &test
- '@doctrine.fixtures.loader'
- '@doctrine'
- { default: '@App\Doctrine\Purger\DoNotUsePurgerFactory' }
when@dev:
*test

View File

@@ -50,21 +50,6 @@ docker-compose logs -f
Please include the error logs in your issue on GitHub, if you open an issue.
## KiCad Integration Issues
### "API responded with error code: 0: Unknown"
If you get this error when trying to connect KiCad to Part-DB, it is most likely caused by KiCad not trusting your SSL/TLS certificate.
**Cause:** KiCad does not trust self-signed SSL/TLS certificates.
**Solutions:**
- Use HTTP instead of HTTPS for the `root_url` in your KiCad library configuration (only recommended for local networks)
- Use a certificate from a trusted Certificate Authority (CA) like [Let's Encrypt](https://letsencrypt.org/)
- Add your self-signed certificate to the system's trusted certificate store on the computer running KiCad (the exact steps depend on your operating system)
For more information about KiCad integration, see the [EDA / KiCad integration](../usage/eda_integration.md) documentation.
## Report Issue
If an error occurs, or you found a bug, please [open an issue on GitHub](https://github.com/Part-DB/Part-DB-server).

View File

@@ -22,16 +22,6 @@ This also allows to configure available and usable parts and their properties in
Part-DB should be accessible from the PCs with KiCad. The URL should be stable (so no dynamically changing IP).
You require a user account in Part-DB, which has permission to access the Part-DB API and create API tokens. Every user can have their own account, or you set up a shared read-only account.
{: .warning }
> **HTTPS with Self-Signed Certificates**
>
> KiCad does not trust self-signed SSL/TLS certificates. If your Part-DB instance uses HTTPS with a self-signed certificate, KiCad will fail to connect and show an error like: `API responded with error code: 0: Unknown`.
>
> To resolve this issue, you have the following options:
> - Use HTTP instead of HTTPS for the `root_url` (only recommended for local networks)
> - Use a certificate from a trusted Certificate Authority (CA) like [Let's Encrypt](https://letsencrypt.org/)
> - Add your self-signed certificate to the system's trusted certificate store on the computer running KiCad (the exact steps depend on your operating system)
To connect KiCad with Part-DB do the following steps:
1. Create an API token on the user settings page for the KiCad application and copy/save it when it is shown. Currently, KiCad can only read the Part-DB database, so a token with a read-only scope is enough.

View File

@@ -366,14 +366,6 @@ abstract class BaseAdminController extends AbstractController
}
}
//Count how many actual new entities were created (id is null until persisted)
$created_count = 0;
foreach ($results as $result) {
if (null === $result->getID()) {
$created_count++;
}
}
//Persist valid entities to DB
foreach ($results as $result) {
$em->persist($result);
@@ -381,14 +373,8 @@ abstract class BaseAdminController extends AbstractController
$em->flush();
if (count($results) > 0) {
$this->addFlash('success', t('entity.mass_creation_flash', ['%COUNT%' => $created_count]));
$this->addFlash('success', t('entity.mass_creation_flash', ['%COUNT%' => count($results)]));
}
if (count($errors)) {
//Recreate mass creation form, so we get the updated parent list and empty lines
$mass_creation_form = $this->createForm(MassCreationForm::class, ['entity_class' => $this->entity_class]);
}
}
return $this->render($this->twig_template, [

View File

@@ -169,7 +169,7 @@ abstract class Attachment extends AbstractNamedDBElement
#[ORM\Column(type: Types::STRING, length: 2048, nullable: true)]
#[Groups(['attachment:read'])]
#[ApiProperty(example: 'http://example.com/image.jpg')]
#[Assert\Length(max: 2048)]
#[Assert\Length(2048)]
protected ?string $external_path = null;
/**

View File

@@ -24,11 +24,13 @@ namespace App\Entity\Attachments;
use App\Entity\Base\AbstractNamedDBElement;
use App\Entity\Base\MasterAttachmentTrait;
use App\Entity\Base\AttachmentsTrait;
use App\Entity\Contracts\HasAttachmentsInterface;
use App\Entity\Contracts\HasMasterAttachmentInterface;
use App\Repository\AttachmentContainingDBElementRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @template AT of Attachment
@@ -37,18 +39,83 @@ use Doctrine\ORM\Mapping as ORM;
abstract class AttachmentContainingDBElement extends AbstractNamedDBElement implements HasMasterAttachmentInterface, HasAttachmentsInterface
{
use MasterAttachmentTrait;
use AttachmentsTrait;
/**
* @var Collection<int, Attachment>
* @phpstan-var Collection<int, AT>
* ORM Mapping is done in subclasses (e.g. Part)
*/
#[Groups(['full', 'import'])]
protected Collection $attachments;
public function __construct()
{
$this->initializeAttachments();
$this->attachments = new ArrayCollection();
}
public function __clone()
{
$this->cloneAttachments();
if ($this->id) {
$attachments = $this->attachments;
$this->attachments = new ArrayCollection();
//Set master attachment is needed
foreach ($attachments as $attachment) {
$clone = clone $attachment;
if ($attachment === $this->master_picture_attachment) {
$this->setMasterPictureAttachment($clone);
}
$this->addAttachment($clone);
}
}
//Parent has to be last call, as it resets the ID
parent::__clone();
}
/********************************************************************************
*
* Getters
*
*********************************************************************************/
/**
* Gets all attachments associated with this element.
*/
public function getAttachments(): Collection
{
return $this->attachments;
}
/**
* Adds an attachment to this element.
*
* @param Attachment $attachment Attachment
*
* @return $this
*/
public function addAttachment(Attachment $attachment): self
{
//Attachment must be associated with this element
$attachment->setElement($this);
$this->attachments->add($attachment);
return $this;
}
/**
* Removes the given attachment from this element.
*
* @return $this
*/
public function removeAttachment(Attachment $attachment): self
{
$this->attachments->removeElement($attachment);
//Check if this is the master attachment -> remove it from master attachment too, or it can not be deleted from DB...
if ($attachment === $this->getMasterPictureAttachment()) {
$this->setMasterPictureAttachment(null);
}
return $this;
}
}

View File

@@ -52,14 +52,12 @@ use Symfony\Component\Validator\Constraints as Assert;
/**
* Class AttachmentType.
* @see \App\Tests\Entity\Attachments\AttachmentTypeTest
* @extends AbstractStructuralDBElement<AttachmentTypeAttachment, AttachmentTypeParameter>
*/
#[ORM\Entity(repositoryClass: StructuralDBElementRepository::class)]
#[ORM\Table(name: '`attachment_types`')]
#[ORM\Index(columns: ['name'], name: 'attachment_types_idx_name')]
#[ORM\Index(columns: ['parent_id', 'name'], name: 'attachment_types_idx_parent_name')]
#[ORM\HasLifecycleCallbacks]
#[ORM\EntityListeners([TreeCacheInvalidationListener::class])]
#[UniqueEntity(fields: ['name', 'parent'], message: 'structural.entity.unique_name', ignoreNull: false)]
#[ApiResource(
operations: [
new Get(security: 'is_granted("read", object)'),
@@ -86,16 +84,8 @@ use Symfony\Component\Validator\Constraints as Assert;
#[ApiFilter(LikeFilter::class, properties: ["name", "comment"])]
#[ApiFilter(DateFilter::class, strategy: DateFilterInterface::EXCLUDE_NULL)]
#[ApiFilter(OrderFilter::class, properties: ['name', 'id', 'addedDate', 'lastModified'])]
class AttachmentType implements DBElementInterface, NamedElementInterface, TimeStampableInterface, HasAttachmentsInterface, HasMasterAttachmentInterface, StructuralElementInterface, HasParametersInterface, \Stringable, \JsonSerializable
class AttachmentType extends AbstractStructuralDBElement
{
use DBElementTrait;
use NamedElementTrait;
use TimestampTrait;
use AttachmentsTrait;
use MasterAttachmentTrait;
use StructuralElementTrait;
use ParametersTrait;
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: AttachmentType::class, cascade: ['persist'])]
#[ORM\OrderBy(['name' => Criteria::ASC])]
protected Collection $children;
@@ -104,10 +94,7 @@ class AttachmentType implements DBElementInterface, NamedElementInterface, TimeS
#[ORM\JoinColumn(name: 'parent_id')]
#[Groups(['attachment_type:read', 'attachment_type:write'])]
#[ApiProperty(readableLink: true, writableLink: false)]
protected ?self $parent = null;
#[Groups(['attachment_type:read', 'attachment_type:write'])]
protected string $comment = '';
protected ?AbstractStructuralDBElement $parent = null;
/**
* @var string A comma separated list of file types, which are allowed for attachment files.
@@ -136,7 +123,6 @@ class AttachmentType implements DBElementInterface, NamedElementInterface, TimeS
/** @var Collection<int, AttachmentTypeParameter>
*/
#[Assert\Valid]
#[UniqueObjectCollection(fields: ['name', 'group', 'element'])]
#[ORM\OneToMany(mappedBy: 'element', targetEntity: AttachmentTypeParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
#[Groups(['attachment_type:read', 'attachment_type:write', 'import', 'full'])]
@@ -156,37 +142,13 @@ class AttachmentType implements DBElementInterface, NamedElementInterface, TimeS
public function __construct()
{
$this->initializeAttachments();
$this->initializeStructuralElement();
$this->children = new ArrayCollection();
$this->parameters = new ArrayCollection();
parent::__construct();
$this->attachments = new ArrayCollection();
$this->attachments_with_type = new ArrayCollection();
}
public function __clone()
{
if ($this->id) {
$this->cloneDBElement();
$this->cloneAttachments();
// We create a new object, so give it a new creation date
$this->addedDate = null;
//Deep clone parameters
$parameters = $this->parameters;
$this->parameters = new ArrayCollection();
foreach ($parameters as $parameter) {
$this->addParameter(clone $parameter);
}
}
}
public function jsonSerialize(): array
{
return ['@id' => $this->getID()];
}
/**
* Get all attachments ("Attachment" objects) with this type.
*

View File

@@ -24,9 +24,11 @@ namespace App\Entity\Base;
use App\Entity\Attachments\Attachment;
use App\Entity\Parameters\AbstractParameter;
use App\Entity\Contracts\CompanyInterface;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use function is_string;
use Symfony\Component\Validator\Constraints as Assert;
/**
* This abstract class is used for companies like suppliers or manufacturers.
@@ -36,15 +38,226 @@ use Symfony\Component\Serializer\Annotation\Groups;
* @extends AbstractPartsContainingDBElement<AT, PT>
*/
#[ORM\MappedSuperclass]
abstract class AbstractCompany extends AbstractPartsContainingDBElement implements CompanyInterface
abstract class AbstractCompany extends AbstractPartsContainingDBElement
{
use CompanyTrait;
#[Groups(['company:read'])]
protected ?\DateTimeImmutable $addedDate = null;
#[Groups(['company:read'])]
protected ?\DateTimeImmutable $lastModified = null;
/**
* @var string The address of the company
*/
#[Groups(['full', 'company:read', 'company:write', 'import', 'extended'])]
#[ORM\Column(type: Types::STRING)]
#[Assert\Length(max: 255)]
protected string $address = '';
/**
* @var string The phone number of the company
*/
#[Groups(['full', 'company:read', 'company:write', 'import', 'extended'])]
#[ORM\Column(type: Types::STRING)]
#[Assert\Length(max: 255)]
protected string $phone_number = '';
/**
* @var string The fax number of the company
*/
#[Groups(['full', 'company:read', 'company:write', 'import', 'extended'])]
#[ORM\Column(type: Types::STRING)]
#[Assert\Length(max: 255)]
protected string $fax_number = '';
/**
* @var string The email address of the company
*/
#[Assert\Email]
#[Groups(['full', 'company:read', 'company:write', 'import', 'extended'])]
#[ORM\Column(type: Types::STRING)]
#[Assert\Length(max: 255)]
protected string $email_address = '';
/**
* @var string The website of the company
*/
#[Assert\Url(requireTld: false)]
#[Groups(['full', 'company:read', 'company:write', 'import', 'extended'])]
#[ORM\Column(type: Types::STRING, length: 2048)]
#[Assert\Length(max: 2048)]
protected string $website = '';
#[Groups(['company:read', 'company:write', 'import', 'full', 'extended'])]
protected string $comment = '';
/**
* @var string The link to the website of an article. Use %PARTNUMBER% as placeholder for the part number.
*/
#[ORM\Column(type: Types::STRING, length: 2048)]
#[Assert\Length(max: 2048)]
#[Groups(['full', 'company:read', 'company:write', 'import', 'extended'])]
protected string $auto_product_url = '';
/********************************************************************************
*
* Getters
*
*********************************************************************************/
/**
* Get the address.
*
* @return string the address of the company (with "\n" as line break)
*/
public function getAddress(): string
{
return $this->address;
}
/**
* Get the phone number.
*
* @return string the phone number of the company
*/
public function getPhoneNumber(): string
{
return $this->phone_number;
}
/**
* Get the fax number.
*
* @return string the fax number of the company
*/
public function getFaxNumber(): string
{
return $this->fax_number;
}
/**
* Get the e-mail address.
*
* @return string the e-mail address of the company
*/
public function getEmailAddress(): string
{
return $this->email_address;
}
/**
* Get the website.
*
* @return string the website of the company
*/
public function getWebsite(): string
{
return $this->website;
}
/**
* Get the link to the website of an article.
*
* @param string|null $partnr * NULL for returning the URL with a placeholder for the part number
* * or the part number for returning the direct URL to the article
*
* @return string the link to the article
*/
public function getAutoProductUrl(?string $partnr = null): string
{
if (is_string($partnr)) {
return str_replace('%PARTNUMBER%', $partnr, $this->auto_product_url);
}
return $this->auto_product_url;
}
/********************************************************************************
*
* Setters
*
*********************************************************************************/
/**
* Set the addres.
*
* @param string $new_address the new address (with "\n" as line break)
*
* @return $this
*/
public function setAddress(string $new_address): self
{
$this->address = $new_address;
return $this;
}
/**
* Set the phone number.
*
* @param string $new_phone_number the new phone number
*
* @return $this
*/
public function setPhoneNumber(string $new_phone_number): self
{
$this->phone_number = $new_phone_number;
return $this;
}
/**
* Set the fax number.
*
* @param string $new_fax_number the new fax number
*
* @return $this
*/
public function setFaxNumber(string $new_fax_number): self
{
$this->fax_number = $new_fax_number;
return $this;
}
/**
* Set the e-mail address.
*
* @param string $new_email_address the new e-mail address
*
* @return $this
*/
public function setEmailAddress(string $new_email_address): self
{
$this->email_address = $new_email_address;
return $this;
}
/**
* Set the website.
*
* @param string $new_website the new website
*
* @return $this
*/
public function setWebsite(string $new_website): self
{
$this->website = $new_website;
return $this;
}
/**
* Set the link to the website of an article.
*
* @param string $new_url the new URL with the placeholder %PARTNUMBER% for the part number
*
* @return $this
*/
public function setAutoProductUrl(string $new_url): self
{
$this->auto_product_url = $new_url;
return $this;
}
}

View File

@@ -38,7 +38,6 @@ use App\Entity\Attachments\ProjectAttachment;
use App\Entity\Attachments\StorageLocationAttachment;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Attachments\UserAttachment;
use App\Entity\Contracts\DBElementInterface;
use App\Entity\Parameters\AbstractParameter;
use App\Entity\Parts\Category;
use App\Entity\PriceInformations\Pricedetail;
@@ -57,9 +56,11 @@ use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Supplier;
use App\Entity\UserSystem\User;
use App\Repository\DBElementRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* This class is for managing all database objects.
@@ -105,13 +106,36 @@ use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
'user' => User::class]
)]
#[ORM\MappedSuperclass(repositoryClass: DBElementRepository::class)]
abstract class AbstractDBElement implements JsonSerializable, DBElementInterface
abstract class AbstractDBElement implements JsonSerializable
{
use DBElementTrait;
/** @var int|null The Identification number for this part. This value is unique for the element in this table.
* Null if the element is not saved to DB yet.
*/
#[Groups(['full', 'api:basic:read'])]
#[ORM\Column(type: Types::INTEGER)]
#[ORM\Id]
#[ORM\GeneratedValue]
protected ?int $id = null;
public function __clone()
{
$this->cloneDBElement();
if ($this->id) {
//Set ID to null, so that an new entry is created
$this->id = null;
}
}
/**
* Get the ID. The ID can be zero, or even negative (for virtual elements). If an element is virtual, can be
* checked with isVirtualElement().
*
* Returns null, if the element is not saved to the DB yet.
*
* @return int|null the ID of this element
*/
public function getID(): ?int
{
return $this->id;
}
public function jsonSerialize(): array

View File

@@ -23,9 +23,12 @@ declare(strict_types=1);
namespace App\Entity\Base;
use App\Repository\NamedDBElementRepository;
use Doctrine\DBAL\Types\Types;
use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Contracts\TimeStampableInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* All subclasses of this class have an attribute "name".
@@ -35,7 +38,26 @@ use Doctrine\ORM\Mapping as ORM;
abstract class AbstractNamedDBElement extends AbstractDBElement implements NamedElementInterface, TimeStampableInterface, \Stringable
{
use TimestampTrait;
use NamedElementTrait;
/**
* @var string The name of this element
*/
#[Assert\NotBlank]
#[Groups(['simple', 'extended', 'full', 'import', 'api:basic:read', 'api:basic:write'])]
#[ORM\Column(type: Types::STRING)]
#[Assert\Length(max: 255)]
protected string $name = '';
/******************************************************************************
*
* Helpers
*
******************************************************************************/
public function __toString(): string
{
return $this->getName();
}
public function __clone()
{
@@ -43,6 +65,40 @@ abstract class AbstractNamedDBElement extends AbstractDBElement implements Named
//We create a new object, so give it a new creation date
$this->addedDate = null;
}
parent::__clone();
parent::__clone(); // TODO: Change the autogenerated stub
}
/********************************************************************************
*
* Getters
*
*********************************************************************************/
/**
* Get the name of this element.
*
* @return string the name of this element
*/
public function getName(): string
{
return $this->name;
}
/********************************************************************************
*
* Setters
*
*********************************************************************************/
/**
* Change the name of this element.
*
* @param string $new_name the new name
*/
public function setName(string $new_name): self
{
$this->name = $new_name;
return $this;
}
}

View File

@@ -24,18 +24,22 @@ namespace App\Entity\Base;
use App\Entity\Attachments\Attachment;
use App\Entity\Parameters\AbstractParameter;
use App\Entity\Contracts\StructuralElementInterface;
use App\Entity\Contracts\HasParametersInterface;
use App\Repository\StructuralDBElementRepository;
use App\EntityListeners\TreeCacheInvalidationListener;
use App\Validator\Constraints\UniqueObjectCollection;
use Doctrine\DBAL\Types\Types;
use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Parameters\ParametersTrait;
use App\Validator\Constraints\NoneOfItsChildren;
use Symfony\Component\Serializer\Annotation\SerializedName;
use Symfony\Component\Validator\Constraints as Assert;
use function count;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* All elements with the fields "id", "name" and "parent_id" (at least).
@@ -58,10 +62,52 @@ use Symfony\Component\Validator\Constraints as Assert;
#[UniqueEntity(fields: ['name', 'parent'], message: 'structural.entity.unique_name', ignoreNull: false)]
#[ORM\MappedSuperclass(repositoryClass: StructuralDBElementRepository::class)]
#[ORM\EntityListeners([TreeCacheInvalidationListener::class])]
abstract class AbstractStructuralDBElement extends AttachmentContainingDBElement implements StructuralElementInterface, HasParametersInterface
abstract class AbstractStructuralDBElement extends AttachmentContainingDBElement
{
use ParametersTrait;
use StructuralElementTrait;
/**
* This is a not standard character, so build a const, so a dev can easily use it.
*/
final public const PATH_DELIMITER_ARROW = ' → ';
/**
* @var string The comment info for this element as markdown
*/
#[Groups(['full', 'import'])]
#[ORM\Column(type: Types::TEXT)]
protected string $comment = '';
/**
* @var bool If this property is set, this element can not be selected for part properties.
* Useful if this element should be used only for grouping, sorting.
*/
#[Groups(['full', 'import'])]
#[ORM\Column(type: Types::BOOLEAN)]
protected bool $not_selectable = false;
/**
* @var int
*/
protected int $level = 0;
/**
* We can not define the mapping here, or we will get an exception. Unfortunately we have to do the mapping in the
* subclasses.
*
* @var Collection<int, AbstractStructuralDBElement>
* @phpstan-var Collection<int, static>
*/
#[Groups(['include_children'])]
protected Collection $children;
/**
* @var AbstractStructuralDBElement|null
* @phpstan-var static|null
*/
#[Groups(['include_parents', 'import'])]
#[NoneOfItsChildren]
protected ?AbstractStructuralDBElement $parent = null;
/**
* Mapping done in subclasses.
@@ -73,10 +119,21 @@ abstract class AbstractStructuralDBElement extends AttachmentContainingDBElement
#[UniqueObjectCollection(fields: ['name', 'group', 'element'])]
protected Collection $parameters;
/** @var string[] all names of all parent elements as an array of strings,
* the last array element is the name of the element itself
*/
private array $full_path_strings = [];
/**
* Alternative names (semicolon-separated) for this element, which can be used for searching (especially for info provider system)
*/
#[ORM\Column(type: Types::TEXT, nullable: true, options: ['default' => null])]
private ?string $alternative_names = "";
public function __construct()
{
parent::__construct();
$this->initializeStructuralElement();
$this->children = new ArrayCollection();
$this->parameters = new ArrayCollection();
}
@@ -92,4 +149,307 @@ abstract class AbstractStructuralDBElement extends AttachmentContainingDBElement
}
parent::__clone();
}
/******************************************************************************
* StructuralDBElement constructor.
*****************************************************************************/
/**
* Check if this element is a child of another element (recursive).
*
* @param AbstractStructuralDBElement $another_element the object to compare
* IMPORTANT: both objects to compare must be from the same class (for example two "Device" objects)!
*
* @return bool true, if this element is child of $another_element
*
* @throws InvalidArgumentException if there was an error
*/
public function isChildOf(self $another_element): bool
{
$class_name = static::class;
//Check if both elements compared, are from the same type
// (we have to check inheritance, or we get exceptions when using doctrine entities (they have a proxy type):
if (!$another_element instanceof $class_name && !is_a($this, $another_element::class)) {
throw new InvalidArgumentException('isChildOf() only works for objects of the same type!');
}
if (!$this->getParent() instanceof self) { // this is the root node
return false;
}
//If the parent element is equal to the element we want to compare, return true
if ($this->getParent()->getID() === null) {
//If the IDs are not yet defined, we have to compare the objects itself
if ($this->getParent() === $another_element) {
return true;
}
} elseif ($this->getParent()->getID() === $another_element->getID()) {
return true;
}
//Otherwise, check recursively
return $this->parent->isChildOf($another_element);
}
/**
* Checks if this element is an root element (has no parent).
*
* @return bool true if this element is a root element
*/
public function isRoot(): bool
{
return $this->parent === null;
}
/******************************************************************************
*
* Getters
*
******************************************************************************/
/**
* Get the parent of this element.
*
* @return static|null The parent element. Null if this element, does not have a parent.
*/
public function getParent(): ?self
{
return $this->parent;
}
/**
* Get the comment of the element as markdown encoded string.
*
* @return string the comment
*/
public function getComment(): ?string
{
return $this->comment;
}
/**
* Get the level.
*
* The level of the root node is -1.
*
* @return int the level of this element (zero means a most top element
* [a sub element of the root node])
*/
public function getLevel(): int
{
/*
* Only check for nodes that have a parent. In the other cases zero is correct.
*/
if (0 === $this->level && $this->parent instanceof self) {
$element = $this->parent;
while ($element instanceof self) {
/** @var AbstractStructuralDBElement $element */
$element = $element->parent;
++$this->level;
}
}
return $this->level;
}
/**
* Get the full path.
*
* @param string $delimiter the delimiter of the returned string
*
* @return string the full path (incl. the name of this element), delimited by $delimiter
*/
#[Groups(['api:basic:read'])]
#[SerializedName('full_path')]
public function getFullPath(string $delimiter = self::PATH_DELIMITER_ARROW): string
{
if ($this->full_path_strings === []) {
$this->full_path_strings = [];
$this->full_path_strings[] = $this->getName();
$element = $this;
$overflow = 20; //We only allow 20 levels depth
while ($element->parent instanceof self && $overflow >= 0) {
$element = $element->parent;
$this->full_path_strings[] = $element->getName();
//Decrement to prevent mem overflow.
--$overflow;
}
$this->full_path_strings = array_reverse($this->full_path_strings);
}
return implode($delimiter, $this->full_path_strings);
}
/**
* Gets the path to this element (including the element itself).
*
* @return self[] An array with all (recursively) parent elements (including this one),
* ordered from the lowest levels (root node) first to the highest level (the element itself)
*/
public function getPathArray(): array
{
$tmp = [];
$tmp[] = $this;
//We only allow 20 levels depth
while (!end($tmp)->isRoot() && count($tmp) < 20) {
$tmp[] = end($tmp)->parent;
}
return array_reverse($tmp);
}
/**
* Get all sub elements of this element.
*
* @return Collection<static>|iterable all subelements as an array of objects (sorted by their full path)
* @psalm-return Collection<int, static>
*/
public function getSubelements(): iterable
{
//If the parent is equal to this object, we would get an endless loop, so just return an empty array
//This is just a workaround, as validator should prevent this behaviour, before it gets written to the database
if ($this->parent === $this) {
return new ArrayCollection();
}
//@phpstan-ignore-next-line
return $this->children ?? new ArrayCollection();
}
/**
* @see getSubelements()
* @return Collection<static>|iterable
* @psalm-return Collection<int, static>
*/
public function getChildren(): iterable
{
return $this->getSubelements();
}
public function isNotSelectable(): bool
{
return $this->not_selectable;
}
/******************************************************************************
*
* Setters
*
******************************************************************************/
/**
* Sets the new parent object.
*
* @param static|null $new_parent The new parent object
* @return $this
*/
public function setParent(?self $new_parent): self
{
/*
if ($new_parent->isChildOf($this)) {
throw new \InvalidArgumentException('You can not use one of the element childs as parent!');
} */
$this->parent = $new_parent;
//Add this element as child to the new parent
if ($new_parent instanceof self) {
$new_parent->getChildren()->add($this);
}
return $this;
}
/**
* Set the comment.
*
* @param string $new_comment the new comment
*
* @return $this
*/
public function setComment(string $new_comment): self
{
$this->comment = $new_comment;
return $this;
}
/**
* Adds the given element as child to this element.
* @param static $child
* @return $this
*/
public function addChild(self $child): self
{
$this->children->add($child);
//Children get this element as parent
$child->setParent($this);
return $this;
}
/**
* Removes the given element as child from this element.
* @param static $child
* @return $this
*/
public function removeChild(self $child): self
{
$this->children->removeElement($child);
//Children has no parent anymore
$child->setParent(null);
return $this;
}
/**
* @return AbstractStructuralDBElement
*/
public function setNotSelectable(bool $not_selectable): self
{
$this->not_selectable = $not_selectable;
return $this;
}
public function clearChildren(): self
{
$this->children = new ArrayCollection();
return $this;
}
/**
* Returns a comma separated list of alternative names.
* @return string|null
*/
public function getAlternativeNames(): ?string
{
if ($this->alternative_names === null) {
return null;
}
//Remove trailing comma
return rtrim($this->alternative_names, ',');
}
/**
* Sets a comma separated list of alternative names.
* @return $this
*/
public function setAlternativeNames(?string $new_value): self
{
//Add a trailing comma, if not already there (makes it easier to find in the database)
if (is_string($new_value) && !str_ends_with($new_value, ',')) {
$new_value .= ',';
}
$this->alternative_names = $new_value;
return $this;
}
}

View File

@@ -1,118 +0,0 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Entity\Base;
use App\Entity\Attachments\Attachment;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* Trait providing attachments functionality.
*
* Requirements:
* - Class using this trait should have $id property (e.g., via DBElementTrait)
* - Class using this trait should use MasterAttachmentTrait for full functionality
* - Class should implement HasAttachmentsInterface
*
* Note: This trait has an optional dependency on MasterAttachmentTrait.
* If MasterAttachmentTrait is used, the removeAttachment and cloneAttachments methods
* will handle master picture attachment properly. Otherwise, those checks are no-ops.
*/
trait AttachmentsTrait
{
/**
* @var Collection<int, Attachment>
* ORM Mapping is done in subclasses (e.g. Part)
*/
#[Groups(['full', 'import'])]
protected Collection $attachments;
/**
* Initialize the attachments collection.
*/
protected function initializeAttachments(): void
{
$this->attachments = new ArrayCollection();
}
/**
* Gets all attachments associated with this element.
*/
public function getAttachments(): Collection
{
return $this->attachments;
}
/**
* Adds an attachment to this element.
*
* @param Attachment $attachment Attachment
*
* @return $this
*/
public function addAttachment(Attachment $attachment): self
{
//Attachment must be associated with this element
$attachment->setElement($this);
$this->attachments->add($attachment);
return $this;
}
/**
* Removes the given attachment from this element.
*
* @return $this
*/
public function removeAttachment(Attachment $attachment): self
{
$this->attachments->removeElement($attachment);
//Check if this is the master attachment -> remove it from master attachment too, or it can not be deleted from DB...
if ($this->master_picture_attachment !== null && $attachment === $this->master_picture_attachment) {
$this->setMasterPictureAttachment(null);
}
return $this;
}
/**
* Clone helper for attachments - deep clones all attachments.
*/
protected function cloneAttachments(): void
{
if (isset($this->id) && $this->id) {
$attachments = $this->attachments;
$this->attachments = new ArrayCollection();
//Set master attachment is needed
foreach ($attachments as $attachment) {
$clone = clone $attachment;
if ($this->master_picture_attachment !== null && $attachment === $this->master_picture_attachment) {
$this->setMasterPictureAttachment($clone);
}
$this->addAttachment($clone);
}
}
}
}

View File

@@ -1,236 +0,0 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Entity\Base;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use function is_string;
/**
* Trait for company-specific fields like address, phone, email, etc.
*/
trait CompanyTrait
{
/**
* @var string The address of the company
*/
#[Groups(['full', 'company:read', 'company:write', 'import', 'extended'])]
#[ORM\Column(type: Types::STRING)]
#[Assert\Length(max: 255)]
protected string $address = '';
/**
* @var string The phone number of the company
*/
#[Groups(['full', 'company:read', 'company:write', 'import', 'extended'])]
#[ORM\Column(type: Types::STRING)]
#[Assert\Length(max: 255)]
protected string $phone_number = '';
/**
* @var string The fax number of the company
*/
#[Groups(['full', 'company:read', 'company:write', 'import', 'extended'])]
#[ORM\Column(type: Types::STRING)]
#[Assert\Length(max: 255)]
protected string $fax_number = '';
/**
* @var string The email address of the company
*/
#[Assert\Email]
#[Groups(['full', 'company:read', 'company:write', 'import', 'extended'])]
#[ORM\Column(type: Types::STRING)]
#[Assert\Length(max: 255)]
protected string $email_address = '';
/**
* @var string The website of the company
*/
#[Assert\Url(requireTld: false)]
#[Groups(['full', 'company:read', 'company:write', 'import', 'extended'])]
#[ORM\Column(type: Types::STRING, length: 2048)]
#[Assert\Length(max: 2048)]
protected string $website = '';
/**
* @var string The link to the website of an article. Use %PARTNUMBER% as placeholder for the part number.
*/
#[ORM\Column(type: Types::STRING, length: 2048)]
#[Assert\Length(max: 2048)]
#[Groups(['full', 'company:read', 'company:write', 'import', 'extended'])]
protected string $auto_product_url = '';
/**
* Get the address.
*
* @return string the address of the company (with "\n" as line break)
*/
public function getAddress(): string
{
return $this->address;
}
/**
* Set the address.
*
* @param string $new_address the new address (with "\n" as line break)
*
* @return $this
*/
public function setAddress(string $new_address): self
{
$this->address = $new_address;
return $this;
}
/**
* Get the phone number.
*
* @return string the phone number of the company
*/
public function getPhoneNumber(): string
{
return $this->phone_number;
}
/**
* Set the phone number.
*
* @param string $new_phone_number the new phone number
*
* @return $this
*/
public function setPhoneNumber(string $new_phone_number): self
{
$this->phone_number = $new_phone_number;
return $this;
}
/**
* Get the fax number.
*
* @return string the fax number of the company
*/
public function getFaxNumber(): string
{
return $this->fax_number;
}
/**
* Set the fax number.
*
* @param string $new_fax_number the new fax number
*
* @return $this
*/
public function setFaxNumber(string $new_fax_number): self
{
$this->fax_number = $new_fax_number;
return $this;
}
/**
* Get the e-mail address.
*
* @return string the e-mail address of the company
*/
public function getEmailAddress(): string
{
return $this->email_address;
}
/**
* Set the e-mail address.
*
* @param string $new_email_address the new e-mail address
*
* @return $this
*/
public function setEmailAddress(string $new_email_address): self
{
$this->email_address = $new_email_address;
return $this;
}
/**
* Get the website.
*
* @return string the website of the company
*/
public function getWebsite(): string
{
return $this->website;
}
/**
* Set the website.
*
* @param string $new_website the new website
*
* @return $this
*/
public function setWebsite(string $new_website): self
{
$this->website = $new_website;
return $this;
}
/**
* Get the link to the website of an article.
*
* @param string|null $partnr * NULL for returning the URL with a placeholder for the part number
* * or the part number for returning the direct URL to the article
*
* @return string the link to the article
*/
public function getAutoProductUrl(?string $partnr = null): string
{
if (is_string($partnr)) {
return str_replace('%PARTNUMBER%', $partnr, $this->auto_product_url);
}
return $this->auto_product_url;
}
/**
* Set the link to the website of an article.
*
* @param string $new_url the new URL with the placeholder %PARTNUMBER% for the part number
*
* @return $this
*/
public function setAutoProductUrl(string $new_url): self
{
$this->auto_product_url = $new_url;
return $this;
}
}

View File

@@ -1,67 +0,0 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Entity\Base;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* Trait providing basic database element functionality with an ID.
*/
trait DBElementTrait
{
/**
* @var int|null The Identification number for this element. This value is unique for the element in this table.
* Null if the element is not saved to DB yet.
*/
#[Groups(['full', 'api:basic:read'])]
#[ORM\Column(type: Types::INTEGER)]
#[ORM\Id]
#[ORM\GeneratedValue]
protected ?int $id = null;
/**
* Get the ID. The ID can be zero, or even negative (for virtual elements). If an element is virtual, can be
* checked with isVirtualElement().
*
* Returns null, if the element is not saved to the DB yet.
*
* @return int|null the ID of this element
*/
public function getID(): ?int
{
return $this->id;
}
/**
* Clone helper for DB element - resets ID on clone.
*/
protected function cloneDBElement(): void
{
if ($this->id) {
//Set ID to null, so that a new entry is created
$this->id = null;
}
}
}

View File

@@ -1,73 +0,0 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Entity\Base;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Trait providing named element functionality.
*/
trait NamedElementTrait
{
/**
* @var string The name of this element
*/
#[Assert\NotBlank]
#[Groups(['simple', 'extended', 'full', 'import', 'api:basic:read', 'api:basic:write'])]
#[ORM\Column(type: Types::STRING)]
#[Assert\Length(max: 255)]
protected string $name = '';
/**
* Get the name of this element.
*
* @return string the name of this element
*/
public function getName(): string
{
return $this->name;
}
/**
* Change the name of this element.
*
* @param string $new_name the new name
*/
public function setName(string $new_name): self
{
$this->name = $new_name;
return $this;
}
/**
* String representation returns the name.
*/
public function __toString(): string
{
return $this->getName();
}
}

View File

@@ -1,381 +0,0 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Entity\Base;
use App\Validator\Constraints\NoneOfItsChildren;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
use function count;
/**
* Trait for structural/hierarchical elements forming a tree structure.
*
* Requirements:
* - Class using this trait must have getName() method (e.g., via NamedElementTrait)
* - Class using this trait must have getID() method (e.g., via DBElementTrait)
* - Class should implement StructuralElementInterface
*/
trait StructuralElementTrait
{
/**
* This is a not standard character, so build a const, so a dev can easily use it.
*/
final public const PATH_DELIMITER_ARROW = ' → ';
/**
* @var string The comment info for this element as markdown
*/
#[Groups(['full', 'import'])]
#[ORM\Column(type: Types::TEXT)]
protected string $comment = '';
/**
* @var bool If this property is set, this element can not be selected for part properties.
* Useful if this element should be used only for grouping, sorting.
*/
#[Groups(['full', 'import'])]
#[ORM\Column(type: Types::BOOLEAN)]
protected bool $not_selectable = false;
/**
* @var int
*/
protected int $level = 0;
/**
* We can not define the mapping here, or we will get an exception. Unfortunately we have to do the mapping in the
* subclasses.
*
* @var Collection<int, static>
*/
#[Groups(['include_children'])]
protected Collection $children;
/**
* @var static|null
*/
#[Groups(['include_parents', 'import'])]
#[NoneOfItsChildren]
protected ?self $parent = null;
/** @var string[] all names of all parent elements as an array of strings,
* the last array element is the name of the element itself
*/
private array $full_path_strings = [];
/**
* Alternative names (semicolon-separated) for this element, which can be used for searching (especially for info provider system)
*/
#[ORM\Column(type: Types::TEXT, nullable: true, options: ['default' => null])]
private ?string $alternative_names = '';
/**
* Initialize structural element collections.
*/
protected function initializeStructuralElement(): void
{
$this->children = new ArrayCollection();
}
/**
* Check if this element is a child of another element (recursive).
*
* @param self $another_element the object to compare
* IMPORTANT: both objects to compare must be from the same class (for example two "Device" objects)!
*
* @return bool true, if this element is child of $another_element
*
* @throws InvalidArgumentException if there was an error
*/
public function isChildOf(self $another_element): bool
{
$class_name = static::class;
//Check if both elements compared, are from the same type
// (we have to check inheritance, or we get exceptions when using doctrine entities (they have a proxy type):
if (!$another_element instanceof $class_name && !is_a($this, $another_element::class)) {
throw new InvalidArgumentException('isChildOf() only works for objects of the same type!');
}
if (!$this->getParent() instanceof self) { // this is the root node
return false;
}
//If the parent element is equal to the element we want to compare, return true
if ($this->getParent()->getID() === null) {
//If the IDs are not yet defined, we have to compare the objects itself
if ($this->getParent() === $another_element) {
return true;
}
} elseif ($this->getParent()->getID() === $another_element->getID()) {
return true;
}
//Otherwise, check recursively
return $this->parent->isChildOf($another_element);
}
/**
* Checks if this element is a root element (has no parent).
*
* @return bool true if this element is a root element
*/
public function isRoot(): bool
{
return $this->parent === null;
}
/**
* Get the parent of this element.
*
* @return static|null The parent element. Null if this element does not have a parent.
*/
public function getParent(): ?self
{
return $this->parent;
}
/**
* Get the comment of the element as markdown encoded string.
*
* @return string|null the comment
*/
public function getComment(): ?string
{
return $this->comment;
}
/**
* Set the comment.
*
* @param string $new_comment the new comment
*
* @return $this
*/
public function setComment(string $new_comment): self
{
$this->comment = $new_comment;
return $this;
}
/**
* Get the level.
*
* The level of the root node is -1.
*
* @return int the level of this element (zero means the topmost element
* [a sub element of the root node])
*/
public function getLevel(): int
{
/*
* Only check for nodes that have a parent. In the other cases zero is correct.
*/
if (0 === $this->level && $this->parent instanceof self) {
$element = $this->parent;
while ($element instanceof self) {
$element = $element->parent;
++$this->level;
}
}
return $this->level;
}
/**
* Get the full path.
*
* @param string $delimiter the delimiter of the returned string
*
* @return string the full path (incl. the name of this element), delimited by $delimiter
*/
#[Groups(['api:basic:read'])]
#[SerializedName('full_path')]
public function getFullPath(string $delimiter = self::PATH_DELIMITER_ARROW): string
{
if ($this->full_path_strings === []) {
$this->full_path_strings = [];
$this->full_path_strings[] = $this->getName();
$element = $this;
$overflow = 20; //We only allow 20 levels depth
while ($element->parent instanceof self && $overflow >= 0) {
$element = $element->parent;
$this->full_path_strings[] = $element->getName();
//Decrement to prevent mem overflow.
--$overflow;
}
$this->full_path_strings = array_reverse($this->full_path_strings);
}
return implode($delimiter, $this->full_path_strings);
}
/**
* Gets the path to this element (including the element itself).
*
* @return self[] An array with all (recursively) parent elements (including this one),
* ordered from the lowest levels (root node) first to the highest level (the element itself)
*/
public function getPathArray(): array
{
$tmp = [];
$tmp[] = $this;
//We only allow 20 levels depth
while (!end($tmp)->isRoot() && count($tmp) < 20) {
$tmp[] = end($tmp)->parent;
}
return array_reverse($tmp);
}
/**
* Get all sub elements of this element.
*
* @return Collection<static>|iterable all subelements as an array of objects (sorted by their full path)
*/
public function getSubelements(): iterable
{
//If the parent is equal to this object, we would get an endless loop, so just return an empty array
//This is just a workaround, as validator should prevent this behaviour, before it gets written to the database
if ($this->parent === $this) {
return new ArrayCollection();
}
return $this->children ?? new ArrayCollection();
}
/**
* @see getSubelements()
* @return Collection<static>|iterable
*/
public function getChildren(): iterable
{
return $this->getSubelements();
}
/**
* Sets the new parent object.
*
* @param static|null $new_parent The new parent object
* @return $this
*/
public function setParent(?self $new_parent): self
{
$this->parent = $new_parent;
//Add this element as child to the new parent
if ($new_parent instanceof self) {
$new_parent->getChildren()->add($this);
}
return $this;
}
/**
* Adds the given element as child to this element.
* @param static $child
* @return $this
*/
public function addChild(self $child): self
{
$this->children->add($child);
//Children get this element as parent
$child->setParent($this);
return $this;
}
/**
* Removes the given element as child from this element.
* @param static $child
* @return $this
*/
public function removeChild(self $child): self
{
$this->children->removeElement($child);
//Children has no parent anymore
$child->setParent(null);
return $this;
}
public function isNotSelectable(): bool
{
return $this->not_selectable;
}
/**
* @return $this
*/
public function setNotSelectable(bool $not_selectable): self
{
$this->not_selectable = $not_selectable;
return $this;
}
public function clearChildren(): self
{
$this->children = new ArrayCollection();
return $this;
}
/**
* Returns a comma separated list of alternative names.
* @return string|null
*/
public function getAlternativeNames(): ?string
{
if ($this->alternative_names === null) {
return null;
}
//Remove trailing comma
return rtrim($this->alternative_names, ',');
}
/**
* Sets a comma separated list of alternative names.
* @return $this
*/
public function setAlternativeNames(?string $new_value): self
{
//Add a trailing comma, if not already there (makes it easier to find in the database)
if (is_string($new_value) && !str_ends_with($new_value, ',')) {
$new_value .= ',';
}
$this->alternative_names = $new_value;
return $this;
}
}

View File

@@ -1,57 +0,0 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Entity\Contracts;
/**
* Interface for company entities (suppliers, manufacturers).
*/
interface CompanyInterface
{
/**
* Get the address.
*
* @return string the address of the company (with "\n" as line break)
*/
public function getAddress(): string;
/**
* Get the phone number.
*
* @return string the phone number of the company
*/
public function getPhoneNumber(): string;
/**
* Get the e-mail address.
*
* @return string the e-mail address of the company
*/
public function getEmailAddress(): string;
/**
* Get the website.
*
* @return string the website of the company
*/
public function getWebsite(): string;
}

View File

@@ -1,38 +0,0 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Entity\Contracts;
/**
* Interface for entities that have a database ID.
*/
interface DBElementInterface
{
/**
* Get the ID. The ID can be zero, or even negative (for virtual elements).
*
* Returns null, if the element is not saved to the DB yet.
*
* @return int|null the ID of this element
*/
public function getID(): ?int;
}

View File

@@ -1,38 +0,0 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Entity\Contracts;
use Doctrine\Common\Collections\Collection;
/**
* Interface for entities that have parameters.
*/
interface HasParametersInterface
{
/**
* Return all associated parameters.
*
* @return Collection
*/
public function getParameters(): Collection;
}

View File

@@ -1,70 +0,0 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Entity\Contracts;
use Doctrine\Common\Collections\Collection;
/**
* Interface for structural elements that form a tree hierarchy.
*/
interface StructuralElementInterface
{
/**
* Get the parent of this element.
*
* @return static|null The parent element. Null if this element does not have a parent.
*/
public function getParent(): ?self;
/**
* Get all sub elements of this element.
*
* @return Collection<static>|iterable all subelements
*/
public function getChildren(): iterable;
/**
* Checks if this element is a root element (has no parent).
*
* @return bool true if this element is a root element
*/
public function isRoot(): bool;
/**
* Get the full path.
*
* @param string $delimiter the delimiter of the returned string
*
* @return string the full path (incl. the name of this element), delimited by $delimiter
*/
public function getFullPath(string $delimiter = ' → '): string;
/**
* Get the level.
*
* The level of the root node is -1.
*
* @return int the level of this element (zero means the topmost element)
*/
public function getLevel(): int;
}

View File

@@ -39,44 +39,28 @@ use ApiPlatform\OpenApi\Model\Operation;
use ApiPlatform\Serializer\Filter\PropertyFilter;
use App\ApiPlatform\Filter\LikeFilter;
use App\Entity\Attachments\Attachment;
use App\Entity\Base\AttachmentsTrait;
use App\Entity\Base\DBElementTrait;
use App\Entity\Base\MasterAttachmentTrait;
use App\Entity\Base\NamedElementTrait;
use App\Entity\Base\StructuralElementTrait;
use App\Entity\Base\TimestampTrait;
use App\Entity\Contracts\DBElementInterface;
use App\Entity\Contracts\HasAttachmentsInterface;
use App\Entity\Contracts\HasMasterAttachmentInterface;
use App\Entity\Contracts\HasParametersInterface;
use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Contracts\StructuralElementInterface;
use App\Entity\Contracts\TimeStampableInterface;
use App\Entity\EDA\EDACategoryInfo;
use App\Entity\Parameters\ParametersTrait;
use App\EntityListeners\TreeCacheInvalidationListener;
use App\Repository\Parts\CategoryRepository;
use App\Validator\Constraints\UniqueObjectCollection;
use Doctrine\DBAL\Types\Types;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Attachments\CategoryAttachment;
use App\Entity\Base\AbstractPartsContainingDBElement;
use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\Parameters\CategoryParameter;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* This entity describes a category, a part can belong to, which is used to group parts by their function.
*
* @extends AbstractPartsContainingDBElement<CategoryAttachment, CategoryParameter>
*/
#[ORM\Entity(repositoryClass: CategoryRepository::class)]
#[ORM\Table(name: '`categories`')]
#[ORM\Index(columns: ['name'], name: 'category_idx_name')]
#[ORM\Index(columns: ['parent_id', 'name'], name: 'category_idx_parent_name')]
#[ORM\HasLifecycleCallbacks]
#[ORM\EntityListeners([TreeCacheInvalidationListener::class])]
#[UniqueEntity(fields: ['name', 'parent'], message: 'structural.entity.unique_name', ignoreNull: false)]
#[ApiResource(
operations: [
new Get(security: 'is_granted("read", object)'),
@@ -105,16 +89,8 @@ use Symfony\Component\Validator\Constraints as Assert;
#[ApiFilter(LikeFilter::class, properties: ["name", "comment"])]
#[ApiFilter(DateFilter::class, strategy: DateFilterInterface::EXCLUDE_NULL)]
#[ApiFilter(OrderFilter::class, properties: ['name', 'id', 'addedDate', 'lastModified'])]
class Category implements DBElementInterface, NamedElementInterface, TimeStampableInterface, HasAttachmentsInterface, HasMasterAttachmentInterface, StructuralElementInterface, HasParametersInterface, \Stringable, \JsonSerializable
class Category extends AbstractPartsContainingDBElement
{
use DBElementTrait;
use NamedElementTrait;
use TimestampTrait;
use AttachmentsTrait;
use MasterAttachmentTrait;
use StructuralElementTrait;
use ParametersTrait;
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
#[ORM\OrderBy(['name' => Criteria::ASC])]
protected Collection $children;
@@ -123,7 +99,7 @@ class Category implements DBElementInterface, NamedElementInterface, TimeStampab
#[ORM\JoinColumn(name: 'parent_id')]
#[Groups(['category:read', 'category:write'])]
#[ApiProperty(readableLink: false, writableLink: false)]
protected ?self $parent = null;
protected ?AbstractStructuralDBElement $parent = null;
#[Groups(['category:read', 'category:write'])]
protected string $comment = '';
@@ -208,7 +184,6 @@ class Category implements DBElementInterface, NamedElementInterface, TimeStampab
/** @var Collection<int, CategoryParameter>
*/
#[Assert\Valid]
#[UniqueObjectCollection(fields: ['name', 'group', 'element'])]
#[Groups(['full', 'category:read', 'category:write'])]
#[ORM\OneToMany(mappedBy: 'element', targetEntity: CategoryParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
@@ -226,37 +201,13 @@ class Category implements DBElementInterface, NamedElementInterface, TimeStampab
public function __construct()
{
$this->initializeAttachments();
$this->initializeStructuralElement();
parent::__construct();
$this->children = new ArrayCollection();
$this->attachments = new ArrayCollection();
$this->parameters = new ArrayCollection();
$this->eda_info = new EDACategoryInfo();
}
public function __clone()
{
if ($this->id) {
$this->cloneDBElement();
$this->cloneAttachments();
// We create a new object, so give it a new creation date
$this->addedDate = null;
//Deep clone parameters
$parameters = $this->parameters;
$this->parameters = new ArrayCollection();
foreach ($parameters as $parameter) {
$this->addParameter(clone $parameter);
}
}
}
public function jsonSerialize(): array
{
return ['@id' => $this->getID()];
}
public function getPartnameHint(): string
{
return $this->partname_hint;

View File

@@ -39,43 +39,27 @@ use ApiPlatform\OpenApi\Model\Operation;
use ApiPlatform\Serializer\Filter\PropertyFilter;
use App\ApiPlatform\Filter\LikeFilter;
use App\Entity\Attachments\Attachment;
use App\Entity\Base\AttachmentsTrait;
use App\Entity\Base\DBElementTrait;
use App\Entity\Base\MasterAttachmentTrait;
use App\Entity\Base\NamedElementTrait;
use App\Entity\Base\StructuralElementTrait;
use App\Entity\Base\TimestampTrait;
use App\Entity\Contracts\DBElementInterface;
use App\Entity\Contracts\HasAttachmentsInterface;
use App\Entity\Contracts\HasMasterAttachmentInterface;
use App\Entity\Contracts\HasParametersInterface;
use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Contracts\StructuralElementInterface;
use App\Entity\Contracts\TimeStampableInterface;
use App\Entity\EDA\EDAFootprintInfo;
use App\Entity\Parameters\ParametersTrait;
use App\EntityListeners\TreeCacheInvalidationListener;
use App\Repository\Parts\FootprintRepository;
use App\Validator\Constraints\UniqueObjectCollection;
use App\Entity\Base\AbstractStructuralDBElement;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Attachments\FootprintAttachment;
use App\Entity\Base\AbstractPartsContainingDBElement;
use App\Entity\Parameters\FootprintParameter;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* This entity represents a footprint of a part (its physical dimensions and shape).
*
* @extends AbstractPartsContainingDBElement<FootprintAttachment, FootprintParameter>
*/
#[ORM\Entity(repositoryClass: FootprintRepository::class)]
#[ORM\Table('`footprints`')]
#[ORM\Index(columns: ['name'], name: 'footprint_idx_name')]
#[ORM\Index(columns: ['parent_id', 'name'], name: 'footprint_idx_parent_name')]
#[ORM\HasLifecycleCallbacks]
#[ORM\EntityListeners([TreeCacheInvalidationListener::class])]
#[UniqueEntity(fields: ['name', 'parent'], message: 'structural.entity.unique_name', ignoreNull: false)]
#[ApiResource(
operations: [
new Get(security: 'is_granted("read", object)'),
@@ -104,21 +88,13 @@ use Symfony\Component\Validator\Constraints as Assert;
#[ApiFilter(LikeFilter::class, properties: ["name", "comment"])]
#[ApiFilter(DateFilter::class, strategy: DateFilterInterface::EXCLUDE_NULL)]
#[ApiFilter(OrderFilter::class, properties: ['name', 'id', 'addedDate', 'lastModified'])]
class Footprint implements DBElementInterface, NamedElementInterface, TimeStampableInterface, HasAttachmentsInterface, HasMasterAttachmentInterface, StructuralElementInterface, HasParametersInterface, \Stringable, \JsonSerializable
class Footprint extends AbstractPartsContainingDBElement
{
use DBElementTrait;
use NamedElementTrait;
use TimestampTrait;
use AttachmentsTrait;
use MasterAttachmentTrait;
use StructuralElementTrait;
use ParametersTrait;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
#[ORM\JoinColumn(name: 'parent_id')]
#[Groups(['footprint:read', 'footprint:write'])]
#[ApiProperty(readableLink: false, writableLink: false)]
protected ?self $parent = null;
protected ?AbstractStructuralDBElement $parent = null;
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
#[ORM\OrderBy(['name' => Criteria::ASC])]
@@ -152,7 +128,6 @@ class Footprint implements DBElementInterface, NamedElementInterface, TimeStampa
/** @var Collection<int, FootprintParameter>
*/
#[Assert\Valid]
#[UniqueObjectCollection(fields: ['name', 'group', 'element'])]
#[ORM\OneToMany(mappedBy: 'element', targetEntity: FootprintParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
#[Groups(['footprint:read', 'footprint:write'])]
@@ -170,37 +145,13 @@ class Footprint implements DBElementInterface, NamedElementInterface, TimeStampa
public function __construct()
{
$this->initializeAttachments();
$this->initializeStructuralElement();
parent::__construct();
$this->children = new ArrayCollection();
$this->attachments = new ArrayCollection();
$this->parameters = new ArrayCollection();
$this->eda_info = new EDAFootprintInfo();
}
public function __clone()
{
if ($this->id) {
$this->cloneDBElement();
$this->cloneAttachments();
// We create a new object, so give it a new creation date
$this->addedDate = null;
//Deep clone parameters
$parameters = $this->parameters;
$this->parameters = new ArrayCollection();
foreach ($parameters as $parameter) {
$this->addParameter(clone $parameter);
}
}
}
public function jsonSerialize(): array
{
return ['@id' => $this->getID()];
}
/****************************************
* Getters
****************************************/

View File

@@ -39,44 +39,26 @@ use ApiPlatform\OpenApi\Model\Operation;
use ApiPlatform\Serializer\Filter\PropertyFilter;
use App\ApiPlatform\Filter\LikeFilter;
use App\Entity\Attachments\Attachment;
use App\Entity\Base\AttachmentsTrait;
use App\Entity\Base\CompanyTrait;
use App\Entity\Base\DBElementTrait;
use App\Entity\Base\MasterAttachmentTrait;
use App\Entity\Base\NamedElementTrait;
use App\Entity\Base\StructuralElementTrait;
use App\Entity\Base\TimestampTrait;
use App\Entity\Contracts\CompanyInterface;
use App\Entity\Contracts\DBElementInterface;
use App\Entity\Contracts\HasAttachmentsInterface;
use App\Entity\Contracts\HasMasterAttachmentInterface;
use App\Entity\Contracts\HasParametersInterface;
use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Contracts\StructuralElementInterface;
use App\Entity\Contracts\TimeStampableInterface;
use App\Entity\Parameters\ParametersTrait;
use App\EntityListeners\TreeCacheInvalidationListener;
use App\Repository\Parts\ManufacturerRepository;
use App\Validator\Constraints\UniqueObjectCollection;
use App\Entity\Base\AbstractStructuralDBElement;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Base\AbstractCompany;
use App\Entity\Parameters\ManufacturerParameter;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* This entity represents a manufacturer of a part (The company that produces the part).
*
* @extends AbstractCompany<ManufacturerAttachment, ManufacturerParameter>
*/
#[ORM\Entity(repositoryClass: ManufacturerRepository::class)]
#[ORM\Table('`manufacturers`')]
#[ORM\Index(columns: ['name'], name: 'manufacturer_name')]
#[ORM\Index(columns: ['parent_id', 'name'], name: 'manufacturer_idx_parent_name')]
#[ORM\HasLifecycleCallbacks]
#[ORM\EntityListeners([TreeCacheInvalidationListener::class])]
#[UniqueEntity(fields: ['name', 'parent'], message: 'structural.entity.unique_name', ignoreNull: false)]
#[ApiResource(
operations: [
new Get(security: 'is_granted("read", object)'),
@@ -105,22 +87,13 @@ use Symfony\Component\Validator\Constraints as Assert;
#[ApiFilter(LikeFilter::class, properties: ["name", "comment"])]
#[ApiFilter(DateFilter::class, strategy: DateFilterInterface::EXCLUDE_NULL)]
#[ApiFilter(OrderFilter::class, properties: ['name', 'id', 'addedDate', 'lastModified'])]
class Manufacturer implements DBElementInterface, NamedElementInterface, TimeStampableInterface, HasAttachmentsInterface, HasMasterAttachmentInterface, StructuralElementInterface, HasParametersInterface, CompanyInterface, \Stringable, \JsonSerializable
class Manufacturer extends AbstractCompany
{
use DBElementTrait;
use NamedElementTrait;
use TimestampTrait;
use AttachmentsTrait;
use MasterAttachmentTrait;
use StructuralElementTrait;
use ParametersTrait;
use CompanyTrait;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
#[ORM\JoinColumn(name: 'parent_id')]
#[Groups(['manufacturer:read', 'manufacturer:write'])]
#[ApiProperty(readableLink: false, writableLink: false)]
protected ?self $parent = null;
protected ?AbstractStructuralDBElement $parent = null;
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
#[ORM\OrderBy(['name' => Criteria::ASC])]
@@ -145,50 +118,16 @@ class Manufacturer implements DBElementInterface, NamedElementInterface, TimeSta
/** @var Collection<int, ManufacturerParameter>
*/
#[Assert\Valid]
#[UniqueObjectCollection(fields: ['name', 'group', 'element'])]
#[ORM\OneToMany(mappedBy: 'element', targetEntity: ManufacturerParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
#[Groups(['manufacturer:read', 'manufacturer:write'])]
#[ApiProperty(readableLink: false, writableLink: true)]
protected Collection $parameters;
#[Groups(['manufacturer:read', 'manufacturer:write'])]
protected string $comment = '';
#[Groups(['manufacturer:read'])]
protected ?\DateTimeImmutable $addedDate = null;
#[Groups(['manufacturer:read'])]
protected ?\DateTimeImmutable $lastModified = null;
public function __construct()
{
$this->initializeAttachments();
$this->initializeStructuralElement();
parent::__construct();
$this->children = new ArrayCollection();
$this->attachments = new ArrayCollection();
$this->parameters = new ArrayCollection();
}
public function __clone()
{
if ($this->id) {
$this->cloneDBElement();
$this->cloneAttachments();
// We create a new object, so give it a new creation date
$this->addedDate = null;
//Deep clone parameters
$parameters = $this->parameters;
$this->parameters = new ArrayCollection();
foreach ($parameters as $parameter) {
$this->addParameter(clone $parameter);
}
}
}
public function jsonSerialize(): array
{
return ['@id' => $this->getID()];
}
}

View File

@@ -39,26 +39,12 @@ use ApiPlatform\OpenApi\Model\Operation;
use ApiPlatform\Serializer\Filter\PropertyFilter;
use App\ApiPlatform\Filter\LikeFilter;
use App\Entity\Attachments\Attachment;
use App\Entity\Base\AttachmentsTrait;
use App\Entity\Base\DBElementTrait;
use App\Entity\Base\MasterAttachmentTrait;
use App\Entity\Base\NamedElementTrait;
use App\Entity\Base\StructuralElementTrait;
use App\Entity\Base\TimestampTrait;
use App\Entity\Contracts\DBElementInterface;
use App\Entity\Contracts\HasAttachmentsInterface;
use App\Entity\Contracts\HasMasterAttachmentInterface;
use App\Entity\Contracts\HasParametersInterface;
use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Contracts\StructuralElementInterface;
use App\Entity\Contracts\TimeStampableInterface;
use App\Entity\Parameters\ParametersTrait;
use App\EntityListeners\TreeCacheInvalidationListener;
use App\Repository\Parts\MeasurementUnitRepository;
use App\Validator\Constraints\UniqueObjectCollection;
use Doctrine\DBAL\Types\Types;
use App\Entity\Base\AbstractStructuralDBElement;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Attachments\MeasurementUnitAttachment;
use App\Entity\Base\AbstractPartsContainingDBElement;
use App\Entity\Parameters\MeasurementUnitParameter;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@@ -70,15 +56,14 @@ use Symfony\Component\Validator\Constraints\Length;
/**
* This unit represents the unit in which the amount of parts in stock are measured.
* This could be something like N, grams, meters, etc...
*
* @extends AbstractPartsContainingDBElement<MeasurementUnitAttachment,MeasurementUnitParameter>
*/
#[UniqueEntity('unit')]
#[ORM\Entity(repositoryClass: MeasurementUnitRepository::class)]
#[ORM\Table(name: '`measurement_units`')]
#[ORM\Index(columns: ['name'], name: 'unit_idx_name')]
#[ORM\Index(columns: ['parent_id', 'name'], name: 'unit_idx_parent_name')]
#[ORM\HasLifecycleCallbacks]
#[ORM\EntityListeners([TreeCacheInvalidationListener::class])]
#[UniqueEntity(fields: ['name', 'parent'], message: 'structural.entity.unique_name', ignoreNull: false)]
#[ApiResource(
operations: [
new Get(security: 'is_granted("read", object)'),
@@ -107,15 +92,8 @@ use Symfony\Component\Validator\Constraints\Length;
#[ApiFilter(LikeFilter::class, properties: ["name", "comment", "unit"])]
#[ApiFilter(DateFilter::class, strategy: DateFilterInterface::EXCLUDE_NULL)]
#[ApiFilter(OrderFilter::class, properties: ['name', 'id', 'addedDate', 'lastModified'])]
class MeasurementUnit implements DBElementInterface, NamedElementInterface, TimeStampableInterface, HasAttachmentsInterface, HasMasterAttachmentInterface, StructuralElementInterface, HasParametersInterface, \Stringable, \JsonSerializable
class MeasurementUnit extends AbstractPartsContainingDBElement
{
use DBElementTrait;
use NamedElementTrait;
use TimestampTrait;
use AttachmentsTrait;
use MasterAttachmentTrait;
use StructuralElementTrait;
use ParametersTrait;
/**
* @var string The unit symbol that should be used for the Unit. This could be something like "", g (for grams)
* or m (for meters).
@@ -153,7 +131,7 @@ class MeasurementUnit implements DBElementInterface, NamedElementInterface, Time
#[ORM\JoinColumn(name: 'parent_id')]
#[Groups(['measurement_unit:read', 'measurement_unit:write'])]
#[ApiProperty(readableLink: false, writableLink: false)]
protected ?self $parent = null;
protected ?AbstractStructuralDBElement $parent = null;
/**
* @var Collection<int, MeasurementUnitAttachment>
@@ -172,7 +150,6 @@ class MeasurementUnit implements DBElementInterface, NamedElementInterface, Time
/** @var Collection<int, MeasurementUnitParameter>
*/
#[Assert\Valid]
#[UniqueObjectCollection(fields: ['name', 'group', 'element'])]
#[ORM\OneToMany(mappedBy: 'element', targetEntity: MeasurementUnitParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
#[Groups(['measurement_unit:read', 'measurement_unit:write'])]
@@ -224,33 +201,9 @@ class MeasurementUnit implements DBElementInterface, NamedElementInterface, Time
}
public function __construct()
{
$this->initializeAttachments();
$this->initializeStructuralElement();
parent::__construct();
$this->children = new ArrayCollection();
$this->attachments = new ArrayCollection();
$this->parameters = new ArrayCollection();
}
public function __clone()
{
if ($this->id) {
$this->cloneDBElement();
$this->cloneAttachments();
// We create a new object, so give it a new creation date
$this->addedDate = null;
//Deep clone parameters
$parameters = $this->parameters;
$this->parameters = new ArrayCollection();
foreach ($parameters as $parameter) {
$this->addParameter(clone $parameter);
}
}
}
public function jsonSerialize(): array
{
return ['@id' => $this->getID()];
}
}

View File

@@ -37,42 +37,26 @@ use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Serializer\Filter\PropertyFilter;
use App\ApiPlatform\Filter\LikeFilter;
use App\Entity\Base\AttachmentsTrait;
use App\Entity\Base\DBElementTrait;
use App\Entity\Base\MasterAttachmentTrait;
use App\Entity\Base\NamedElementTrait;
use App\Entity\Base\StructuralElementTrait;
use App\Entity\Base\TimestampTrait;
use App\Entity\Contracts\DBElementInterface;
use App\Entity\Contracts\HasAttachmentsInterface;
use App\Entity\Contracts\HasMasterAttachmentInterface;
use App\Entity\Contracts\HasParametersInterface;
use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Contracts\StructuralElementInterface;
use App\Entity\Contracts\TimeStampableInterface;
use App\Entity\Base\AbstractPartsContainingDBElement;
use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\Parameters\PartCustomStateParameter;
use App\Entity\Parameters\ParametersTrait;
use App\EntityListeners\TreeCacheInvalidationListener;
use App\Repository\Parts\PartCustomStateRepository;
use App\Validator\Constraints\UniqueObjectCollection;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* This entity represents a custom part state.
* If an organisation uses Part-DB and has its custom part states, this is useful.
*
* @extends AbstractPartsContainingDBElement<PartCustomStateAttachment,PartCustomStateParameter>
*/
#[ORM\Entity(repositoryClass: PartCustomStateRepository::class)]
#[ORM\Table('`part_custom_states`')]
#[ORM\Index(columns: ['name'], name: 'part_custom_state_name')]
#[ORM\HasLifecycleCallbacks]
#[ORM\EntityListeners([TreeCacheInvalidationListener::class])]
#[UniqueEntity(fields: ['name', 'parent'], message: 'structural.entity.unique_name', ignoreNull: false)]
#[ApiResource(
operations: [
new Get(security: 'is_granted("read", object)'),
@@ -88,16 +72,8 @@ use Symfony\Component\Validator\Constraints as Assert;
#[ApiFilter(LikeFilter::class, properties: ["name"])]
#[ApiFilter(DateFilter::class, strategy: DateFilterInterface::EXCLUDE_NULL)]
#[ApiFilter(OrderFilter::class, properties: ['name', 'id', 'addedDate', 'lastModified'])]
class PartCustomState implements DBElementInterface, NamedElementInterface, TimeStampableInterface, HasAttachmentsInterface, HasMasterAttachmentInterface, StructuralElementInterface, HasParametersInterface, \Stringable, \JsonSerializable
class PartCustomState extends AbstractPartsContainingDBElement
{
use DBElementTrait;
use NamedElementTrait;
use TimestampTrait;
use AttachmentsTrait;
use MasterAttachmentTrait;
use StructuralElementTrait;
use ParametersTrait;
/**
* @var string The comment info for this element as markdown
*/
@@ -112,7 +88,7 @@ class PartCustomState implements DBElementInterface, NamedElementInterface, Time
#[ORM\JoinColumn(name: 'parent_id')]
#[Groups(['part_custom_state:read', 'part_custom_state:write'])]
#[ApiProperty(readableLink: false, writableLink: false)]
protected ?self $parent = null;
protected ?AbstractStructuralDBElement $parent = null;
/**
* @var Collection<int, PartCustomStateAttachment>
@@ -131,7 +107,6 @@ class PartCustomState implements DBElementInterface, NamedElementInterface, Time
/** @var Collection<int, PartCustomStateParameter>
*/
#[Assert\Valid]
#[UniqueObjectCollection(fields: ['name', 'group', 'element'])]
#[ORM\OneToMany(mappedBy: 'element', targetEntity: PartCustomStateParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ORM\OrderBy(['name' => 'ASC'])]
#[Groups(['part_custom_state:read', 'part_custom_state:write'])]
@@ -144,33 +119,9 @@ class PartCustomState implements DBElementInterface, NamedElementInterface, Time
public function __construct()
{
$this->initializeAttachments();
$this->initializeStructuralElement();
parent::__construct();
$this->children = new ArrayCollection();
$this->attachments = new ArrayCollection();
$this->parameters = new ArrayCollection();
}
public function __clone()
{
if ($this->id) {
$this->cloneDBElement();
$this->cloneAttachments();
// We create a new object, so give it a new creation date
$this->addedDate = null;
//Deep clone parameters
$parameters = $this->parameters;
$this->parameters = new ArrayCollection();
foreach ($parameters as $parameter) {
$this->addParameter(clone $parameter);
}
}
}
public function jsonSerialize(): array
{
return ['@id' => $this->getID()];
}
}

View File

@@ -39,44 +39,27 @@ use ApiPlatform\OpenApi\Model\Operation;
use ApiPlatform\Serializer\Filter\PropertyFilter;
use App\ApiPlatform\Filter\LikeFilter;
use App\Entity\Attachments\Attachment;
use App\Entity\Base\AttachmentsTrait;
use App\Entity\Base\DBElementTrait;
use App\Entity\Base\MasterAttachmentTrait;
use App\Entity\Base\NamedElementTrait;
use App\Entity\Base\StructuralElementTrait;
use App\Entity\Base\TimestampTrait;
use App\Entity\Contracts\DBElementInterface;
use App\Entity\Contracts\HasAttachmentsInterface;
use App\Entity\Contracts\HasMasterAttachmentInterface;
use App\Entity\Contracts\HasParametersInterface;
use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Contracts\StructuralElementInterface;
use App\Entity\Contracts\TimeStampableInterface;
use App\Entity\Parameters\ParametersTrait;
use App\EntityListeners\TreeCacheInvalidationListener;
use App\Repository\Parts\StorelocationRepository;
use App\Validator\Constraints\UniqueObjectCollection;
use Doctrine\DBAL\Types\Types;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Attachments\StorageLocationAttachment;
use App\Entity\Base\AbstractPartsContainingDBElement;
use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\Parameters\StorageLocationParameter;
use App\Entity\UserSystem\User;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* This entity represents a storage location, where parts can be stored.
* @extends AbstractPartsContainingDBElement<StorageLocationAttachment, StorageLocationParameter>
*/
#[ORM\Entity(repositoryClass: StorelocationRepository::class)]
#[ORM\Table('`storelocations`')]
#[ORM\Index(columns: ['name'], name: 'location_idx_name')]
#[ORM\Index(columns: ['parent_id', 'name'], name: 'location_idx_parent_name')]
#[ORM\HasLifecycleCallbacks]
#[ORM\EntityListeners([TreeCacheInvalidationListener::class])]
#[UniqueEntity(fields: ['name', 'parent'], message: 'structural.entity.unique_name', ignoreNull: false)]
#[ApiResource(
operations: [
new Get(security: 'is_granted("read", object)'),
@@ -105,16 +88,8 @@ use Symfony\Component\Validator\Constraints as Assert;
#[ApiFilter(LikeFilter::class, properties: ["name", "comment"])]
#[ApiFilter(DateFilter::class, strategy: DateFilterInterface::EXCLUDE_NULL)]
#[ApiFilter(OrderFilter::class, properties: ['name', 'id', 'addedDate', 'lastModified'])]
class StorageLocation implements DBElementInterface, NamedElementInterface, TimeStampableInterface, HasAttachmentsInterface, HasMasterAttachmentInterface, StructuralElementInterface, HasParametersInterface, \Stringable, \JsonSerializable
class StorageLocation extends AbstractPartsContainingDBElement
{
use DBElementTrait;
use NamedElementTrait;
use TimestampTrait;
use AttachmentsTrait;
use MasterAttachmentTrait;
use StructuralElementTrait;
use ParametersTrait;
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
#[ORM\OrderBy(['name' => Criteria::ASC])]
protected Collection $children;
@@ -123,7 +98,7 @@ class StorageLocation implements DBElementInterface, NamedElementInterface, Time
#[ORM\JoinColumn(name: 'parent_id')]
#[Groups(['location:read', 'location:write'])]
#[ApiProperty(readableLink: false, writableLink: false)]
protected ?self $parent = null;
protected ?AbstractStructuralDBElement $parent = null;
#[Groups(['location:read', 'location:write'])]
protected string $comment = '';
@@ -139,7 +114,6 @@ class StorageLocation implements DBElementInterface, NamedElementInterface, Time
/** @var Collection<int, StorageLocationParameter>
*/
#[Assert\Valid]
#[UniqueObjectCollection(fields: ['name', 'group', 'element'])]
#[ORM\OneToMany(mappedBy: 'element', targetEntity: StorageLocationParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
#[Groups(['location:read', 'location:write'])]
@@ -321,33 +295,9 @@ class StorageLocation implements DBElementInterface, NamedElementInterface, Time
}
public function __construct()
{
$this->initializeAttachments();
$this->initializeStructuralElement();
parent::__construct();
$this->children = new ArrayCollection();
$this->parameters = new ArrayCollection();
$this->attachments = new ArrayCollection();
}
public function __clone()
{
if ($this->id) {
$this->cloneDBElement();
$this->cloneAttachments();
// We create a new object, so give it a new creation date
$this->addedDate = null;
//Deep clone parameters
$parameters = $this->parameters;
$this->parameters = new ArrayCollection();
foreach ($parameters as $parameter) {
$this->addParameter(clone $parameter);
}
}
}
public function jsonSerialize(): array
{
return ['@id' => $this->getID()];
}
}

View File

@@ -39,28 +39,12 @@ use ApiPlatform\OpenApi\Model\Operation;
use ApiPlatform\Serializer\Filter\PropertyFilter;
use App\ApiPlatform\Filter\LikeFilter;
use App\Entity\Attachments\Attachment;
use App\Entity\Base\AttachmentsTrait;
use App\Entity\Base\CompanyTrait;
use App\Entity\Base\DBElementTrait;
use App\Entity\Base\MasterAttachmentTrait;
use App\Entity\Base\NamedElementTrait;
use App\Entity\Base\StructuralElementTrait;
use App\Entity\Base\TimestampTrait;
use App\Entity\Contracts\CompanyInterface;
use App\Entity\Contracts\DBElementInterface;
use App\Entity\Contracts\HasAttachmentsInterface;
use App\Entity\Contracts\HasMasterAttachmentInterface;
use App\Entity\Contracts\HasParametersInterface;
use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Contracts\StructuralElementInterface;
use App\Entity\Contracts\TimeStampableInterface;
use App\Entity\Parameters\ParametersTrait;
use App\EntityListeners\TreeCacheInvalidationListener;
use App\Repository\Parts\SupplierRepository;
use App\Entity\PriceInformations\Orderdetail;
use App\Validator\Constraints\UniqueObjectCollection;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Base\AbstractCompany;
use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\Parameters\SupplierParameter;
use App\Entity\PriceInformations\Currency;
use App\Validator\Constraints\BigDecimal\BigDecimalPositiveOrZero;
@@ -68,20 +52,18 @@ use App\Validator\Constraints\Selectable;
use Brick\Math\BigDecimal;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* This entity represents a supplier of parts (the company that sells the parts).
*
* @extends AbstractCompany<SupplierAttachment, SupplierParameter>
*/
#[ORM\Entity(repositoryClass: SupplierRepository::class)]
#[ORM\Table('`suppliers`')]
#[ORM\Index(columns: ['name'], name: 'supplier_idx_name')]
#[ORM\Index(columns: ['parent_id', 'name'], name: 'supplier_idx_parent_name')]
#[ORM\HasLifecycleCallbacks]
#[ORM\EntityListeners([TreeCacheInvalidationListener::class])]
#[UniqueEntity(fields: ['name', 'parent'], message: 'structural.entity.unique_name', ignoreNull: false)]
#[ApiResource(
operations: [
new Get(security: 'is_granted("read", object)'),
@@ -108,17 +90,8 @@ use Symfony\Component\Validator\Constraints as Assert;
#[ApiFilter(LikeFilter::class, properties: ["name", "comment"])]
#[ApiFilter(DateFilter::class, strategy: DateFilterInterface::EXCLUDE_NULL)]
#[ApiFilter(OrderFilter::class, properties: ['name', 'id', 'addedDate', 'lastModified'])]
class Supplier implements DBElementInterface, NamedElementInterface, TimeStampableInterface, HasAttachmentsInterface, HasMasterAttachmentInterface, StructuralElementInterface, HasParametersInterface, CompanyInterface, \Stringable, \JsonSerializable
class Supplier extends AbstractCompany
{
use DBElementTrait;
use NamedElementTrait;
use TimestampTrait;
use AttachmentsTrait;
use MasterAttachmentTrait;
use StructuralElementTrait;
use ParametersTrait;
use CompanyTrait;
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
#[ORM\OrderBy(['name' => Criteria::ASC])]
protected Collection $children;
@@ -127,7 +100,7 @@ class Supplier implements DBElementInterface, NamedElementInterface, TimeStampab
#[ORM\JoinColumn(name: 'parent_id')]
#[Groups(['supplier:read', 'supplier:write'])]
#[ApiProperty(readableLink: false, writableLink: false)]
protected ?self $parent = null;
protected ?AbstractStructuralDBElement $parent = null;
/**
* @var Collection<int, Orderdetail>
@@ -171,21 +144,12 @@ class Supplier implements DBElementInterface, NamedElementInterface, TimeStampab
/** @var Collection<int, SupplierParameter>
*/
#[Assert\Valid]
#[UniqueObjectCollection(fields: ['name', 'group', 'element'])]
#[ORM\OneToMany(mappedBy: 'element', targetEntity: SupplierParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
#[Groups(['supplier:read', 'supplier:write'])]
#[ApiProperty(readableLink: false, writableLink: true)]
protected Collection $parameters;
#[Groups(['supplier:read', 'supplier:write'])]
protected string $comment = '';
#[Groups(['supplier:read'])]
protected ?\DateTimeImmutable $addedDate = null;
#[Groups(['supplier:read'])]
protected ?\DateTimeImmutable $lastModified = null;
/**
* Gets the currency that should be used by default, when creating a orderdetail with this supplier.
*/
@@ -234,34 +198,10 @@ class Supplier implements DBElementInterface, NamedElementInterface, TimeStampab
}
public function __construct()
{
$this->initializeAttachments();
$this->initializeStructuralElement();
parent::__construct();
$this->children = new ArrayCollection();
$this->orderdetails = new ArrayCollection();
$this->attachments = new ArrayCollection();
$this->parameters = new ArrayCollection();
}
public function __clone()
{
if ($this->id) {
$this->cloneDBElement();
$this->cloneAttachments();
// We create a new object, so give it a new creation date
$this->addedDate = null;
//Deep clone parameters
$parameters = $this->parameters;
$this->parameters = new ArrayCollection();
foreach ($parameters as $parameter) {
$this->addParameter(clone $parameter);
}
}
}
public function jsonSerialize(): array
{
return ['@id' => $this->getID()];
}
}

View File

@@ -243,14 +243,6 @@ class StructuralDBElementRepository extends AttachmentContainingDBElementReposit
return $result[0];
}
//If the name contains category delimiters like ->, try to find the element by its full path
if (str_contains($name, '->')) {
$tmp = $this->getEntityByPath($name, '->');
if (count($tmp) > 0) {
return $tmp[count($tmp) - 1];
}
}
//If we find nothing, return null
return null;
}

View File

@@ -167,7 +167,7 @@ class EntityImporter
}
//Only return objects once
return array_values(array_unique($valid_entities, SORT_REGULAR));
return array_values(array_unique($valid_entities));
}
/**

View File

@@ -152,7 +152,7 @@ class PKDatastructureImporter
public function importPartCustomStates(array $data): int
{
if (!isset($data['partcustomstate'])) {
return 0; //Not all PartKeepr installations have custom states
throw new \RuntimeException('$data must contain a "partcustomstate" key!');
}
$partCustomStateData = $data['partcustomstate'];

View File

@@ -150,11 +150,6 @@ trait PKImportHelperTrait
$target->addAttachment($attachment);
$this->em->persist($attachment);
//If the attachment is an image, and the target has no master picture yet, set it
if ($attachment->isPicture() && $target->getMasterPictureAttachment() === null) {
$target->setMasterPictureAttachment($attachment);
}
}
$this->em->flush();

View File

@@ -91,10 +91,7 @@ class PKPartImporter
$this->setAssociationField($entity, 'partUnit', MeasurementUnit::class, $part['partUnit_id']);
}
if (isset($part['partCustomState_id'])) {
$this->setAssociationField($entity, 'partCustomState', MeasurementUnit::class,
$part['partCustomState_id']);
}
$this->setAssociationField($entity, 'partCustomState', MeasurementUnit::class, $part['partCustomState_id']);
//Create a part lot to store the stock level and location
$lot = new PartLot();

1642
yarn.lock

File diff suppressed because it is too large Load Diff