mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-25 03:08:51 +02:00
Applied code style rules to src/
This commit is contained in:
parent
700c049d26
commit
f861de791f
186 changed files with 1462 additions and 1059 deletions
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -36,13 +39,13 @@ class CustomORMAdapter extends ORMAdapter
|
|||
{
|
||||
protected $hydrationMode;
|
||||
|
||||
public function configure(array $options)
|
||||
public function configure(array $options): void
|
||||
{
|
||||
parent::configure($options);
|
||||
$this->hydrationMode = isset($options['hydrate']) ? $options['hydrate'] : Query::HYDRATE_OBJECT;
|
||||
$this->hydrationMode = $options['hydrate'] ?? Query::HYDRATE_OBJECT;
|
||||
}
|
||||
|
||||
protected function prepareQuery(AdapterQuery $query)
|
||||
protected function prepareQuery(AdapterQuery $query): void
|
||||
{
|
||||
parent::prepareQuery($query);
|
||||
$query->setIdentifierPropertyPath(null);
|
||||
|
@ -57,7 +60,7 @@ class CustomORMAdapter extends ORMAdapter
|
|||
$builder = $query->get('qb');
|
||||
$state = $query->getState();
|
||||
// Apply definitive view state for current 'page' of the table
|
||||
foreach ($state->getOrderBy() as list($column, $direction)) {
|
||||
foreach ($state->getOrderBy() as [$column, $direction]) {
|
||||
/** @var AbstractColumn $column */
|
||||
if ($column->isOrderable()) {
|
||||
$builder->addOrderBy($column->getOrderField(), $direction);
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -54,23 +57,13 @@ class AttachmentDataTable implements DataTableTypeInterface
|
|||
$this->attachmentURLGenerator = $attachmentURLGenerator;
|
||||
}
|
||||
|
||||
protected function getQuery(QueryBuilder $builder)
|
||||
{
|
||||
$builder->distinct()->select('attachment')
|
||||
->addSelect('attachment_type')
|
||||
//->addSelect('element')
|
||||
->from(Attachment::class, 'attachment')
|
||||
->leftJoin('attachment.attachment_type', 'attachment_type');
|
||||
//->leftJoin('attachment.element', 'element');
|
||||
}
|
||||
|
||||
public function configure(DataTable $dataTable, array $options)
|
||||
public function configure(DataTable $dataTable, array $options): void
|
||||
{
|
||||
$dataTable->add('picture', TextColumn::class, [
|
||||
'label' => '',
|
||||
'render' => function ($value, Attachment $context) {
|
||||
if ($context->isPicture()
|
||||
&& !$context->isExternal()
|
||||
&& ! $context->isExternal()
|
||||
&& $this->attachmentHelper->isFileExisting($context)) {
|
||||
return sprintf(
|
||||
'<img alt="%s" src="%s" data-thumbnail="%s" class="%s">',
|
||||
|
@ -204,9 +197,19 @@ class AttachmentDataTable implements DataTableTypeInterface
|
|||
|
||||
$dataTable->createAdapter(ORMAdapter::class, [
|
||||
'entity' => Attachment::class,
|
||||
'query' => function (QueryBuilder $builder) {
|
||||
'query' => function (QueryBuilder $builder): void {
|
||||
$this->getQuery($builder);
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getQuery(QueryBuilder $builder): void
|
||||
{
|
||||
$builder->distinct()->select('attachment')
|
||||
->addSelect('attachment_type')
|
||||
//->addSelect('element')
|
||||
->from(Attachment::class, 'attachment')
|
||||
->leftJoin('attachment.attachment_type', 'attachment_type');
|
||||
//->leftJoin('attachment.element', 'element');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -50,11 +53,11 @@ class EntityColumn extends AbstractColumn
|
|||
*/
|
||||
public function normalize($value)
|
||||
{
|
||||
/* @var NamedDBElement $value */
|
||||
/** @var NamedDBElement $value */
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
|
@ -76,9 +79,9 @@ class EntityColumn extends AbstractColumn
|
|||
$this->urlGenerator->listPartsURL($entity),
|
||||
$value
|
||||
);
|
||||
} else {
|
||||
return sprintf('<i>%s</i>', $value);
|
||||
}
|
||||
|
||||
return sprintf('<i>%s</i>', $value);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -31,14 +34,11 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||
*/
|
||||
class LocaleDateTimeColumn extends AbstractColumn
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($value)
|
||||
{
|
||||
if (null === $value) {
|
||||
return $this->options['nullValue'];
|
||||
} elseif (!$value instanceof \DateTimeInterface) {
|
||||
} elseif (! $value instanceof \DateTimeInterface) {
|
||||
$value = new \DateTime((string) $value);
|
||||
}
|
||||
|
||||
|
@ -60,9 +60,6 @@ class LocaleDateTimeColumn extends AbstractColumn
|
|||
return $formatter->format($value->getTimestamp());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -56,7 +59,7 @@ class PartAttachmentsColumn extends AbstractColumn
|
|||
|
||||
public function render($value, $context)
|
||||
{
|
||||
if (!$context instanceof Part) {
|
||||
if (! $context instanceof Part) {
|
||||
throw new \RuntimeException('$context must be a Part object!');
|
||||
}
|
||||
$tmp = '';
|
||||
|
@ -70,7 +73,7 @@ class PartAttachmentsColumn extends AbstractColumn
|
|||
if (--$count < 0) {
|
||||
break;
|
||||
}
|
||||
/* @var Attachment $attachment */
|
||||
/** @var Attachment $attachment */
|
||||
$tmp .= sprintf(
|
||||
'<a href="%s" title="%s" class="attach-table-icon" target="_blank" rel="noopener" data-no-ajax>%s</a>',
|
||||
$this->urlGenerator->viewURL($attachment),
|
||||
|
@ -87,7 +90,7 @@ class PartAttachmentsColumn extends AbstractColumn
|
|||
return $tmp;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -71,87 +74,7 @@ class PartsDataTable implements DataTableTypeInterface
|
|||
$this->attachmentURLGenerator = $attachmentURLGenerator;
|
||||
}
|
||||
|
||||
protected function getQuery(QueryBuilder $builder)
|
||||
{
|
||||
$builder->distinct()->select('part')
|
||||
->addSelect('category')
|
||||
->addSelect('footprint')
|
||||
->addSelect('manufacturer')
|
||||
->addSelect('partUnit')
|
||||
->addSelect('master_picture_attachment')
|
||||
->addSelect('footprint_attachment')
|
||||
->addSelect('partLots')
|
||||
->addSelect('orderdetails')
|
||||
->addSelect('attachments')
|
||||
->addSelect('storelocations')
|
||||
->from(Part::class, 'part')
|
||||
->leftJoin('part.category', 'category')
|
||||
->leftJoin('part.master_picture_attachment', 'master_picture_attachment')
|
||||
->leftJoin('part.partLots', 'partLots')
|
||||
->leftJoin('partLots.storage_location', 'storelocations')
|
||||
->leftJoin('part.footprint', 'footprint')
|
||||
->leftJoin('footprint.master_picture_attachment', 'footprint_attachment')
|
||||
->leftJoin('part.manufacturer', 'manufacturer')
|
||||
->leftJoin('part.orderdetails', 'orderdetails')
|
||||
->leftJoin('part.attachments', 'attachments')
|
||||
->leftJoin('part.partUnit', 'partUnit');
|
||||
}
|
||||
|
||||
protected function buildCriteria(QueryBuilder $builder, array $options)
|
||||
{
|
||||
$em = $builder->getEntityManager();
|
||||
|
||||
if (isset($options['category'])) {
|
||||
$category = $options['category'];
|
||||
$list = $this->treeBuilder->typeToNodesList(Category::class, $category);
|
||||
$list[] = $category;
|
||||
|
||||
$builder->andWhere('part.category IN (:cid)')->setParameter('cid', $list);
|
||||
}
|
||||
|
||||
if (isset($options['footprint'])) {
|
||||
$category = $options['footprint'];
|
||||
$list = $this->treeBuilder->typeToNodesList(Footprint::class, $category);
|
||||
$list[] = $category;
|
||||
|
||||
$builder->andWhere('part.footprint IN (:cid)')->setParameter('cid', $list);
|
||||
}
|
||||
|
||||
if (isset($options['manufacturer'])) {
|
||||
$category = $options['manufacturer'];
|
||||
$list = $this->treeBuilder->typeToNodesList(Manufacturer::class, $category);
|
||||
$list[] = $category;
|
||||
|
||||
$builder->andWhere('part.manufacturer IN (:cid)')->setParameter('cid', $list);
|
||||
}
|
||||
|
||||
if (isset($options['storelocation'])) {
|
||||
$location = $options['storelocation'];
|
||||
$list = $this->treeBuilder->typeToNodesList(Storelocation::class, $location);
|
||||
$list[] = $location;
|
||||
|
||||
$builder->andWhere('partLots.storage_location IN (:cid)')->setParameter('cid', $list);
|
||||
}
|
||||
|
||||
if (isset($options['supplier'])) {
|
||||
$supplier = $options['supplier'];
|
||||
$list = $this->treeBuilder->typeToNodesList(Supplier::class, $supplier);
|
||||
$list[] = $supplier;
|
||||
|
||||
$builder->andWhere('orderdetails.supplier IN (:cid)')->setParameter('cid', $list);
|
||||
}
|
||||
|
||||
if (isset($options['tag'])) {
|
||||
$builder->andWhere('part.tags LIKE :tag')->setParameter('tag', '%'.$options['tag'].'%');
|
||||
}
|
||||
|
||||
if (isset($options['search'])) {
|
||||
$builder->AndWhere('part.name LIKE :search')->orWhere('part.description LIKE :search')->orWhere('part.comment LIKE :search')
|
||||
->setParameter('search', '%'.$options['search'].'%');
|
||||
}
|
||||
}
|
||||
|
||||
public function configure(DataTable $dataTable, array $options)
|
||||
public function configure(DataTable $dataTable, array $options): void
|
||||
{
|
||||
$dataTable
|
||||
->add('picture', TextColumn::class, [
|
||||
|
@ -293,16 +216,96 @@ class PartsDataTable implements DataTableTypeInterface
|
|||
|
||||
->addOrderBy('name')
|
||||
->createAdapter(CustomORMAdapter::class, [
|
||||
'query' => function (QueryBuilder $builder) {
|
||||
'query' => function (QueryBuilder $builder): void {
|
||||
$this->getQuery($builder);
|
||||
},
|
||||
'entity' => Part::class,
|
||||
'criteria' => [
|
||||
function (QueryBuilder $builder) use ($options) {
|
||||
function (QueryBuilder $builder) use ($options): void {
|
||||
$this->buildCriteria($builder, $options);
|
||||
},
|
||||
new SearchCriteriaProvider(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getQuery(QueryBuilder $builder): void
|
||||
{
|
||||
$builder->distinct()->select('part')
|
||||
->addSelect('category')
|
||||
->addSelect('footprint')
|
||||
->addSelect('manufacturer')
|
||||
->addSelect('partUnit')
|
||||
->addSelect('master_picture_attachment')
|
||||
->addSelect('footprint_attachment')
|
||||
->addSelect('partLots')
|
||||
->addSelect('orderdetails')
|
||||
->addSelect('attachments')
|
||||
->addSelect('storelocations')
|
||||
->from(Part::class, 'part')
|
||||
->leftJoin('part.category', 'category')
|
||||
->leftJoin('part.master_picture_attachment', 'master_picture_attachment')
|
||||
->leftJoin('part.partLots', 'partLots')
|
||||
->leftJoin('partLots.storage_location', 'storelocations')
|
||||
->leftJoin('part.footprint', 'footprint')
|
||||
->leftJoin('footprint.master_picture_attachment', 'footprint_attachment')
|
||||
->leftJoin('part.manufacturer', 'manufacturer')
|
||||
->leftJoin('part.orderdetails', 'orderdetails')
|
||||
->leftJoin('part.attachments', 'attachments')
|
||||
->leftJoin('part.partUnit', 'partUnit');
|
||||
}
|
||||
|
||||
protected function buildCriteria(QueryBuilder $builder, array $options): void
|
||||
{
|
||||
$em = $builder->getEntityManager();
|
||||
|
||||
if (isset($options['category'])) {
|
||||
$category = $options['category'];
|
||||
$list = $this->treeBuilder->typeToNodesList(Category::class, $category);
|
||||
$list[] = $category;
|
||||
|
||||
$builder->andWhere('part.category IN (:cid)')->setParameter('cid', $list);
|
||||
}
|
||||
|
||||
if (isset($options['footprint'])) {
|
||||
$category = $options['footprint'];
|
||||
$list = $this->treeBuilder->typeToNodesList(Footprint::class, $category);
|
||||
$list[] = $category;
|
||||
|
||||
$builder->andWhere('part.footprint IN (:cid)')->setParameter('cid', $list);
|
||||
}
|
||||
|
||||
if (isset($options['manufacturer'])) {
|
||||
$category = $options['manufacturer'];
|
||||
$list = $this->treeBuilder->typeToNodesList(Manufacturer::class, $category);
|
||||
$list[] = $category;
|
||||
|
||||
$builder->andWhere('part.manufacturer IN (:cid)')->setParameter('cid', $list);
|
||||
}
|
||||
|
||||
if (isset($options['storelocation'])) {
|
||||
$location = $options['storelocation'];
|
||||
$list = $this->treeBuilder->typeToNodesList(Storelocation::class, $location);
|
||||
$list[] = $location;
|
||||
|
||||
$builder->andWhere('partLots.storage_location IN (:cid)')->setParameter('cid', $list);
|
||||
}
|
||||
|
||||
if (isset($options['supplier'])) {
|
||||
$supplier = $options['supplier'];
|
||||
$list = $this->treeBuilder->typeToNodesList(Supplier::class, $supplier);
|
||||
$list[] = $supplier;
|
||||
|
||||
$builder->andWhere('orderdetails.supplier IN (:cid)')->setParameter('cid', $list);
|
||||
}
|
||||
|
||||
if (isset($options['tag'])) {
|
||||
$builder->andWhere('part.tags LIKE :tag')->setParameter('tag', '%'.$options['tag'].'%');
|
||||
}
|
||||
|
||||
if (isset($options['search'])) {
|
||||
$builder->AndWhere('part.name LIKE :search')->orWhere('part.description LIKE :search')->orWhere('part.comment LIKE :search')
|
||||
->setParameter('search', '%'.$options['search'].'%');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue