Added an PHP CS fixer config file and applied it to files.

We now use the same the same style as the symfony project, and it allows us to simply fix the style by executing php_cs_fixer fix in the project root.
This commit is contained in:
Jan Böhmer 2019-11-09 00:47:20 +01:00
parent 89258bc102
commit e557bdedd5
210 changed files with 2099 additions and 2742 deletions

1
.php_cs.cache Normal file

File diff suppressed because one or more lines are too long

30
.php_cs.dist Normal file
View file

@ -0,0 +1,30 @@
<?php
/**
* Based on the .php_cs.dist of the symfony project
* https://github.com/symfony/symfony/blob/4.4/.php_cs.dist
*/
if (!file_exists(__DIR__.'/src')) {
exit(0);
}
return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHPUnit75Migration:risky' => true,
'php_unit_dedicate_assert' => ['target' => '5.6'],
'array_syntax' => ['syntax' => 'short'],
'fopen_flags' => false,
'protected_to_private' => false,
'combine_nested_dirname' => true,
])
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
->append([__FILE__])
)
;

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,26 +17,21 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Command;
use App\Services\Attachments\AttachmentManager;
use App\Services\Attachments\AttachmentReverseSearch;
use App\Services\Attachments\AttachmentPathResolver;
use App\Services\Attachments\AttachmentReverseSearch;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Mime\FileinfoMimeTypeGuesser;
use Symfony\Component\Mime\MimeTypes;
use Symfony\Component\Mime\MimeTypesInterface;
class CleanAttachmentsCommand extends Command
{
@ -69,9 +64,9 @@ class CleanAttachmentsCommand extends Command
$io = new SymfonyStyle($input, $output);
$mediaPath = $this->pathResolver->getMediaPath();
$io->note("The media path is " . $mediaPath);
$io->note('The media path is '.$mediaPath);
$securePath = $this->pathResolver->getSecurePath();
$io->note("The secure media path is ". $securePath);
$io->note('The secure media path is '.$securePath);
$finder = new Finder();
//We look for files in the media folder only
@ -81,7 +76,7 @@ class CleanAttachmentsCommand extends Command
$fs = new Filesystem();
$file_list = array();
$file_list = [];
$table = new Table($output);
$table->setHeaders(['Filename', 'MIME Type', 'Last modified date']);
@ -89,20 +84,20 @@ class CleanAttachmentsCommand extends Command
foreach ($finder as $file) {
//If not attachment object uses this file, print it
if (count($this->reverseSearch->findAttachmentsByFile($file)) == 0) {
if (0 == \count($this->reverseSearch->findAttachmentsByFile($file))) {
$file_list[] = $file;
$table->addRow([
$fs->makePathRelative($file->getPathname(), $mediaPath),
$this->mimeTypeGuesser->guessMimeType($file->getPathname()),
$dateformatter->format($file->getMTime())
$dateformatter->format($file->getMTime()),
]);
}
}
if (count($file_list) > 0) {
if (\count($file_list) > 0) {
$table->render();
$continue = $io->confirm(sprintf("Found %d abandoned files. Do you want to delete them? This can not be undone!", count($file_list)), false);
$continue = $io->confirm(sprintf('Found %d abandoned files. Do you want to delete them? This can not be undone!', \count($file_list)), false);
if (!$continue) {
//We are finished here, when no files should be deleted
@ -114,27 +109,26 @@ class CleanAttachmentsCommand extends Command
//Delete empty folders:
$this->removeEmptySubFolders($mediaPath);
$io->success("All abandoned files were removed.");
$io->success('All abandoned files were removed.');
} else {
$io->success("No abandoned files found.");
$io->success('No abandoned files found.');
}
}
/**
* This function removes all empty folders inside $path. Taken from https://stackoverflow.com/a/1833681
* This function removes all empty folders inside $path. Taken from https://stackoverflow.com/a/1833681.
*
* @param string $path The path in which the empty folders should be deleted
*
* @return bool
*/
protected function removeEmptySubFolders($path)
{
$empty=true;
foreach (glob($path . DIRECTORY_SEPARATOR . "*") as $file)
{
$empty = true;
foreach (glob($path.\DIRECTORY_SEPARATOR.'*') as $file) {
$empty &= is_dir($file) && $this->removeEmptySubFolders($file);
}
return $empty && rmdir($path);
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Command;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Base\NamedDBElement;
use App\Entity\Devices\Device;
@ -45,13 +43,12 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
/**
* This command converts the BBCode used by old Part-DB versions (<1.0), to the current used markdown format.
* @package App\Command
*/
class ConvertBBCodeCommand extends Command
{
/** @var string The LIKE criteria used to detect on SQL server if a entry contains BBCode */
protected const BBCODE_CRITERIA = "%[%]%[/%]%";
/** @var string The regex (performed in PHP) used to check if a property really contains BBCODE */
protected const BBCODE_CRITERIA = '%[%]%[/%]%';
/** @var string The regex (performed in PHP) used to check if a property really contains BBCODE */
protected const BBCODE_REGEX = '/\\[.+\\].*\\[\\/.+\\]/';
protected static $defaultName = 'app:convert-bbcode';
@ -83,9 +80,10 @@ class ConvertBBCodeCommand extends Command
/**
* Returns a list which entities and which properties need to be checked.
*
* @return array
*/
protected function getTargetsLists() : array
protected function getTargetsLists(): array
{
return [
Part::class => ['description', 'comment'],
@ -120,19 +118,19 @@ class ConvertBBCodeCommand extends Command
->select('e');
//Add fields criteria
foreach ($properties as $key => $property) {
$qb->orWhere('e.' . $property . ' LIKE ?' . $key);
$qb->orWhere('e.'.$property.' LIKE ?'.$key);
$qb->setParameter($key, static::BBCODE_CRITERIA);
}
//Fetch resulting classes
$results = $qb->getQuery()->getResult();
$io->note(sprintf('Found %d entities, that need to be converted!', count($results)));
$io->note(sprintf('Found %d entities, that need to be converted!', \count($results)));
//In verbose mode print the names of the entities
foreach ($results as $result) {
/** @var NamedDBElement $result */
/* @var NamedDBElement $result */
$io->writeln(
'Convert entity: ' . $result->getName() . ' (' . $result->getIDString() . ')',
'Convert entity: '.$result->getName().' ('.$result->getIDString().')',
OutputInterface::VERBOSITY_VERBOSE
);
foreach ($properties as $property) {
@ -144,19 +142,18 @@ class ConvertBBCodeCommand extends Command
}
$io->writeln(
'BBCode (old): '
. str_replace('\n', ' ', substr($bbcode, 0, 255)),
.str_replace('\n', ' ', substr($bbcode, 0, 255)),
OutputInterface::VERBOSITY_VERY_VERBOSE
);
$markdown = $this->converter->convert($bbcode);
$io->writeln(
'Markdown (new): '
. str_replace('\n', ' ', substr($markdown, 0, 255)),
.str_replace('\n', ' ', substr($markdown, 0, 255)),
OutputInterface::VERBOSITY_VERY_VERBOSE
);
$io->writeln('', OutputInterface::VERBOSITY_VERY_VERBOSE);
$this->propertyAccessor->setValue($result, $property, $markdown);
}
}
}
@ -166,6 +163,4 @@ class ConvertBBCodeCommand extends Command
$io->success('Changes saved to DB successfully!');
}
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Command;

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,15 +17,12 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Command;
use App\Entity\PriceInformations\Currency;
use App\Form\AdminPages\CurrencyAdminForm;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Runner\Exception;
use Swap\Builder;
use Swap\Swap;
use Symfony\Component\Console\Command\Command;
@ -70,12 +67,13 @@ class UpdateExchangeRatesCommand extends Command
$io = new SymfonyStyle($input, $output);
//Check for valid base current
if (strlen($this->base_current) !== 3) {
$io->error("Choosen Base current is not valid. Check your settings!");
if (3 !== \strlen($this->base_current)) {
$io->error('Choosen Base current is not valid. Check your settings!');
return;
}
$io->note('Update currency exchange rates with base currency: ' . $this->base_current);
$io->note('Update currency exchange rates with base currency: '.$this->base_current);
$service = $input->getOption('service');
$api_key = $input->getOption('api_key');
@ -88,7 +86,7 @@ class UpdateExchangeRatesCommand extends Command
//Check what currencies we need to update:
$iso_code = $input->getArgument('iso_code');
$repo = $this->em->getRepository(Currency::class);
$candidates = array();
$candidates = [];
if (!empty($iso_code)) {
$candidates = $repo->findBy(['iso_code' => $iso_code]);
@ -101,22 +99,21 @@ class UpdateExchangeRatesCommand extends Command
//Iterate over each candidate and update exchange rate
foreach ($candidates as $currency) {
try {
$rate = $swap->latest($currency->getIsoCode() . '/' . $this->base_current);
$rate = $swap->latest($currency->getIsoCode().'/'.$this->base_current);
$currency->setExchangeRate($rate->getValue());
$io->note(sprintf('Set exchange rate of %s to %f', $currency->getIsoCode(), $currency->getExchangeRate()));
$this->em->persist($currency);
$success_counter++;
++$success_counter;
} catch (\Exchanger\Exception\Exception $ex) {
$io->warning(sprintf('Error updating %s:', $currency->getIsoCode()));
$io->warning($ex->getMessage());
}
}
//Save to database
$this->em->flush();
$io->success(sprintf('%d (of %d) currency exchange rates were updated.', $success_counter, count($candidates)));
$io->success(sprintf('%d (of %d) currency exchange rates were updated.', $success_counter, \count($candidates)));
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Configuration;

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,16 +17,13 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller\AdminPages;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Attachments\AttachmentTypeAttachment;
use App\Form\AdminPages\AttachmentTypeAdminForm;
use App\Form\AdminPages\BaseEntityAdminForm;
use App\Services\EntityExporter;
use App\Services\EntityImporter;
use App\Services\StructuralElementRecursionHelper;
@ -37,11 +34,9 @@ use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/attachment_type")
* @package App\Controller
*/
class AttachmentTypeController extends BaseAdminController
{
protected $entity_class = AttachmentType::class;
protected $twig_template = 'AdminPages/AttachmentTypeAdmin.html.twig';
protected $form_class = AttachmentTypeAdminForm::class;
@ -50,9 +45,7 @@ class AttachmentTypeController extends BaseAdminController
/**
* @Route("/{id}", name="attachment_type_delete", methods={"DELETE"})
* @param Request $request
* @param AttachmentType $entity
* @param StructuralElementRecursionHelper $recursionHelper
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function delete(Request $request, AttachmentType $entity, StructuralElementRecursionHelper $recursionHelper)
@ -60,13 +53,10 @@ class AttachmentTypeController extends BaseAdminController
return $this->_delete($request, $entity, $recursionHelper);
}
/**
* @Route("/{id}/edit", requirements={"id"="\d+"}, name="attachment_type_edit")
* @Route("/{id}", requirements={"id"="\d+"})
* @param AttachmentType $entity
* @param Request $request
* @param EntityManagerInterface $em
*
* @return Response
*/
public function edit(AttachmentType $entity, Request $request, EntityManagerInterface $em)
@ -78,9 +68,6 @@ class AttachmentTypeController extends BaseAdminController
* @Route("/new", name="attachment_type_new")
* @Route("/")
*
* @param Request $request
* @param EntityManagerInterface $em
* @param EntityImporter $importer
* @return Response
*/
public function new(Request $request, EntityManagerInterface $em, EntityImporter $importer)
@ -90,8 +77,7 @@ class AttachmentTypeController extends BaseAdminController
/**
* @Route("/export", name="attachment_type_export_all")
* @param Request $request
* @param EntityManagerInterface $em
*
* @return Response
*/
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)
@ -101,13 +87,11 @@ class AttachmentTypeController extends BaseAdminController
/**
* @Route("/{id}/export", name="attachment_type_export")
* @param Request $request
* @param AttachmentType $entity
*
* @return Response
*/
public function exportEntity(AttachmentType $entity, EntityExporter $exporter, Request $request)
{
return $this->_exportEntity($entity, $exporter, $request);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller\AdminPages;
@ -38,22 +37,18 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Core\Tests\Encoder\PasswordEncoder;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Contracts\Translation\TranslatorInterface;
abstract class BaseAdminController extends AbstractController
{
protected $entity_class = '';
protected $form_class = '';
protected $twig_template = '';
protected $route_base = '';
protected $attachment_class = '';
protected $passwordEncoder;
protected $translator;
protected $attachmentHelper;
@ -62,11 +57,11 @@ abstract class BaseAdminController extends AbstractController
public function __construct(TranslatorInterface $translator, UserPasswordEncoderInterface $passwordEncoder,
AttachmentManager $attachmentHelper, AttachmentSubmitHandler $attachmentSubmitHandler)
{
if ($this->entity_class === '' || $this->form_class === '' || $this->twig_template === '' || $this->route_base === '') {
if ('' === $this->entity_class || '' === $this->form_class || '' === $this->twig_template || '' === $this->route_base) {
throw new \InvalidArgumentException('You have to override the $entity_class, $form_class, $route_base and $twig_template value in your subclasss!');
}
if ($this->attachment_class === '') {
if ('' === $this->attachment_class) {
throw new \InvalidArgumentException('You have to override the $attachment_class value in your subclass!');
}
@ -78,7 +73,6 @@ abstract class BaseAdminController extends AbstractController
protected function _edit(NamedDBElement $entity, Request $request, EntityManagerInterface $em)
{
$this->denyAccessUnlessGranted('read', $entity);
$form = $this->createForm($this->form_class, $entity, ['attachment_class' => $this->attachment_class]);
@ -99,14 +93,14 @@ abstract class BaseAdminController extends AbstractController
/** @var $attachment FormInterface */
$options = [
'secure_attachment' => $attachment['secureFile']->getData(),
'download_url' => $attachment['downloadURL']->getData()
'download_url' => $attachment['downloadURL']->getData(),
];
try {
$this->attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options);
} catch (AttachmentDownloadException $ex) {
$this->addFlash(
'error',
$this->translator->trans('attachment.download_failed') . ' ' . $ex->getMessage()
$this->translator->trans('attachment.download_failed').' '.$ex->getMessage()
);
}
}
@ -118,14 +112,14 @@ abstract class BaseAdminController extends AbstractController
//Rebuild form, so it is based on the updated data. Important for the parent field!
//We can not use dynamic form events here, because the parent entity list is build from database!
$form = $this->createForm($this->form_class, $entity, ['attachment_class' => $this->attachment_class]);
} elseif ($form->isSubmitted() && ! $form->isValid()) {
} elseif ($form->isSubmitted() && !$form->isValid()) {
$this->addFlash('error', $this->translator->trans('entity.edit_flash.invalid'));
}
return $this->render($this->twig_template, [
'entity' => $entity,
'form' => $form->createView(),
'attachment_helper' => $this->attachmentHelper
'attachment_helper' => $this->attachmentHelper,
]);
}
@ -155,14 +149,14 @@ abstract class BaseAdminController extends AbstractController
/** @var $attachment FormInterface */
$options = [
'secure_attachment' => $attachment['secureFile']->getData(),
'download_url' => $attachment['downloadURL']->getData()
'download_url' => $attachment['downloadURL']->getData(),
];
try {
$this->attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options);
} catch (AttachmentDownloadException $ex) {
$this->addFlash(
'error',
$this->translator->trans('attachment.download_failed') . ' ' . $ex->getMessage()
$this->translator->trans('attachment.download_failed').' '.$ex->getMessage()
);
}
}
@ -171,10 +165,10 @@ abstract class BaseAdminController extends AbstractController
$em->flush();
$this->addFlash('success', $this->translator->trans('entity.created_flash'));
return $this->redirectToRoute($this->route_base . '_edit', ['id' => $new_entity->getID()]);
return $this->redirectToRoute($this->route_base.'_edit', ['id' => $new_entity->getID()]);
}
if ($form->isSubmitted() && ! $form->isValid()) {
if ($form->isSubmitted() && !$form->isValid()) {
$this->addFlash('error', $this->translator->trans('entity.created_flash.invalid'));
}
@ -187,14 +181,14 @@ abstract class BaseAdminController extends AbstractController
$file = $import_form['file']->getData();
$data = $import_form->getData();
$options = array('parent' => $data['parent'], 'preserve_children' => $data['preserve_children'],
'format' => $data['format'], 'csv_separator' => $data['csv_separator']);
$options = ['parent' => $data['parent'], 'preserve_children' => $data['preserve_children'],
'format' => $data['format'], 'csv_separator' => $data['csv_separator'], ];
$errors = $importer->fileToDBEntities($file, $this->entity_class, $options);
foreach ($errors as $name => $error) {
/** @var $error ConstraintViolationList */
$this->addFlash('error', $name . ':' . $error);
/* @var $error ConstraintViolationList */
$this->addFlash('error', $name.':'.$error);
}
}
@ -212,8 +206,8 @@ abstract class BaseAdminController extends AbstractController
//Show errors to user:
foreach ($errors as $name => $error) {
/** @var $error ConstraintViolationList */
$this->addFlash('error', $name . ':' . $error);
/* @var $error ConstraintViolationList */
$this->addFlash('error', $name.':'.$error);
}
}
@ -222,7 +216,7 @@ abstract class BaseAdminController extends AbstractController
'form' => $form->createView(),
'import_form' => $import_form->createView(),
'mass_creation_form' => $mass_creation_form->createView(),
'attachment_helper' => $this->attachmentHelper
'attachment_helper' => $this->attachmentHelper,
]);
}
@ -259,7 +253,7 @@ abstract class BaseAdminController extends AbstractController
$this->addFlash('error', 'csfr_invalid');
}
return $this->redirectToRoute($this->route_base . '_new');
return $this->redirectToRoute($this->route_base.'_new');
}
protected function _exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)
@ -270,7 +264,7 @@ abstract class BaseAdminController extends AbstractController
$entities = $em->getRepository($this->entity_class)->findAll();
return $exporter->exportEntityFromRequest($entities,$request);
return $exporter->exportEntityFromRequest($entities, $request);
}
protected function _exportEntity(NamedDBElement $entity, EntityExporter $exporter, Request $request)
@ -279,4 +273,4 @@ abstract class BaseAdminController extends AbstractController
return $exporter->exportEntityFromRequest($entity, $request);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller\AdminPages;
use App\Entity\Attachments\CategoryAttachment;
use App\Entity\Parts\Category;
use App\Form\AdminPages\CategoryAdminForm;
@ -36,11 +34,9 @@ use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/category")
* @package App\Controller
*/
class CategoryController extends BaseAdminController
{
protected $entity_class = Category::class;
protected $twig_template = 'AdminPages/CategoryAdmin.html.twig';
protected $form_class = CategoryAdminForm::class;
@ -49,9 +45,7 @@ class CategoryController extends BaseAdminController
/**
* @Route("/{id}", name="category_delete", methods={"DELETE"})
* @param Request $request
* @param Category $entity
* @param StructuralElementRecursionHelper $recursionHelper
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function delete(Request $request, Category $entity, StructuralElementRecursionHelper $recursionHelper)
@ -62,9 +56,7 @@ class CategoryController extends BaseAdminController
/**
* @Route("/{id}/edit", requirements={"id"="\d+"}, name="category_edit")
* @Route("/{id}", requirements={"id"="\d+"})
* @param Category $entity
* @param Request $request
* @param EntityManagerInterface $em
*
* @return Response
*/
public function edit(Category $entity, Request $request, EntityManagerInterface $em)
@ -76,9 +68,6 @@ class CategoryController extends BaseAdminController
* @Route("/new", name="category_new")
* @Route("/")
*
* @param Request $request
* @param EntityManagerInterface $em
* @param EntityImporter $importer
* @return Response
*/
public function new(Request $request, EntityManagerInterface $em, EntityImporter $importer)
@ -88,9 +77,7 @@ class CategoryController extends BaseAdminController
/**
* @Route("/export", name="category_export_all")
* @param EntityManagerInterface $em
* @param EntityExporter $exporter
* @param Request $request
*
* @return Response
*/
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)
@ -100,14 +87,11 @@ class CategoryController extends BaseAdminController
/**
* @Route("/{id}/export", name="category_export")
* @param Category $entity
* @param EntityExporter $exporter
* @param Request $request
*
* @return Response
*/
public function exportEntity(Category $entity, EntityExporter $exporter, Request $request)
{
return $this->_exportEntity($entity, $exporter, $request);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller\AdminPages;
use App\Entity\Attachments\CurrencyAttachment;
use App\Entity\PriceInformations\Currency;
use App\Form\AdminPages\CurrencyAdminForm;
@ -38,7 +36,6 @@ use Symfony\Component\Routing\Annotation\Route;
* @Route("/currency")
*
* Class CurrencyController
* @package App\Controller\AdminPages
*/
class CurrencyController extends BaseAdminController
{
@ -50,9 +47,7 @@ class CurrencyController extends BaseAdminController
/**
* @Route("/{id}", name="currency_delete", methods={"DELETE"})
* @param Request $request
* @param Currency $entity
* @param StructuralElementRecursionHelper $recursionHelper
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function delete(Request $request, Currency $entity, StructuralElementRecursionHelper $recursionHelper)
@ -63,9 +58,7 @@ class CurrencyController extends BaseAdminController
/**
* @Route("/{id}/edit", requirements={"id"="\d+"}, name="currency_edit")
* @Route("/{id}", requirements={"id"="\d+"})
* @param Currency $entity
* @param Request $request
* @param EntityManagerInterface $em
*
* @return Response
*/
public function edit(Currency $entity, Request $request, EntityManagerInterface $em)
@ -77,9 +70,6 @@ class CurrencyController extends BaseAdminController
* @Route("/new", name="currency_new")
* @Route("/")
*
* @param Request $request
* @param EntityManagerInterface $em
* @param EntityImporter $importer
* @return Response
*/
public function new(Request $request, EntityManagerInterface $em, EntityImporter $importer)
@ -89,9 +79,7 @@ class CurrencyController extends BaseAdminController
/**
* @Route("/export", name="currency_export_all")
* @param EntityManagerInterface $em
* @param EntityExporter $exporter
* @param Request $request
*
* @return Response
*/
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)
@ -101,13 +89,11 @@ class CurrencyController extends BaseAdminController
/**
* @Route("/{id}/export", name="currency_export")
* @param Currency $entity
* @param EntityExporter $exporter
* @param Request $request
*
* @return Response
*/
public function exportEntity(Currency $entity, EntityExporter $exporter, Request $request)
{
return $this->_exportEntity($entity, $exporter, $request);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller\AdminPages;
use App\Entity\Attachments\DeviceAttachment;
use App\Entity\Devices\Device;
use App\Form\AdminPages\BaseEntityAdminForm;
@ -36,11 +34,9 @@ use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/device")
* @package App\Controller
*/
class DeviceController extends BaseAdminController
{
protected $entity_class = Device::class;
protected $twig_template = 'AdminPages/DeviceAdmin.html.twig';
protected $form_class = BaseEntityAdminForm::class;
@ -49,9 +45,7 @@ class DeviceController extends BaseAdminController
/**
* @Route("/{id}", name="device_delete", methods={"DELETE"})
* @param Request $request
* @param Device $entity
* @param StructuralElementRecursionHelper $recursionHelper
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function delete(Request $request, Device $entity, StructuralElementRecursionHelper $recursionHelper)
@ -62,9 +56,7 @@ class DeviceController extends BaseAdminController
/**
* @Route("/{id}/edit", requirements={"id"="\d+"}, name="device_edit")
* @Route("/{id}", requirements={"id"="\d+"})
* @param Device $entity
* @param Request $request
* @param EntityManagerInterface $em
*
* @return Response
*/
public function edit(Device $entity, Request $request, EntityManagerInterface $em)
@ -76,9 +68,6 @@ class DeviceController extends BaseAdminController
* @Route("/new", name="device_new")
* @Route("/")
*
* @param Request $request
* @param EntityManagerInterface $em
* @param EntityImporter $importer
* @return Response
*/
public function new(Request $request, EntityManagerInterface $em, EntityImporter $importer)
@ -88,9 +77,7 @@ class DeviceController extends BaseAdminController
/**
* @Route("/export", name="device_export_all")
* @param EntityManagerInterface $em
* @param EntityExporter $exporter
* @param Request $request
*
* @return Response
*/
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)
@ -100,14 +87,11 @@ class DeviceController extends BaseAdminController
/**
* @Route("/{id}/export", name="device_export")
* @param Device $entity
* @param EntityExporter $exporter
* @param Request $request
*
* @return Response
*/
public function exportEntity(Device $entity, EntityExporter $exporter, Request $request)
{
return $this->_exportEntity($entity, $exporter, $request);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,17 +17,13 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller\AdminPages;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Attachments\FootprintAttachment;
use App\Entity\Parts\Footprint;
use App\Form\AdminPages\BaseEntityAdminForm;
use App\Form\AdminPages\FootprintAdminForm;
use App\Services\EntityExporter;
use App\Services\EntityImporter;
@ -40,11 +36,9 @@ use Symfony\Component\Serializer\SerializerInterface;
/**
* @Route("/footprint")
* @package App\Controller
*/
class FootprintController extends BaseAdminController
{
protected $entity_class = Footprint::class;
protected $twig_template = 'AdminPages/FootprintAdmin.html.twig';
protected $form_class = FootprintAdminForm::class;
@ -59,7 +53,6 @@ class FootprintController extends BaseAdminController
return $this->_delete($request, $entity, $recursionHelper);
}
/**
* @Route("/{id}/edit", requirements={"id"="\d+"}, name="footprint_edit")
* @Route("/{id}", requirements={"id"="\d+"})
@ -82,9 +75,9 @@ class FootprintController extends BaseAdminController
/**
* @Route("/export", name="footprint_export_all")
* @param Request $request
*
* @param SerializerInterface $serializer
* @param EntityManagerInterface $em
*
* @return Response
*/
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)
@ -94,13 +87,11 @@ class FootprintController extends BaseAdminController
/**
* @Route("/{id}/export", name="footprint_export")
* @param Request $request
* @param AttachmentType $entity
*
* @return Response
*/
public function exportEntity(AttachmentType $entity, EntityExporter $exporter, Request $request)
{
return $this->_exportEntity($entity, $exporter, $request);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller\AdminPages;
use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Supplier;
@ -38,11 +36,9 @@ use Symfony\Component\Serializer\SerializerInterface;
/**
* @Route("/manufacturer")
* @package App\Controller
*/
class ManufacturerController extends BaseAdminController
{
protected $entity_class = Manufacturer::class;
protected $twig_template = 'AdminPages/ManufacturerAdmin.html.twig';
protected $form_class = CompanyForm::class;
@ -77,13 +73,11 @@ class ManufacturerController extends BaseAdminController
return $this->_new($request, $em, $importer);
}
/**
* @Route("/export", name="manufacturer_export_all")
* @param Request $request
*
* @param SerializerInterface $serializer
* @param EntityManagerInterface $em
*
* @return Response
*/
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)
@ -93,13 +87,13 @@ class ManufacturerController extends BaseAdminController
/**
* @Route("/{id}/export", name="manufacturer_export")
* @param Request $request
*
* @param Supplier $entity
*
* @return Response
*/
public function exportEntity(Manufacturer $entity, EntityExporter $exporter, Request $request)
{
return $this->_exportEntity($entity, $exporter, $request);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller\AdminPages;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Attachments\MeasurementUnitAttachment;
use App\Entity\Parts\MeasurementUnit;
@ -38,11 +36,9 @@ use Symfony\Component\Serializer\SerializerInterface;
/**
* @Route("/measurement_unit")
* @package App\Controller
*/
class MeasurementUnitController extends BaseAdminController
{
protected $entity_class = MeasurementUnit::class;
protected $twig_template = 'AdminPages/MeasurementUnitAdmin.html.twig';
protected $form_class = MeasurementUnitAdminForm::class;
@ -79,9 +75,9 @@ class MeasurementUnitController extends BaseAdminController
/**
* @Route("/export", name="measurement_unit_export_all")
* @param Request $request
*
* @param SerializerInterface $serializer
* @param EntityManagerInterface $em
*
* @return Response
*/
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)
@ -91,13 +87,11 @@ class MeasurementUnitController extends BaseAdminController
/**
* @Route("/{id}/export", name="measurement_unit_export")
* @param Request $request
* @param AttachmentType $entity
*
* @return Response
*/
public function exportEntity(AttachmentType $entity, EntityExporter $exporter, Request $request)
{
return $this->_exportEntity($entity, $exporter, $request);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,13 +17,11 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller\AdminPages;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Parts\Storelocation;
use App\Form\AdminPages\StorelocationAdminForm;
use App\Services\EntityExporter;
@ -37,11 +35,9 @@ use Symfony\Component\Serializer\SerializerInterface;
/**
* @Route("/store_location")
* @package App\Controller
*/
class StorelocationController extends BaseAdminController
{
protected $entity_class = Storelocation::class;
protected $twig_template = 'AdminPages/StorelocationAdmin.html.twig';
protected $form_class = StorelocationAdminForm::class;
@ -56,7 +52,6 @@ class StorelocationController extends BaseAdminController
return $this->_delete($request, $entity, $recursionHelper);
}
/**
* @Route("/{id}/edit", requirements={"id"="\d+"}, name="store_location_edit")
* @Route("/{id}", requirements={"id"="\d+"})
@ -79,9 +74,9 @@ class StorelocationController extends BaseAdminController
/**
* @Route("/export", name="store_location_export_all")
* @param Request $request
*
* @param SerializerInterface $serializer
* @param EntityManagerInterface $em
*
* @return Response
*/
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)
@ -91,13 +86,13 @@ class StorelocationController extends BaseAdminController
/**
* @Route("/{id}/export", name="store_location_export")
* @param Request $request
*
* @param AttachmentType $entity
*
* @return Response
*/
public function exportEntity(Storelocation $entity, EntityExporter $exporter, Request $request)
{
return $this->_exportEntity($entity, $exporter, $request);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller\AdminPages;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Parts\Supplier;
use App\Form\AdminPages\SupplierForm;
@ -37,11 +35,9 @@ use Symfony\Component\Serializer\SerializerInterface;
/**
* @Route("/supplier")
* @package App\Controller
*/
class SupplierController extends BaseAdminController
{
protected $entity_class = Supplier::class;
protected $twig_template = 'AdminPages/SupplierAdmin.html.twig';
protected $form_class = SupplierForm::class;
@ -76,12 +72,11 @@ class SupplierController extends BaseAdminController
return $this->_new($request, $em, $importer);
}
/**
* @Route("/export", name="supplier_export_all")
* @param Request $request
*
* @param SerializerInterface $serializer
* @param EntityManagerInterface $em
*
* @return Response
*/
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)
@ -91,13 +86,11 @@ class SupplierController extends BaseAdminController
/**
* @Route("/{id}/export", name="supplier_export")
* @param Request $request
* @param Supplier $entity
*
* @return Response
*/
public function exportEntity(Supplier $entity, EntityExporter $exporter, Request $request)
{
return $this->_exportEntity($entity, $exporter, $request);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,14 +17,11 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller;
use App\DataTables\AttachmentDataTable;
use App\DataTables\PartsDataTable;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\PartAttachment;
use App\Services\Attachments\AttachmentManager;
@ -37,14 +34,13 @@ use Symfony\Component\Routing\Annotation\Route;
class AttachmentFileController extends AbstractController
{
/**
* Download the selected attachment
* Download the selected attachment.
*
* @Route("/attachment/{id}/download", name="attachment_download")
* @param Attachment $attachment
* @param AttachmentManager $helper
*
* @return BinaryFileResponse
*
* @throws \Exception
*/
public function download(Attachment $attachment, AttachmentManager $helper)
@ -59,7 +55,6 @@ class AttachmentFileController extends AbstractController
throw new \RuntimeException('The file associated with the attachment is not existing!');
}
$file_path = $helper->toAbsoluteFilePath($attachment);
$response = new BinaryFileResponse($file_path);
@ -70,12 +65,12 @@ class AttachmentFileController extends AbstractController
}
/**
* View the attachment
* View the attachment.
*
* @Route("/attachment/{id}/view", name="attachment_view")
* @param Attachment $attachment
* @param AttachmentManager $helper
*
* @return BinaryFileResponse
*
* @throws \Exception
*/
public function view(Attachment $attachment, AttachmentManager $helper)
@ -90,7 +85,6 @@ class AttachmentFileController extends AbstractController
throw new \RuntimeException('The file associated with the attachment is not existing!');
}
$file_path = $helper->toAbsoluteFilePath($attachment);
$response = new BinaryFileResponse($file_path);
@ -102,8 +96,7 @@ class AttachmentFileController extends AbstractController
/**
* @Route("/attachment/list", name="attachment_list")
* @param DataTableFactory $dataTable
* @param Request $request
*
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
*/
public function attachmentsTable(DataTableFactory $dataTable, Request $request)
@ -118,8 +111,7 @@ class AttachmentFileController extends AbstractController
}
return $this->render('attachment_list.html.twig', [
'datatable' => $table
'datatable' => $table,
]);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller;
@ -44,8 +43,6 @@ class DebugController extends AbstractController
$this->addFlash('testkjfd', 'Blabla. This message type should be not know to template!');
return $this->render('base.html.twig');
}
@ -81,6 +78,5 @@ class DebugController extends AbstractController
$translator->trans('flash.info');
$translator->trans('validator.noLockout');
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller;
use App\Controller\AdminPages\BaseAdminController;
use App\Entity\Attachments\GroupAttachment;
use App\Entity\UserSystem\Group;
@ -49,9 +47,7 @@ class GroupController extends BaseAdminController
/**
* @Route("/{id}/edit", requirements={"id"="\d+"}, name="group_edit")
* @Route("/{id}/", requirements={"id"="\d+"})
* @param Group $entity
* @param Request $request
* @param EntityManagerInterface $em
*
* @return Response
*/
public function edit(Group $entity, Request $request, EntityManagerInterface $em)
@ -62,9 +58,7 @@ class GroupController extends BaseAdminController
/**
* @Route("/new", name="group_new")
* @Route("/")
* @param Request $request
* @param EntityManagerInterface $em
* @param EntityImporter $importer
*
* @return Response
*/
public function new(Request $request, EntityManagerInterface $em, EntityImporter $importer)
@ -74,9 +68,7 @@ class GroupController extends BaseAdminController
/**
* @Route("/{id}", name="group_delete", methods={"DELETE"})
* @param Request $request
* @param Group $entity
* @param StructuralElementRecursionHelper $recursionHelper
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function delete(Request $request, Group $entity, StructuralElementRecursionHelper $recursionHelper)
@ -86,9 +78,7 @@ class GroupController extends BaseAdminController
/**
* @Route("/export", name="group_export_all")
* @param EntityManagerInterface $em
* @param EntityExporter $exporter
* @param Request $request
*
* @return Response
*/
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)
@ -98,13 +88,11 @@ class GroupController extends BaseAdminController
/**
* @Route("/{id}/export", name="group_export")
* @param Group $entity
* @param EntityExporter $exporter
* @param Request $request
*
* @return Response
*/
public function exportEntity(Group $entity, EntityExporter $exporter, Request $request)
{
return $this->_exportEntity($entity, $exporter, $request);
}
}
}

View file

@ -1,7 +1,7 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -18,16 +18,12 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller;
use App\Services\GitVersionInfo;
use SebastianBergmann\CodeCoverage\Node\File;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Cache\CacheInterface;
@ -43,12 +39,12 @@ class HomepageController extends AbstractController
$this->kernel = $kernel;
}
public function getBanner() : string
public function getBanner(): string
{
$banner = $this->getParameter('banner');
if (empty($banner)) {
$banner_path = $this->kernel->getProjectDir()
. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'banner.md';
.\DIRECTORY_SEPARATOR.'config'.\DIRECTORY_SEPARATOR.'banner.md';
return file_get_contents($banner_path);
}
@ -64,7 +60,7 @@ class HomepageController extends AbstractController
return $this->render('homepage.html.twig', [
'banner' => $this->getBanner(),
'git_branch' => $versionInfo->getGitBranchName(),
'git_commit' => $versionInfo->getGitCommitHash()
'git_commit' => $versionInfo->getGitCommitHash(),
]);
}
}

View file

@ -1,7 +1,7 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller;
@ -40,15 +39,13 @@ use Symfony\Contracts\Translation\TranslatorInterface;
/**
* @Route("/part")
* @package App\Controller
*/
class PartController extends AbstractController
{
/**
* @Route("/{id}/info", name="part_info")
* @Route("/{id}", requirements={"id"="\d+"})
* @param Part $part
* @param AttachmentManager $attachmentHelper
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function show(Part $part, AttachmentManager $attachmentHelper, PricedetailHelper $pricedetailHelper, PartPreviewGenerator $previewGenerator)
@ -61,7 +58,7 @@ class PartController extends AbstractController
'part' => $part,
'attachment_helper' => $attachmentHelper,
'pricedetail_helper' => $pricedetailHelper,
'pictures' => $previewGenerator->getPreviewAttachments($part)
'pictures' => $previewGenerator->getPreviewAttachments($part),
]
);
}
@ -69,10 +66,6 @@ class PartController extends AbstractController
/**
* @Route("/{id}/edit", name="part_edit")
*
* @param Part $part
*
* @param Request $request
* @param EntityManagerInterface $em
* @return \Symfony\Component\HttpFoundation\Response
*/
public function edit(Part $part, Request $request, EntityManagerInterface $em, TranslatorInterface $translator,
@ -90,25 +83,24 @@ class PartController extends AbstractController
/** @var $attachment FormInterface */
$options = [
'secure_attachment' => $attachment['secureFile']->getData(),
'download_url' => $attachment['downloadURL']->getData()
'download_url' => $attachment['downloadURL']->getData(),
];
try {
$attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options);
} catch (AttachmentDownloadException $ex) {
$this->addFlash(
'error',
$translator->trans('attachment.download_failed') . ' ' . $ex->getMessage()
$translator->trans('attachment.download_failed').' '.$ex->getMessage()
);
}
}
$em->persist($part);
$em->flush();
$this->addFlash('info', $translator->trans('part.edited_flash'));
//Reload form, so the SIUnitType entries use the new part unit
$form = $this->createForm(PartBaseType::class, $part);
} elseif ($form->isSubmitted() && ! $form->isValid()) {
} elseif ($form->isSubmitted() && !$form->isValid()) {
$this->addFlash('error', $translator->trans('part.edited_flash.invalid'));
}
@ -122,15 +114,14 @@ class PartController extends AbstractController
/**
* @Route("/{id}/delete", name="part_delete", methods={"DELETE"})
* @param Request $request
* @param Part $part
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function delete(Request $request, Part $part)
{
$this->denyAccessUnlessGranted('delete', $part);
if ($this->isCsrfTokenValid('delete' . $part->getId(), $request->request->get('_token'))) {
if ($this->isCsrfTokenValid('delete'.$part->getId(), $request->request->get('_token'))) {
$entityManager = $this->getDoctrine()->getManager();
//Remove part
@ -148,9 +139,6 @@ class PartController extends AbstractController
/**
* @Route("/new", name="part_new")
*
* @param Request $request
* @param EntityManagerInterface $em
* @param TranslatorInterface $translator
* @return \Symfony\Component\HttpFoundation\Response
*/
public function new(Request $request, EntityManagerInterface $em, TranslatorInterface $translator,
@ -176,14 +164,14 @@ class PartController extends AbstractController
/** @var $attachment FormInterface */
$options = [
'secure_attachment' => $attachment['secureFile']->getData(),
'download_url' => $attachment['downloadURL']->getData()
'download_url' => $attachment['downloadURL']->getData(),
];
try {
$attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options);
} catch (AttachmentDownloadException $ex) {
$this->addFlash(
'error',
$translator->trans('attachment.download_failed') . ' ' . $ex->getMessage()
$translator->trans('attachment.download_failed').' '.$ex->getMessage()
);
}
}
@ -195,7 +183,7 @@ class PartController extends AbstractController
return $this->redirectToRoute('part_edit', ['id' => $new_part->getID()]);
}
if ($form->isSubmitted() && ! $form->isValid()) {
if ($form->isSubmitted() && !$form->isValid()) {
$this->addFlash('error', $translator->trans('part.created_flash.invalid'));
}
@ -203,16 +191,13 @@ class PartController extends AbstractController
[
'part' => $new_part,
'form' => $form->createView(),
'attachment_helper' => $attachmentHelper
'attachment_helper' => $attachmentHelper,
]);
}
/**
* @Route("/{id}/clone", name="part_clone")
* @param Part $part
* @param Request $request
* @param EntityManagerInterface $em
* @param TranslatorInterface $translator
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function clone(Part $part, Request $request, EntityManagerInterface $em, TranslatorInterface $translator)

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller;
@ -53,7 +52,7 @@ class PartListsController extends AbstractController
return $this->render('Parts/lists/category_list.html.twig', [
'datatable' => $table,
'entity' => $category
'entity' => $category,
]);
}
@ -75,7 +74,7 @@ class PartListsController extends AbstractController
return $this->render('Parts/lists/footprint_list.html.twig', [
'datatable' => $table,
'entity' => $footprint
'entity' => $footprint,
]);
}
@ -97,7 +96,7 @@ class PartListsController extends AbstractController
return $this->render('Parts/lists/manufacturer_list.html.twig', [
'datatable' => $table,
'entity' => $manufacturer
'entity' => $manufacturer,
]);
}
@ -119,7 +118,7 @@ class PartListsController extends AbstractController
return $this->render('Parts/lists/store_location_list.html.twig', [
'datatable' => $table,
'entity' => $storelocation
'entity' => $storelocation,
]);
}
@ -141,16 +140,13 @@ class PartListsController extends AbstractController
return $this->render('Parts/lists/supplier_list.html.twig', [
'datatable' => $table,
'entity' => $supplier
'entity' => $supplier,
]);
}
/**
* @Route("/parts/by_tag/{tag}", name="part_list_tags")
* @param string $tag
* @param Request $request
* @param DataTableFactory $dataTable
*
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
*/
public function showTag(string $tag, Request $request, DataTableFactory $dataTable)
@ -164,7 +160,7 @@ class PartListsController extends AbstractController
return $this->render('Parts/lists/tags_list.html.twig', [
'tag' => $tag,
'datatable' => $table
'datatable' => $table,
]);
}
@ -184,16 +180,13 @@ class PartListsController extends AbstractController
return $this->render('Parts/lists/search_list.html.twig', [
'datatable' => $table,
'keyword' => $keyword
'keyword' => $keyword,
]);
}
/**
* @Route("/parts", name="parts_show_all")
*
* @param Request $request
* @param DataTableFactory $dataTable
*
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
*/
public function showAll(Request $request, DataTableFactory $dataTable)

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller;
@ -46,7 +45,7 @@ class RedirectController extends AbstractController
/**
* This function is called whenever a route was not matching the localized routes.
* The purpose is to redirect the user to the localized version of the page.
* @param Request $request
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function addLocalePart(Request $request)
@ -63,36 +62,39 @@ class RedirectController extends AbstractController
//Check if the user needs to change the password. In that case redirect him to settings_page
if ($user instanceof User && $user->isNeedPwChange()) {
$this->session->getFlashBag()->add('warning', $this->translator->trans('flash.password_change_needed'));
return $this->redirectToRoute('user_settings', ['_locale' => $locale]);
}
//$new_url = str_replace($request->getPathInfo(), '/' . $locale . $request->getPathInfo(), $request->getUri());
$new_url = $request->getUriForPath('/' . $locale . $request->getPathInfo());
$new_url = $request->getUriForPath('/'.$locale.$request->getPathInfo());
//If either mod_rewrite is not enabled or the index.php version is enforced, add index.php to the string
if (($this->enforce_index_php || !$this->checkIfModRewriteAvailable())
&& strpos($new_url, 'index.php') === false) {
&& false === strpos($new_url, 'index.php')) {
//Like Request::getUriForPath only with index.php
$new_url = $request->getSchemeAndHttpHost(). $request->getBaseUrl().'/index.php/' . $locale . $request->getPathInfo();
$new_url = $request->getSchemeAndHttpHost().$request->getBaseUrl().'/index.php/'.$locale.$request->getPathInfo();
}
return $this->redirect($new_url);
}
/**
* Check if mod_rewrite is availabe (URL rewriting is possible).
* If this is true, we can redirect to /en, otherwise we have to redirect to index.php/en.
* When the PHP is not used via Apache SAPI, we just assume that URL rewriting is available
* When the PHP is not used via Apache SAPI, we just assume that URL rewriting is available.
*
* @return bool
*/
public function checkIfModRewriteAvailable()
{
if (!function_exists('apache_get_modules')) {
if (!\function_exists('apache_get_modules')) {
//If we can not check for apache modules, we just hope for the best and assume url rewriting is available
//If you want to enforce index.php versions of the url, you can override this via ENV vars.
return true;
}
//Check if the mod_rewrite module is loaded
return in_array('mod_rewrite', apache_get_modules(), false);
return \in_array('mod_rewrite', apache_get_modules(), false);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller;

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller;
@ -35,8 +34,6 @@ use Symfony\Component\Routing\Annotation\Route;
/**
* This controller has the purpose to provide the data for all treeviews.
*
* @package App\Controller
*/
class TreeController extends AbstractController
{
@ -57,13 +54,12 @@ class TreeController extends AbstractController
*/
public function categoryTree(TreeBuilder $builder, Category $category = null)
{
if ($category !== null) {
if (null !== $category) {
$tree[] = $builder->elementToTreeNode($category);
} else {
$tree = $builder->typeToTree(Category::class);
}
return $this->json($tree, 200, [], ['skip_null_values' => true]);
}
@ -73,13 +69,12 @@ class TreeController extends AbstractController
*/
public function footprintTree(TreeBuilder $builder, Footprint $footprint = null)
{
if ($footprint !== null) {
if (null !== $footprint) {
$tree[] = $builder->elementToTreeNode($footprint);
} else {
$tree = $builder->typeToTree(Footprint::class);
}
return $this->json($tree, 200, [], ['skip_null_values' => true]);
}
@ -89,13 +84,12 @@ class TreeController extends AbstractController
*/
public function locationTree(TreeBuilder $builder, Storelocation $location = null)
{
if ($location !== null) {
if (null !== $location) {
$tree[] = $builder->elementToTreeNode($location);
} else {
$tree = $builder->typeToTree(Storelocation::class);
}
return $this->json($tree, 200, [], ['skip_null_values' => true]);
}
@ -105,13 +99,12 @@ class TreeController extends AbstractController
*/
public function manufacturerTree(TreeBuilder $builder, Manufacturer $manufacturer = null)
{
if ($manufacturer !== null) {
if (null !== $manufacturer) {
$tree[] = $builder->elementToTreeNode($manufacturer);
} else {
$tree = $builder->typeToTree(Manufacturer::class);
}
return $this->json($tree, 200, [], ['skip_null_values' => true]);
}
@ -121,13 +114,12 @@ class TreeController extends AbstractController
*/
public function supplierTree(TreeBuilder $builder, Supplier $supplier = null)
{
if ($supplier !== null) {
if (null !== $supplier) {
$tree[] = $builder->elementToTreeNode($supplier);
} else {
$tree = $builder->typeToTree(Supplier::class);
}
return $this->json($tree, 200, [], ['skip_null_values' => true]);
}
@ -137,15 +129,12 @@ class TreeController extends AbstractController
*/
public function deviceTree(TreeBuilder $builder, Device $device = null)
{
if ($device !== null) {
if (null !== $device) {
$tree[] = $builder->elementToTreeNode($device);
} else {
$tree = $builder->typeToTree(Device::class, null);
}
return $this->json($tree, 200, [], ['skip_null_values' => true]);
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller;
use App\Services\Attachments\BuiltinAttachmentsFinder;
use App\Services\TagFinder;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -34,9 +32,9 @@ use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
/**
* In this controller the endpoints for the typeaheads are collected
* In this controller the endpoints for the typeaheads are collected.
*
* @Route("/typeahead")
* @package App\Controller
*/
class TypeaheadController extends AbstractController
{
@ -47,15 +45,15 @@ class TypeaheadController extends AbstractController
{
$array = $finder->find($query);
$normalizers = [
new ObjectNormalizer()
new ObjectNormalizer(),
];
$encoders = [
new JsonEncoder()
$encoders = [
new JsonEncoder(),
];
$serializer = new Serializer($normalizers, $encoders);
$data = $serializer->serialize($array, 'json');
return new JsonResponse($data, 200, [], true);
}
@ -67,13 +65,14 @@ class TypeaheadController extends AbstractController
$array = $finder->searchTags($query);
$normalizers = [
new ObjectNormalizer()
new ObjectNormalizer(),
];
$encoders = [
new JsonEncoder()
$encoders = [
new JsonEncoder(),
];
$serializer = new Serializer($normalizers, $encoders);
$data = $serializer->serialize($array, 'json');
return new JsonResponse($data, 200, [], true);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Controller;
@ -47,18 +46,15 @@ use Symfony\Component\Validator\Constraints\Length;
/**
* @Route("/user")
* Class UserController
* @package App\Controller
*/
class UserController extends AdminPages\BaseAdminController
{
protected $entity_class = User::class;
protected $twig_template = 'AdminPages/UserAdmin.html.twig';
protected $form_class = UserAdminForm::class;
protected $route_base = 'user';
protected $attachment_class = UserAttachment::class;
/**
* @Route("/{id}/edit", requirements={"id"="\d+"}, name="user_edit")
* @Route("/{id}/", requirements={"id"="\d+"})
@ -84,17 +80,18 @@ class UserController extends AdminPages\BaseAdminController
*/
public function delete(Request $request, User $entity, StructuralElementRecursionHelper $recursionHelper)
{
if ($entity->getID() == User::ID_ANONYMOUS) {
if (User::ID_ANONYMOUS == $entity->getID()) {
throw new \InvalidArgumentException('You can not delete the anonymous user! It is needed for permission checking without a logged in user');
}
return $this->_delete($request, $entity, $recursionHelper);
}
/**
* @Route("/export", name="user_export_all")
* @param Request $request
*
* @param SerializerInterface $serializer
* @param EntityManagerInterface $em
*
* @return Response
*/
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)
@ -104,8 +101,9 @@ class UserController extends AdminPages\BaseAdminController
/**
* @Route("/{id}/export", name="user_export")
* @param Request $request
*
* @param AttachmentType $entity
*
* @return Response
*/
public function exportEntity(User $entity, EntityExporter $exporter, Request $request)
@ -113,7 +111,6 @@ class UserController extends AdminPages\BaseAdminController
return $this->_exportEntity($entity, $exporter, $request);
}
/**
* @Route("/info", name="user_info_self")
* @Route("/{id}/info")
@ -135,17 +132,17 @@ class UserController extends AdminPages\BaseAdminController
}
//Show permissions to user
$builder = $this->createFormBuilder()->add('permissions',PermissionsType::class, [
$builder = $this->createFormBuilder()->add('permissions', PermissionsType::class, [
'mapped' => false,
'disabled' => true,
'inherit' => true,
'data' => $user
'data' => $user,
]);
return $this->render('Users/user_info.html.twig', [
'user' => $user,
'avatar' => $avatar,
'form' => $builder->getForm()->createView()
'form' => $builder->getForm()->createView(),
]);
}
@ -161,8 +158,8 @@ class UserController extends AdminPages\BaseAdminController
$page_need_reload = false;
if(!$user instanceof User) {
return new \RuntimeException("This controller only works only for Part-DB User objects!");
if (!$user instanceof User) {
return new \RuntimeException('This controller only works only for Part-DB User objects!');
}
//When user change its settings, he should be logged in fully.
@ -233,7 +230,7 @@ class UserController extends AdminPages\BaseAdminController
return $this->render('Users/user_settings.html.twig', [
'settings_form' => $form->createView(),
'pw_form' => $pw_form->createView(),
'page_need_reload' => $page_need_reload
'page_need_reload' => $page_need_reload,
]);
}
@ -250,10 +247,10 @@ class UserController extends AdminPages\BaseAdminController
* @return string containing either just a URL or a complete image tag
* @source https://gravatar.com/site/implement/images/php/
*/
public function getGravatar(?string $email, int $s = 80, string $d = 'mm', string $r = 'g', bool $img = false, array $atts = array())
public function getGravatar(?string $email, int $s = 80, string $d = 'mm', string $r = 'g', bool $img = false, array $atts = [])
{
if ($email === null) {
return "";
if (null === $email) {
return '';
}
$url = 'https://www.gravatar.com/avatar/';

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\DataFixtures;
use App\Entity\Parts\Part;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\DataFixtures;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Base\StructuralDBElement;
use App\Entity\Devices\Device;
@ -32,15 +30,12 @@ use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
class DataStructureFixtures extends Fixture
{
protected $em;
public function __construct(EntityManagerInterface $entityManager)
@ -49,15 +44,13 @@ class DataStructureFixtures extends Fixture
}
/**
* Load data fixtures with the passed EntityManager
*
* @param ObjectManager $manager
* Load data fixtures with the passed EntityManager.
*/
public function load(ObjectManager $manager)
{
//Reset autoincrement
$types = [AttachmentType::class, Device::class, Category::class, Footprint::class, Manufacturer::class,
MeasurementUnit::class, Storelocation::class, Supplier::class];
MeasurementUnit::class, Storelocation::class, Supplier::class, ];
foreach ($types as $type) {
$this->createNodesForClass($type, $manager);
@ -68,7 +61,8 @@ class DataStructureFixtures extends Fixture
/**
* Creates a datafixture with serveral nodes for the given class.
* @param string $class The class for which the nodes should be generated (must be a StructuralDBElement child)
*
* @param string $class The class for which the nodes should be generated (must be a StructuralDBElement child)
* @param ObjectManager $manager The ObjectManager that should be used to persist the nodes
*/
public function createNodesForClass(string $class, ObjectManager $manager)
@ -116,4 +110,4 @@ class DataStructureFixtures extends Fixture
$manager->persist($node2_1);
$manager->persist($node1_1_1);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\DataFixtures;
@ -38,15 +37,15 @@ class GroupFixtures extends Fixture
$admins->setName('admins');
//Perm values taken from Version 1
$admins->getPermissions()->setRawPermissionValues([
'system' => '21','groups' => '1365','users' => '87381','self' => '85','config' => '85',
'database' => '21','parts' => '1431655765','parts_name' => '5','parts_description' => '5',
'parts_footprint' => '5','parts_manufacturer' => '5','parts_comment' => '5','parts_order' => '5',
'parts_orderdetails' => '341','parts_prices' => '341','parts_attachments' => '341','devices' => '5461',
'devices_parts' => '325','storelocations' => '5461','footprints' => '5461','categories' => '5461',
'suppliers' => '5461','manufacturers' => '5461','attachment_types' => '1365','tools' => '1365',
'labels' => '21','parts_category' => '5','parts_minamount' => '5','parts_lots' => '85','parts_tags' => '5',
'parts_unit' => '5','parts_mass' => '5','parts_status' => '5','parts_mpn' => '5','currencies' => '5461',
'measurement_units' => '5461'
'system' => '21', 'groups' => '1365', 'users' => '87381', 'self' => '85', 'config' => '85',
'database' => '21', 'parts' => '1431655765', 'parts_name' => '5', 'parts_description' => '5',
'parts_footprint' => '5', 'parts_manufacturer' => '5', 'parts_comment' => '5', 'parts_order' => '5',
'parts_orderdetails' => '341', 'parts_prices' => '341', 'parts_attachments' => '341', 'devices' => '5461',
'devices_parts' => '325', 'storelocations' => '5461', 'footprints' => '5461', 'categories' => '5461',
'suppliers' => '5461', 'manufacturers' => '5461', 'attachment_types' => '1365', 'tools' => '1365',
'labels' => '21', 'parts_category' => '5', 'parts_minamount' => '5', 'parts_lots' => '85', 'parts_tags' => '5',
'parts_unit' => '5', 'parts_mass' => '5', 'parts_status' => '5', 'parts_mpn' => '5', 'currencies' => '5461',
'measurement_units' => '5461',
]);
$this->setReference(self::ADMINS, $admins);
$manager->persist($admins);
@ -54,15 +53,15 @@ class GroupFixtures extends Fixture
$readonly = new Group();
$readonly->setName('readonly');
$readonly->getPermissions()->setRawPermissionValues([
'system' => '2','groups' => '2730','users' => '43690','self' => '25','config' => '170',
'database' => '42','parts' => '2778027689','parts_name' => '9','parts_description' => '9',
'parts_footprint' => '9','parts_manufacturer' => '9','parts_comment' => '9','parts_order' => '9',
'parts_orderdetails' => '681','parts_prices' => '681','parts_attachments' => '681','devices' => '1705',
'devices_parts' => '649','storelocations' => '1705','footprints' => '1705','categories' => '1705',
'suppliers' => '1705','manufacturers' => '1705','attachment_types' => '681','tools' => '1366',
'labels' => '165','parts_category' => '9','parts_minamount' => '9','parts_lots' => '169','parts_tags' => '9',
'parts_unit' => '9','parts_mass' => '9','parts_status' => '9','parts_mpn' => '9','currencies' => '9897',
'measurement_units' => '9897'
'system' => '2', 'groups' => '2730', 'users' => '43690', 'self' => '25', 'config' => '170',
'database' => '42', 'parts' => '2778027689', 'parts_name' => '9', 'parts_description' => '9',
'parts_footprint' => '9', 'parts_manufacturer' => '9', 'parts_comment' => '9', 'parts_order' => '9',
'parts_orderdetails' => '681', 'parts_prices' => '681', 'parts_attachments' => '681', 'devices' => '1705',
'devices_parts' => '649', 'storelocations' => '1705', 'footprints' => '1705', 'categories' => '1705',
'suppliers' => '1705', 'manufacturers' => '1705', 'attachment_types' => '681', 'tools' => '1366',
'labels' => '165', 'parts_category' => '9', 'parts_minamount' => '9', 'parts_lots' => '169', 'parts_tags' => '9',
'parts_unit' => '9', 'parts_mass' => '9', 'parts_status' => '9', 'parts_mpn' => '9', 'currencies' => '9897',
'measurement_units' => '9897',
]);
$this->setReference(self::READONLY, $readonly);
$manager->persist($readonly);
@ -70,15 +69,15 @@ class GroupFixtures extends Fixture
$users = new Group();
$users->setName('users');
$users->getPermissions()->setRawPermissionValues([
'system' => '42','groups' => '2730','users' => '43690','self' => '89','config' => '105',
'database' => '41','parts' => '1431655765','parts_name' => '5','parts_description' => '5',
'parts_footprint' => '5','parts_manufacturer' => '5','parts_comment' => '5','parts_order' => '5',
'parts_orderdetails' => '341','parts_prices' => '341','parts_attachments' => '341','devices' => '5461',
'devices_parts' => '325','storelocations' => '5461','footprints' => '5461','categories' => '5461',
'suppliers' => '5461','manufacturers' => '5461','attachment_types' => '1365','tools' => '1365',
'labels' => '85','parts_category' => '5','parts_minamount' => '5','parts_lots' => '85','parts_tags' => '5',
'parts_unit' => '5','parts_mass' => '5','parts_status' => '5','parts_mpn' => '5','currencies' => '5461',
'measurement_units' => '5461'
'system' => '42', 'groups' => '2730', 'users' => '43690', 'self' => '89', 'config' => '105',
'database' => '41', 'parts' => '1431655765', 'parts_name' => '5', 'parts_description' => '5',
'parts_footprint' => '5', 'parts_manufacturer' => '5', 'parts_comment' => '5', 'parts_order' => '5',
'parts_orderdetails' => '341', 'parts_prices' => '341', 'parts_attachments' => '341', 'devices' => '5461',
'devices_parts' => '325', 'storelocations' => '5461', 'footprints' => '5461', 'categories' => '5461',
'suppliers' => '5461', 'manufacturers' => '5461', 'attachment_types' => '1365', 'tools' => '1365',
'labels' => '85', 'parts_category' => '5', 'parts_minamount' => '5', 'parts_lots' => '85', 'parts_tags' => '5',
'parts_unit' => '5', 'parts_mass' => '5', 'parts_status' => '5', 'parts_mpn' => '5', 'currencies' => '5461',
'measurement_units' => '5461',
]);
$this->setReference(self::USERS, $users);
$manager->persist($users);

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\DataFixtures;
@ -26,7 +25,6 @@ use App\Entity\UserSystem\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use ReflectionClass;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
class UserFixtures extends Fixture

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,16 +17,12 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\DataTables;
use App\DataTables\Column\LocaleDateTimeColumn;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\FootprintAttachment;
use App\Entity\Parts\Part;
use App\Services\Attachments\AttachmentManager;
use App\Services\Attachments\AttachmentURLGenerator;
use App\Services\ElementTypeNameGenerator;
@ -41,7 +37,6 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class AttachmentDataTable implements DataTableTypeInterface
{
protected $translator;
protected $entityURLGenerator;
protected $attachmentHelper;
@ -69,10 +64,6 @@ class AttachmentDataTable implements DataTableTypeInterface
//->leftJoin('attachment.element', 'element');
}
/**
* @param DataTable $dataTable
* @param array $options
*/
public function configure(DataTable $dataTable, array $options)
{
$dataTable->add('picture', TextColumn::class, [
@ -91,7 +82,7 @@ class AttachmentDataTable implements DataTableTypeInterface
}
return '';
}
},
]);
$dataTable->add('name', TextColumn::class, [
@ -115,7 +106,7 @@ class AttachmentDataTable implements DataTableTypeInterface
}
return $value;
}
},
]);
$dataTable->add('attachment_type', TextColumn::class, [
@ -126,7 +117,7 @@ class AttachmentDataTable implements DataTableTypeInterface
$this->entityURLGenerator->editURL($context->getAttachmentType()),
htmlspecialchars($value)
);
}
},
]);
$dataTable->add('element', TextColumn::class, [
@ -138,11 +129,11 @@ class AttachmentDataTable implements DataTableTypeInterface
$this->entityURLGenerator->infoURL($context->getElement()),
$this->elementTypeNameGenerator->getTypeNameCombination($context->getElement(), true)
);
}
},
]);
$dataTable->add('filename', TextColumn::class, [
'propertyPath' => 'filename'
'propertyPath' => 'filename',
]);
$dataTable->add('filesize', TextColumn::class, [
@ -151,7 +142,7 @@ class AttachmentDataTable implements DataTableTypeInterface
return $this->attachmentHelper->getHumanFileSize($context);
}
if ($context->isExternal()) {
return '<i>' . $this->translator->trans('attachment.external') . '</i>';
return '<i>'.$this->translator->trans('attachment.external').'</i>';
}
return sprintf(
@ -160,17 +151,17 @@ class AttachmentDataTable implements DataTableTypeInterface
</span>',
$this->translator->trans('attachment.file_not_found')
);
}
},
]);
$dataTable
->add('addedDate', LocaleDateTimeColumn::class, [
'label' => $this->translator->trans('part.table.addedDate'),
'visible' => false
'visible' => false,
])
->add('lastModified', LocaleDateTimeColumn::class, [
'label' => $this->translator->trans('part.table.lastModified'),
'visible' => false
'visible' => false,
]);
$dataTable->add('show_in_table', BoolColumn::class, [
@ -178,7 +169,7 @@ class AttachmentDataTable implements DataTableTypeInterface
'trueValue' => $this->translator->trans('true'),
'falseValue' => $this->translator->trans('false'),
'nullValue' => '',
'visible' => false
'visible' => false,
]);
$dataTable->add('isPicture', BoolColumn::class, [
@ -187,7 +178,7 @@ class AttachmentDataTable implements DataTableTypeInterface
'falseValue' => $this->translator->trans('false'),
'nullValue' => '',
'visible' => false,
'propertyPath' => 'picture'
'propertyPath' => 'picture',
]);
$dataTable->add('is3DModel', BoolColumn::class, [
@ -196,7 +187,7 @@ class AttachmentDataTable implements DataTableTypeInterface
'falseValue' => $this->translator->trans('false'),
'nullValue' => '',
'visible' => false,
'propertyPath' => '3dmodel'
'propertyPath' => '3dmodel',
]);
$dataTable->add('isBuiltin', BoolColumn::class, [
@ -205,7 +196,7 @@ class AttachmentDataTable implements DataTableTypeInterface
'falseValue' => $this->translator->trans('false'),
'nullValue' => '',
'visible' => false,
'propertyPath' => 'builtin'
'propertyPath' => 'builtin',
]);
$dataTable->createAdapter(ORMAdapter::class, [
@ -215,4 +206,4 @@ class AttachmentDataTable implements DataTableTypeInterface
},
]);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\DataTables\Column;
use App\Entity\Base\DBElement;
use App\Entity\Base\NamedDBElement;
use App\Entity\Parts\Part;
@ -34,7 +32,6 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
class EntityColumn extends AbstractColumn
{
protected $urlGenerator;
protected $accessor;
@ -48,11 +45,12 @@ class EntityColumn extends AbstractColumn
* The normalize function is responsible for converting parsed and processed data to a datatables-appropriate type.
*
* @param mixed $value The single value of the column
*
* @return mixed
*/
public function normalize($value)
{
/** @var NamedDBElement $value */
/* @var NamedDBElement $value */
return $value;
}
@ -63,7 +61,7 @@ class EntityColumn extends AbstractColumn
$resolver->setRequired('property');
$resolver->setDefault('field', function (Options $option) {
return $option['property'] . '.name';
return $option['property'].'.name';
});
$resolver->setDefault('render', function (Options $options) {
@ -72,7 +70,7 @@ class EntityColumn extends AbstractColumn
$entity = $this->accessor->getValue($context, $options['property']);
if ($entity) {
if ($entity->getID() !== null) {
if (null !== $entity->getID()) {
return sprintf(
'<a href="%s">%s</a>',
$this->urlGenerator->listPartsURL($entity),
@ -85,4 +83,4 @@ class EntityColumn extends AbstractColumn
};
});
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\DataTables\Column;
use IntlDateFormatter;
use Omines\DataTablesBundle\Column\AbstractColumn;
use Symfony\Component\OptionsResolver\OptionsResolver;
@ -30,7 +28,6 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Similar to the built in DateTimeColumn, but the datetime is formatted using a IntlDateFormatter,
* to get prettier locale based formatting.
* @package App\DataTables\Column
*/
class LocaleDateTimeColumn extends AbstractColumn
{
@ -45,13 +42,13 @@ class LocaleDateTimeColumn extends AbstractColumn
$value = new \DateTime((string) $value);
}
$formatValues = array(
$formatValues = [
'none' => IntlDateFormatter::NONE,
'short' => IntlDateFormatter::SHORT,
'medium' => IntlDateFormatter::MEDIUM,
'long' => IntlDateFormatter::LONG,
'full' => IntlDateFormatter::FULL,
);
];
$formatter = IntlDateFormatter::create(
\Locale::getDefault(),
@ -74,11 +71,11 @@ class LocaleDateTimeColumn extends AbstractColumn
->setDefaults([
'dateFormat' => 'short',
'timeFormat' => 'short',
'nullValue' => ''
'nullValue' => '',
])
->setAllowedTypes('nullValue', 'string')
;
return $this;
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\DataTables;
@ -28,25 +27,21 @@ use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use App\Services\AmountFormatter;
use App\Services\Attachments\AttachmentURLGenerator;
use App\Services\Attachments\PartPreviewGenerator;
use App\Services\EntityURLGenerator;
use App\Services\ToolsTreeBuilder;
use App\Services\TreeBuilder;
use Doctrine\ORM\QueryBuilder;
use Omines\DataTablesBundle\Adapter\Doctrine\ORM\SearchCriteriaProvider;
use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter;
use Omines\DataTablesBundle\Column\BoolColumn;
use Omines\DataTablesBundle\Column\DateTimeColumn;
use Omines\DataTablesBundle\Column\MapColumn;
use Omines\DataTablesBundle\Column\TextColumn;
use Omines\DataTablesBundle\DataTable;
use Omines\DataTablesBundle\DataTableTypeInterface;
use SebastianBergmann\CodeCoverage\Report\Text;
use Symfony\Contracts\Translation\TranslatorInterface;
class PartsDataTable implements DataTableTypeInterface
@ -134,19 +129,15 @@ class PartsDataTable implements DataTableTypeInterface
}
if (isset($options['tag'])) {
$builder->andWhere('part.tags LIKE :tag')->setParameter('tag', '%' . $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'] . '%');
->setParameter('search', '%'.$options['search'].'%');
}
}
/**
* @param DataTable $dataTable
* @param array $options
*/
public function configure(DataTable $dataTable, array $options)
{
$dataTable
@ -154,7 +145,7 @@ class PartsDataTable implements DataTableTypeInterface
'label' => '',
'render' => function ($value, Part $context) {
$preview_attachment = $this->previewGenerator->getTablePreviewAttachment($context);
if ($preview_attachment === null) {
if (null === $preview_attachment) {
return '';
}
@ -165,7 +156,7 @@ class PartsDataTable implements DataTableTypeInterface
$this->attachmentURLGenerator->getThumbnailURL($preview_attachment, 'thumbnail_md'),
'img-fluid hoverpic'
);
}
},
])
->add('name', TextColumn::class, [
'label' => $this->translator->trans('part.table.name'),
@ -179,7 +170,7 @@ class PartsDataTable implements DataTableTypeInterface
])
->add('id', TextColumn::class, [
'label' => $this->translator->trans('part.table.id'),
'visible' => false
'visible' => false,
])
->add('description', TextColumn::class, [
'label' => $this->translator->trans('part.table.description'),
@ -190,19 +181,19 @@ class PartsDataTable implements DataTableTypeInterface
])
->add('footprint', EntityColumn::class, [
'property' => 'footprint',
'label' => $this->translator->trans('part.table.footprint')
'label' => $this->translator->trans('part.table.footprint'),
])
->add('manufacturer', EntityColumn::class, [
'property' => 'manufacturer',
'label' => $this->translator->trans('part.table.manufacturer')
'label' => $this->translator->trans('part.table.manufacturer'),
])
->add('storelocation', TextColumn::class, [
'label' => $this->translator->trans('part.table.storeLocations'),
'render' => function ($value, Part $context) {
$tmp = array();
$tmp = [];
foreach ($context->getPartLots() as $lot) {
//Ignore lots without storelocation
if ($lot->getStorageLocation() === null) {
if (null === $lot->getStorageLocation()) {
continue;
}
$tmp[] = sprintf(
@ -210,51 +201,52 @@ class PartsDataTable implements DataTableTypeInterface
$this->urlGenerator->listPartsURL($lot->getStorageLocation()),
$lot->getStorageLocation()->getName()
);
}
return implode('<br>', $tmp);
}
},
])
->add('amount', TextColumn::class, [
'label' => $this->translator->trans('part.table.amount'),
'render' => function ($value, Part $context) {
$amount = $context->getAmountSum();
return $this->amountFormatter->format($amount, $context->getPartUnit());
}
},
])
->add('minamount', TextColumn::class, [
'label' => $this->translator->trans('part.table.minamount'),
'visible' => false,
'render' => function ($value, Part $context) {
return $this->amountFormatter->format($value, $context->getPartUnit());
}
},
])
->add('partUnit', TextColumn::class, [
'field' => 'partUnit.name',
'label' => $this->translator->trans('part.table.partUnit'),
'visible' => false
'visible' => false,
])
->add('addedDate', LocaleDateTimeColumn::class, [
'label' => $this->translator->trans('part.table.addedDate'),
'visible' => false
'visible' => false,
])
->add('lastModified', LocaleDateTimeColumn::class, [
'label' => $this->translator->trans('part.table.lastModified'),
'visible' => false
'visible' => false,
])
->add('needs_review', BoolColumn::class, [
'label' => $this->translator->trans('part.table.needsReview'),
'trueValue' => $this->translator->trans('true'),
'falseValue' => $this->translator->trans('false'),
'nullValue' => '',
'visible' => false
'visible' => false,
])
->add('favorite', BoolColumn::class, [
'label' => $this->translator->trans('part.table.favorite'),
'trueValue' => $this->translator->trans('true'),
'falseValue' => $this->translator->trans('false'),
'nullValue' => '',
'visible' => false
'visible' => false,
])
->add('manufacturing_status', MapColumn::class, [
'label' => $this->translator->trans('part.table.manufacturingStatus'),
@ -266,25 +258,25 @@ class PartsDataTable implements DataTableTypeInterface
'active' => $this->translator->trans('m_status.active'),
'nrfnd' => $this->translator->trans('m_status.nrfnd'),
'eol' => $this->translator->trans('m_status.eol'),
'discontinued' => $this->translator->trans('m_status.discontinued')
]
'discontinued' => $this->translator->trans('m_status.discontinued'),
],
])
->add('manufacturer_product_number', TextColumn::class, [
'label' => $this->translator->trans('part.table.mpn'),
'visible' => false
'visible' => false,
])
->add('mass', TextColumn::class, [
'label' => $this->translator->trans('part.table.mass'),
'visible' => false
'visible' => false,
])
->add('tags', TextColumn::class, [
'label' => $this->translator->trans('part.table.tags'),
'visible' => false
'visible' => false,
])
->addOrderBy('name')
->createAdapter(ORMAdapter::class, [
'query' => function(QueryBuilder $builder) {
'query' => function (QueryBuilder $builder) {
$this->getQuery($builder);
},
'entity' => Part::class,
@ -292,8 +284,8 @@ class PartsDataTable implements DataTableTypeInterface
function (QueryBuilder $builder) use ($options) {
$this->buildCriteria($builder, $options);
},
new SearchCriteriaProvider()
]
new SearchCriteriaProvider(),
],
]);
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -65,7 +64,6 @@ use Doctrine\ORM\Mapping as ORM;
* "Supplier" = "SupplierAttachment", "User" = "UserAttachment"
* })
* @ORM\EntityListeners({"App\EntityListeners\AttachmentDeleteListener"})
*
*/
abstract class Attachment extends NamedDBElement
{
@ -75,7 +73,7 @@ abstract class Attachment extends NamedDBElement
* It will be used to determine if a attachment is a picture and therefore will be shown to user as preview.
*/
public const PICTURE_EXTS = ['apng', 'bmp', 'gif', 'ico', 'cur', 'jpg', 'jpeg', 'jfif', 'pjpeg', 'pjp', 'png',
'svg', 'webp'];
'svg', 'webp', ];
/**
* A list of extensions that will be treated as a 3D Model that can be shown to user directly in Part-DB.
@ -83,7 +81,7 @@ abstract class Attachment extends NamedDBElement
public const MODEL_EXTS = ['x3d'];
/**
* When the path begins with one of this placeholders
* When the path begins with one of this placeholders.
*/
public const INTERNAL_PLACEHOLDER = ['%BASE%', '%MEDIA%', '%SECURE%'];
@ -109,7 +107,7 @@ abstract class Attachment extends NamedDBElement
protected $original_filename;
/**
* ORM mapping is done in sub classes (like PartAttachment)
* ORM mapping is done in sub classes (like PartAttachment).
*/
protected $element;
@ -129,7 +127,7 @@ abstract class Attachment extends NamedDBElement
public function __construct()
{
//parent::__construct();
if (static::ALLOWED_ELEMENT_CLASS === '') {
if ('' === static::ALLOWED_ELEMENT_CLASS) {
throw new \LogicException('An *Attachment class must override the ALLOWED_ELEMENT_CLASS const!');
}
}
@ -154,15 +152,16 @@ abstract class Attachment extends NamedDBElement
$extension = pathinfo($this->getPath(), PATHINFO_EXTENSION);
return in_array(strtolower($extension), static::PICTURE_EXTS, true);
return \in_array(strtolower($extension), static::PICTURE_EXTS, true);
}
/**
* Check if this attachment is a 3D model and therfore can be directly shown to user.
* If the attachment is external, false is returned (3D Models must be internal).
*
* @return bool
*/
public function is3DModel() : bool
public function is3DModel(): bool
{
//We just assume that 3D Models are internally saved, otherwise we get problems loading them.
if ($this->isExternal()) {
@ -171,14 +170,15 @@ abstract class Attachment extends NamedDBElement
$extension = pathinfo($this->getPath(), PATHINFO_EXTENSION);
return in_array(strtolower($extension), static::MODEL_EXTS, true);
return \in_array(strtolower($extension), static::MODEL_EXTS, true);
}
/**
* Checks if the attachment file is externally saved (the database saves an URL)
* Checks if the attachment file is externally saved (the database saves an URL).
*
* @return bool true, if the file is saved externally
*/
public function isExternal() : bool
public function isExternal(): bool
{
//When path is empty, this attachment can not be external
if (empty($this->path)) {
@ -186,38 +186,40 @@ abstract class Attachment extends NamedDBElement
}
//After the %PLACEHOLDER% comes a slash, so we can check if we have a placholder via explode
$tmp = explode("/", $this->path);
$tmp = explode('/', $this->path);
if (empty($tmp)) {
return true;
}
return !in_array($tmp[0], array_merge(static::INTERNAL_PLACEHOLDER, static::BUILTIN_PLACEHOLDER), false);
return !\in_array($tmp[0], array_merge(static::INTERNAL_PLACEHOLDER, static::BUILTIN_PLACEHOLDER), false);
}
/**
* Check if this attachment is saved in a secure place.
* This means that it can not be accessed directly via a web request, but must be viewed via a controller.
*
* @return bool True, if the file is secure.
*/
public function isSecure() : bool
public function isSecure(): bool
{
//After the %PLACEHOLDER% comes a slash, so we can check if we have a placholder via explode
$tmp = explode("/", $this->path);
$tmp = explode('/', $this->path);
if (empty($tmp)) {
return false;
}
return $tmp[0] === '%SECURE%';
return '%SECURE%' === $tmp[0];
}
/**
* Checks if the attachment file is using a builtin file. (see BUILTIN_PLACEHOLDERS const for possible placeholders)
* If a file is built in, the path is shown to user in url field (no sensitive infos are provided)
* If a file is built in, the path is shown to user in url field (no sensitive infos are provided).
*
* @return bool True if the attachment is uning an builtin file.
*/
public function isBuiltIn() : bool
public function isBuiltIn(): bool
{
return static::checkIfBuiltin($this->path);
}
@ -232,9 +234,10 @@ abstract class Attachment extends NamedDBElement
* Returns the extension of the file referenced via the attachment.
* For a path like %BASE/path/foo.bar, bar will be returned.
* If this attachment is external null is returned.
*
* @return string|null The file extension in lower case.
*/
public function getExtension() : ?string
public function getExtension(): ?string
{
if ($this->isExternal()) {
return null;
@ -260,6 +263,7 @@ abstract class Attachment extends NamedDBElement
/**
* The URL to the external file, or the path to the built in file.
* Returns null, if the file is not external (and not builtin).
*
* @return string|null
*/
public function getURL(): ?string
@ -274,6 +278,7 @@ abstract class Attachment extends NamedDBElement
/**
* Returns the hostname where the external file is stored.
* Returns null, if the file is not external.
*
* @return string|null
*/
public function getHost(): ?string
@ -319,16 +324,19 @@ abstract class Attachment extends NamedDBElement
/**
* Sets the filename that is shown for this attachment. Useful when the internal path is some generated value.
*
* @param string|null $new_filename The filename that should be shown.
* Set to null to generate the filename from path.
* Set to null to generate the filename from path.
*
* @return Attachment
*/
public function setFilename(?string $new_filename): Attachment
public function setFilename(?string $new_filename): self
{
if ($new_filename === "") {
if ('' === $new_filename) {
$new_filename = null;
}
$this->original_filename = $new_filename;
return $this;
}
@ -347,7 +355,6 @@ abstract class Attachment extends NamedDBElement
* Get the type of this attachement.
*
* @return AttachmentType the type of this attachement
*
*/
public function getAttachmentType(): ?AttachmentType
{
@ -370,8 +377,6 @@ abstract class Attachment extends NamedDBElement
****************************************************************************************************/
/**
* @param bool $show_in_table
*
* @return self
*/
public function setShowInTable(bool $show_in_table): self
@ -381,51 +386,48 @@ abstract class Attachment extends NamedDBElement
return $this;
}
public function setElement(AttachmentContainingDBElement $element) : Attachment
public function setElement(AttachmentContainingDBElement $element): self
{
if (!is_a($element,static::ALLOWED_ELEMENT_CLASS)) {
throw new \InvalidArgumentException(sprintf(
'The element associated with a %s must be a %s!',
get_class($this),
static::ALLOWED_ELEMENT_CLASS
));
if (!is_a($element, static::ALLOWED_ELEMENT_CLASS)) {
throw new \InvalidArgumentException(sprintf('The element associated with a %s must be a %s!', \get_class($this), static::ALLOWED_ELEMENT_CLASS));
}
$this->element = $element;
return $this;
}
/**
* @param string $path
* @return Attachment
*/
public function setPath(string $path): Attachment
public function setPath(string $path): self
{
$this->path = $path;
return $this;
}
/**
* @param AttachmentType $attachement_type
* @return Attachment
*/
public function setAttachmentType(AttachmentType $attachement_type): Attachment
public function setAttachmentType(AttachmentType $attachement_type): self
{
$this->attachment_type = $attachement_type;
return $this;
}
/**
* Sets the url associated with this attachment.
* If the url is empty nothing is changed, to not override the file path.
* @param string|null $url
*
* @return Attachment
*/
public function setURL(?string $url) : Attachment
public function setURL(?string $url): self
{
//Only set if the URL is not empty
if (!empty($url)) {
if (strpos($url, '%BASE%') !== false || strpos($url, '%MEDIA%') !== false) {
if (false !== strpos($url, '%BASE%') || false !== strpos($url, '%MEDIA%')) {
throw new \InvalidArgumentException('You can not reference internal files via the url field! But nice try!');
}
@ -437,17 +439,18 @@ abstract class Attachment extends NamedDBElement
return $this;
}
/*****************************************************************************************************
* Static functions
*****************************************************************************************************/
/**
* Checks if the given path is a path to a builtin ressource.
*
* @param string $path The path that should be checked
*
* @return bool True if the path is pointing to a builtin ressource.
*/
public static function checkIfBuiltin(string $path) : bool
public static function checkIfBuiltin(string $path): bool
{
//After the %PLACEHOLDER% comes a slash, so we can check if we have a placholder via explode
$tmp = explode('/', $path);
@ -455,22 +458,25 @@ abstract class Attachment extends NamedDBElement
if (empty($tmp)) {
return false;
}
return in_array($tmp[0], static::BUILTIN_PLACEHOLDER, false);
return \in_array($tmp[0], static::BUILTIN_PLACEHOLDER, false);
}
/**
* Check if a string is a URL and is valid.
*
* @param $string string The string which should be checked.
* @param bool $path_required If true, the string must contain a path to be valid. (e.g. foo.bar would be invalid, foo.bar/test.php would be valid).
* @param $only_http bool Set this to true, if only HTTPS or HTTP schemata should be allowed.
* *Caution: When this is set to false, a attacker could use the file:// schema, to get internal server files, like /etc/passwd.*
*
* @return bool True if the string is a valid URL. False, if the string is not an URL or invalid.
*/
public static function isURL(string $string, bool $path_required = true, bool $only_http = true) : bool
public static function isURL(string $string, bool $path_required = true, bool $only_http = true): bool
{
if ($only_http) { //Check if scheme is HTTPS or HTTP
$scheme = parse_url($string, PHP_URL_SCHEME);
if ($scheme !== 'http' && $scheme !== 'https') {
if ('http' !== $scheme && 'https' !== $scheme) {
return false; //All other schemes are not valid.
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -48,7 +47,6 @@ use App\Entity\Base\NamedDBElement;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\MappedSuperclass()
@ -59,8 +57,8 @@ abstract class AttachmentContainingDBElement extends NamedDBElement
/**
* @var Attachment[]
* //TODO
* //@ORM\OneToMany(targetEntity="Attachment", mappedBy="element")
* //TODO
* //@ORM\OneToMany(targetEntity="Attachment", mappedBy="element")
*
* Mapping is done in sub classes like part
*/
@ -79,34 +77,39 @@ abstract class AttachmentContainingDBElement extends NamedDBElement
/**
* Gets all attachments associated with this element.
*
* @return Attachment[]|Collection
*/
public function getAttachments() : Collection
public function getAttachments(): Collection
{
return $this->attachments;
}
/**
* Adds an attachment to this element
* Adds an attachment to this element.
*
* @param Attachment $attachment Attachment
*
* @return $this
*/
public function addAttachment(Attachment $attachment) : self
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
* @param Attachment $attachment
* Removes the given attachment from this element.
*
* @return $this
*/
public function removeAttachment(Attachment $attachment) : self
public function removeAttachment(Attachment $attachment): self
{
$this->attachments->removeElement($attachment);
return $this;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -44,10 +43,10 @@ declare(strict_types=1);
namespace App\Entity\Attachments;
use App\Entity\Base\StructuralDBElement;
use App\Validator\Constraints\ValidFileFilter;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Validator\Constraints\ValidFileFilter;
/**
* Class AttachmentType.
@ -85,7 +84,7 @@ class AttachmentType extends StructuralDBElement
* @ORM\Column(type="text")
* @ValidFileFilter
*/
protected $filetype_filter = "";
protected $filetype_filter = '';
public function __construct()
{
@ -97,7 +96,7 @@ class AttachmentType extends StructuralDBElement
* Get all attachments ("Attachment" objects) with this type.
*
* @return Collection|Attachment[] all attachements with this type, as a one-dimensional array of Attachements
* (sorted by their names)
* (sorted by their names)
*/
public function getAttachmentsForType(): Collection
{
@ -108,6 +107,7 @@ class AttachmentType extends StructuralDBElement
* Gets an filter, which file types are allowed for attachment files.
* Must be in the format of <input type=file> accept attribute
* (See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Unique_file_type_specifiers).
*
* @return string
*/
public function getFiletypeFilter(): string
@ -116,12 +116,12 @@ class AttachmentType extends StructuralDBElement
}
/**
* @param string $filetype_filter
* @return AttachmentType
*/
public function setFiletypeFilter(string $filetype_filter): AttachmentType
public function setFiletypeFilter(string $filetype_filter): self
{
$this->filetype_filter = $filetype_filter;
return $this;
}
@ -133,6 +133,6 @@ class AttachmentType extends StructuralDBElement
*/
public function getIDString(): string
{
return 'AT' . sprintf('%09d', $this->getID());
return 'AT'.sprintf('%09d', $this->getID());
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,22 +17,19 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to an attachmentType element.
* @package App\Entity
*
* @ORM\Entity()
*/
class AttachmentTypeAttachment extends Attachment
{
/**
* @var AttachmentType The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Attachments\AttachmentType", inversedBy="attachments")
@ -40,5 +37,5 @@ class AttachmentTypeAttachment extends Attachment
*/
protected $element;
public const ALLOWED_ELEMENT_CLASS = AttachmentType::class;
}
public const ALLOWED_ELEMENT_CLASS = AttachmentType::class;
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,24 +17,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Category;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a category element.
* @package App\Entity
*
* @ORM\Entity()
*/
class CategoryAttachment extends Attachment
{
/**
* @var Category The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Category", inversedBy="attachments")
@ -43,4 +39,4 @@ class CategoryAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = Category::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,28 +17,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a currency element.
* @package App\Entity
*
* @ORM\Entity()
*/
class CurrencyAttachment extends Attachment
{
/**
* @var Currency The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\PriceInformations\Currency", inversedBy="attachments")
@ -47,4 +39,4 @@ class CurrencyAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = Currency::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,18 +17,16 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a device element.
* @package App\Entity
*
* @ORM\Entity()
*/
class DeviceAttachment extends Attachment
@ -41,4 +39,4 @@ class DeviceAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = Device::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,24 +17,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a footprint element.
* @package App\Entity
*
* @ORM\Entity()
*/
class FootprintAttachment extends Attachment
{
/**
* @var Footprint The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Footprint", inversedBy="attachments")
@ -43,4 +39,4 @@ class FootprintAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = Footprint::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,30 +17,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a Group element.
* @package App\Entity
*
* @ORM\Entity()
*/
class GroupAttachment extends Attachment
{
/**
* @var Group The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\Group", inversedBy="attachments")

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,24 +17,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a manufacturer element.
* @package App\Entity
*
* @ORM\Entity()
*/
class ManufacturerAttachment extends Attachment
{
/**
* @var Manufacturer The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Manufacturer", inversedBy="attachments")
@ -43,4 +39,4 @@ class ManufacturerAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = Manufacturer::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,25 +17,21 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a measurement unit element.
* @package App\Entity
*
* @ORM\Entity()
*/
class MeasurementUnitAttachment extends Attachment
{
/**
* @var Manufacturer The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\MeasurementUnit", inversedBy="attachments")
@ -44,4 +40,4 @@ class MeasurementUnitAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = MeasurementUnit::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
@ -27,12 +26,11 @@ use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a part element.
* @package App\Entity
*
* @ORM\Entity()
*/
class PartAttachment extends Attachment
{
/**
* @var Part The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Part", inversedBy="attachments")
@ -41,4 +39,4 @@ class PartAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = Part::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,27 +17,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpKernel\HttpCache\Store;
/**
* A attachment attached to a measurement unit element.
* @package App\Entity
*
* @ORM\Entity()
*/
class StorelocationAttachment extends Attachment
{
/**
* @var Storelocation The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Storelocation", inversedBy="attachments")
@ -46,4 +39,4 @@ class StorelocationAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = Storelocation::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,27 +17,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a supplier element.
* @package App\Entity
*
* @ORM\Entity()
*/
class SupplierAttachment extends Attachment
{
/**
* @var Supplier The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Supplier", inversedBy="attachments")
@ -46,4 +39,4 @@ class SupplierAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = Supplier::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,29 +17,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use App\Entity\UserSystem\User;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a user element.
* @package App\Entity
*
* @ORM\Entity()
*/
class UserAttachment extends Attachment
{
/**
* @var User The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User", inversedBy="attachments")
@ -48,4 +39,4 @@ class UserAttachment extends Attachment
protected $element;
public const ALLOWED_ELEMENT_CLASS = User::class;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -104,7 +103,6 @@ abstract class DBElement
* This should have a form like P000014, for a part with ID 14.
*
* @return string The ID as a string;
*
*/
abstract public function getIDString(): string;

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,20 +17,16 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Base;
use App\Entity\Attachments\Attachment;
use App\Entity\Parts\Part;
use App\Security\Annotations\ColumnSecurity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* A entity with this class has a master attachment, which is used as a preview image for this object.
* @package App\Entity\Parts\PartTraits
*/
trait MasterAttachmentTrait
{
@ -42,10 +38,10 @@ trait MasterAttachmentTrait
*/
protected $master_picture_attachment;
/**
* Get the master picture "Attachment"-object of this part (if there is one).
* The master picture should be used as a visual description/representation of this part.
*
* @return Attachment the master picture Attachement of this part (if there is one)
*/
public function getMasterPictureAttachment(): ?Attachment
@ -55,14 +51,13 @@ trait MasterAttachmentTrait
/**
* Sets the new master picture for this part.
* @param Attachment|null $new_master_attachment
*
* @return Part
*/
public function setMasterPictureAttachment(?Attachment $new_master_attachment): self
{
$this->master_picture_attachment = $new_master_attachment;
return $this;
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -44,8 +43,8 @@ declare(strict_types=1);
namespace App\Entity\Base;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* All subclasses of this class have an attribute "name".
@ -55,7 +54,6 @@ use Symfony\Component\Serializer\Annotation\Groups;
*/
abstract class NamedDBElement extends DBElement
{
use TimestampTrait;
/**
@ -73,7 +71,8 @@ abstract class NamedDBElement extends DBElement
*********************************************************************************/
/**
* Get the name of this element
* Get the name of this element.
*
* @return string the name of this element
*/
public function getName(): string
@ -91,6 +90,7 @@ abstract class NamedDBElement extends DBElement
* Change the name of this element.
*
* @param string $new_name the new name
*
* @return self
*/
public function setName(string $new_name): self

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -68,9 +67,10 @@ abstract class PartsContainingDBElement extends StructuralDBElement
/**
* Returns the parts associated with this element.
*
* @return Collection|Part[]
*/
public function getParts() : Collection
public function getParts(): Collection
{
return $this->parts;
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -44,9 +43,9 @@ declare(strict_types=1);
namespace App\Entity\Base;
use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Validator\Constraints\NoneOfItsChildren;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use App\Validator\Constraints\NoneOfItsChildren;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
@ -95,7 +94,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
/**
* @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.
* Useful if this element should be used only for grouping, sorting.
* @ORM\Column(type="boolean")
*/
protected $not_selectable = false;
@ -107,12 +106,9 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
/** @var string[] all names of all parent elements as a array of strings,
* the last array element is the name of the element itself
*
*/
private $full_path_strings;
public function __construct()
{
parent::__construct();
@ -127,19 +123,19 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
* Check if this element is a child of another element (recursive).
*
* @param StructuralDBElement $another_element the object to compare
* IMPORTANT: both objects to compare must be from the same class (for example two "Device" objects)!
* 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(StructuralDBElement $another_element) : bool
public function isChildOf(self $another_element): bool
{
$class_name = \get_class($this);
//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 (!is_a($another_element, $class_name) && !is_a($this, get_class($another_element))) {
if (!is_a($another_element, $class_name) && !is_a($this, \get_class($another_element))) {
throw new \InvalidArgumentException('isChildOf() only works for objects of the same type!');
}
@ -153,12 +149,13 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
}
/**
* Checks if this element is an root element (has no parent)
* Checks if this element is an root element (has no parent).
*
* @return bool True if the this element is an root element.
*/
public function isRoot() : bool
public function isRoot(): bool
{
return $this->parent === null;
return null === $this->parent;
}
/******************************************************************************
@ -180,6 +177,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
/**
* Get the comment of the element.
*
* @return string the comment
*/
public function getComment(): ?string
@ -194,21 +192,21 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
*
* @return int the level of this element (zero means a most top element
* [a subelement 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 !== null) {
if (0 === $this->level && null !== $this->parent) {
$element = $this->parent;
while ($element !== null) {
while (null !== $element) {
/** @var StructuralDBElement $element */
$element = $element->parent;
++$this->level;
}
}
return $this->level;
}
@ -218,12 +216,11 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
* @param string $delimeter the delimeter of the returned string
*
* @return string the full path (incl. the name of this element), delimeted by $delimeter
*
*/
public function getFullPath(string $delimeter = self::PATH_DELIMITER_ARROW): string
{
if (!\is_array($this->full_path_strings)) {
$this->full_path_strings = array();
$this->full_path_strings = [];
$this->full_path_strings[] = $this->getName();
$element = $this;
@ -233,7 +230,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
$element = $element->parent;
$this->full_path_strings[] = $element->getName();
//Decrement to prevent mem overflow.
$overflow--;
--$overflow;
}
$this->full_path_strings = array_reverse($this->full_path_strings);
@ -242,11 +239,11 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
return implode($delimeter, $this->full_path_strings);
}
/**
* Gets the path to this element (including the element itself)
* Gets the path to this element (including the element itself).
*
* @return self[] An array with all (recursivily) parent elements (including this one),
* ordered from the lowest levels (root node) first to the highest level (the element itself)
* ordered from the lowest levels (root node) first to the highest level (the element itself)
*/
public function getPathArray(): array
{
@ -254,7 +251,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
$tmp[] = $this;
//We only allow 20 levels depth
while (!end($tmp)->isRoot() && count($tmp) < 20) {
while (!end($tmp)->isRoot() && \count($tmp) < 20) {
$tmp[] = end($tmp)->parent;
}
@ -293,11 +290,13 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
******************************************************************************/
/**
* Sets the new parent object
* Sets the new parent object.
*
* @param self $new_parent The new parent object
*
* @return StructuralDBElement
*/
public function setParent(?self $new_parent) : self
public function setParent(?self $new_parent): self
{
/*
if ($new_parent->isChildOf($this)) {
@ -311,7 +310,9 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
/**
* Set the comment.
*
* @param string $new_comment the new comment
*
* @return StructuralDBElement
*/
public function setComment(?string $new_comment): self
@ -321,7 +322,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
return $this;
}
public function setChildren(array $element) : self
public function setChildren(array $element): self
{
$this->children = $element;
@ -329,16 +330,16 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
}
/**
* @param bool $not_selectable
* @return StructuralDBElement
*/
public function setNotSelectable(bool $not_selectable): StructuralDBElement
public function setNotSelectable(bool $not_selectable): self
{
$this->not_selectable = $not_selectable;
return $this;
}
public function clearChildren() : self
public function clearChildren(): self
{
$this->children = new ArrayCollection();

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,17 +17,14 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Base;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* A entity with these trait contains informations about, when it was created and edited last time
* @package App\Entity\Base
* A entity with these trait contains informations about, when it was created and edited last time.
*/
trait TimestampTrait
{
@ -80,4 +77,4 @@ trait TimestampTrait
$this->addedDate = new \DateTime('now');
}
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -52,7 +51,6 @@ declare(strict_types=1);
namespace App\Entity\Devices;
use App\Entity\Attachments\AttachmentTypeAttachment;
use App\Entity\Attachments\DeviceAttachment;
use App\Entity\Base\PartsContainingDBElement;
use Doctrine\Common\Collections\Collection;
@ -66,7 +64,6 @@ use Doctrine\ORM\Mapping as ORM;
*/
class Device extends PartsContainingDBElement
{
/**
* @var Collection|DeviceAttachment[]
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\DeviceAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
@ -137,8 +134,6 @@ class Device extends PartsContainingDBElement
* Set the order quantity.
*
* @param int $new_order_quantity the new order quantity
*
* @return self
*/
public function setOrderQuantity(int $new_order_quantity): self
{
@ -154,8 +149,6 @@ class Device extends PartsContainingDBElement
* Set the "order_only_missing_parts" attribute.
*
* @param bool $new_order_only_missing_parts the new "order_only_missing_parts" attribute
*
* @return self
*/
public function setOrderOnlyMissingParts(bool $new_order_only_missing_parts): self
{

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -90,7 +89,6 @@ class DevicePart extends DBElement
*/
protected $mountnames;
/**
* Returns the ID as an string, defined by the element class.
* This should have a form like P000014, for a part with ID 14.

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -56,7 +55,6 @@ use Doctrine\ORM\Mapping as ORM;
*/
class Category extends PartsContainingDBElement
{
/**
* @var Collection|CategoryAttachment[]
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\CategoryAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
@ -147,12 +145,12 @@ class Category extends PartsContainingDBElement
}
/**
* @param string $partname_hint
* @return Category
*/
public function setPartnameHint(string $partname_hint): Category
public function setPartnameHint(string $partname_hint): self
{
$this->partname_hint = $partname_hint;
return $this;
}
@ -165,12 +163,12 @@ class Category extends PartsContainingDBElement
}
/**
* @param string $partname_regex
* @return Category
*/
public function setPartnameRegex(string $partname_regex): Category
public function setPartnameRegex(string $partname_regex): self
{
$this->partname_regex = $partname_regex;
return $this;
}
@ -183,12 +181,12 @@ class Category extends PartsContainingDBElement
}
/**
* @param bool $disable_footprints
* @return Category
*/
public function setDisableFootprints(bool $disable_footprints): Category
public function setDisableFootprints(bool $disable_footprints): self
{
$this->disable_footprints = $disable_footprints;
return $this;
}
@ -201,12 +199,12 @@ class Category extends PartsContainingDBElement
}
/**
* @param bool $disable_manufacturers
* @return Category
*/
public function setDisableManufacturers(bool $disable_manufacturers): Category
public function setDisableManufacturers(bool $disable_manufacturers): self
{
$this->disable_manufacturers = $disable_manufacturers;
return $this;
}
@ -219,12 +217,12 @@ class Category extends PartsContainingDBElement
}
/**
* @param bool $disable_autodatasheets
* @return Category
*/
public function setDisableAutodatasheets(bool $disable_autodatasheets): Category
public function setDisableAutodatasheets(bool $disable_autodatasheets): self
{
$this->disable_autodatasheets = $disable_autodatasheets;
return $this;
}
@ -237,12 +235,12 @@ class Category extends PartsContainingDBElement
}
/**
* @param bool $disable_properties
* @return Category
*/
public function setDisableProperties(bool $disable_properties): Category
public function setDisableProperties(bool $disable_properties): self
{
$this->disable_properties = $disable_properties;
return $this;
}
@ -255,12 +253,12 @@ class Category extends PartsContainingDBElement
}
/**
* @param string $default_description
* @return Category
*/
public function setDefaultDescription(string $default_description): Category
public function setDefaultDescription(string $default_description): self
{
$this->default_description = $default_description;
return $this;
}
@ -273,14 +271,12 @@ class Category extends PartsContainingDBElement
}
/**
* @param string $default_comment
* @return Category
*/
public function setDefaultComment(string $default_comment): Category
public function setDefaultComment(string $default_comment): self
{
$this->default_comment = $default_comment;
return $this;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -52,7 +51,6 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\FootprintAttachment;
use App\Entity\Base\PartsContainingDBElement;
use Doctrine\Common\Collections\Collection;
@ -112,9 +110,10 @@ class Footprint extends PartsContainingDBElement
/**
* Returns the 3D Model associated with this footprint.
*
* @return FootprintAttachment|null
*/
public function getFootprint3d() : ?FootprintAttachment
public function getFootprint3d(): ?FootprintAttachment
{
return $this->footprint_3d;
}
@ -127,13 +126,13 @@ class Footprint extends PartsContainingDBElement
/**
* Sets the 3D Model associated with this footprint.
* @param FootprintAttachment|null $new_attachment
*
* @return Footprint
*/
public function setFootprint3d(?FootprintAttachment $new_attachment) : Footprint
public function setFootprint3d(?FootprintAttachment $new_attachment): self
{
$this->footprint_3d = $new_attachment;
return $this;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -52,7 +51,6 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\FootprintAttachment;
use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Base\Company;
use Doctrine\Common\Collections\Collection;
@ -72,7 +70,6 @@ class Manufacturer extends Company
*/
protected $attachments;
/**
* @ORM\OneToMany(targetEntity="Manufacturer", mappedBy="parent")
*/

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,13 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Parts;
use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Attachments\MeasurementUnitAttachment;
use App\Entity\Base\PartsContainingDBElement;
use Doctrine\Common\Collections\Collection;
@ -35,14 +32,12 @@ use Symfony\Component\Validator\Constraints as Assert;
* This unit represents the unit in which the amount of parts in stock are measured.
* This could be something like N, gramms, meters, etc...
*
* @package App\Entity
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
* @ORM\Table(name="`measurement_units`")
* @UniqueEntity("unit")
*/
class MeasurementUnit extends PartsContainingDBElement
{
/**
* @var Collection|MeasurementUnitAttachment[]
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\MeasurementUnitAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
@ -51,7 +46,7 @@ class MeasurementUnit extends PartsContainingDBElement
/**
* @var string The unit symbol that should be used for the Unit. This could be something like "", g (for gramms)
* or m (for meters).
* or m (for meters).
* @ORM\Column(type="string", name="unit", nullable=true)
* @Assert\Length(max=10)
*/
@ -59,14 +54,14 @@ class MeasurementUnit extends PartsContainingDBElement
/**
* @var bool Determines if the amount value associated with this unit should be treated as integer.
* Set to false, to measure continuous sizes likes masses or lengthes.
* Set to false, to measure continuous sizes likes masses or lengthes.
* @ORM\Column(type="boolean", name="is_integer")
*/
protected $is_integer = false;
/**
* @var bool Determines if the unit can be used with SI Prefixes (kilo, giga, milli, etc.).
* Useful for sizes like meters.
* Useful for sizes like meters.
* @ORM\Column(type="boolean", name="use_si_prefix")
*/
protected $use_si_prefix = false;
@ -92,11 +87,10 @@ class MeasurementUnit extends PartsContainingDBElement
* This should have a form like P000014, for a part with ID 14.
*
* @return string The ID as a string;
*
*/
public function getIDString(): string
{
return 'MU' . $this->getID();
return 'MU'.$this->getID();
}
/**
@ -109,11 +103,13 @@ class MeasurementUnit extends PartsContainingDBElement
/**
* @param string $unit
*
* @return MeasurementUnit
*/
public function setUnit(?string $unit): MeasurementUnit
public function setUnit(?string $unit): self
{
$this->unit = $unit;
return $this;
}
@ -126,12 +122,12 @@ class MeasurementUnit extends PartsContainingDBElement
}
/**
* @param bool $isInteger
* @return MeasurementUnit
*/
public function setIsInteger(bool $isInteger): MeasurementUnit
public function setIsInteger(bool $isInteger): self
{
$this->is_integer = $isInteger;
return $this;
}
@ -144,12 +140,12 @@ class MeasurementUnit extends PartsContainingDBElement
}
/**
* @param bool $usesSIPrefixes
* @return MeasurementUnit
*/
public function setUseSIPrefix(bool $usesSIPrefixes): MeasurementUnit
public function setUseSIPrefix(bool $usesSIPrefixes): self
{
$this->use_si_prefix = $usesSIPrefixes;
return $this;
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -54,9 +53,9 @@ namespace App\Entity\Parts;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Base\MasterAttachmentTrait;
use App\Entity\Devices\Device;
use App\Entity\Parts\PartTraits\AdvancedPropertyTrait;
use App\Entity\Base\MasterAttachmentTrait;
use App\Entity\Parts\PartTraits\BasicPropertyTrait;
use App\Entity\Parts\PartTraits\InstockTrait;
use App\Entity\Parts\PartTraits\ManufacturerTrait;
@ -64,7 +63,6 @@ use App\Entity\Parts\PartTraits\OrderTrait;
use App\Security\Annotations\ColumnSecurity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
@ -143,7 +141,7 @@ class Part extends AttachmentContainingDBElement
*/
public function getIDString(): string
{
return 'P' . sprintf('%06d', $this->getID());
return 'P'.sprintf('%06d', $this->getID());
}
/**
@ -152,11 +150,9 @@ class Part extends AttachmentContainingDBElement
* @return Device[] * all devices which uses this part as a one-dimensional array of Device objects
* (empty array if there are no ones)
* * the array is sorted by the devices names
*
*/
public function getDevices(): array
{
return $this->devices;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Parts;
use App\Entity\Base\DBElement;
use App\Entity\Base\TimestampTrait;
use App\Entity\Parts\PartTraits\InstockTrait;
@ -34,7 +32,7 @@ use Symfony\Component\Validator\Constraints as Assert;
/**
* This entity describes a lot where parts can be stored.
* It is the connection between a part and its store locations.
* @package App\Entity\Parts
*
* @ORM\Entity()
* @ORM\Table(name="part_lots")
* @ORM\HasLifecycleCallbacks()
@ -42,7 +40,6 @@ use Symfony\Component\Validator\Constraints as Assert;
*/
class PartLot extends DBElement
{
use TimestampTrait;
/**
@ -59,7 +56,7 @@ class PartLot extends DBElement
/**
* @var ?\DateTime Set a time until when the lot must be used.
* Set to null, if the lot can be used indefinitley.
* Set to null, if the lot can be used indefinitley.
* @ORM\Column(type="datetime", name="expiration_date", nullable=true)
*/
protected $expiration_date;
@ -86,7 +83,6 @@ class PartLot extends DBElement
*/
protected $instock_unknown = false;
/**
* @var float For continuos sizes (length, volume, etc.) the instock is saved here.
* @ORM\Column(type="float")
@ -95,7 +91,7 @@ class PartLot extends DBElement
protected $amount = 0;
/**
* @var boolean Determines if this lot was manually marked for refilling.
* @var bool Determines if this lot was manually marked for refilling.
* @ORM\Column(type="boolean")
*/
protected $needs_refill = false;
@ -105,21 +101,21 @@ class PartLot extends DBElement
* This should have a form like P000014, for a part with ID 14.
*
* @return string The ID as a string;
*
*/
public function getIDString(): string
{
return 'PL' . $this->getID();
return 'PL'.$this->getID();
}
/**
* Check if the current part lot is expired.
* This is the case, if the expiration date is greater the the current date.
*
* @return bool|null True, if the part lot is expired. Returns null, if no expiration date was set.
*/
public function isExpired(): ?bool
{
if ($this->expiration_date === null) {
if (null === $this->expiration_date) {
return null;
}
@ -129,6 +125,7 @@ class PartLot extends DBElement
/**
* Gets the description of the part lot. Similar to a "name" of the part lot.
*
* @return string
*/
public function getDescription(): string
@ -138,17 +135,19 @@ class PartLot extends DBElement
/**
* Sets the description of the part lot.
* @param string $description
*
* @return PartLot
*/
public function setDescription(string $description): PartLot
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
/**
* Gets the comment for this part lot.
*
* @return string
*/
public function getComment(): string
@ -158,17 +157,19 @@ class PartLot extends DBElement
/**
* Sets the comment for this part lot.
* @param string $comment
*
* @return PartLot
*/
public function setComment(string $comment): PartLot
public function setComment(string $comment): self
{
$this->comment = $comment;
return $this;
}
/**
* Gets the expiration date for the part lot. Returns null, if no expiration date was set.
*
* @return \DateTime|null
*/
public function getExpirationDate(): ?\DateTime
@ -178,17 +179,21 @@ class PartLot extends DBElement
/**
* Sets the expiration date for the part lot. Set to null, if the part lot does not expires.
*
* @param \DateTime $expiration_date
*
* @return PartLot
*/
public function setExpirationDate(?\DateTime $expiration_date): PartLot
public function setExpirationDate(?\DateTime $expiration_date): self
{
$this->expiration_date = $expiration_date;
return $this;
}
/**
* Gets the storage locatiion, where this part lot is stored.
*
* @return Storelocation|null The store location where this part is stored
*/
public function getStorageLocation(): ?Storelocation
@ -197,18 +202,20 @@ class PartLot extends DBElement
}
/**
* Sets the storage location, where this part lot is stored
* @param Storelocation|null $storage_location
* Sets the storage location, where this part lot is stored.
*
* @return PartLot
*/
public function setStorageLocation(?Storelocation $storage_location): PartLot
public function setStorageLocation(?Storelocation $storage_location): self
{
$this->storage_location = $storage_location;
return $this;
}
/**
* Return the part that is stored in this part lot.
*
* @return Part
*/
public function getPart(): Part
@ -218,12 +225,15 @@ class PartLot extends DBElement
/**
* Sets the part that is stored in this part lot.
*
* @param Part|InstockTrait $part
*
* @return PartLot
*/
public function setPart(Part $part): PartLot
public function setPart(Part $part): self
{
$this->part = $part;
return $this;
}
@ -239,12 +249,13 @@ class PartLot extends DBElement
/**
* Set the unknown instock status of this part lot.
* @param bool $instock_unknown
*
* @return PartLot
*/
public function setInstockUnknown(bool $instock_unknown): PartLot
public function setInstockUnknown(bool $instock_unknown): self
{
$this->instock_unknown = $instock_unknown;
return $this;
}
@ -256,17 +267,17 @@ class PartLot extends DBElement
if ($this->part instanceof Part && !$this->part->useFloatAmount()) {
return round($this->amount);
}
return (float) $this->amount;
}
public function setAmount(float $new_amount): PartLot
public function setAmount(float $new_amount): self
{
$this->amount = $new_amount;
$this->amount = $new_amount;
return $this;
}
/**
* @return bool
*/
@ -276,14 +287,12 @@ class PartLot extends DBElement
}
/**
* @param bool $needs_refill
* @return PartLot
*/
public function setNeedsRefill(bool $needs_refill): PartLot
public function setNeedsRefill(bool $needs_refill): self
{
$this->needs_refill = $needs_refill;
return $this;
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,18 +17,15 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Parts\PartTraits;
use App\Entity\Parts\Part;
use App\Security\Annotations\ColumnSecurity;
/**
* Advanced properties of a part, not related to a more specific group.
* @package App\Entity\Parts\PartTraits
*/
trait AdvancedPropertyTrait
{
@ -56,6 +53,7 @@ trait AdvancedPropertyTrait
/**
* Checks if this part is marked, for that it needs further review.
*
* @return bool
*/
public function isNeedsReview(): bool
@ -65,18 +63,19 @@ trait AdvancedPropertyTrait
/**
* Sets the "needs review" status of this part.
* @param bool $needs_review
*
* @return Part|self
*/
public function setNeedsReview(bool $needs_review): self
{
$this->needs_review = $needs_review;
return $this;
}
/**
* Gets a comma separated list, of tags, that are assigned to this part
* Gets a comma separated list, of tags, that are assigned to this part.
*
* @return string
*/
public function getTags(): string
@ -86,18 +85,20 @@ trait AdvancedPropertyTrait
/**
* Sets a comma separated list of tags, that are assigned to this part.
* @param string $tags
*
* @return self
*/
public function setTags(string $tags): self
{
$this->tags = $tags;
return $this;
}
/**
* Returns the mass of a single part unit.
* Returns null, if the mass is unknown/not set yet
* Returns null, if the mass is unknown/not set yet.
*
* @return float|null
*/
public function getMass(): ?float
@ -108,14 +109,13 @@ trait AdvancedPropertyTrait
/**
* Sets the mass of a single part unit.
* Sett to null, if the mass is unknown.
* @param float|null $mass
*
* @return self
*/
public function setMass(?float $mass): self
{
$this->mass = $mass;
return $this;
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Parts\PartTraits;
use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Part;
@ -60,7 +58,7 @@ trait BasicPropertyTrait
/**
* @var Category The category this part belongs too (e.g. Resistors). Use tags, for more complex grouping.
* Every part must have a category.
* Every part must have a category.
* @ORM\ManyToOne(targetEntity="Category", inversedBy="parts")
* @ORM\JoinColumn(name="id_category", referencedColumnName="id", nullable=false)
* @ColumnSecurity(prefix="category", type="App\Entity\Parts\Category")
@ -80,6 +78,7 @@ trait BasicPropertyTrait
/**
* Get the description string like it is saved in the database.
* This can contain BBCode, it is not parsed yet.
*
* @return string the description
*/
public function getDescription(): string
@ -89,6 +88,7 @@ trait BasicPropertyTrait
/**
* Get the comment associated with this part.
*
* @return string The raw/unparsed comment
*/
public function getComment(): string
@ -99,6 +99,7 @@ trait BasicPropertyTrait
/**
* Get if this part is visible.
* This property is not used yet.
*
* @return bool true if this part is visible
* false if this part isn't visible
*/
@ -109,6 +110,7 @@ trait BasicPropertyTrait
/**
* Check if this part is a favorite.
*
* @return bool * true if this part is a favorite
* * false if this part is not a favorite.
*/
@ -117,10 +119,10 @@ trait BasicPropertyTrait
return $this->favorite;
}
/**
* Get the category of this part (e.g. Resistors).
* There is always a category, for each part!
*
* @return Category the category of this part
*/
public function getCategory(): ?Category
@ -129,7 +131,8 @@ trait BasicPropertyTrait
}
/**
* Gets the Footprint of this part (e.g. DIP8)
* Gets the Footprint of this part (e.g. DIP8).
*
* @return Footprint|null The footprint of this part. Null if this part should no have a footprint.
*/
public function getFootprint(): ?Footprint
@ -139,36 +142,44 @@ trait BasicPropertyTrait
/**
* Sets the description of this part.
*
* @param string $new_description the new description
*
* @return self
*/
public function setDescription(?string $new_description): self
{
$this->description = $new_description;
return $this;
}
/**
* Sets the comment property of this part.
*
* @param string $new_comment the new comment
*
* @return self
*/
public function setComment(string $new_comment): self
{
$this->comment = $new_comment;
return $this;
}
/**
* Set the category of this Part.
* The category property is required for every part, so you can not pass null like the other properties (footprints)
* The category property is required for every part, so you can not pass null like the other properties (footprints).
*
* @param Category $category The new category of this part
*
* @return self
*/
public function setCategory(Category $category): self
{
$this->category = $category;
return $this;
}
@ -183,6 +194,7 @@ trait BasicPropertyTrait
public function setFootprint(?Footprint $new_footprint): self
{
$this->footprint = $new_footprint;
return $this;
}
@ -197,7 +209,7 @@ trait BasicPropertyTrait
public function setFavorite(bool $new_favorite_status): self
{
$this->favorite = $new_favorite_status;
return $this;
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Parts\PartTraits;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\PartLot;
use App\Security\Annotations\ColumnSecurity;
@ -30,7 +28,6 @@ use Doctrine\Common\Collections\Collection;
/**
* This trait collects all aspects of a part related to instock, part lots.
* @package App\Entity\Parts\PartTraits
*/
trait InstockTrait
{
@ -44,7 +41,7 @@ trait InstockTrait
/**
* @var float The minimum amount of the part that has to be instock, otherwise more is ordered.
* Given in the partUnit.
* Given in the partUnit.
* @ORM\Column(type="float")
* @Assert\PositiveOrZero()
* @ColumnSecurity(prefix="mininstock", type="integer")
@ -61,9 +58,10 @@ trait InstockTrait
/**
* Get all part lots where this part is stored.
*
* @return PartLot[]|Collection
*/
public function getPartLots() : Collection
public function getPartLots(): Collection
{
return $this->partLots;
}
@ -71,30 +69,35 @@ trait InstockTrait
/**
* Adds the given part lot, to the list of part lots.
* The part lot is assigned to this part.
* @param PartLot $lot
*
* @return self
*/
public function addPartLot(PartLot $lot): self
{
$lot->setPart($this);
$this->partLots->add($lot);
return $this;
}
/**
* Removes the given part lot from the list of part lots.
*
* @param PartLot $lot The part lot that should be deleted.
*
* @return self
*/
public function removePartLot(PartLot $lot): self
{
$this->partLots->removeElement($lot);
return $this;
}
/**
* Gets the measurement unit in which the part's amount should be measured.
* Returns null if no specific unit was that. That means the parts are measured simply in quantity numbers.
*
* @return MeasurementUnit|null
*/
public function getPartUnit(): ?MeasurementUnit
@ -105,18 +108,19 @@ trait InstockTrait
/**
* Sets the measurement unit in which the part's amount should be measured.
* Set to null, if the part should be measured in quantities.
* @param MeasurementUnit|null $partUnit
*
* @return self
*/
public function setPartUnit(?MeasurementUnit $partUnit): self
{
$this->partUnit = $partUnit;
return $this;
}
/**
* Get the count of parts which must be in stock at least.
* If a integer-based part unit is selected, the value will be rounded to integers
* If a integer-based part unit is selected, the value will be rounded to integers.
*
* @return float count of parts which must be in stock at least
*/
@ -132,6 +136,7 @@ trait InstockTrait
/**
* Checks if this part uses the float amount .
* This setting is based on the part unit (see MeasurementUnit->isInteger()).
*
* @return bool True if the float amount field should be used. False if the integer instock field should be used.
*/
public function useFloatAmount(): bool
@ -146,10 +151,11 @@ trait InstockTrait
/**
* Returns the summed amount of this part (over all part lots)
* Part Lots that have unknown value or are expired, are not used for this value
* Part Lots that have unknown value or are expired, are not used for this value.
*
* @return float The amount of parts given in partUnit
*/
public function getAmountSum() : float
public function getAmountSum(): float
{
//TODO: Find a method to do this natively in SQL, the current method could be a bit slow
$sum = 0;
@ -172,12 +178,15 @@ trait InstockTrait
/**
* Set the minimum amount of parts that have to be instock.
* See getPartUnit() for the associated unit.
*
* @param float $new_minamount the new count of parts which should be in stock at least
*
* @return self
*/
public function setMinAmount(float $new_minamount): self
{
$this->minamount = $new_minamount;
return $this;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Parts\PartTraits;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Part;
use App\Security\Annotations\ColumnSecurity;
@ -30,7 +28,6 @@ use App\Validator\Constraints\Selectable;
/**
* In this trait all manufacturer related properties of a part are collected (like MPN, manufacturer URL).
* @package App\Entity\Parts\PartTraits
*/
trait ManufacturerTrait
{
@ -70,6 +67,7 @@ trait ManufacturerTrait
* Get the link to the website of the article on the manufacturers website
* When no this part has no explicit url set, then it is tried to generate one from the Manufacturer of this part
* automatically.
*
* @return string the link to the article
*/
public function getManufacturerProductUrl(): string
@ -87,6 +85,7 @@ trait ManufacturerTrait
/**
* Similar to getManufacturerProductUrl, but here only the database value is returned.
*
* @return string The manufacturer url saved in DB for this part.
*/
public function getCustomProductURL(): string
@ -103,7 +102,8 @@ trait ManufacturerTrait
* * "active": Part is in production and will be for the forseeable future
* * "nrfnd": Not recommended for new designs.
* * "eol": Part will become discontinued soon
* * "discontinued": Part is obsolete/discontinued by the manufacturer
* * "discontinued": Part is obsolete/discontinued by the manufacturer.
*
* @return string
*/
public function getManufacturingStatus(): ?string
@ -114,12 +114,13 @@ trait ManufacturerTrait
/**
* Sets the manufacturing status for this part
* See getManufacturingStatus() for valid values.
* @param string $manufacturing_status
*
* @return Part
*/
public function setManufacturingStatus(string $manufacturing_status): self
{
$this->manufacturing_status = $manufacturing_status;
return $this;
}
@ -133,9 +134,9 @@ trait ManufacturerTrait
return $this->manufacturer;
}
/**
* Returns the assigned manufacturer product number (MPN) for this part.
*
* @return string
*/
public function getManufacturerProductNumber(): string
@ -145,19 +146,22 @@ trait ManufacturerTrait
/**
* Sets the manufacturer product number (MPN) for this part.
* @param string $manufacturer_product_number
*
* @return Part
*/
public function setManufacturerProductNumber(string $manufacturer_product_number): self
{
$this->manufacturer_product_number = $manufacturer_product_number;
return $this;
}
/**
* Sets the URL to the manufacturer site about this Part.
* Set to "" if this part should use the automatically URL based on its manufacturer.
*
* @param string $new_url The new url
*
* @return self
*/
public function setManufacturerProductURL(string $new_url): self
@ -181,5 +185,4 @@ trait ManufacturerTrait
return $this;
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\Parts\PartTraits;
use App\Entity\Parts\Part;
use App\Entity\PriceInformations\Orderdetail;
use App\Security\Annotations\ColumnSecurity;
@ -30,7 +28,6 @@ use Doctrine\Common\Collections\Collection;
/**
* This trait collects all aspects of a part related to orders and priceinformations.
* @package App\Entity\Parts\PartTraits
*/
trait OrderTrait
{
@ -67,6 +64,7 @@ trait OrderTrait
/**
* Get the selected order orderdetails of this part.
*
* @return Orderdetail the selected order orderdetails
*/
public function getOrderOrderdetails(): ?Orderdetail
@ -76,6 +74,7 @@ trait OrderTrait
/**
* Get the order quantity of this part.
*
* @return int the order quantity
*/
public function getOrderQuantity(): int
@ -99,11 +98,10 @@ trait OrderTrait
* @param bool $hide_obsolete If true, obsolete orderdetails will NOT be returned
*
* @return Collection|Orderdetail[] * all orderdetails as a one-dimensional array of Orderdetails objects
* (empty array if there are no ones)
* * the array is sorted by the suppliers names / minimum order quantity
*
* (empty array if there are no ones)
* * the array is sorted by the suppliers names / minimum order quantity
*/
public function getOrderdetails(bool $hide_obsolete = false) : Collection
public function getOrderdetails(bool $hide_obsolete = false): Collection
{
//If needed hide the obsolete entries
if ($hide_obsolete) {
@ -123,38 +121,42 @@ trait OrderTrait
/**
* Adds the given orderdetail to list of orderdetails.
* The orderdetail is assigned to this part.
*
* @param Orderdetail $orderdetail The orderdetail that should be added.
*
* @return self
*/
public function addOrderdetail(Orderdetail $orderdetail) : self
public function addOrderdetail(Orderdetail $orderdetail): self
{
$orderdetail->setPart($this);
$this->orderdetails->add($orderdetail);
return $this;
}
/**
* Removes the given orderdetail from the list of orderdetails.
* @param Orderdetail $orderdetail
*
* @return OrderTrait
*/
public function removeOrderdetail(Orderdetail $orderdetail) : self
public function removeOrderdetail(Orderdetail $orderdetail): self
{
$this->orderdetails->removeElement($orderdetail);
return $this;
}
/**
* Set the "manual_order" attribute.
*
* @param bool $new_manual_order the new "manual_order" attribute
* @param int $new_order_quantity the new order quantity
* @param bool $new_manual_order the new "manual_order" attribute
* @param int $new_order_quantity the new order quantity
* @param Orderdetail|null $new_order_orderdetail * the ID of the new order orderdetails
* * or Zero for "no order orderdetails"
* * or NULL for automatic order orderdetails
* (if the part has exactly one orderdetails,
* set this orderdetails as order orderdetails.
* Otherwise, set "no order orderdetails")
* * or Zero for "no order orderdetails"
* * or NULL for automatic order orderdetails
* (if the part has exactly one orderdetails,
* set this orderdetails as order orderdetails.
* Otherwise, set "no order orderdetails")
*
* @return self
*/
@ -183,7 +185,7 @@ trait OrderTrait
{
$all_orderdetails = $this->getOrderdetails();
if (0 === count($all_orderdetails)) {
if (0 === \count($all_orderdetails)) {
return false;
}
@ -195,5 +197,4 @@ trait OrderTrait
return true;
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -52,7 +51,6 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Attachments\StorelocationAttachment;
use App\Entity\Base\PartsContainingDBElement;
use Doctrine\Common\Collections\Collection;
@ -66,7 +64,6 @@ use Doctrine\ORM\Mapping as ORM;
*/
class Storelocation extends PartsContainingDBElement
{
/**
* @var Collection|StorelocationAttachment[]
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\StorelocationAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
@ -148,12 +145,12 @@ class Storelocation extends PartsContainingDBElement
}
/**
* @param bool $only_single_part
* @return Storelocation
*/
public function setOnlySinglePart(bool $only_single_part): Storelocation
public function setOnlySinglePart(bool $only_single_part): self
{
$this->only_single_part = $only_single_part;
return $this;
}
@ -168,12 +165,12 @@ class Storelocation extends PartsContainingDBElement
}
/**
* @param bool $limit_to_existing_parts
* @return Storelocation
*/
public function setLimitToExistingParts(bool $limit_to_existing_parts): Storelocation
public function setLimitToExistingParts(bool $limit_to_existing_parts): self
{
$this->limit_to_existing_parts = $limit_to_existing_parts;
return $this;
}
@ -186,17 +183,15 @@ class Storelocation extends PartsContainingDBElement
}
/**
* @param MeasurementUnit|null $storage_type
* @return Storelocation
*/
public function setStorageType(?MeasurementUnit $storage_type): Storelocation
public function setStorageType(?MeasurementUnit $storage_type): self
{
$this->storage_type = $storage_type;
return $this;
}
/********************************************************************************
*
* Setters
@ -211,9 +206,10 @@ class Storelocation extends PartsContainingDBElement
*
* @param bool $new_is_full * true means that the storelocation is full
* * false means that the storelocation isn't full
*
* @return Storelocation
*/
public function setIsFull(bool $new_is_full): Storelocation
public function setIsFull(bool $new_is_full): self
{
$this->is_full = $new_is_full;

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -52,7 +51,6 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Base\Company;
use App\Entity\PriceInformations\Currency;
@ -93,7 +91,7 @@ class Supplier extends Company
/**
* @var Currency|null The currency that should be used by default for order informations with this supplier.
* Set to null, to use global base currency.
* Set to null, to use global base currency.
* @ORM\ManyToOne(targetEntity="App\Entity\PriceInformations\Currency")
* @ORM\JoinColumn(name="default_currency_id", referencedColumnName="id", nullable=true)
* @Selectable()
@ -101,7 +99,7 @@ class Supplier extends Company
protected $default_currency;
/**
* @var float|null The shipping costs that have to be paid, when ordering via this supplier.
* @var float|null the shipping costs that have to be paid, when ordering via this supplier
* @ORM\Column(name="shipping_costs", nullable=true, type="decimal", precision=11, scale=5)
* @Assert\PositiveOrZero()
*/
@ -118,45 +116,48 @@ class Supplier extends Company
/**
* Gets the currency that should be used by default, when creating a orderdetail with this supplier.
*
* @return ?Currency
*/
public function getDefaultCurrency() : ?Currency
public function getDefaultCurrency(): ?Currency
{
return $this->default_currency;
}
/**
* Sets the default currency.
*
* @param ?Currency $default_currency
* @return Supplier
*/
public function setDefaultCurrency(?Currency $default_currency) : Supplier
public function setDefaultCurrency(?Currency $default_currency): self
{
$this->default_currency = $default_currency;
return $this;
}
/**
* Gets the shipping costs for an order with this supplier, given in base currency.
*
* @return string|null A bcmath string with the shipping costs
*/
public function getShippingCosts() : ?string
public function getShippingCosts(): ?string
{
return $this->shipping_costs;
}
/**
* Sets the shipping costs for an order with this supplier.
* @param string|null $shipping_costs A bcmath string with the shipping costs.
* @return Supplier
*
* @param string|null $shipping_costs a bcmath string with the shipping costs
*/
public function setShippingCosts(?string $shipping_costs) : Supplier
public function setShippingCosts(?string $shipping_costs): self
{
$this->shipping_costs = $shipping_costs;
return $this;
}
/**
* Returns the ID as an string, defined by the element class.
* This should have a form like P000014, for a part with ID 14.

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,14 +17,11 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\PriceInformations;
use App\Entity\Attachments\CurrencyAttachment;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Base\StructuralDBElement;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@ -33,14 +30,13 @@ use Symfony\Component\Validator\Constraints as Assert;
/**
* This entity describes a currency that can be used for price informations.
* @package App\Entity
*
* @UniqueEntity("iso_code")
* @ORM\Entity()
* @ORM\Table(name="currencies")
*/
class Currency extends StructuralDBElement
{
public const PRICE_SCALE = 5;
/**
@ -58,7 +54,7 @@ class Currency extends StructuralDBElement
/**
* @var string|null The exchange rate between this currency and the base currency
* (how many base units the current currency is worth)
* (how many base units the current currency is worth)
* @ORM\Column(type="decimal", precision=11, scale=5, nullable=true)
* @Assert\Positive()
*/
@ -76,7 +72,8 @@ class Currency extends StructuralDBElement
protected $parent;
/**
* Returns the 3 letter ISO code of this currency
* Returns the 3 letter ISO code of this currency.
*
* @return string
*/
public function getIsoCode(): ?string
@ -86,23 +83,26 @@ class Currency extends StructuralDBElement
/**
* @param string $iso_code
*
* @return Currency
*/
public function setIsoCode(?string $iso_code): Currency
public function setIsoCode(?string $iso_code): self
{
$this->iso_code = $iso_code;
return $this;
}
/**
* Returns the inverse exchange rate (how many of the current currency the base unit is worth)
* Returns the inverse exchange rate (how many of the current currency the base unit is worth).
*
* @return string|null
*/
public function getInverseExchangeRate(): ?string
{
$tmp = $this->getExchangeRate();
if ($tmp === null || $tmp === "0") {
if (null === $tmp || '0' === $tmp) {
return null;
}
@ -111,7 +111,8 @@ class Currency extends StructuralDBElement
/**
* Returns The exchange rate between this currency and the base currency
* (how many base units the current currency is worth)
* (how many base units the current currency is worth).
*
* @return string|null
*/
public function getExchangeRate(): ?string
@ -120,25 +121,23 @@ class Currency extends StructuralDBElement
}
/**
* @param string|null $exchange_rate
* @return Currency
*/
public function setExchangeRate(?string $exchange_rate): Currency
public function setExchangeRate(?string $exchange_rate): self
{
$this->exchange_rate = $exchange_rate;
return $this;
}
/**
* Returns the ID as an string, defined by the element class.
* This should have a form like P000014, for a part with ID 14.
*
* @return string The ID as a string;
*
*/
public function getIDString(): string
{
return 'C' . $this->getID();
return 'C'.$this->getID();
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -193,7 +192,7 @@ class Orderdetail extends DBElement
return $this->supplier_product_url;
}
if ($this->getSupplier() === null) {
if (null === $this->getSupplier()) {
return '';
}
@ -204,7 +203,7 @@ class Orderdetail extends DBElement
* Get all pricedetails.
*
* @return Pricedetail[]|Collection all pricedetails as a one-dimensional array of Pricedetails objects,
* sorted by minimum discount quantity
* sorted by minimum discount quantity
*/
public function getPricedetails(): Collection
{
@ -212,36 +211,41 @@ class Orderdetail extends DBElement
}
/**
* Adds an pricedetail to this orderdetail
* Adds an pricedetail to this orderdetail.
*
* @param Pricedetail $pricedetail The pricedetail to add
*
* @return Orderdetail
*/
public function addPricedetail(Pricedetail $pricedetail) : Orderdetail
public function addPricedetail(Pricedetail $pricedetail): self
{
$pricedetail->setOrderdetail($this);
$this->pricedetails->add($pricedetail);
return $this;
}
/**
* Removes an pricedetail from this orderdetail
* @param Pricedetail $pricedetail
* Removes an pricedetail from this orderdetail.
*
* @return Orderdetail
*/
public function removePricedetail(Pricedetail $pricedetail) : Orderdetail
public function removePricedetail(Pricedetail $pricedetail): self
{
$this->pricedetails->removeElement($pricedetail);
return $this;
}
/**
* Find the pricedetail that is correct for the desired amount (the one with the greatest discount value with a
* minimum order amount of the wished quantity)
* @param float $quantity this is the quantity to choose the correct pricedetails
* minimum order amount of the wished quantity).
*
* @param float $quantity this is the quantity to choose the correct pricedetails
*
* @return Pricedetail|null: the price as a bcmath string. Null if there are no orderdetails for the given quantity
*/
public function findPriceForQty(float $quantity = 1) : ?Pricedetail
public function findPriceForQty(float $quantity = 1): ?Pricedetail
{
if ($quantity <= 0) {
return null;
@ -269,30 +273,34 @@ class Orderdetail extends DBElement
*********************************************************************************/
/**
* Sets a new part with which this orderdetail is associated
* @param Part $part
* Sets a new part with which this orderdetail is associated.
*
* @return Orderdetail
*/
public function setPart(Part $part) : Orderdetail
public function setPart(Part $part): self
{
$this->part = $part;
return $this;
}
/**
* Sets the new supplier associated with this orderdetail.
* @param Supplier $new_supplier
*
* @return Orderdetail
*/
public function setSupplier(Supplier $new_supplier) : Orderdetail
public function setSupplier(Supplier $new_supplier): self
{
$this->supplier = $new_supplier;
return $this;
}
/**
* Set the supplier part-nr.
*
* @param string $new_supplierpartnr the new supplier-part-nr
*
* @return Orderdetail
* @return Orderdetail
*/
@ -305,7 +313,9 @@ class Orderdetail extends DBElement
/**
* Set if the part is obsolete at the supplier of that orderdetails.
*
* @param bool $new_obsolete true means that this part is obsolete
*
* @return Orderdetail
* @return Orderdetail
*/
@ -319,10 +329,12 @@ class Orderdetail extends DBElement
/**
* Sets the custom product supplier URL for this order detail.
* Set this to "", if the function getSupplierProductURL should return the automatic generated URL.
*
* @param $new_url string The new URL for the supplier URL.
*
* @return Orderdetail
*/
public function setSupplierProductUrl(string $new_url) : Orderdetail
public function setSupplierProductUrl(string $new_url): self
{
//Only change the internal URL if it is not the auto generated one
if ($new_url === $this->supplier->getAutoProductUrl($this->getSupplierPartNr())) {

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -69,7 +68,6 @@ use Symfony\Component\Validator\Constraints as Assert;
*/
class Pricedetail extends DBElement
{
public const PRICE_PRECISION = 5;
use TimestampTrait;
@ -91,7 +89,7 @@ class Pricedetail extends DBElement
/**
* @var ?Currency The currency used for the current price information.
* If this is null, the global base unit is assumed.
* If this is null, the global base unit is assumed.
* @ORM\ManyToOne(targetEntity="Currency")
* @ORM\JoinColumn(name="id_currency", referencedColumnName="id", nullable=true)
* @Selectable()
@ -142,9 +140,10 @@ class Pricedetail extends DBElement
/**
* Returns the price associated with this pricedetail.
* It is given in current currency and for the price related quantity.
*
* @return string The price as string, like returned raw from DB.
*/
public function getPrice() : string
public function getPrice(): string
{
return $this->price;
}
@ -152,18 +151,19 @@ class Pricedetail extends DBElement
/**
* Get the price for a single unit in the currency associated with this price detail.
*
* @param float|string $multiplier The returned price (float or string) will be multiplied
* with this multiplier.
* @param float|string $multiplier The returned price (float or string) will be multiplied
* with this multiplier.
*
* You will get the price for $multiplier parts. If you want the price which is stored
* in the database, you have to pass the "price_related_quantity" count as $multiplier.
*
* @return string the price as a bcmath string
* @return string the price as a bcmath string
*/
public function getPricePerUnit($multiplier = 1.0) : string
public function getPricePerUnit($multiplier = 1.0): string
{
$multiplier = (string) $multiplier;
$tmp = bcmul($this->price, $multiplier, static::PRICE_PRECISION);
return bcdiv($tmp, (string) $this->price_related_quantity, static::PRICE_PRECISION);
//return ($this->price * $multiplier) / $this->price_related_quantity;
}
@ -180,10 +180,12 @@ class Pricedetail extends DBElement
*/
public function getPriceRelatedQuantity(): float
{
if ($this->orderdetail && $this->orderdetail->getPart() && !$this->orderdetail->getPart()->useFloatAmount()) {
if ($this->orderdetail && $this->orderdetail->getPart() && !$this->orderdetail->getPart()->useFloatAmount()) {
$tmp = round($this->price_related_quantity);
return $tmp < 1 ? 1 : $tmp;
}
return $this->price_related_quantity;
}
@ -203,6 +205,7 @@ class Pricedetail extends DBElement
{
if ($this->orderdetail && $this->orderdetail->getPart() && !$this->orderdetail->getPart()->useFloatAmount()) {
$tmp = round($this->min_discount_quantity);
return $tmp < 1 ? 1 : $tmp;
}
@ -212,6 +215,7 @@ class Pricedetail extends DBElement
/**
* Returns the currency associated with this price information.
* Returns null, if no specific currency is selected and the global base currency should be assumed.
*
* @return Currency|null
*/
public function getCurrency(): ?Currency
@ -227,24 +231,26 @@ class Pricedetail extends DBElement
/**
* Sets the orderdetail to which this pricedetail belongs to.
* @param Orderdetail $orderdetail
*
* @return $this
*/
public function setOrderdetail(Orderdetail $orderdetail) : self
public function setOrderdetail(Orderdetail $orderdetail): self
{
$this->orderdetail = $orderdetail;
return $this;
}
/**
* Sets the currency associated with the price informations.
* Set to null, to use the global base currency.
* @param Currency|null $currency
*
* @return Pricedetail
*/
public function setCurrency(?Currency $currency): Pricedetail
public function setCurrency(?Currency $currency): self
{
$this->currency = $currency;
return $this;
}
@ -259,7 +265,7 @@ class Pricedetail extends DBElement
*
* @return self
*/
public function setPrice(string $new_price): Pricedetail
public function setPrice(string $new_price): self
{
//Assert::natural($new_price, 'The new price must be positive! Got %s!');
@ -322,6 +328,6 @@ class Pricedetail extends DBElement
*/
public function getIDString(): string
{
return 'PD' . sprintf('%06d', $this->getID());
return 'PD'.sprintf('%06d', $this->getID());
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,13 +17,11 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\UserSystem;
use App\Entity\Attachments\GroupAttachment;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Base\StructuralDBElement;
use App\Security\Interfaces\HasPermissionsInterface;
use App\Validator\Constraints\ValidPermission;
@ -38,7 +36,6 @@ use Doctrine\ORM\Mapping as ORM;
*/
class Group extends StructuralDBElement implements HasPermissionsInterface
{
/**
* @var Collection|GroupAttachment[]
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\ManufacturerAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Entity\UserSystem;
@ -293,10 +292,12 @@ class PermissionsEmbed
/**
* Checks whether a permission with the given name is valid for this object.
* @param string $permission_name The name of the permission which should be checked for.
* @return bool True if the permission is existing on this object.
*
* @param string $permission_name the name of the permission which should be checked for
*
* @return bool true if the permission is existing on this object
*/
public function isValidPermissionName(string $permission_name) : bool
public function isValidPermissionName(string $permission_name): bool
{
return isset($this->$permission_name);
}
@ -304,8 +305,8 @@ class PermissionsEmbed
/**
* Returns the bit pair value of the given permission.
*
* @param string $permission_name The name of the permission, for which the bit pair should be returned.
* @param int $bit_n The (lower) bit number of the bit pair, which should be read.
* @param string $permission_name the name of the permission, for which the bit pair should be returned
* @param int $bit_n the (lower) bit number of the bit pair, which should be read
*
* @return int The value of the bit pair. Compare to the INHERIT, ALLOW, and DISALLOW consts in this class.
*/
@ -323,8 +324,8 @@ class PermissionsEmbed
/**
* Returns the value of the operation for the given permission.
*
* @param string $permission_name The name of the permission, for which the operation should be returned.
* @param int $bit_n The (lower) bit number of the bit pair for the operation.
* @param string $permission_name the name of the permission, for which the operation should be returned
* @param int $bit_n the (lower) bit number of the bit pair for the operation
*
* @return bool|null The value of the operation. True, if the given operation is allowed, false if disallowed
* and null if it should inherit from parent.
@ -345,19 +346,21 @@ class PermissionsEmbed
/**
* Sets the value of the given permission and operation.
* @param string $permission_name The name of the permission, for which the bit pair should be written.
* @param int $bit_n The (lower) bit number of the bit pair, which should be written.
* @param bool|null $new_value The new value for the operation:
* True, if the given operation is allowed, false if disallowed
* and null if it should inherit from parent.
* @return PermissionsEmbed The instance itself.
*
* @param string $permission_name the name of the permission, for which the bit pair should be written
* @param int $bit_n the (lower) bit number of the bit pair, which should be written
* @param bool|null $new_value the new value for the operation:
* True, if the given operation is allowed, false if disallowed
* and null if it should inherit from parent
*
* @return PermissionsEmbed the instance itself
*/
public function setPermissionValue(string $permission_name, int $bit_n, ?bool $new_value) : self
public function setPermissionValue(string $permission_name, int $bit_n, ?bool $new_value): self
{
//Determine which bit value the given value is.
if ($new_value === true) {
if (true === $new_value) {
$bit_value = static::ALLOW;
} elseif ($new_value === false) {
} elseif (false === $new_value) {
$bit_value = static::DISALLOW;
} else {
$bit_value = static::INHERIT;
@ -370,12 +373,14 @@ class PermissionsEmbed
/**
* Sets the bit value of the given permission and operation.
* @param string $permission_name The name of the permission, for which the bit pair should be written.
* @param int $bit_n The (lower) bit number of the bit pair, which should be written.
* @param int $new_value The new (bit) value of the bit pair, which should be written.
* @return PermissionsEmbed The instance itself.
*
* @param string $permission_name the name of the permission, for which the bit pair should be written
* @param int $bit_n the (lower) bit number of the bit pair, which should be written
* @param int $new_value the new (bit) value of the bit pair, which should be written
*
* @return PermissionsEmbed the instance itself
*/
public function setBitValue(string $permission_name, int $bit_n, int $new_value) : self
public function setBitValue(string $permission_name, int $bit_n, int $new_value): self
{
if (!$this->isValidPermissionName($permission_name)) {
throw new \InvalidArgumentException('No permission with the given name is existing!');
@ -387,12 +392,14 @@ class PermissionsEmbed
}
/**
* Returns the given permission as raw int (all bit at once)
* Returns the given permission as raw int (all bit at once).
*
* @param string $permission_name The name of the permission, which should be retrieved.
* If this is not existing an exception is thrown.
* @return int The raw permission value.
* If this is not existing an exception is thrown.
*
* @return int the raw permission value
*/
public function getRawPermissionValue(string $permission_name) : int
public function getRawPermissionValue(string $permission_name): int
{
if (!$this->isValidPermissionName($permission_name)) {
throw new \InvalidArgumentException('No permission with the given name is existing!');
@ -403,30 +410,33 @@ class PermissionsEmbed
/**
* Sets the given permission to the value.
* @param string $permission_name The name of the permission to that should be set.
* @param int $value The new value of the permsission
*
* @param string $permission_name the name of the permission to that should be set
* @param int $value The new value of the permsission
*
* @return $this
*/
public function setRawPermissionValue(string $permission_name, int $value) : self
public function setRawPermissionValue(string $permission_name, int $value): self
{
if (!$this->isValidPermissionName($permission_name)) {
throw new \InvalidArgumentException(
sprintf('No permission with the given name %s is existing!', $permission_name)
);
throw new \InvalidArgumentException(sprintf('No permission with the given name %s is existing!', $permission_name));
}
$this->$permission_name = $value;
return $this;
}
/**
* Sets multiple permissions at once.
* @param array $values An array in the form ['perm_name' => $value], containing the new data
* @param array|null $values2 If this array is not null, the first array will treated of list of perm names,
* and this array as an array of new values.
*
* @param array $values An array in the form ['perm_name' => $value], containing the new data
* @param array|null $values2 if this array is not null, the first array will treated of list of perm names,
* and this array as an array of new values
*
* @return $this
*/
public function setRawPermissionValues(array $values, array $values2 = null) : self
public function setRawPermissionValues(array $values, array $values2 = null): self
{
if (!empty($values2)) {
$values = array_combine($values, $values2);
@ -435,16 +445,17 @@ class PermissionsEmbed
foreach ($values as $key => $value) {
$this->setRawPermissionValue($key, $value);
}
return $this;
}
/**
* Reads a bit pair from $data.
*
* @param $data int The data from where the bits should be extracted from.
* @param $data int The data from where the bits should be extracted from
* @param $n int The number of the lower bit (of the pair) that should be read. Starting from zero.
*
* @return int The value of the bit pair.
* @return int the value of the bit pair
*/
final protected static function readBitPair(int $data, int $n): int
{
@ -460,11 +471,11 @@ class PermissionsEmbed
/**
* Writes a bit pair in the given $data and returns it.
*
* @param $data int The data which should be modified.
* @param $n int The number of the lower bit of the pair which should be written.
* @param $new int The new value of the pair.
* @param $data int The data which should be modified
* @param $n int The number of the lower bit of the pair which should be written
* @param $new int The new value of the pair
*
* @return int The new data with the modified pair.
* @return int the new data with the modified pair
*/
final protected static function writeBitPair(int $data, int $n, int $new): int
{

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
declare(strict_types=1);
@ -53,7 +52,6 @@ declare(strict_types=1);
namespace App\Entity\UserSystem;
use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Attachments\UserAttachment;
use App\Entity\Base\NamedDBElement;
use App\Entity\PriceInformations\Currency;
@ -82,7 +80,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
public const AVAILABLE_THEMES = ['bootstrap', 'cerulean', 'cosmo', 'cyborg', 'darkly', 'flatly', 'journal',
'litera', 'lumen', 'lux', 'materia', 'minty', 'pulse', 'sandstone', 'simplex', 'sketchy', 'slate', 'solar',
'spacelab', 'united', 'yeti'];
'spacelab', 'united', 'yeti', ];
/**
* @var Collection|UserAttachment[]
@ -182,9 +180,9 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/**
* @var Currency|null The currency the user wants to see prices in.
* Dont use fetch=EAGER here, this will cause problems with setting the currency setting.
* TODO: This is most likely a bug in doctrine/symfony related to the UniqueEntity constraint (it makes a db call).
* TODO: Find a way to use fetch EAGER (this improves performance a bit)
* Dont use fetch=EAGER here, this will cause problems with setting the currency setting.
* TODO: This is most likely a bug in doctrine/symfony related to the UniqueEntity constraint (it makes a db call).
* TODO: Find a way to use fetch EAGER (this improves performance a bit)
* @ORM\ManyToOne(targetEntity="App\Entity\PriceInformations\Currency")
* @ORM\JoinColumn(name="currency_id", referencedColumnName="id")
* @Selectable()
@ -225,7 +223,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*/
protected $disabled = false;
public function __construct()
{
parent::__construct();
@ -284,8 +281,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/**
* Sets the password hash for this user.
*
* @param string $password
*
* @return User
*/
public function setPassword(string $password): self
@ -314,6 +309,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/**
* Gets the currency the user prefers when showing him prices.
*
* @return Currency|null The currency the user prefers, or null if the global currency should be used.
*/
public function getCurrency(): ?Currency
@ -323,17 +319,19 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/**
* Sets the currency the users prefers to see prices in.
* @param Currency|null $currency
*
* @return User
*/
public function setCurrency(?Currency $currency): User
public function setCurrency(?Currency $currency): self
{
$this->currency = $currency;
return $this;
}
/**
* Checks if this user is disabled (user cannot login any more).
*
* @return bool True, if the user is disabled.
*/
public function isDisabled(): bool
@ -343,17 +341,18 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/**
* Sets the status if a user is disabled.
*
* @param bool $disabled True if the user should be disabled.
*
* @return User
*/
public function setDisabled(bool $disabled): User
public function setDisabled(bool $disabled): self
{
$this->disabled = $disabled;
return $this;
}
/**
* Returns the ID as an string, defined by the element class.
* This should have a form like P000014, for a part with ID 14.
@ -371,7 +370,8 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
}
/**
* Check if the user needs a password change
* Check if the user needs a password change.
*
* @return bool
*/
public function isNeedPwChange(): bool
@ -381,12 +381,13 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/**
* Set the status, if the user needs a password change.
* @param bool $need_pw_change
*
* @return User
*/
public function setNeedPwChange(bool $need_pw_change): User
public function setNeedPwChange(bool $need_pw_change): self
{
$this->need_pw_change = $need_pw_change;
return $this;
}
@ -394,8 +395,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
* Getters
************************************************/
/**
* Returns the full name in the format FIRSTNAME LASTNAME [(USERNAME)].
* Example: Max Muster (m.muster).
@ -436,7 +435,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*
* @return User
*/
public function setFirstName(?string $first_name): User
public function setFirstName(?string $first_name): self
{
$this->first_name = $first_name;
@ -456,7 +455,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*
* @return User
*/
public function setLastName(?string $last_name): User
public function setLastName(?string $last_name): self
{
$this->last_name = $last_name;
@ -476,7 +475,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*
* @return User
*/
public function setDepartment(?string $department): User
public function setDepartment(?string $department): self
{
$this->department = $department;
@ -496,7 +495,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*
* @return User
*/
public function setEmail(?string $email): User
public function setEmail(?string $email): self
{
$this->email = $email;
@ -516,7 +515,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*
* @return User
*/
public function setLanguage(?string $language): User
public function setLanguage(?string $language): self
{
$this->language = $language;
@ -536,7 +535,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*
* @return User
*/
public function setTimezone(?string $timezone): User
public function setTimezone(?string $timezone): self
{
$this->timezone = $timezone;
@ -556,7 +555,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*
* @return User
*/
public function setTheme(?string $theme): User
public function setTheme(?string $theme): self
{
$this->theme = $theme;
@ -578,6 +577,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
public function __toString()
{
$tmp = $this->isDisabled() ? ' [DISABLED]' : '';
return $this->getFullName(true) . $tmp;
return $this->getFullName(true).$tmp;
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,16 +17,14 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\EntityListeners;
use App\Entity\Attachments\Attachment;
use App\Services\Attachments\AttachmentManager;
use App\Services\Attachments\AttachmentReverseSearch;
use App\Services\Attachments\AttachmentPathResolver;
use App\Services\Attachments\AttachmentReverseSearch;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Doctrine\ORM\Mapping\PostRemove;
@ -35,7 +33,6 @@ use Doctrine\ORM\Mapping\PreUpdate;
/**
* This listener watches for changes on attachments and deletes the files associated with an attachment, that are not
* used any more. This can happens after an attachment is delteted or the path is changed.
* @package App\EntityListeners
*/
class AttachmentDeleteListener
{
@ -52,8 +49,6 @@ class AttachmentDeleteListener
/**
* Removes the file associated with the attachment, if the file associated with the attachment changes.
* @param Attachment $attachment
* @param PreUpdateEventArgs $event
*
* @PreUpdate
*/
@ -73,9 +68,6 @@ class AttachmentDeleteListener
/**
* Removes the file associated with the attachment, after the attachment was deleted.
*
* @param Attachment $attachment
* @param LifecycleEventArgs $event
*
* @PostRemove
*/
public function postRemoveHandler(Attachment $attachment, LifecycleEventArgs $event)
@ -87,9 +79,8 @@ class AttachmentDeleteListener
$file = $this->attachmentHelper->attachmentToFile($attachment);
//Only delete if the attachment has a valid file.
if ($file !== null) {
if (null !== $file) {
$this->attachmentReverseSearch->deleteIfNotUsed($file);
}
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,20 +17,16 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\EntityListeners;
use App\Entity\Base\DBElement;
use App\Entity\Base\StructuralDBElement;
use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use App\Services\UserCacheKeyGenerator;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PostFlushEventArgs;
use Doctrine\ORM\Event\PreFlushEventArgs;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Contracts\Cache\TagAwareCacheInterface;
@ -49,15 +45,12 @@ class TreeCacheInvalidationListener
* @ORM\PostUpdate()
* @ORM\PostPersist()
* @ORM\PostRemove()
*
* @param DBElement $element
* @param LifecycleEventArgs $event
*/
public function invalidate(DBElement $element, LifecycleEventArgs $event)
{
//If an element was changed, then invalidate all cached trees with this element class
if ($element instanceof StructuralDBElement) {
$secure_class_name = str_replace("\\", '_', get_class($element));
$secure_class_name = str_replace('\\', '_', \get_class($element));
$this->cache->invalidateTags([$secure_class_name]);
}
@ -69,10 +62,9 @@ class TreeCacheInvalidationListener
/* If any group change, then invalidate all cached trees. Users Permissions can be inherited from groups,
so a change in any group can cause big permisssion changes for users. So to be sure, invalidate all trees */
if($element instanceof Group) {
$tag = "groups";
if ($element instanceof Group) {
$tag = 'groups';
$this->cache->invalidateTags([$tag]);
}
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
@ -31,11 +29,9 @@ use Symfony\Contracts\Translation\TranslatorInterface;
/**
* This event listener shows an login successful flash to the user after login.
* @package App\EventSubscriber
*/
class LoginSuccessListener implements EventSubscriberInterface
{
protected $translator;
protected $flashBag;
@ -72,4 +68,4 @@ class LoginSuccessListener implements EventSubscriberInterface
{
return [SecurityEvents::INTERACTIVE_LOGIN => 'onLogin'];
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,27 +17,20 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\EventSubscriber;
use App\Entity\UserSystem\User;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Http\SecurityEvents;
use Symfony\Contracts\Translation\TranslatorInterface;
class LogoutOnDisabledUserListener implements EventSubscriberInterface
{
protected $security;
protected $translator;
protected $flashBag;
@ -82,4 +75,4 @@ class LogoutOnDisabledUserListener implements EventSubscriberInterface
{
return [KernelEvents::REQUEST => 'onRequest'];
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,19 +17,16 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\EventSubscriber;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\Tests\Debug\EventSubscriber;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
class SymfonyDebugToolbarSubscriber implements EventSubscriberInterface
{
protected $kernel;
public function __construct(ContainerInterface $kernel)
@ -60,7 +57,6 @@ class SymfonyDebugToolbarSubscriber implements EventSubscriberInterface
return ['kernel.response' => 'onKernelResponse'];
}
public function onKernelResponse(FilterResponseEvent $event)
{
if (!$this->kernel->getParameter('kernel.debug')) {
@ -70,5 +66,4 @@ class SymfonyDebugToolbarSubscriber implements EventSubscriberInterface
$response = $event->getResponse();
$response->headers->set('Symfony-Debug-Toolbar-Replace', 1);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\EventSubscriber;
use App\Entity\UserSystem\User;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
@ -31,11 +29,9 @@ use Symfony\Component\Security\Core\Security;
/**
* The purpose of this event listener is to set the timezone to the one preferred by the user.
* @package App\EventSubscriber
*/
class TimezoneListener implements EventSubscriberInterface
{
protected $default_timezone;
protected $security;
@ -56,14 +52,13 @@ class TimezoneListener implements EventSubscriberInterface
}
//Fill with default value if needed
if ($timezone === null && !empty($this->default_timezone)) {
if (null === $timezone && !empty($this->default_timezone)) {
$timezone = $this->default_timezone;
}
//If timezone was configured anywhere set it, otherwise just use the one from php.ini
if ($timezone !== null) {
if (null !== $timezone) {
date_default_timezone_set($timezone);
}
}
@ -89,7 +84,7 @@ class TimezoneListener implements EventSubscriberInterface
{
//Set the timezone shortly before executing the controller
return [
KernelEvents::CONTROLLER => 'setTimeZone'
KernelEvents::CONTROLLER => 'setTimeZone',
];
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,14 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Exceptions;
use Throwable;
class AttachmentDownloadException extends \RuntimeException
{
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Exceptions;

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,18 +17,14 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement;
use App\Form\AdminPages\BaseEntityAdminForm;
use App\Services\Attachments\FileTypeFilterTools;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Security;
@ -46,14 +42,14 @@ class AttachmentTypeAdminForm extends BaseEntityAdminForm
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
{
$is_new = $entity->getID() === null;
$is_new = null === $entity->getID();
$builder->add('filetype_filter', TextType::class, ['required' => false,
'label' => $this->trans->trans('attachment_type.edit.filetype_filter'),
'help' => $this->trans->trans('attachment_type.edit.filetype_filter.help'),
'label' => $this->trans->trans('attachment_type.edit.filetype_filter'),
'help' => $this->trans->trans('attachment_type.edit.filetype_filter.help'),
'attr' => ['placeholder' => $this->trans->trans('attachment_type.edit.filetype_filter.placeholder')],
'empty_data' => '',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
//Normalize data before writing it to database
$builder->get('filetype_filter')->addViewTransformer(new CallbackTransformer(
@ -65,4 +61,4 @@ class AttachmentTypeAdminForm extends BaseEntityAdminForm
}
));
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,24 +17,17 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\AdminPages;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\FootprintAttachment;
use App\Entity\Attachments\PartAttachment;
use App\Entity\Base\NamedDBElement;
use App\Entity\Base\StructuralDBElement;
use App\Form\AttachmentFormType;
use App\Form\Type\MasterPictureAttachmentType;
use App\Form\Type\StructuralEntityType;
use Doctrine\ORM\EntityRepository;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
@ -45,12 +38,10 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Translation\Reader\TranslationReader;
use Symfony\Contracts\Translation\TranslatorInterface;
class BaseEntityAdminForm extends AbstractType
{
protected $security;
protected $params;
protected $trans;
@ -72,27 +63,27 @@ class BaseEntityAdminForm extends AbstractType
{
/** @var StructuralDBElement $entity */
$entity = $options['data'];
$is_new = $entity->getID() === null;
$is_new = null === $entity->getID();
$builder
->add('name', TextType::class, ['empty_data' => '', 'label' => $this->trans->trans('name.label'),
'attr' => ['placeholder' => $this->trans->trans('part.name.placeholder')],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ])
->add('parent', StructuralEntityType::class, ['class' => get_class($entity),
'required' => false, 'label' => $this->trans->trans('parent.label'),
->add('parent', StructuralEntityType::class, ['class' => \get_class($entity),
'required' => false, 'label' => $this->trans->trans('parent.label'),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ])
->add('not_selectable', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('entity.edit.not_selectable'),
'help' => $this->trans->trans('entity.edit.not_selectable.help'),
'label' => $this->trans->trans('entity.edit.not_selectable'),
'help' => $this->trans->trans('entity.edit.not_selectable.help'),
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity) ])
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ])
->add('comment', CKEditorType::class, ['required' => false, 'empty_data' => '',
'label' => $this->trans->trans('comment.label'),
'attr' => ['rows' => 4], 'help' => $this->trans->trans('bbcode.hint'),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
'label' => $this->trans->trans('comment.label'),
'attr' => ['rows' => 4], 'help' => $this->trans->trans('bbcode.hint'),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$this->additionalFormElements($builder, $options, $entity);
@ -106,27 +97,27 @@ class BaseEntityAdminForm extends AbstractType
'entry_options' => [
'data_class' => $options['attachment_class'],
],
'by_reference' => false
'by_reference' => false,
]);
$builder->add('master_picture_attachment', MasterPictureAttachmentType::class, [
'required' => false,
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'label' => $this->trans->trans('part.edit.master_attachment'),
'entity' => $entity
'entity' => $entity,
]);
//Buttons
$builder->add('save', SubmitType::class, [
'label' => $is_new ? $this->trans->trans('entity.create') : $this->trans->trans('entity.edit.save'),
'label' => $is_new ? $this->trans->trans('entity.create') : $this->trans->trans('entity.edit.save'),
'attr' => ['class' => $is_new ? 'btn-success' : ''],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)])
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ])
->add('reset', ResetType::class, ['label' => 'entity.edit.reset',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
}
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
{
//Empty for Base
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,14 +17,11 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement;
use App\Form\AdminPages\BaseEntityAdminForm;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
@ -33,50 +30,50 @@ class CategoryAdminForm extends BaseEntityAdminForm
{
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
{
$is_new = $entity->getID() === null;
$is_new = null === $entity->getID();
$builder->add('disable_footprints', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('category.edit.disable_footprints'),
'help' => $this->trans->trans('category.edit.disable_footprints.help'),
'label' => $this->trans->trans('category.edit.disable_footprints'),
'help' => $this->trans->trans('category.edit.disable_footprints.help'),
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('disable_manufacturers', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('category.edit.disable_manufacturers'),
'help' => $this->trans->trans('category.edit.disable_manufacturers.help'),
'label_attr'=> ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
'label' => $this->trans->trans('category.edit.disable_manufacturers'),
'help' => $this->trans->trans('category.edit.disable_manufacturers.help'),
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('disable_autodatasheets', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('category.edit.disable_autodatasheets'),
'help' => $this->trans->trans('category.edit.disable_autodatasheets.help'),
'label_attr'=> ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
'label' => $this->trans->trans('category.edit.disable_autodatasheets'),
'help' => $this->trans->trans('category.edit.disable_autodatasheets.help'),
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('disable_properties', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('category.edit.disable_properties'),
'help' => $this->trans->trans('category.edit.disable_properties.help'),
'label_attr'=> ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
'label' => $this->trans->trans('category.edit.disable_properties'),
'help' => $this->trans->trans('category.edit.disable_properties.help'),
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('partname_hint', TextType::class, ['required' => false, 'empty_data' => '',
'label' => $this->trans->trans('category.edit.partname_hint'),
'attr' => ['placeholder' => $this->trans->trans('category.edit.partname_hint.placeholder')],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
'label' => $this->trans->trans('category.edit.partname_hint'),
'attr' => ['placeholder' => $this->trans->trans('category.edit.partname_hint.placeholder')],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('partname_regex', TextType::class, ['required' => false, 'empty_data' => '',
'label' => $this->trans->trans('category.edit.partname_regex'),
'attr' => ['placeholder' => 'category.edit.partname_regex.placeholder'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('default_description', TextType::class, ['required' => false, 'empty_data' => '',
'label' => $this->trans->trans('category.edit.default_description'),
'label' => $this->trans->trans('category.edit.default_description'),
'attr' => ['placeholder' => $this->trans->trans('category.edit.default_description.placeholder')],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('default_comment', TextType::class, ['required' => false, 'empty_data' => '',
'label' => $this->trans->trans('category.edit.default_comment'),
'attr' => ['placeholder' => $this->trans->trans('category.edit.default_comment.placeholder')],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,19 +17,14 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement;
use App\Form\AdminPages\BaseEntityAdminForm;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
@ -37,13 +32,13 @@ class CompanyForm extends BaseEntityAdminForm
{
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
{
$is_new = $entity->getID() === null;
$is_new = null === $entity->getID();
$builder->add('address', TextareaType::class, [
'label' => $this->trans->trans('company.edit.address'),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => $this->trans->trans('company.edit.address.placeholder')], 'required' => false,
'empty_data' => ''
'empty_data' => '',
]);
$builder->add('phone_number', TelType::class, [
@ -51,28 +46,28 @@ class CompanyForm extends BaseEntityAdminForm
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => $this->trans->trans('company.edit.phone_number.placeholder')],
'required' => false,
'empty_data' => ''
'empty_data' => '',
]);
$builder->add('fax_number', TelType::class, [
'label' => $this->trans->trans('company.edit.fax_number'),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.fax_number.placeholder'], 'required' => false,
'empty_data' => ''
'empty_data' => '',
]);
$builder->add('email_address', EmailType::class, [
'label' => $this->trans->trans('company.edit.email'),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => $this->trans->trans('company.edit.email.placeholder')], 'required' => false,
'empty_data' => ''
'empty_data' => '',
]);
$builder->add('website', UrlType::class, [
'label' => $this->trans->trans('company.edit.website'),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => $this->trans->trans('company.edit.website.placeholder')], 'required' => false,
'empty_data' => ''
'empty_data' => '',
]);
$builder->add('auto_product_url', UrlType::class, [
@ -81,7 +76,7 @@ class CompanyForm extends BaseEntityAdminForm
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => $this->trans->trans('company.edit.auto_product_url.placeholder')],
'required' => false,
'empty_data' => ''
'empty_data' => '',
]);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,14 +17,11 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\FormBuilderInterface;
@ -33,20 +30,20 @@ class CurrencyAdminForm extends BaseEntityAdminForm
{
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
{
$is_new = $entity->getID() === null;
$is_new = null === $entity->getID();
$builder->add('iso_code', CurrencyType::class, [
'required' => false,
'label' => $this->trans->trans('currency.edit.iso_code'),
'preferred_choices' => ['EUR', 'USD', 'GBP', 'JPY', 'CNY'],
'attr' => ['class' => 'selectpicker', 'data-live-search' => true],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('exchange_rate', MoneyType::class, [
'required' => false,
'label' => $this->trans->trans('currency.edit.exchange_rate'),
'currency' => $this->params->get('default_currency'),
'scale' => 6,
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement;
use App\Form\Type\MasterPictureAttachmentType;
use Symfony\Component\Form\FormBuilderInterface;
@ -33,10 +31,10 @@ class FootprintAdminForm extends BaseEntityAdminForm
{
$builder->add('footprint_3d', MasterPictureAttachmentType::class, [
'required' => false,
'disabled' => !$this->security->isGranted($entity->getID() === null ? 'create' : 'edit', $entity),
'disabled' => !$this->security->isGranted(null === $entity->getID() ? 'create' : 'edit', $entity),
'label' => $this->trans->trans('footprint.edit.3d_model'),
'filter' => '3d_model',
'entity' => $entity
'entity' => $entity,
]);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,12 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement;
use App\Form\Permissions\PermissionsType;
use Symfony\Component\Form\FormBuilderInterface;
@ -34,7 +32,7 @@ class GroupAdminForm extends BaseEntityAdminForm
$builder->add('permissions', PermissionsType::class, [
'mapped' => false,
'data' => $builder->getData(),
'disabled' => !$this->security->isGranted('edit_permissions', $entity)
'disabled' => !$this->security->isGranted('edit_permissions', $entity),
]);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,16 +17,12 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\AdminPages;
use App\Entity\Base\StructuralDBElement;
use App\Form\Type\StructuralEntityType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Bundle\MakerBundle\Str;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
@ -39,7 +35,6 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class ImportType extends AbstractType
{
protected $security;
protected $trans;
@ -51,48 +46,47 @@ class ImportType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$data = $options['data'];
//Disable import if user is not allowed to create elements.
$entity = new $data['entity_class']();
$perm_name = "create";
$disabled = ! $this->security->isGranted($perm_name, $entity);
$perm_name = 'create';
$disabled = !$this->security->isGranted($perm_name, $entity);
$builder
->add('format', ChoiceType::class, [
'choices' => ['JSON' => 'json', 'XML' => 'xml','CSV' => 'csv' ,'YAML' => 'yaml'],
'choices' => ['JSON' => 'json', 'XML' => 'xml', 'CSV' => 'csv', 'YAML' => 'yaml'],
'label' => $this->trans->trans('export.format'),
'disabled' => $disabled])
'disabled' => $disabled, ])
->add('csv_separator', TextType::class, ['data' => ';',
'label' => $this->trans->trans('import.csv_separator'),
'disabled' => $disabled]);
'disabled' => $disabled, ]);
if ($entity instanceof StructuralDBElement) {
$builder->add('parent', StructuralEntityType::class, [
'class' => $data['entity_class'],
'required' => false,
'label' => $this->trans->trans('parent.label'),
'disabled' => $disabled
'disabled' => $disabled,
]);
}
$builder->add('file', FileType::class, [
'label' => $this->trans->trans('import.file'),
'attr' => ['class' => 'file', 'data-show-preview' => 'false', 'data-show-upload' => 'false'],
'disabled' => $disabled
'disabled' => $disabled,
])
->add('preserve_children', CheckboxType::class, ['data' => true, 'required' => false,
'label' => $this->trans->trans('import.preserve_children'),
'label_attr' => ['class' => 'checkbox-custom'], 'disabled' => $disabled])
'label_attr' => ['class' => 'checkbox-custom'], 'disabled' => $disabled, ])
->add('abort_on_validation_error', CheckboxType::class, ['data' => true, 'required' => false,
'label' => $this->trans->trans('import.abort_on_validation'),
'help' => $this->trans->trans('import.abort_on_validation.help'),
'label_attr' => ['class' => 'checkbox-custom'], 'disabled' => $disabled])
'label_attr' => ['class' => 'checkbox-custom'], 'disabled' => $disabled, ])
//Buttons
->add('import', SubmitType::class, ['label' => 'import.btn', 'disabled' => $disabled]);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,22 +17,15 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\AdminPages;
use App\Entity\Base\StructuralDBElement;
use App\Form\Type\StructuralEntityType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -50,13 +43,12 @@ class MassCreationForm extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$data = $options['data'];
//Disable import if user is not allowed to create elements.
$entity = new $data['entity_class']();
$perm_name = "create";
$disabled = ! $this->security->isGranted($perm_name, $entity);
$perm_name = 'create';
$disabled = !$this->security->isGranted($perm_name, $entity);
$builder
->add('lines', TextareaType::class, ['data' => '',
@ -64,21 +56,21 @@ class MassCreationForm extends AbstractType
'disabled' => $disabled, 'required' => true,
'attr' => [
'placeholder' => $this->translator->trans('mass_creation.lines.placeholder'),
'rows' => 10
]
'rows' => 10,
],
]);
if ($entity instanceof StructuralDBElement) {
$builder->add('parent', StructuralEntityType::class, [
'class' => $data['entity_class'],
'required' => false,
'label' => $this->translator->trans('parent.label'),
'disabled' => $disabled]);
'disabled' => $disabled, ]);
}
//Buttons
$builder->add('create', SubmitType::class, [
'label' => $this->translator->trans('entity.mass_creation.btn'),
'disabled' => $disabled
'disabled' => $disabled,
]);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,14 +17,11 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement;
use App\Form\AdminPages\BaseEntityAdminForm;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
@ -33,23 +30,23 @@ class MeasurementUnitAdminForm extends BaseEntityAdminForm
{
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
{
$is_new = $entity->getID() === null;
$is_new = null === $entity->getID();
$builder->add('is_integer', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('measurement_unit.edit.is_integer'),
'label' => $this->trans->trans('measurement_unit.edit.is_integer'),
'help' => $this->trans->trans('measurement_unit.edit.is_integer.help'),
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('use_si_prefix', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('measurement_unit.edit.use_si_prefix'),
'help' => $this->trans->trans('measurement_unit.edit.use_si_prefix.help'),
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('unit', TextType::class, ['required' => false,
'label' => $this->trans->trans('measurement_unit.edit.unit_symbol'),
'attr' => ['placeholder' => $this->trans->trans('measurement_unit.edit.unit_symbol.placeholder')],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]);
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,53 +17,48 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement;
use App\Entity\Parts\MeasurementUnit;
use App\Form\AdminPages\BaseEntityAdminForm;
use App\Form\Type\StructuralEntityType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
class StorelocationAdminForm extends BaseEntityAdminForm
{
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
{
$is_new = $entity->getID() === null;
$is_new = null === $entity->getID();
$builder->add('is_full', CheckboxType::class, [
'required' => false,
'label' => $this->trans->trans('storelocation.edit.is_full.label'),
'help' => $this->trans->trans('storelocation.edit.is_full.help'),
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity)]);
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]);
$builder->add('limit_to_existing_parts', CheckboxType::class, [
'required' => false,
'label' => $this->trans->trans('storelocation.limit_to_existing.label'),
'help' => $this->trans->trans('storelocation.limit_to_existing.help'),
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity)]);
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]);
$builder->add('only_single_part', CheckboxType::class, [
'required' => false,
'label' => $this->trans->trans('storelocation.only_single_part.label'),
'help' => $this->trans->trans('storelocation.only_single_part.help'),
'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity)]);
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]);
$builder->add('storage_type', StructuralEntityType::class, [
'required' => false,
'label' => $this->trans->trans('storelocation.storage_type.label'),
'help' => $this->trans->trans('storelocation.storage_type.help'),
'class' => MeasurementUnit::class, 'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity)]);
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,34 +17,23 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement;
use App\Entity\PriceInformations\Currency;
use App\Form\AdminPages\BaseEntityAdminForm;
use App\Form\Type\StructuralEntityType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
class SupplierForm extends CompanyForm
{
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
{
$is_new = $entity->getID() === null;
$is_new = null === $entity->getID();
parent::additionalFormElements($builder, $options, $entity);
parent::additionalFormElements($builder, $options, $entity);
$builder->add('default_currency', StructuralEntityType::class, [
'class' => Currency::class,
@ -58,7 +47,7 @@ class SupplierForm extends CompanyForm
'currency' => $this->params->get('default_currency'),
'scale' => 3,
'label' => $this->trans->trans('supplier.shipping_costs.label'),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity)
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity),
]);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,15 +17,12 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Form;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Base\StructuralDBElement;
use App\Form\Type\StructuralEntityType;
use App\Services\Attachments\AttachmentManager;
use App\Validator\Constraints\AllowedFileExtension;
@ -34,13 +31,11 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Validator\Constraints\File;
use Symfony\Component\Validator\Constraints\Url;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -64,60 +59,59 @@ class AttachmentFormType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', TextType::class, [
'label' => $this->trans->trans('attachment.edit.name')
'label' => $this->trans->trans('attachment.edit.name'),
])
->add('attachment_type', StructuralEntityType::class, [
'label' => $this->trans->trans('attachment.edit.attachment_type'),
'label' => $this->trans->trans('attachment.edit.attachment_type'),
'class' => AttachmentType::class,
'disable_not_selectable' => true,
'attr' => ['class' => 'attachment_type_selector']
'attr' => ['class' => 'attachment_type_selector'],
]);
$builder->add('showInTable', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('attachment.edit.show_in_table'),
'label' => $this->trans->trans('attachment.edit.show_in_table'),
'attr' => ['class' => 'form-control-sm'],
'label_attr' => ['class' => 'checkbox-custom']]);
'label_attr' => ['class' => 'checkbox-custom'], ]);
$builder->add('secureFile', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('attachment.edit.secure_file'),
'label' => $this->trans->trans('attachment.edit.secure_file'),
'mapped' => false,
'attr' => ['class' => 'form-control-sm'],
'help' => $this->trans->trans('attachment.edit.secure_file.help'),
'label_attr' => ['class' => 'checkbox-custom']]);
'label_attr' => ['class' => 'checkbox-custom'], ]);
$builder->add('url', TextType::class, [
'label' => $this->trans->trans('attachment.edit.url'),
'label' => $this->trans->trans('attachment.edit.url'),
'required' => false,
'attr' => [
'data-autocomplete' => $this->urlGenerator->generate('typeahead_builtInRessources', ['query' => 'QUERY']),
//Disable browser autocomplete
'autocomplete' => 'off'
'autocomplete' => 'off',
],
'help' => $this->trans->trans('attachment.edit.url.help'),
'constraints' => [
$options['allow_builtins'] ? new UrlOrBuiltin() : new Url()
]
$options['allow_builtins'] ? new UrlOrBuiltin() : new Url(),
],
]);
$builder->add('downloadURL', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('attachment.edit.download_url'),
'label' => $this->trans->trans('attachment.edit.download_url'),
'mapped' => false,
'disabled' => !$this->allow_attachments_download,
'attr' => ['class' => 'form-control-sm'],
'label_attr' => ['class' => 'checkbox-custom']]);
'label_attr' => ['class' => 'checkbox-custom'], ]);
$builder->add('file', FileType::class, [
'label' => $this->trans->trans('attachment.edit.file'),
'label' => $this->trans->trans('attachment.edit.file'),
'mapped' => false,
'required' => false,
'attr' => ['class' => 'file', 'data-show-preview' => 'false', 'data-show-upload' => 'false'],
'constraints' => [
new AllowedFileExtension(),
new File([
'maxSize' => $options['max_file_size']
'maxSize' => $options['max_file_size'],
]),
]
],
]);
//Check the secure file checkbox, if file is in securefile location
@ -137,8 +131,7 @@ class AttachmentFormType extends AbstractType
$resolver->setDefaults([
'data_class' => Attachment::class,
'max_file_size' => '16M',
'allow_builtins' => true
'allow_builtins' => true,
]);
}
}
}

Some files were not shown because too many files have changed in this diff Show more