mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-20 17:15:51 +02:00
Added Doctrine Entities.
This commit is contained in:
parent
a0801afdbd
commit
160e826b51
20 changed files with 3400 additions and 1 deletions
2
.env
2
.env
|
@ -24,7 +24,7 @@ APP_SECRET=7915fd8481d1a52cf42010ebe2caa974
|
|||
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
|
||||
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
|
||||
# Configure your db driver and server_version in config/packages/doctrine.yaml
|
||||
DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_name
|
||||
DATABASE_URL=mysql://root:@127.0.0.1:3306/part-db
|
||||
###< doctrine/doctrine-bundle ###
|
||||
|
||||
###> symfony/swiftmailer-bundle ###
|
||||
|
|
30
src/Controller/HomepageController.php
Normal file
30
src/Controller/HomepageController.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
|
||||
use App\Entity\Attachment;
|
||||
use App\Entity\AttachmentType;
|
||||
use App\Entity\Category;
|
||||
use App\Entity\StructuralDBElement;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class HomepageController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @Route("/")
|
||||
*/
|
||||
function homepage()
|
||||
{
|
||||
$repo = $this->getDoctrine()->getRepository(Category::class);
|
||||
|
||||
/** @var StructuralDBElement $attachment */
|
||||
$attachment = $repo->find(1);
|
||||
|
||||
dump($attachment, $attachment->getSubelements(false)->toArray());
|
||||
$response = "";
|
||||
return $this->render('base.html.twig');
|
||||
}
|
||||
}
|
148
src/Entity/Attachment.php
Normal file
148
src/Entity/Attachment.php
Normal file
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* Part-DB Version 0.4+ "nextgen"
|
||||
* Copyright (C) 2016 - 2019 Jan Böhmer
|
||||
* 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
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* 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 Attachment
|
||||
* @package PartDB\Models
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="attachements")
|
||||
*/
|
||||
class Attachment extends NamedDBElement
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $show_in_table;
|
||||
|
||||
/**
|
||||
* @var string The filename using the %BASE% variable
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $filename;
|
||||
|
||||
/**
|
||||
* //TODO
|
||||
* //@ORM\ManyToOne(targetEntity="AttachmentContainingDBElement", inversedBy="attachment")
|
||||
* //@ORM\JoinColumn(name="element_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $element;
|
||||
|
||||
/**
|
||||
* @var AttachmentType
|
||||
* @ORM\ManyToOne(targetEntity="AttachmentType", inversedBy="attachments")
|
||||
* @ORM\JoinColumn(name="type_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $attachement_type;
|
||||
|
||||
/***********************************************************
|
||||
* Various function
|
||||
***********************************************************/
|
||||
|
||||
/**
|
||||
* Check if this attachement is a picture (analyse the file's extension)
|
||||
*
|
||||
* @return boolean @li true if the file extension is a picture extension
|
||||
* @li otherwise false
|
||||
*/
|
||||
public function isPicture() : bool
|
||||
{
|
||||
$extension = pathinfo($this->getFilename(), PATHINFO_EXTENSION);
|
||||
|
||||
// list all file extensions which are supported to display them by HTML code
|
||||
$picture_extensions = array('gif', 'png', 'jpg', 'jpeg', 'bmp', 'svg', 'tif');
|
||||
|
||||
return in_array(strtolower($extension), $picture_extensions, true);
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Getters
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Get the element, associated with this Attachement (for example a "Part" object)
|
||||
* @return DBElement The associated Element.
|
||||
*/
|
||||
public function getElement() : AttachmentContainingDBElement
|
||||
{
|
||||
return $this->element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the file in this attachement is existing. This works for files on the HDD, and for URLs
|
||||
* (it's not checked if the ressource behind the URL is really existing).
|
||||
*
|
||||
* @return bool True if the file is existing.
|
||||
*/
|
||||
public function isFileExisting() : bool
|
||||
{
|
||||
return file_exists($this->getFilename()) || isURL($this->getFilename());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filename (absolute path from filesystem root, as a UNIX path [only slashes])
|
||||
*
|
||||
* @return string the filename as an absolute UNIX filepath from filesystem root
|
||||
*/
|
||||
public function getFilename() : string
|
||||
{
|
||||
return str_replace('%BASE%', BASE, $this->filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
return (bool) $this->show_in_table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of this attachement
|
||||
* @return AttachmentType the type of this attachement
|
||||
* @throws Exception if there was an error
|
||||
*/
|
||||
public function getType() : AttachmentType
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
}
|
91
src/Entity/AttachmentContainingDBElement.php
Normal file
91
src/Entity/AttachmentContainingDBElement.php
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* Part-DB Version 0.4+ "nextgen"
|
||||
* Copyright (C) 2016 - 2019 Jan Böhmer
|
||||
* 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
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @ORM\MappedSuperclass()
|
||||
*/
|
||||
abstract class AttachmentContainingDBElement extends NamedDBElement
|
||||
{
|
||||
/**
|
||||
* @var
|
||||
* //TODO
|
||||
* //@ORM\OneToMany(targetEntity="Attachment", mappedBy="element")
|
||||
*/
|
||||
protected $attachment;
|
||||
|
||||
//TODO
|
||||
protected $attachmentTypes;
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Getters
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
return $this->attachmentTypes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all attachements of this element / Get the element's attachements with a specific type
|
||||
*
|
||||
* @param integer $type_id @li if NULL, all attachements of this element will be returned
|
||||
* @li 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"
|
||||
*
|
||||
* @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
|
||||
{
|
||||
if ($only_table_attachements || $type_id) {
|
||||
$attachements = $this->attachments;
|
||||
|
||||
foreach ($attachements as $key => $attachement) {
|
||||
if (($only_table_attachements && (! $attachement->getShowInTable()))
|
||||
|| ($type_id && ($attachement->getType()->getID() != $type_id))) {
|
||||
unset($attachements[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $attachements;
|
||||
} else {
|
||||
return $this->attachments;
|
||||
}
|
||||
}
|
||||
}
|
82
src/Entity/AttachmentType.php
Normal file
82
src/Entity/AttachmentType.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* Part-DB Version 0.4+ "nextgen"
|
||||
* Copyright (C) 2016 - 2019 Jan Böhmer
|
||||
* 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
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* 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\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class AttachmentType
|
||||
* @package PartDB\Models
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table(name="attachement_types")
|
||||
*/
|
||||
class AttachmentType extends StructuralDBElement
|
||||
{
|
||||
/**
|
||||
* @var ArrayCollection
|
||||
* @ORM\OneToMany(targetEntity="Attachment", mappedBy="attachement_type")
|
||||
*/
|
||||
protected $attachments = null;
|
||||
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="AttachmentType", mappedBy="parent")
|
||||
*/
|
||||
protected $children;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="AttachmentType", inversedBy="children")
|
||||
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
// the attribute $this->attachements is used from class "AttachementsContainingDBELement"
|
||||
if ($this->attachments == null) {
|
||||
$this->attachments = new ArrayCollection();
|
||||
}
|
||||
|
||||
return $this->attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 "";
|
||||
//return 'AT' . sprintf('%09d', $this->getID());
|
||||
}
|
||||
}
|
110
src/Entity/Category.php
Normal file
110
src/Entity/Category.php
Normal file
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* Part-DB Version 0.4+ "nextgen"
|
||||
* Copyright (C) 2016 - 2019 Jan Böhmer
|
||||
* 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
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* 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 AttachmentType
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="categories")
|
||||
*/
|
||||
class Category extends PartsContainingDBElement
|
||||
{
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
|
||||
*/
|
||||
protected $children;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Category", inversedBy="children")
|
||||
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Part", mappedBy="category")
|
||||
*/
|
||||
protected $parts;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $partname_hint;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $partname_regex;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $disable_footprints;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $disable_manufacturers;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $disable_autodatasheets;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $disable_properties;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $default_description;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
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());
|
||||
}
|
||||
}
|
211
src/Entity/Company.php
Normal file
211
src/Entity/Company.php
Normal file
|
@ -0,0 +1,211 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* Part-DB Version 0.4+ "nextgen"
|
||||
* Copyright (C) 2016 - 2019 Jan Böhmer
|
||||
* 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
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* 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
|
||||
{
|
||||
/**
|
||||
* @var string The address of the company
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $address;
|
||||
|
||||
/**
|
||||
* @var string The phone number of the company
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $phone_number;
|
||||
|
||||
/**
|
||||
* @var string The fax number of the company
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $fax_number;
|
||||
|
||||
/**
|
||||
* @var string The email address of the company
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $email_address;
|
||||
|
||||
/**
|
||||
* @var string The website of the company
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $website;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $auto_product_url;
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Getters
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Get the address
|
||||
*
|
||||
* @return string the address of the company (with "\n" as line break)
|
||||
*/
|
||||
public function getAddress() : string
|
||||
{
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the phone number
|
||||
*
|
||||
* @return string the phone number of the company
|
||||
*/
|
||||
public function getPhoneNumber() : string
|
||||
{
|
||||
return $this->phone_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fax number
|
||||
*
|
||||
* @return string the fax number of the company
|
||||
*/
|
||||
public function getFaxNumber() : string
|
||||
{
|
||||
return $this->fax_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the e-mail address
|
||||
*
|
||||
* @return string the e-mail address of the company
|
||||
*/
|
||||
public function getEmailAddress() : string
|
||||
{
|
||||
return $this->email_address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the website
|
||||
*
|
||||
* @return string the website of the company
|
||||
*/
|
||||
public function getWebsite() : string
|
||||
{
|
||||
return $this->website;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the link to the website of an article
|
||||
*
|
||||
* @param string $partnr @li NULL for returning the URL with a placeholder for the part number
|
||||
* @li 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
|
||||
{
|
||||
if (\is_string($partnr)) {
|
||||
return str_replace('%PARTNUMBER%', $partnr, $this->auto_product_url);
|
||||
}
|
||||
return $this->auto_product_url;
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Setters
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Set the addres
|
||||
* @param string $new_address the new address (with "\n" as line break)
|
||||
*/
|
||||
public function setAddress(string $new_address)
|
||||
{
|
||||
$this->address = $new_address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the phone number
|
||||
*
|
||||
* @param string $new_phone_number the new phone number
|
||||
*/
|
||||
public function setPhoneNumber(string $new_phone_number)
|
||||
{
|
||||
$this->phone_number = $new_phone_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the fax number
|
||||
*
|
||||
* @param string $new_fax_number the new fax number
|
||||
*/
|
||||
public function setFaxNumber(string $new_fax_number)
|
||||
{
|
||||
$this->fax_number = $new_fax_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the e-mail address
|
||||
*
|
||||
* @param string $new_email_address the new e-mail address
|
||||
|
||||
*/
|
||||
public function setEmailAddress(string $new_email_address)
|
||||
{
|
||||
$this->email_address = $new_email_address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the website
|
||||
*
|
||||
* @param string $new_website the new website
|
||||
*/
|
||||
public function setWebsite(string $new_website)
|
||||
{
|
||||
$this->website = $new_website;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the link to the website of an article
|
||||
*
|
||||
* @param string $new_url the new URL with the placeholder %PARTNUMBER% for the part number
|
||||
*
|
||||
*/
|
||||
public function setAutoProductUrl(string $new_url)
|
||||
{
|
||||
$this->auto_product_url = $new_url;
|
||||
}
|
||||
|
||||
}
|
66
src/Entity/DBElement.php
Normal file
66
src/Entity/DBElement.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* Part-DB Version 0.4+ "nextgen"
|
||||
* Copyright (C) 2016 - 2019 Jan Böhmer
|
||||
* 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
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* 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 class is for managing all database objects.
|
||||
*
|
||||
* You should use this class for ALL classes which manages database records!
|
||||
* (except special tables like "internal"...)
|
||||
* Every database table which are managed with this class (or a subclass of it)
|
||||
* must have the table row "id"!! The ID is the unique key to identify the elements.
|
||||
*
|
||||
* @ORM\MappedSuperclass()
|
||||
*/
|
||||
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()
|
||||
* @ORM\GeneratedValue()
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* Get the ID. The ID can be zero, or even negative (for virtual elements). If an elemenent is virtual, can be
|
||||
* checked with isVirtualElement()
|
||||
*
|
||||
* @return integer the ID of this element
|
||||
*/
|
||||
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;
|
||||
|
||||
}
|
111
src/Entity/Device.php
Normal file
111
src/Entity/Device.php
Normal file
|
@ -0,0 +1,111 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class AttachmentType
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table(name="devices")
|
||||
*/
|
||||
class Device extends PartsContainingDBElement
|
||||
{
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
|
||||
*/
|
||||
protected $children;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Category", inversedBy="children")
|
||||
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Column(type="integer")
|
||||
*
|
||||
*/
|
||||
protected $order_quantity;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $order_only_missing_parts;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="DevicePart", mappedBy="device")
|
||||
*/
|
||||
protected $parts;
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Getters
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Get the order quantity of this device
|
||||
*
|
||||
* @return integer the order quantity
|
||||
*/
|
||||
public function getOrderQuantity() : int
|
||||
{
|
||||
return $this->order_quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the "order_only_missing_parts" attribute
|
||||
*
|
||||
* @return boolean the "order_only_missing_parts" attribute
|
||||
*/
|
||||
public function getOrderOnlyMissingParts() : bool
|
||||
{
|
||||
return $this->order_only_missing_parts;
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Setters
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Set the order quantity
|
||||
*
|
||||
* @param integer $new_order_quantity the new order quantity
|
||||
*/
|
||||
public function setOrderQuantity(int $new_order_quantity)
|
||||
{
|
||||
if($new_order_quantity < 0)
|
||||
{
|
||||
throw new \InvalidArgumentException("The new order quantity must not be negative!");
|
||||
}
|
||||
$this->order_quantity = $new_order_quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the "order_only_missing_parts" attribute
|
||||
*
|
||||
* @param boolean $new_order_only_missing_parts the new "order_only_missing_parts" attribute
|
||||
*
|
||||
*/
|
||||
public function setOrderOnlyMissingParts(bool $new_order_only_missing_parts)
|
||||
{
|
||||
$this->order_only_missing_parts = $new_order_only_missing_parts;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
}
|
42
src/Entity/DevicePart.php
Normal file
42
src/Entity/DevicePart.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: janhb
|
||||
* Date: 23.02.2019
|
||||
* Time: 18:55
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class DevicePart
|
||||
* @package App\Entity
|
||||
*
|
||||
* @ORM\Table("device_parts")
|
||||
* @ORM\Entity()
|
||||
*/
|
||||
class DevicePart extends DBElement
|
||||
{
|
||||
/**
|
||||
* @var Device
|
||||
* @ORM\ManyToOne(targetEntity="Device", inversedBy="parts")
|
||||
* @ORM\JoinColumn(name="id_device", referencedColumnName="id")
|
||||
*/
|
||||
protected $device;
|
||||
|
||||
//TODO
|
||||
protected $part;
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
}
|
192
src/Entity/Footprint.php
Normal file
192
src/Entity/Footprint.php
Normal file
|
@ -0,0 +1,192 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: janhb
|
||||
* Date: 23.02.2019
|
||||
* Time: 19:02
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class Footprint
|
||||
* @package App\Entity
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table("footprints")
|
||||
*/
|
||||
class Footprint extends PartsContainingDBElement
|
||||
{
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Footprint", mappedBy="parent")
|
||||
*/
|
||||
protected $children;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Footprint", inversedBy="children")
|
||||
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $filename;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Part", mappedBy="footprint")
|
||||
*/
|
||||
protected $parts;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $filename_3d;
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
|
||||
/****************************************
|
||||
* Getters
|
||||
****************************************/
|
||||
|
||||
/**
|
||||
* Get the filename of the picture (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.
|
||||
* @return string @li the absolute path to the picture (from filesystem root), as a UNIX path (with slashes)
|
||||
* @li an empty string if there is no picture
|
||||
*/
|
||||
public function getFilename(bool $absolute = true) : string
|
||||
{
|
||||
if ($absolute == true) {
|
||||
//TODO
|
||||
throw new \Exception("Not Implemented yet...");
|
||||
//return str_replace('%BASE%', BASE, $this->db_data['filename']);
|
||||
} else {
|
||||
return $this->filename;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return string @li the absolute path to the model (from filesystem root), as a UNIX path (with slashes)
|
||||
* @li an empty string if there is no model
|
||||
*/
|
||||
public function get3dFilename(bool $absolute = true) : string
|
||||
{
|
||||
if ($absolute == true) {
|
||||
//TODO
|
||||
throw new \Exception("Not Implemented yet...");
|
||||
//return str_replace('%BASE%', BASE, $this->db_data['filename_3d']);
|
||||
} else {
|
||||
return $this->filename_3d;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()).
|
||||
*
|
||||
* @note An empty filename is a valid filename.
|
||||
*
|
||||
* @return boolean @li true if file exists or filename is empty
|
||||
* @li false if there is no file with this filename
|
||||
*/
|
||||
public function isFilenameValid() : bool
|
||||
{
|
||||
if (empty($this->getFilename())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return file_exists($this->getFilename());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()).
|
||||
*
|
||||
* @note An empty filename is a valid filename.
|
||||
*
|
||||
* @return boolean @li true if file exists or filename is empty
|
||||
* @li false if there is no file with this filename
|
||||
*/
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return file_exists($this->get3dFilename());
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Setters
|
||||
****************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Setters
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Change the filename of this footprint
|
||||
*
|
||||
* @note The filename won't be checked if it is valid.
|
||||
* It's not really a Problem if there is no such file...
|
||||
* (For this purpose we have the method Footprint::get_broken_filename_footprints())
|
||||
*
|
||||
* @param string $new_filename @li the new filename (absolute path from filesystem root, as a UNIX path [only slashes!] !! )
|
||||
* @li see also lib.functions.php::to_unix_path()
|
||||
*
|
||||
* @warning It's really important that you pass the whole (UNIX) path from filesystem root!
|
||||
* If the file is located in the base directory of Part-DB, the base path
|
||||
* will be automatically replaced with a placeholder before write it in the database.
|
||||
* This way, the filenames are still correct if the installation directory
|
||||
* of Part-DB is moved.
|
||||
*
|
||||
* @note The path-replacing will be done in Footprint::check_values_validity(), not here.
|
||||
*
|
||||
* @throws Exception if there was an error
|
||||
*/
|
||||
public function setFilename(string $new_filename)
|
||||
{
|
||||
$this->filename = $new_filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the 3d model filename of this footprint
|
||||
* @throws Exception if there was an error
|
||||
*/
|
||||
public function set3dFilename(string $new_filename)
|
||||
{
|
||||
$this->filename = $new_filename;
|
||||
}
|
||||
}
|
47
src/Entity/Manufacturer.php
Normal file
47
src/Entity/Manufacturer.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: janhb
|
||||
* Date: 23.02.2019
|
||||
* Time: 19:11
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class Manufacturer
|
||||
* @package App\Entity
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table("manufacturers")
|
||||
*/
|
||||
class Manufacturer extends Company
|
||||
{
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Manufacturer", mappedBy="parent")
|
||||
*/
|
||||
protected $children;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Manufacturer", inversedBy="children")
|
||||
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Part", mappedBy="manufacturer")
|
||||
*/
|
||||
protected $parts;
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
}
|
114
src/Entity/NamedDBElement.php
Normal file
114
src/Entity/NamedDBElement.php
Normal file
|
@ -0,0 +1,114 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* Part-DB Version 0.4+ "nextgen"
|
||||
* Copyright (C) 2016 - 2019 Jan Böhmer
|
||||
* 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
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* All subclasses of this class have an attribute "name".
|
||||
*
|
||||
* @ORM\MappedSuperclass()
|
||||
*/
|
||||
abstract class NamedDBElement extends DBElement
|
||||
{
|
||||
/**
|
||||
* @var string The name of this element.
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @var \DateTime The date when this element was modified the last time.
|
||||
* @ORM\Column(type="datetimetz", name="last_modified")
|
||||
*/
|
||||
protected $lastModified;
|
||||
|
||||
/**
|
||||
* @var \DateTime The date when this element was created.
|
||||
* @ORM\Column(type="datetimetz", name="datetime_added")
|
||||
*/
|
||||
protected $addedDate;
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Getters
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Get the name
|
||||
*
|
||||
* @return string the name of this element
|
||||
*/
|
||||
public function getName() : string
|
||||
{
|
||||
//Strip HTML from Name, so no XSS injection is possible.
|
||||
return strip_tags($this->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last time when the element was modified.
|
||||
* @param $formatted bool When true, the date gets formatted with the locale and timezone settings.
|
||||
* When false, the raw value from the DB is returned.
|
||||
* @return string The time of the last edit.
|
||||
*/
|
||||
public function getLastModified(bool $formatted = true) : string
|
||||
{
|
||||
//TODO
|
||||
return "TODO";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date/time when the element was created.
|
||||
* @param $formatted bool When true, the date gets formatted with the locale and timezone settings.
|
||||
* When false, the raw value from the DB is returned.
|
||||
* @return string The creation time of the part.
|
||||
*/
|
||||
public function getDatetimeAdded(bool $formatted = true) : string
|
||||
{
|
||||
//TODO
|
||||
return "TODO";
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Setters
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Change the name of this element
|
||||
*
|
||||
* @note 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
|
||||
*/
|
||||
public function setName(string $new_name)
|
||||
{
|
||||
$this->name = $new_name;
|
||||
}
|
||||
|
||||
}
|
266
src/Entity/Orderdetail.php
Normal file
266
src/Entity/Orderdetail.php
Normal file
|
@ -0,0 +1,266 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: janhb
|
||||
* Date: 23.02.2019
|
||||
* Time: 19:14
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class Orderdetail
|
||||
* @package App\Entity
|
||||
*
|
||||
* @ORM\Table("oderdetails")
|
||||
* @ORM\Entity()
|
||||
*/
|
||||
class Orderdetail extends DBElement
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Part
|
||||
* @ORM\ManyToOne(targetEntity="Part", inversedBy="orderdetails")
|
||||
* @ORM\JoinColumn(name="part_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $part;
|
||||
|
||||
/**
|
||||
* @var Supplier
|
||||
* @ORM\ManyToOne(targetEntity="Supplier", inversedBy="orderdetails")
|
||||
* @ORM\JoinColumn(name="id_supplier", referencedColumnName="id")
|
||||
*/
|
||||
protected $supplier;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Pricedetail", mappedBy="orderdetail")
|
||||
*/
|
||||
protected $pricedetails;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $supplierpartnr;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $obsolete;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $supplier_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 'O' . sprintf('%06d', $this->getID());
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Getters
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Get the part
|
||||
*
|
||||
* @return Part the part of this orderdetails
|
||||
*/
|
||||
public function getPart() : Part
|
||||
{
|
||||
return $this->part;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the supplier
|
||||
*
|
||||
* @return Supplier the supplier of this orderdetails
|
||||
*
|
||||
* @throws DatabaseException if there was an error
|
||||
*/
|
||||
public function getSupplier() : Supplier
|
||||
{
|
||||
return $this->supplier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the supplier part-nr.
|
||||
*
|
||||
* @return string the part-nr.
|
||||
*/
|
||||
public function getSupplierPartNr() : string
|
||||
{
|
||||
return $this->supplierpartnr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 @li true if this part is obsolete at that supplier
|
||||
* @li false if this part isn't obsolete at that supplier
|
||||
*/
|
||||
public function getObsolete() : bool
|
||||
{
|
||||
return (bool) $this->obsolete;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the link to the website of the article on the suppliers website.
|
||||
*
|
||||
* @param $no_automatic_url bool Set this to true, if you only want to get the local set product URL for this Orderdetail
|
||||
* and not a automatic generated one, based from the Supplier
|
||||
*
|
||||
* @return string the link to the article
|
||||
*/
|
||||
public function getSupplierProductUrl(bool $no_automatic_url = false) : string
|
||||
{
|
||||
if ($no_automatic_url || $this->supplierpartnr != '') {
|
||||
return $this->supplierpartnr;
|
||||
} else {
|
||||
return $this->getSupplier()->getAutoProductUrl($this->supplierpartnr);
|
||||
} // maybe an automatic url is available...
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
return $this->pricedetails;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the price for a specific quantity
|
||||
*
|
||||
* @param boolean $as_money_string @li if true, this method returns a money string incl. currency
|
||||
* @li 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 @li This is the multiplier which will be applied to every single price
|
||||
* @li 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")
|
||||
* * null: if there are no prices and "$as_money_string == false"
|
||||
* * string: the price as a string incl. currency (if "$as_money_string == true")
|
||||
*
|
||||
* @throws Exception if there are no pricedetails for the choosed quantity
|
||||
* (for example, there are only one pricedetails with the minimum discount quantity '10',
|
||||
* but the choosed quantity is '5' --> the price for 5 parts is not defined!)
|
||||
* @throws Exception if there was an error
|
||||
*
|
||||
* @see floatToMoneyString()
|
||||
*/
|
||||
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);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
$all_pricedetails = $this->getPricedetails();
|
||||
|
||||
if (count($all_pricedetails) == 0) {
|
||||
if ($as_money_string) {
|
||||
return floatToMoneyString(null);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($all_pricedetails as $pricedetails) {
|
||||
// choose the correct pricedetails for the choosed quantity ($quantity)
|
||||
if ($quantity < $pricedetails->getMinDiscountQuantity()) {
|
||||
break;
|
||||
}
|
||||
|
||||
$correct_pricedetails = $pricedetails;
|
||||
}
|
||||
|
||||
if (! isset($correct_pricedetails) || (! \is_object($correct_pricedetails))) {
|
||||
throw new Exception(_('Es sind keine Preisinformationen für die angegebene Bestellmenge vorhanden!'));
|
||||
}
|
||||
|
||||
if ($multiplier === null) {
|
||||
$multiplier = $quantity;
|
||||
}
|
||||
|
||||
return $correct_pricedetails->getPrice($as_money_string, $multiplier);
|
||||
* */
|
||||
//TODO
|
||||
throw new \Exception("Not implemented yet...");
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Setters
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Set the supplier ID
|
||||
*
|
||||
* @param integer $new_supplier_id the ID of the new supplier
|
||||
|
||||
*/
|
||||
public function setSupplierId(int $new_supplier_id)
|
||||
{
|
||||
throw new \Exception("Not implemented yet!");
|
||||
//TODO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the supplier part-nr.
|
||||
*
|
||||
* @param string $new_supplierpartnr the new supplier-part-nr
|
||||
*
|
||||
*/
|
||||
public function setSupplierpartnr(string $new_supplierpartnr)
|
||||
{
|
||||
$this->supplierpartnr = $new_supplierpartnr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the part is obsolete at the supplier of that orderdetails
|
||||
*
|
||||
* @param boolean $new_obsolete true means that this part is obsolete
|
||||
*/
|
||||
public function setObsolete(bool $new_obsolete)
|
||||
{
|
||||
$this->obsolete = $new_obsolete;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @throws Exception if there was an error
|
||||
*/
|
||||
public function setSupplierProductUrl(string $new_url)
|
||||
{
|
||||
$this->setAttributes(array('supplier_product_url' => $new_url));
|
||||
}
|
||||
}
|
1050
src/Entity/Part.php
Normal file
1050
src/Entity/Part.php
Normal file
File diff suppressed because it is too large
Load diff
39
src/Entity/PartsContainingDBElement.php
Normal file
39
src/Entity/PartsContainingDBElement.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* Part-DB Version 0.4+ "nextgen"
|
||||
* Copyright (C) 2016 - 2019 Jan Böhmer
|
||||
* 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
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* 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\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class PartsContainingDBElement
|
||||
* @package PartDB\Models
|
||||
*
|
||||
* @ORM\MappedSuperclass()
|
||||
*/
|
||||
abstract class PartsContainingDBElement extends StructuralDBElement
|
||||
{
|
||||
|
||||
protected $parts;
|
||||
}
|
214
src/Entity/Pricedetail.php
Normal file
214
src/Entity/Pricedetail.php
Normal file
|
@ -0,0 +1,214 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: janhb
|
||||
* Date: 23.02.2019
|
||||
* Time: 19:21
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class Pricedetail
|
||||
* @package App\Entity
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table("pricedetails")
|
||||
*/
|
||||
class Pricedetail extends DBElement
|
||||
{
|
||||
/**
|
||||
* @var Orderdetail
|
||||
* @ORM\ManyToOne(targetEntity="Orderdetail", inversedBy="pricedetails")
|
||||
* @ORM\JoinColumn(name="orderdetails_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $orderdetail;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
* @ORM\Column(type="decimal", precision=11, scale=5)
|
||||
*/
|
||||
protected $price;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
protected $price_related_quantity;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
protected $min_discount_quantity;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $manual_input;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetimetz")
|
||||
*/
|
||||
protected $last_modified;
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Getters
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Get the orderdetails of this pricedetails
|
||||
*
|
||||
* @return Orderdetail the orderdetails object
|
||||
*
|
||||
*/
|
||||
public function getOrderdetails() : Orderdetail
|
||||
{
|
||||
return $this->orderdetail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the price
|
||||
*
|
||||
* @param boolean $as_money_string @li if true, this method returns a money string incl. currency
|
||||
* @li if false, this method returns the price as float
|
||||
* @param integer $multiplier The returned price (float or string) will be multiplied
|
||||
* with this multiplier.
|
||||
*
|
||||
* @note You will get the price for $multiplier parts. If you want the price which is stored
|
||||
* in the database, you have to pass the "price_related_quantity" count as $multiplier.
|
||||
*
|
||||
* @return float the price as a float number (if "$as_money_string == false")
|
||||
* @return string the price as a string incl. currency (if "$as_money_string == true")
|
||||
*
|
||||
* @see floatToMoneyString()
|
||||
*/
|
||||
public function getPrice(bool $as_money_string = false, int $multiplier = 1)
|
||||
{
|
||||
$price = ($this->price * $multiplier) / $this->price_related_quantity;
|
||||
|
||||
if ($as_money_string) {
|
||||
throw new \Exception("Not implemented yet...");
|
||||
//return floatToMoneyString($price);
|
||||
} else {
|
||||
return $price;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the price related quantity
|
||||
*
|
||||
* This is the quantity, for which the price is valid.
|
||||
*
|
||||
* @return integer the price related quantity
|
||||
*
|
||||
* @see Pricedetails::setPriceRelatedQuantity()
|
||||
*/
|
||||
public function getPriceRelatedQuantity() : int
|
||||
{
|
||||
return (int) $this->price_related_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
|
||||
*
|
||||
* @see Pricedetails::setMinDiscountQuantity()
|
||||
*/
|
||||
public function getMinDiscountQuantity() : int
|
||||
{
|
||||
return (int) $this->min_discount_quantity;
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Setters
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Set the price
|
||||
*
|
||||
* @param float $new_price the new price as a float number
|
||||
*
|
||||
* @warning @li This is the price for "price_related_quantity" parts!!
|
||||
* @li Example: if "price_related_quantity" is '10',
|
||||
* you have to set here the price for 10 parts!
|
||||
*/
|
||||
public function setPrice(float $new_price) : void
|
||||
{
|
||||
if($new_price < 0)
|
||||
{
|
||||
throw new \InvalidArgumentException('$new_price must be positive!');
|
||||
}
|
||||
$this->price = $new_price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the price related quantity
|
||||
*
|
||||
* This is the quantity, for which the price is valid.
|
||||
*
|
||||
* @par Example:
|
||||
* 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
|
||||
*/
|
||||
public function setPriceRelatedQuantity(int $new_price_related_quantity) : void
|
||||
{
|
||||
if($new_price_related_quantity <= 0) {
|
||||
throw new \InvalidArgumentException('$new_price_related_quantity must be greater 0!');
|
||||
}
|
||||
$this->price_related_quantity = $new_price_related_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
|
||||
* for different order quantities (quantity discount!).
|
||||
*
|
||||
* @par Example:
|
||||
* - 1-9pcs costs 10$: set price to 10$/pcs and minimum discount quantity to 1
|
||||
* - 10-99pcs costs 9$: set price to 9$/pcs and minimum discount quantity to 10
|
||||
* - 100pcs or more costs 8$: set price/pcs to 8$ and minimum discount quantity to 100
|
||||
*
|
||||
* (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
|
||||
*/
|
||||
public function setMinDiscountQuantity(int $new_min_discount_quantity)
|
||||
{
|
||||
if($new_min_discount_quantity <= 0 ){
|
||||
throw new \InvalidArgumentException('$new_min_discount_quantity must be positive!');
|
||||
}
|
||||
$this->min_discount_quantity = $new_min_discount_quantity;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
}
|
89
src/Entity/Storelocation.php
Normal file
89
src/Entity/Storelocation.php
Normal file
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class Storelocation
|
||||
* @package App\Entity
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table("storelocations")
|
||||
*/
|
||||
class Storelocation extends PartsContainingDBElement
|
||||
{
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Storelocation", mappedBy="parent")
|
||||
*/
|
||||
protected $children;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Storelocation", inversedBy="children")
|
||||
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Part", mappedBy="storelocation")
|
||||
*/
|
||||
protected $parts;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
protected $is_full;
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Getters
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Get the "is full" attribute
|
||||
*
|
||||
* @note "is_full == true" means that there is no more space in this storelocation.
|
||||
* @note This attribute is only for information, it has no effect.
|
||||
*
|
||||
* @return boolean @li true if the storelocation is full
|
||||
* @li false if the storelocation isn't full
|
||||
*/
|
||||
public function getIsFull() : bool
|
||||
{
|
||||
return (bool) $this->is_full;
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Setters
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* Change the "is full" attribute of this storelocation
|
||||
*
|
||||
* @note "is_full" = true means that there is no more space in this storelocation.
|
||||
* @note This attribute is only for information, it has no effect.
|
||||
*
|
||||
* @param boolean $new_is_full @li true means that the storelocation is full
|
||||
* @li false means that the storelocation isn't full
|
||||
*
|
||||
* @throws Exception if there was an error
|
||||
*/
|
||||
public function setIsFull(bool $new_is_full) : void
|
||||
{
|
||||
$this->is_full = $new_is_full;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
}
|
416
src/Entity/StructuralDBElement.php
Normal file
416
src/Entity/StructuralDBElement.php
Normal file
|
@ -0,0 +1,416 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* Part-DB Version 0.4+ "nextgen"
|
||||
* Copyright (C) 2016 - 2019 Jan Böhmer
|
||||
* 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
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* 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\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\ORM\PersistentCollection;
|
||||
use Symfony\Bundle\MakerBundle\Str;
|
||||
|
||||
/**
|
||||
*
|
||||
* 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)!
|
||||
* The root node has always the ID '0'.
|
||||
* It's allowed to have instances of root elements, but if you try to change
|
||||
* an attribute of a root element, you will get an exception!
|
||||
*
|
||||
* @ORM\MappedSuperclass()
|
||||
*/
|
||||
abstract class StructuralDBElement extends AttachmentContainingDBElement
|
||||
{
|
||||
const ID_ROOT_ELEMENT = 0;
|
||||
|
||||
//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
|
||||
/**
|
||||
* @var StructuralDBElement[]
|
||||
*/
|
||||
protected $children;
|
||||
/**
|
||||
* @var StructuralDBElement
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* @var string The comment info for this element
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $comment;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
protected $parent_id;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
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 */
|
||||
private $full_path_strings = null;
|
||||
|
||||
/******************************************************************************
|
||||
* StructuralDBElement constructor.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* 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)!
|
||||
*
|
||||
* @return bool True, if this element is child of $another_element.
|
||||
*
|
||||
* @throws \InvalidArgumentException if there was an error
|
||||
*/
|
||||
public function isChildOf(StructuralDBElement $another_element)
|
||||
{
|
||||
$class_name = \get_class($this);
|
||||
|
||||
//Check if both elements compared, are from the same type:
|
||||
if ($class_name != \get_class($another_element)) {
|
||||
throw new \InvalidArgumentException(_('isChildOf() funktioniert nur mit Elementen des gleichen Typs!'));
|
||||
}
|
||||
|
||||
if ($this->getID() == null) { // this is the root node
|
||||
return false;
|
||||
} else {
|
||||
//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
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief Get the parent-ID
|
||||
*
|
||||
* @retval integer @li the ID of the parent element
|
||||
* @li NULL means, the parent is the root node
|
||||
* @li the parent ID of the root node is -1
|
||||
*/
|
||||
public function getParentID() : int
|
||||
{
|
||||
return $this->parent_id ?? self::ID_ROOT_ELEMENT; //Null means root element
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the comment of the element.
|
||||
*
|
||||
* @param boolean $parse_bbcode Should BBCode converted to HTML, before returning
|
||||
* @return string the comment
|
||||
*/
|
||||
public function getComment(bool $parse_bbcode = true) : string
|
||||
{
|
||||
$val = htmlspecialchars($this->comment ?? '');
|
||||
if ($parse_bbcode) {
|
||||
//$bbcode = new BBCodeParser();
|
||||
//$val = $bbcode->parse($val);
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the level
|
||||
*
|
||||
* @note The level of the root node is -1.
|
||||
*
|
||||
* @return integer the level of this element (zero means a most top element
|
||||
* [a subelement of the root node])
|
||||
*
|
||||
*/
|
||||
public function getLevel() : int
|
||||
{
|
||||
if ($this->level === 0) {
|
||||
$element = $this->parent;
|
||||
$parent_id = $element->getParentID();
|
||||
while ($parent_id > 0) {
|
||||
/** @var StructuralDBElement $element */
|
||||
$element = $element->parent;
|
||||
$parent_id = $element->getParentID();
|
||||
$this->level++;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full path
|
||||
*
|
||||
* @param string $delimeter the delimeter of the returned string
|
||||
*
|
||||
* @return string the full path (incl. the name of this element), delimeted by $delimeter
|
||||
*
|
||||
* @throws Exception if there was an error
|
||||
*/
|
||||
public function getFullPath(string $delimeter = self::PATH_DELIMITER_ARROW) : string
|
||||
{
|
||||
if (! \is_array($this->full_path_strings)) {
|
||||
$this->full_path_strings = array();
|
||||
$this->full_path_strings[] = $this->getName();
|
||||
$parent_id = $this->getParentID();
|
||||
while ($parent_id > 0) {
|
||||
/** @var StructuralDBElement $element */
|
||||
$element = static::getInstance($this->database, $this->current_user, $this->log, $parent_id);
|
||||
$parent_id = $element->getParentID();
|
||||
$this->full_path_strings[] = $element->getName();
|
||||
}
|
||||
$this->full_path_strings = array_reverse($this->full_path_strings);
|
||||
}
|
||||
|
||||
return implode($delimeter, $this->full_path_strings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all subelements of this element
|
||||
*
|
||||
* @param boolean $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
|
||||
{
|
||||
if ($this->children == null) {
|
||||
$this->children = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
}
|
||||
|
||||
if (! $recursive) {
|
||||
return $this->children;
|
||||
} else {
|
||||
$all_elements = array();
|
||||
foreach ($this->children as $subelement) {
|
||||
$all_elements[] = $subelement;
|
||||
$all_elements = array_merge($all_elements, $subelement->getSubelements(true));
|
||||
}
|
||||
|
||||
return $all_elements;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Setters
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* Change the parent ID of this element
|
||||
*
|
||||
* @param integer|null $new_parent_id @li the ID of the new parent element
|
||||
* @li NULL if the parent should be the root node
|
||||
*/
|
||||
public function setParentID($new_parent_id)
|
||||
{
|
||||
$this->parent_id = $new_parent_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the comment
|
||||
*
|
||||
* @param string $new_comment the new comment
|
||||
* @throws Exception if there was an error
|
||||
*/
|
||||
public function setComment(string $new_comment)
|
||||
{
|
||||
$this->comment = $new_comment;
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
*
|
||||
* Tree / Table Builders
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* 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 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.
|
||||
*
|
||||
* @return string HTML string if success
|
||||
*
|
||||
* @throws Exception if there was an error
|
||||
*/
|
||||
public function buildHtmlTree(
|
||||
$selected_id = null,
|
||||
bool $recursive = true,
|
||||
bool $show_root = true,
|
||||
string $root_name = '$$',
|
||||
string $value_prefix = ''
|
||||
) : string {
|
||||
if ($root_name == '$$') {
|
||||
$root_name = _('Oberste Ebene');
|
||||
}
|
||||
|
||||
$html = array();
|
||||
|
||||
if ($show_root) {
|
||||
$root_level = $this->getLevel();
|
||||
if ($this->getID() > 0) {
|
||||
$root_name = htmlspecialchars($this->getName());
|
||||
}
|
||||
|
||||
$html[] = '<option value="'. $value_prefix . $this->getID() . '">' . $root_name . '</option>';
|
||||
} else {
|
||||
$root_level = $this->getLevel() + 1;
|
||||
}
|
||||
|
||||
// get all subelements
|
||||
$subelements = $this->getSubelements($recursive);
|
||||
|
||||
foreach ($subelements as $element) {
|
||||
$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[] = ' ';
|
||||
}
|
||||
$html[] = htmlspecialchars($element->getName()) . '</option>';
|
||||
}
|
||||
|
||||
return implode("\n", $html);
|
||||
}
|
||||
|
||||
|
||||
public function buildBootstrapTree(
|
||||
$page,
|
||||
$parameter,
|
||||
$recursive = false,
|
||||
$show_root = false,
|
||||
$use_db_root_name = true,
|
||||
$root_name = '$$'
|
||||
): array
|
||||
{
|
||||
if ($root_name == '$$') {
|
||||
$root_name = _('Oberste Ebene');
|
||||
}
|
||||
|
||||
$subelements = $this->getSubelements(false);
|
||||
$nodes = array();
|
||||
|
||||
foreach ($subelements as $element) {
|
||||
$nodes[] = $element->buildBootstrapTree($page, $parameter);
|
||||
}
|
||||
|
||||
// if we are on root level?
|
||||
if ($this->getParentID() == -1) {
|
||||
if ($show_root) {
|
||||
$tree = array(
|
||||
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
|
||||
);
|
||||
} else {
|
||||
$tree = array('text' => htmlspecialchars($this->getName()),
|
||||
'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
|
||||
{
|
||||
$breadcrumb = array();
|
||||
|
||||
if ($root_name == '$$') {
|
||||
$root_name = _('Oberste Ebene');
|
||||
}
|
||||
|
||||
if ($show_root) {
|
||||
$breadcrumb[] = array('label' => $root_name,
|
||||
'disabled' => true);
|
||||
}
|
||||
|
||||
if (!$this->current_user->canDo(static::getPermissionName(), StructuralPermission::READ)) {
|
||||
return array('label' => '???',
|
||||
'disabled' => true);
|
||||
}
|
||||
|
||||
$tmp = array();
|
||||
|
||||
if ($element_is_link) {
|
||||
$tmp[] = array('label' => $this->getName(), 'href' => $page . '?' . $parameter . '=' .$this->getID(), 'selected' => true);
|
||||
} else {
|
||||
$tmp[] = array('label' => $this->getName(), 'selected' => true);
|
||||
}
|
||||
|
||||
$parent_id = $this->getParentID();
|
||||
while ($parent_id > 0) {
|
||||
/** @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_reverse($tmp);
|
||||
|
||||
$breadcrumb = array_merge($breadcrumb, $tmp);
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
}
|
81
src/Entity/Supplier.php
Normal file
81
src/Entity/Supplier.php
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: janhb
|
||||
* Date: 23.02.2019
|
||||
* Time: 19:40
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class Supplier
|
||||
* @package App\Entity
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table("suppliers")
|
||||
*/
|
||||
class Supplier extends Company
|
||||
{
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
|
||||
*/
|
||||
protected $children;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Category", inversedBy="children")
|
||||
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Orderdetail", mappedBy="supplier")
|
||||
*/
|
||||
protected $orderdetails;
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
/*
|
||||
$query = 'SELECT COUNT(*) as count FROM parts '.
|
||||
'LEFT JOIN device_parts ON device_parts.id_part = parts.id '.
|
||||
'LEFT JOIN devices ON devices.id = device_parts.id_device '.
|
||||
'LEFT JOIN orderdetails ON orderdetails.id = parts.order_orderdetails_id '.
|
||||
'WHERE ((parts.instock < parts.mininstock) OR (parts.manual_order != false) '.
|
||||
'OR ((devices.order_quantity > 0) '.
|
||||
'AND ((devices.order_only_missing_parts = false) '.
|
||||
'OR (parts.instock - device_parts.quantity * devices.order_quantity < parts.mininstock)))) '.
|
||||
'AND (parts.order_orderdetails_id IS NOT NULL) '.
|
||||
'AND (orderdetails.id_supplier = ?)';
|
||||
|
||||
$query_data = $this->database->query($query, array($this->getID()));
|
||||
|
||||
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue