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 <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Command; namespace App\Command;
use App\Services\Attachments\AttachmentManager; use App\Services\Attachments\AttachmentManager;
use App\Services\Attachments\AttachmentReverseSearch;
use App\Services\Attachments\AttachmentPathResolver; use App\Services\Attachments\AttachmentPathResolver;
use App\Services\Attachments\AttachmentReverseSearch;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
use Symfony\Component\Mime\FileinfoMimeTypeGuesser;
use Symfony\Component\Mime\MimeTypes; use Symfony\Component\Mime\MimeTypes;
use Symfony\Component\Mime\MimeTypesInterface;
class CleanAttachmentsCommand extends Command class CleanAttachmentsCommand extends Command
{ {
@ -69,9 +64,9 @@ class CleanAttachmentsCommand extends Command
$io = new SymfonyStyle($input, $output); $io = new SymfonyStyle($input, $output);
$mediaPath = $this->pathResolver->getMediaPath(); $mediaPath = $this->pathResolver->getMediaPath();
$io->note("The media path is " . $mediaPath); $io->note('The media path is '.$mediaPath);
$securePath = $this->pathResolver->getSecurePath(); $securePath = $this->pathResolver->getSecurePath();
$io->note("The secure media path is ". $securePath); $io->note('The secure media path is '.$securePath);
$finder = new Finder(); $finder = new Finder();
//We look for files in the media folder only //We look for files in the media folder only
@ -81,7 +76,7 @@ class CleanAttachmentsCommand extends Command
$fs = new Filesystem(); $fs = new Filesystem();
$file_list = array(); $file_list = [];
$table = new Table($output); $table = new Table($output);
$table->setHeaders(['Filename', 'MIME Type', 'Last modified date']); $table->setHeaders(['Filename', 'MIME Type', 'Last modified date']);
@ -89,20 +84,20 @@ class CleanAttachmentsCommand extends Command
foreach ($finder as $file) { foreach ($finder as $file) {
//If not attachment object uses this file, print it //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; $file_list[] = $file;
$table->addRow([ $table->addRow([
$fs->makePathRelative($file->getPathname(), $mediaPath), $fs->makePathRelative($file->getPathname(), $mediaPath),
$this->mimeTypeGuesser->guessMimeType($file->getPathname()), $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(); $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) { if (!$continue) {
//We are finished here, when no files should be deleted //We are finished here, when no files should be deleted
@ -114,27 +109,26 @@ class CleanAttachmentsCommand extends Command
//Delete empty folders: //Delete empty folders:
$this->removeEmptySubFolders($mediaPath); $this->removeEmptySubFolders($mediaPath);
$io->success("All abandoned files were removed."); $io->success('All abandoned files were removed.');
} else { } 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 * @param string $path The path in which the empty folders should be deleted
*
* @return bool * @return bool
*/ */
protected function removeEmptySubFolders($path) protected function removeEmptySubFolders($path)
{ {
$empty=true; $empty = true;
foreach (glob($path . DIRECTORY_SEPARATOR . "*") as $file) foreach (glob($path.\DIRECTORY_SEPARATOR.'*') as $file) {
{
$empty &= is_dir($file) && $this->removeEmptySubFolders($file); $empty &= is_dir($file) && $this->removeEmptySubFolders($file);
} }
return $empty && rmdir($path); return $empty && rmdir($path);
} }
} }

View file

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

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Command; namespace App\Command;

View file

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

View file

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

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Controller\AdminPages; namespace App\Controller\AdminPages;
@ -38,22 +37,18 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Core\Tests\Encoder\PasswordEncoder;
use Symfony\Component\Validator\ConstraintViolationList; use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
abstract class BaseAdminController extends AbstractController abstract class BaseAdminController extends AbstractController
{ {
protected $entity_class = ''; protected $entity_class = '';
protected $form_class = ''; protected $form_class = '';
protected $twig_template = ''; protected $twig_template = '';
protected $route_base = ''; protected $route_base = '';
protected $attachment_class = ''; protected $attachment_class = '';
protected $passwordEncoder; protected $passwordEncoder;
protected $translator; protected $translator;
protected $attachmentHelper; protected $attachmentHelper;
@ -62,11 +57,11 @@ abstract class BaseAdminController extends AbstractController
public function __construct(TranslatorInterface $translator, UserPasswordEncoderInterface $passwordEncoder, public function __construct(TranslatorInterface $translator, UserPasswordEncoderInterface $passwordEncoder,
AttachmentManager $attachmentHelper, AttachmentSubmitHandler $attachmentSubmitHandler) 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!'); 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!'); 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) protected function _edit(NamedDBElement $entity, Request $request, EntityManagerInterface $em)
{ {
$this->denyAccessUnlessGranted('read', $entity); $this->denyAccessUnlessGranted('read', $entity);
$form = $this->createForm($this->form_class, $entity, ['attachment_class' => $this->attachment_class]); $form = $this->createForm($this->form_class, $entity, ['attachment_class' => $this->attachment_class]);
@ -99,14 +93,14 @@ abstract class BaseAdminController extends AbstractController
/** @var $attachment FormInterface */ /** @var $attachment FormInterface */
$options = [ $options = [
'secure_attachment' => $attachment['secureFile']->getData(), 'secure_attachment' => $attachment['secureFile']->getData(),
'download_url' => $attachment['downloadURL']->getData() 'download_url' => $attachment['downloadURL']->getData(),
]; ];
try { try {
$this->attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options); $this->attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options);
} catch (AttachmentDownloadException $ex) { } catch (AttachmentDownloadException $ex) {
$this->addFlash( $this->addFlash(
'error', '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! //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! //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]); $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')); $this->addFlash('error', $this->translator->trans('entity.edit_flash.invalid'));
} }
return $this->render($this->twig_template, [ return $this->render($this->twig_template, [
'entity' => $entity, 'entity' => $entity,
'form' => $form->createView(), 'form' => $form->createView(),
'attachment_helper' => $this->attachmentHelper 'attachment_helper' => $this->attachmentHelper,
]); ]);
} }
@ -155,14 +149,14 @@ abstract class BaseAdminController extends AbstractController
/** @var $attachment FormInterface */ /** @var $attachment FormInterface */
$options = [ $options = [
'secure_attachment' => $attachment['secureFile']->getData(), 'secure_attachment' => $attachment['secureFile']->getData(),
'download_url' => $attachment['downloadURL']->getData() 'download_url' => $attachment['downloadURL']->getData(),
]; ];
try { try {
$this->attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options); $this->attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options);
} catch (AttachmentDownloadException $ex) { } catch (AttachmentDownloadException $ex) {
$this->addFlash( $this->addFlash(
'error', '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(); $em->flush();
$this->addFlash('success', $this->translator->trans('entity.created_flash')); $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')); $this->addFlash('error', $this->translator->trans('entity.created_flash.invalid'));
} }
@ -187,14 +181,14 @@ abstract class BaseAdminController extends AbstractController
$file = $import_form['file']->getData(); $file = $import_form['file']->getData();
$data = $import_form->getData(); $data = $import_form->getData();
$options = array('parent' => $data['parent'], 'preserve_children' => $data['preserve_children'], $options = ['parent' => $data['parent'], 'preserve_children' => $data['preserve_children'],
'format' => $data['format'], 'csv_separator' => $data['csv_separator']); 'format' => $data['format'], 'csv_separator' => $data['csv_separator'], ];
$errors = $importer->fileToDBEntities($file, $this->entity_class, $options); $errors = $importer->fileToDBEntities($file, $this->entity_class, $options);
foreach ($errors as $name => $error) { foreach ($errors as $name => $error) {
/** @var $error ConstraintViolationList */ /* @var $error ConstraintViolationList */
$this->addFlash('error', $name . ':' . $error); $this->addFlash('error', $name.':'.$error);
} }
} }
@ -212,8 +206,8 @@ abstract class BaseAdminController extends AbstractController
//Show errors to user: //Show errors to user:
foreach ($errors as $name => $error) { foreach ($errors as $name => $error) {
/** @var $error ConstraintViolationList */ /* @var $error ConstraintViolationList */
$this->addFlash('error', $name . ':' . $error); $this->addFlash('error', $name.':'.$error);
} }
} }
@ -222,7 +216,7 @@ abstract class BaseAdminController extends AbstractController
'form' => $form->createView(), 'form' => $form->createView(),
'import_form' => $import_form->createView(), 'import_form' => $import_form->createView(),
'mass_creation_form' => $mass_creation_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'); $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) 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(); $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) protected function _exportEntity(NamedDBElement $entity, EntityExporter $exporter, Request $request)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Controller; namespace App\Controller;
@ -44,8 +43,6 @@ class DebugController extends AbstractController
$this->addFlash('testkjfd', 'Blabla. This message type should be not know to template!'); $this->addFlash('testkjfd', 'Blabla. This message type should be not know to template!');
return $this->render('base.html.twig'); return $this->render('base.html.twig');
} }
@ -81,6 +78,5 @@ class DebugController extends AbstractController
$translator->trans('flash.info'); $translator->trans('flash.info');
$translator->trans('validator.noLockout'); $translator->trans('validator.noLockout');
} }
} }

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Controller; namespace App\Controller;
@ -46,7 +45,7 @@ class RedirectController extends AbstractController
/** /**
* This function is called whenever a route was not matching the localized routes. * 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. * The purpose is to redirect the user to the localized version of the page.
* @param Request $request *
* @return \Symfony\Component\HttpFoundation\RedirectResponse * @return \Symfony\Component\HttpFoundation\RedirectResponse
*/ */
public function addLocalePart(Request $request) 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 //Check if the user needs to change the password. In that case redirect him to settings_page
if ($user instanceof User && $user->isNeedPwChange()) { if ($user instanceof User && $user->isNeedPwChange()) {
$this->session->getFlashBag()->add('warning', $this->translator->trans('flash.password_change_needed')); $this->session->getFlashBag()->add('warning', $this->translator->trans('flash.password_change_needed'));
return $this->redirectToRoute('user_settings', ['_locale' => $locale]); return $this->redirectToRoute('user_settings', ['_locale' => $locale]);
} }
//$new_url = str_replace($request->getPathInfo(), '/' . $locale . $request->getPathInfo(), $request->getUri()); //$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 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()) 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 //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); return $this->redirect($new_url);
} }
/** /**
* Check if mod_rewrite is availabe (URL rewriting is possible). * 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. * 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 * @return bool
*/ */
public function checkIfModRewriteAvailable() 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 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. //If you want to enforce index.php versions of the url, you can override this via ENV vars.
return true; return true;
} }
//Check if the mod_rewrite module is loaded //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 <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Controller; namespace App\Controller;

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Controller; 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. * This controller has the purpose to provide the data for all treeviews.
*
* @package App\Controller
*/ */
class TreeController extends AbstractController class TreeController extends AbstractController
{ {
@ -57,13 +54,12 @@ class TreeController extends AbstractController
*/ */
public function categoryTree(TreeBuilder $builder, Category $category = null) public function categoryTree(TreeBuilder $builder, Category $category = null)
{ {
if ($category !== null) { if (null !== $category) {
$tree[] = $builder->elementToTreeNode($category); $tree[] = $builder->elementToTreeNode($category);
} else { } else {
$tree = $builder->typeToTree(Category::class); $tree = $builder->typeToTree(Category::class);
} }
return $this->json($tree, 200, [], ['skip_null_values' => true]); 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) public function footprintTree(TreeBuilder $builder, Footprint $footprint = null)
{ {
if ($footprint !== null) { if (null !== $footprint) {
$tree[] = $builder->elementToTreeNode($footprint); $tree[] = $builder->elementToTreeNode($footprint);
} else { } else {
$tree = $builder->typeToTree(Footprint::class); $tree = $builder->typeToTree(Footprint::class);
} }
return $this->json($tree, 200, [], ['skip_null_values' => true]); 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) public function locationTree(TreeBuilder $builder, Storelocation $location = null)
{ {
if ($location !== null) { if (null !== $location) {
$tree[] = $builder->elementToTreeNode($location); $tree[] = $builder->elementToTreeNode($location);
} else { } else {
$tree = $builder->typeToTree(Storelocation::class); $tree = $builder->typeToTree(Storelocation::class);
} }
return $this->json($tree, 200, [], ['skip_null_values' => true]); 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) public function manufacturerTree(TreeBuilder $builder, Manufacturer $manufacturer = null)
{ {
if ($manufacturer !== null) { if (null !== $manufacturer) {
$tree[] = $builder->elementToTreeNode($manufacturer); $tree[] = $builder->elementToTreeNode($manufacturer);
} else { } else {
$tree = $builder->typeToTree(Manufacturer::class); $tree = $builder->typeToTree(Manufacturer::class);
} }
return $this->json($tree, 200, [], ['skip_null_values' => true]); 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) public function supplierTree(TreeBuilder $builder, Supplier $supplier = null)
{ {
if ($supplier !== null) { if (null !== $supplier) {
$tree[] = $builder->elementToTreeNode($supplier); $tree[] = $builder->elementToTreeNode($supplier);
} else { } else {
$tree = $builder->typeToTree(Supplier::class); $tree = $builder->typeToTree(Supplier::class);
} }
return $this->json($tree, 200, [], ['skip_null_values' => true]); 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) public function deviceTree(TreeBuilder $builder, Device $device = null)
{ {
if ($device !== null) { if (null !== $device) {
$tree[] = $builder->elementToTreeNode($device); $tree[] = $builder->elementToTreeNode($device);
} else { } else {
$tree = $builder->typeToTree(Device::class, null); $tree = $builder->typeToTree(Device::class, null);
} }
return $this->json($tree, 200, [], ['skip_null_values' => true]); return $this->json($tree, 200, [], ['skip_null_values' => true]);
} }
} }

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Controller; namespace App\Controller;
use App\Services\Attachments\BuiltinAttachmentsFinder; use App\Services\Attachments\BuiltinAttachmentsFinder;
use App\Services\TagFinder; use App\Services\TagFinder;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -34,9 +32,9 @@ use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer; 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") * @Route("/typeahead")
* @package App\Controller
*/ */
class TypeaheadController extends AbstractController class TypeaheadController extends AbstractController
{ {
@ -47,15 +45,15 @@ class TypeaheadController extends AbstractController
{ {
$array = $finder->find($query); $array = $finder->find($query);
$normalizers = [ $normalizers = [
new ObjectNormalizer() new ObjectNormalizer(),
]; ];
$encoders = [ $encoders = [
new JsonEncoder() new JsonEncoder(),
]; ];
$serializer = new Serializer($normalizers, $encoders); $serializer = new Serializer($normalizers, $encoders);
$data = $serializer->serialize($array, 'json'); $data = $serializer->serialize($array, 'json');
return new JsonResponse($data, 200, [], true); return new JsonResponse($data, 200, [], true);
} }
@ -67,13 +65,14 @@ class TypeaheadController extends AbstractController
$array = $finder->searchTags($query); $array = $finder->searchTags($query);
$normalizers = [ $normalizers = [
new ObjectNormalizer() new ObjectNormalizer(),
]; ];
$encoders = [ $encoders = [
new JsonEncoder() new JsonEncoder(),
]; ];
$serializer = new Serializer($normalizers, $encoders); $serializer = new Serializer($normalizers, $encoders);
$data = $serializer->serialize($array, 'json'); $data = $serializer->serialize($array, 'json');
return new JsonResponse($data, 200, [], true); return new JsonResponse($data, 200, [], true);
} }
} }

View file

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

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\DataFixtures; namespace App\DataFixtures;
use App\Entity\Parts\Part;
use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectManager;

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\DataFixtures; namespace App\DataFixtures;
use App\Entity\Attachments\AttachmentType; use App\Entity\Attachments\AttachmentType;
use App\Entity\Base\StructuralDBElement; use App\Entity\Base\StructuralDBElement;
use App\Entity\Devices\Device; use App\Entity\Devices\Device;
@ -32,15 +30,12 @@ use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit; use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Storelocation; use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier; use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
class DataStructureFixtures extends Fixture class DataStructureFixtures extends Fixture
{ {
protected $em; protected $em;
public function __construct(EntityManagerInterface $entityManager) public function __construct(EntityManagerInterface $entityManager)
@ -49,15 +44,13 @@ class DataStructureFixtures extends Fixture
} }
/** /**
* Load data fixtures with the passed EntityManager * Load data fixtures with the passed EntityManager.
*
* @param ObjectManager $manager
*/ */
public function load(ObjectManager $manager) public function load(ObjectManager $manager)
{ {
//Reset autoincrement //Reset autoincrement
$types = [AttachmentType::class, Device::class, Category::class, Footprint::class, Manufacturer::class, $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) { foreach ($types as $type) {
$this->createNodesForClass($type, $manager); $this->createNodesForClass($type, $manager);
@ -68,6 +61,7 @@ class DataStructureFixtures extends Fixture
/** /**
* Creates a datafixture with serveral nodes for the given class. * 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 * @param ObjectManager $manager The ObjectManager that should be used to persist the nodes
*/ */

View file

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

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\DataFixtures; namespace App\DataFixtures;
@ -26,7 +25,6 @@ use App\Entity\UserSystem\User;
use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use ReflectionClass;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
class UserFixtures extends Fixture class UserFixtures extends Fixture

View file

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

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\DataTables\Column; namespace App\DataTables\Column;
use App\Entity\Base\DBElement; use App\Entity\Base\DBElement;
use App\Entity\Base\NamedDBElement; use App\Entity\Base\NamedDBElement;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
@ -34,7 +32,6 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
class EntityColumn extends AbstractColumn class EntityColumn extends AbstractColumn
{ {
protected $urlGenerator; protected $urlGenerator;
protected $accessor; 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. * 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 * @param mixed $value The single value of the column
*
* @return mixed * @return mixed
*/ */
public function normalize($value) public function normalize($value)
{ {
/** @var NamedDBElement $value */ /* @var NamedDBElement $value */
return $value; return $value;
} }
@ -63,7 +61,7 @@ class EntityColumn extends AbstractColumn
$resolver->setRequired('property'); $resolver->setRequired('property');
$resolver->setDefault('field', function (Options $option) { $resolver->setDefault('field', function (Options $option) {
return $option['property'] . '.name'; return $option['property'].'.name';
}); });
$resolver->setDefault('render', function (Options $options) { $resolver->setDefault('render', function (Options $options) {
@ -72,7 +70,7 @@ class EntityColumn extends AbstractColumn
$entity = $this->accessor->getValue($context, $options['property']); $entity = $this->accessor->getValue($context, $options['property']);
if ($entity) { if ($entity) {
if ($entity->getID() !== null) { if (null !== $entity->getID()) {
return sprintf( return sprintf(
'<a href="%s">%s</a>', '<a href="%s">%s</a>',
$this->urlGenerator->listPartsURL($entity), $this->urlGenerator->listPartsURL($entity),

View file

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

View file

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

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
declare(strict_types=1); declare(strict_types=1);
@ -65,7 +64,6 @@ use Doctrine\ORM\Mapping as ORM;
* "Supplier" = "SupplierAttachment", "User" = "UserAttachment" * "Supplier" = "SupplierAttachment", "User" = "UserAttachment"
* }) * })
* @ORM\EntityListeners({"App\EntityListeners\AttachmentDeleteListener"}) * @ORM\EntityListeners({"App\EntityListeners\AttachmentDeleteListener"})
*
*/ */
abstract class Attachment extends NamedDBElement 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. * 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', 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. * 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']; 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%']; public const INTERNAL_PLACEHOLDER = ['%BASE%', '%MEDIA%', '%SECURE%'];
@ -109,7 +107,7 @@ abstract class Attachment extends NamedDBElement
protected $original_filename; protected $original_filename;
/** /**
* ORM mapping is done in sub classes (like PartAttachment) * ORM mapping is done in sub classes (like PartAttachment).
*/ */
protected $element; protected $element;
@ -129,7 +127,7 @@ abstract class Attachment extends NamedDBElement
public function __construct() public function __construct()
{ {
//parent::__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!'); 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); $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. * 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). * If the attachment is external, false is returned (3D Models must be internal).
*
* @return bool * @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. //We just assume that 3D Models are internally saved, otherwise we get problems loading them.
if ($this->isExternal()) { if ($this->isExternal()) {
@ -171,14 +170,15 @@ abstract class Attachment extends NamedDBElement
$extension = pathinfo($this->getPath(), PATHINFO_EXTENSION); $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 * @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 //When path is empty, this attachment can not be external
if (empty($this->path)) { 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 //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)) { if (empty($tmp)) {
return true; 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. * 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. * 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. * @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 //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)) { if (empty($tmp)) {
return false; 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) * 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. * @return bool True if the attachment is uning an builtin file.
*/ */
public function isBuiltIn() : bool public function isBuiltIn(): bool
{ {
return static::checkIfBuiltin($this->path); return static::checkIfBuiltin($this->path);
} }
@ -232,9 +234,10 @@ abstract class Attachment extends NamedDBElement
* Returns the extension of the file referenced via the attachment. * Returns the extension of the file referenced via the attachment.
* For a path like %BASE/path/foo.bar, bar will be returned. * For a path like %BASE/path/foo.bar, bar will be returned.
* If this attachment is external null is returned. * If this attachment is external null is returned.
*
* @return string|null The file extension in lower case. * @return string|null The file extension in lower case.
*/ */
public function getExtension() : ?string public function getExtension(): ?string
{ {
if ($this->isExternal()) { if ($this->isExternal()) {
return null; 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. * 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). * Returns null, if the file is not external (and not builtin).
*
* @return string|null * @return string|null
*/ */
public function getURL(): ?string public function getURL(): ?string
@ -274,6 +278,7 @@ abstract class Attachment extends NamedDBElement
/** /**
* Returns the hostname where the external file is stored. * Returns the hostname where the external file is stored.
* Returns null, if the file is not external. * Returns null, if the file is not external.
*
* @return string|null * @return string|null
*/ */
public function getHost(): ?string 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. * 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. * @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 * @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; $new_filename = null;
} }
$this->original_filename = $new_filename; $this->original_filename = $new_filename;
return $this; return $this;
} }
@ -347,7 +355,6 @@ abstract class Attachment extends NamedDBElement
* Get the type of this attachement. * Get the type of this attachement.
* *
* @return AttachmentType the type of this attachement * @return AttachmentType the type of this attachement
*
*/ */
public function getAttachmentType(): ?AttachmentType public function getAttachmentType(): ?AttachmentType
{ {
@ -370,8 +377,6 @@ abstract class Attachment extends NamedDBElement
****************************************************************************************************/ ****************************************************************************************************/
/** /**
* @param bool $show_in_table
*
* @return self * @return self
*/ */
public function setShowInTable(bool $show_in_table): self public function setShowInTable(bool $show_in_table): self
@ -381,51 +386,48 @@ abstract class Attachment extends NamedDBElement
return $this; return $this;
} }
public function setElement(AttachmentContainingDBElement $element) : Attachment public function setElement(AttachmentContainingDBElement $element): self
{ {
if (!is_a($element,static::ALLOWED_ELEMENT_CLASS)) { if (!is_a($element, static::ALLOWED_ELEMENT_CLASS)) {
throw new \InvalidArgumentException(sprintf( throw new \InvalidArgumentException(sprintf('The element associated with a %s must be a %s!', \get_class($this), static::ALLOWED_ELEMENT_CLASS));
'The element associated with a %s must be a %s!',
get_class($this),
static::ALLOWED_ELEMENT_CLASS
));
} }
$this->element = $element; $this->element = $element;
return $this; return $this;
} }
/** /**
* @param string $path
* @return Attachment * @return Attachment
*/ */
public function setPath(string $path): Attachment public function setPath(string $path): self
{ {
$this->path = $path; $this->path = $path;
return $this; return $this;
} }
/** /**
* @param AttachmentType $attachement_type
* @return Attachment * @return Attachment
*/ */
public function setAttachmentType(AttachmentType $attachement_type): Attachment public function setAttachmentType(AttachmentType $attachement_type): self
{ {
$this->attachment_type = $attachement_type; $this->attachment_type = $attachement_type;
return $this; return $this;
} }
/** /**
* Sets the url associated with this attachment. * Sets the url associated with this attachment.
* If the url is empty nothing is changed, to not override the file path. * If the url is empty nothing is changed, to not override the file path.
* @param string|null $url *
* @return Attachment * @return Attachment
*/ */
public function setURL(?string $url) : Attachment public function setURL(?string $url): self
{ {
//Only set if the URL is not empty //Only set if the URL is not empty
if (!empty($url)) { 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!'); 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; return $this;
} }
/***************************************************************************************************** /*****************************************************************************************************
* Static functions * Static functions
*****************************************************************************************************/ *****************************************************************************************************/
/** /**
* Checks if the given path is a path to a builtin ressource. * Checks if the given path is a path to a builtin ressource.
*
* @param string $path The path that should be checked * @param string $path The path that should be checked
*
* @return bool True if the path is pointing to a builtin ressource. * @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 //After the %PLACEHOLDER% comes a slash, so we can check if we have a placholder via explode
$tmp = explode('/', $path); $tmp = explode('/', $path);
@ -455,22 +458,25 @@ abstract class Attachment extends NamedDBElement
if (empty($tmp)) { if (empty($tmp)) {
return false; 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. * Check if a string is a URL and is valid.
*
* @param $string string The string which should be checked. * @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 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. * @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.* * *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. * @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 if ($only_http) { //Check if scheme is HTTPS or HTTP
$scheme = parse_url($string, PHP_URL_SCHEME); $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. return false; //All other schemes are not valid.
} }
} }

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
declare(strict_types=1); declare(strict_types=1);
@ -48,7 +47,6 @@ use App\Entity\Base\NamedDBElement;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/** /**
* @ORM\MappedSuperclass() * @ORM\MappedSuperclass()
@ -79,34 +77,39 @@ abstract class AttachmentContainingDBElement extends NamedDBElement
/** /**
* Gets all attachments associated with this element. * Gets all attachments associated with this element.
*
* @return Attachment[]|Collection * @return Attachment[]|Collection
*/ */
public function getAttachments() : Collection public function getAttachments(): Collection
{ {
return $this->attachments; return $this->attachments;
} }
/** /**
* Adds an attachment to this element * Adds an attachment to this element.
*
* @param Attachment $attachment Attachment * @param Attachment $attachment Attachment
*
* @return $this * @return $this
*/ */
public function addAttachment(Attachment $attachment) : self public function addAttachment(Attachment $attachment): self
{ {
//Attachment must be associated with this element //Attachment must be associated with this element
$attachment->setElement($this); $attachment->setElement($this);
$this->attachments->add($attachment); $this->attachments->add($attachment);
return $this; return $this;
} }
/** /**
* Removes the given attachment from this element * Removes the given attachment from this element.
* @param Attachment $attachment *
* @return $this * @return $this
*/ */
public function removeAttachment(Attachment $attachment) : self public function removeAttachment(Attachment $attachment): self
{ {
$this->attachments->removeElement($attachment); $this->attachments->removeElement($attachment);
return $this; return $this;
} }
} }

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
declare(strict_types=1); declare(strict_types=1);
@ -44,10 +43,10 @@ declare(strict_types=1);
namespace App\Entity\Attachments; namespace App\Entity\Attachments;
use App\Entity\Base\StructuralDBElement; use App\Entity\Base\StructuralDBElement;
use App\Validator\Constraints\ValidFileFilter;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use App\Validator\Constraints\ValidFileFilter;
/** /**
* Class AttachmentType. * Class AttachmentType.
@ -85,7 +84,7 @@ class AttachmentType extends StructuralDBElement
* @ORM\Column(type="text") * @ORM\Column(type="text")
* @ValidFileFilter * @ValidFileFilter
*/ */
protected $filetype_filter = ""; protected $filetype_filter = '';
public function __construct() public function __construct()
{ {
@ -108,6 +107,7 @@ class AttachmentType extends StructuralDBElement
* Gets an filter, which file types are allowed for attachment files. * Gets an filter, which file types are allowed for attachment files.
* Must be in the format of <input type=file> accept attribute * 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). * (See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Unique_file_type_specifiers).
*
* @return string * @return string
*/ */
public function getFiletypeFilter(): string public function getFiletypeFilter(): string
@ -116,12 +116,12 @@ class AttachmentType extends StructuralDBElement
} }
/** /**
* @param string $filetype_filter
* @return AttachmentType * @return AttachmentType
*/ */
public function setFiletypeFilter(string $filetype_filter): AttachmentType public function setFiletypeFilter(string $filetype_filter): self
{ {
$this->filetype_filter = $filetype_filter; $this->filetype_filter = $filetype_filter;
return $this; return $this;
} }
@ -133,6 +133,6 @@ class AttachmentType extends StructuralDBElement
*/ */
public function getIDString(): string public function getIDString(): string
{ {
return 'AT' . sprintf('%09d', $this->getID()); return 'AT'.sprintf('%09d', $this->getID());
} }
} }

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\Attachments; namespace App\Entity\Attachments;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* A attachment attached to an attachmentType element. * A attachment attached to an attachmentType element.
* @package App\Entity *
* @ORM\Entity() * @ORM\Entity()
*/ */
class AttachmentTypeAttachment extends Attachment class AttachmentTypeAttachment extends Attachment
{ {
/** /**
* @var AttachmentType The element this attachment is associated with. * @var AttachmentType The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Attachments\AttachmentType", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\Attachments\AttachmentType", inversedBy="attachments")

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\Attachments; namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Category; use App\Entity\Parts\Category;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* A attachment attached to a category element. * A attachment attached to a category element.
* @package App\Entity *
* @ORM\Entity() * @ORM\Entity()
*/ */
class CategoryAttachment extends Attachment class CategoryAttachment extends Attachment
{ {
/** /**
* @var Category The element this attachment is associated with. * @var Category The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Category", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\Parts\Category", inversedBy="attachments")

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\Attachments; 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\PriceInformations\Currency;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* A attachment attached to a currency element. * A attachment attached to a currency element.
* @package App\Entity *
* @ORM\Entity() * @ORM\Entity()
*/ */
class CurrencyAttachment extends Attachment class CurrencyAttachment extends Attachment
{ {
/** /**
* @var Currency The element this attachment is associated with. * @var Currency The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\PriceInformations\Currency", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\PriceInformations\Currency", inversedBy="attachments")

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\Attachments; namespace App\Entity\Attachments;
use App\Entity\Devices\Device; use App\Entity\Devices\Device;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* A attachment attached to a device element. * A attachment attached to a device element.
* @package App\Entity *
* @ORM\Entity() * @ORM\Entity()
*/ */
class DeviceAttachment extends Attachment class DeviceAttachment extends Attachment

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\Attachments; namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Footprint; use App\Entity\Parts\Footprint;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* A attachment attached to a footprint element. * A attachment attached to a footprint element.
* @package App\Entity *
* @ORM\Entity() * @ORM\Entity()
*/ */
class FootprintAttachment extends Attachment class FootprintAttachment extends Attachment
{ {
/** /**
* @var Footprint The element this attachment is associated with. * @var Footprint The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Footprint", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\Parts\Footprint", inversedBy="attachments")

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\Attachments; 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\Group;
use App\Entity\UserSystem\User;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* A attachment attached to a Group element. * A attachment attached to a Group element.
* @package App\Entity *
* @ORM\Entity() * @ORM\Entity()
*/ */
class GroupAttachment extends Attachment class GroupAttachment extends Attachment
{ {
/** /**
* @var Group The element this attachment is associated with. * @var Group The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\Group", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\Group", inversedBy="attachments")

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\Attachments; namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer; use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* A attachment attached to a manufacturer element. * A attachment attached to a manufacturer element.
* @package App\Entity *
* @ORM\Entity() * @ORM\Entity()
*/ */
class ManufacturerAttachment extends Attachment class ManufacturerAttachment extends Attachment
{ {
/** /**
* @var Manufacturer The element this attachment is associated with. * @var Manufacturer The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Manufacturer", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\Parts\Manufacturer", inversedBy="attachments")

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\Attachments; namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer; use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit; use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* A attachment attached to a measurement unit element. * A attachment attached to a measurement unit element.
* @package App\Entity *
* @ORM\Entity() * @ORM\Entity()
*/ */
class MeasurementUnitAttachment extends Attachment class MeasurementUnitAttachment extends Attachment
{ {
/** /**
* @var Manufacturer The element this attachment is associated with. * @var Manufacturer The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\MeasurementUnit", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\Parts\MeasurementUnit", inversedBy="attachments")

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\Attachments; namespace App\Entity\Attachments;
@ -27,12 +26,11 @@ use Doctrine\ORM\Mapping as ORM;
/** /**
* A attachment attached to a part element. * A attachment attached to a part element.
* @package App\Entity *
* @ORM\Entity() * @ORM\Entity()
*/ */
class PartAttachment extends Attachment class PartAttachment extends Attachment
{ {
/** /**
* @var Part The element this attachment is associated with. * @var Part The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Part", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\Parts\Part", inversedBy="attachments")

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\Attachments; 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\Storelocation;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpKernel\HttpCache\Store;
/** /**
* A attachment attached to a measurement unit element. * A attachment attached to a measurement unit element.
* @package App\Entity *
* @ORM\Entity() * @ORM\Entity()
*/ */
class StorelocationAttachment extends Attachment class StorelocationAttachment extends Attachment
{ {
/** /**
* @var Storelocation The element this attachment is associated with. * @var Storelocation The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Storelocation", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\Parts\Storelocation", inversedBy="attachments")

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\Attachments; 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\Parts\Supplier;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* A attachment attached to a supplier element. * A attachment attached to a supplier element.
* @package App\Entity *
* @ORM\Entity() * @ORM\Entity()
*/ */
class SupplierAttachment extends Attachment class SupplierAttachment extends Attachment
{ {
/** /**
* @var Supplier The element this attachment is associated with. * @var Supplier The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Supplier", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\Parts\Supplier", inversedBy="attachments")

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\Attachments; 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 App\Entity\UserSystem\User;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* A attachment attached to a user element. * A attachment attached to a user element.
* @package App\Entity *
* @ORM\Entity() * @ORM\Entity()
*/ */
class UserAttachment extends Attachment class UserAttachment extends Attachment
{ {
/** /**
* @var User The element this attachment is associated with. * @var User The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User", inversedBy="attachments")

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
declare(strict_types=1); declare(strict_types=1);

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
declare(strict_types=1); declare(strict_types=1);
@ -104,7 +103,6 @@ abstract class DBElement
* This should have a form like P000014, for a part with ID 14. * This should have a form like P000014, for a part with ID 14.
* *
* @return string The ID as a string; * @return string The ID as a string;
*
*/ */
abstract public function getIDString(): string; abstract public function getIDString(): string;

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\Base; namespace App\Entity\Base;
use App\Entity\Attachments\Attachment; use App\Entity\Attachments\Attachment;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
use App\Security\Annotations\ColumnSecurity;
use Symfony\Component\Validator\Constraints as Assert; 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. * 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 trait MasterAttachmentTrait
{ {
@ -42,10 +38,10 @@ trait MasterAttachmentTrait
*/ */
protected $master_picture_attachment; protected $master_picture_attachment;
/** /**
* Get the master picture "Attachment"-object of this part (if there is one). * 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. * 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) * @return Attachment the master picture Attachement of this part (if there is one)
*/ */
public function getMasterPictureAttachment(): ?Attachment public function getMasterPictureAttachment(): ?Attachment
@ -55,14 +51,13 @@ trait MasterAttachmentTrait
/** /**
* Sets the new master picture for this part. * Sets the new master picture for this part.
* @param Attachment|null $new_master_attachment *
* @return Part * @return Part
*/ */
public function setMasterPictureAttachment(?Attachment $new_master_attachment): self public function setMasterPictureAttachment(?Attachment $new_master_attachment): self
{ {
$this->master_picture_attachment = $new_master_attachment; $this->master_picture_attachment = $new_master_attachment;
return $this; return $this;
} }
} }

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
declare(strict_types=1); declare(strict_types=1);
@ -44,8 +43,8 @@ declare(strict_types=1);
namespace App\Entity\Base; namespace App\Entity\Base;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/** /**
* All subclasses of this class have an attribute "name". * All subclasses of this class have an attribute "name".
@ -55,7 +54,6 @@ use Symfony\Component\Serializer\Annotation\Groups;
*/ */
abstract class NamedDBElement extends DBElement abstract class NamedDBElement extends DBElement
{ {
use TimestampTrait; 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 * @return string the name of this element
*/ */
public function getName(): string public function getName(): string
@ -91,6 +90,7 @@ abstract class NamedDBElement extends DBElement
* Change the name of this element. * Change the name of this element.
* *
* @param string $new_name the new name * @param string $new_name the new name
*
* @return self * @return self
*/ */
public function setName(string $new_name): self public function setName(string $new_name): self

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
declare(strict_types=1); declare(strict_types=1);
@ -68,9 +67,10 @@ abstract class PartsContainingDBElement extends StructuralDBElement
/** /**
* Returns the parts associated with this element. * Returns the parts associated with this element.
*
* @return Collection|Part[] * @return Collection|Part[]
*/ */
public function getParts() : Collection public function getParts(): Collection
{ {
return $this->parts; return $this->parts;
} }

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
declare(strict_types=1); declare(strict_types=1);
@ -44,9 +43,9 @@ declare(strict_types=1);
namespace App\Entity\Base; namespace App\Entity\Base;
use App\Entity\Attachments\AttachmentContainingDBElement; use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Validator\Constraints\NoneOfItsChildren;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use App\Validator\Constraints\NoneOfItsChildren;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\Groups;
@ -107,12 +106,9 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
/** @var string[] all names of all parent elements as a array of strings, /** @var string[] all names of all parent elements as a array of strings,
* the last array element is the name of the element itself * the last array element is the name of the element itself
*
*/ */
private $full_path_strings; private $full_path_strings;
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
@ -133,13 +129,13 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
* *
* @throws \InvalidArgumentException if there was an error * @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); $class_name = \get_class($this);
//Check if both elements compared, are from the same type //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): // (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!'); 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. * @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. * Get the comment of the element.
*
* @return string the comment * @return string the comment
*/ */
public function getComment(): ?string 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 * @return int the level of this element (zero means a most top element
* [a subelement of the root node]) * [a subelement of the root node])
*
*/ */
public function getLevel(): int public function getLevel(): int
{ {
/** /*
* Only check for nodes that have a parent. In the other cases zero is correct. * 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; $element = $this->parent;
while ($element !== null) { while (null !== $element) {
/** @var StructuralDBElement $element */ /** @var StructuralDBElement $element */
$element = $element->parent; $element = $element->parent;
++$this->level; ++$this->level;
} }
} }
return $this->level; return $this->level;
} }
@ -218,12 +216,11 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
* @param string $delimeter the delimeter of the returned string * @param string $delimeter the delimeter of the returned string
* *
* @return string the full path (incl. the name of this element), delimeted by $delimeter * @return string the full path (incl. the name of this element), delimeted by $delimeter
*
*/ */
public function getFullPath(string $delimeter = self::PATH_DELIMITER_ARROW): string public function getFullPath(string $delimeter = self::PATH_DELIMITER_ARROW): string
{ {
if (!\is_array($this->full_path_strings)) { if (!\is_array($this->full_path_strings)) {
$this->full_path_strings = array(); $this->full_path_strings = [];
$this->full_path_strings[] = $this->getName(); $this->full_path_strings[] = $this->getName();
$element = $this; $element = $this;
@ -233,7 +230,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
$element = $element->parent; $element = $element->parent;
$this->full_path_strings[] = $element->getName(); $this->full_path_strings[] = $element->getName();
//Decrement to prevent mem overflow. //Decrement to prevent mem overflow.
$overflow--; --$overflow;
} }
$this->full_path_strings = array_reverse($this->full_path_strings); $this->full_path_strings = array_reverse($this->full_path_strings);
@ -242,9 +239,9 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
return implode($delimeter, $this->full_path_strings); 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), * @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)
*/ */
@ -254,7 +251,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
$tmp[] = $this; $tmp[] = $this;
//We only allow 20 levels depth //We only allow 20 levels depth
while (!end($tmp)->isRoot() && count($tmp) < 20) { while (!end($tmp)->isRoot() && \count($tmp) < 20) {
$tmp[] = end($tmp)->parent; $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 * @param self $new_parent The new parent object
*
* @return StructuralDBElement * @return StructuralDBElement
*/ */
public function setParent(?self $new_parent) : self public function setParent(?self $new_parent): self
{ {
/* /*
if ($new_parent->isChildOf($this)) { if ($new_parent->isChildOf($this)) {
@ -311,7 +310,9 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
/** /**
* Set the comment. * Set the comment.
*
* @param string $new_comment the new comment * @param string $new_comment the new comment
*
* @return StructuralDBElement * @return StructuralDBElement
*/ */
public function setComment(?string $new_comment): self public function setComment(?string $new_comment): self
@ -321,7 +322,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
return $this; return $this;
} }
public function setChildren(array $element) : self public function setChildren(array $element): self
{ {
$this->children = $element; $this->children = $element;
@ -329,16 +330,16 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
} }
/** /**
* @param bool $not_selectable
* @return StructuralDBElement * @return StructuralDBElement
*/ */
public function setNotSelectable(bool $not_selectable): StructuralDBElement public function setNotSelectable(bool $not_selectable): self
{ {
$this->not_selectable = $not_selectable; $this->not_selectable = $not_selectable;
return $this; return $this;
} }
public function clearChildren() : self public function clearChildren(): self
{ {
$this->children = new ArrayCollection(); $this->children = new ArrayCollection();

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\Base; namespace App\Entity\Base;
use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\Groups;
/** /**
* A entity with these trait contains informations about, when it was created and edited last time * A entity with these trait contains informations about, when it was created and edited last time.
* @package App\Entity\Base
*/ */
trait TimestampTrait trait TimestampTrait
{ {

View file

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

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
declare(strict_types=1); declare(strict_types=1);
@ -90,7 +89,6 @@ class DevicePart extends DBElement
*/ */
protected $mountnames; protected $mountnames;
/** /**
* Returns the ID as an string, defined by the element class. * Returns the ID as an string, defined by the element class.
* This should have a form like P000014, for a part with ID 14. * This should have a form like P000014, for a part with ID 14.

View file

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

View file

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

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
declare(strict_types=1); declare(strict_types=1);
@ -52,7 +51,6 @@ declare(strict_types=1);
namespace App\Entity\Parts; namespace App\Entity\Parts;
use App\Entity\Attachments\FootprintAttachment;
use App\Entity\Attachments\ManufacturerAttachment; use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Base\Company; use App\Entity\Base\Company;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
@ -72,7 +70,6 @@ class Manufacturer extends Company
*/ */
protected $attachments; protected $attachments;
/** /**
* @ORM\OneToMany(targetEntity="Manufacturer", mappedBy="parent") * @ORM\OneToMany(targetEntity="Manufacturer", mappedBy="parent")
*/ */

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\Parts; namespace App\Entity\Parts;
use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Attachments\MeasurementUnitAttachment; use App\Entity\Attachments\MeasurementUnitAttachment;
use App\Entity\Base\PartsContainingDBElement; use App\Entity\Base\PartsContainingDBElement;
use Doctrine\Common\Collections\Collection; 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 unit represents the unit in which the amount of parts in stock are measured.
* This could be something like N, gramms, meters, etc... * This could be something like N, gramms, meters, etc...
* *
* @package App\Entity
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository") * @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
* @ORM\Table(name="`measurement_units`") * @ORM\Table(name="`measurement_units`")
* @UniqueEntity("unit") * @UniqueEntity("unit")
*/ */
class MeasurementUnit extends PartsContainingDBElement class MeasurementUnit extends PartsContainingDBElement
{ {
/** /**
* @var Collection|MeasurementUnitAttachment[] * @var Collection|MeasurementUnitAttachment[]
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\MeasurementUnitAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true) * @ORM\OneToMany(targetEntity="App\Entity\Attachments\MeasurementUnitAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
@ -92,11 +87,10 @@ class MeasurementUnit extends PartsContainingDBElement
* This should have a form like P000014, for a part with ID 14. * This should have a form like P000014, for a part with ID 14.
* *
* @return string The ID as a string; * @return string The ID as a string;
*
*/ */
public function getIDString(): string public function getIDString(): string
{ {
return 'MU' . $this->getID(); return 'MU'.$this->getID();
} }
/** /**
@ -109,11 +103,13 @@ class MeasurementUnit extends PartsContainingDBElement
/** /**
* @param string $unit * @param string $unit
*
* @return MeasurementUnit * @return MeasurementUnit
*/ */
public function setUnit(?string $unit): MeasurementUnit public function setUnit(?string $unit): self
{ {
$this->unit = $unit; $this->unit = $unit;
return $this; return $this;
} }
@ -126,12 +122,12 @@ class MeasurementUnit extends PartsContainingDBElement
} }
/** /**
* @param bool $isInteger
* @return MeasurementUnit * @return MeasurementUnit
*/ */
public function setIsInteger(bool $isInteger): MeasurementUnit public function setIsInteger(bool $isInteger): self
{ {
$this->is_integer = $isInteger; $this->is_integer = $isInteger;
return $this; return $this;
} }
@ -144,12 +140,12 @@ class MeasurementUnit extends PartsContainingDBElement
} }
/** /**
* @param bool $usesSIPrefixes
* @return MeasurementUnit * @return MeasurementUnit
*/ */
public function setUseSIPrefix(bool $usesSIPrefixes): MeasurementUnit public function setUseSIPrefix(bool $usesSIPrefixes): self
{ {
$this->use_si_prefix = $usesSIPrefixes; $this->use_si_prefix = $usesSIPrefixes;
return $this; return $this;
} }
} }

View file

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

View file

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

View file

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

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\Parts\PartTraits; namespace App\Entity\Parts\PartTraits;
use App\Entity\Parts\Category; use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint; use App\Entity\Parts\Footprint;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
@ -80,6 +78,7 @@ trait BasicPropertyTrait
/** /**
* Get the description string like it is saved in the database. * Get the description string like it is saved in the database.
* This can contain BBCode, it is not parsed yet. * This can contain BBCode, it is not parsed yet.
*
* @return string the description * @return string the description
*/ */
public function getDescription(): string public function getDescription(): string
@ -89,6 +88,7 @@ trait BasicPropertyTrait
/** /**
* Get the comment associated with this part. * Get the comment associated with this part.
*
* @return string The raw/unparsed comment * @return string The raw/unparsed comment
*/ */
public function getComment(): string public function getComment(): string
@ -99,6 +99,7 @@ trait BasicPropertyTrait
/** /**
* Get if this part is visible. * Get if this part is visible.
* This property is not used yet. * This property is not used yet.
*
* @return bool true if this part is visible * @return bool true if this part is visible
* false if this part isn't visible * false if this part isn't visible
*/ */
@ -109,6 +110,7 @@ trait BasicPropertyTrait
/** /**
* Check if this part is a favorite. * Check if this part is a favorite.
*
* @return bool * true if this part is a favorite * @return bool * true if this part is a favorite
* * false if this part is not a favorite. * * false if this part is not a favorite.
*/ */
@ -117,10 +119,10 @@ trait BasicPropertyTrait
return $this->favorite; return $this->favorite;
} }
/** /**
* Get the category of this part (e.g. Resistors). * Get the category of this part (e.g. Resistors).
* There is always a category, for each part! * There is always a category, for each part!
*
* @return Category the category of this part * @return Category the category of this part
*/ */
public function getCategory(): ?Category 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. * @return Footprint|null The footprint of this part. Null if this part should no have a footprint.
*/ */
public function getFootprint(): ?Footprint public function getFootprint(): ?Footprint
@ -139,36 +142,44 @@ trait BasicPropertyTrait
/** /**
* Sets the description of this part. * Sets the description of this part.
*
* @param string $new_description the new description * @param string $new_description the new description
*
* @return self * @return self
*/ */
public function setDescription(?string $new_description): self public function setDescription(?string $new_description): self
{ {
$this->description = $new_description; $this->description = $new_description;
return $this; return $this;
} }
/** /**
* Sets the comment property of this part. * Sets the comment property of this part.
*
* @param string $new_comment the new comment * @param string $new_comment the new comment
*
* @return self * @return self
*/ */
public function setComment(string $new_comment): self public function setComment(string $new_comment): self
{ {
$this->comment = $new_comment; $this->comment = $new_comment;
return $this; return $this;
} }
/** /**
* Set the category of this Part. * 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 * @param Category $category The new category of this part
*
* @return self * @return self
*/ */
public function setCategory(Category $category): self public function setCategory(Category $category): self
{ {
$this->category = $category; $this->category = $category;
return $this; return $this;
} }
@ -183,6 +194,7 @@ trait BasicPropertyTrait
public function setFootprint(?Footprint $new_footprint): self public function setFootprint(?Footprint $new_footprint): self
{ {
$this->footprint = $new_footprint; $this->footprint = $new_footprint;
return $this; return $this;
} }
@ -197,7 +209,7 @@ trait BasicPropertyTrait
public function setFavorite(bool $new_favorite_status): self public function setFavorite(bool $new_favorite_status): self
{ {
$this->favorite = $new_favorite_status; $this->favorite = $new_favorite_status;
return $this; return $this;
} }
} }

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\Parts\PartTraits; namespace App\Entity\Parts\PartTraits;
use App\Entity\Parts\MeasurementUnit; use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\PartLot; use App\Entity\Parts\PartLot;
use App\Security\Annotations\ColumnSecurity; 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. * This trait collects all aspects of a part related to instock, part lots.
* @package App\Entity\Parts\PartTraits
*/ */
trait InstockTrait trait InstockTrait
{ {
@ -61,9 +58,10 @@ trait InstockTrait
/** /**
* Get all part lots where this part is stored. * Get all part lots where this part is stored.
*
* @return PartLot[]|Collection * @return PartLot[]|Collection
*/ */
public function getPartLots() : Collection public function getPartLots(): Collection
{ {
return $this->partLots; return $this->partLots;
} }
@ -71,30 +69,35 @@ trait InstockTrait
/** /**
* Adds the given part lot, to the list of part lots. * Adds the given part lot, to the list of part lots.
* The part lot is assigned to this part. * The part lot is assigned to this part.
* @param PartLot $lot *
* @return self * @return self
*/ */
public function addPartLot(PartLot $lot): self public function addPartLot(PartLot $lot): self
{ {
$lot->setPart($this); $lot->setPart($this);
$this->partLots->add($lot); $this->partLots->add($lot);
return $this; return $this;
} }
/** /**
* Removes the given part lot from the list of part lots. * Removes the given part lot from the list of part lots.
*
* @param PartLot $lot The part lot that should be deleted. * @param PartLot $lot The part lot that should be deleted.
*
* @return self * @return self
*/ */
public function removePartLot(PartLot $lot): self public function removePartLot(PartLot $lot): self
{ {
$this->partLots->removeElement($lot); $this->partLots->removeElement($lot);
return $this; return $this;
} }
/** /**
* Gets the measurement unit in which the part's amount should be measured. * 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. * Returns null if no specific unit was that. That means the parts are measured simply in quantity numbers.
*
* @return MeasurementUnit|null * @return MeasurementUnit|null
*/ */
public function getPartUnit(): ?MeasurementUnit public function getPartUnit(): ?MeasurementUnit
@ -105,18 +108,19 @@ trait InstockTrait
/** /**
* Sets the measurement unit in which the part's amount should be measured. * Sets the measurement unit in which the part's amount should be measured.
* Set to null, if the part should be measured in quantities. * Set to null, if the part should be measured in quantities.
* @param MeasurementUnit|null $partUnit *
* @return self * @return self
*/ */
public function setPartUnit(?MeasurementUnit $partUnit): self public function setPartUnit(?MeasurementUnit $partUnit): self
{ {
$this->partUnit = $partUnit; $this->partUnit = $partUnit;
return $this; return $this;
} }
/** /**
* Get the count of parts which must be in stock at least. * 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 * @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 . * Checks if this part uses the float amount .
* This setting is based on the part unit (see MeasurementUnit->isInteger()). * 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. * @return bool True if the float amount field should be used. False if the integer instock field should be used.
*/ */
public function useFloatAmount(): bool public function useFloatAmount(): bool
@ -146,10 +151,11 @@ trait InstockTrait
/** /**
* Returns the summed amount of this part (over all part lots) * 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 * @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 //TODO: Find a method to do this natively in SQL, the current method could be a bit slow
$sum = 0; $sum = 0;
@ -172,12 +178,15 @@ trait InstockTrait
/** /**
* Set the minimum amount of parts that have to be instock. * Set the minimum amount of parts that have to be instock.
* See getPartUnit() for the associated unit. * See getPartUnit() for the associated unit.
*
* @param float $new_minamount the new count of parts which should be in stock at least * @param float $new_minamount the new count of parts which should be in stock at least
*
* @return self * @return self
*/ */
public function setMinAmount(float $new_minamount): self public function setMinAmount(float $new_minamount): self
{ {
$this->minamount = $new_minamount; $this->minamount = $new_minamount;
return $this; return $this;
} }
} }

View file

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

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\Parts\PartTraits; namespace App\Entity\Parts\PartTraits;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
use App\Entity\PriceInformations\Orderdetail; use App\Entity\PriceInformations\Orderdetail;
use App\Security\Annotations\ColumnSecurity; 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. * This trait collects all aspects of a part related to orders and priceinformations.
* @package App\Entity\Parts\PartTraits
*/ */
trait OrderTrait trait OrderTrait
{ {
@ -67,6 +64,7 @@ trait OrderTrait
/** /**
* Get the selected order orderdetails of this part. * Get the selected order orderdetails of this part.
*
* @return Orderdetail the selected order orderdetails * @return Orderdetail the selected order orderdetails
*/ */
public function getOrderOrderdetails(): ?Orderdetail public function getOrderOrderdetails(): ?Orderdetail
@ -76,6 +74,7 @@ trait OrderTrait
/** /**
* Get the order quantity of this part. * Get the order quantity of this part.
*
* @return int the order quantity * @return int the order quantity
*/ */
public function getOrderQuantity(): int public function getOrderQuantity(): int
@ -101,9 +100,8 @@ trait OrderTrait
* @return Collection|Orderdetail[] * all orderdetails as a one-dimensional array of Orderdetails objects * @return Collection|Orderdetail[] * all orderdetails as a one-dimensional array of Orderdetails objects
* (empty array if there are no ones) * (empty array if there are no ones)
* * the array is sorted by the suppliers names / minimum order quantity * * 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 needed hide the obsolete entries
if ($hide_obsolete) { if ($hide_obsolete) {
@ -123,24 +121,28 @@ trait OrderTrait
/** /**
* Adds the given orderdetail to list of orderdetails. * Adds the given orderdetail to list of orderdetails.
* The orderdetail is assigned to this part. * The orderdetail is assigned to this part.
*
* @param Orderdetail $orderdetail The orderdetail that should be added. * @param Orderdetail $orderdetail The orderdetail that should be added.
*
* @return self * @return self
*/ */
public function addOrderdetail(Orderdetail $orderdetail) : self public function addOrderdetail(Orderdetail $orderdetail): self
{ {
$orderdetail->setPart($this); $orderdetail->setPart($this);
$this->orderdetails->add($orderdetail); $this->orderdetails->add($orderdetail);
return $this; return $this;
} }
/** /**
* Removes the given orderdetail from the list of orderdetails. * Removes the given orderdetail from the list of orderdetails.
* @param Orderdetail $orderdetail *
* @return OrderTrait * @return OrderTrait
*/ */
public function removeOrderdetail(Orderdetail $orderdetail) : self public function removeOrderdetail(Orderdetail $orderdetail): self
{ {
$this->orderdetails->removeElement($orderdetail); $this->orderdetails->removeElement($orderdetail);
return $this; return $this;
} }
@ -183,7 +185,7 @@ trait OrderTrait
{ {
$all_orderdetails = $this->getOrderdetails(); $all_orderdetails = $this->getOrderdetails();
if (0 === count($all_orderdetails)) { if (0 === \count($all_orderdetails)) {
return false; return false;
} }
@ -195,5 +197,4 @@ trait OrderTrait
return true; return true;
} }
} }

View file

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

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
declare(strict_types=1); declare(strict_types=1);
@ -52,7 +51,6 @@ declare(strict_types=1);
namespace App\Entity\Parts; namespace App\Entity\Parts;
use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Attachments\SupplierAttachment; use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Base\Company; use App\Entity\Base\Company;
use App\Entity\PriceInformations\Currency; use App\Entity\PriceInformations\Currency;
@ -101,7 +99,7 @@ class Supplier extends Company
protected $default_currency; 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) * @ORM\Column(name="shipping_costs", nullable=true, type="decimal", precision=11, scale=5)
* @Assert\PositiveOrZero() * @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. * Gets the currency that should be used by default, when creating a orderdetail with this supplier.
*
* @return ?Currency * @return ?Currency
*/ */
public function getDefaultCurrency() : ?Currency public function getDefaultCurrency(): ?Currency
{ {
return $this->default_currency; return $this->default_currency;
} }
/** /**
* Sets the default currency. * Sets the default currency.
*
* @param ?Currency $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; $this->default_currency = $default_currency;
return $this; return $this;
} }
/** /**
* Gets the shipping costs for an order with this supplier, given in base currency. * Gets the shipping costs for an order with this supplier, given in base currency.
*
* @return string|null A bcmath string with the shipping costs * @return string|null A bcmath string with the shipping costs
*/ */
public function getShippingCosts() : ?string public function getShippingCosts(): ?string
{ {
return $this->shipping_costs; return $this->shipping_costs;
} }
/** /**
* Sets the shipping costs for an order with this supplier. * 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; $this->shipping_costs = $shipping_costs;
return $this; return $this;
} }
/** /**
* Returns the ID as an string, defined by the element class. * Returns the ID as an string, defined by the element class.
* This should have a form like P000014, for a part with ID 14. * This should have a form like P000014, for a part with ID 14.

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\PriceInformations; namespace App\Entity\PriceInformations;
use App\Entity\Attachments\CurrencyAttachment; use App\Entity\Attachments\CurrencyAttachment;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Base\StructuralDBElement; use App\Entity\Base\StructuralDBElement;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; 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. * This entity describes a currency that can be used for price informations.
* @package App\Entity *
* @UniqueEntity("iso_code") * @UniqueEntity("iso_code")
* @ORM\Entity() * @ORM\Entity()
* @ORM\Table(name="currencies") * @ORM\Table(name="currencies")
*/ */
class Currency extends StructuralDBElement class Currency extends StructuralDBElement
{ {
public const PRICE_SCALE = 5; public const PRICE_SCALE = 5;
/** /**
@ -76,7 +72,8 @@ class Currency extends StructuralDBElement
protected $parent; protected $parent;
/** /**
* Returns the 3 letter ISO code of this currency * Returns the 3 letter ISO code of this currency.
*
* @return string * @return string
*/ */
public function getIsoCode(): ?string public function getIsoCode(): ?string
@ -86,23 +83,26 @@ class Currency extends StructuralDBElement
/** /**
* @param string $iso_code * @param string $iso_code
*
* @return Currency * @return Currency
*/ */
public function setIsoCode(?string $iso_code): Currency public function setIsoCode(?string $iso_code): self
{ {
$this->iso_code = $iso_code; $this->iso_code = $iso_code;
return $this; 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 * @return string|null
*/ */
public function getInverseExchangeRate(): ?string public function getInverseExchangeRate(): ?string
{ {
$tmp = $this->getExchangeRate(); $tmp = $this->getExchangeRate();
if ($tmp === null || $tmp === "0") { if (null === $tmp || '0' === $tmp) {
return null; return null;
} }
@ -111,7 +111,8 @@ class Currency extends StructuralDBElement
/** /**
* Returns The exchange rate between this currency and the base currency * 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 * @return string|null
*/ */
public function getExchangeRate(): ?string public function getExchangeRate(): ?string
@ -120,25 +121,23 @@ class Currency extends StructuralDBElement
} }
/** /**
* @param string|null $exchange_rate
* @return Currency * @return Currency
*/ */
public function setExchangeRate(?string $exchange_rate): Currency public function setExchangeRate(?string $exchange_rate): self
{ {
$this->exchange_rate = $exchange_rate; $this->exchange_rate = $exchange_rate;
return $this; return $this;
} }
/** /**
* Returns the ID as an string, defined by the element class. * Returns the ID as an string, defined by the element class.
* This should have a form like P000014, for a part with ID 14. * This should have a form like P000014, for a part with ID 14.
* *
* @return string The ID as a string; * @return string The ID as a string;
*
*/ */
public function getIDString(): string public function getIDString(): string
{ {
return 'C' . $this->getID(); return 'C'.$this->getID();
} }
} }

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
declare(strict_types=1); declare(strict_types=1);
@ -193,7 +192,7 @@ class Orderdetail extends DBElement
return $this->supplier_product_url; return $this->supplier_product_url;
} }
if ($this->getSupplier() === null) { if (null === $this->getSupplier()) {
return ''; return '';
} }
@ -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 * @param Pricedetail $pricedetail The pricedetail to add
*
* @return Orderdetail * @return Orderdetail
*/ */
public function addPricedetail(Pricedetail $pricedetail) : Orderdetail public function addPricedetail(Pricedetail $pricedetail): self
{ {
$pricedetail->setOrderdetail($this); $pricedetail->setOrderdetail($this);
$this->pricedetails->add($pricedetail); $this->pricedetails->add($pricedetail);
return $this; return $this;
} }
/** /**
* Removes an pricedetail from this orderdetail * Removes an pricedetail from this orderdetail.
* @param Pricedetail $pricedetail *
* @return Orderdetail * @return Orderdetail
*/ */
public function removePricedetail(Pricedetail $pricedetail) : Orderdetail public function removePricedetail(Pricedetail $pricedetail): self
{ {
$this->pricedetails->removeElement($pricedetail); $this->pricedetails->removeElement($pricedetail);
return $this; return $this;
} }
/** /**
* Find the pricedetail that is correct for the desired amount (the one with the greatest discount value with a * 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) * minimum order amount of the wished quantity).
*
* @param float $quantity this is the quantity to choose the correct pricedetails * @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 * @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) { if ($quantity <= 0) {
return null; return null;
@ -269,30 +273,34 @@ class Orderdetail extends DBElement
*********************************************************************************/ *********************************************************************************/
/** /**
* Sets a new part with which this orderdetail is associated * Sets a new part with which this orderdetail is associated.
* @param Part $part *
* @return Orderdetail * @return Orderdetail
*/ */
public function setPart(Part $part) : Orderdetail public function setPart(Part $part): self
{ {
$this->part = $part; $this->part = $part;
return $this; return $this;
} }
/** /**
* Sets the new supplier associated with this orderdetail. * Sets the new supplier associated with this orderdetail.
* @param Supplier $new_supplier *
* @return Orderdetail * @return Orderdetail
*/ */
public function setSupplier(Supplier $new_supplier) : Orderdetail public function setSupplier(Supplier $new_supplier): self
{ {
$this->supplier = $new_supplier; $this->supplier = $new_supplier;
return $this; return $this;
} }
/** /**
* Set the supplier part-nr. * Set the supplier part-nr.
*
* @param string $new_supplierpartnr the new supplier-part-nr * @param string $new_supplierpartnr the new supplier-part-nr
*
* @return Orderdetail * @return Orderdetail
* @return Orderdetail * @return Orderdetail
*/ */
@ -305,7 +313,9 @@ class Orderdetail extends DBElement
/** /**
* Set if the part is obsolete at the supplier of that orderdetails. * Set if the part is obsolete at the supplier of that orderdetails.
*
* @param bool $new_obsolete true means that this part is obsolete * @param bool $new_obsolete true means that this part is obsolete
*
* @return Orderdetail * @return Orderdetail
* @return Orderdetail * @return Orderdetail
*/ */
@ -319,10 +329,12 @@ class Orderdetail extends DBElement
/** /**
* Sets the custom product supplier URL for this order detail. * Sets the custom product supplier URL for this order detail.
* Set this to "", if the function getSupplierProductURL should return the automatic generated URL. * Set this to "", if the function getSupplierProductURL should return the automatic generated URL.
*
* @param $new_url string The new URL for the supplier URL. * @param $new_url string The new URL for the supplier URL.
*
* @return Orderdetail * @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 //Only change the internal URL if it is not the auto generated one
if ($new_url === $this->supplier->getAutoProductUrl($this->getSupplierPartNr())) { if ($new_url === $this->supplier->getAutoProductUrl($this->getSupplierPartNr())) {

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
declare(strict_types=1); declare(strict_types=1);
@ -69,7 +68,6 @@ use Symfony\Component\Validator\Constraints as Assert;
*/ */
class Pricedetail extends DBElement class Pricedetail extends DBElement
{ {
public const PRICE_PRECISION = 5; public const PRICE_PRECISION = 5;
use TimestampTrait; use TimestampTrait;
@ -142,9 +140,10 @@ class Pricedetail extends DBElement
/** /**
* Returns the price associated with this pricedetail. * Returns the price associated with this pricedetail.
* It is given in current currency and for the price related quantity. * It is given in current currency and for the price related quantity.
*
* @return string The price as string, like returned raw from DB. * @return string The price as string, like returned raw from DB.
*/ */
public function getPrice() : string public function getPrice(): string
{ {
return $this->price; return $this->price;
} }
@ -160,10 +159,11 @@ class Pricedetail extends DBElement
* *
* @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; $multiplier = (string) $multiplier;
$tmp = bcmul($this->price, $multiplier, static::PRICE_PRECISION); $tmp = bcmul($this->price, $multiplier, static::PRICE_PRECISION);
return bcdiv($tmp, (string) $this->price_related_quantity, static::PRICE_PRECISION); return bcdiv($tmp, (string) $this->price_related_quantity, static::PRICE_PRECISION);
//return ($this->price * $multiplier) / $this->price_related_quantity; //return ($this->price * $multiplier) / $this->price_related_quantity;
} }
@ -182,8 +182,10 @@ class Pricedetail extends DBElement
{ {
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); $tmp = round($this->price_related_quantity);
return $tmp < 1 ? 1 : $tmp; return $tmp < 1 ? 1 : $tmp;
} }
return $this->price_related_quantity; return $this->price_related_quantity;
} }
@ -203,6 +205,7 @@ class Pricedetail extends DBElement
{ {
if ($this->orderdetail && $this->orderdetail->getPart() && !$this->orderdetail->getPart()->useFloatAmount()) { if ($this->orderdetail && $this->orderdetail->getPart() && !$this->orderdetail->getPart()->useFloatAmount()) {
$tmp = round($this->min_discount_quantity); $tmp = round($this->min_discount_quantity);
return $tmp < 1 ? 1 : $tmp; return $tmp < 1 ? 1 : $tmp;
} }
@ -212,6 +215,7 @@ class Pricedetail extends DBElement
/** /**
* Returns the currency associated with this price information. * Returns the currency associated with this price information.
* Returns null, if no specific currency is selected and the global base currency should be assumed. * Returns null, if no specific currency is selected and the global base currency should be assumed.
*
* @return Currency|null * @return Currency|null
*/ */
public function getCurrency(): ?Currency public function getCurrency(): ?Currency
@ -227,24 +231,26 @@ class Pricedetail extends DBElement
/** /**
* Sets the orderdetail to which this pricedetail belongs to. * Sets the orderdetail to which this pricedetail belongs to.
* @param Orderdetail $orderdetail *
* @return $this * @return $this
*/ */
public function setOrderdetail(Orderdetail $orderdetail) : self public function setOrderdetail(Orderdetail $orderdetail): self
{ {
$this->orderdetail = $orderdetail; $this->orderdetail = $orderdetail;
return $this; return $this;
} }
/** /**
* Sets the currency associated with the price informations. * Sets the currency associated with the price informations.
* Set to null, to use the global base currency. * Set to null, to use the global base currency.
* @param Currency|null $currency *
* @return Pricedetail * @return Pricedetail
*/ */
public function setCurrency(?Currency $currency): Pricedetail public function setCurrency(?Currency $currency): self
{ {
$this->currency = $currency; $this->currency = $currency;
return $this; return $this;
} }
@ -259,7 +265,7 @@ class Pricedetail extends DBElement
* *
* @return self * @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!'); //Assert::natural($new_price, 'The new price must be positive! Got %s!');
@ -322,6 +328,6 @@ class Pricedetail extends DBElement
*/ */
public function getIDString(): string public function getIDString(): string
{ {
return 'PD' . sprintf('%06d', $this->getID()); return 'PD'.sprintf('%06d', $this->getID());
} }
} }

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\UserSystem; namespace App\Entity\UserSystem;
use App\Entity\Attachments\GroupAttachment; use App\Entity\Attachments\GroupAttachment;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Base\StructuralDBElement; use App\Entity\Base\StructuralDBElement;
use App\Security\Interfaces\HasPermissionsInterface; use App\Security\Interfaces\HasPermissionsInterface;
use App\Validator\Constraints\ValidPermission; use App\Validator\Constraints\ValidPermission;
@ -38,7 +36,6 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
class Group extends StructuralDBElement implements HasPermissionsInterface class Group extends StructuralDBElement implements HasPermissionsInterface
{ {
/** /**
* @var Collection|GroupAttachment[] * @var Collection|GroupAttachment[]
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\ManufacturerAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true) * @ORM\OneToMany(targetEntity="App\Entity\Attachments\ManufacturerAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Entity\UserSystem; namespace App\Entity\UserSystem;
@ -293,10 +292,12 @@ class PermissionsEmbed
/** /**
* Checks whether a permission with the given name is valid for this object. * 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); return isset($this->$permission_name);
} }
@ -304,8 +305,8 @@ class PermissionsEmbed
/** /**
* Returns the bit pair value of the given permission. * 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 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 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. * @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. * 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 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 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 * @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. * and null if it should inherit from parent.
@ -345,19 +346,21 @@ class PermissionsEmbed
/** /**
* Sets the value of the given permission and operation. * 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 string $permission_name the name of the permission, for which the bit pair should be written
* @param bool|null $new_value The new value for the operation: * @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 * True, if the given operation is allowed, false if disallowed
* and null if it should inherit from parent. * and null if it should inherit from parent
* @return PermissionsEmbed The instance itself. *
* @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. //Determine which bit value the given value is.
if ($new_value === true) { if (true === $new_value) {
$bit_value = static::ALLOW; $bit_value = static::ALLOW;
} elseif ($new_value === false) { } elseif (false === $new_value) {
$bit_value = static::DISALLOW; $bit_value = static::DISALLOW;
} else { } else {
$bit_value = static::INHERIT; $bit_value = static::INHERIT;
@ -370,12 +373,14 @@ class PermissionsEmbed
/** /**
* Sets the bit value of the given permission and operation. * 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 string $permission_name the name of the permission, for which the bit pair should be written
* @param int $new_value The new (bit) value of the bit pair, which should be written. * @param int $bit_n the (lower) bit number of the bit pair, which should be written
* @return PermissionsEmbed The instance itself. * @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)) { if (!$this->isValidPermissionName($permission_name)) {
throw new \InvalidArgumentException('No permission with the given name is existing!'); 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. * @param string $permission_name The name of the permission, which should be retrieved.
* If this is not existing an exception is thrown. * If this is not existing an exception is thrown.
* @return int The raw permission value. *
* @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)) { if (!$this->isValidPermissionName($permission_name)) {
throw new \InvalidArgumentException('No permission with the given name is existing!'); throw new \InvalidArgumentException('No permission with the given name is existing!');
@ -403,30 +410,33 @@ class PermissionsEmbed
/** /**
* Sets the given permission to the value. * Sets the given permission to the value.
* @param string $permission_name The name of the permission to that should be set. *
* @param string $permission_name the name of the permission to that should be set
* @param int $value The new value of the permsission * @param int $value The new value of the permsission
*
* @return $this * @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)) { if (!$this->isValidPermissionName($permission_name)) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(sprintf('No permission with the given name %s is existing!', $permission_name));
sprintf('No permission with the given name %s is existing!', $permission_name)
);
} }
$this->$permission_name = $value; $this->$permission_name = $value;
return $this; return $this;
} }
/** /**
* Sets multiple permissions at once. * Sets multiple permissions at once.
*
* @param array $values An array in the form ['perm_name' => $value], containing the new data * @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, * @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. * and this array as an array of new values
*
* @return $this * @return $this
*/ */
public function setRawPermissionValues(array $values, array $values2 = null) : self public function setRawPermissionValues(array $values, array $values2 = null): self
{ {
if (!empty($values2)) { if (!empty($values2)) {
$values = array_combine($values, $values2); $values = array_combine($values, $values2);
@ -435,16 +445,17 @@ class PermissionsEmbed
foreach ($values as $key => $value) { foreach ($values as $key => $value) {
$this->setRawPermissionValue($key, $value); $this->setRawPermissionValue($key, $value);
} }
return $this; return $this;
} }
/** /**
* Reads a bit pair from $data. * 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. * @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 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. * Writes a bit pair in the given $data and returns it.
* *
* @param $data int The data which should be modified. * @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 $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 $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 final protected static function writeBitPair(int $data, int $n, int $new): int
{ {

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
declare(strict_types=1); declare(strict_types=1);
@ -53,7 +52,6 @@ declare(strict_types=1);
namespace App\Entity\UserSystem; namespace App\Entity\UserSystem;
use App\Entity\Attachments\AttachmentContainingDBElement; use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Attachments\UserAttachment; use App\Entity\Attachments\UserAttachment;
use App\Entity\Base\NamedDBElement; use App\Entity\Base\NamedDBElement;
use App\Entity\PriceInformations\Currency; 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', public const AVAILABLE_THEMES = ['bootstrap', 'cerulean', 'cosmo', 'cyborg', 'darkly', 'flatly', 'journal',
'litera', 'lumen', 'lux', 'materia', 'minty', 'pulse', 'sandstone', 'simplex', 'sketchy', 'slate', 'solar', 'litera', 'lumen', 'lux', 'materia', 'minty', 'pulse', 'sandstone', 'simplex', 'sketchy', 'slate', 'solar',
'spacelab', 'united', 'yeti']; 'spacelab', 'united', 'yeti', ];
/** /**
* @var Collection|UserAttachment[] * @var Collection|UserAttachment[]
@ -225,7 +223,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*/ */
protected $disabled = false; protected $disabled = false;
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
@ -284,8 +281,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/** /**
* Sets the password hash for this user. * Sets the password hash for this user.
* *
* @param string $password
*
* @return User * @return User
*/ */
public function setPassword(string $password): self 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. * 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. * @return Currency|null The currency the user prefers, or null if the global currency should be used.
*/ */
public function getCurrency(): ?Currency 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. * Sets the currency the users prefers to see prices in.
* @param Currency|null $currency *
* @return User * @return User
*/ */
public function setCurrency(?Currency $currency): User public function setCurrency(?Currency $currency): self
{ {
$this->currency = $currency; $this->currency = $currency;
return $this; return $this;
} }
/** /**
* Checks if this user is disabled (user cannot login any more). * Checks if this user is disabled (user cannot login any more).
*
* @return bool True, if the user is disabled. * @return bool True, if the user is disabled.
*/ */
public function isDisabled(): bool public function isDisabled(): bool
@ -343,17 +341,18 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/** /**
* Sets the status if a user is disabled. * Sets the status if a user is disabled.
*
* @param bool $disabled True if the user should be disabled. * @param bool $disabled True if the user should be disabled.
*
* @return User * @return User
*/ */
public function setDisabled(bool $disabled): User public function setDisabled(bool $disabled): self
{ {
$this->disabled = $disabled; $this->disabled = $disabled;
return $this; return $this;
} }
/** /**
* Returns the ID as an string, defined by the element class. * Returns the ID as an string, defined by the element class.
* This should have a form like P000014, for a part with ID 14. * 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 * @return bool
*/ */
public function isNeedPwChange(): 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. * Set the status, if the user needs a password change.
* @param bool $need_pw_change *
* @return User * @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; $this->need_pw_change = $need_pw_change;
return $this; return $this;
} }
@ -394,8 +395,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
* Getters * Getters
************************************************/ ************************************************/
/** /**
* Returns the full name in the format FIRSTNAME LASTNAME [(USERNAME)]. * Returns the full name in the format FIRSTNAME LASTNAME [(USERNAME)].
* Example: Max Muster (m.muster). * Example: Max Muster (m.muster).
@ -436,7 +435,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
* *
* @return User * @return User
*/ */
public function setFirstName(?string $first_name): User public function setFirstName(?string $first_name): self
{ {
$this->first_name = $first_name; $this->first_name = $first_name;
@ -456,7 +455,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
* *
* @return User * @return User
*/ */
public function setLastName(?string $last_name): User public function setLastName(?string $last_name): self
{ {
$this->last_name = $last_name; $this->last_name = $last_name;
@ -476,7 +475,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
* *
* @return User * @return User
*/ */
public function setDepartment(?string $department): User public function setDepartment(?string $department): self
{ {
$this->department = $department; $this->department = $department;
@ -496,7 +495,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
* *
* @return User * @return User
*/ */
public function setEmail(?string $email): User public function setEmail(?string $email): self
{ {
$this->email = $email; $this->email = $email;
@ -516,7 +515,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
* *
* @return User * @return User
*/ */
public function setLanguage(?string $language): User public function setLanguage(?string $language): self
{ {
$this->language = $language; $this->language = $language;
@ -536,7 +535,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
* *
* @return User * @return User
*/ */
public function setTimezone(?string $timezone): User public function setTimezone(?string $timezone): self
{ {
$this->timezone = $timezone; $this->timezone = $timezone;
@ -556,7 +555,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
* *
* @return User * @return User
*/ */
public function setTheme(?string $theme): User public function setTheme(?string $theme): self
{ {
$this->theme = $theme; $this->theme = $theme;
@ -578,6 +577,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
public function __toString() public function __toString()
{ {
$tmp = $this->isDisabled() ? ' [DISABLED]' : ''; $tmp = $this->isDisabled() ? ' [DISABLED]' : '';
return $this->getFullName(true) . $tmp;
return $this->getFullName(true).$tmp;
} }
} }

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\EntityListeners; namespace App\EntityListeners;
use App\Entity\Attachments\Attachment; use App\Entity\Attachments\Attachment;
use App\Services\Attachments\AttachmentManager; use App\Services\Attachments\AttachmentManager;
use App\Services\Attachments\AttachmentReverseSearch;
use App\Services\Attachments\AttachmentPathResolver; use App\Services\Attachments\AttachmentPathResolver;
use App\Services\Attachments\AttachmentReverseSearch;
use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs; use Doctrine\ORM\Event\PreUpdateEventArgs;
use Doctrine\ORM\Mapping\PostRemove; 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 * 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. * used any more. This can happens after an attachment is delteted or the path is changed.
* @package App\EntityListeners
*/ */
class AttachmentDeleteListener class AttachmentDeleteListener
{ {
@ -52,8 +49,6 @@ class AttachmentDeleteListener
/** /**
* Removes the file associated with the attachment, if the file associated with the attachment changes. * Removes the file associated with the attachment, if the file associated with the attachment changes.
* @param Attachment $attachment
* @param PreUpdateEventArgs $event
* *
* @PreUpdate * @PreUpdate
*/ */
@ -73,9 +68,6 @@ class AttachmentDeleteListener
/** /**
* Removes the file associated with the attachment, after the attachment was deleted. * Removes the file associated with the attachment, after the attachment was deleted.
* *
* @param Attachment $attachment
* @param LifecycleEventArgs $event
*
* @PostRemove * @PostRemove
*/ */
public function postRemoveHandler(Attachment $attachment, LifecycleEventArgs $event) public function postRemoveHandler(Attachment $attachment, LifecycleEventArgs $event)
@ -87,9 +79,8 @@ class AttachmentDeleteListener
$file = $this->attachmentHelper->attachmentToFile($attachment); $file = $this->attachmentHelper->attachmentToFile($attachment);
//Only delete if the attachment has a valid file. //Only delete if the attachment has a valid file.
if ($file !== null) { if (null !== $file) {
$this->attachmentReverseSearch->deleteIfNotUsed($file); $this->attachmentReverseSearch->deleteIfNotUsed($file);
} }
} }
} }

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\EntityListeners; namespace App\EntityListeners;
use App\Entity\Base\DBElement; use App\Entity\Base\DBElement;
use App\Entity\Base\StructuralDBElement; use App\Entity\Base\StructuralDBElement;
use App\Entity\UserSystem\Group; use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User; use App\Entity\UserSystem\User;
use App\Services\UserCacheKeyGenerator; use App\Services\UserCacheKeyGenerator;
use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PostFlushEventArgs;
use Doctrine\ORM\Event\PreFlushEventArgs;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Contracts\Cache\TagAwareCacheInterface; use Symfony\Contracts\Cache\TagAwareCacheInterface;
@ -49,15 +45,12 @@ class TreeCacheInvalidationListener
* @ORM\PostUpdate() * @ORM\PostUpdate()
* @ORM\PostPersist() * @ORM\PostPersist()
* @ORM\PostRemove() * @ORM\PostRemove()
*
* @param DBElement $element
* @param LifecycleEventArgs $event
*/ */
public function invalidate(DBElement $element, LifecycleEventArgs $event) public function invalidate(DBElement $element, LifecycleEventArgs $event)
{ {
//If an element was changed, then invalidate all cached trees with this element class //If an element was changed, then invalidate all cached trees with this element class
if ($element instanceof StructuralDBElement) { 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]); $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, /* 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 */ so a change in any group can cause big permisssion changes for users. So to be sure, invalidate all trees */
if($element instanceof Group) { if ($element instanceof Group) {
$tag = "groups"; $tag = 'groups';
$this->cache->invalidateTags([$tag]); $this->cache->invalidateTags([$tag]);
} }
} }
} }

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\EventSubscriber; namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; 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. * This event listener shows an login successful flash to the user after login.
* @package App\EventSubscriber
*/ */
class LoginSuccessListener implements EventSubscriberInterface class LoginSuccessListener implements EventSubscriberInterface
{ {
protected $translator; protected $translator;
protected $flashBag; protected $flashBag;

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\EventSubscriber; namespace App\EventSubscriber;
use App\Entity\UserSystem\User; use App\Entity\UserSystem\User;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse; 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\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Http\SecurityEvents;
use Symfony\Contracts\Translation\TranslatorInterface;
class LogoutOnDisabledUserListener implements EventSubscriberInterface class LogoutOnDisabledUserListener implements EventSubscriberInterface
{ {
protected $security; protected $security;
protected $translator; protected $translator;
protected $flashBag; protected $flashBag;

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\EventSubscriber; namespace App\EventSubscriber;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\Tests\Debug\EventSubscriber;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
class SymfonyDebugToolbarSubscriber implements EventSubscriberInterface class SymfonyDebugToolbarSubscriber implements EventSubscriberInterface
{ {
protected $kernel; protected $kernel;
public function __construct(ContainerInterface $kernel) public function __construct(ContainerInterface $kernel)
@ -60,7 +57,6 @@ class SymfonyDebugToolbarSubscriber implements EventSubscriberInterface
return ['kernel.response' => 'onKernelResponse']; return ['kernel.response' => 'onKernelResponse'];
} }
public function onKernelResponse(FilterResponseEvent $event) public function onKernelResponse(FilterResponseEvent $event)
{ {
if (!$this->kernel->getParameter('kernel.debug')) { if (!$this->kernel->getParameter('kernel.debug')) {
@ -70,5 +66,4 @@ class SymfonyDebugToolbarSubscriber implements EventSubscriberInterface
$response = $event->getResponse(); $response = $event->getResponse();
$response->headers->set('Symfony-Debug-Toolbar-Replace', 1); $response->headers->set('Symfony-Debug-Toolbar-Replace', 1);
} }
} }

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\EventSubscriber; namespace App\EventSubscriber;
use App\Entity\UserSystem\User; use App\Entity\UserSystem\User;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent; 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. * 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 class TimezoneListener implements EventSubscriberInterface
{ {
protected $default_timezone; protected $default_timezone;
protected $security; protected $security;
@ -56,14 +52,13 @@ class TimezoneListener implements EventSubscriberInterface
} }
//Fill with default value if needed //Fill with default value if needed
if ($timezone === null && !empty($this->default_timezone)) { if (null === $timezone && !empty($this->default_timezone)) {
$timezone = $this->default_timezone; $timezone = $this->default_timezone;
} }
//If timezone was configured anywhere set it, otherwise just use the one from php.ini //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); date_default_timezone_set($timezone);
} }
} }
@ -89,7 +84,7 @@ class TimezoneListener implements EventSubscriberInterface
{ {
//Set the timezone shortly before executing the controller //Set the timezone shortly before executing the controller
return [ return [
KernelEvents::CONTROLLER => 'setTimeZone' KernelEvents::CONTROLLER => 'setTimeZone',
]; ];
} }
} }

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Exceptions; namespace App\Exceptions;
use Throwable;
class AttachmentDownloadException extends \RuntimeException class AttachmentDownloadException extends \RuntimeException
{ {
} }

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Exceptions; namespace App\Exceptions;

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Form\AdminPages; namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement; use App\Entity\Base\NamedDBElement;
use App\Form\AdminPages\BaseEntityAdminForm;
use App\Services\Attachments\FileTypeFilterTools; use App\Services\Attachments\FileTypeFilterTools;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\CallbackTransformer; 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\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
@ -46,14 +42,14 @@ class AttachmentTypeAdminForm extends BaseEntityAdminForm
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) 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, $builder->add('filetype_filter', TextType::class, ['required' => false,
'label' => $this->trans->trans('attachment_type.edit.filetype_filter'), 'label' => $this->trans->trans('attachment_type.edit.filetype_filter'),
'help' => $this->trans->trans('attachment_type.edit.filetype_filter.help'), 'help' => $this->trans->trans('attachment_type.edit.filetype_filter.help'),
'attr' => ['placeholder' => $this->trans->trans('attachment_type.edit.filetype_filter.placeholder')], 'attr' => ['placeholder' => $this->trans->trans('attachment_type.edit.filetype_filter.placeholder')],
'empty_data' => '', '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 //Normalize data before writing it to database
$builder->get('filetype_filter')->addViewTransformer(new CallbackTransformer( $builder->get('filetype_filter')->addViewTransformer(new CallbackTransformer(

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Form\AdminPages; namespace App\Form\AdminPages;
use App\Entity\Attachments\Attachment; use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\FootprintAttachment;
use App\Entity\Attachments\PartAttachment;
use App\Entity\Base\NamedDBElement; use App\Entity\Base\NamedDBElement;
use App\Entity\Base\StructuralDBElement; use App\Entity\Base\StructuralDBElement;
use App\Form\AttachmentFormType; use App\Form\AttachmentFormType;
use App\Form\Type\MasterPictureAttachmentType; use App\Form\Type\MasterPictureAttachmentType;
use App\Form\Type\StructuralEntityType; use App\Form\Type\StructuralEntityType;
use Doctrine\ORM\EntityRepository;
use FOS\CKEditorBundle\Form\Type\CKEditorType; 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\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; 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\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Symfony\Component\Translation\Reader\TranslationReader;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
class BaseEntityAdminForm extends AbstractType class BaseEntityAdminForm extends AbstractType
{ {
protected $security; protected $security;
protected $params; protected $params;
protected $trans; protected $trans;
@ -72,14 +63,14 @@ class BaseEntityAdminForm extends AbstractType
{ {
/** @var StructuralDBElement $entity */ /** @var StructuralDBElement $entity */
$entity = $options['data']; $entity = $options['data'];
$is_new = $entity->getID() === null; $is_new = null === $entity->getID();
$builder $builder
->add('name', TextType::class, ['empty_data' => '', 'label' => $this->trans->trans('name.label'), ->add('name', TextType::class, ['empty_data' => '', 'label' => $this->trans->trans('name.label'),
'attr' => ['placeholder' => $this->trans->trans('part.name.placeholder')], 'attr' => ['placeholder' => $this->trans->trans('part.name.placeholder')],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]) 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ])
->add('parent', StructuralEntityType::class, ['class' => get_class($entity), ->add('parent', StructuralEntityType::class, ['class' => \get_class($entity),
'required' => false, 'label' => $this->trans->trans('parent.label'), 'required' => false, 'label' => $this->trans->trans('parent.label'),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]) 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ])
@ -87,12 +78,12 @@ class BaseEntityAdminForm extends AbstractType
'label' => $this->trans->trans('entity.edit.not_selectable'), 'label' => $this->trans->trans('entity.edit.not_selectable'),
'help' => $this->trans->trans('entity.edit.not_selectable.help'), 'help' => $this->trans->trans('entity.edit.not_selectable.help'),
'label_attr' => ['class' => 'checkbox-custom'], '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' => '', ->add('comment', CKEditorType::class, ['required' => false, 'empty_data' => '',
'label' => $this->trans->trans('comment.label'), 'label' => $this->trans->trans('comment.label'),
'attr' => ['rows' => 4], 'help' => $this->trans->trans('bbcode.hint'), 'attr' => ['rows' => 4], 'help' => $this->trans->trans('bbcode.hint'),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]); 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$this->additionalFormElements($builder, $options, $entity); $this->additionalFormElements($builder, $options, $entity);
@ -106,23 +97,23 @@ class BaseEntityAdminForm extends AbstractType
'entry_options' => [ 'entry_options' => [
'data_class' => $options['attachment_class'], 'data_class' => $options['attachment_class'],
], ],
'by_reference' => false 'by_reference' => false,
]); ]);
$builder->add('master_picture_attachment', MasterPictureAttachmentType::class, [ $builder->add('master_picture_attachment', MasterPictureAttachmentType::class, [
'required' => false, 'required' => false,
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'label' => $this->trans->trans('part.edit.master_attachment'), 'label' => $this->trans->trans('part.edit.master_attachment'),
'entity' => $entity 'entity' => $entity,
]); ]);
//Buttons //Buttons
$builder->add('save', SubmitType::class, [ $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' : ''], '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', ->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) protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Form\AdminPages; namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement; 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\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -33,50 +30,50 @@ class CategoryAdminForm extends BaseEntityAdminForm
{ {
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) 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, $builder->add('disable_footprints', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('category.edit.disable_footprints'), 'label' => $this->trans->trans('category.edit.disable_footprints'),
'help' => $this->trans->trans('category.edit.disable_footprints.help'), 'help' => $this->trans->trans('category.edit.disable_footprints.help'),
'label_attr' => ['class' => 'checkbox-custom'], '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, $builder->add('disable_manufacturers', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('category.edit.disable_manufacturers'), 'label' => $this->trans->trans('category.edit.disable_manufacturers'),
'help' => $this->trans->trans('category.edit.disable_manufacturers.help'), 'help' => $this->trans->trans('category.edit.disable_manufacturers.help'),
'label_attr'=> ['class' => 'checkbox-custom'], '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_autodatasheets', CheckboxType::class, ['required' => false, $builder->add('disable_autodatasheets', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('category.edit.disable_autodatasheets'), 'label' => $this->trans->trans('category.edit.disable_autodatasheets'),
'help' => $this->trans->trans('category.edit.disable_autodatasheets.help'), 'help' => $this->trans->trans('category.edit.disable_autodatasheets.help'),
'label_attr'=> ['class' => 'checkbox-custom'], '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_properties', CheckboxType::class, ['required' => false, $builder->add('disable_properties', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('category.edit.disable_properties'), 'label' => $this->trans->trans('category.edit.disable_properties'),
'help' => $this->trans->trans('category.edit.disable_properties.help'), 'help' => $this->trans->trans('category.edit.disable_properties.help'),
'label_attr'=> ['class' => 'checkbox-custom'], '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('partname_hint', TextType::class, ['required' => false, 'empty_data' => '', $builder->add('partname_hint', TextType::class, ['required' => false, 'empty_data' => '',
'label' => $this->trans->trans('category.edit.partname_hint'), 'label' => $this->trans->trans('category.edit.partname_hint'),
'attr' => ['placeholder' => $this->trans->trans('category.edit.partname_hint.placeholder')], 'attr' => ['placeholder' => $this->trans->trans('category.edit.partname_hint.placeholder')],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]); 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('partname_regex', TextType::class, ['required' => false, 'empty_data' => '', $builder->add('partname_regex', TextType::class, ['required' => false, 'empty_data' => '',
'label' => $this->trans->trans('category.edit.partname_regex'), 'label' => $this->trans->trans('category.edit.partname_regex'),
'attr' => ['placeholder' => 'category.edit.partname_regex.placeholder'], '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' => '', $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')], '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' => '', $builder->add('default_comment', TextType::class, ['required' => false, 'empty_data' => '',
'label' => $this->trans->trans('category.edit.default_comment'), 'label' => $this->trans->trans('category.edit.default_comment'),
'attr' => ['placeholder' => $this->trans->trans('category.edit.default_comment.placeholder')], '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 <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Form\AdminPages; namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement; 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\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TelType; use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType; 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\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -37,13 +32,13 @@ class CompanyForm extends BaseEntityAdminForm
{ {
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity)
{ {
$is_new = $entity->getID() === null; $is_new = null === $entity->getID();
$builder->add('address', TextareaType::class, [ $builder->add('address', TextareaType::class, [
'label' => $this->trans->trans('company.edit.address'), 'label' => $this->trans->trans('company.edit.address'),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => $this->trans->trans('company.edit.address.placeholder')], 'required' => false, 'attr' => ['placeholder' => $this->trans->trans('company.edit.address.placeholder')], 'required' => false,
'empty_data' => '' 'empty_data' => '',
]); ]);
$builder->add('phone_number', TelType::class, [ $builder->add('phone_number', TelType::class, [
@ -51,28 +46,28 @@ class CompanyForm extends BaseEntityAdminForm
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => $this->trans->trans('company.edit.phone_number.placeholder')], 'attr' => ['placeholder' => $this->trans->trans('company.edit.phone_number.placeholder')],
'required' => false, 'required' => false,
'empty_data' => '' 'empty_data' => '',
]); ]);
$builder->add('fax_number', TelType::class, [ $builder->add('fax_number', TelType::class, [
'label' => $this->trans->trans('company.edit.fax_number'), 'label' => $this->trans->trans('company.edit.fax_number'),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.fax_number.placeholder'], 'required' => false, 'attr' => ['placeholder' => 'company.fax_number.placeholder'], 'required' => false,
'empty_data' => '' 'empty_data' => '',
]); ]);
$builder->add('email_address', EmailType::class, [ $builder->add('email_address', EmailType::class, [
'label' => $this->trans->trans('company.edit.email'), 'label' => $this->trans->trans('company.edit.email'),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => $this->trans->trans('company.edit.email.placeholder')], 'required' => false, 'attr' => ['placeholder' => $this->trans->trans('company.edit.email.placeholder')], 'required' => false,
'empty_data' => '' 'empty_data' => '',
]); ]);
$builder->add('website', UrlType::class, [ $builder->add('website', UrlType::class, [
'label' => $this->trans->trans('company.edit.website'), 'label' => $this->trans->trans('company.edit.website'),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => $this->trans->trans('company.edit.website.placeholder')], 'required' => false, 'attr' => ['placeholder' => $this->trans->trans('company.edit.website.placeholder')], 'required' => false,
'empty_data' => '' 'empty_data' => '',
]); ]);
$builder->add('auto_product_url', UrlType::class, [ $builder->add('auto_product_url', UrlType::class, [
@ -81,7 +76,7 @@ class CompanyForm extends BaseEntityAdminForm
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => $this->trans->trans('company.edit.auto_product_url.placeholder')], 'attr' => ['placeholder' => $this->trans->trans('company.edit.auto_product_url.placeholder')],
'required' => false, 'required' => false,
'empty_data' => '' 'empty_data' => '',
]); ]);
} }
} }

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Form\AdminPages; namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement; 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\CurrencyType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType; use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -33,20 +30,20 @@ class CurrencyAdminForm extends BaseEntityAdminForm
{ {
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) 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, [ $builder->add('iso_code', CurrencyType::class, [
'required' => false, 'required' => false,
'label' => $this->trans->trans('currency.edit.iso_code'), 'label' => $this->trans->trans('currency.edit.iso_code'),
'preferred_choices' => ['EUR', 'USD', 'GBP', 'JPY', 'CNY'], 'preferred_choices' => ['EUR', 'USD', 'GBP', 'JPY', 'CNY'],
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], '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, [ $builder->add('exchange_rate', MoneyType::class, [
'required' => false, 'required' => false,
'label' => $this->trans->trans('currency.edit.exchange_rate'), 'label' => $this->trans->trans('currency.edit.exchange_rate'),
'currency' => $this->params->get('default_currency'), 'currency' => $this->params->get('default_currency'),
'scale' => 6, '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 <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Form\AdminPages; namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement; use App\Entity\Base\NamedDBElement;
use App\Form\Type\MasterPictureAttachmentType; use App\Form\Type\MasterPictureAttachmentType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -33,10 +31,10 @@ class FootprintAdminForm extends BaseEntityAdminForm
{ {
$builder->add('footprint_3d', MasterPictureAttachmentType::class, [ $builder->add('footprint_3d', MasterPictureAttachmentType::class, [
'required' => false, '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'), 'label' => $this->trans->trans('footprint.edit.3d_model'),
'filter' => '3d_model', 'filter' => '3d_model',
'entity' => $entity 'entity' => $entity,
]); ]);
} }
} }

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Form\AdminPages; namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement; use App\Entity\Base\NamedDBElement;
use App\Form\Permissions\PermissionsType; use App\Form\Permissions\PermissionsType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -34,7 +32,7 @@ class GroupAdminForm extends BaseEntityAdminForm
$builder->add('permissions', PermissionsType::class, [ $builder->add('permissions', PermissionsType::class, [
'mapped' => false, 'mapped' => false,
'data' => $builder->getData(), 'data' => $builder->getData(),
'disabled' => !$this->security->isGranted('edit_permissions', $entity) 'disabled' => !$this->security->isGranted('edit_permissions', $entity),
]); ]);
} }
} }

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Form\AdminPages; namespace App\Form\AdminPages;
use App\Entity\Base\StructuralDBElement; use App\Entity\Base\StructuralDBElement;
use App\Form\Type\StructuralEntityType; 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\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
@ -39,7 +35,6 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class ImportType extends AbstractType class ImportType extends AbstractType
{ {
protected $security; protected $security;
protected $trans; protected $trans;
@ -51,46 +46,45 @@ class ImportType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$data = $options['data']; $data = $options['data'];
//Disable import if user is not allowed to create elements. //Disable import if user is not allowed to create elements.
$entity = new $data['entity_class'](); $entity = new $data['entity_class']();
$perm_name = "create"; $perm_name = 'create';
$disabled = ! $this->security->isGranted($perm_name, $entity); $disabled = !$this->security->isGranted($perm_name, $entity);
$builder $builder
->add('format', ChoiceType::class, [ ->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'), 'label' => $this->trans->trans('export.format'),
'disabled' => $disabled]) 'disabled' => $disabled, ])
->add('csv_separator', TextType::class, ['data' => ';', ->add('csv_separator', TextType::class, ['data' => ';',
'label' => $this->trans->trans('import.csv_separator'), 'label' => $this->trans->trans('import.csv_separator'),
'disabled' => $disabled]); 'disabled' => $disabled, ]);
if ($entity instanceof StructuralDBElement) { if ($entity instanceof StructuralDBElement) {
$builder->add('parent', StructuralEntityType::class, [ $builder->add('parent', StructuralEntityType::class, [
'class' => $data['entity_class'], 'class' => $data['entity_class'],
'required' => false, 'required' => false,
'label' => $this->trans->trans('parent.label'), 'label' => $this->trans->trans('parent.label'),
'disabled' => $disabled 'disabled' => $disabled,
]); ]);
} }
$builder->add('file', FileType::class, [ $builder->add('file', FileType::class, [
'label' => $this->trans->trans('import.file'), 'label' => $this->trans->trans('import.file'),
'attr' => ['class' => 'file', 'data-show-preview' => 'false', 'data-show-upload' => 'false'], 'attr' => ['class' => 'file', 'data-show-preview' => 'false', 'data-show-upload' => 'false'],
'disabled' => $disabled 'disabled' => $disabled,
]) ])
->add('preserve_children', CheckboxType::class, ['data' => true, 'required' => false, ->add('preserve_children', CheckboxType::class, ['data' => true, 'required' => false,
'label' => $this->trans->trans('import.preserve_children'), '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, ->add('abort_on_validation_error', CheckboxType::class, ['data' => true, 'required' => false,
'label' => $this->trans->trans('import.abort_on_validation'), 'label' => $this->trans->trans('import.abort_on_validation'),
'help' => $this->trans->trans('import.abort_on_validation.help'), 'help' => $this->trans->trans('import.abort_on_validation.help'),
'label_attr' => ['class' => 'checkbox-custom'], 'disabled' => $disabled]) 'label_attr' => ['class' => 'checkbox-custom'], 'disabled' => $disabled, ])
//Buttons //Buttons
->add('import', SubmitType::class, ['label' => 'import.btn', 'disabled' => $disabled]); ->add('import', SubmitType::class, ['label' => 'import.btn', 'disabled' => $disabled]);

View file

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

View file

@ -1,6 +1,6 @@
<?php <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Form\AdminPages; namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement; 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\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -33,23 +30,23 @@ class MeasurementUnitAdminForm extends BaseEntityAdminForm
{ {
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) 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, $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'), 'help' => $this->trans->trans('measurement_unit.edit.is_integer.help'),
'label_attr' => ['class' => 'checkbox-custom'], '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, $builder->add('use_si_prefix', CheckboxType::class, ['required' => false,
'label' => $this->trans->trans('measurement_unit.edit.use_si_prefix'), 'label' => $this->trans->trans('measurement_unit.edit.use_si_prefix'),
'help' => $this->trans->trans('measurement_unit.edit.use_si_prefix.help'), 'help' => $this->trans->trans('measurement_unit.edit.use_si_prefix.help'),
'label_attr' => ['class' => 'checkbox-custom'], '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, $builder->add('unit', TextType::class, ['required' => false,
'label' => $this->trans->trans('measurement_unit.edit.unit_symbol'), 'label' => $this->trans->trans('measurement_unit.edit.unit_symbol'),
'attr' => ['placeholder' => $this->trans->trans('measurement_unit.edit.unit_symbol.placeholder')], '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 <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Form\AdminPages; namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement; use App\Entity\Base\NamedDBElement;
use App\Entity\Parts\MeasurementUnit; use App\Entity\Parts\MeasurementUnit;
use App\Form\AdminPages\BaseEntityAdminForm;
use App\Form\Type\StructuralEntityType; use App\Form\Type\StructuralEntityType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class StorelocationAdminForm extends BaseEntityAdminForm class StorelocationAdminForm extends BaseEntityAdminForm
{ {
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) 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, [ $builder->add('is_full', CheckboxType::class, [
'required' => false, 'required' => false,
'label' => $this->trans->trans('storelocation.edit.is_full.label'), 'label' => $this->trans->trans('storelocation.edit.is_full.label'),
'help' => $this->trans->trans('storelocation.edit.is_full.help'), 'help' => $this->trans->trans('storelocation.edit.is_full.help'),
'label_attr' => ['class' => 'checkbox-custom'], '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, [ $builder->add('limit_to_existing_parts', CheckboxType::class, [
'required' => false, 'required' => false,
'label' => $this->trans->trans('storelocation.limit_to_existing.label'), 'label' => $this->trans->trans('storelocation.limit_to_existing.label'),
'help' => $this->trans->trans('storelocation.limit_to_existing.help'), 'help' => $this->trans->trans('storelocation.limit_to_existing.help'),
'label_attr' => ['class' => 'checkbox-custom'], '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, [ $builder->add('only_single_part', CheckboxType::class, [
'required' => false, 'required' => false,
'label' => $this->trans->trans('storelocation.only_single_part.label'), 'label' => $this->trans->trans('storelocation.only_single_part.label'),
'help' => $this->trans->trans('storelocation.only_single_part.help'), 'help' => $this->trans->trans('storelocation.only_single_part.help'),
'label_attr' => ['class' => 'checkbox-custom'], '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, [ $builder->add('storage_type', StructuralEntityType::class, [
'required' => false, 'required' => false,
'label' => $this->trans->trans('storelocation.storage_type.label'), 'label' => $this->trans->trans('storelocation.storage_type.label'),
'help' => $this->trans->trans('storelocation.storage_type.help'), 'help' => $this->trans->trans('storelocation.storage_type.help'),
'class' => MeasurementUnit::class, 'disable_not_selectable' => true, '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 <?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) * Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
* *
@ -17,32 +17,21 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Form\AdminPages; namespace App\Form\AdminPages;
use App\Entity\Base\NamedDBElement; use App\Entity\Base\NamedDBElement;
use App\Entity\PriceInformations\Currency; use App\Entity\PriceInformations\Currency;
use App\Form\AdminPages\BaseEntityAdminForm;
use App\Form\Type\StructuralEntityType; 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\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; use Symfony\Component\Form\FormBuilderInterface;
class SupplierForm extends CompanyForm class SupplierForm extends CompanyForm
{ {
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) 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);
@ -58,7 +47,7 @@ class SupplierForm extends CompanyForm
'currency' => $this->params->get('default_currency'), 'currency' => $this->params->get('default_currency'),
'scale' => 3, 'scale' => 3,
'label' => $this->trans->trans('supplier.shipping_costs.label'), '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 <?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) * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/ */
namespace App\Form; namespace App\Form;
use App\Entity\Attachments\Attachment; use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentType; use App\Entity\Attachments\AttachmentType;
use App\Entity\Base\StructuralDBElement;
use App\Form\Type\StructuralEntityType; use App\Form\Type\StructuralEntityType;
use App\Services\Attachments\AttachmentManager; use App\Services\Attachments\AttachmentManager;
use App\Validator\Constraints\AllowedFileExtension; 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\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\FileType; use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\TextType; 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\FormBuilderInterface;
use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Validator\Constraints\File; use Symfony\Component\Validator\Constraints\File;
use Symfony\Component\Validator\Constraints\Url; use Symfony\Component\Validator\Constraints\Url;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
@ -64,26 +59,26 @@ class AttachmentFormType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$builder->add('name', TextType::class, [ $builder->add('name', TextType::class, [
'label' => $this->trans->trans('attachment.edit.name') 'label' => $this->trans->trans('attachment.edit.name'),
]) ])
->add('attachment_type', StructuralEntityType::class, [ ->add('attachment_type', StructuralEntityType::class, [
'label' => $this->trans->trans('attachment.edit.attachment_type'), 'label' => $this->trans->trans('attachment.edit.attachment_type'),
'class' => AttachmentType::class, 'class' => AttachmentType::class,
'disable_not_selectable' => true, 'disable_not_selectable' => true,
'attr' => ['class' => 'attachment_type_selector'] 'attr' => ['class' => 'attachment_type_selector'],
]); ]);
$builder->add('showInTable', CheckboxType::class, ['required' => false, $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'], 'attr' => ['class' => 'form-control-sm'],
'label_attr' => ['class' => 'checkbox-custom']]); 'label_attr' => ['class' => 'checkbox-custom'], ]);
$builder->add('secureFile', CheckboxType::class, ['required' => false, $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, 'mapped' => false,
'attr' => ['class' => 'form-control-sm'], 'attr' => ['class' => 'form-control-sm'],
'help' => $this->trans->trans('attachment.edit.secure_file.help'), 'help' => $this->trans->trans('attachment.edit.secure_file.help'),
'label_attr' => ['class' => 'checkbox-custom']]); 'label_attr' => ['class' => 'checkbox-custom'], ]);
$builder->add('url', TextType::class, [ $builder->add('url', TextType::class, [
'label' => $this->trans->trans('attachment.edit.url'), 'label' => $this->trans->trans('attachment.edit.url'),
@ -91,12 +86,12 @@ class AttachmentFormType extends AbstractType
'attr' => [ 'attr' => [
'data-autocomplete' => $this->urlGenerator->generate('typeahead_builtInRessources', ['query' => 'QUERY']), 'data-autocomplete' => $this->urlGenerator->generate('typeahead_builtInRessources', ['query' => 'QUERY']),
//Disable browser autocomplete //Disable browser autocomplete
'autocomplete' => 'off' 'autocomplete' => 'off',
], ],
'help' => $this->trans->trans('attachment.edit.url.help'), 'help' => $this->trans->trans('attachment.edit.url.help'),
'constraints' => [ 'constraints' => [
$options['allow_builtins'] ? new UrlOrBuiltin() : new Url() $options['allow_builtins'] ? new UrlOrBuiltin() : new Url(),
] ],
]); ]);
$builder->add('downloadURL', CheckboxType::class, ['required' => false, $builder->add('downloadURL', CheckboxType::class, ['required' => false,
@ -104,8 +99,7 @@ class AttachmentFormType extends AbstractType
'mapped' => false, 'mapped' => false,
'disabled' => !$this->allow_attachments_download, 'disabled' => !$this->allow_attachments_download,
'attr' => ['class' => 'form-control-sm'], 'attr' => ['class' => 'form-control-sm'],
'label_attr' => ['class' => 'checkbox-custom']]); 'label_attr' => ['class' => 'checkbox-custom'], ]);
$builder->add('file', FileType::class, [ $builder->add('file', FileType::class, [
'label' => $this->trans->trans('attachment.edit.file'), 'label' => $this->trans->trans('attachment.edit.file'),
@ -115,9 +109,9 @@ class AttachmentFormType extends AbstractType
'constraints' => [ 'constraints' => [
new AllowedFileExtension(), new AllowedFileExtension(),
new File([ new File([
'maxSize' => $options['max_file_size'] 'maxSize' => $options['max_file_size'],
]), ]),
] ],
]); ]);
//Check the secure file checkbox, if file is in securefile location //Check the secure file checkbox, if file is in securefile location
@ -137,8 +131,7 @@ class AttachmentFormType extends AbstractType
$resolver->setDefaults([ $resolver->setDefaults([
'data_class' => Attachment::class, 'data_class' => Attachment::class,
'max_file_size' => '16M', '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