mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Used PHP_CS_Fixer with symfony preset on codebase.
This commit is contained in:
parent
0f3ba9b6a8
commit
e2f7aafa2d
43 changed files with 971 additions and 1068 deletions
|
@ -7,7 +7,6 @@ use Doctrine\ORM\EntityManagerInterface;
|
|||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||
|
@ -24,11 +23,9 @@ class SetPasswordCommand extends Command
|
|||
$this->entityManager = $entityManager;
|
||||
$this->encoder = $passwordEncoder;
|
||||
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
|
@ -44,15 +41,14 @@ class SetPasswordCommand extends Command
|
|||
$user_name = $input->getArgument('user');
|
||||
|
||||
/**
|
||||
* @var User $user
|
||||
* @var User
|
||||
*/
|
||||
$users = $this->entityManager->getRepository(User::class)->findBy(['name' => $user_name]);
|
||||
$user = $users[0];
|
||||
|
||||
|
||||
if($user == null)
|
||||
{
|
||||
if (null == $user) {
|
||||
$io->error(sprintf('No user with the given username %s found in the database!', $user_name));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -62,18 +58,17 @@ class SetPasswordCommand extends Command
|
|||
sprintf('You are going to change the password of %s with ID %d. Proceed?',
|
||||
$user->getFullName(true), $user->getID()));
|
||||
|
||||
if(!$proceed)
|
||||
{
|
||||
if (!$proceed) {
|
||||
return;
|
||||
}
|
||||
|
||||
$success = false;
|
||||
$new_password = "";
|
||||
$new_password = '';
|
||||
|
||||
while(!$success) {
|
||||
$pw1 = $io->askHidden("Please enter new password:");
|
||||
while (!$success) {
|
||||
$pw1 = $io->askHidden('Please enter new password:');
|
||||
$pw2 = $io->askHidden('Please confirm:');
|
||||
if($pw1 !== $pw2) {
|
||||
if ($pw1 !== $pw2) {
|
||||
$io->error('The entered password did not match! Please try again.');
|
||||
} else {
|
||||
//Exit loop
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Configuration;
|
||||
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
||||
class PermissionsConfiguration implements ConfigurationInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Generates the configuration tree builder.
|
||||
*
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Controller;
|
||||
|
@ -35,8 +33,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
* Class DebugController
|
||||
* @package App\Controller
|
||||
* Class DebugController.
|
||||
*/
|
||||
class DebugController extends AbstractController
|
||||
{
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
<?php
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
|
@ -46,7 +42,7 @@ class HomepageController extends AbstractController
|
|||
{
|
||||
return $this->render('homepage.html.twig',
|
||||
[
|
||||
'banner' => $this->getParameter('banner')
|
||||
'banner' => $this->getParameter('banner'),
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -1,10 +1,9 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
|
||||
use App\Entity\Category;
|
||||
use App\Entity\Part;
|
||||
use App\Form\PartType;
|
||||
|
@ -45,7 +42,6 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||
|
||||
class PartController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
* @Route("/part/{id}/info", name="part_info")
|
||||
* @Route("/part/{id}", requirements={"id"="\d+"})
|
||||
|
@ -59,7 +55,7 @@ class PartController extends AbstractController
|
|||
return $this->render('Parts/show_part_info.html.twig',
|
||||
[
|
||||
'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")
|
||||
*
|
||||
* @param Part $part
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function edit(Part $part, Request $request, EntityManagerInterface $em)
|
||||
|
@ -114,24 +111,22 @@ class PartController extends AbstractController
|
|||
$em->persist($new_part);
|
||||
$em->flush();
|
||||
$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',
|
||||
[
|
||||
'part' => $new_part,
|
||||
'form' => $form->createView()
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/part/{id}/clone", name="part_clone")
|
||||
*
|
||||
*/
|
||||
public function clone(Part $part, Request $request, EntityManagerInterface $em, TranslatorInterface $translator)
|
||||
{
|
||||
|
||||
/** @var Part $new_part */
|
||||
$new_part = clone $part;
|
||||
|
||||
|
@ -145,15 +140,14 @@ class PartController extends AbstractController
|
|||
$em->persist($new_part);
|
||||
$em->flush();
|
||||
$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',
|
||||
[
|
||||
'part' => $new_part,
|
||||
'form' => $form->createView()
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
|
||||
use App\DataTables\PartsDataTable;
|
||||
use Omines\DataTablesBundle\DataTableFactory;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
@ -42,11 +39,13 @@ class PartListsController extends AbstractController
|
|||
{
|
||||
/**
|
||||
* @Route("/category/{id}/parts")
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
|
||||
/*$table = $dataTable->create()
|
||||
->add("id", TextColumn::class)
|
||||
->add("name", TextColumn::class)
|
||||
|
@ -60,7 +59,6 @@ class PartListsController extends AbstractController
|
|||
$table = $dataTable->createFromType(PartsDataTable::class, ['cid' => $id])
|
||||
->handleRequest($request);
|
||||
|
||||
|
||||
if ($table->isCallback()) {
|
||||
return $table->getResponse();
|
||||
}
|
||||
|
@ -73,6 +71,7 @@ class PartListsController extends AbstractController
|
|||
*
|
||||
* @param Request $request
|
||||
* @param DataTableFactory $dataTable
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function showAll(Request $request, DataTableFactory $dataTable)
|
||||
|
@ -80,13 +79,10 @@ class PartListsController extends AbstractController
|
|||
$table = $dataTable->createFromType(PartsDataTable::class)
|
||||
->handleRequest($request);
|
||||
|
||||
|
||||
if ($table->isCallback()) {
|
||||
return $table->getResponse();
|
||||
}
|
||||
|
||||
return $this->render('parts_list.html.twig', ['datatable' => $table]);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
|
@ -62,5 +59,4 @@ class SecurityController extends AbstractController
|
|||
{
|
||||
throw new \Exception('Will be intercepted before getting here');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Form\UserSettingsType;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
@ -48,7 +45,6 @@ use Symfony\Component\Validator\Constraints\Length;
|
|||
|
||||
class UserController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
* @Route("/user/info", name="user_info_self")
|
||||
* @Route("/user/{id}/info")
|
||||
|
@ -56,23 +52,22 @@ class UserController extends AbstractController
|
|||
public function userInfo(?User $user, Packages $packages)
|
||||
{
|
||||
//If no user id was passed, then we show info about the current user
|
||||
if($user === null) {
|
||||
if (null === $user) {
|
||||
$user = $this->getUser();
|
||||
} else {
|
||||
//Else we must check, if the current user is allowed to access $user
|
||||
$this->denyAccessUnlessGranted('read', $user);
|
||||
}
|
||||
|
||||
if($this->getParameter('use_gravatar')) {
|
||||
if ($this->getParameter('use_gravatar')) {
|
||||
$avatar = $this->getGravatar($user->getEmail(), 200, 'identicon');
|
||||
} else {
|
||||
$avatar = $packages->getUrl('/img/default_avatar.png');
|
||||
}
|
||||
|
||||
|
||||
return $this->render('Users/user_info.html.twig', [
|
||||
'user' => $user,
|
||||
'avatar' => $avatar
|
||||
'avatar' => $avatar,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -110,16 +105,16 @@ class UserController extends AbstractController
|
|||
$pw_form = $this->createFormBuilder()
|
||||
->add('old_password', PasswordType::class, [
|
||||
'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, [
|
||||
'type' => PasswordType::class,
|
||||
'first_options' => ['label'=> 'user.settings.pw_new.label'],
|
||||
'second_options' => ['label'=> 'user.settings.pw_confirm.label'],
|
||||
'first_options' => ['label' => 'user.settings.pw_new.label'],
|
||||
'second_options' => ['label' => 'user.settings.pw_confirm.label'],
|
||||
'invalid_message' => 'password_must_match',
|
||||
'constraints' => [new Length([
|
||||
'min' => 6,
|
||||
'max' => 128
|
||||
])]
|
||||
'max' => 128,
|
||||
])],
|
||||
])
|
||||
->add('submit', SubmitType::class, ['label' => 'save'])
|
||||
->getForm();
|
||||
|
@ -127,7 +122,7 @@ class UserController extends AbstractController
|
|||
$pw_form->handleRequest($request);
|
||||
|
||||
//Check if password if everything was correct, then save it to User and DB
|
||||
if($pw_form->isSubmitted() && $pw_form->isValid()) {
|
||||
if ($pw_form->isSubmitted() && $pw_form->isValid()) {
|
||||
$password = $passwordEncoder->encodePassword($user, $pw_form['new_password']->getData());
|
||||
$user->setPassword($password);
|
||||
$em->persist($user);
|
||||
|
@ -141,11 +136,10 @@ class UserController extends AbstractController
|
|||
|
||||
return $this->render('Users/user_settings.html.twig', [
|
||||
'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.
|
||||
*
|
||||
|
@ -155,7 +149,8 @@ class UserController extends AbstractController
|
|||
* @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 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/
|
||||
*/
|
||||
public function getGravatar(string $email, int $s = 80, string $d = 'mm', string $r = 'g', bool $img = false, array $atts = array())
|
||||
|
@ -164,13 +159,13 @@ class UserController extends AbstractController
|
|||
$url .= md5(strtolower(trim($email)));
|
||||
$url .= "?s=$s&d=$d&r=$r";
|
||||
if ($img) {
|
||||
$url = '<img src="' . $url . '"';
|
||||
$url = '<img src="'.$url.'"';
|
||||
foreach ($atts as $key => $val) {
|
||||
$url .= ' ' . $key . '="' . $val . '"';
|
||||
$url .= ' '.$key.'="'.$val.'"';
|
||||
}
|
||||
$url .= ' />';
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\DataTables;
|
||||
|
||||
|
||||
use App\Entity\Part;
|
||||
use App\Services\EntityURLGenerator;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
|
@ -40,11 +37,9 @@ use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter;
|
|||
use Omines\DataTablesBundle\Column\TextColumn;
|
||||
use Omines\DataTablesBundle\DataTable;
|
||||
use Omines\DataTablesBundle\DataTableTypeInterface;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
class PartsDataTable implements DataTableTypeInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EntityURLGenerator
|
||||
*/
|
||||
|
@ -62,27 +57,27 @@ class PartsDataTable implements DataTableTypeInterface
|
|||
public function configure(DataTable $dataTable, array $options)
|
||||
{
|
||||
$dataTable//->add("id", TextColumn::class)
|
||||
->add("name", TextColumn::class, ['label' => 'name.label',
|
||||
'render' => function($value, Part $context) {
|
||||
->add('name', TextColumn::class, ['label' => 'name.label',
|
||||
'render' => function ($value, Part $context) {
|
||||
return $this->urlGenerator->infoHTML($context);
|
||||
}])
|
||||
->add("description", TextColumn::class, ['label' => 'description.label'])
|
||||
->add("category", TextColumn::class, ['field' => 'category.name', 'label' => 'category.label'])
|
||||
->add("instock", TextColumn::class, ['label' => 'instock.label_short'])
|
||||
->add("mininstock", TextColumn::class, ['label' => 'mininstock.label_short'])
|
||||
->add("storelocation", TextColumn::class, ['field' => 'storelocation.name', 'label' => 'storelocation.label'])
|
||||
}, ])
|
||||
->add('description', TextColumn::class, ['label' => 'description.label'])
|
||||
->add('category', TextColumn::class, ['field' => 'category.name', 'label' => 'category.label'])
|
||||
->add('instock', TextColumn::class, ['label' => 'instock.label_short'])
|
||||
->add('mininstock', TextColumn::class, ['label' => 'mininstock.label_short'])
|
||||
->add('storelocation', TextColumn::class, ['field' => 'storelocation.name', 'label' => 'storelocation.label'])
|
||||
->addOrderBy('name')
|
||||
->createAdapter(ORMAdapter::class, [
|
||||
'entity' => Part::class,
|
||||
'criteria' => [
|
||||
function (QueryBuilder $builder) use($options) {
|
||||
if(isset($options['cid'])) {
|
||||
function (QueryBuilder $builder) use ($options) {
|
||||
if (isset($options['cid'])) {
|
||||
$builder->andWhere('part.category = :cid')
|
||||
->setParameter('cid', $options['cid']);
|
||||
}
|
||||
},
|
||||
new SearchCriteriaProvider()
|
||||
]
|
||||
new SearchCriteriaProvider(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -1,9 +1,10 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*
|
||||
* Part-DB Version 0.4+ "nextgen"
|
||||
* 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
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
@ -27,8 +27,8 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
use Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
|
||||
/**
|
||||
* Class Attachment
|
||||
* @package PartDB\Models
|
||||
* Class Attachment.
|
||||
*
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="attachements")
|
||||
*/
|
||||
|
@ -40,8 +40,6 @@ class Attachment extends NamedDBElement
|
|||
*/
|
||||
protected $show_in_table;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @var string The filename using the %BASE% variable
|
||||
* @ORM\Column(type="string")
|
||||
|
@ -51,7 +49,7 @@ class Attachment extends NamedDBElement
|
|||
/**
|
||||
* //TODO
|
||||
* //@ORM\ManyToOne(targetEntity="AttachmentContainingDBElement", inversedBy="attachment")
|
||||
* //@ORM\JoinColumn(name="element_id", referencedColumnName="id")
|
||||
* //@ORM\JoinColumn(name="element_id", referencedColumnName="id").
|
||||
*/
|
||||
protected $element;
|
||||
|
||||
|
@ -67,12 +65,12 @@ 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
|
||||
*/
|
||||
public function isPicture() : bool
|
||||
public function isPicture(): bool
|
||||
{
|
||||
$extension = pathinfo($this->getFilename(), PATHINFO_EXTENSION);
|
||||
|
||||
|
@ -89,10 +87,11 @@ 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.
|
||||
*/
|
||||
public function getElement() : AttachmentContainingDBElement
|
||||
public function getElement(): AttachmentContainingDBElement
|
||||
{
|
||||
return $this->element;
|
||||
}
|
||||
|
@ -103,53 +102,56 @@ class Attachment extends NamedDBElement
|
|||
*
|
||||
* @return bool True if the file is existing.
|
||||
*/
|
||||
public function isFileExisting() : bool
|
||||
public function isFileExisting(): bool
|
||||
{
|
||||
return file_exists($this->getFilename()) || isURL($this->getFilename());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filename, relative to %BASE%
|
||||
* Get the filename, relative to %BASE%.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFilename() : string
|
||||
public function getFilename(): string
|
||||
{
|
||||
return $this->filename;
|
||||
//return str_replace('%BASE%', BASE, $this->filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* false means, this attachement won't be listed in the "Attachements" column of the HTML tables
|
||||
*/
|
||||
public function getShowInTable() : bool
|
||||
public function getShowInTable(): bool
|
||||
{
|
||||
return (bool) $this->show_in_table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of this attachement
|
||||
* Get the type of this attachement.
|
||||
*
|
||||
* @return AttachmentType the type of this attachement
|
||||
*
|
||||
* @throws Exception if there was an error
|
||||
*/
|
||||
public function getType() : AttachmentType
|
||||
public function getType(): AttachmentType
|
||||
{
|
||||
//TODO
|
||||
|
||||
throw new NotImplementedException("Not implemented yet!");
|
||||
throw new NotImplementedException('Not implemented yet!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
* This should have a form like P000014, for a part with ID 14.
|
||||
*
|
||||
* @return string The ID as a string;
|
||||
*/
|
||||
public function getIDString(): string
|
||||
{
|
||||
return 'A' . sprintf('%09d', $this->getID());
|
||||
return 'A'.sprintf('%09d', $this->getID());
|
||||
}
|
||||
|
||||
/*****************************************************************************************************
|
||||
|
@ -158,11 +160,13 @@ class Attachment extends NamedDBElement
|
|||
|
||||
/**
|
||||
* @param bool $show_in_table
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setShowInTable(bool $show_in_table): self
|
||||
{
|
||||
$this->show_in_table = $show_in_table;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -1,9 +1,10 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*
|
||||
* Part-DB Version 0.4+ "nextgen"
|
||||
* 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
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
@ -47,37 +47,36 @@ 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,
|
||||
* sorted by their names
|
||||
*
|
||||
* @throws Exception if there was an error
|
||||
*/
|
||||
public function getAttachmentTypes() : array
|
||||
public function getAttachmentTypes(): array
|
||||
{
|
||||
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
|
||||
* @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
|
||||
*
|
||||
* @throws Exception if there was an error
|
||||
*/
|
||||
public function getAttachments($type_id = null, bool $only_table_attachements = false) : array
|
||||
public function getAttachments($type_id = null, bool $only_table_attachements = false): array
|
||||
{
|
||||
if ($only_table_attachements || $type_id) {
|
||||
$attachements = $this->attachments;
|
||||
|
||||
foreach ($attachements as $key => $attachement) {
|
||||
if (($only_table_attachements && (! $attachement->getShowInTable()))
|
||||
if (($only_table_attachements && (!$attachement->getShowInTable()))
|
||||
|| ($type_id && ($attachement->getType()->getID() !== $type_id))) {
|
||||
unset($attachements[$key]);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*
|
||||
* Part-DB Version 0.4+ "nextgen"
|
||||
* 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
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
@ -27,8 +27,8 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class AttachmentType
|
||||
* @package PartDB\Models
|
||||
* Class AttachmentType.
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table(name="attachement_types")
|
||||
*/
|
||||
|
@ -40,7 +40,6 @@ class AttachmentType extends StructuralDBElement
|
|||
*/
|
||||
protected $attachments;
|
||||
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="AttachmentType", mappedBy="parent")
|
||||
*/
|
||||
|
@ -53,16 +52,15 @@ class AttachmentType extends StructuralDBElement
|
|||
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
|
||||
* (sorted by their names)
|
||||
*
|
||||
*/
|
||||
public function getAttachementsForType() : ArrayCollection
|
||||
public function getAttachementsForType(): ArrayCollection
|
||||
{
|
||||
// the attribute $this->attachements is used from class "AttachementsContainingDBELement"
|
||||
if ($this->attachments === null) {
|
||||
if (null === $this->attachments) {
|
||||
$this->attachments = new ArrayCollection();
|
||||
}
|
||||
|
||||
|
@ -72,6 +70,7 @@ class AttachmentType extends StructuralDBElement
|
|||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
* This should have a form like P000014, for a part with ID 14.
|
||||
*
|
||||
* @return string The ID as a string;
|
||||
*/
|
||||
public function getIDString(): string
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*
|
||||
* Part-DB Version 0.4+ "nextgen"
|
||||
* 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
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
@ -26,13 +26,13 @@ namespace App\Entity;
|
|||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class AttachmentType
|
||||
* Class AttachmentType.
|
||||
*
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="categories")
|
||||
*/
|
||||
class Category extends PartsContainingDBElement
|
||||
{
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
|
||||
*/
|
||||
|
@ -97,14 +97,14 @@ class Category extends PartsContainingDBElement
|
|||
*/
|
||||
protected $default_comment;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
* This should have a form like P000014, for a part with ID 14.
|
||||
*
|
||||
* @return string The ID as a string;
|
||||
*/
|
||||
public function getIDString(): string
|
||||
{
|
||||
return 'C' . sprintf('%09d', $this->getID());
|
||||
return 'C'.sprintf('%09d', $this->getID());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*
|
||||
* Part-DB Version 0.4+ "nextgen"
|
||||
* 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
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* This abstract class is used for companies like suppliers or manufacturers.
|
||||
*
|
||||
* @ORM\MappedSuperclass()
|
||||
*/
|
||||
abstract class Company extends StructuralDBElement
|
||||
|
@ -68,7 +68,6 @@ abstract class Company extends StructuralDBElement
|
|||
*/
|
||||
protected $auto_product_url;
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Getters
|
||||
|
@ -76,68 +75,69 @@ abstract class Company extends StructuralDBElement
|
|||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Get the address
|
||||
* Get the address.
|
||||
*
|
||||
* @return string the address of the company (with "\n" as line break)
|
||||
*/
|
||||
public function getAddress() : string
|
||||
public function getAddress(): string
|
||||
{
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the phone number
|
||||
* Get the phone number.
|
||||
*
|
||||
* @return string the phone number of the company
|
||||
*/
|
||||
public function getPhoneNumber() : string
|
||||
public function getPhoneNumber(): string
|
||||
{
|
||||
return $this->phone_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fax number
|
||||
* Get the fax number.
|
||||
*
|
||||
* @return string the fax number of the company
|
||||
*/
|
||||
public function getFaxNumber() : string
|
||||
public function getFaxNumber(): string
|
||||
{
|
||||
return $this->fax_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the e-mail address
|
||||
* Get the e-mail address.
|
||||
*
|
||||
* @return string the e-mail address of the company
|
||||
*/
|
||||
public function getEmailAddress() : string
|
||||
public function getEmailAddress(): string
|
||||
{
|
||||
return $this->email_address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the website
|
||||
* Get the website.
|
||||
*
|
||||
* @return string the website of the company
|
||||
*/
|
||||
public function getWebsite() : string
|
||||
public function getWebsite(): string
|
||||
{
|
||||
return $this->website;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* * or the part number for returning the direct URL to the article
|
||||
*
|
||||
* @return string the link to the article
|
||||
*/
|
||||
public function getAutoProductUrl($partnr = null) : string
|
||||
public function getAutoProductUrl($partnr = null): string
|
||||
{
|
||||
if (\is_string($partnr)) {
|
||||
return str_replace('%PARTNUMBER%', $partnr, $this->auto_product_url);
|
||||
}
|
||||
|
||||
return $this->auto_product_url;
|
||||
}
|
||||
|
||||
|
@ -148,81 +148,86 @@ abstract class Company extends StructuralDBElement
|
|||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Set the addres
|
||||
* Set the addres.
|
||||
*
|
||||
* @param string $new_address the new address (with "\n" as line break)
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setAddress(string $new_address) : self
|
||||
public function setAddress(string $new_address): self
|
||||
{
|
||||
$this->address = $new_address;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the phone number
|
||||
* Set the phone number.
|
||||
*
|
||||
* @param string $new_phone_number the new phone number
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setPhoneNumber(string $new_phone_number) : self
|
||||
public function setPhoneNumber(string $new_phone_number): self
|
||||
{
|
||||
$this->phone_number = $new_phone_number;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the fax number
|
||||
* Set the fax number.
|
||||
*
|
||||
* @param string $new_fax_number the new fax number
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setFaxNumber(string $new_fax_number) : self
|
||||
public function setFaxNumber(string $new_fax_number): self
|
||||
{
|
||||
$this->fax_number = $new_fax_number;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the e-mail address
|
||||
* Set the e-mail address.
|
||||
*
|
||||
* @param string $new_email_address the new e-mail address
|
||||
*
|
||||
* @return self
|
||||
|
||||
*/
|
||||
public function setEmailAddress(string $new_email_address) : self
|
||||
public function setEmailAddress(string $new_email_address): self
|
||||
{
|
||||
$this->email_address = $new_email_address;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the website
|
||||
* Set the website.
|
||||
*
|
||||
* @param string $new_website the new website
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setWebsite(string $new_website) : self
|
||||
public function setWebsite(string $new_website): self
|
||||
{
|
||||
$this->website = $new_website;
|
||||
|
||||
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
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setAutoProductUrl(string $new_url) : self
|
||||
public function setAutoProductUrl(string $new_url): self
|
||||
{
|
||||
$this->auto_product_url = $new_url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,10 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*
|
||||
* Part-DB Version 0.4+ "nextgen"
|
||||
* 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
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
@ -39,7 +39,6 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
*/
|
||||
abstract class DBElement
|
||||
{
|
||||
|
||||
/** @var int The Identification number for this part. This value is unique for the element in this table.
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\Id()
|
||||
|
@ -49,27 +48,26 @@ abstract class DBElement
|
|||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
* This should have a form like P000014, for a part with ID 14.
|
||||
*
|
||||
* @return string The ID as a string;
|
||||
*/
|
||||
abstract public function getIDString() : string;
|
||||
abstract public function getIDString(): string;
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
//Set ID to null, so that an new entry is created
|
||||
$this->id = null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
@ -36,13 +35,13 @@ namespace App\Entity;
|
|||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class AttachmentType
|
||||
* Class AttachmentType.
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table(name="devices")
|
||||
*/
|
||||
class Device extends PartsContainingDBElement
|
||||
{
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
|
||||
*/
|
||||
|
@ -57,7 +56,6 @@ class Device extends PartsContainingDBElement
|
|||
/**
|
||||
* @var int
|
||||
* @ORM\Column(type="integer")
|
||||
*
|
||||
*/
|
||||
protected $order_quantity;
|
||||
|
||||
|
@ -79,21 +77,21 @@ 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
|
||||
{
|
||||
return $this->order_quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
return $this->order_only_missing_parts;
|
||||
}
|
||||
|
@ -105,40 +103,44 @@ 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
|
||||
*/
|
||||
public function setOrderQuantity(int $new_order_quantity) : self
|
||||
{
|
||||
if($new_order_quantity < 0)
|
||||
public function setOrderQuantity(int $new_order_quantity): self
|
||||
{
|
||||
if ($new_order_quantity < 0) {
|
||||
throw new \InvalidArgumentException('The new order quantity must not be negative!');
|
||||
}
|
||||
$this->order_quantity = $new_order_quantity;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the "order_only_missing_parts" attribute
|
||||
* @param boolean $new_order_only_missing_parts the new "order_only_missing_parts" attribute
|
||||
* Set the "order_only_missing_parts" attribute.
|
||||
*
|
||||
* @param bool $new_order_only_missing_parts the new "order_only_missing_parts" attribute
|
||||
*
|
||||
* @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;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
* This should have a form like P000014, for a part with ID 14.
|
||||
*
|
||||
* @return string The ID as a string;
|
||||
*/
|
||||
public function getIDString(): string
|
||||
{
|
||||
return 'D' . sprintf('%09d', $this->getID());
|
||||
return 'D'.sprintf('%09d', $this->getID());
|
||||
}
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class DevicePart
|
||||
* @package App\Entity
|
||||
* Class DevicePart.
|
||||
*
|
||||
* @ORM\Table("device_parts")
|
||||
* @ORM\Entity()
|
||||
|
@ -57,10 +55,11 @@ class DevicePart extends DBElement
|
|||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
* This should have a form like P000014, for a part with ID 14.
|
||||
*
|
||||
* @return string The ID as a string;
|
||||
*/
|
||||
public function getIDString(): string
|
||||
{
|
||||
return 'DP' . sprintf('%06d', $this->getID());
|
||||
return 'DP'.sprintf('%06d', $this->getID());
|
||||
}
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class Footprint
|
||||
* @package App\Entity
|
||||
* Class Footprint.
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table("footprints")
|
||||
*/
|
||||
class Footprint extends PartsContainingDBElement
|
||||
{
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Footprint", mappedBy="parent")
|
||||
*/
|
||||
|
@ -76,11 +73,12 @@ class Footprint extends PartsContainingDBElement
|
|||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
* This should have a form like P000014, for a part with ID 14.
|
||||
*
|
||||
* @return string The ID as a string;
|
||||
*/
|
||||
public function getIDString(): string
|
||||
{
|
||||
return 'F' . sprintf('%06d', $this->getID());
|
||||
return 'F'.sprintf('%06d', $this->getID());
|
||||
}
|
||||
|
||||
/****************************************
|
||||
|
@ -88,17 +86,18 @@ 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
|
||||
* * an empty string if there is no picture
|
||||
*/
|
||||
public function getFilename() : string
|
||||
public function getFilename(): string
|
||||
{
|
||||
return $this->filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* If set to false, then the path relative to Part-DB folder is returned.
|
||||
|
@ -106,9 +105,9 @@ class Footprint extends PartsContainingDBElement
|
|||
* @return string * the absolute path to the model (from filesystem root), as a UNIX path (with slashes)
|
||||
* * an empty string if there is no model
|
||||
*/
|
||||
public function get3dFilename(bool $absolute = true) : string
|
||||
public function get3dFilename(bool $absolute = true): string
|
||||
{
|
||||
if ($absolute === true) {
|
||||
if (true === $absolute) {
|
||||
//TODO
|
||||
throw new \Exception('Not Implemented yet...');
|
||||
//return str_replace('%BASE%', BASE, $this->db_data['filename_3d']);
|
||||
|
@ -118,17 +117,17 @@ 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
|
||||
* (Footprint::get_broken_filename_footprints()).
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
public function isFilenameValid() : bool
|
||||
public function isFilenameValid(): bool
|
||||
{
|
||||
if (empty($this->getFilename())) {
|
||||
return true;
|
||||
|
@ -138,24 +137,24 @@ 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
|
||||
* (Footprint::get_broken_3d_filename_footprints()).
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
public function is3dFilenameValid() : bool
|
||||
public function is3dFilenameValid(): bool
|
||||
{
|
||||
if (empty($this->get3dFilename())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Check if file is X3D-Model (these has .x3d extension)
|
||||
if (strpos($this->get3dFilename(), '.x3d') === false) {
|
||||
if (false === strpos($this->get3dFilename(), '.x3d')) {
|
||||
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.
|
||||
* 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.
|
||||
*
|
||||
* @return Footprint
|
||||
*
|
||||
* @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;
|
||||
|
||||
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
|
||||
*/
|
||||
public function set3dFilename(string $new_filename) : self
|
||||
public function set3dFilename(string $new_filename): self
|
||||
{
|
||||
$this->filename = $new_filename;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
@ -35,15 +33,13 @@ use App\Security\Interfaces\HasPermissionsInterface;
|
|||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* This entity represents an user group
|
||||
* @package App\Entity
|
||||
* This entity represents an user group.
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table("groups")
|
||||
*/
|
||||
class Group extends StructuralDBElement implements HasPermissionsInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Group", mappedBy="parent")
|
||||
*/
|
||||
|
@ -65,15 +61,15 @@ class Group extends StructuralDBElement implements HasPermissionsInterface
|
|||
*/
|
||||
protected $permissions;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
* This should have a form like P000014, for a part with ID 14.
|
||||
*
|
||||
* @return string The ID as a string;
|
||||
*/
|
||||
public function getIDString(): string
|
||||
{
|
||||
return 'G' . sprintf('%06d', $this->getID());
|
||||
return 'G'.sprintf('%06d', $this->getID());
|
||||
}
|
||||
|
||||
public function getPermissions(): PermissionsEmbed
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class Manufacturer
|
||||
* @package App\Entity
|
||||
* Class Manufacturer.
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table("manufacturers")
|
||||
|
@ -63,10 +61,11 @@ class Manufacturer extends Company
|
|||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
* This should have a form like P000014, for a part with ID 14.
|
||||
*
|
||||
* @return string The ID as a string;
|
||||
*/
|
||||
public function getIDString(): string
|
||||
{
|
||||
return 'M' . sprintf('%06d', $this->getID());
|
||||
return 'M'.sprintf('%06d', $this->getID());
|
||||
}
|
||||
}
|
|
@ -1,9 +1,10 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*
|
||||
* Part-DB Version 0.4+ "nextgen"
|
||||
* 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
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
|
@ -39,7 +38,6 @@ abstract class NamedDBElement extends DBElement
|
|||
* @var string The name of this element.
|
||||
* @ORM\Column(type="string")
|
||||
* @Assert\NotBlank()
|
||||
*
|
||||
*/
|
||||
protected $name = '';
|
||||
|
||||
|
@ -62,11 +60,11 @@ abstract class NamedDBElement extends DBElement
|
|||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Get the name
|
||||
* Get the name.
|
||||
*
|
||||
* @return string the name of this element
|
||||
*/
|
||||
public function getName() : string
|
||||
public function getName(): string
|
||||
{
|
||||
/*
|
||||
//Strip HTML from Name, so no XSS injection is possible.
|
||||
|
@ -76,18 +74,20 @@ abstract class NamedDBElement extends DBElement
|
|||
|
||||
/**
|
||||
* Returns the last time when the element was modified.
|
||||
*
|
||||
* @return \DateTime The time of the last edit.
|
||||
*/
|
||||
public function getLastModified() : \DateTime
|
||||
public function getLastModified(): \DateTime
|
||||
{
|
||||
return $this->lastModified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date/time when the element was created.
|
||||
*
|
||||
* @return \DateTime The creation time of the part.
|
||||
*/
|
||||
public function getAddedDate() : \DateTime
|
||||
public function getAddedDate(): \DateTime
|
||||
{
|
||||
return $this->addedDate;
|
||||
}
|
||||
|
@ -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
|
||||
* automatically in NamedDBElement::check_values_validity().
|
||||
* So you don't have to do this yourself.
|
||||
*
|
||||
* @param string $new_name the new name
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setName(string $new_name) : self
|
||||
public function setName(string $new_name): self
|
||||
{
|
||||
$this->name = $new_name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -122,15 +124,15 @@ abstract class NamedDBElement extends DBElement
|
|||
|
||||
/**
|
||||
* Helper for updating the timestamp. It is automatically called by doctrine before persisting.
|
||||
*
|
||||
* @ORM\PrePersist
|
||||
* @ORM\PreUpdate
|
||||
*/
|
||||
public function updatedTimestamps(): void
|
||||
{
|
||||
$this->lastModified = new \DateTime('now');
|
||||
if ($this->addedDate === null) {
|
||||
if (null === $this->addedDate) {
|
||||
$this->addedDate = new \DateTime('now');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class Orderdetail
|
||||
* @package App\Entity
|
||||
* Class Orderdetail.
|
||||
*
|
||||
* @ORM\Table("orderdetails")
|
||||
* @ORM\Entity()
|
||||
*/
|
||||
class Orderdetail extends DBElement
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Part
|
||||
* @ORM\ManyToOne(targetEntity="Part", inversedBy="orderdetails")
|
||||
|
@ -85,11 +82,12 @@ class Orderdetail extends DBElement
|
|||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
* This should have a form like P000014, for a part with ID 14.
|
||||
*
|
||||
* @return string The ID as a string;
|
||||
*/
|
||||
public function getIDString(): string
|
||||
{
|
||||
return 'O' . sprintf('%06d', $this->getID());
|
||||
return 'O'.sprintf('%06d', $this->getID());
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
|
@ -99,23 +97,23 @@ class Orderdetail extends DBElement
|
|||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Get the part
|
||||
* Get the part.
|
||||
*
|
||||
* @return Part the part of this orderdetails
|
||||
*/
|
||||
public function getPart() : Part
|
||||
public function getPart(): Part
|
||||
{
|
||||
return $this->part;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the supplier
|
||||
* Get the supplier.
|
||||
*
|
||||
* @return Supplier the supplier of this orderdetails
|
||||
*
|
||||
* @throws DatabaseException if there was an error
|
||||
*/
|
||||
public function getSupplier() : Supplier
|
||||
public function getSupplier(): Supplier
|
||||
{
|
||||
return $this->supplier;
|
||||
}
|
||||
|
@ -125,21 +123,21 @@ class Orderdetail extends DBElement
|
|||
*
|
||||
* @return string the part-nr.
|
||||
*/
|
||||
public function getSupplierPartNr() : string
|
||||
public function getSupplierPartNr(): string
|
||||
{
|
||||
return $this->supplierpartnr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if this orderdetails is obsolete
|
||||
* Get if this orderdetails is obsolete.
|
||||
*
|
||||
* "Orderdetails is obsolete" means that the part with that supplier-part-nr
|
||||
* 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
|
||||
*/
|
||||
public function getObsolete() : bool
|
||||
public function getObsolete(): bool
|
||||
{
|
||||
return (bool) $this->obsolete;
|
||||
}
|
||||
|
@ -152,9 +150,9 @@ class Orderdetail extends DBElement
|
|||
*
|
||||
* @return string the link to the article
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -162,28 +160,28 @@ class Orderdetail extends DBElement
|
|||
}
|
||||
|
||||
/**
|
||||
* Get all pricedetails
|
||||
* Get all pricedetails.
|
||||
*
|
||||
* @return Pricedetails[] all pricedetails as a one-dimensional array of Pricedetails objects,
|
||||
* sorted by minimum discount quantity
|
||||
*
|
||||
* @throws Exception if there was an error
|
||||
*/
|
||||
public function getPricedetails() : array
|
||||
public function getPricedetails(): array
|
||||
{
|
||||
return $this->pricedetails;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param integer $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 $quantity this is the quantity to choose the correct pricedetails
|
||||
* @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
|
||||
*
|
||||
* @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"
|
||||
* * 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)
|
||||
{
|
||||
/**
|
||||
/*
|
||||
if (($quantity == 0) && ($multiplier === null)) {
|
||||
if ($as_money_string) {
|
||||
return floatToMoneyString(0);
|
||||
|
@ -245,12 +243,11 @@ 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
|
||||
{
|
||||
throw new \Exception('Not implemented yet!');
|
||||
//TODO;
|
||||
|
@ -262,28 +259,30 @@ class Orderdetail extends DBElement
|
|||
* Set the 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;
|
||||
|
||||
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;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the custom product supplier URL for this order detail.
|
||||
* Set this to "", if the function getSupplierProductURL should return the automatic generated URL.
|
||||
*
|
||||
* @param $new_url string The new URL for the supplier URL.
|
||||
*/
|
||||
public function setSupplierProductUrl(string $new_url)
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
|
||||
use App\Security\Annotations\ColumnSecurity;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
//use Webmozart\Assert\Assert;
|
||||
|
@ -41,8 +39,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Class Part
|
||||
* @package App\Entity
|
||||
* Class Part.
|
||||
*
|
||||
* @ORM\Entity(repositoryClass="App\Repository\PartRepository")
|
||||
* @ORM\Table("parts")
|
||||
|
@ -127,7 +124,6 @@ class Part extends AttachmentContainingDBElement
|
|||
*/
|
||||
protected $lastModified;
|
||||
|
||||
|
||||
/**********************
|
||||
* Propertys
|
||||
***********************/
|
||||
|
@ -207,18 +203,17 @@ class Part extends AttachmentContainingDBElement
|
|||
*/
|
||||
protected $manufacturer_product_url = '';
|
||||
|
||||
|
||||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
* This should have a form like P000014, for a part with ID 14.
|
||||
*
|
||||
* @return string The ID as a string;
|
||||
*/
|
||||
public function getIDString(): string
|
||||
{
|
||||
return 'P' . sprintf('%06d', $this->getID());
|
||||
return 'P'.sprintf('%06d', $this->getID());
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************
|
||||
* Getters
|
||||
********************************************************************************/
|
||||
|
@ -229,7 +224,7 @@ class Part extends AttachmentContainingDBElement
|
|||
*
|
||||
* @return string the description
|
||||
*/
|
||||
public function getDescription() : string
|
||||
public function getDescription(): string
|
||||
{
|
||||
return htmlspecialchars($this->description);
|
||||
}
|
||||
|
@ -240,26 +235,29 @@ class Part extends AttachmentContainingDBElement
|
|||
*
|
||||
* @return int count of parts which are in stock
|
||||
*/
|
||||
public function getInstock() : int
|
||||
public function getInstock(): int
|
||||
{
|
||||
return $this->instock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check 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;
|
||||
}/** @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
|
||||
{
|
||||
return $this->mininstock;
|
||||
}
|
||||
|
@ -269,30 +267,29 @@ class Part extends AttachmentContainingDBElement
|
|||
*
|
||||
* @return string The raw/unparsed comment
|
||||
*/
|
||||
public function getComment() : string
|
||||
public function getComment(): string
|
||||
{
|
||||
|
||||
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".
|
||||
* 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();
|
||||
|
||||
if (count($all_orderdetails) === 0) {
|
||||
if (0 === count($all_orderdetails)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($all_orderdetails as $orderdetails) {
|
||||
if (! $orderdetails->getObsolete()) {
|
||||
if (!$orderdetails->getObsolete()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -301,12 +298,12 @@ 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
|
||||
*/
|
||||
public function isVisible() : bool
|
||||
public function isVisible(): bool
|
||||
{
|
||||
return $this->visible;
|
||||
}
|
||||
|
@ -317,19 +314,19 @@ class Part extends AttachmentContainingDBElement
|
|||
* @return bool * true if this part is a favorite
|
||||
* * false if this part is not a favorite.
|
||||
*/
|
||||
public function isFavorite() : bool
|
||||
public function isFavorite(): bool
|
||||
{
|
||||
return $this->favorite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selected order orderdetails of this part
|
||||
* Get the selected order orderdetails of this part.
|
||||
*
|
||||
* @return Orderdetail the selected order orderdetails
|
||||
* @return NULL if there is no order supplier selected
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getOrderOrderdetails() : ?Orderdetail
|
||||
public function getOrderOrderdetails(): ?Orderdetail
|
||||
{
|
||||
//TODO
|
||||
/*
|
||||
|
@ -342,37 +339,37 @@ 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
|
||||
{
|
||||
return $this->order_quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @return integer the minimum order quantity
|
||||
* @return int the minimum order quantity
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getMinOrderQuantity(bool $with_devices = true) : int
|
||||
public function getMinOrderQuantity(bool $with_devices = true): int
|
||||
{
|
||||
//TODO
|
||||
throw new \Exception('Not implemented yet...');
|
||||
|
||||
/**
|
||||
/*
|
||||
if ($with_devices) {
|
||||
$count_must_order = 0; // for devices with "order_only_missing_parts == false"
|
||||
$count_should_order = 0; // for devices with "order_only_missing_parts == true"
|
||||
$deviceparts = DevicePart::getOrderDeviceParts($this->database, $this->current_user, $this->log, $this->getID());
|
||||
foreach ($deviceparts as $devicepart) {
|
||||
/** @var $devicepart DevicePart */
|
||||
/** @var $device Device */ /**
|
||||
/* @var $device Device */ /*
|
||||
$device = $devicepart->getDevice();
|
||||
if ($device->getOrderOnlyMissingParts()) {
|
||||
$count_should_order += $device->getOrderQuantity() * $devicepart->getMountQuantity();
|
||||
|
@ -388,21 +385,22 @@ 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
|
||||
{
|
||||
return $this->manual_order;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function isAutoOrdered() : bool
|
||||
public function isAutoOrdered(): bool
|
||||
{
|
||||
//Parts with negative instock never gets ordered.
|
||||
if ($this->getInstock() < 0) {
|
||||
|
@ -421,13 +419,13 @@ class Part extends AttachmentContainingDBElement
|
|||
*
|
||||
* @return string the link to the article
|
||||
*/
|
||||
public function getManufacturerProductUrl() : string
|
||||
public function getManufacturerProductUrl(): string
|
||||
{
|
||||
if ($this->manufacturer_product_url !== '') {
|
||||
if ('' !== $this->manufacturer_product_url) {
|
||||
return $this->manufacturer_product_url;
|
||||
}
|
||||
|
||||
if ($this->getManufacturer() !== null) {
|
||||
if (null !== $this->getManufacturer()) {
|
||||
return $this->getManufacturer()->getAutoProductUrl($this->name);
|
||||
}
|
||||
|
||||
|
@ -436,73 +434,70 @@ class Part extends AttachmentContainingDBElement
|
|||
|
||||
/**
|
||||
* Similar to getManufacturerProductUrl, but here only the database value is returned.
|
||||
*
|
||||
* @return string The manufacturer url saved in DB for this part.
|
||||
*/
|
||||
public function getOwnProductURL() : string
|
||||
public function getOwnProductURL(): string
|
||||
{
|
||||
return $this->manufacturer_product_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the category of this part
|
||||
* Get the category of this part.
|
||||
*
|
||||
* There is always a category, for each part!
|
||||
*
|
||||
* @return Category the category of this part
|
||||
*/
|
||||
public function getCategory() : Category
|
||||
public function getCategory(): Category
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 NULL if this part has no footprint
|
||||
*/
|
||||
public function getFootprint() : ?Footprint
|
||||
public function getFootprint(): ?Footprint
|
||||
{
|
||||
return $this->footprint;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 NULL if this part has no storelocation
|
||||
*/
|
||||
public function getStorelocation() : ?Storelocation
|
||||
public function getStorelocation(): ?Storelocation
|
||||
{
|
||||
return $this->storelocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 NULL if this part has no manufacturer
|
||||
*/
|
||||
public function getManufacturer() : ?Manufacturer
|
||||
public function getManufacturer(): ?Manufacturer
|
||||
{
|
||||
return $this->manufacturer;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 NULL if this part has no master picture
|
||||
*/
|
||||
public function getMasterPictureAttachement() : ?Attachment
|
||||
public function getMasterPictureAttachement(): ?Attachment
|
||||
{
|
||||
return $this->master_picture_attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* (empty array if there are no ones)
|
||||
|
@ -519,6 +514,7 @@ class Part extends AttachmentContainingDBElement
|
|||
unset($orderdetails[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $orderdetails;
|
||||
} else {
|
||||
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
|
||||
* (empty array if there are no ones)
|
||||
|
@ -534,27 +530,27 @@ class Part extends AttachmentContainingDBElement
|
|||
*
|
||||
* @throws Exception if there was an error
|
||||
*/
|
||||
public function getDevices() : array
|
||||
public function getDevices(): array
|
||||
{
|
||||
return $this->devices;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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
|
||||
* @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
|
||||
* 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)
|
||||
* * if true and "$object_array = false", the returned
|
||||
* 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
|
||||
* (if "$object_array == true")
|
||||
|
@ -579,7 +575,7 @@ class Part extends AttachmentContainingDBElement
|
|||
} else {
|
||||
$supplier_names = array();
|
||||
foreach ($suppliers as $supplier) {
|
||||
/** @var Supplier $supplier */
|
||||
/* @var Supplier $supplier */
|
||||
if ($full_paths) {
|
||||
$supplier_names[] = $supplier->getFullPath();
|
||||
} 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
|
||||
* 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
|
||||
* @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 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
|
||||
* 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
|
||||
* @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.
|
||||
* @param integer $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 $quantity this is the quantity to choose the correct priceinformation
|
||||
* @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
|
||||
* @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 strings (if "$delimeter == NULL" & "$float_array == false")
|
||||
|
@ -655,7 +651,7 @@ class Part extends AttachmentContainingDBElement
|
|||
$prices = array();
|
||||
|
||||
foreach ($this->getOrderdetails($hide_obsolete) as $details) {
|
||||
$prices[] = $details->getPrice(! $float_array, $quantity, $multiplier);
|
||||
$prices[] = $details->getPrice(!$float_array, $quantity, $multiplier);
|
||||
}
|
||||
|
||||
if (\is_string($delimeter)) {
|
||||
|
@ -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.
|
||||
* 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().
|
||||
* * if false, the returned value is a float
|
||||
* @param integer $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 $quantity this is the quantity to choose the correct priceinformations
|
||||
* @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
|
||||
*
|
||||
* @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")
|
||||
*
|
||||
* @throws Exception if there was an error
|
||||
|
@ -691,9 +686,9 @@ class Part extends AttachmentContainingDBElement
|
|||
|
||||
$count = 0;
|
||||
foreach ($prices as $price) {
|
||||
if ($price !== null) {
|
||||
if (null !== $price) {
|
||||
$average_price += $price;
|
||||
$count++;
|
||||
++$count;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -709,29 +704,28 @@ 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)
|
||||
* * if false, and this part has no picture,
|
||||
* this method will return NULL
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function getMasterPictureFilename(bool $use_footprint_filename = false) : ?string
|
||||
public function getMasterPictureFilename(bool $use_footprint_filename = false): ?string
|
||||
{
|
||||
$master_picture = $this->getMasterPictureAttachement(); // returns an Attachement-object
|
||||
|
||||
if ($master_picture !== null) {
|
||||
if (null !== $master_picture) {
|
||||
return $master_picture->getFilename();
|
||||
}
|
||||
|
||||
if ($use_footprint_filename) {
|
||||
$footprint = $this->getFootprint();
|
||||
if ($footprint !== null) {
|
||||
if (null !== $footprint) {
|
||||
return $footprint->getFilename();
|
||||
}
|
||||
}
|
||||
|
@ -741,15 +735,18 @@ class Part extends AttachmentContainingDBElement
|
|||
|
||||
/**
|
||||
* Parses the selected fields and extract Properties of the part.
|
||||
*
|
||||
* @param bool $use_description Use the description 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 $force_output Properties are parsed even if properties are disabled.
|
||||
*
|
||||
* @return array A array of PartProperty objects.
|
||||
* @return array If Properties are disabled or nothing was detected, then an empty array is returned.
|
||||
*
|
||||
* @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
|
||||
{
|
||||
//TODO
|
||||
throw new \Exception('Not implemented yet!');
|
||||
|
@ -783,11 +780,13 @@ class Part extends AttachmentContainingDBElement
|
|||
|
||||
/**
|
||||
* 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_comment Use the comment field for parsing
|
||||
*
|
||||
* @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
|
||||
{
|
||||
//TODO
|
||||
throw new \Exception('Not implemented yet!');
|
||||
|
@ -796,6 +795,7 @@ class Part extends AttachmentContainingDBElement
|
|||
/* @var PartProperty $property */
|
||||
$arr[] = $property->getArray(true);
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
|
@ -812,26 +812,27 @@ class Part extends AttachmentContainingDBElement
|
|||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Set the description
|
||||
* Set the description.
|
||||
*
|
||||
* @param string $new_description the new description
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setDescription(?string $new_description) : self
|
||||
public function setDescription(?string $new_description): self
|
||||
{
|
||||
$this->description = $new_description;
|
||||
|
||||
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
|
||||
*/
|
||||
public function setInstock(int $new_instock, $comment = null) : self
|
||||
public function setInstock(int $new_instock, $comment = null): self
|
||||
{
|
||||
//Assert::natural($new_instock, 'New instock must be positive. Got: %s');
|
||||
|
||||
|
@ -858,28 +859,29 @@ class Part extends AttachmentContainingDBElement
|
|||
* 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.
|
||||
*
|
||||
* @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;
|
||||
} else if ($this->isInstockUnknown()) {
|
||||
} elseif ($this->isInstockUnknown()) {
|
||||
$this->setInstock(0);
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Withdrawal the given number of parts.
|
||||
*
|
||||
* @param $count int The number of parts which should be withdrawan.
|
||||
* @param $comment string A comment that should be associated with the withdrawal.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function withdrawalParts(int $count, $comment = null) : self
|
||||
public function withdrawalParts(int $count, $comment = null): self
|
||||
{
|
||||
//Assert::greaterThan($count,0, 'Count of withdrawn parts must be greater 0! Got %s!');
|
||||
//Assert::greaterThan($count, $this->instock, 'You can not withdraw more parts, than there are existing!');
|
||||
|
@ -906,12 +908,13 @@ class Part extends AttachmentContainingDBElement
|
|||
|
||||
/**
|
||||
* Add the given number of parts.
|
||||
*
|
||||
* @param $count int The number of parts which should be withdrawan.
|
||||
* @param $comment string A comment that should be associated with the withdrawal.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function addParts(int $count, string $comment = null) : self
|
||||
public function addParts(int $count, string $comment = null): self
|
||||
{
|
||||
//Assert::greaterThan($count, 0, 'Count of added parts must be greater zero! Got %s.');
|
||||
|
||||
|
@ -938,27 +941,29 @@ 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
|
||||
*/
|
||||
public function setMinInstock(int $new_mininstock) : self
|
||||
public function setMinInstock(int $new_mininstock): self
|
||||
{
|
||||
//Assert::natural($new_mininstock, 'The new minimum instock value must be positive! Got %s.');
|
||||
|
||||
$this->mininstock = $new_mininstock;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the comment
|
||||
* Set the comment.
|
||||
*
|
||||
* @param string $new_comment the new comment
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setComment(string $new_comment) : self
|
||||
public function setComment(string $new_comment): self
|
||||
{
|
||||
$this->comment = $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 integer $new_order_quantity the new order quantity
|
||||
* @param integer|NULL $new_order_orderdetails_id * the ID of the new order orderdetails
|
||||
* @param bool $new_manual_order the new "manual_order" attribute
|
||||
* @param int $new_order_quantity the new order quantity
|
||||
* @param int|null $new_order_orderdetails_id * the ID of the new order orderdetails
|
||||
* * or Zero for "no order orderdetails"
|
||||
* * or NULL for automatic order orderdetails
|
||||
* (if the part has exactly one orderdetails,
|
||||
|
@ -979,11 +984,10 @@ class Part extends AttachmentContainingDBElement
|
|||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setManualOrder(bool $new_manual_order, int $new_order_quantity = 1, $new_order_orderdetails_id = null) : self
|
||||
public function setManualOrder(bool $new_manual_order, int $new_order_quantity = 1, $new_order_orderdetails_id = null): self
|
||||
{
|
||||
//Assert::greaterThan($new_order_quantity, 0, 'The new order quantity must be greater zero. Got %s!');
|
||||
|
||||
|
||||
$this->manual_order = $new_manual_order;
|
||||
|
||||
//TODO;
|
||||
|
@ -994,14 +998,14 @@ 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
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setOrderOrderdetailsID($new_order_orderdetails_id) : self
|
||||
public function setOrderOrderdetailsID($new_order_orderdetails_id): self
|
||||
{
|
||||
//TODO
|
||||
throw new \Exception('Not implemented yet...');
|
||||
|
@ -1010,13 +1014,13 @@ 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
|
||||
*/
|
||||
public function setOrderQuantity(int $new_order_quantity) : self
|
||||
public function setOrderQuantity(int $new_order_quantity): self
|
||||
{
|
||||
//Assert::greaterThan($new_order_quantity,0, 'The new order quantity must be greater zero. Got %s!');
|
||||
|
||||
|
@ -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
|
||||
* attributes "footprint", "storelocation", ...)!
|
||||
|
@ -1035,7 +1039,7 @@ class Part extends AttachmentContainingDBElement
|
|||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setCategory(Category $category) : self
|
||||
public function setCategory(Category $category): self
|
||||
{
|
||||
$this->category = $category;
|
||||
|
||||
|
@ -1047,24 +1051,25 @@ class Part extends AttachmentContainingDBElement
|
|||
*
|
||||
* @param Footprint|null $new_footprint The new footprint of this part. Set to null, if this part should not have
|
||||
* a footprint.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setFootprint(?Footprint $new_footprint) : self
|
||||
public function setFootprint(?Footprint $new_footprint): self
|
||||
{
|
||||
$this->footprint = $new_footprint;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* not have a storelocation.
|
||||
*
|
||||
* @return Part
|
||||
*/
|
||||
public function setStorelocation(?Storelocation $new_storelocation) : self
|
||||
public function setStorelocation(?Storelocation $new_storelocation): self
|
||||
{
|
||||
$this->storelocation = $new_storelocation;
|
||||
|
||||
|
@ -1076,9 +1081,10 @@ class Part extends AttachmentContainingDBElement
|
|||
*
|
||||
* @param Manufacturer|null $new_manufacturer The new Manufacturer of this part. Set to null, if this part should
|
||||
* not have a manufacturer.
|
||||
*
|
||||
* @return Part
|
||||
*/
|
||||
public function setManufacturer(?Manufacturer $new_manufacturer) : self
|
||||
public function setManufacturer(?Manufacturer $new_manufacturer): self
|
||||
{
|
||||
$this->manufacturer = $new_manufacturer;
|
||||
|
||||
|
@ -1087,12 +1093,13 @@ class Part extends AttachmentContainingDBElement
|
|||
|
||||
/**
|
||||
* Set the favorite status for 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.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setFavorite(bool $new_favorite_status) : self
|
||||
public function setFavorite(bool $new_favorite_status): self
|
||||
{
|
||||
$this->favorite = $new_favorite_status;
|
||||
|
||||
|
@ -1101,10 +1108,12 @@ 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.
|
||||
*
|
||||
* @param string $new_url The new url
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setManufacturerProductURL(string $new_url) : self
|
||||
public function setManufacturerProductURL(string $new_url): self
|
||||
{
|
||||
$this->manufacturer_product_url = $new_url;
|
||||
|
||||
|
@ -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"
|
||||
*
|
||||
* @throws Exception if the new ID is not valid
|
||||
|
@ -1122,13 +1131,11 @@ class Part extends AttachmentContainingDBElement
|
|||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setMasterPictureAttachementID($new_master_picture_attachement_id) : self
|
||||
public function setMasterPictureAttachementID($new_master_picture_attachement_id): self
|
||||
{
|
||||
//TODO
|
||||
throw new \Exception('Not implemented yet!');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,9 +1,10 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*
|
||||
* Part-DB Version 0.4+ "nextgen"
|
||||
* 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
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
@ -26,13 +26,11 @@ namespace App\Entity;
|
|||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class PartsContainingDBElement
|
||||
* @package PartDB\Models
|
||||
* Class PartsContainingDBElement.
|
||||
*
|
||||
* @ORM\MappedSuperclass()
|
||||
*/
|
||||
abstract class PartsContainingDBElement extends StructuralDBElement
|
||||
{
|
||||
|
||||
protected $parts;
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
@ -38,23 +36,19 @@ use Webmozart\Assert\Assert;
|
|||
* This entity represents the permission fields a user or group can have.
|
||||
*
|
||||
* @ORM\Embeddable()
|
||||
* @package App\Entity
|
||||
*/
|
||||
class PermissionsEmbed
|
||||
{
|
||||
|
||||
/**
|
||||
* Permission values
|
||||
* Permission values.
|
||||
*/
|
||||
public const INHERIT = 0b00;
|
||||
public const ALLOW = 0b01;
|
||||
public const DISALLOW = 0b10;
|
||||
|
||||
|
||||
/**
|
||||
* Permission strings
|
||||
* Permission strings.
|
||||
*/
|
||||
|
||||
public const STORELOCATIONS = 'storelocations';
|
||||
public const FOOTRPINTS = 'footprints';
|
||||
public const CATEGORIES = 'categories';
|
||||
|
@ -259,14 +253,15 @@ class PermissionsEmbed
|
|||
*/
|
||||
protected $labels;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the bit pair value of the given permission.
|
||||
*
|
||||
* @param string $permission_name The name of the permission, for which the bit pair should be returned.
|
||||
* @param int $bit_n The (lower) bit number of the bit pair, which should be read.
|
||||
*
|
||||
* @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
|
||||
{
|
||||
$perm_int = $this->$permission_name;
|
||||
|
||||
|
@ -275,19 +270,21 @@ class PermissionsEmbed
|
|||
|
||||
/**
|
||||
* Returns the value of the operation for the given permission.
|
||||
*
|
||||
* @param string $permission_name The name of the permission, for which the operation should be returned.
|
||||
* @param int $bit_n The (lower) bit number of the bit pair for the operation.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
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);
|
||||
if ($value == self::ALLOW) {
|
||||
if (self::ALLOW == $value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if($value == self::DISALLOW) {
|
||||
if (self::DISALLOW == $value) {
|
||||
return false;
|
||||
} else {
|
||||
return null;
|
||||
|
@ -296,14 +293,16 @@ class PermissionsEmbed
|
|||
|
||||
/**
|
||||
* Reads a bit pair from $data.
|
||||
*
|
||||
* @param $data int The data from where the bits should be extracted from.
|
||||
* @param $n int The number of the lower bit (of the pair) that should be read. Starting from zero.
|
||||
*
|
||||
* @return int The value of the bit pair.
|
||||
*/
|
||||
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.');
|
||||
if ($n % 2 !== 0) {
|
||||
Assert::lessThanEq($n, 31, '$n must be smaller than 32, because only a 32bit int is used! Got %s.');
|
||||
if (0 !== $n % 2) {
|
||||
throw new \InvalidArgumentException('$n must be dividable by 2, because we address bit pairs here!');
|
||||
}
|
||||
|
||||
|
@ -313,24 +312,26 @@ class PermissionsEmbed
|
|||
|
||||
/**
|
||||
* Writes a bit pair in the given $data and returns it.
|
||||
*
|
||||
* @param $data int The data which should be modified.
|
||||
* @param $n int The number of the lower bit of the pair which should be written.
|
||||
* @param $new int The new value of the pair.
|
||||
*
|
||||
* @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
|
||||
{
|
||||
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.');
|
||||
|
||||
if ($n % 2 !== 0) {
|
||||
if (0 !== $n % 2) {
|
||||
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
|
||||
$newval = $new << $n; //The new value.
|
||||
$data = ($data & ~$mask) | ($newval & $mask);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* Class Pricedetail
|
||||
* @package App\Entity
|
||||
* Class Pricedetail.
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table("pricedetails")
|
||||
|
@ -82,7 +79,6 @@ class Pricedetail extends DBElement
|
|||
*/
|
||||
protected $last_modified;
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Getters
|
||||
|
@ -90,22 +86,21 @@ class Pricedetail extends DBElement
|
|||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Get the orderdetails of this pricedetails
|
||||
* Get the orderdetails of this pricedetails.
|
||||
*
|
||||
* @return Orderdetail the orderdetails object
|
||||
*
|
||||
*/
|
||||
public function getOrderdetails() : Orderdetail
|
||||
public function getOrderdetails(): Orderdetail
|
||||
{
|
||||
return $this->orderdetail;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @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.
|
||||
*
|
||||
* You will get the price for $multiplier parts. If you want the price which is stored
|
||||
|
@ -129,30 +124,30 @@ class Pricedetail extends DBElement
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the price related quantity
|
||||
* Get the price related quantity.
|
||||
*
|
||||
* 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()
|
||||
*/
|
||||
public function getPriceRelatedQuantity() : int
|
||||
public function getPriceRelatedQuantity(): int
|
||||
{
|
||||
return $this->price_related_quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum discount quantity
|
||||
* Get the minimum discount quantity.
|
||||
*
|
||||
* "Minimum discount quantity" means the minimum order quantity for which the price
|
||||
* of this orderdetails is valid.
|
||||
*
|
||||
* @return integer the minimum discount quantity
|
||||
* @return int the minimum discount quantity
|
||||
*
|
||||
* @see Pricedetails::setMinDiscountQuantity()
|
||||
*/
|
||||
public function getMinDiscountQuantity() : int
|
||||
public function getMinDiscountQuantity(): int
|
||||
{
|
||||
return $this->min_discount_quantity;
|
||||
}
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -174,7 +169,7 @@ class Pricedetail extends DBElement
|
|||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setPrice(float $new_price) : self
|
||||
public function setPrice(float $new_price): self
|
||||
{
|
||||
Assert::natural($new_price, 'The new price must be positive! Got %s!');
|
||||
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -192,13 +187,12 @@ class Pricedetail extends DBElement
|
|||
* 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.
|
||||
*
|
||||
* @param integer $new_price_related_quantity the price related quantity
|
||||
* @param int $new_price_related_quantity the price related quantity
|
||||
*
|
||||
* @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,
|
||||
'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
|
||||
* of this orderdetails is valid. This way, you're able to use different prices
|
||||
|
@ -222,11 +216,11 @@ class Pricedetail extends DBElement
|
|||
* (Each of this examples would be an own Pricedetails-object.
|
||||
* 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
|
||||
*/
|
||||
public function setMinDiscountQuantity(int $new_min_discount_quantity) : self
|
||||
public function setMinDiscountQuantity(int $new_min_discount_quantity): self
|
||||
{
|
||||
Assert::greaterThan($new_min_discount_quantity, 0,
|
||||
'The new minimum discount quantity must be greater zero! Got %s.');
|
||||
|
@ -236,16 +230,14 @@ class Pricedetail extends DBElement
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
* This should have a form like P000014, for a part with ID 14.
|
||||
*
|
||||
* @return string The ID as a string;
|
||||
*/
|
||||
public function getIDString(): string
|
||||
{
|
||||
return 'PD' . sprintf('%06d', $this->getID());
|
||||
return 'PD'.sprintf('%06d', $this->getID());
|
||||
}
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
@ -36,8 +35,7 @@ namespace App\Entity;
|
|||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class Storelocation
|
||||
* @package App\Entity
|
||||
* Class Storelocation.
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table("storelocations")
|
||||
|
@ -73,15 +71,15 @@ 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.
|
||||
* 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
|
||||
*/
|
||||
public function getIsFull() : bool
|
||||
public function getIsFull(): bool
|
||||
{
|
||||
return (bool) $this->is_full;
|
||||
}
|
||||
|
@ -93,29 +91,31 @@ 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.
|
||||
* 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
|
||||
*
|
||||
* @throws Exception if there was an error
|
||||
*/
|
||||
public function setIsFull(bool $new_is_full) : self
|
||||
public function setIsFull(bool $new_is_full): self
|
||||
{
|
||||
$this->is_full = $new_is_full;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
* This should have a form like P000014, for a part with ID 14.
|
||||
*
|
||||
* @return string The ID as a string;
|
||||
*/
|
||||
public function getIDString(): string
|
||||
{
|
||||
return 'L' . sprintf('%06d', $this->getID());
|
||||
return 'L'.sprintf('%06d', $this->getID());
|
||||
}
|
||||
}
|
|
@ -1,9 +1,10 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*
|
||||
* Part-DB Version 0.4+ "nextgen"
|
||||
* 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
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
@ -28,8 +28,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
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.
|
||||
* 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
|
||||
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
|
||||
// subclasses
|
||||
/**
|
||||
|
@ -73,7 +71,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $level=0;
|
||||
protected $level = 0;
|
||||
|
||||
/** @var string[] all names of all parent elements as a array of strings,
|
||||
* the last array element is the name of the element itself */
|
||||
|
@ -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
|
||||
* 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!');
|
||||
}
|
||||
|
||||
if ($this->getID() == null) { // this is the root node
|
||||
if (null == $this->getID()) { // this is the root node
|
||||
return false;
|
||||
}
|
||||
|
||||
//If this' parents element, is $another_element, then we are finished
|
||||
return (($this->parent->getID() == $another_element->getID())
|
||||
|| $this->parent->isChildOf($another_element)); //Otherwise, check recursivley
|
||||
//If this' parents element, is $another_element, then we are finished
|
||||
return ($this->parent->getID() == $another_element->getID())
|
||||
|| $this->parent->isChildOf($another_element); //Otherwise, check recursivley
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Getters
|
||||
|
@ -125,16 +122,17 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
* * NULL means, the parent is the root node
|
||||
* * the parent ID of the root node is -1
|
||||
*/
|
||||
public function getParentID() : int
|
||||
public function getParentID(): int
|
||||
{
|
||||
return $this->parent_id ?? self::ID_ROOT_ELEMENT; //Null means root element
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent of this element.
|
||||
*
|
||||
* @return StructuralDBElement|null The parent element. Null if this element, does not have a parent.
|
||||
*/
|
||||
public function getParent() : ?self
|
||||
public function getParent(): ?self
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
@ -142,10 +140,11 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
/**
|
||||
* 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
|
||||
*/
|
||||
public function getComment(bool $parse_bbcode = true) : string
|
||||
public function getComment(bool $parse_bbcode = true): string
|
||||
{
|
||||
$val = htmlspecialchars($this->comment ?? '');
|
||||
|
||||
|
@ -153,24 +152,23 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the level
|
||||
* Get the level.
|
||||
*
|
||||
* 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])
|
||||
*
|
||||
*/
|
||||
public function getLevel() : int
|
||||
public function getLevel(): int
|
||||
{
|
||||
if ($this->level === 0) {
|
||||
if (0 === $this->level) {
|
||||
$element = $this->parent;
|
||||
$parent_id = $element->getParentID();
|
||||
while ($parent_id > 0) {
|
||||
/** @var StructuralDBElement $element */
|
||||
$element = $element->parent;
|
||||
$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
|
||||
*
|
||||
|
@ -186,14 +184,14 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
*
|
||||
* @throws Exception if there was an error
|
||||
*/
|
||||
public function getFullPath(string $delimeter = self::PATH_DELIMITER_ARROW) : string
|
||||
public function getFullPath(string $delimeter = self::PATH_DELIMITER_ARROW): string
|
||||
{
|
||||
if (! \is_array($this->full_path_strings)) {
|
||||
if (!\is_array($this->full_path_strings)) {
|
||||
$this->full_path_strings = array();
|
||||
$this->full_path_strings[] = $this->getName();
|
||||
$element = $this;
|
||||
|
||||
while ($element->parent != null) {
|
||||
while (null != $element->parent) {
|
||||
$element = $element->parent;
|
||||
$this->full_path_strings[] = $element->getName();
|
||||
}
|
||||
|
@ -205,19 +203,19 @@ 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)
|
||||
*/
|
||||
public function getSubelements(bool $recursive) : PersistentCollection
|
||||
public function getSubelements(bool $recursive): PersistentCollection
|
||||
{
|
||||
if ($this->children == null) {
|
||||
if (null == $this->children) {
|
||||
$this->children = new ArrayCollection();
|
||||
}
|
||||
|
||||
if (! $recursive) {
|
||||
if (!$recursive) {
|
||||
return $this->children;
|
||||
} else {
|
||||
$all_elements = array();
|
||||
|
@ -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
|
||||
*/
|
||||
public function setParentID($new_parent_id) : self
|
||||
public function setParentID($new_parent_id): self
|
||||
{
|
||||
$this->parent_id = $new_parent_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the comment
|
||||
* Set the comment.
|
||||
*
|
||||
* @param string $new_comment the new comment
|
||||
*
|
||||
* @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;
|
||||
|
||||
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.
|
||||
* <b>The <select>-tags are not printed here, you have to print them yourself!</b>
|
||||
* Deeper levels have more spaces in front.
|
||||
*
|
||||
* @param integer $selected_id the ID of the selected item
|
||||
* @param boolean $recursive if true, the tree will be recursive
|
||||
* @param boolean $show_root if true, the root node will be displayed
|
||||
* @param int $selected_id the ID of the selected item
|
||||
* @param bool $recursive if true, the tree will be recursive
|
||||
* @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 $value_prefix This string is used as a prefix before the id in the value part of the option.
|
||||
*
|
||||
|
@ -289,8 +290,8 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
bool $show_root = true,
|
||||
string $root_name = '$$',
|
||||
string $value_prefix = ''
|
||||
) : string {
|
||||
if ($root_name == '$$') {
|
||||
): string {
|
||||
if ('$$' == $root_name) {
|
||||
$root_name = _('Oberste Ebene');
|
||||
}
|
||||
|
||||
|
@ -302,7 +303,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
$root_name = htmlspecialchars($this->getName());
|
||||
}
|
||||
|
||||
$html[] = '<option value="'. $value_prefix . $this->getID() . '">' . $root_name . '</option>';
|
||||
$html[] = '<option value="'.$value_prefix.$this->getID().'">'.$root_name.'</option>';
|
||||
} else {
|
||||
$root_level = $this->getLevel() + 1;
|
||||
}
|
||||
|
@ -314,17 +315,16 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
$level = $element->getLevel() - $root_level;
|
||||
$selected = ($element->getID() == $selected_id) ? 'selected' : '';
|
||||
|
||||
$html[] = '<option ' . $selected . ' value="' . $value_prefix . $element->getID() . '">';
|
||||
for ($i = 0; $i < $level; $i++) {
|
||||
$html[] = '<option '.$selected.' value="'.$value_prefix.$element->getID().'">';
|
||||
for ($i = 0; $i < $level; ++$i) {
|
||||
$html[] = ' ';
|
||||
}
|
||||
$html[] = htmlspecialchars($element->getName()) . '</option>';
|
||||
$html[] = htmlspecialchars($element->getName()).'</option>';
|
||||
}
|
||||
|
||||
return implode("\n", $html);
|
||||
}
|
||||
|
||||
|
||||
public function buildBootstrapTree(
|
||||
$page,
|
||||
$parameter,
|
||||
|
@ -332,9 +332,8 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
$show_root = false,
|
||||
$use_db_root_name = true,
|
||||
$root_name = '$$'
|
||||
): array
|
||||
{
|
||||
if ($root_name == '$$') {
|
||||
): array {
|
||||
if ('$$' == $root_name) {
|
||||
$root_name = _('Oberste Ebene');
|
||||
}
|
||||
|
||||
|
@ -346,61 +345,62 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
}
|
||||
|
||||
// if we are on root level?
|
||||
if ($this->getParentID() == -1) {
|
||||
if (-1 == $this->getParentID()) {
|
||||
if ($show_root) {
|
||||
$tree = array(
|
||||
array('text' => $use_db_root_name ? htmlspecialchars($this->getName()) : $root_name ,
|
||||
'href' => $page . '?' . $parameter . '=' . $this->getID(),
|
||||
'nodes' => $nodes)
|
||||
array('text' => $use_db_root_name ? htmlspecialchars($this->getName()) : $root_name,
|
||||
'href' => $page.'?'.$parameter.'='.$this->getID(),
|
||||
'nodes' => $nodes, ),
|
||||
);
|
||||
} else { //Dont show root node
|
||||
$tree = $nodes;
|
||||
}
|
||||
} elseif (!empty($nodes)) {
|
||||
$tree = array('text' => htmlspecialchars($this->getName()),
|
||||
'href' => $page . '?' . $parameter . '=' . $this->getID(),
|
||||
'nodes' => $nodes
|
||||
'href' => $page.'?'.$parameter.'='.$this->getID(),
|
||||
'nodes' => $nodes,
|
||||
);
|
||||
} else {
|
||||
$tree = array('text' => htmlspecialchars($this->getName()),
|
||||
'href' => $page . '?' . $parameter . '=' . $this->getID()
|
||||
'href' => $page.'?'.$parameter.'='.$this->getID(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return $tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 $parameter string The parameter, which selects the ID of the StructuralDBElement.
|
||||
* @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.
|
||||
*
|
||||
* @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();
|
||||
|
||||
if ($root_name == '$$') {
|
||||
if ('$$' == $root_name) {
|
||||
$root_name = _('Oberste Ebene');
|
||||
}
|
||||
|
||||
if ($show_root) {
|
||||
$breadcrumb[] = array('label' => $root_name,
|
||||
'disabled' => true);
|
||||
'disabled' => true, );
|
||||
}
|
||||
|
||||
if (!$this->current_user->canDo(static::getPermissionName(), StructuralPermission::READ)) {
|
||||
return array('label' => '???',
|
||||
'disabled' => true);
|
||||
'disabled' => true, );
|
||||
}
|
||||
|
||||
$tmp = array();
|
||||
|
||||
if ($element_is_link) {
|
||||
$tmp[] = array('label' => $this->getName(), 'href' => $page . '?' . $parameter . '=' .$this->getID(), 'selected' => true);
|
||||
$tmp[] = array('label' => $this->getName(), 'href' => $page.'?'.$parameter.'='.$this->getID(), 'selected' => true);
|
||||
} else {
|
||||
$tmp[] = array('label' => $this->getName(), 'selected' => true);
|
||||
}
|
||||
|
@ -410,7 +410,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
/** @var StructuralDBElement $element */
|
||||
$element = static::getInstance($this->database, $this->current_user, $this->log, $parent_id);
|
||||
$parent_id = $element->getParentID();
|
||||
$tmp[] = array('label' => $element->getName(), 'href' => $page . '?' . $parameter . '=' . $element->getID());
|
||||
$tmp[] = array('label' => $element->getName(), 'href' => $page.'?'.$parameter.'='.$element->getID());
|
||||
}
|
||||
$tmp = array_reverse($tmp);
|
||||
|
||||
|
@ -418,5 +418,4 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
|
|||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
@ -35,8 +35,7 @@ namespace App\Entity;
|
|||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class Supplier
|
||||
* @package App\Entity
|
||||
* Class Supplier.
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table("suppliers")
|
||||
|
@ -60,13 +59,13 @@ class Supplier extends Company
|
|||
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
|
||||
*
|
||||
* @throws Exception if there was an error
|
||||
*/
|
||||
public function getCountOfPartsToOrder() : int
|
||||
public function getCountOfPartsToOrder(): int
|
||||
{
|
||||
/*
|
||||
$query = 'SELECT COUNT(*) as count FROM parts '.
|
||||
|
@ -86,20 +85,18 @@ class Supplier extends Company
|
|||
|
||||
return (int) $query_data[0]['count']; */
|
||||
|
||||
|
||||
//TODO
|
||||
throw new \Exception('Not implemented yet!');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
* This should have a form like P000014, for a part with ID 14.
|
||||
*
|
||||
* @return string The ID as a string;
|
||||
*/
|
||||
public function getIDString(): string
|
||||
{
|
||||
return 'L' . sprintf('%06d', $this->getID());
|
||||
return 'L'.sprintf('%06d', $this->getID());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Entity\Embeddables\PermissionEntity;
|
||||
use App\Security\Interfaces\HasPermissionsInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
@ -64,7 +63,7 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
|
|||
protected $name;
|
||||
|
||||
/**
|
||||
* //@ORM\Column(type="json")
|
||||
* //@ORM\Column(type="json").
|
||||
*/
|
||||
//protected $roles = [];
|
||||
|
||||
|
@ -98,7 +97,6 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
|
|||
*/
|
||||
protected $department = '';
|
||||
|
||||
|
||||
/**
|
||||
* @var string|null The email address of the user
|
||||
* @ORM\Column(type="string", length=255, nullable=true)
|
||||
|
@ -125,7 +123,7 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
|
|||
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\JoinColumn(name="group_id", referencedColumnName="id")
|
||||
*/
|
||||
|
@ -136,14 +134,14 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
|
|||
*/
|
||||
protected $permissions;
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param string $password
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setPassword(string $password): self
|
||||
|
@ -217,15 +217,15 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
|
|||
/**
|
||||
* Returns the ID as an string, defined by the element class.
|
||||
* This should have a form like P000014, for a part with ID 14.
|
||||
*
|
||||
* @return string The ID as a string;
|
||||
*/
|
||||
public function getIDString(): string
|
||||
{
|
||||
return 'U' . sprintf('%06d', $this->getID());
|
||||
return 'U'.sprintf('%06d', $this->getID());
|
||||
}
|
||||
|
||||
|
||||
public function getPermissions() : PermissionsEmbed
|
||||
public function getPermissions(): PermissionsEmbed
|
||||
{
|
||||
return $this->permissions;
|
||||
}
|
||||
|
@ -236,25 +236,26 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
|
|||
|
||||
/**
|
||||
* Returns the full name in the format FIRSTNAME LASTNAME [(USERNAME)].
|
||||
* 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.
|
||||
* 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
|
||||
*/
|
||||
public function getFullName(bool $including_username = false) : string
|
||||
public function getFullName(bool $including_username = false): string
|
||||
{
|
||||
$str = $this->getFirstName() . ' ' . $this->getLastName();
|
||||
$str = $this->getFirstName().' '.$this->getLastName();
|
||||
if ($including_username) {
|
||||
$str .= ' (' . $this->getName() . ')';
|
||||
$str .= ' ('.$this->getName().')';
|
||||
}
|
||||
|
||||
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
|
||||
if(!$this->isAnonymousUser()) {
|
||||
if (!$this->isAnonymousUser()) {
|
||||
$this->name = $new_name;
|
||||
}
|
||||
|
||||
|
@ -271,11 +272,13 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
|
|||
|
||||
/**
|
||||
* @param string $first_name
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setFirstName(?string $first_name): User
|
||||
{
|
||||
$this->first_name = $first_name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -289,11 +292,13 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
|
|||
|
||||
/**
|
||||
* @param string $last_name
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setLastName(?string $last_name): User
|
||||
{
|
||||
$this->last_name = $last_name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -307,11 +312,13 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
|
|||
|
||||
/**
|
||||
* @param string $department
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setDepartment(?string $department): User
|
||||
{
|
||||
$this->department = $department;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -325,11 +332,13 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
|
|||
|
||||
/**
|
||||
* @param string $email
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setEmail(?string $email): User
|
||||
{
|
||||
$this->email = $email;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -343,11 +352,13 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
|
|||
|
||||
/**
|
||||
* @param string $language
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setLanguage(?string $language): User
|
||||
{
|
||||
$this->language = $language;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -361,11 +372,13 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
|
|||
|
||||
/**
|
||||
* @param string $timezone
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setTimezone(?string $timezone): User
|
||||
{
|
||||
$this->timezone = $timezone;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -379,11 +392,13 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
|
|||
|
||||
/**
|
||||
* @param string $theme
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setTheme(?string $theme): User
|
||||
{
|
||||
$this->theme = $theme;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -395,7 +410,7 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf
|
|||
public function setGroup(?Group $group): self
|
||||
{
|
||||
$this->group = $group;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
|
||||
class EntityNotSupported extends \Exception
|
||||
{
|
||||
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
|
||||
use App\Entity\Category;
|
||||
use App\Entity\Manufacturer;
|
||||
use App\Entity\Part;
|
||||
|
@ -39,7 +36,6 @@ use App\Entity\Storelocation;
|
|||
use FOS\CKEditorBundle\Form\Type\CKEditorType;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
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\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
|
@ -58,39 +54,38 @@ class PartType extends AbstractType
|
|||
$this->security = $security;
|
||||
}
|
||||
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$part = $options['data'];
|
||||
|
||||
$builder
|
||||
->add('name', TextType::class, ['empty_data'=>'', 'label'=> 'name.label',
|
||||
->add('name', TextType::class, ['empty_data' => '', 'label' => 'name.label',
|
||||
'attr' => ['placeholder' => 'part.name.placeholder'],
|
||||
'disabled' => !$this->security->isGranted('name.edit', $part)])
|
||||
->add('description', TextType::class, ['required'=>false, 'empty_data'=>'',
|
||||
'label'=> 'description.label', 'help' => 'bbcode.hint', 'attr' => ['placeholder' => 'part.description.placeholder'],
|
||||
'disabled' => !$this->security->isGranted('description.edit', $part)])
|
||||
'disabled' => !$this->security->isGranted('name.edit', $part), ])
|
||||
->add('description', TextType::class, ['required' => false, 'empty_data' => '',
|
||||
'label' => 'description.label', 'help' => 'bbcode.hint', 'attr' => ['placeholder' => 'part.description.placeholder'],
|
||||
'disabled' => !$this->security->isGranted('description.edit', $part), ])
|
||||
->add('instock', IntegerType::class,
|
||||
['attr' => ['min'=>0, 'placeholder' => 'part.instock.placeholder'], 'label'=> 'instock.label',
|
||||
'disabled' => !$this->security->isGranted('instock.edit', $part)])
|
||||
['attr' => ['min' => 0, 'placeholder' => 'part.instock.placeholder'], 'label' => 'instock.label',
|
||||
'disabled' => !$this->security->isGranted('instock.edit', $part), ])
|
||||
->add('mininstock', IntegerType::class,
|
||||
['attr' => ['min'=>0, 'placeholder' => 'part.mininstock.placeholder'], 'label'=> 'mininstock.label',
|
||||
'disabled' => !$this->security->isGranted('mininstock.edit', $part)])
|
||||
['attr' => ['min' => 0, 'placeholder' => 'part.mininstock.placeholder'], 'label' => 'mininstock.label',
|
||||
'disabled' => !$this->security->isGranted('mininstock.edit', $part), ])
|
||||
->add('category', EntityType::class, ['class' => Category::class, 'choice_label' => 'full_path',
|
||||
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'label'=> 'category.label',
|
||||
'disabled' => !$this->security->isGranted('move', $part)])
|
||||
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'label' => 'category.label',
|
||||
'disabled' => !$this->security->isGranted('move', $part), ])
|
||||
->add('storelocation', EntityType::class, ['class' => Storelocation::class, 'choice_label' => 'full_path',
|
||||
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'required' => false, 'label'=> 'storelocation.label',
|
||||
'disabled' => !$this->security->isGranted('storelocation.edit', $part)])
|
||||
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'required' => false, 'label' => 'storelocation.label',
|
||||
'disabled' => !$this->security->isGranted('storelocation.edit', $part), ])
|
||||
->add('manufacturer', EntityType::class, ['class' => Manufacturer::class, 'choice_label' => 'full_path',
|
||||
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'required' => false, 'label'=> 'manufacturer.label',
|
||||
'disabled' => !$this->security->isGranted('manufacturer.edit', $part)])
|
||||
->add('manufacturer_product_url', UrlType::class, ['required'=>false, 'empty_data' => '',
|
||||
'label'=> 'manufacturer_url.label',
|
||||
'disabled' => !$this->security->isGranted('manufacturer.edit', $part)])
|
||||
->add('comment', CKEditorType::class, ['required'=>false,
|
||||
'label'=> 'comment.label', 'attr' => ['rows'=> 4], 'help' => 'bbcode.hint',
|
||||
'disabled' => !$this->security->isGranted('comment.edit', $part)])
|
||||
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'required' => false, 'label' => 'manufacturer.label',
|
||||
'disabled' => !$this->security->isGranted('manufacturer.edit', $part), ])
|
||||
->add('manufacturer_product_url', UrlType::class, ['required' => false, 'empty_data' => '',
|
||||
'label' => 'manufacturer_url.label',
|
||||
'disabled' => !$this->security->isGranted('manufacturer.edit', $part), ])
|
||||
->add('comment', CKEditorType::class, ['required' => false,
|
||||
'label' => 'comment.label', 'attr' => ['rows' => 4], 'help' => 'bbcode.hint',
|
||||
'disabled' => !$this->security->isGranted('comment.edit', $part), ])
|
||||
|
||||
//Buttons
|
||||
->add('save', SubmitType::class, ['label' => 'part.edit.save'])
|
||||
|
@ -100,7 +95,7 @@ class PartType extends AbstractType
|
|||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Part::class
|
||||
'data_class' => Part::class,
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -6,7 +6,6 @@ use App\Entity\User;
|
|||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
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\ResetType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
|
@ -25,37 +24,34 @@ class UserSettingsType extends AbstractType
|
|||
$this->security = $security;
|
||||
}
|
||||
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('name', TextType::class, ['label'=>'user.username.label',
|
||||
'disabled' => !$this->security->isGranted('edit_username', $options['data'])])
|
||||
->add('name', TextType::class, ['label' => 'user.username.label',
|
||||
'disabled' => !$this->security->isGranted('edit_username', $options['data']), ])
|
||||
->add('first_name', TextType::class, ['required' => false,
|
||||
'label'=>'user.firstName.label',
|
||||
'disabled' => !$this->security->isGranted('edit_infos', $options['data'])])
|
||||
'label' => 'user.firstName.label',
|
||||
'disabled' => !$this->security->isGranted('edit_infos', $options['data']), ])
|
||||
->add('last_name', TextType::class, ['required' => false,
|
||||
'label'=>'user.lastName.label',
|
||||
'disabled' => !$this->security->isGranted('edit_infos', $options['data'])])
|
||||
'label' => 'user.lastName.label',
|
||||
'disabled' => !$this->security->isGranted('edit_infos', $options['data']), ])
|
||||
->add('department', TextType::class, ['required' => false,
|
||||
'label'=>'user.department.label',
|
||||
'disabled' => !$this->security->isGranted('edit_infos', $options['data'])])
|
||||
'label' => 'user.department.label',
|
||||
'disabled' => !$this->security->isGranted('edit_infos', $options['data']), ])
|
||||
->add('email', EmailType::class, ['required' => false,
|
||||
'label'=>'user.email.label',
|
||||
'disabled' => !$this->security->isGranted('edit_infos', $options['data'])])
|
||||
'label' => 'user.email.label',
|
||||
'disabled' => !$this->security->isGranted('edit_infos', $options['data']), ])
|
||||
->add('language', LocaleType::class, ['required' => false,
|
||||
'attr'=>['class'=> 'selectpicker', 'data-live-search' => true]
|
||||
, 'placeholder' => 'user_settings.language.placeholder', 'label'=>'user.language_select'])
|
||||
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'placeholder' => 'user_settings.language.placeholder', 'label' => 'user.language_select', ])
|
||||
->add('timezone', TimezoneType::class, ['required' => false,
|
||||
'attr'=>['class'=> 'selectpicker', 'data-live-search' => true],
|
||||
'placeholder' => 'user_settings.timezone.placeholder', 'label'=>'user.timezone.label'])
|
||||
'attr' => ['class' => 'selectpicker', 'data-live-search' => true],
|
||||
'placeholder' => 'user_settings.timezone.placeholder', 'label' => 'user.timezone.label', ])
|
||||
->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
|
||||
->add('save', SubmitType::class, ['label' => 'save'])
|
||||
->add('reset', ResetType::class, ['label' => 'reset']);
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Security\Annotations;
|
||||
|
@ -40,22 +38,20 @@ use Doctrine\Common\Annotations\Annotation;
|
|||
*
|
||||
* 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.
|
||||
*
|
||||
* @package App\Annotations
|
||||
*/
|
||||
class ColumnSecurity
|
||||
{
|
||||
/**
|
||||
* @var string The name of the edit permission
|
||||
*/
|
||||
public $edit = "edit";
|
||||
public $edit = 'edit';
|
||||
/**
|
||||
* @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 = '';
|
||||
|
||||
|
@ -72,18 +68,19 @@ class ColumnSecurity
|
|||
*/
|
||||
public $type = 'string';
|
||||
|
||||
public function getReadOperationName() : string
|
||||
public function getReadOperationName(): string
|
||||
{
|
||||
if($this->prefix !== '') {
|
||||
return $this->prefix . '.' . $this->read;
|
||||
if ('' !== $this->prefix) {
|
||||
return $this->prefix.'.'.$this->read;
|
||||
}
|
||||
|
||||
return $this->read;
|
||||
}
|
||||
|
||||
public function getEditOperationName() : string
|
||||
public function getEditOperationName(): string
|
||||
{
|
||||
if($this->prefix !== '') {
|
||||
return $this->prefix . '.' . $this->edit;
|
||||
if ('' !== $this->prefix) {
|
||||
return $this->prefix.'.'.$this->edit;
|
||||
}
|
||||
|
||||
return $this->edit;
|
||||
|
@ -91,10 +88,8 @@ class ColumnSecurity
|
|||
|
||||
public function getPlaceholder()
|
||||
{
|
||||
if($this->placeholder === null)
|
||||
{
|
||||
switch($this->type)
|
||||
{
|
||||
if (null === $this->placeholder) {
|
||||
switch ($this->type) {
|
||||
case 'integer':
|
||||
return 0;
|
||||
case 'string':
|
||||
|
@ -105,11 +100,11 @@ class ColumnSecurity
|
|||
return false;
|
||||
case 'datetime':
|
||||
$date = new \DateTime();
|
||||
|
||||
return $date->setTimestamp(0);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->placeholder;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Security\EntityListeners;
|
||||
|
||||
|
||||
use App\Security\Annotations\ColumnSecurity;
|
||||
use App\Entity\DBElement;
|
||||
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.
|
||||
* The edit process is also catched, so that these placeholders, does not get saved to database.
|
||||
* @package App\EntityListeners
|
||||
*/
|
||||
class ElementPermissionListener
|
||||
{
|
||||
|
@ -59,14 +55,12 @@ class ElementPermissionListener
|
|||
$this->security = $security;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @PostLoad
|
||||
*
|
||||
* 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
|
||||
* into the element properties, so that a user only gets non sensitve data.
|
||||
*
|
||||
*/
|
||||
public function postLoadHandler(DBElement $element, LifecycleEventArgs $event)
|
||||
{
|
||||
|
@ -75,19 +69,16 @@ class ElementPermissionListener
|
|||
$properties = $reflectionClass->getProperties();
|
||||
$reader = new AnnotationReader();
|
||||
|
||||
foreach($properties as $property)
|
||||
{
|
||||
foreach ($properties as $property) {
|
||||
/**
|
||||
* @var ColumnSecurity $annotation
|
||||
* @var ColumnSecurity
|
||||
*/
|
||||
$annotation = $reader->getPropertyAnnotation($property,
|
||||
ColumnSecurity::class);
|
||||
|
||||
if($annotation !== null)
|
||||
{
|
||||
if (null !== $annotation) {
|
||||
//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->setValue($element, $annotation->getPlaceholder());
|
||||
}
|
||||
|
@ -106,28 +97,23 @@ class ElementPermissionListener
|
|||
$properties = $reflectionClass->getProperties();
|
||||
$reader = new AnnotationReader();
|
||||
|
||||
foreach($properties as $property)
|
||||
{
|
||||
foreach ($properties as $property) {
|
||||
/**
|
||||
* @var ColumnSecurity $annotation
|
||||
* @var ColumnSecurity
|
||||
*/
|
||||
$annotation = $reader->getPropertyAnnotation($property,
|
||||
ColumnSecurity::class);
|
||||
|
||||
if($annotation !== null)
|
||||
{
|
||||
if (null !== $annotation) {
|
||||
$field_name = $property->getName();
|
||||
|
||||
//Check if user is allowed to edit info, otherwise overwrite the new value
|
||||
// so that nothing is changed in the DB.
|
||||
if($event->hasChangedField($field_name) &&
|
||||
!$this->security->isGranted($annotation->getEditOperationName(), $element))
|
||||
{
|
||||
if ($event->hasChangedField($field_name) &&
|
||||
!$this->security->isGranted($annotation->getEditOperationName(), $element)) {
|
||||
$event->setNewValue($field_name, $event->getOldValue($field_name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
|
||||
|
@ -26,15 +25,13 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Security\Interfaces;
|
||||
|
||||
|
||||
use App\Entity\PermissionsEmbed;
|
||||
|
||||
interface HasPermissionsInterface
|
||||
{
|
||||
public function getPermissions() : PermissionsEmbed;
|
||||
public function getPermissions(): PermissionsEmbed;
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Security\Voter;
|
||||
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Services\PermissionResolver;
|
||||
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.
|
||||
* @package App\Security\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 (!$user instanceof User) {
|
||||
$user = $this->entityManager->find(User::class, User::ID_ANONYMOUS);
|
||||
if($user === null) {
|
||||
if (null === $user) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -74,10 +70,12 @@ abstract class ExtendedVoter extends Voter
|
|||
/**
|
||||
* Similar to voteOnAttribute, but checking for the anonymous user is already done.
|
||||
* The current user (or the anonymous user) is passed by $user.
|
||||
*
|
||||
* @param $attribute
|
||||
* @param $subject
|
||||
* @param User $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function voteOnUser($attribute, $subject, User $user) : bool;
|
||||
abstract protected function voteOnUser($attribute, $subject, User $user): bool;
|
||||
}
|
|
@ -2,26 +2,18 @@
|
|||
|
||||
namespace App\Security\Voter;
|
||||
|
||||
use App\Configuration\PermissionsConfiguration;
|
||||
use App\Entity\Part;
|
||||
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\User\UserInterface;
|
||||
|
||||
|
||||
/**
|
||||
* A Voter that votes on Part entities.
|
||||
*
|
||||
* See parts permissions for valid operations.
|
||||
*
|
||||
* @package App\Security\Voter
|
||||
*/
|
||||
class PartVoter extends ExtendedVoter
|
||||
{
|
||||
const READ = "read";
|
||||
|
||||
const READ = 'read';
|
||||
|
||||
protected function supports($attribute, $subject)
|
||||
{
|
||||
|
@ -29,31 +21,28 @@ class PartVoter extends ExtendedVoter
|
|||
// https://symfony.com/doc/current/security/voters.html
|
||||
//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
|
||||
if(strpos($attribute, '.') !== false) {
|
||||
if (false !== strpos($attribute, '.')) {
|
||||
[$perm, $op] = explode('.', $attribute);
|
||||
|
||||
return in_array($op, $this->resolver->listOperationsForPermission('parts_'.$perm), false);
|
||||
}
|
||||
|
||||
|
||||
return in_array($attribute, $this->resolver->listOperationsForPermission('parts'), false);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected function voteOnUser($attribute, $subject, User $user): bool
|
||||
{
|
||||
if($subject instanceof Part) {
|
||||
|
||||
if ($subject instanceof Part) {
|
||||
//Check for sub permissions
|
||||
if(strpos($attribute, '.') !== false) {
|
||||
if (false !== strpos($attribute, '.')) {
|
||||
[$perm, $op] = explode('.', $attribute);
|
||||
return $this->resolver->inherit($user, 'parts_'. $perm, $op) ?? false;
|
||||
|
||||
return $this->resolver->inherit($user, 'parts_'.$perm, $op) ?? false;
|
||||
}
|
||||
|
||||
//Null concealing operator means, that no
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Security\Voter;
|
||||
|
||||
|
||||
use App\Entity\User;
|
||||
|
||||
class UserVoter extends ExtendedVoter
|
||||
{
|
||||
|
||||
/**
|
||||
* Determines if the attribute and subject are supported by this voter.
|
||||
*
|
||||
|
@ -47,8 +43,7 @@ class UserVoter extends ExtendedVoter
|
|||
*/
|
||||
protected function supports($attribute, $subject)
|
||||
{
|
||||
if($subject instanceof User)
|
||||
{
|
||||
if ($subject instanceof User) {
|
||||
return in_array($attribute, array_merge(
|
||||
$this->resolver->listOperationsForPermission('users'),
|
||||
$this->resolver->listOperationsForPermission('self')),
|
||||
|
@ -62,30 +57,30 @@ class UserVoter extends ExtendedVoter
|
|||
/**
|
||||
* Similar to voteOnAttribute, but checking for the anonymous user is already done.
|
||||
* The current user (or the anonymous user) is passed by $user.
|
||||
*
|
||||
* @param $attribute
|
||||
* @param $subject
|
||||
* @param User $user
|
||||
*
|
||||
* @return 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
|
||||
if($subject->getID() === $user->getID() &&
|
||||
if ($subject->getID() === $user->getID() &&
|
||||
$this->resolver->isValidOperation('self', $attribute)) {
|
||||
//Then we also need to check the self permission
|
||||
$tmp = $this->resolver->inherit($user, 'self', $attribute) ?? false;
|
||||
//But if the self value is not allowed then use just the user value:
|
||||
if($tmp)
|
||||
if ($tmp) {
|
||||
return $tmp;
|
||||
}
|
||||
}
|
||||
//Else just check users permission:
|
||||
return $this->resolver->inherit($user, 'users', $attribute) ?? false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
|
||||
use Symfony\Component\Asset\Packages;
|
||||
|
||||
class AttachmentFilenameService
|
||||
|
@ -43,13 +40,13 @@ class AttachmentFilenameService
|
|||
$this->package = $package;
|
||||
}
|
||||
|
||||
public function attachmentPathToAbsolutePath(?string $filename) : ?string
|
||||
public function attachmentPathToAbsolutePath(?string $filename): ?string
|
||||
{
|
||||
//Return placeholder if a part does not have an attachment
|
||||
if ($filename == null) {
|
||||
if (null == $filename) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
|
||||
use App\Entity\DBElement;
|
||||
use App\Entity\NamedDBElement;
|
||||
use App\Entity\Part;
|
||||
use App\Exceptions\EntityNotSupported;
|
||||
use Doctrine\Migrations\Finder\Exception\NameIsReserved;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
class EntityURLGenerator
|
||||
|
@ -53,15 +48,16 @@ class EntityURLGenerator
|
|||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return string The URL to the info page
|
||||
*
|
||||
* @throws EntityNotSupported If the method is not supported for the given Entity
|
||||
*/
|
||||
public function infoURL($entity) : string
|
||||
{
|
||||
if($entity instanceof Part)
|
||||
public function infoURL($entity): string
|
||||
{
|
||||
if ($entity instanceof Part) {
|
||||
return $this->urlGenerator->generate('part_info', ['id' => $entity->getID()]);
|
||||
}
|
||||
|
||||
|
@ -69,10 +65,9 @@ class EntityURLGenerator
|
|||
throw new EntityNotSupported('The given entity is not supported yet!');
|
||||
}
|
||||
|
||||
public function editURL($entity) : string
|
||||
{
|
||||
if($entity instanceof Part)
|
||||
public function editURL($entity): string
|
||||
{
|
||||
if ($entity instanceof Part) {
|
||||
return $this->urlGenerator->generate('part_edit', ['id' => $entity->getID()]);
|
||||
}
|
||||
|
||||
|
@ -80,20 +75,18 @@ class EntityURLGenerator
|
|||
throw new EntityNotSupported('The given entity is not supported yet!');
|
||||
}
|
||||
|
||||
public function createURL($entity) : string
|
||||
{
|
||||
if($entity instanceof Part)
|
||||
public function createURL($entity): string
|
||||
{
|
||||
if ($entity instanceof Part) {
|
||||
return $this->urlGenerator->generate('part_new');
|
||||
}
|
||||
|
||||
throw new EntityNotSupported('The given entity is not supported yet!');
|
||||
}
|
||||
|
||||
public function cloneURL($entity) : string
|
||||
{
|
||||
if($entity instanceof Part)
|
||||
public function cloneURL($entity): string
|
||||
{
|
||||
if ($entity instanceof Part) {
|
||||
return $this->urlGenerator->generate('part_clone', ['id' => $entity->getID()]);
|
||||
}
|
||||
|
||||
|
@ -102,20 +95,19 @@ class EntityURLGenerator
|
|||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return string The HTML of the info page link
|
||||
*
|
||||
* @throws EntityNotSupported
|
||||
*/
|
||||
public function infoHTML($entity) : string
|
||||
public function infoHTML($entity): string
|
||||
{
|
||||
$href = $this->infoURL($entity);
|
||||
|
||||
if($entity instanceof NamedDBElement)
|
||||
{
|
||||
if ($entity instanceof NamedDBElement) {
|
||||
return sprintf('<a href="%s">%s</a>', $href, $entity->getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
|
||||
use App\Configuration\PermissionsConfiguration;
|
||||
use App\Entity\User;
|
||||
use App\Security\Interfaces\HasPermissionsInterface;
|
||||
|
@ -43,20 +40,18 @@ class PermissionResolver
|
|||
{
|
||||
protected $permission_structure;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* PermissionResolver constructor.
|
||||
*
|
||||
* @param ParameterBagInterface $params
|
||||
*/
|
||||
public function __construct(ParameterBagInterface $params)
|
||||
{
|
||||
//Read the permission config file...
|
||||
$config = Yaml::parse(
|
||||
file_get_contents(__DIR__ . '/../../config/permissions.yaml')
|
||||
file_get_contents(__DIR__.'/../../config/permissions.yaml')
|
||||
);
|
||||
|
||||
|
||||
$configs = [$config];
|
||||
|
||||
//... And parse it
|
||||
|
@ -72,7 +67,6 @@ class PermissionResolver
|
|||
//dump($this->permission_structure);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a user/group is allowed to do the specified operation for the permission.
|
||||
*
|
||||
|
@ -81,10 +75,11 @@ class PermissionResolver
|
|||
* @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 $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,
|
||||
* if the value is set to inherit.
|
||||
*/
|
||||
public function dontInherit(HasPermissionsInterface $user, string $permission, string $operation) : ?bool
|
||||
public function dontInherit(HasPermissionsInterface $user, string $permission, string $operation): ?bool
|
||||
{
|
||||
//Get the permissions from the user
|
||||
$perm_list = $user->getPermissions();
|
||||
|
@ -95,7 +90,6 @@ class PermissionResolver
|
|||
return $perm_list->getPermissionValue($permission, $bit);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -107,24 +101,25 @@ class PermissionResolver
|
|||
* @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 $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,
|
||||
* if the value is set to inherit.
|
||||
*/
|
||||
public function inherit(User $user, string $permission, string $operation) : ?bool
|
||||
public function inherit(User $user, string $permission, string $operation): ?bool
|
||||
{
|
||||
//Check if we need to inherit
|
||||
$allowed = $this->dontInherit($user, $permission, $operation);
|
||||
|
||||
if ($allowed !== null) {
|
||||
if (null !== $allowed) {
|
||||
//Just return the value of the user.
|
||||
return $allowed;
|
||||
}
|
||||
|
||||
$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
|
||||
$allowed = $this->dontInherit($parent, $permission, $operation);
|
||||
if ($allowed !== null) {
|
||||
if (null !== $allowed) {
|
||||
return $allowed;
|
||||
}
|
||||
//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.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Lists the names of all operations that is supported for the given permission.
|
||||
*
|
||||
|
@ -143,9 +137,10 @@ class PermissionResolver
|
|||
* This function is useful for the support() function of the voters.
|
||||
*
|
||||
* @param string $permission The permission for which the
|
||||
*
|
||||
* @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
|
||||
{
|
||||
$operations = $this->permission_structure['perms'][$permission]['operations'];
|
||||
|
||||
|
@ -156,9 +151,10 @@ class PermissionResolver
|
|||
* Checks if the permission with the given name is existing.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
public function isValidPermission(string $permission) : bool
|
||||
public function isValidPermission(string $permission): bool
|
||||
{
|
||||
return isset($this->permission_structure['perms'][$permission]);
|
||||
}
|
||||
|
@ -168,13 +164,12 @@ class PermissionResolver
|
|||
*
|
||||
* @param string $permission The name of the permission 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.
|
||||
*/
|
||||
public function isValidOperation(string $permission, string $operation) : bool
|
||||
public function isValidOperation(string $permission, string $operation): bool
|
||||
{
|
||||
return $this->isValidPermission($permission) &&
|
||||
isset($this->permission_structure['perms'][$permission]['operations'][$operation]);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* part-db version 0.1
|
||||
* Copyright (C) 2005 Christoph Lechner
|
||||
* http://www.cl-projects.de/
|
||||
* http://www.cl-projects.de/.
|
||||
*
|
||||
* part-db version 0.2+
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
namespace App\Twig;
|
||||
|
||||
|
||||
use App\Entity\DBElement;
|
||||
use App\Services\EntityURLGenerator;
|
||||
use Symfony\Component\Cache\Adapter\AdapterInterface;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
use s9e\TextFormatter\Bundles\Forum as TextFormatter;
|
||||
|
||||
class AppExtension extends AbstractExtension
|
||||
|
@ -55,13 +51,13 @@ class AppExtension extends AbstractExtension
|
|||
{
|
||||
return [
|
||||
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']]),
|
||||
];
|
||||
}
|
||||
|
||||
public function generateEntityURL(DBElement $entity, string $method = 'info') : string
|
||||
public function generateEntityURL(DBElement $entity, string $method = 'info'): string
|
||||
{
|
||||
switch($method) {
|
||||
switch ($method) {
|
||||
case 'info':
|
||||
return $this->entityURLGenerator->infoURL($entity);
|
||||
case 'edit':
|
||||
|
@ -75,12 +71,14 @@ class AppExtension extends AbstractExtension
|
|||
throw new \InvalidArgumentException('method is not supported!');
|
||||
}
|
||||
|
||||
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));
|
||||
if(!$item->isHit()) {
|
||||
$item = $this->cache->getItem('bbcode_'.md5($bbcode));
|
||||
if (!$item->isHit()) {
|
||||
$xml = TextFormatter::parse($bbcode);
|
||||
$item->set(TextFormatter::render($xml));
|
||||
$this->cache->save($item);
|
||||
|
@ -88,5 +86,4 @@ class AppExtension extends AbstractExtension
|
|||
|
||||
return $item->get();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue