Used PHP_CS_Fixer with symfony preset on codebase.

This commit is contained in:
Jan Böhmer 2019-03-20 23:16:07 +01:00
parent 0f3ba9b6a8
commit e2f7aafa2d
43 changed files with 971 additions and 1068 deletions

View file

@ -7,7 +7,6 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument; 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\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
@ -24,11 +23,9 @@ class SetPasswordCommand extends Command
$this->entityManager = $entityManager; $this->entityManager = $entityManager;
$this->encoder = $passwordEncoder; $this->encoder = $passwordEncoder;
parent::__construct(); parent::__construct();
} }
protected function configure() protected function configure()
{ {
$this $this
@ -44,15 +41,14 @@ class SetPasswordCommand extends Command
$user_name = $input->getArgument('user'); $user_name = $input->getArgument('user');
/** /**
* @var User $user * @var User
*/ */
$users = $this->entityManager->getRepository(User::class)->findBy(['name' => $user_name]); $users = $this->entityManager->getRepository(User::class)->findBy(['name' => $user_name]);
$user = $users[0]; $user = $users[0];
if (null == $user) {
if($user == null)
{
$io->error(sprintf('No user with the given username %s found in the database!', $user_name)); $io->error(sprintf('No user with the given username %s found in the database!', $user_name));
return; return;
} }
@ -62,16 +58,15 @@ class SetPasswordCommand extends Command
sprintf('You are going to change the password of %s with ID %d. Proceed?', sprintf('You are going to change the password of %s with ID %d. Proceed?',
$user->getFullName(true), $user->getID())); $user->getFullName(true), $user->getID()));
if(!$proceed) if (!$proceed) {
{
return; return;
} }
$success = false; $success = false;
$new_password = ""; $new_password = '';
while (!$success) { while (!$success) {
$pw1 = $io->askHidden("Please enter new password:"); $pw1 = $io->askHidden('Please enter new password:');
$pw2 = $io->askHidden('Please confirm:'); $pw2 = $io->askHidden('Please confirm:');
if ($pw1 !== $pw2) { if ($pw1 !== $pw2) {
$io->error('The entered password did not match! Please try again.'); $io->error('The entered password did not match! Please try again.');

View file

@ -1,9 +1,8 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,18 +25,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\Configuration; namespace App\Configuration;
use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\Definition\ConfigurationInterface;
class PermissionsConfiguration implements ConfigurationInterface class PermissionsConfiguration implements ConfigurationInterface
{ {
/** /**
* Generates the configuration tree builder. * Generates the configuration tree builder.
* *

View file

@ -1,9 +1,8 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,7 +25,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 +33,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
/** /**
* Class DebugController * Class DebugController.
* @package App\Controller
*/ */
class DebugController extends AbstractController class DebugController extends AbstractController
{ {

View file

@ -1,11 +1,9 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -28,12 +26,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 Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
@ -46,7 +42,7 @@ class HomepageController extends AbstractController
{ {
return $this->render('homepage.html.twig', return $this->render('homepage.html.twig',
[ [
'banner' => $this->getParameter('banner') 'banner' => $this->getParameter('banner'),
]); ]);
} }
} }

View file

@ -1,10 +1,9 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -27,12 +26,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\Entity\Category; use App\Entity\Category;
use App\Entity\Part; use App\Entity\Part;
use App\Form\PartType; use App\Form\PartType;
@ -45,7 +42,6 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class PartController extends AbstractController class PartController extends AbstractController
{ {
/** /**
* @Route("/part/{id}/info", name="part_info") * @Route("/part/{id}/info", name="part_info")
* @Route("/part/{id}", requirements={"id"="\d+"}) * @Route("/part/{id}", requirements={"id"="\d+"})
@ -59,7 +55,7 @@ class PartController extends AbstractController
return $this->render('Parts/show_part_info.html.twig', return $this->render('Parts/show_part_info.html.twig',
[ [
'part' => $part, 'part' => $part,
'main_image' => $attachmentFilenameService->attachmentPathToAbsolutePath($filename) 'main_image' => $attachmentFilenameService->attachmentPathToAbsolutePath($filename),
] ]
); );
} }
@ -68,6 +64,7 @@ class PartController extends AbstractController
* @Route("/part/{id}/edit", name="part_edit") * @Route("/part/{id}/edit", name="part_edit")
* *
* @param Part $part * @param Part $part
*
* @return \Symfony\Component\HttpFoundation\Response * @return \Symfony\Component\HttpFoundation\Response
*/ */
public function edit(Part $part, Request $request, EntityManagerInterface $em) public function edit(Part $part, Request $request, EntityManagerInterface $em)
@ -114,24 +111,22 @@ class PartController extends AbstractController
$em->persist($new_part); $em->persist($new_part);
$em->flush(); $em->flush();
$this->addFlash('success', $translator->trans('part.created_flash')); $this->addFlash('success', $translator->trans('part.created_flash'));
return $this->redirectToRoute('part_edit', ['id' => $new_part->getID()]); return $this->redirectToRoute('part_edit', ['id' => $new_part->getID()]);
} }
return $this->render('Parts/new_part.html.twig', return $this->render('Parts/new_part.html.twig',
[ [
'part' => $new_part, 'part' => $new_part,
'form' => $form->createView() 'form' => $form->createView(),
]); ]);
} }
/** /**
* @Route("/part/{id}/clone", name="part_clone") * @Route("/part/{id}/clone", name="part_clone")
*
*/ */
public function clone(Part $part, Request $request, EntityManagerInterface $em, TranslatorInterface $translator) public function clone(Part $part, Request $request, EntityManagerInterface $em, TranslatorInterface $translator)
{ {
/** @var Part $new_part */ /** @var Part $new_part */
$new_part = clone $part; $new_part = clone $part;
@ -145,15 +140,14 @@ class PartController extends AbstractController
$em->persist($new_part); $em->persist($new_part);
$em->flush(); $em->flush();
$this->addFlash('success', $translator->trans('part.created_flash')); $this->addFlash('success', $translator->trans('part.created_flash'));
return $this->redirectToRoute('part_edit', ['id' => $new_part->getID()]); return $this->redirectToRoute('part_edit', ['id' => $new_part->getID()]);
} }
return $this->render('Parts/new_part.html.twig', return $this->render('Parts/new_part.html.twig',
[ [
'part' => $new_part, 'part' => $new_part,
'form' => $form->createView() 'form' => $form->createView(),
]); ]);
} }
} }

View file

@ -1,9 +1,8 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,12 +25,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\DataTables\PartsDataTable; use App\DataTables\PartsDataTable;
use Omines\DataTablesBundle\DataTableFactory; use Omines\DataTablesBundle\DataTableFactory;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -42,11 +39,13 @@ class PartListsController extends AbstractController
{ {
/** /**
* @Route("/category/{id}/parts") * @Route("/category/{id}/parts")
*
* @param $id int The id of the category * @param $id int The id of the category
*
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
*/ */
public function showCategory(int $id, Request $request, DataTableFactory $dataTable) public function showCategory(int $id, Request $request, DataTableFactory $dataTable)
{ {
/*$table = $dataTable->create() /*$table = $dataTable->create()
->add("id", TextColumn::class) ->add("id", TextColumn::class)
->add("name", TextColumn::class) ->add("name", TextColumn::class)
@ -60,7 +59,6 @@ class PartListsController extends AbstractController
$table = $dataTable->createFromType(PartsDataTable::class, ['cid' => $id]) $table = $dataTable->createFromType(PartsDataTable::class, ['cid' => $id])
->handleRequest($request); ->handleRequest($request);
if ($table->isCallback()) { if ($table->isCallback()) {
return $table->getResponse(); return $table->getResponse();
} }
@ -73,6 +71,7 @@ class PartListsController extends AbstractController
* *
* @param Request $request * @param Request $request
* @param DataTableFactory $dataTable * @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)
@ -80,13 +79,10 @@ class PartListsController extends AbstractController
$table = $dataTable->createFromType(PartsDataTable::class) $table = $dataTable->createFromType(PartsDataTable::class)
->handleRequest($request); ->handleRequest($request);
if ($table->isCallback()) { if ($table->isCallback()) {
return $table->getResponse(); return $table->getResponse();
} }
return $this->render('parts_list.html.twig', ['datatable' => $table]); return $this->render('parts_list.html.twig', ['datatable' => $table]);
} }
} }

View file

@ -1,9 +1,8 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,12 +25,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 Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
@ -62,5 +59,4 @@ class SecurityController extends AbstractController
{ {
throw new \Exception('Will be intercepted before getting here'); throw new \Exception('Will be intercepted before getting here');
} }
} }

View file

@ -1,9 +1,8 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,12 +25,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\Entity\User; use App\Entity\User;
use App\Form\UserSettingsType; use App\Form\UserSettingsType;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
@ -48,7 +45,6 @@ use Symfony\Component\Validator\Constraints\Length;
class UserController extends AbstractController class UserController extends AbstractController
{ {
/** /**
* @Route("/user/info", name="user_info_self") * @Route("/user/info", name="user_info_self")
* @Route("/user/{id}/info") * @Route("/user/{id}/info")
@ -56,7 +52,7 @@ class UserController extends AbstractController
public function userInfo(?User $user, Packages $packages) public function userInfo(?User $user, Packages $packages)
{ {
//If no user id was passed, then we show info about the current user //If no user id was passed, then we show info about the current user
if($user === null) { if (null === $user) {
$user = $this->getUser(); $user = $this->getUser();
} else { } else {
//Else we must check, if the current user is allowed to access $user //Else we must check, if the current user is allowed to access $user
@ -69,10 +65,9 @@ class UserController extends AbstractController
$avatar = $packages->getUrl('/img/default_avatar.png'); $avatar = $packages->getUrl('/img/default_avatar.png');
} }
return $this->render('Users/user_info.html.twig', [ return $this->render('Users/user_info.html.twig', [
'user' => $user, 'user' => $user,
'avatar' => $avatar 'avatar' => $avatar,
]); ]);
} }
@ -110,7 +105,7 @@ class UserController extends AbstractController
$pw_form = $this->createFormBuilder() $pw_form = $this->createFormBuilder()
->add('old_password', PasswordType::class, [ ->add('old_password', PasswordType::class, [
'label' => 'user.settings.pw_old.label', 'label' => 'user.settings.pw_old.label',
'constraints'=> [new UserPassword()]]) //This constraint checks, if the current user pw was inputted. 'constraints' => [new UserPassword()], ]) //This constraint checks, if the current user pw was inputted.
->add('new_password', RepeatedType::class, [ ->add('new_password', RepeatedType::class, [
'type' => PasswordType::class, 'type' => PasswordType::class,
'first_options' => ['label' => 'user.settings.pw_new.label'], 'first_options' => ['label' => 'user.settings.pw_new.label'],
@ -118,8 +113,8 @@ class UserController extends AbstractController
'invalid_message' => 'password_must_match', 'invalid_message' => 'password_must_match',
'constraints' => [new Length([ 'constraints' => [new Length([
'min' => 6, 'min' => 6,
'max' => 128 'max' => 128,
])] ])],
]) ])
->add('submit', SubmitType::class, ['label' => 'save']) ->add('submit', SubmitType::class, ['label' => 'save'])
->getForm(); ->getForm();
@ -141,11 +136,10 @@ class UserController extends AbstractController
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(),
]); ]);
} }
/** /**
* Get either a Gravatar URL or complete image tag for a specified email address. * Get either a Gravatar URL or complete image tag for a specified email address.
* *
@ -155,7 +149,8 @@ class UserController extends AbstractController
* @param string $r Maximum rating (inclusive) [ g | pg | r | x ] * @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
* @param bool $img True to return a complete IMG tag False for just the URL * @param bool $img True to return a complete IMG tag False for just the URL
* @param array $atts Optional, additional key/value attributes to include in the IMG tag * @param array $atts Optional, additional key/value attributes to include in the IMG tag
* @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 = array())
@ -170,7 +165,7 @@ class UserController extends AbstractController
} }
$url .= ' />'; $url .= ' />';
} }
return $url; return $url;
} }
} }

View file

@ -1,9 +1,8 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,12 +25,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; namespace App\DataTables;
use App\Entity\Part; use App\Entity\Part;
use App\Services\EntityURLGenerator; use App\Services\EntityURLGenerator;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
@ -40,11 +37,9 @@ use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter;
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 Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class PartsDataTable implements DataTableTypeInterface class PartsDataTable implements DataTableTypeInterface
{ {
/** /**
* @var EntityURLGenerator * @var EntityURLGenerator
*/ */
@ -62,15 +57,15 @@ class PartsDataTable implements DataTableTypeInterface
public function configure(DataTable $dataTable, array $options) public function configure(DataTable $dataTable, array $options)
{ {
$dataTable//->add("id", TextColumn::class) $dataTable//->add("id", TextColumn::class)
->add("name", TextColumn::class, ['label' => 'name.label', ->add('name', TextColumn::class, ['label' => 'name.label',
'render' => function ($value, Part $context) { 'render' => function ($value, Part $context) {
return $this->urlGenerator->infoHTML($context); return $this->urlGenerator->infoHTML($context);
}]) }, ])
->add("description", TextColumn::class, ['label' => 'description.label']) ->add('description', TextColumn::class, ['label' => 'description.label'])
->add("category", TextColumn::class, ['field' => 'category.name', 'label' => 'category.label']) ->add('category', TextColumn::class, ['field' => 'category.name', 'label' => 'category.label'])
->add("instock", TextColumn::class, ['label' => 'instock.label_short']) ->add('instock', TextColumn::class, ['label' => 'instock.label_short'])
->add("mininstock", TextColumn::class, ['label' => 'mininstock.label_short']) ->add('mininstock', TextColumn::class, ['label' => 'mininstock.label_short'])
->add("storelocation", TextColumn::class, ['field' => 'storelocation.name', 'label' => 'storelocation.label']) ->add('storelocation', TextColumn::class, ['field' => 'storelocation.name', 'label' => 'storelocation.label'])
->addOrderBy('name') ->addOrderBy('name')
->createAdapter(ORMAdapter::class, [ ->createAdapter(ORMAdapter::class, [
'entity' => Part::class, 'entity' => Part::class,
@ -81,8 +76,8 @@ class PartsDataTable implements DataTableTypeInterface
->setParameter('cid', $options['cid']); ->setParameter('cid', $options['cid']);
} }
}, },
new SearchCriteriaProvider() new SearchCriteriaProvider(),
] ],
]); ]);
} }
} }

View file

@ -1,9 +1,10 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
/** /**
*
* Part-DB Version 0.4+ "nextgen" * Part-DB Version 0.4+ "nextgen"
* Copyright (C) 2016 - 2019 Jan Böhmer * Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics * https://github.com/jbtronics.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -18,7 +19,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; namespace App\Entity;
@ -27,8 +27,8 @@ use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Intl\Exception\NotImplementedException; use Symfony\Component\Intl\Exception\NotImplementedException;
/** /**
* Class Attachment * Class Attachment.
* @package PartDB\Models *
* @ORM\Entity * @ORM\Entity
* @ORM\Table(name="attachements") * @ORM\Table(name="attachements")
*/ */
@ -40,8 +40,6 @@ class Attachment extends NamedDBElement
*/ */
protected $show_in_table; protected $show_in_table;
/** /**
* @var string The filename using the %BASE% variable * @var string The filename using the %BASE% variable
* @ORM\Column(type="string") * @ORM\Column(type="string")
@ -51,7 +49,7 @@ class Attachment extends NamedDBElement
/** /**
* //TODO * //TODO
* //@ORM\ManyToOne(targetEntity="AttachmentContainingDBElement", inversedBy="attachment") * //@ORM\ManyToOne(targetEntity="AttachmentContainingDBElement", inversedBy="attachment")
* //@ORM\JoinColumn(name="element_id", referencedColumnName="id") * //@ORM\JoinColumn(name="element_id", referencedColumnName="id").
*/ */
protected $element; protected $element;
@ -67,9 +65,9 @@ class Attachment extends NamedDBElement
***********************************************************/ ***********************************************************/
/** /**
* Check if this attachement is a picture (analyse the file's extension) * Check if this attachement is a picture (analyse the file's extension).
* *
* @return boolean * true if the file extension is a picture extension * @return bool * true if the file extension is a picture extension
* * otherwise false * * otherwise false
*/ */
public function isPicture(): bool public function isPicture(): bool
@ -89,7 +87,8 @@ class Attachment extends NamedDBElement
*********************************************************************************/ *********************************************************************************/
/** /**
* Get the element, associated with this Attachement (for example a "Part" object) * Get the element, associated with this Attachement (for example a "Part" object).
*
* @return DBElement The associated Element. * @return DBElement The associated Element.
*/ */
public function getElement(): AttachmentContainingDBElement public function getElement(): AttachmentContainingDBElement
@ -109,7 +108,7 @@ class Attachment extends NamedDBElement
} }
/** /**
* Get the filename, relative to %BASE% * Get the filename, relative to %BASE%.
* *
* @return string * @return string
*/ */
@ -120,7 +119,7 @@ class Attachment extends NamedDBElement
} }
/** /**
* Get the show_in_table attribute * Get the show_in_table attribute.
* *
* @return bool true means, this attachement will be listed in the "Attachements" column of the HTML tables * @return bool true means, this attachement will be listed in the "Attachements" column of the HTML tables
* false means, this attachement won't be listed in the "Attachements" column of the HTML tables * false means, this attachement won't be listed in the "Attachements" column of the HTML tables
@ -131,20 +130,23 @@ 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
*
* @throws Exception if there was an error * @throws Exception if there was an error
*/ */
public function getType(): AttachmentType public function getType(): AttachmentType
{ {
//TODO //TODO
throw new NotImplementedException("Not implemented yet!"); throw new NotImplementedException('Not implemented yet!');
} }
/** /**
* 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
@ -158,11 +160,13 @@ class Attachment extends NamedDBElement
/** /**
* @param bool $show_in_table * @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
{ {
$this->show_in_table = $show_in_table; $this->show_in_table = $show_in_table;
return $this; return $this;
} }
} }

View file

@ -1,9 +1,10 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
/** /**
*
* Part-DB Version 0.4+ "nextgen" * Part-DB Version 0.4+ "nextgen"
* Copyright (C) 2016 - 2019 Jan Böhmer * Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics * https://github.com/jbtronics.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -18,7 +19,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; namespace App\Entity;
@ -47,7 +47,7 @@ abstract class AttachmentContainingDBElement extends NamedDBElement
*********************************************************************************/ *********************************************************************************/
/** /**
* Get all different attachement types of the attachements of this element * Get all different attachement types of the attachements of this element.
* *
* @return AttachmentType[] the attachement types as a one-dimensional array of AttachementType objects, * @return AttachmentType[] the attachement types as a one-dimensional array of AttachementType objects,
* sorted by their names * sorted by their names
@ -59,13 +59,12 @@ abstract class AttachmentContainingDBElement extends NamedDBElement
return $this->attachmentTypes; return $this->attachmentTypes;
} }
/** /**
* Get all attachements of this element / Get the element's attachements with a specific type * Get all attachements of this element / Get the element's attachements with a specific type.
* *
* @param integer $type_id * if NULL, all attachements of this element will be returned * @param int $type_id * if NULL, all attachements of this element will be returned
* * if this is a number > 0, only attachements with this type ID will be returned * * if this is a number > 0, only attachements with this type ID will be returned
* @param boolean $only_table_attachements if true, only attachements with "show_in_table == true" * @param bool $only_table_attachements if true, only attachements with "show_in_table == true"
* *
* @return Attachment[] the attachements as a one-dimensional array of Attachement objects * @return Attachment[] the attachements as a one-dimensional array of Attachement objects
* *

View file

@ -1,9 +1,10 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
/** /**
*
* Part-DB Version 0.4+ "nextgen" * Part-DB Version 0.4+ "nextgen"
* Copyright (C) 2016 - 2019 Jan Böhmer * Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics * https://github.com/jbtronics.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -18,7 +19,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; namespace App\Entity;
@ -27,8 +27,8 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* Class AttachmentType * Class AttachmentType.
* @package PartDB\Models *
* @ORM\Entity() * @ORM\Entity()
* @ORM\Table(name="attachement_types") * @ORM\Table(name="attachement_types")
*/ */
@ -40,7 +40,6 @@ class AttachmentType extends StructuralDBElement
*/ */
protected $attachments; protected $attachments;
/** /**
* @ORM\OneToMany(targetEntity="AttachmentType", mappedBy="parent") * @ORM\OneToMany(targetEntity="AttachmentType", mappedBy="parent")
*/ */
@ -53,16 +52,15 @@ class AttachmentType extends StructuralDBElement
protected $parent; protected $parent;
/** /**
* Get all attachements ("Attachement" objects) with this type * Get all attachements ("Attachement" objects) with this type.
* *
* @return Attachment[] all attachements with this type, as a one-dimensional array of Attachement-objects * @return Attachment[] all attachements with this type, as a one-dimensional array of Attachement-objects
* (sorted by their names) * (sorted by their names)
*
*/ */
public function getAttachementsForType(): ArrayCollection public function getAttachementsForType(): ArrayCollection
{ {
// the attribute $this->attachements is used from class "AttachementsContainingDBELement" // the attribute $this->attachements is used from class "AttachementsContainingDBELement"
if ($this->attachments === null) { if (null === $this->attachments) {
$this->attachments = new ArrayCollection(); $this->attachments = new ArrayCollection();
} }
@ -72,6 +70,7 @@ class AttachmentType extends StructuralDBElement
/** /**
* 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

View file

@ -1,9 +1,10 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
/** /**
*
* Part-DB Version 0.4+ "nextgen" * Part-DB Version 0.4+ "nextgen"
* Copyright (C) 2016 - 2019 Jan Böhmer * Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics * https://github.com/jbtronics.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -18,7 +19,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; namespace App\Entity;
@ -26,13 +26,13 @@ namespace App\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* Class AttachmentType * Class AttachmentType.
*
* @ORM\Entity * @ORM\Entity
* @ORM\Table(name="categories") * @ORM\Table(name="categories")
*/ */
class Category extends PartsContainingDBElement class Category extends PartsContainingDBElement
{ {
/** /**
* @ORM\OneToMany(targetEntity="Category", mappedBy="parent") * @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
*/ */
@ -97,10 +97,10 @@ class Category extends PartsContainingDBElement
*/ */
protected $default_comment; protected $default_comment;
/** /**
* 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

View file

@ -1,9 +1,10 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
/** /**
*
* Part-DB Version 0.4+ "nextgen" * Part-DB Version 0.4+ "nextgen"
* Copyright (C) 2016 - 2019 Jan Böhmer * Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics * https://github.com/jbtronics.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -18,16 +19,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; namespace App\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* This abstract class is used for companies like suppliers or manufacturers. * This abstract class is used for companies like suppliers or manufacturers.
*
* @ORM\MappedSuperclass() * @ORM\MappedSuperclass()
*/ */
abstract class Company extends StructuralDBElement abstract class Company extends StructuralDBElement
@ -68,7 +68,6 @@ abstract class Company extends StructuralDBElement
*/ */
protected $auto_product_url; protected $auto_product_url;
/******************************************************************************** /********************************************************************************
* *
* Getters * Getters
@ -76,7 +75,7 @@ abstract class Company extends StructuralDBElement
*********************************************************************************/ *********************************************************************************/
/** /**
* Get the address * Get the address.
* *
* @return string the address of the company (with "\n" as line break) * @return string the address of the company (with "\n" as line break)
*/ */
@ -86,7 +85,7 @@ abstract class Company extends StructuralDBElement
} }
/** /**
* Get the phone number * Get the phone number.
* *
* @return string the phone number of the company * @return string the phone number of the company
*/ */
@ -96,7 +95,7 @@ abstract class Company extends StructuralDBElement
} }
/** /**
* Get the fax number * Get the fax number.
* *
* @return string the fax number of the company * @return string the fax number of the company
*/ */
@ -106,7 +105,7 @@ abstract class Company extends StructuralDBElement
} }
/** /**
* Get the e-mail address * Get the e-mail address.
* *
* @return string the e-mail address of the company * @return string the e-mail address of the company
*/ */
@ -116,7 +115,7 @@ abstract class Company extends StructuralDBElement
} }
/** /**
* Get the website * Get the website.
* *
* @return string the website of the company * @return string the website of the company
*/ */
@ -126,7 +125,7 @@ abstract class Company extends StructuralDBElement
} }
/** /**
* Get the link to the website of an article * Get the link to the website of an article.
* *
* @param string $partnr * NULL for returning the URL with a placeholder for the part number * @param string $partnr * NULL for returning the URL with a placeholder for the part number
* * or the part number for returning the direct URL to the article * * or the part number for returning the direct URL to the article
@ -138,6 +137,7 @@ abstract class Company extends StructuralDBElement
if (\is_string($partnr)) { if (\is_string($partnr)) {
return str_replace('%PARTNUMBER%', $partnr, $this->auto_product_url); return str_replace('%PARTNUMBER%', $partnr, $this->auto_product_url);
} }
return $this->auto_product_url; return $this->auto_product_url;
} }
@ -148,7 +148,8 @@ abstract class Company extends StructuralDBElement
*********************************************************************************/ *********************************************************************************/
/** /**
* Set the addres * Set the addres.
*
* @param string $new_address the new address (with "\n" as line break) * @param string $new_address the new address (with "\n" as line break)
* *
* @return self * @return self
@ -156,11 +157,12 @@ abstract class Company extends StructuralDBElement
public function setAddress(string $new_address): self public function setAddress(string $new_address): self
{ {
$this->address = $new_address; $this->address = $new_address;
return $this; return $this;
} }
/** /**
* Set the phone number * Set the phone number.
* *
* @param string $new_phone_number the new phone number * @param string $new_phone_number the new phone number
* *
@ -169,11 +171,12 @@ abstract class Company extends StructuralDBElement
public function setPhoneNumber(string $new_phone_number): self public function setPhoneNumber(string $new_phone_number): self
{ {
$this->phone_number = $new_phone_number; $this->phone_number = $new_phone_number;
return $this; return $this;
} }
/** /**
* Set the fax number * Set the fax number.
* *
* @param string $new_fax_number the new fax number * @param string $new_fax_number the new fax number
* *
@ -182,25 +185,26 @@ abstract class Company extends StructuralDBElement
public function setFaxNumber(string $new_fax_number): self public function setFaxNumber(string $new_fax_number): self
{ {
$this->fax_number = $new_fax_number; $this->fax_number = $new_fax_number;
return $this; return $this;
} }
/** /**
* Set the e-mail address * Set the e-mail address.
* *
* @param string $new_email_address the new e-mail address * @param string $new_email_address the new e-mail address
* *
* @return self * @return self
*/ */
public function setEmailAddress(string $new_email_address): self public function setEmailAddress(string $new_email_address): self
{ {
$this->email_address = $new_email_address; $this->email_address = $new_email_address;
return $this; return $this;
} }
/** /**
* Set the website * Set the website.
* *
* @param string $new_website the new website * @param string $new_website the new website
* *
@ -209,11 +213,12 @@ abstract class Company extends StructuralDBElement
public function setWebsite(string $new_website): self public function setWebsite(string $new_website): self
{ {
$this->website = $new_website; $this->website = $new_website;
return $this; return $this;
} }
/** /**
* Set the link to the website of an article * Set the link to the website of an article.
* *
* @param string $new_url the new URL with the placeholder %PARTNUMBER% for the part number * @param string $new_url the new URL with the placeholder %PARTNUMBER% for the part number
* *
@ -222,7 +227,7 @@ abstract class Company extends StructuralDBElement
public function setAutoProductUrl(string $new_url): self public function setAutoProductUrl(string $new_url): self
{ {
$this->auto_product_url = $new_url; $this->auto_product_url = $new_url;
return $this; return $this;
} }
} }

View file

@ -1,9 +1,10 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
/** /**
*
* Part-DB Version 0.4+ "nextgen" * Part-DB Version 0.4+ "nextgen"
* Copyright (C) 2016 - 2019 Jan Böhmer * Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics * https://github.com/jbtronics.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -18,7 +19,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; namespace App\Entity;
@ -39,7 +39,6 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
abstract class DBElement abstract class DBElement
{ {
/** @var int The Identification number for this part. This value is unique for the element in this table. /** @var int The Identification number for this part. This value is unique for the element in this table.
* @ORM\Column(type="integer") * @ORM\Column(type="integer")
* @ORM\Id() * @ORM\Id()
@ -49,19 +48,19 @@ abstract class DBElement
/** /**
* Get the ID. The ID can be zero, or even negative (for virtual elements). If an elemenent is virtual, can be * Get the ID. The ID can be zero, or even negative (for virtual elements). If an elemenent is virtual, can be
* checked with isVirtualElement() * checked with isVirtualElement().
* *
* @return integer the ID of this element * @return int the ID of this element
*/ */
final public function getID(): int final public function getID(): int
{ {
return (int) $this->id; return (int) $this->id;
} }
/** /**
* 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;
*/ */
abstract public function getIDString(): string; abstract public function getIDString(): string;
@ -71,5 +70,4 @@ abstract class DBElement
//Set ID to null, so that an new entry is created //Set ID to null, so that an new entry is created
$this->id = null; $this->id = null;
} }
} }

View file

@ -1,11 +1,11 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -28,7 +28,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; namespace App\Entity;
@ -36,13 +35,13 @@ namespace App\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* Class AttachmentType * Class AttachmentType.
*
* @ORM\Entity() * @ORM\Entity()
* @ORM\Table(name="devices") * @ORM\Table(name="devices")
*/ */
class Device extends PartsContainingDBElement class Device extends PartsContainingDBElement
{ {
/** /**
* @ORM\OneToMany(targetEntity="Category", mappedBy="parent") * @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
*/ */
@ -57,7 +56,6 @@ class Device extends PartsContainingDBElement
/** /**
* @var int * @var int
* @ORM\Column(type="integer") * @ORM\Column(type="integer")
*
*/ */
protected $order_quantity; protected $order_quantity;
@ -79,9 +77,9 @@ class Device extends PartsContainingDBElement
*********************************************************************************/ *********************************************************************************/
/** /**
* Get the order quantity of this device * Get the order quantity of this device.
* *
* @return integer the order quantity * @return int the order quantity
*/ */
public function getOrderQuantity(): int public function getOrderQuantity(): int
{ {
@ -89,9 +87,9 @@ class Device extends PartsContainingDBElement
} }
/** /**
* Get the "order_only_missing_parts" attribute * Get the "order_only_missing_parts" attribute.
* *
* @return boolean the "order_only_missing_parts" attribute * @return bool the "order_only_missing_parts" attribute
*/ */
public function getOrderOnlyMissingParts(): bool public function getOrderOnlyMissingParts(): bool
{ {
@ -105,36 +103,40 @@ class Device extends PartsContainingDBElement
*********************************************************************************/ *********************************************************************************/
/** /**
* Set the order quantity * Set the order quantity.
*
* @param int $new_order_quantity the new order quantity
* *
* @param integer $new_order_quantity the new order quantity
* @return self * @return self
*/ */
public function setOrderQuantity(int $new_order_quantity): self public function setOrderQuantity(int $new_order_quantity): self
{ {
if($new_order_quantity < 0) if ($new_order_quantity < 0) {
{
throw new \InvalidArgumentException('The new order quantity must not be negative!'); throw new \InvalidArgumentException('The new order quantity must not be negative!');
} }
$this->order_quantity = $new_order_quantity; $this->order_quantity = $new_order_quantity;
return $this; return $this;
} }
/** /**
* Set the "order_only_missing_parts" attribute * Set the "order_only_missing_parts" attribute.
* @param boolean $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 * @return self
*/ */
public function setOrderOnlyMissingParts(bool $new_order_only_missing_parts): self public function setOrderOnlyMissingParts(bool $new_order_only_missing_parts): self
{ {
$this->order_only_missing_parts = $new_order_only_missing_parts; $this->order_only_missing_parts = $new_order_only_missing_parts;
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

View file

@ -1,10 +1,11 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -27,17 +28,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; namespace App\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* Class DevicePart * Class DevicePart.
* @package App\Entity
* *
* @ORM\Table("device_parts") * @ORM\Table("device_parts")
* @ORM\Entity() * @ORM\Entity()
@ -57,6 +55,7 @@ class DevicePart extends DBElement
/** /**
* 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

View file

@ -1,10 +1,11 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -27,24 +28,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; namespace App\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* Class Footprint * Class Footprint.
* @package App\Entity
* *
* @ORM\Entity() * @ORM\Entity()
* @ORM\Table("footprints") * @ORM\Table("footprints")
*/ */
class Footprint extends PartsContainingDBElement class Footprint extends PartsContainingDBElement
{ {
/** /**
* @ORM\OneToMany(targetEntity="Footprint", mappedBy="parent") * @ORM\OneToMany(targetEntity="Footprint", mappedBy="parent")
*/ */
@ -76,6 +73,7 @@ class Footprint extends PartsContainingDBElement
/** /**
* 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
@ -88,7 +86,8 @@ class Footprint extends PartsContainingDBElement
****************************************/ ****************************************/
/** /**
* Get the filename of the picture (absolute path from filesystem root) * Get the filename of the picture (absolute path from filesystem root).
*
* @return string the saved filename in the DB * @return string the saved filename in the DB
* * an empty string if there is no picture * * an empty string if there is no picture
*/ */
@ -98,7 +97,7 @@ class Footprint extends PartsContainingDBElement
} }
/** /**
* Get the filename of the 3d model (absolute path from filesystem root) * Get the filename of the 3d model (absolute path from filesystem root).
* *
* @param bool $absolute If set to true, then the absolute filename (from system root) is returned. * @param bool $absolute If set to true, then the absolute filename (from system root) is returned.
* If set to false, then the path relative to Part-DB folder is returned. * If set to false, then the path relative to Part-DB folder is returned.
@ -108,7 +107,7 @@ class Footprint extends PartsContainingDBElement
*/ */
public function get3dFilename(bool $absolute = true): string public function get3dFilename(bool $absolute = true): string
{ {
if ($absolute === true) { if (true === $absolute) {
//TODO //TODO
throw new \Exception('Not Implemented yet...'); throw new \Exception('Not Implemented yet...');
//return str_replace('%BASE%', BASE, $this->db_data['filename_3d']); //return str_replace('%BASE%', BASE, $this->db_data['filename_3d']);
@ -118,14 +117,14 @@ class Footprint extends PartsContainingDBElement
} }
/** /**
* Check if the filename of this footprint is valid (picture exists) * Check if the filename of this footprint is valid (picture exists).
* *
* This method is used to get all footprints with broken filename * This method is used to get all footprints with broken filename
* (Footprint::get_broken_filename_footprints()). * (Footprint::get_broken_filename_footprints()).
* *
* An empty filename is a valid filename. * An empty filename is a valid filename.
* *
* @return boolean * true if file exists or filename is empty * @return bool * true if file exists or filename is empty
* * false if there is no file with this filename * * false if there is no file with this filename
*/ */
public function isFilenameValid(): bool public function isFilenameValid(): bool
@ -138,14 +137,14 @@ class Footprint extends PartsContainingDBElement
} }
/** /**
* Check if the filename of this 3d footprint is valid (model exists and have ) * Check if the filename of this 3d footprint is valid (model exists and have ).
* *
* This method is used to get all footprints with broken 3d filename * This method is used to get all footprints with broken 3d filename
* (Footprint::get_broken_3d_filename_footprints()). * (Footprint::get_broken_3d_filename_footprints()).
* *
* An empty filename is a valid filename. * An empty filename is a valid filename.
* *
* @return boolean * true if file exists or filename is empty * @return bool * true if file exists or filename is empty
* * false if there is no file with this filename * * false if there is no file with this filename
*/ */
public function is3dFilenameValid(): bool public function is3dFilenameValid(): bool
@ -155,7 +154,7 @@ class Footprint extends PartsContainingDBElement
} }
//Check if file is X3D-Model (these has .x3d extension) //Check if file is X3D-Model (these has .x3d extension)
if (strpos($this->get3dFilename(), '.x3d') === false) { if (false === strpos($this->get3dFilename(), '.x3d')) {
return false; return false;
} }
@ -173,7 +172,7 @@ class Footprint extends PartsContainingDBElement
*********************************************************************************/ *********************************************************************************/
/** /**
* Change the filename of this footprint * Change the filename of this footprint.
* *
* The filename won't be checked if it is valid. * The filename won't be checked if it is valid.
* It's not really a Problem if there is no such file... * It's not really a Problem if there is no such file...
@ -190,21 +189,26 @@ class Footprint extends PartsContainingDBElement
* *
* The path-replacing will be done in Footprint::check_values_validity(), not here. * The path-replacing will be done in Footprint::check_values_validity(), not here.
* *
* @return Footprint
*
* @throws Exception if there was an error * @throws Exception if there was an error
*/ */
public function setFilename(string $new_filename): self public function setFilename(string $new_filename): self
{ {
$this->filename = $new_filename; $this->filename = $new_filename;
return $this; return $this;
} }
/** /**
* Change the 3d model filename of this footprint * Change the 3d model filename of this footprint.
*
* @throws Exception if there was an error * @throws Exception if there was an error
*/ */
public function set3dFilename(string $new_filename): self public function set3dFilename(string $new_filename): self
{ {
$this->filename = $new_filename; $this->filename = $new_filename;
return $this; return $this;
} }
} }

View file

@ -1,9 +1,8 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,7 +25,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; namespace App\Entity;
@ -35,15 +33,13 @@ use App\Security\Interfaces\HasPermissionsInterface;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* This entity represents an user group * This entity represents an user group.
* @package App\Entity
* *
* @ORM\Entity() * @ORM\Entity()
* @ORM\Table("groups") * @ORM\Table("groups")
*/ */
class Group extends StructuralDBElement implements HasPermissionsInterface class Group extends StructuralDBElement implements HasPermissionsInterface
{ {
/** /**
* @ORM\OneToMany(targetEntity="Group", mappedBy="parent") * @ORM\OneToMany(targetEntity="Group", mappedBy="parent")
*/ */
@ -65,10 +61,10 @@ class Group extends StructuralDBElement implements HasPermissionsInterface
*/ */
protected $permissions; protected $permissions;
/** /**
* 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

View file

@ -1,10 +1,11 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -27,17 +28,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; namespace App\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* Class Manufacturer * Class Manufacturer.
* @package App\Entity
* *
* @ORM\Entity() * @ORM\Entity()
* @ORM\Table("manufacturers") * @ORM\Table("manufacturers")
@ -63,6 +61,7 @@ class Manufacturer extends Company
/** /**
* 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

View file

@ -1,9 +1,10 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
/** /**
*
* Part-DB Version 0.4+ "nextgen" * Part-DB Version 0.4+ "nextgen"
* Copyright (C) 2016 - 2019 Jan Böhmer * Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics * https://github.com/jbtronics.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -18,13 +19,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; namespace App\Entity;
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;
/** /**
@ -39,7 +38,6 @@ abstract class NamedDBElement extends DBElement
* @var string The name of this element. * @var string The name of this element.
* @ORM\Column(type="string") * @ORM\Column(type="string")
* @Assert\NotBlank() * @Assert\NotBlank()
*
*/ */
protected $name = ''; protected $name = '';
@ -62,7 +60,7 @@ abstract class NamedDBElement extends DBElement
*********************************************************************************/ *********************************************************************************/
/** /**
* Get the name * Get the name.
* *
* @return string the name of this element * @return string the name of this element
*/ */
@ -76,6 +74,7 @@ abstract class NamedDBElement extends DBElement
/** /**
* Returns the last time when the element was modified. * Returns the last time when the element was modified.
*
* @return \DateTime The time of the last edit. * @return \DateTime The time of the last edit.
*/ */
public function getLastModified(): \DateTime public function getLastModified(): \DateTime
@ -85,6 +84,7 @@ abstract class NamedDBElement extends DBElement
/** /**
* Returns the date/time when the element was created. * Returns the date/time when the element was created.
*
* @return \DateTime The creation time of the part. * @return \DateTime The creation time of the part.
*/ */
public function getAddedDate(): \DateTime public function getAddedDate(): \DateTime
@ -99,18 +99,20 @@ abstract class NamedDBElement extends DBElement
*********************************************************************************/ *********************************************************************************/
/** /**
* Change the name of this element * Change the name of this element.
* *
* Spaces at the begin and at the end of the string will be removed * Spaces at the begin and at the end of the string will be removed
* automatically in NamedDBElement::check_values_validity(). * automatically in NamedDBElement::check_values_validity().
* So you don't have to do this yourself. * So you don't have to do this yourself.
* *
* @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
{ {
$this->name = $new_name; $this->name = $new_name;
return $this; return $this;
} }
@ -122,15 +124,15 @@ abstract class NamedDBElement extends DBElement
/** /**
* Helper for updating the timestamp. It is automatically called by doctrine before persisting. * Helper for updating the timestamp. It is automatically called by doctrine before persisting.
*
* @ORM\PrePersist * @ORM\PrePersist
* @ORM\PreUpdate * @ORM\PreUpdate
*/ */
public function updatedTimestamps(): void public function updatedTimestamps(): void
{ {
$this->lastModified = new \DateTime('now'); $this->lastModified = new \DateTime('now');
if ($this->addedDate === null) { if (null === $this->addedDate) {
$this->addedDate = new \DateTime('now'); $this->addedDate = new \DateTime('now');
} }
} }
} }

View file

@ -1,10 +1,11 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -27,24 +28,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; namespace App\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* Class Orderdetail * Class Orderdetail.
* @package App\Entity
* *
* @ORM\Table("orderdetails") * @ORM\Table("orderdetails")
* @ORM\Entity() * @ORM\Entity()
*/ */
class Orderdetail extends DBElement class Orderdetail extends DBElement
{ {
/** /**
* @var Part * @var Part
* @ORM\ManyToOne(targetEntity="Part", inversedBy="orderdetails") * @ORM\ManyToOne(targetEntity="Part", inversedBy="orderdetails")
@ -85,6 +82,7 @@ class Orderdetail extends DBElement
/** /**
* 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
@ -99,7 +97,7 @@ class Orderdetail extends DBElement
*********************************************************************************/ *********************************************************************************/
/** /**
* Get the part * Get the part.
* *
* @return Part the part of this orderdetails * @return Part the part of this orderdetails
*/ */
@ -109,7 +107,7 @@ class Orderdetail extends DBElement
} }
/** /**
* Get the supplier * Get the supplier.
* *
* @return Supplier the supplier of this orderdetails * @return Supplier the supplier of this orderdetails
* *
@ -131,12 +129,12 @@ class Orderdetail extends DBElement
} }
/** /**
* Get if this orderdetails is obsolete * Get if this orderdetails is obsolete.
* *
* "Orderdetails is obsolete" means that the part with that supplier-part-nr * "Orderdetails is obsolete" means that the part with that supplier-part-nr
* is no longer available from the supplier of that orderdetails. * is no longer available from the supplier of that orderdetails.
* *
* @return boolean * true if this part is obsolete at that supplier * @return bool * true if this part is obsolete at that supplier
* * false if this part isn't obsolete at that supplier * * false if this part isn't obsolete at that supplier
*/ */
public function getObsolete(): bool public function getObsolete(): bool
@ -154,7 +152,7 @@ class Orderdetail extends DBElement
*/ */
public function getSupplierProductUrl(bool $no_automatic_url = false): string public function getSupplierProductUrl(bool $no_automatic_url = false): string
{ {
if ($no_automatic_url || $this->supplierpartnr !== '') { if ($no_automatic_url || '' !== $this->supplierpartnr) {
return $this->supplierpartnr; return $this->supplierpartnr;
} }
@ -162,7 +160,7 @@ class Orderdetail extends DBElement
} }
/** /**
* Get all pricedetails * Get all pricedetails.
* *
* @return Pricedetails[] all pricedetails as a one-dimensional array of Pricedetails objects, * @return Pricedetails[] all pricedetails as a one-dimensional array of Pricedetails objects,
* sorted by minimum discount quantity * sorted by minimum discount quantity
@ -175,15 +173,15 @@ class Orderdetail extends DBElement
} }
/** /**
* Get the price for a specific quantity * Get the price for a specific quantity.
* *
* @param boolean $as_money_string * if true, this method returns a money string incl. currency * @param bool $as_money_string * if true, this method returns a money string incl. currency
* * if false, this method returns the price as float * * if false, this method returns the price as float
* @param integer $quantity this is the quantity to choose the correct pricedetails * @param int $quantity this is the quantity to choose the correct pricedetails
* @param integer|NULL $multiplier * This is the multiplier which will be applied to every single price * @param int|null $multiplier * This is the multiplier which will be applied to every single price
* * If you pass NULL, the number from $quantity will be used * * If you pass NULL, the number from $quantity will be used
* *
* @return float|null|string float: the price as a float number (if "$as_money_string == false") * @return float|string|null float: the price as a float number (if "$as_money_string == false")
* * null: if there are no prices and "$as_money_string == false" * * null: if there are no prices and "$as_money_string == false"
* * string: the price as a string incl. currency (if "$as_money_string == true") * * string: the price as a string incl. currency (if "$as_money_string == true")
* *
@ -196,7 +194,7 @@ class Orderdetail extends DBElement
*/ */
public function getPrice(bool $as_money_string = false, int $quantity = 1, $multiplier = null) public function getPrice(bool $as_money_string = false, int $quantity = 1, $multiplier = null)
{ {
/** /*
if (($quantity == 0) && ($multiplier === null)) { if (($quantity == 0) && ($multiplier === null)) {
if ($as_money_string) { if ($as_money_string) {
return floatToMoneyString(0); return floatToMoneyString(0);
@ -245,10 +243,9 @@ class Orderdetail extends DBElement
*********************************************************************************/ *********************************************************************************/
/** /**
* Set the supplier ID * Set the supplier ID.
* *
* @param integer $new_supplier_id the ID of the new supplier * @param int $new_supplier_id the ID of the new supplier
*/ */
public function setSupplierId(int $new_supplier_id): self public function setSupplierId(int $new_supplier_id): self
{ {
@ -262,28 +259,30 @@ class Orderdetail extends DBElement
* 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
*
*/ */
public function setSupplierpartnr(string $new_supplierpartnr): self public function setSupplierpartnr(string $new_supplierpartnr): self
{ {
$this->supplierpartnr = $new_supplierpartnr; $this->supplierpartnr = $new_supplierpartnr;
return $this; return $this;
} }
/** /**
* 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 boolean $new_obsolete true means that this part is obsolete * @param bool $new_obsolete true means that this part is obsolete
*/ */
public function setObsolete(bool $new_obsolete): self public function setObsolete(bool $new_obsolete): self
{ {
$this->obsolete = $new_obsolete; $this->obsolete = $new_obsolete;
return $this; return $this;
} }
/** /**
* 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.
*/ */
public function setSupplierProductUrl(string $new_url) public function setSupplierProductUrl(string $new_url)

View file

@ -1,10 +1,11 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -27,13 +28,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; namespace App\Entity;
use App\Security\Annotations\ColumnSecurity; use App\Security\Annotations\ColumnSecurity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
//use Webmozart\Assert\Assert; //use Webmozart\Assert\Assert;
@ -41,8 +39,7 @@ use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
/** /**
* Class Part * Class Part.
* @package App\Entity
* *
* @ORM\Entity(repositoryClass="App\Repository\PartRepository") * @ORM\Entity(repositoryClass="App\Repository\PartRepository")
* @ORM\Table("parts") * @ORM\Table("parts")
@ -127,7 +124,6 @@ class Part extends AttachmentContainingDBElement
*/ */
protected $lastModified; protected $lastModified;
/********************** /**********************
* Propertys * Propertys
***********************/ ***********************/
@ -207,10 +203,10 @@ class Part extends AttachmentContainingDBElement
*/ */
protected $manufacturer_product_url = ''; protected $manufacturer_product_url = '';
/** /**
* 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
@ -218,7 +214,6 @@ class Part extends AttachmentContainingDBElement
return 'P'.sprintf('%06d', $this->getID()); return 'P'.sprintf('%06d', $this->getID());
} }
/********************************************************************************* /*********************************************************************************
* Getters * Getters
********************************************************************************/ ********************************************************************************/
@ -247,17 +242,20 @@ class Part extends AttachmentContainingDBElement
/** /**
* Check if the value of the Instock is unknown. * Check if the value of the Instock is unknown.
*
* @return bool True, if the value of the instock is unknown. * @return bool True, if the value of the instock is unknown.
*/ */
public function isInstockUnknown(): bool public function isInstockUnknown(): bool
{ {
return $this->instock <= static::INSTOCK_UNKNOWN; return $this->instock <= static::INSTOCK_UNKNOWN;
}/** @noinspection ReturnTypeCanBeDeclaredInspection */ }
/** @noinspection ReturnTypeCanBeDeclaredInspection */
/** /**
* Get the count of parts which must be in stock at least * Get the count of parts which must be in stock at least.
* *
* @return integer count of parts which must be in stock at least * @return int count of parts which must be in stock at least
*/ */
public function getMinInstock(): int public function getMinInstock(): int
{ {
@ -271,23 +269,22 @@ class Part extends AttachmentContainingDBElement
*/ */
public function getComment(): string public function getComment(): string
{ {
return htmlspecialchars($this->comment); return htmlspecialchars($this->comment);
} }
/** /**
* Get if this part is obsolete * Get if this part is obsolete.
* *
* A Part is marked as "obsolete" if all their orderdetails are marked as "obsolete". * A Part is marked as "obsolete" if all their orderdetails are marked as "obsolete".
* If a part has no orderdetails, the part isn't marked as obsolete. * If a part has no orderdetails, the part isn't marked as obsolete.
* *
* @return boolean true, if this part is obsolete. false, if this part isn't obsolete * @return bool true, if this part is obsolete. false, if this part isn't obsolete
*/ */
public function isObsolete(): bool public function isObsolete(): bool
{ {
$all_orderdetails = $this->getOrderdetails(); $all_orderdetails = $this->getOrderdetails();
if (count($all_orderdetails) === 0) { if (0 === count($all_orderdetails)) {
return false; return false;
} }
@ -301,9 +298,9 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Get if this part is visible * Get if this part is visible.
* *
* @return boolean 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
*/ */
public function isVisible(): bool public function isVisible(): bool
@ -323,10 +320,10 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* 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
* @return NULL if there is no order supplier selected *
* @throws Exception * @throws Exception
*/ */
public function getOrderOrderdetails(): ?Orderdetail public function getOrderOrderdetails(): ?Orderdetail
@ -342,9 +339,9 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Get the order quantity of this part * Get the order quantity of this part.
* *
* @return integer the order quantity * @return int the order quantity
*/ */
public function getOrderQuantity(): int public function getOrderQuantity(): int
{ {
@ -352,27 +349,27 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Get the minimum quantity which should be ordered * Get the minimum quantity which should be ordered.
* *
* @param boolean $with_devices * if true, all parts from devices which are marked as "to order" will be included in the calculation * @param bool $with_devices * if true, all parts from devices which are marked as "to order" will be included in the calculation
* * if false, only max(mininstock - instock, 0) will be returned * * if false, only max(mininstock - instock, 0) will be returned
* *
* @return integer the minimum order quantity * @return int the minimum order quantity
*
* @throws Exception * @throws Exception
*/ */
public function getMinOrderQuantity(bool $with_devices = true): int public function getMinOrderQuantity(bool $with_devices = true): int
{ {
//TODO //TODO
throw new \Exception('Not implemented yet...'); throw new \Exception('Not implemented yet...');
/*
/**
if ($with_devices) { if ($with_devices) {
$count_must_order = 0; // for devices with "order_only_missing_parts == false" $count_must_order = 0; // for devices with "order_only_missing_parts == false"
$count_should_order = 0; // for devices with "order_only_missing_parts == true" $count_should_order = 0; // for devices with "order_only_missing_parts == true"
$deviceparts = DevicePart::getOrderDeviceParts($this->database, $this->current_user, $this->log, $this->getID()); $deviceparts = DevicePart::getOrderDeviceParts($this->database, $this->current_user, $this->log, $this->getID());
foreach ($deviceparts as $devicepart) { foreach ($deviceparts as $devicepart) {
/** @var $devicepart DevicePart */ /** @var $devicepart DevicePart */
/** @var $device Device */ /** /* @var $device Device */ /*
$device = $devicepart->getDevice(); $device = $devicepart->getDevice();
if ($device->getOrderOnlyMissingParts()) { if ($device->getOrderOnlyMissingParts()) {
$count_should_order += $device->getOrderQuantity() * $devicepart->getMountQuantity(); $count_should_order += $device->getOrderQuantity() * $devicepart->getMountQuantity();
@ -388,9 +385,9 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Check if this part is marked for manual ordering * Check if this part is marked for manual ordering.
* *
* @return boolean the "manual_order" attribute * @return bool the "manual_order" attribute
*/ */
public function isMarkedForManualOrder(): bool public function isMarkedForManualOrder(): bool
{ {
@ -399,7 +396,8 @@ class Part extends AttachmentContainingDBElement
/** /**
* Check if the part is automatically marked for Ordering, because the instock value is smaller than the min instock value. * Check if the part is automatically marked for Ordering, because the instock value is smaller than the min instock value.
* This is called automatic ordering * This is called automatic ordering.
*
* @return bool True, if the part should be ordered. * @return bool True, if the part should be ordered.
*/ */
public function isAutoOrdered(): bool public function isAutoOrdered(): bool
@ -423,11 +421,11 @@ class Part extends AttachmentContainingDBElement
*/ */
public function getManufacturerProductUrl(): string public function getManufacturerProductUrl(): string
{ {
if ($this->manufacturer_product_url !== '') { if ('' !== $this->manufacturer_product_url) {
return $this->manufacturer_product_url; return $this->manufacturer_product_url;
} }
if ($this->getManufacturer() !== null) { if (null !== $this->getManufacturer()) {
return $this->getManufacturer()->getAutoProductUrl($this->name); return $this->getManufacturer()->getAutoProductUrl($this->name);
} }
@ -436,6 +434,7 @@ class Part extends AttachmentContainingDBElement
/** /**
* 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 getOwnProductURL(): string public function getOwnProductURL(): string
@ -444,7 +443,7 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Get the category of this part * Get the category of this part.
* *
* There is always a category, for each part! * There is always a category, for each part!
* *
@ -456,10 +455,9 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Get the footprint of this part (if there is one) * Get the footprint of this part (if there is one).
* *
* @return Footprint the footprint of this part (if there is one) * @return Footprint the footprint of this part (if there is one)
* @return NULL if this part has no footprint
*/ */
public function getFootprint(): ?Footprint public function getFootprint(): ?Footprint
{ {
@ -467,10 +465,9 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Get the storelocation of this part (if there is one) * Get the storelocation of this part (if there is one).
* *
* @return Storelocation the storelocation of this part (if there is one) * @return Storelocation the storelocation of this part (if there is one)
* @return NULL if this part has no storelocation
*/ */
public function getStorelocation(): ?Storelocation public function getStorelocation(): ?Storelocation
{ {
@ -478,10 +475,9 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Get the manufacturer of this part (if there is one) * Get the manufacturer of this part (if there is one).
* *
* @return Manufacturer the manufacturer of this part (if there is one) * @return Manufacturer the manufacturer of this part (if there is one)
* @return NULL if this part has no manufacturer
*/ */
public function getManufacturer(): ?Manufacturer public function getManufacturer(): ?Manufacturer
{ {
@ -489,10 +485,9 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Get the master picture "Attachement"-object of this part (if there is one) * Get the master picture "Attachement"-object of this part (if there is one).
* *
* @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)
* @return NULL if this part has no master picture
*/ */
public function getMasterPictureAttachement(): ?Attachment public function getMasterPictureAttachement(): ?Attachment
{ {
@ -500,9 +495,9 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Get all orderdetails of this part * Get all orderdetails of this part.
* *
* @param boolean $hide_obsolete If true, obsolete orderdetails will NOT be returned * @param bool $hide_obsolete If true, obsolete orderdetails will NOT be returned
* *
* @return Orderdetails[] * all orderdetails as a one-dimensional array of Orderdetails objects * @return Orderdetails[] * all orderdetails as a one-dimensional array of Orderdetails objects
* (empty array if there are no ones) * (empty array if there are no ones)
@ -519,6 +514,7 @@ class Part extends AttachmentContainingDBElement
unset($orderdetails[$key]); unset($orderdetails[$key]);
} }
} }
return $orderdetails; return $orderdetails;
} else { } else {
return $this->orderdetails; return $this->orderdetails;
@ -526,7 +522,7 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Get all devices which uses this part * Get all devices which uses this part.
* *
* @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)
@ -540,21 +536,21 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Get all suppliers of this part * Get all suppliers of this part.
* *
* This method simply gets the suppliers of the orderdetails and prepare them.\n * This method simply gets the suppliers of the orderdetails and prepare them.\n
* You can get the suppliers as an array or as a string with individual delimeter. * You can get the suppliers as an array or as a string with individual delimeter.
* *
* @param boolean $object_array * if true, this method returns an array of Supplier objects * @param bool $object_array * if true, this method returns an array of Supplier objects
* * if false, this method returns an array of strings * * if false, this method returns an array of strings
* @param string|NULL $delimeter * if this is a string and "$object_array == false", * @param string|null $delimeter * if this is a string and "$object_array == false",
* this method returns a string with all * this method returns a string with all
* supplier names, delimeted by "$delimeter" * supplier names, delimeted by "$delimeter"
* @param boolean $full_paths * if true and "$object_array = false", the returned * @param bool $full_paths * if true and "$object_array = false", the returned
* suppliernames are full paths (path + name) * suppliernames are full paths (path + name)
* * if true and "$object_array = false", the returned * * if true and "$object_array = false", the returned
* suppliernames are only the names (without path) * suppliernames are only the names (without path)
* @param boolean $hide_obsolete If true, suppliers from obsolete orderdetails will NOT be returned * @param bool $hide_obsolete If true, suppliers from obsolete orderdetails will NOT be returned
* *
* @return array all suppliers as a one-dimensional array of Supplier objects * @return array all suppliers as a one-dimensional array of Supplier objects
* (if "$object_array == true") * (if "$object_array == true")
@ -579,7 +575,7 @@ class Part extends AttachmentContainingDBElement
} else { } else {
$supplier_names = array(); $supplier_names = array();
foreach ($suppliers as $supplier) { foreach ($suppliers as $supplier) {
/** @var Supplier $supplier */ /* @var Supplier $supplier */
if ($full_paths) { if ($full_paths) {
$supplier_names[] = $supplier->getFullPath(); $supplier_names[] = $supplier->getFullPath();
} else { } else {
@ -596,14 +592,14 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Get all supplier-part-Nrs * Get all supplier-part-Nrs.
* *
* This method simply gets the suppliers-part-Nrs of the orderdetails and prepare them.\n * This method simply gets the suppliers-part-Nrs of the orderdetails and prepare them.\n
* You can get the numbers as an array or as a string with individual delimeter. * You can get the numbers as an array or as a string with individual delimeter.
* *
* @param string|NULL $delimeter * if this is a string, this method returns a delimeted string * @param string|null $delimeter * if this is a string, this method returns a delimeted string
* * otherwise, this method returns an array of strings * * otherwise, this method returns an array of strings
* @param boolean $hide_obsolete If true, supplierpartnrs from obsolete orderdetails will NOT be returned * @param bool $hide_obsolete If true, supplierpartnrs from obsolete orderdetails will NOT be returned
* *
* @return array all supplierpartnrs as an array of strings (if "$delimeter == NULL") * @return array all supplierpartnrs as an array of strings (if "$delimeter == NULL")
* @return string all supplierpartnrs as a string, delimeted ba $delimeter (if $delimeter is a string) * @return string all supplierpartnrs as a string, delimeted ba $delimeter (if $delimeter is a string)
@ -626,19 +622,19 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Get all prices of this part * Get all prices of this part.
* *
* This method simply gets the prices of the orderdetails and prepare them.\n * This method simply gets the prices of the orderdetails and prepare them.\n
* In the returned array/string there is a price for every supplier. * In the returned array/string there is a price for every supplier.
* *
* @param boolean $float_array * if true, the returned array is an array of floats * @param bool $float_array * if true, the returned array is an array of floats
* * if false, the returned array is an array of strings * * if false, the returned array is an array of strings
* @param string|NULL $delimeter if this is a string, this method returns a delimeted string * @param string|null $delimeter if this is a string, this method returns a delimeted string
* instead of an array. * instead of an array.
* @param integer $quantity this is the quantity to choose the correct priceinformation * @param int $quantity this is the quantity to choose the correct priceinformation
* @param integer|NULL $multiplier * This is the multiplier which will be applied to every single price * @param int|null $multiplier * This is the multiplier which will be applied to every single price
* * If you pass NULL, the number from $quantity will be used * * If you pass NULL, the number from $quantity will be used
* @param boolean $hide_obsolete If true, prices from obsolete orderdetails will NOT be returned * @param bool $hide_obsolete If true, prices from obsolete orderdetails will NOT be returned
* *
* @return array all prices as an array of floats (if "$delimeter == NULL" & "$float_array == true") * @return array all prices as an array of floats (if "$delimeter == NULL" & "$float_array == true")
* @return array all prices as an array of strings (if "$delimeter == NULL" & "$float_array == false") * @return array all prices as an array of strings (if "$delimeter == NULL" & "$float_array == false")
@ -666,20 +662,19 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Get the average price of all orderdetails * Get the average price of all orderdetails.
* *
* With the $multiplier you're able to multiply the price before it will be returned. * With the $multiplier you're able to multiply the price before it will be returned.
* This is useful if you want to have the price as a string with currency, but multiplied with a factor. * This is useful if you want to have the price as a string with currency, but multiplied with a factor.
* *
* @param boolean $as_money_string * if true, the retruned value will be a string incl. currency, * @param bool $as_money_string * if true, the retruned value will be a string incl. currency,
* ready to print it out. See float_to_money_string(). * ready to print it out. See float_to_money_string().
* * if false, the returned value is a float * * if false, the returned value is a float
* @param integer $quantity this is the quantity to choose the correct priceinformations * @param int $quantity this is the quantity to choose the correct priceinformations
* @param integer|NULL $multiplier * This is the multiplier which will be applied to every single price * @param int|null $multiplier * This is the multiplier which will be applied to every single price
* * If you pass NULL, the number from $quantity will be used * * If you pass NULL, the number from $quantity will be used
* *
* @return float price (if "$as_money_string == false") * @return float price (if "$as_money_string == false")
* @return NULL if there are no prices for this part and "$as_money_string == false"
* @return string price with currency (if "$as_money_string == true") * @return string price with currency (if "$as_money_string == true")
* *
* @throws Exception if there was an error * @throws Exception if there was an error
@ -691,9 +686,9 @@ class Part extends AttachmentContainingDBElement
$count = 0; $count = 0;
foreach ($prices as $price) { foreach ($prices as $price) {
if ($price !== null) { if (null !== $price) {
$average_price += $price; $average_price += $price;
$count++; ++$count;
} }
} }
@ -709,15 +704,14 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Get the filename of the master picture (absolute path from filesystem root) * Get the filename of the master picture (absolute path from filesystem root).
* *
* @param boolean $use_footprint_filename * if true, and this part has no picture, this method * @param bool $use_footprint_filename * if true, and this part has no picture, this method
* will return the filename of its footprint (if available) * will return the filename of its footprint (if available)
* * if false, and this part has no picture, * * if false, and this part has no picture,
* this method will return NULL * this method will return NULL
* *
* @return string the whole path + filename from filesystem root as a UNIX path (with slashes) * @return string the whole path + filename from filesystem root as a UNIX path (with slashes)
* @return NULL if there is no picture
* *
* @throws \Exception if there was an error * @throws \Exception if there was an error
*/ */
@ -725,13 +719,13 @@ class Part extends AttachmentContainingDBElement
{ {
$master_picture = $this->getMasterPictureAttachement(); // returns an Attachement-object $master_picture = $this->getMasterPictureAttachement(); // returns an Attachement-object
if ($master_picture !== null) { if (null !== $master_picture) {
return $master_picture->getFilename(); return $master_picture->getFilename();
} }
if ($use_footprint_filename) { if ($use_footprint_filename) {
$footprint = $this->getFootprint(); $footprint = $this->getFootprint();
if ($footprint !== null) { if (null !== $footprint) {
return $footprint->getFilename(); return $footprint->getFilename();
} }
} }
@ -741,12 +735,15 @@ class Part extends AttachmentContainingDBElement
/** /**
* Parses the selected fields and extract Properties of the part. * Parses the selected fields and extract Properties of the part.
*
* @param bool $use_description Use the description field for parsing * @param bool $use_description Use the description field for parsing
* @param bool $use_comment Use the comment field for parsing * @param bool $use_comment Use the comment field for parsing
* @param bool $use_name Use the name field for parsing * @param bool $use_name Use the name field for parsing
* @param bool $force_output Properties are parsed even if properties are disabled. * @param bool $force_output Properties are parsed even if properties are disabled.
*
* @return array A array of PartProperty objects. * @return array A array of PartProperty objects.
* @return array If Properties are disabled or nothing was detected, then an empty array is returned. * @return array If Properties are disabled or nothing was detected, then an empty array is returned.
*
* @throws Exception * @throws Exception
*/ */
public function getProperties(bool $use_description = true, bool $use_comment = true, bool $use_name = true, bool $force_output = false): array public function getProperties(bool $use_description = true, bool $use_comment = true, bool $use_name = true, bool $force_output = false): array
@ -783,8 +780,10 @@ class Part extends AttachmentContainingDBElement
/** /**
* Returns a loop (array) of the array representations of the properties of this part. * Returns a loop (array) of the array representations of the properties of this part.
*
* @param bool $use_description Use the description field for parsing * @param bool $use_description Use the description field for parsing
* @param bool $use_comment Use the comment field for parsing * @param bool $use_comment Use the comment field for parsing
*
* @return array A array of arrays with the name and value of the properties. * @return array A array of arrays with the name and value of the properties.
*/ */
public function getPropertiesLoop(bool $use_description = true, bool $use_comment = true, bool $use_name = true): array public function getPropertiesLoop(bool $use_description = true, bool $use_comment = true, bool $use_name = true): array
@ -796,6 +795,7 @@ class Part extends AttachmentContainingDBElement
/* @var PartProperty $property */ /* @var PartProperty $property */
$arr[] = $property->getArray(true); $arr[] = $property->getArray(true);
} }
return $arr; return $arr;
} }
@ -812,7 +812,7 @@ class Part extends AttachmentContainingDBElement
*********************************************************************************/ *********************************************************************************/
/** /**
* Set the description * Set the description.
* *
* @param string $new_description the new description * @param string $new_description the new description
* *
@ -821,13 +821,14 @@ class Part extends AttachmentContainingDBElement
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;
} }
/** /**
* Set the count of parts which are in stock * Set the count of parts which are in stock.
* *
* @param integer $new_instock the new count of parts which are in stock * @param int $new_instock the new count of parts which are in stock
* *
* @return self * @return self
*/ */
@ -858,22 +859,23 @@ class Part extends AttachmentContainingDBElement
* If the instock is not unknown and you pass false, nothing is changed. * If the instock is not unknown and you pass false, nothing is changed.
* *
* @param bool $new_unknown Set this to true if the instock should be marked as unknown. * @param bool $new_unknown Set this to true if the instock should be marked as unknown.
*
* @return Part * @return Part
*/ */
public function setInstockUnknown(bool $new_unknown): self public function setInstockUnknown(bool $new_unknown): self
{ {
if($new_unknown === true) { if (true === $new_unknown) {
$this->instock = self::INSTOCK_UNKNOWN; $this->instock = self::INSTOCK_UNKNOWN;
} elseif ($this->isInstockUnknown()) { } elseif ($this->isInstockUnknown()) {
$this->setInstock(0); $this->setInstock(0);
} }
return $this; return $this;
} }
/** /**
* Withdrawal the given number of parts. * Withdrawal the given number of parts.
*
* @param $count int The number of parts which should be withdrawan. * @param $count int The number of parts which should be withdrawan.
* @param $comment string A comment that should be associated with the withdrawal. * @param $comment string A comment that should be associated with the withdrawal.
* *
@ -906,6 +908,7 @@ class Part extends AttachmentContainingDBElement
/** /**
* Add the given number of parts. * Add the given number of parts.
*
* @param $count int The number of parts which should be withdrawan. * @param $count int The number of parts which should be withdrawan.
* @param $comment string A comment that should be associated with the withdrawal. * @param $comment string A comment that should be associated with the withdrawal.
* *
@ -938,9 +941,10 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Set the count of parts which should be in stock at least * Set the count of parts which should be in stock at least.
*
* @param int $new_mininstock the new count of parts which should be in stock at least
* *
* @param integer $new_mininstock the new count of parts which should be in stock at least
* @return self * @return self
*/ */
public function setMinInstock(int $new_mininstock): self public function setMinInstock(int $new_mininstock): self
@ -948,11 +952,12 @@ class Part extends AttachmentContainingDBElement
//Assert::natural($new_mininstock, 'The new minimum instock value must be positive! Got %s.'); //Assert::natural($new_mininstock, 'The new minimum instock value must be positive! Got %s.');
$this->mininstock = $new_mininstock; $this->mininstock = $new_mininstock;
return $this; return $this;
} }
/** /**
* Set the comment * Set the comment.
* *
* @param string $new_comment the new comment * @param string $new_comment the new comment
* *
@ -966,11 +971,11 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Set the "manual_order" attribute * Set the "manual_order" attribute.
* *
* @param boolean $new_manual_order the new "manual_order" attribute * @param bool $new_manual_order the new "manual_order" attribute
* @param integer $new_order_quantity the new order quantity * @param int $new_order_quantity the new order quantity
* @param integer|NULL $new_order_orderdetails_id * the ID of the new order orderdetails * @param int|null $new_order_orderdetails_id * the ID of the new order orderdetails
* * or Zero for "no order orderdetails" * * or Zero for "no order orderdetails"
* * or NULL for automatic order orderdetails * * or NULL for automatic order orderdetails
* (if the part has exactly one orderdetails, * (if the part has exactly one orderdetails,
@ -983,7 +988,6 @@ class Part extends AttachmentContainingDBElement
{ {
//Assert::greaterThan($new_order_quantity, 0, 'The new order quantity must be greater zero. Got %s!'); //Assert::greaterThan($new_order_quantity, 0, 'The new order quantity must be greater zero. Got %s!');
$this->manual_order = $new_manual_order; $this->manual_order = $new_manual_order;
//TODO; //TODO;
@ -994,9 +998,9 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Set the ID of the order orderdetails * Set the ID of the order orderdetails.
* *
* @param integer|NULL $new_order_orderdetails_id * the new order orderdetails ID * @param int|null $new_order_orderdetails_id * the new order orderdetails ID
* * Or, to remove the orderdetails, pass a NULL * * Or, to remove the orderdetails, pass a NULL
* *
* @return self * @return self
@ -1010,9 +1014,9 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Set the order quantity * Set the order quantity.
* *
* @param integer $new_order_quantity the new order quantity * @param int $new_order_quantity the new order quantity
* *
* @return self * @return self
*/ */
@ -1026,7 +1030,7 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Set the category of this Part * Set the category of this Part.
* *
* Every part must have a valid category (in contrast to the * Every part must have a valid category (in contrast to the
* attributes "footprint", "storelocation", ...)! * attributes "footprint", "storelocation", ...)!
@ -1047,6 +1051,7 @@ class Part extends AttachmentContainingDBElement
* *
* @param Footprint|null $new_footprint The new footprint of this part. Set to null, if this part should not have * @param Footprint|null $new_footprint The new footprint of this part. Set to null, if this part should not have
* a footprint. * a footprint.
*
* @return self * @return self
*/ */
public function setFootprint(?Footprint $new_footprint): self public function setFootprint(?Footprint $new_footprint): self
@ -1056,12 +1061,12 @@ class Part extends AttachmentContainingDBElement
return $this; return $this;
} }
/** /**
* Set the new store location of this part. * Set the new store location of this part.
* *
* @param Storelocation|null $new_storelocation The new Storelocation of this part. Set to null, if this part should * @param Storelocation|null $new_storelocation The new Storelocation of this part. Set to null, if this part should
* not have a storelocation. * not have a storelocation.
*
* @return Part * @return Part
*/ */
public function setStorelocation(?Storelocation $new_storelocation): self public function setStorelocation(?Storelocation $new_storelocation): self
@ -1076,6 +1081,7 @@ class Part extends AttachmentContainingDBElement
* *
* @param Manufacturer|null $new_manufacturer The new Manufacturer of this part. Set to null, if this part should * @param Manufacturer|null $new_manufacturer The new Manufacturer of this part. Set to null, if this part should
* not have a manufacturer. * not have a manufacturer.
*
* @return Part * @return Part
*/ */
public function setManufacturer(?Manufacturer $new_manufacturer): self public function setManufacturer(?Manufacturer $new_manufacturer): self
@ -1087,6 +1093,7 @@ class Part extends AttachmentContainingDBElement
/** /**
* Set the favorite status for this part. * Set the favorite status for this part.
*
* @param $new_favorite_status bool The new favorite status, that should be applied on this part. * @param $new_favorite_status bool The new favorite status, that should be applied on this part.
* Set this to true, when the part should be a favorite. * Set this to true, when the part should be a favorite.
* *
@ -1101,7 +1108,9 @@ class Part extends AttachmentContainingDBElement
/** /**
* Sets the URL to the manufacturer site about this Part. Set to "" if this part should use the automatically URL based on its manufacturer. * Sets the URL to the manufacturer site about this Part. Set to "" if this part should use the automatically URL based on its manufacturer.
*
* @param string $new_url The new url * @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
@ -1112,9 +1121,9 @@ class Part extends AttachmentContainingDBElement
} }
/** /**
* Set the ID of the master picture Attachement * Set the ID of the master picture Attachement.
* *
* @param integer|NULL $new_master_picture_attachement_id * the ID of the Attachement object of the master picture * @param int|null $new_master_picture_attachement_id * the ID of the Attachement object of the master picture
* * NULL means "no master picture" * * NULL means "no master picture"
* *
* @throws Exception if the new ID is not valid * @throws Exception if the new ID is not valid
@ -1129,6 +1138,4 @@ class Part extends AttachmentContainingDBElement
return $this; return $this;
} }
} }

View file

@ -1,9 +1,10 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
/** /**
*
* Part-DB Version 0.4+ "nextgen" * Part-DB Version 0.4+ "nextgen"
* Copyright (C) 2016 - 2019 Jan Böhmer * Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics * https://github.com/jbtronics.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -18,7 +19,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; namespace App\Entity;
@ -26,13 +26,11 @@ namespace App\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* Class PartsContainingDBElement * Class PartsContainingDBElement.
* @package PartDB\Models
* *
* @ORM\MappedSuperclass() * @ORM\MappedSuperclass()
*/ */
abstract class PartsContainingDBElement extends StructuralDBElement abstract class PartsContainingDBElement extends StructuralDBElement
{ {
protected $parts; protected $parts;
} }

View file

@ -1,9 +1,8 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,7 +25,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; namespace App\Entity;
@ -38,23 +36,19 @@ use Webmozart\Assert\Assert;
* This entity represents the permission fields a user or group can have. * This entity represents the permission fields a user or group can have.
* *
* @ORM\Embeddable() * @ORM\Embeddable()
* @package App\Entity
*/ */
class PermissionsEmbed class PermissionsEmbed
{ {
/** /**
* Permission values * Permission values.
*/ */
public const INHERIT = 0b00; public const INHERIT = 0b00;
public const ALLOW = 0b01; public const ALLOW = 0b01;
public const DISALLOW = 0b10; public const DISALLOW = 0b10;
/** /**
* Permission strings * Permission strings.
*/ */
public const STORELOCATIONS = 'storelocations'; public const STORELOCATIONS = 'storelocations';
public const FOOTRPINTS = 'footprints'; public const FOOTRPINTS = 'footprints';
public const CATEGORIES = 'categories'; public const CATEGORIES = 'categories';
@ -259,11 +253,12 @@ class PermissionsEmbed
*/ */
protected $labels; protected $labels;
/** /**
* 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.
*/ */
public function getBitValue(string $permission_name, int $bit_n): int public function getBitValue(string $permission_name, int $bit_n): int
@ -275,19 +270,21 @@ 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.
*/ */
public function getPermissionValue(string $permission_name, int $bit_n): ?bool public function getPermissionValue(string $permission_name, int $bit_n): ?bool
{ {
$value = $this->getBitValue($permission_name, $bit_n); $value = $this->getBitValue($permission_name, $bit_n);
if ($value == self::ALLOW) { if (self::ALLOW == $value) {
return true; return true;
} }
if($value == self::DISALLOW) { if (self::DISALLOW == $value) {
return false; return false;
} else { } else {
return null; return null;
@ -296,14 +293,16 @@ class PermissionsEmbed
/** /**
* 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
{ {
Assert::lessThanEq($n, 31, '$n must be smaller than 32, because only a 32bit int is used! Got %s.'); Assert::lessThanEq($n, 31, '$n must be smaller than 32, because only a 32bit int is used! Got %s.');
if ($n % 2 !== 0) { if (0 !== $n % 2) {
throw new \InvalidArgumentException('$n must be dividable by 2, because we address bit pairs here!'); throw new \InvalidArgumentException('$n must be dividable by 2, because we address bit pairs here!');
} }
@ -313,9 +312,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
@ -323,14 +324,14 @@ class PermissionsEmbed
Assert::lessThanEq($n, 31, '$n must be smaller than 32, because only a 32bit int is used! Got %s.'); Assert::lessThanEq($n, 31, '$n must be smaller than 32, because only a 32bit int is used! Got %s.');
Assert::lessThanEq($new, 3, '$new must be smaller than 3, because a bit pair is written! Got %s.'); Assert::lessThanEq($new, 3, '$new must be smaller than 3, because a bit pair is written! Got %s.');
if ($n % 2 !== 0) { if (0 !== $n % 2) {
throw new \InvalidArgumentException('$n must be dividable by 2, because we address bit pairs here!'); throw new \InvalidArgumentException('$n must be dividable by 2, because we address bit pairs here!');
} }
$mask = 0b11 << $n; //Mask all bits that should be writen $mask = 0b11 << $n; //Mask all bits that should be writen
$newval = $new << $n; //The new value. $newval = $new << $n; //The new value.
$data = ($data & ~$mask) | ($newval & $mask); $data = ($data & ~$mask) | ($newval & $mask);
return $data; return $data;
} }
} }

View file

@ -1,10 +1,11 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -27,19 +28,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; namespace App\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Webmozart\Assert\Assert; use Webmozart\Assert\Assert;
/** /**
* Class Pricedetail * Class Pricedetail.
* @package App\Entity
* *
* @ORM\Entity() * @ORM\Entity()
* @ORM\Table("pricedetails") * @ORM\Table("pricedetails")
@ -82,7 +79,6 @@ class Pricedetail extends DBElement
*/ */
protected $last_modified; protected $last_modified;
/******************************************************************************** /********************************************************************************
* *
* Getters * Getters
@ -90,10 +86,9 @@ class Pricedetail extends DBElement
*********************************************************************************/ *********************************************************************************/
/** /**
* Get the orderdetails of this pricedetails * Get the orderdetails of this pricedetails.
* *
* @return Orderdetail the orderdetails object * @return Orderdetail the orderdetails object
*
*/ */
public function getOrderdetails(): Orderdetail public function getOrderdetails(): Orderdetail
{ {
@ -101,11 +96,11 @@ class Pricedetail extends DBElement
} }
/** /**
* Get the price * Get the price.
* *
* @param boolean $as_money_string * if true, this method returns a money string incl. currency * @param bool $as_money_string * if true, this method returns a money string incl. currency
* * if false, this method returns the price as float * * if false, this method returns the price as float
* @param integer $multiplier The returned price (float or string) will be multiplied * @param int $multiplier The returned price (float or string) will be multiplied
* with this multiplier. * with this multiplier.
* *
* You will get the price for $multiplier parts. If you want the price which is stored * You will get the price for $multiplier parts. If you want the price which is stored
@ -129,11 +124,11 @@ class Pricedetail extends DBElement
} }
/** /**
* Get the price related quantity * Get the price related quantity.
* *
* This is the quantity, for which the price is valid. * This is the quantity, for which the price is valid.
* *
* @return integer the price related quantity * @return int the price related quantity
* *
* @see Pricedetails::setPriceRelatedQuantity() * @see Pricedetails::setPriceRelatedQuantity()
*/ */
@ -143,12 +138,12 @@ class Pricedetail extends DBElement
} }
/** /**
* Get the minimum discount quantity * Get the minimum discount quantity.
* *
* "Minimum discount quantity" means the minimum order quantity for which the price * "Minimum discount quantity" means the minimum order quantity for which the price
* of this orderdetails is valid. * of this orderdetails is valid.
* *
* @return integer the minimum discount quantity * @return int the minimum discount quantity
* *
* @see Pricedetails::setMinDiscountQuantity() * @see Pricedetails::setMinDiscountQuantity()
*/ */
@ -164,7 +159,7 @@ class Pricedetail extends DBElement
*********************************************************************************/ *********************************************************************************/
/** /**
* Set the price * Set the price.
* *
* @param float $new_price the new price as a float number * @param float $new_price the new price as a float number
* *
@ -184,7 +179,7 @@ class Pricedetail extends DBElement
} }
/** /**
* Set the price related quantity * Set the price related quantity.
* *
* This is the quantity, for which the price is valid. * This is the quantity, for which the price is valid.
* *
@ -192,13 +187,12 @@ class Pricedetail extends DBElement
* If 100pcs costs 20$, you have to set the price to 20$ and the price related * If 100pcs costs 20$, you have to set the price to 20$ and the price related
* quantity to 100. The single price (20$/100 = 0.2$) will be calculated automatically. * quantity to 100. The single price (20$/100 = 0.2$) will be calculated automatically.
* *
* @param integer $new_price_related_quantity the price related quantity * @param int $new_price_related_quantity the price related quantity
* *
* @return self * @return self
*/ */
public function setPriceRelatedQuantity(int $new_price_related_quantity): self public function setPriceRelatedQuantity(int $new_price_related_quantity): self
{ {
Assert::greaterThan($new_price_related_quantity, 0, Assert::greaterThan($new_price_related_quantity, 0,
'The new price related quantity must be greater zero! Got %s.'); 'The new price related quantity must be greater zero! Got %s.');
@ -208,7 +202,7 @@ class Pricedetail extends DBElement
} }
/** /**
* Set the minimum discount quantity * Set the minimum discount quantity.
* *
* "Minimum discount quantity" means the minimum order quantity for which the price * "Minimum discount quantity" means the minimum order quantity for which the price
* of this orderdetails is valid. This way, you're able to use different prices * of this orderdetails is valid. This way, you're able to use different prices
@ -222,7 +216,7 @@ class Pricedetail extends DBElement
* (Each of this examples would be an own Pricedetails-object. * (Each of this examples would be an own Pricedetails-object.
* So the orderdetails would have three Pricedetails for one supplier.) * So the orderdetails would have three Pricedetails for one supplier.)
* *
* @param integer $new_min_discount_quantity the minimum discount quantity * @param int $new_min_discount_quantity the minimum discount quantity
* *
* @return self * @return self
*/ */
@ -236,12 +230,10 @@ class Pricedetail extends DBElement
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

View file

@ -1,11 +1,11 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -28,7 +28,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; namespace App\Entity;
@ -36,8 +35,7 @@ namespace App\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* Class Storelocation * Class Storelocation.
* @package App\Entity
* *
* @ORM\Entity() * @ORM\Entity()
* @ORM\Table("storelocations") * @ORM\Table("storelocations")
@ -73,12 +71,12 @@ class Storelocation extends PartsContainingDBElement
*********************************************************************************/ *********************************************************************************/
/** /**
* Get the "is full" attribute * Get the "is full" attribute.
* *
* "is_full == true" means that there is no more space in this storelocation. * "is_full == true" means that there is no more space in this storelocation.
* This attribute is only for information, it has no effect. * This attribute is only for information, it has no effect.
* *
* @return boolean * true if the storelocation is full * @return bool * true if the storelocation is full
* * false if the storelocation isn't full * * false if the storelocation isn't full
*/ */
public function getIsFull(): bool public function getIsFull(): bool
@ -93,12 +91,12 @@ class Storelocation extends PartsContainingDBElement
*********************************************************************************/ *********************************************************************************/
/** /**
* Change the "is full" attribute of this storelocation * Change the "is full" attribute of this storelocation.
* *
* "is_full" = true means that there is no more space in this storelocation. * "is_full" = true means that there is no more space in this storelocation.
* This attribute is only for information, it has no effect. * This attribute is only for information, it has no effect.
* *
* @param boolean $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
* *
* @throws Exception if there was an error * @throws Exception if there was an error
@ -106,12 +104,14 @@ class Storelocation extends PartsContainingDBElement
public function setIsFull(bool $new_is_full): self public function setIsFull(bool $new_is_full): self
{ {
$this->is_full = $new_is_full; $this->is_full = $new_is_full;
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

View file

@ -1,9 +1,10 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
/** /**
*
* Part-DB Version 0.4+ "nextgen" * Part-DB Version 0.4+ "nextgen"
* Copyright (C) 2016 - 2019 Jan Böhmer * Copyright (C) 2016 - 2019 Jan Böhmer
* https://github.com/jbtronics * https://github.com/jbtronics.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -18,7 +19,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; namespace App\Entity;
@ -28,8 +28,7 @@ use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\PersistentCollection;
/** /**
* * All elements with the fields "id", "name" and "parent_id" (at least).
* All elements with the fields "id", "name" and "parent_id" (at least)
* *
* This class is for managing all database objects with a structural design. * This class is for managing all database objects with a structural design.
* All these sub-objects must have the table columns 'id', 'name' and 'parent_id' (at least)! * All these sub-objects must have the table columns 'id', 'name' and 'parent_id' (at least)!
@ -46,7 +45,6 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
//This is a not standard character, so build a const, so a dev can easily use it //This is a not standard character, so build a const, so a dev can easily use it
const PATH_DELIMITER_ARROW = ' → '; const PATH_DELIMITER_ARROW = ' → ';
// We can not define the mapping here or we will get an exception. Unfortunatly we have to do the mapping in the // We can not define the mapping here or we will get an exception. Unfortunatly we have to do the mapping in the
// subclasses // subclasses
/** /**
@ -84,7 +82,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
*****************************************************************************/ *****************************************************************************/
/** /**
* Check if this element is a child of another element (recursive) * Check if this element is a child of another element (recursive).
* *
* @param StructuralDBElement $another_element the object to compare * @param StructuralDBElement $another_element the object to compare
* IMPORTANT: both objects to compare must be from the same class (for example two "Device" objects)! * IMPORTANT: both objects to compare must be from the same class (for example two "Device" objects)!
@ -102,16 +100,15 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
throw new \InvalidArgumentException('isChildOf() funktioniert nur mit Elementen des gleichen Typs!'); throw new \InvalidArgumentException('isChildOf() funktioniert nur mit Elementen des gleichen Typs!');
} }
if ($this->getID() == null) { // this is the root node if (null == $this->getID()) { // this is the root node
return false; return false;
} }
//If this' parents element, is $another_element, then we are finished //If this' parents element, is $another_element, then we are finished
return (($this->parent->getID() == $another_element->getID()) return ($this->parent->getID() == $another_element->getID())
|| $this->parent->isChildOf($another_element)); //Otherwise, check recursivley || $this->parent->isChildOf($another_element); //Otherwise, check recursivley
} }
/****************************************************************************** /******************************************************************************
* *
* Getters * Getters
@ -132,6 +129,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
/** /**
* Get the parent of this element. * Get the parent of this element.
*
* @return StructuralDBElement|null The parent element. Null if this element, does not have a parent. * @return StructuralDBElement|null The parent element. Null if this element, does not have a parent.
*/ */
public function getParent(): ?self public function getParent(): ?self
@ -142,7 +140,8 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
/** /**
* Get the comment of the element. * Get the comment of the element.
* *
* @param boolean $parse_bbcode Should BBCode converted to HTML, before returning * @param bool $parse_bbcode Should BBCode converted to HTML, before returning
*
* @return string the comment * @return string the comment
*/ */
public function getComment(bool $parse_bbcode = true): string public function getComment(bool $parse_bbcode = true): string
@ -153,24 +152,23 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
} }
/** /**
* Get the level * Get the level.
* *
* The level of the root node is -1. * The level of the root node is -1.
* *
* @return integer 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
{ {
if ($this->level === 0) { if (0 === $this->level) {
$element = $this->parent; $element = $this->parent;
$parent_id = $element->getParentID(); $parent_id = $element->getParentID();
while ($parent_id > 0) { while ($parent_id > 0) {
/** @var StructuralDBElement $element */ /** @var StructuralDBElement $element */
$element = $element->parent; $element = $element->parent;
$parent_id = $element->getParentID(); $parent_id = $element->getParentID();
$this->level++; ++$this->level;
} }
} }
@ -178,7 +176,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
} }
/** /**
* Get the full path * Get the full path.
* *
* @param string $delimeter the delimeter of the returned string * @param string $delimeter the delimeter of the returned string
* *
@ -193,7 +191,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
$this->full_path_strings[] = $this->getName(); $this->full_path_strings[] = $this->getName();
$element = $this; $element = $this;
while ($element->parent != null) { while (null != $element->parent) {
$element = $element->parent; $element = $element->parent;
$this->full_path_strings[] = $element->getName(); $this->full_path_strings[] = $element->getName();
} }
@ -205,15 +203,15 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
} }
/** /**
* Get all subelements of this element * Get all subelements of this element.
* *
* @param boolean $recursive if true, the search is recursive * @param bool $recursive if true, the search is recursive
* *
* @return static[] all subelements as an array of objects (sorted by their full path) * @return static[] all subelements as an array of objects (sorted by their full path)
*/ */
public function getSubelements(bool $recursive): PersistentCollection public function getSubelements(bool $recursive): PersistentCollection
{ {
if ($this->children == null) { if (null == $this->children) {
$this->children = new ArrayCollection(); $this->children = new ArrayCollection();
} }
@ -237,26 +235,29 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
******************************************************************************/ ******************************************************************************/
/** /**
* Change the parent ID of this element * Change the parent ID of this element.
* *
* @param integer|null $new_parent_id * the ID of the new parent element * @param int|null $new_parent_id * the ID of the new parent element
* * NULL if the parent should be the root node * * NULL if the parent should be the root node
*/ */
public function setParentID($new_parent_id): self public function setParentID($new_parent_id): self
{ {
$this->parent_id = $new_parent_id; $this->parent_id = $new_parent_id;
return $this; return $this;
} }
/** /**
* Set the comment * Set the comment.
* *
* @param string $new_comment the new comment * @param string $new_comment the new comment
*
* @throws Exception if there was an error * @throws Exception if there was an error
*/ */
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;
} }
@ -267,15 +268,15 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
*********************************************************************************/ *********************************************************************************/
/** /**
* Build a HTML tree with all subcategories of this element * Build a HTML tree with all subcategories of this element.
* *
* This method prints a <option>-Line for every item. * This method prints a <option>-Line for every item.
* <b>The <select>-tags are not printed here, you have to print them yourself!</b> * <b>The <select>-tags are not printed here, you have to print them yourself!</b>
* Deeper levels have more spaces in front. * Deeper levels have more spaces in front.
* *
* @param integer $selected_id the ID of the selected item * @param int $selected_id the ID of the selected item
* @param boolean $recursive if true, the tree will be recursive * @param bool $recursive if true, the tree will be recursive
* @param boolean $show_root if true, the root node will be displayed * @param bool $show_root if true, the root node will be displayed
* @param string $root_name if the root node is the very root element, you can set its name here * @param string $root_name if the root node is the very root element, you can set its name here
* @param string $value_prefix This string is used as a prefix before the id in the value part of the option. * @param string $value_prefix This string is used as a prefix before the id in the value part of the option.
* *
@ -290,7 +291,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
string $root_name = '$$', string $root_name = '$$',
string $value_prefix = '' string $value_prefix = ''
): string { ): string {
if ($root_name == '$$') { if ('$$' == $root_name) {
$root_name = _('Oberste Ebene'); $root_name = _('Oberste Ebene');
} }
@ -315,7 +316,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
$selected = ($element->getID() == $selected_id) ? 'selected' : ''; $selected = ($element->getID() == $selected_id) ? 'selected' : '';
$html[] = '<option '.$selected.' value="'.$value_prefix.$element->getID().'">'; $html[] = '<option '.$selected.' value="'.$value_prefix.$element->getID().'">';
for ($i = 0; $i < $level; $i++) { for ($i = 0; $i < $level; ++$i) {
$html[] = '&nbsp;&nbsp;&nbsp;'; $html[] = '&nbsp;&nbsp;&nbsp;';
} }
$html[] = htmlspecialchars($element->getName()).'</option>'; $html[] = htmlspecialchars($element->getName()).'</option>';
@ -324,7 +325,6 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
return implode("\n", $html); return implode("\n", $html);
} }
public function buildBootstrapTree( public function buildBootstrapTree(
$page, $page,
$parameter, $parameter,
@ -332,9 +332,8 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
$show_root = false, $show_root = false,
$use_db_root_name = true, $use_db_root_name = true,
$root_name = '$$' $root_name = '$$'
): array ): array {
{ if ('$$' == $root_name) {
if ($root_name == '$$') {
$root_name = _('Oberste Ebene'); $root_name = _('Oberste Ebene');
} }
@ -346,12 +345,12 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
} }
// if we are on root level? // if we are on root level?
if ($this->getParentID() == -1) { if (-1 == $this->getParentID()) {
if ($show_root) { if ($show_root) {
$tree = array( $tree = array(
array('text' => $use_db_root_name ? htmlspecialchars($this->getName()) : $root_name, array('text' => $use_db_root_name ? htmlspecialchars($this->getName()) : $root_name,
'href' => $page.'?'.$parameter.'='.$this->getID(), 'href' => $page.'?'.$parameter.'='.$this->getID(),
'nodes' => $nodes) 'nodes' => $nodes, ),
); );
} else { //Dont show root node } else { //Dont show root node
$tree = $nodes; $tree = $nodes;
@ -359,42 +358,43 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
} elseif (!empty($nodes)) { } elseif (!empty($nodes)) {
$tree = array('text' => htmlspecialchars($this->getName()), $tree = array('text' => htmlspecialchars($this->getName()),
'href' => $page.'?'.$parameter.'='.$this->getID(), 'href' => $page.'?'.$parameter.'='.$this->getID(),
'nodes' => $nodes 'nodes' => $nodes,
); );
} else { } else {
$tree = array('text' => htmlspecialchars($this->getName()), $tree = array('text' => htmlspecialchars($this->getName()),
'href' => $page . '?' . $parameter . '=' . $this->getID() 'href' => $page.'?'.$parameter.'='.$this->getID(),
); );
} }
return $tree; return $tree;
} }
/** /**
* Creates a template loop for a Breadcrumb bar, representing the structural DB element. * Creates a template loop for a Breadcrumb bar, representing the structural DB element.
*
* @param $page string The base page, to which the breadcrumb links should be directing to. * @param $page string The base page, to which the breadcrumb links should be directing to.
* @param $parameter string The parameter, which selects the ID of the StructuralDBElement. * @param $parameter string The parameter, which selects the ID of the StructuralDBElement.
* @param bool $show_root Show the root as its own breadcrumb. * @param bool $show_root Show the root as its own breadcrumb.
* @param string $root_name The label which should be used for the root breadcrumb. * @param string $root_name The label which should be used for the root breadcrumb.
*
* @return array An Loop containing multiple arrays, which contains href and caption for the breadcrumb. * @return array An Loop containing multiple arrays, which contains href and caption for the breadcrumb.
*/ */
public function buildBreadcrumbLoop(string $page, string $parameter, bool $show_root = false, $root_name = '$$', bool $element_is_link = false): array public function buildBreadcrumbLoop(string $page, string $parameter, bool $show_root = false, $root_name = '$$', bool $element_is_link = false): array
{ {
$breadcrumb = array(); $breadcrumb = array();
if ($root_name == '$$') { if ('$$' == $root_name) {
$root_name = _('Oberste Ebene'); $root_name = _('Oberste Ebene');
} }
if ($show_root) { if ($show_root) {
$breadcrumb[] = array('label' => $root_name, $breadcrumb[] = array('label' => $root_name,
'disabled' => true); 'disabled' => true, );
} }
if (!$this->current_user->canDo(static::getPermissionName(), StructuralPermission::READ)) { if (!$this->current_user->canDo(static::getPermissionName(), StructuralPermission::READ)) {
return array('label' => '???', return array('label' => '???',
'disabled' => true); 'disabled' => true, );
} }
$tmp = array(); $tmp = array();
@ -418,5 +418,4 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
return $breadcrumb; return $breadcrumb;
} }
} }

View file

@ -1,10 +1,11 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -27,7 +28,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; namespace App\Entity;
@ -35,8 +35,7 @@ namespace App\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/** /**
* Class Supplier * Class Supplier.
* @package App\Entity
* *
* @ORM\Entity() * @ORM\Entity()
* @ORM\Table("suppliers") * @ORM\Table("suppliers")
@ -60,7 +59,7 @@ class Supplier extends Company
protected $orderdetails; protected $orderdetails;
/** /**
* Get all parts from this element * Get all parts from this element.
* *
* @return int all parts in a one-dimensional array of Part objects * @return int all parts in a one-dimensional array of Part objects
* *
@ -86,20 +85,18 @@ class Supplier extends Company
return (int) $query_data[0]['count']; */ return (int) $query_data[0]['count']; */
//TODO //TODO
throw new \Exception('Not implemented yet!'); throw new \Exception('Not implemented yet!');
} }
/** /**
* 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 'L'.sprintf('%06d', $this->getID()); return 'L'.sprintf('%06d', $this->getID());
} }
} }

View file

@ -1,10 +1,11 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -27,12 +28,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; namespace App\Entity;
use App\Entity\Embeddables\PermissionEntity;
use App\Security\Interfaces\HasPermissionsInterface; use App\Security\Interfaces\HasPermissionsInterface;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserInterface;
@ -64,7 +63,7 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
protected $name; protected $name;
/** /**
* //@ORM\Column(type="json") * //@ORM\Column(type="json").
*/ */
//protected $roles = []; //protected $roles = [];
@ -98,7 +97,6 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
*/ */
protected $department = ''; protected $department = '';
/** /**
* @var string|null The email address of the user * @var string|null The email address of the user
* @ORM\Column(type="string", length=255, nullable=true) * @ORM\Column(type="string", length=255, nullable=true)
@ -125,7 +123,7 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
protected $theme = ''; protected $theme = '';
/** /**
* @var Group|null The group this user belongs to. * @var Group|null the group this user belongs to
* @ORM\ManyToOne(targetEntity="Group", inversedBy="users", fetch="EAGER") * @ORM\ManyToOne(targetEntity="Group", inversedBy="users", fetch="EAGER")
* @ORM\JoinColumn(name="group_id", referencedColumnName="id") * @ORM\JoinColumn(name="group_id", referencedColumnName="id")
*/ */
@ -136,14 +134,14 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
*/ */
protected $permissions; protected $permissions;
/** /**
* Checks if the current user, is the user which represents the not logged in (anonymous) users. * Checks if the current user, is the user which represents the not logged in (anonymous) users.
* @return bool True if this user is the anonymous user. *
* @return bool true if this user is the anonymous user
*/ */
public function isAnonymousUser(): bool public function isAnonymousUser(): bool
{ {
return $this->id === static::ID_ANONYMOUS && $this->name === 'anonymous'; return $this->id === static::ID_ANONYMOUS && 'anonymous' === $this->name;
} }
/** /**
@ -187,7 +185,9 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
/** /**
* Sets the password hash for this user. * Sets the password hash for this user.
*
* @param string $password * @param string $password
*
* @return User * @return User
*/ */
public function setPassword(string $password): self public function setPassword(string $password): self
@ -217,6 +217,7 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
/** /**
* 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
@ -224,7 +225,6 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
return 'U'.sprintf('%06d', $this->getID()); return 'U'.sprintf('%06d', $this->getID());
} }
public function getPermissions(): PermissionsEmbed public function getPermissions(): PermissionsEmbed
{ {
return $this->permissions; return $this->permissions;
@ -236,9 +236,11 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
/** /**
* 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).
* @param bool $including_username Include the username in the full name. *
* @return string A string with the full name of this user. * @param bool $including_username include the username in the full name
*
* @return string a string with the full name of this user
*/ */
public function getFullName(bool $including_username = false): string public function getFullName(bool $including_username = false): string
{ {
@ -250,7 +252,6 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
return $str; return $str;
} }
public function setName(string $new_name): NamedDBElement public function setName(string $new_name): NamedDBElement
{ {
// Anonymous user is not allowed to change its username // Anonymous user is not allowed to change its username
@ -271,11 +272,13 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
/** /**
* @param string $first_name * @param string $first_name
*
* @return User * @return User
*/ */
public function setFirstName(?string $first_name): User public function setFirstName(?string $first_name): User
{ {
$this->first_name = $first_name; $this->first_name = $first_name;
return $this; return $this;
} }
@ -289,11 +292,13 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
/** /**
* @param string $last_name * @param string $last_name
*
* @return User * @return User
*/ */
public function setLastName(?string $last_name): User public function setLastName(?string $last_name): User
{ {
$this->last_name = $last_name; $this->last_name = $last_name;
return $this; return $this;
} }
@ -307,11 +312,13 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
/** /**
* @param string $department * @param string $department
*
* @return User * @return User
*/ */
public function setDepartment(?string $department): User public function setDepartment(?string $department): User
{ {
$this->department = $department; $this->department = $department;
return $this; return $this;
} }
@ -325,11 +332,13 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
/** /**
* @param string $email * @param string $email
*
* @return User * @return User
*/ */
public function setEmail(?string $email): User public function setEmail(?string $email): User
{ {
$this->email = $email; $this->email = $email;
return $this; return $this;
} }
@ -343,11 +352,13 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
/** /**
* @param string $language * @param string $language
*
* @return User * @return User
*/ */
public function setLanguage(?string $language): User public function setLanguage(?string $language): User
{ {
$this->language = $language; $this->language = $language;
return $this; return $this;
} }
@ -361,11 +372,13 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
/** /**
* @param string $timezone * @param string $timezone
*
* @return User * @return User
*/ */
public function setTimezone(?string $timezone): User public function setTimezone(?string $timezone): User
{ {
$this->timezone = $timezone; $this->timezone = $timezone;
return $this; return $this;
} }
@ -379,11 +392,13 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
/** /**
* @param string $theme * @param string $theme
*
* @return User * @return User
*/ */
public function setTheme(?string $theme): User public function setTheme(?string $theme): User
{ {
$this->theme = $theme; $this->theme = $theme;
return $this; return $this;
} }
@ -395,7 +410,7 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
public function setGroup(?Group $group): self public function setGroup(?Group $group): self
{ {
$this->group = $group; $this->group = $group;
return $this; return $this;
} }
} }

View file

@ -1,9 +1,8 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,13 +25,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;
class EntityNotSupported extends \Exception class EntityNotSupported extends \Exception
{ {
} }

View file

@ -1,9 +1,8 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,12 +25,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; namespace App\Form;
use App\Entity\Category; use App\Entity\Category;
use App\Entity\Manufacturer; use App\Entity\Manufacturer;
use App\Entity\Part; use App\Entity\Part;
@ -39,7 +36,6 @@ use App\Entity\Storelocation;
use FOS\CKEditorBundle\Form\Type\CKEditorType; use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
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;
use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\Extension\Core\Type\IntegerType;
@ -58,7 +54,6 @@ class PartType extends AbstractType
$this->security = $security; $this->security = $security;
} }
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$part = $options['data']; $part = $options['data'];
@ -66,31 +61,31 @@ class PartType extends AbstractType
$builder $builder
->add('name', TextType::class, ['empty_data' => '', 'label' => 'name.label', ->add('name', TextType::class, ['empty_data' => '', 'label' => 'name.label',
'attr' => ['placeholder' => 'part.name.placeholder'], 'attr' => ['placeholder' => 'part.name.placeholder'],
'disabled' => !$this->security->isGranted('name.edit', $part)]) 'disabled' => !$this->security->isGranted('name.edit', $part), ])
->add('description', TextType::class, ['required' => false, 'empty_data' => '', ->add('description', TextType::class, ['required' => false, 'empty_data' => '',
'label' => 'description.label', 'help' => 'bbcode.hint', 'attr' => ['placeholder' => 'part.description.placeholder'], 'label' => 'description.label', 'help' => 'bbcode.hint', 'attr' => ['placeholder' => 'part.description.placeholder'],
'disabled' => !$this->security->isGranted('description.edit', $part)]) 'disabled' => !$this->security->isGranted('description.edit', $part), ])
->add('instock', IntegerType::class, ->add('instock', IntegerType::class,
['attr' => ['min' => 0, 'placeholder' => 'part.instock.placeholder'], 'label' => 'instock.label', ['attr' => ['min' => 0, 'placeholder' => 'part.instock.placeholder'], 'label' => 'instock.label',
'disabled' => !$this->security->isGranted('instock.edit', $part)]) 'disabled' => !$this->security->isGranted('instock.edit', $part), ])
->add('mininstock', IntegerType::class, ->add('mininstock', IntegerType::class,
['attr' => ['min' => 0, 'placeholder' => 'part.mininstock.placeholder'], 'label' => 'mininstock.label', ['attr' => ['min' => 0, 'placeholder' => 'part.mininstock.placeholder'], 'label' => 'mininstock.label',
'disabled' => !$this->security->isGranted('mininstock.edit', $part)]) 'disabled' => !$this->security->isGranted('mininstock.edit', $part), ])
->add('category', EntityType::class, ['class' => Category::class, 'choice_label' => 'full_path', ->add('category', EntityType::class, ['class' => Category::class, 'choice_label' => 'full_path',
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'label' => 'category.label', 'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'label' => 'category.label',
'disabled' => !$this->security->isGranted('move', $part)]) 'disabled' => !$this->security->isGranted('move', $part), ])
->add('storelocation', EntityType::class, ['class' => Storelocation::class, 'choice_label' => 'full_path', ->add('storelocation', EntityType::class, ['class' => Storelocation::class, 'choice_label' => 'full_path',
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'required' => false, 'label' => 'storelocation.label', 'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'required' => false, 'label' => 'storelocation.label',
'disabled' => !$this->security->isGranted('storelocation.edit', $part)]) 'disabled' => !$this->security->isGranted('storelocation.edit', $part), ])
->add('manufacturer', EntityType::class, ['class' => Manufacturer::class, 'choice_label' => 'full_path', ->add('manufacturer', EntityType::class, ['class' => Manufacturer::class, 'choice_label' => 'full_path',
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'required' => false, 'label' => 'manufacturer.label', 'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'required' => false, 'label' => 'manufacturer.label',
'disabled' => !$this->security->isGranted('manufacturer.edit', $part)]) 'disabled' => !$this->security->isGranted('manufacturer.edit', $part), ])
->add('manufacturer_product_url', UrlType::class, ['required' => false, 'empty_data' => '', ->add('manufacturer_product_url', UrlType::class, ['required' => false, 'empty_data' => '',
'label' => 'manufacturer_url.label', 'label' => 'manufacturer_url.label',
'disabled' => !$this->security->isGranted('manufacturer.edit', $part)]) 'disabled' => !$this->security->isGranted('manufacturer.edit', $part), ])
->add('comment', CKEditorType::class, ['required' => false, ->add('comment', CKEditorType::class, ['required' => false,
'label' => 'comment.label', 'attr' => ['rows' => 4], 'help' => 'bbcode.hint', 'label' => 'comment.label', 'attr' => ['rows' => 4], 'help' => 'bbcode.hint',
'disabled' => !$this->security->isGranted('comment.edit', $part)]) 'disabled' => !$this->security->isGranted('comment.edit', $part), ])
//Buttons //Buttons
->add('save', SubmitType::class, ['label' => 'part.edit.save']) ->add('save', SubmitType::class, ['label' => 'part.edit.save'])
@ -100,7 +95,7 @@ class PartType extends AbstractType
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver)
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'data_class' => Part::class 'data_class' => Part::class,
]); ]);
} }
} }

View file

@ -6,7 +6,6 @@ use App\Entity\User;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType; use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\LanguageType;
use Symfony\Component\Form\Extension\Core\Type\LocaleType; use Symfony\Component\Form\Extension\Core\Type\LocaleType;
use Symfony\Component\Form\Extension\Core\Type\ResetType; use Symfony\Component\Form\Extension\Core\Type\ResetType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
@ -25,37 +24,34 @@ class UserSettingsType extends AbstractType
$this->security = $security; $this->security = $security;
} }
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$builder $builder
->add('name', TextType::class, ['label' => 'user.username.label', ->add('name', TextType::class, ['label' => 'user.username.label',
'disabled' => !$this->security->isGranted('edit_username', $options['data'])]) 'disabled' => !$this->security->isGranted('edit_username', $options['data']), ])
->add('first_name', TextType::class, ['required' => false, ->add('first_name', TextType::class, ['required' => false,
'label' => 'user.firstName.label', 'label' => 'user.firstName.label',
'disabled' => !$this->security->isGranted('edit_infos', $options['data'])]) 'disabled' => !$this->security->isGranted('edit_infos', $options['data']), ])
->add('last_name', TextType::class, ['required' => false, ->add('last_name', TextType::class, ['required' => false,
'label' => 'user.lastName.label', 'label' => 'user.lastName.label',
'disabled' => !$this->security->isGranted('edit_infos', $options['data'])]) 'disabled' => !$this->security->isGranted('edit_infos', $options['data']), ])
->add('department', TextType::class, ['required' => false, ->add('department', TextType::class, ['required' => false,
'label' => 'user.department.label', 'label' => 'user.department.label',
'disabled' => !$this->security->isGranted('edit_infos', $options['data'])]) 'disabled' => !$this->security->isGranted('edit_infos', $options['data']), ])
->add('email', EmailType::class, ['required' => false, ->add('email', EmailType::class, ['required' => false,
'label' => 'user.email.label', 'label' => 'user.email.label',
'disabled' => !$this->security->isGranted('edit_infos', $options['data'])]) 'disabled' => !$this->security->isGranted('edit_infos', $options['data']), ])
->add('language', LocaleType::class, ['required' => false, ->add('language', LocaleType::class, ['required' => false,
'attr'=>['class'=> 'selectpicker', 'data-live-search' => true] 'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'placeholder' => 'user_settings.language.placeholder', 'label' => 'user.language_select', ])
, 'placeholder' => 'user_settings.language.placeholder', 'label'=>'user.language_select'])
->add('timezone', TimezoneType::class, ['required' => false, ->add('timezone', TimezoneType::class, ['required' => false,
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'attr' => ['class' => 'selectpicker', 'data-live-search' => true],
'placeholder' => 'user_settings.timezone.placeholder', 'label'=>'user.timezone.label']) 'placeholder' => 'user_settings.timezone.placeholder', 'label' => 'user.timezone.label', ])
->add('theme', ChoiceType::class, ['required' => false, ->add('theme', ChoiceType::class, ['required' => false,
'placeholder' => 'user_settings.theme.placeholder', 'label'=>'user.theme.label']) 'placeholder' => 'user_settings.theme.placeholder', 'label' => 'user.theme.label', ])
//Buttons //Buttons
->add('save', SubmitType::class, ['label' => 'save']) ->add('save', SubmitType::class, ['label' => 'save'])
->add('reset', ResetType::class, ['label' => 'reset']); ->add('reset', ResetType::class, ['label' => 'reset']);
;
} }
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver)

View file

@ -1,9 +1,8 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,7 +25,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\Security\Annotations; namespace App\Security\Annotations;
@ -40,22 +38,20 @@ use Doctrine\Common\Annotations\Annotation;
* *
* With these annotation you can restrict the access to certain coloumns in entities. * With these annotation you can restrict the access to certain coloumns in entities.
* The entity which should use this class has to use ElementListener as EntityListener. * The entity which should use this class has to use ElementListener as EntityListener.
*
* @package App\Annotations
*/ */
class ColumnSecurity class ColumnSecurity
{ {
/** /**
* @var string The name of the edit permission * @var string The name of the edit permission
*/ */
public $edit = "edit"; public $edit = 'edit';
/** /**
* @var string The name of the read permission * @var string The name of the read permission
*/ */
public $read = "read"; public $read = 'read';
/** /**
* @var string A prefix for all permission names (e.g. $prefix.edit, useful for Parts) * @var string A prefix for all permission names (e.g..edit, useful for Parts)
*/ */
public $prefix = ''; public $prefix = '';
@ -74,15 +70,16 @@ class ColumnSecurity
public function getReadOperationName(): string public function getReadOperationName(): string
{ {
if($this->prefix !== '') { if ('' !== $this->prefix) {
return $this->prefix.'.'.$this->read; return $this->prefix.'.'.$this->read;
} }
return $this->read; return $this->read;
} }
public function getEditOperationName(): string public function getEditOperationName(): string
{ {
if($this->prefix !== '') { if ('' !== $this->prefix) {
return $this->prefix.'.'.$this->edit; return $this->prefix.'.'.$this->edit;
} }
@ -91,10 +88,8 @@ class ColumnSecurity
public function getPlaceholder() public function getPlaceholder()
{ {
if($this->placeholder === null) if (null === $this->placeholder) {
{ switch ($this->type) {
switch($this->type)
{
case 'integer': case 'integer':
return 0; return 0;
case 'string': case 'string':
@ -105,11 +100,11 @@ class ColumnSecurity
return false; return false;
case 'datetime': case 'datetime':
$date = new \DateTime(); $date = new \DateTime();
return $date->setTimestamp(0); return $date->setTimestamp(0);
} }
} }
return $this->placeholder; return $this->placeholder;
} }
} }

View file

@ -1,9 +1,8 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,12 +25,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\Security\EntityListeners; namespace App\Security\EntityListeners;
use App\Security\Annotations\ColumnSecurity; use App\Security\Annotations\ColumnSecurity;
use App\Entity\DBElement; use App\Entity\DBElement;
use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\AnnotationReader;
@ -48,7 +45,6 @@ use Symfony\Component\Security\Core\Security;
* *
* If a user does not have access to an coloumn, it will be filled, with a placeholder, after doctrine loading is finished. * If a user does not have access to an coloumn, it will be filled, with a placeholder, after doctrine loading is finished.
* The edit process is also catched, so that these placeholders, does not get saved to database. * The edit process is also catched, so that these placeholders, does not get saved to database.
* @package App\EntityListeners
*/ */
class ElementPermissionListener class ElementPermissionListener
{ {
@ -59,14 +55,12 @@ class ElementPermissionListener
$this->security = $security; $this->security = $security;
} }
/** /**
* @PostLoad * @PostLoad
* *
* This function is called after doctrine filled, the entity properties with db values. * This function is called after doctrine filled, the entity properties with db values.
* We use this, to check if the user is allowed to access these properties, and if not, we write a placeholder * We use this, to check if the user is allowed to access these properties, and if not, we write a placeholder
* into the element properties, so that a user only gets non sensitve data. * into the element properties, so that a user only gets non sensitve data.
*
*/ */
public function postLoadHandler(DBElement $element, LifecycleEventArgs $event) public function postLoadHandler(DBElement $element, LifecycleEventArgs $event)
{ {
@ -75,19 +69,16 @@ class ElementPermissionListener
$properties = $reflectionClass->getProperties(); $properties = $reflectionClass->getProperties();
$reader = new AnnotationReader(); $reader = new AnnotationReader();
foreach($properties as $property) foreach ($properties as $property) {
{
/** /**
* @var ColumnSecurity $annotation * @var ColumnSecurity
*/ */
$annotation = $reader->getPropertyAnnotation($property, $annotation = $reader->getPropertyAnnotation($property,
ColumnSecurity::class); ColumnSecurity::class);
if($annotation !== null) if (null !== $annotation) {
{
//Check if user is allowed to read info, otherwise apply placeholder //Check if user is allowed to read info, otherwise apply placeholder
if(!$this->security->isGranted($annotation->getReadOperationName(), $element)) if (!$this->security->isGranted($annotation->getReadOperationName(), $element)) {
{
$property->setAccessible(true); $property->setAccessible(true);
$property->setValue($element, $annotation->getPlaceholder()); $property->setValue($element, $annotation->getPlaceholder());
} }
@ -106,28 +97,23 @@ class ElementPermissionListener
$properties = $reflectionClass->getProperties(); $properties = $reflectionClass->getProperties();
$reader = new AnnotationReader(); $reader = new AnnotationReader();
foreach($properties as $property) foreach ($properties as $property) {
{
/** /**
* @var ColumnSecurity $annotation * @var ColumnSecurity
*/ */
$annotation = $reader->getPropertyAnnotation($property, $annotation = $reader->getPropertyAnnotation($property,
ColumnSecurity::class); ColumnSecurity::class);
if($annotation !== null) if (null !== $annotation) {
{
$field_name = $property->getName(); $field_name = $property->getName();
//Check if user is allowed to edit info, otherwise overwrite the new value //Check if user is allowed to edit info, otherwise overwrite the new value
// so that nothing is changed in the DB. // so that nothing is changed in the DB.
if ($event->hasChangedField($field_name) && if ($event->hasChangedField($field_name) &&
!$this->security->isGranted($annotation->getEditOperationName(), $element)) !$this->security->isGranted($annotation->getEditOperationName(), $element)) {
{
$event->setNewValue($field_name, $event->getOldValue($field_name)); $event->setNewValue($field_name, $event->getOldValue($field_name));
} }
} }
} }
} }
} }

View file

@ -1,9 +1,8 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,12 +25,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\Security\Interfaces; namespace App\Security\Interfaces;
use App\Entity\PermissionsEmbed; use App\Entity\PermissionsEmbed;
interface HasPermissionsInterface interface HasPermissionsInterface

View file

@ -1,9 +1,8 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,12 +25,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\Security\Voter; namespace App\Security\Voter;
use App\Entity\User; use App\Entity\User;
use App\Services\PermissionResolver; use App\Services\PermissionResolver;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
@ -40,7 +37,6 @@ use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/** /**
* The purpose of this class is, to use the anonymous user from DB in the case, that nobody is logged in. * The purpose of this class is, to use the anonymous user from DB in the case, that nobody is logged in.
* @package App\Security\Voter
*/ */
abstract class ExtendedVoter extends Voter abstract class ExtendedVoter extends Voter
{ {
@ -63,7 +59,7 @@ abstract class ExtendedVoter extends Voter
// if the user is anonymous, we use the anonymous user. // if the user is anonymous, we use the anonymous user.
if (!$user instanceof User) { if (!$user instanceof User) {
$user = $this->entityManager->find(User::class, User::ID_ANONYMOUS); $user = $this->entityManager->find(User::class, User::ID_ANONYMOUS);
if($user === null) { if (null === $user) {
return false; return false;
} }
} }
@ -74,9 +70,11 @@ abstract class ExtendedVoter extends Voter
/** /**
* Similar to voteOnAttribute, but checking for the anonymous user is already done. * Similar to voteOnAttribute, but checking for the anonymous user is already done.
* The current user (or the anonymous user) is passed by $user. * The current user (or the anonymous user) is passed by $user.
*
* @param $attribute * @param $attribute
* @param $subject * @param $subject
* @param User $user * @param User $user
*
* @return bool * @return bool
*/ */
abstract protected function voteOnUser($attribute, $subject, User $user): bool; abstract protected function voteOnUser($attribute, $subject, User $user): bool;

View file

@ -2,26 +2,18 @@
namespace App\Security\Voter; namespace App\Security\Voter;
use App\Configuration\PermissionsConfiguration;
use App\Entity\Part; use App\Entity\Part;
use App\Entity\User; use App\Entity\User;
use App\Services\PermissionResolver;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter; use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
/** /**
* A Voter that votes on Part entities. * A Voter that votes on Part entities.
* *
* See parts permissions for valid operations. * See parts permissions for valid operations.
*
* @package App\Security\Voter
*/ */
class PartVoter extends ExtendedVoter class PartVoter extends ExtendedVoter
{ {
const READ = "read"; const READ = 'read';
protected function supports($attribute, $subject) protected function supports($attribute, $subject)
{ {
@ -29,30 +21,27 @@ class PartVoter extends ExtendedVoter
// https://symfony.com/doc/current/security/voters.html // https://symfony.com/doc/current/security/voters.html
//return ($subject instanceof Part || in_array($subject, ['PERM_parts', 'PERM_parts_name'])); //return ($subject instanceof Part || in_array($subject, ['PERM_parts', 'PERM_parts_name']));
if ($subject instanceof Part) if ($subject instanceof Part) {
{
//Check if a sub permission should be checked -> $attribute has format name.edit //Check if a sub permission should be checked -> $attribute has format name.edit
if(strpos($attribute, '.') !== false) { if (false !== strpos($attribute, '.')) {
[$perm, $op] = explode('.', $attribute); [$perm, $op] = explode('.', $attribute);
return in_array($op, $this->resolver->listOperationsForPermission('parts_'.$perm), false); return in_array($op, $this->resolver->listOperationsForPermission('parts_'.$perm), false);
} }
return in_array($attribute, $this->resolver->listOperationsForPermission('parts'), false); return in_array($attribute, $this->resolver->listOperationsForPermission('parts'), false);
} }
return false; return false;
} }
protected function voteOnUser($attribute, $subject, User $user): bool protected function voteOnUser($attribute, $subject, User $user): bool
{ {
if ($subject instanceof Part) { if ($subject instanceof Part) {
//Check for sub permissions //Check for sub permissions
if(strpos($attribute, '.') !== false) { if (false !== strpos($attribute, '.')) {
[$perm, $op] = explode('.', $attribute); [$perm, $op] = explode('.', $attribute);
return $this->resolver->inherit($user, 'parts_'.$perm, $op) ?? false; return $this->resolver->inherit($user, 'parts_'.$perm, $op) ?? false;
} }

View file

@ -1,9 +1,8 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,17 +25,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\Security\Voter; namespace App\Security\Voter;
use App\Entity\User; use App\Entity\User;
class UserVoter extends ExtendedVoter class UserVoter extends ExtendedVoter
{ {
/** /**
* Determines if the attribute and subject are supported by this voter. * Determines if the attribute and subject are supported by this voter.
* *
@ -47,8 +43,7 @@ class UserVoter extends ExtendedVoter
*/ */
protected function supports($attribute, $subject) protected function supports($attribute, $subject)
{ {
if($subject instanceof User) if ($subject instanceof User) {
{
return in_array($attribute, array_merge( return in_array($attribute, array_merge(
$this->resolver->listOperationsForPermission('users'), $this->resolver->listOperationsForPermission('users'),
$this->resolver->listOperationsForPermission('self')), $this->resolver->listOperationsForPermission('self')),
@ -62,30 +57,30 @@ class UserVoter extends ExtendedVoter
/** /**
* Similar to voteOnAttribute, but checking for the anonymous user is already done. * Similar to voteOnAttribute, but checking for the anonymous user is already done.
* The current user (or the anonymous user) is passed by $user. * The current user (or the anonymous user) is passed by $user.
*
* @param $attribute * @param $attribute
* @param $subject * @param $subject
* @param User $user * @param User $user
*
* @return bool * @return bool
*/ */
protected function voteOnUser($attribute, $subject, User $user): bool protected function voteOnUser($attribute, $subject, User $user): bool
{ {
if($subject instanceof User) if ($subject instanceof User) {
{
//Check if the checked user is the user itself //Check if the checked user is the user itself
if ($subject->getID() === $user->getID() && if ($subject->getID() === $user->getID() &&
$this->resolver->isValidOperation('self', $attribute)) { $this->resolver->isValidOperation('self', $attribute)) {
//Then we also need to check the self permission //Then we also need to check the self permission
$tmp = $this->resolver->inherit($user, 'self', $attribute) ?? false; $tmp = $this->resolver->inherit($user, 'self', $attribute) ?? false;
//But if the self value is not allowed then use just the user value: //But if the self value is not allowed then use just the user value:
if($tmp) if ($tmp) {
return $tmp; return $tmp;
} }
}
//Else just check users permission: //Else just check users permission:
return $this->resolver->inherit($user, 'users', $attribute) ?? false; return $this->resolver->inherit($user, 'users', $attribute) ?? false;
} }
return false; return false;
} }
} }

View file

@ -1,9 +1,8 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,12 +25,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\Services; namespace App\Services;
use Symfony\Component\Asset\Packages; use Symfony\Component\Asset\Packages;
class AttachmentFilenameService class AttachmentFilenameService
@ -46,10 +43,10 @@ class AttachmentFilenameService
public function attachmentPathToAbsolutePath(?string $filename): ?string public function attachmentPathToAbsolutePath(?string $filename): ?string
{ {
//Return placeholder if a part does not have an attachment //Return placeholder if a part does not have an attachment
if ($filename == null) { if (null == $filename) {
return $this->package->getUrl('/img/part_placeholder.svg'); return $this->package->getUrl('/img/part_placeholder.svg');
} }
if (stripos($filename, "%BASE%/img/") !== false) { if (false !== stripos($filename, '%BASE%/img/')) {
return $this->package->getUrl(str_replace('%BASE%', '', $filename)); return $this->package->getUrl(str_replace('%BASE%', '', $filename));
} }

View file

@ -1,9 +1,8 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,17 +25,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\Services; namespace App\Services;
use App\Entity\DBElement;
use App\Entity\NamedDBElement; use App\Entity\NamedDBElement;
use App\Entity\Part; use App\Entity\Part;
use App\Exceptions\EntityNotSupported; use App\Exceptions\EntityNotSupported;
use Doctrine\Migrations\Finder\Exception\NameIsReserved;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class EntityURLGenerator class EntityURLGenerator
@ -53,15 +48,16 @@ class EntityURLGenerator
/** /**
* Generates an URL to a page, where info about this entity can be viewed. * Generates an URL to a page, where info about this entity can be viewed.
*
* @param $entity mixed The entity for which the info should be generated. * @param $entity mixed The entity for which the info should be generated.
*
* @return string The URL to the info page * @return string The URL to the info page
* *
* @throws EntityNotSupported If the method is not supported for the given Entity * @throws EntityNotSupported If the method is not supported for the given Entity
*/ */
public function infoURL($entity): string public function infoURL($entity): string
{ {
if($entity instanceof Part) if ($entity instanceof Part) {
{
return $this->urlGenerator->generate('part_info', ['id' => $entity->getID()]); return $this->urlGenerator->generate('part_info', ['id' => $entity->getID()]);
} }
@ -71,8 +67,7 @@ class EntityURLGenerator
public function editURL($entity): string public function editURL($entity): string
{ {
if($entity instanceof Part) if ($entity instanceof Part) {
{
return $this->urlGenerator->generate('part_edit', ['id' => $entity->getID()]); return $this->urlGenerator->generate('part_edit', ['id' => $entity->getID()]);
} }
@ -82,8 +77,7 @@ class EntityURLGenerator
public function createURL($entity): string public function createURL($entity): string
{ {
if($entity instanceof Part) if ($entity instanceof Part) {
{
return $this->urlGenerator->generate('part_new'); return $this->urlGenerator->generate('part_new');
} }
@ -92,8 +86,7 @@ class EntityURLGenerator
public function cloneURL($entity): string public function cloneURL($entity): string
{ {
if($entity instanceof Part) if ($entity instanceof Part) {
{
return $this->urlGenerator->generate('part_clone', ['id' => $entity->getID()]); return $this->urlGenerator->generate('part_clone', ['id' => $entity->getID()]);
} }
@ -102,7 +95,9 @@ class EntityURLGenerator
/** /**
* Generates an HTML link to the info page about the given entity. * Generates an HTML link to the info page about the given entity.
*
* @param $entity mixed The entity for which the info link should be generated. * @param $entity mixed The entity for which the info link should be generated.
*
* @return string The HTML of the info page link * @return string The HTML of the info page link
* *
* @throws EntityNotSupported * @throws EntityNotSupported
@ -111,11 +106,8 @@ class EntityURLGenerator
{ {
$href = $this->infoURL($entity); $href = $this->infoURL($entity);
if($entity instanceof NamedDBElement) if ($entity instanceof NamedDBElement) {
{
return sprintf('<a href="%s">%s</a>', $href, $entity->getName()); return sprintf('<a href="%s">%s</a>', $href, $entity->getName());
} }
} }
} }

View file

@ -1,9 +1,8 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,12 +25,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\Services; namespace App\Services;
use App\Configuration\PermissionsConfiguration; use App\Configuration\PermissionsConfiguration;
use App\Entity\User; use App\Entity\User;
use App\Security\Interfaces\HasPermissionsInterface; use App\Security\Interfaces\HasPermissionsInterface;
@ -43,10 +40,9 @@ class PermissionResolver
{ {
protected $permission_structure; protected $permission_structure;
/** /**
*
* PermissionResolver constructor. * PermissionResolver constructor.
*
* @param ParameterBagInterface $params * @param ParameterBagInterface $params
*/ */
public function __construct(ParameterBagInterface $params) public function __construct(ParameterBagInterface $params)
@ -56,7 +52,6 @@ class PermissionResolver
file_get_contents(__DIR__.'/../../config/permissions.yaml') file_get_contents(__DIR__.'/../../config/permissions.yaml')
); );
$configs = [$config]; $configs = [$config];
//... And parse it //... And parse it
@ -72,7 +67,6 @@ class PermissionResolver
//dump($this->permission_structure); //dump($this->permission_structure);
} }
/** /**
* Check if a user/group is allowed to do the specified operation for the permission. * Check if a user/group is allowed to do the specified operation for the permission.
* *
@ -81,6 +75,7 @@ class PermissionResolver
* @param HasPermissionsInterface $user The user/group for which the operation should be checked. * @param HasPermissionsInterface $user The user/group for which the operation should be checked.
* @param string $permission The name of the permission for which should be checked. * @param string $permission The name of the permission for which should be checked.
* @param string $operation The name of the operation for which should be checked. * @param string $operation The name of the operation for which should be checked.
*
* @return bool|null True, if the user is allowed to do the operation (ALLOW), false if not (DISALLOW), and null, * @return bool|null True, if the user is allowed to do the operation (ALLOW), false if not (DISALLOW), and null,
* if the value is set to inherit. * if the value is set to inherit.
*/ */
@ -95,7 +90,6 @@ class PermissionResolver
return $perm_list->getPermissionValue($permission, $bit); return $perm_list->getPermissionValue($permission, $bit);
} }
/** /**
* Checks if a user is allowed to do the specified operation for the permission. * Checks if a user is allowed to do the specified operation for the permission.
* In contrast to dontInherit() it tries to resolve the inherit values, of the user, by going upwards in the * In contrast to dontInherit() it tries to resolve the inherit values, of the user, by going upwards in the
@ -107,6 +101,7 @@ class PermissionResolver
* @param User $user The user for which the operation should be checked. * @param User $user The user for which the operation should be checked.
* @param string $permission The name of the permission for which should be checked. * @param string $permission The name of the permission for which should be checked.
* @param string $operation The name of the operation for which should be checked. * @param string $operation The name of the operation for which should be checked.
*
* @return bool|null True, if the user is allowed to do the operation (ALLOW), false if not (DISALLOW), and null, * @return bool|null True, if the user is allowed to do the operation (ALLOW), false if not (DISALLOW), and null,
* if the value is set to inherit. * if the value is set to inherit.
*/ */
@ -115,16 +110,16 @@ class PermissionResolver
//Check if we need to inherit //Check if we need to inherit
$allowed = $this->dontInherit($user, $permission, $operation); $allowed = $this->dontInherit($user, $permission, $operation);
if ($allowed !== null) { if (null !== $allowed) {
//Just return the value of the user. //Just return the value of the user.
return $allowed; return $allowed;
} }
$parent = $user->getGroup(); $parent = $user->getGroup();
while($parent != null){ //The top group, has parent == null while (null != $parent) { //The top group, has parent == null
//Check if our current element gives a info about disallow/allow //Check if our current element gives a info about disallow/allow
$allowed = $this->dontInherit($parent, $permission, $operation); $allowed = $this->dontInherit($parent, $permission, $operation);
if ($allowed !== null) { if (null !== $allowed) {
return $allowed; return $allowed;
} }
//Else go up in the hierachy. //Else go up in the hierachy.
@ -134,7 +129,6 @@ class PermissionResolver
return null; //The inherited value is never resolved. Should be treat as false, in Voters. return null; //The inherited value is never resolved. Should be treat as false, in Voters.
} }
/** /**
* Lists the names of all operations that is supported for the given permission. * Lists the names of all operations that is supported for the given permission.
* *
@ -143,6 +137,7 @@ class PermissionResolver
* This function is useful for the support() function of the voters. * This function is useful for the support() function of the voters.
* *
* @param string $permission The permission for which the * @param string $permission The permission for which the
*
* @return string[] A list of all operations that are supported by the given * @return string[] A list of all operations that are supported by the given
*/ */
public function listOperationsForPermission(string $permission): array public function listOperationsForPermission(string $permission): array
@ -156,6 +151,7 @@ class PermissionResolver
* Checks if the permission with the given name is existing. * Checks if the permission with the given name is existing.
* *
* @param string $permission The name of the permission which we want to check. * @param string $permission The name of the permission which we want to check.
*
* @return bool True if a perm with that name is existing. False if not. * @return bool True if a perm with that name is existing. False if not.
*/ */
public function isValidPermission(string $permission): bool public function isValidPermission(string $permission): bool
@ -168,6 +164,7 @@ class PermissionResolver
* *
* @param string $permission The name of the permission which should be checked. * @param string $permission The name of the permission which should be checked.
* @param string $operation The name of the operation which should be checked. * @param string $operation The name of the operation which should be checked.
*
* @return bool True if the given permission operation combination is existing. * @return bool True if the given permission operation combination is existing.
*/ */
public function isValidOperation(string $permission, string $operation): bool public function isValidOperation(string $permission, string $operation): bool
@ -175,6 +172,4 @@ class PermissionResolver
return $this->isValidPermission($permission) && return $this->isValidPermission($permission) &&
isset($this->permission_structure['perms'][$permission]['operations'][$operation]); isset($this->permission_structure['perms'][$permission]['operations'][$operation]);
} }
} }

View file

@ -1,9 +1,8 @@
<?php <?php
/** /**
*
* part-db version 0.1 * part-db version 0.1
* Copyright (C) 2005 Christoph Lechner * Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/ * http://www.cl-projects.de/.
* *
* part-db version 0.2+ * part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php) * Copyright (C) 2009 K. Jacobs and others (see authors.php)
@ -26,18 +25,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\Twig; namespace App\Twig;
use App\Entity\DBElement; use App\Entity\DBElement;
use App\Services\EntityURLGenerator; use App\Services\EntityURLGenerator;
use Symfony\Component\Cache\Adapter\AdapterInterface; use Symfony\Component\Cache\Adapter\AdapterInterface;
use Twig\Extension\AbstractExtension; use Twig\Extension\AbstractExtension;
use Twig\TwigFilter; use Twig\TwigFilter;
use s9e\TextFormatter\Bundles\Forum as TextFormatter; use s9e\TextFormatter\Bundles\Forum as TextFormatter;
class AppExtension extends AbstractExtension class AppExtension extends AbstractExtension
@ -55,7 +51,7 @@ class AppExtension extends AbstractExtension
{ {
return [ return [
new TwigFilter('entityURL', [$this, 'generateEntityURL']), new TwigFilter('entityURL', [$this, 'generateEntityURL']),
new TwigFilter('bbCode', [$this, 'parseBBCode'], ['pre_escape' => 'html', 'is_safe' => ['html']]) new TwigFilter('bbCode', [$this, 'parseBBCode'], ['pre_escape' => 'html', 'is_safe' => ['html']]),
]; ];
} }
@ -77,7 +73,9 @@ class AppExtension extends AbstractExtension
public function parseBBCode(string $bbcode): string public function parseBBCode(string $bbcode): string
{ {
if($bbcode === '') return ''; if ('' === $bbcode) {
return '';
}
$item = $this->cache->getItem('bbcode_'.md5($bbcode)); $item = $this->cache->getItem('bbcode_'.md5($bbcode));
if (!$item->isHit()) { if (!$item->isHit()) {
@ -88,5 +86,4 @@ class AppExtension extends AbstractExtension
return $item->get(); return $item->get();
} }
} }