commit 93394fbfe5bfd15eedb5cc757bd74fcb600a6839
parent 26cef64a409378b38b9c231426e693b2f1cd1fb1
Author: Felicitus <felicitus@felicitus.org>
Date: Sun, 2 Aug 2015 15:44:02 +0200
Added part attachments to the info panel
Diffstat:
13 files changed, 329 insertions(+), 1055 deletions(-)
diff --git a/app/config/config.yml b/app/config/config.yml
@@ -343,6 +343,57 @@ services:
arguments:
- { groups: [ "default" ] }
+ resource.part_attachment.item_operation.custom_get:
+ class: "Dunglas\ApiBundle\Api\Operation\Operation"
+ public: false
+ factory: [ "@api.operation_factory", "createItemOperation" ]
+ arguments:
+ - "@resource.part_attachment" # Resource
+ - [ "GET" ] # Methods
+ - "/part_attachments/{id}/getFile" # Path
+ - "PartKeeprPartBundle:PartAttachment:getFile" # Controller
+ - "PartAttachmentGet" # Route name
+ - # Context (will be present in Hydra documentation)
+ "@type": "hydra:Operation"
+ "hydra:title": "A custom operation"
+ "returns": "xmls:string"
+
+ resource.part_attachment.item_operation.custom_get_mime:
+ class: "Dunglas\ApiBundle\Api\Operation\Operation"
+ public: false
+ factory: [ "@api.operation_factory", "createItemOperation" ]
+ arguments:
+ - "@resource.part_attachment" # Resource
+ - [ "GET" ] # Methods
+ - "/part_attachments/{id}/getMimeTypeIcon" # Path
+ - "PartKeeprPartBundle:PartAttachment:getMimeTypeIcon" # Controller
+ - "PartAttachmentMimeTypeIcon" # Route name
+ - # Context (will be present in Hydra documentation)
+ "@type": "hydra:Operation"
+ "hydra:title": "A custom operation"
+ "returns": "xmls:string"
+
+ resource.part_attachment.item_operation.get:
+ class: "Dunglas\ApiBundle\Api\Operation\Operation"
+ public: false
+ factory: [ "@api.operation_factory", "createItemOperation" ]
+ arguments: [ "@resource.part_attachment", "GET" ]
+
+ resource.part_attachment:
+ parent: "api.resource"
+ arguments: [ "PartKeepr\\PartBundle\\Entity\\PartAttachment" ]
+ tags: [ { name: "api.resource" } ]
+ calls:
+ - method: "initItemOperations"
+ arguments: [ [ "@resource.part_attachment.item_operation.get", "@resource.part_attachment.item_operation.custom_get", "@resource.part_attachment.item_operation.custom_get_mime" ] ]
+ - method: "initFilters"
+ arguments: [ [ "@doctrine_reflection_service.search_filter" ] ]
+ - method: "initNormalizationContext"
+ arguments: [ { groups: [ "default" ] } ]
+ - method: "initDenormalizationContext"
+ arguments:
+ - { groups: [ "default" ] }
+
resource.part_category.item_operation.move:
class: "Dunglas\ApiBundle\Api\Operation\Operation"
public: false
diff --git a/app/config/partkeepr.yml b/app/config/partkeepr.yml
@@ -6,5 +6,6 @@ partkeepr:
tempfile: %kernel.root_dir%/../data/files/Temporary/
footprintattachment: %kernel.root_dir%/../data/files/FootprintAttachment/
footprint: %kernel.root_dir%/../data/images/footprint/
+ partattachment: %kernel.root_dir%/../data/files/PartAttachment/
storagelocation: %kernel.root_dir%/../data/images/storagelocation/
mimetype_icons: %kernel.root_dir%/../src/PartKeepr/MimetypeIconsBundle/Resources/public/images/mimes/
\ No newline at end of file
diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartDisplay.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartDisplay.js
@@ -16,7 +16,7 @@ Ext.define('PartKeepr.PartDisplay', {
/**
* Create the template
*/
- this.tpl = new Ext.XTemplate(
+ this.infoTpl = new Ext.XTemplate(
'<h1>{name}</h1>',
'<h2>{description}</h2>',
'<table>',
@@ -68,14 +68,6 @@ Ext.define('PartKeepr.PartDisplay', {
'<td class="e">' + i18n("Used in projects") + ':</td>',
'<td class="e">{[ (values.projects == "") ? "' + i18n("none") + '" : values.projects ]}</td>',
'</tr>',
- '<tr>',
- '<td class="o">' + i18n("Attachments") + ':</td>',
- '<td class="o">' +
- '<tpl for="values.processedAttachments">' +
- '<p><a href="{link}" target="_blank">{data.originalFilename}</a></p>' +
- '</tpl>' +
- '</td>' +
- '</tr>',
'</table>');
/**
@@ -104,7 +96,7 @@ Ext.define('PartKeepr.PartDisplay', {
icon: 'resources/silkicons/brick_edit.png',
handler: Ext.bind(function ()
{
- this.fireEvent("editPart", this.record.get("id"));
+ this.fireEvent("editPart", this.record.getId());
}, this)
});
@@ -126,10 +118,32 @@ Ext.define('PartKeepr.PartDisplay', {
* @todo Add the events "addStock" and "removeStock" and manage these events from the PartManager.
*/
- this.imageDisplay = Ext.create("PartKeepr.PartImageDisplay");
- this.infoContainer = Ext.create("Ext.container.Container");
+ this.attachmentDisplay = Ext.create("Ext.view.View", {
+ title: "Foobar",
+ store: null,
+ itemSelector: 'div.foobar',
+ selectedItemCls: "",
+ focusCls: "",
+ emptyText: i18n("No attachments"),
+ tpl: [
+ '<tpl for=".">',
+ '<div class="foobar"><a href="{[values["@id"]]}/getFile" target="_blank">{[values.originalFilename]}</a></div>',
+ '</tpl>'
+ ]
+ });
- this.items = [this.infoContainer, this.imageDisplay];
+ this.imageDisplay = Ext.create("PartKeepr.PartImageDisplay", {
+ title: i18n("Images"),
+ });
+ this.infoContainer = Ext.create("Ext.container.Container", {});
+
+ this.items = [
+ this.infoContainer, {
+ xtype: 'panel',
+ title: i18n("Attachments"),
+ items: this.attachmentDisplay
+ }, this.imageDisplay
+ ];
this.callParent();
},
/**
@@ -155,15 +169,8 @@ Ext.define('PartKeepr.PartDisplay', {
}
}
- values.processedAttachments = this.record.attachments().data;
-
- for (i = 0; i < values.processedAttachments.getCount(); i++) {
- var data = values.processedAttachments.getAt(i);
-
- data.link = "file.php?type=PartAttachment&id=" + data.internalId;
- }
-
- this.tpl.overwrite(this.infoContainer.getEl(), values);
+ this.attachmentDisplay.bindStore(this.record.attachments());
+ this.infoTpl.overwrite(this.infoContainer.getEl(), values);
this.imageDisplay.setStore(this.record.attachments());
// Scroll the container to top in case the user scrolled the part, then switched to another part
@@ -210,7 +217,7 @@ Ext.define('PartKeepr.PartDisplay', {
"Part",
"deleteStock");
call.setParameter("stock", quantity);
- call.setParameter("part", this.record.get("id"));
+ call.setParameter("part", this.record.getId());
call.setHandler(Ext.bind(this.reloadPart, this));
call.doCall();
},
@@ -219,7 +226,7 @@ Ext.define('PartKeepr.PartDisplay', {
*/
reloadPart: function ()
{
- this.loadPart(this.record.get("id"));
+ this.loadPart(this.record.getId());
},
/**
* Load the part from the database.
diff --git a/src/PartKeepr/FrontendBundle/Resources/views/index.html.twig b/src/PartKeepr/FrontendBundle/Resources/views/index.html.twig
@@ -14,8 +14,8 @@
<!-- Include the ExtJS CSS Theme -->
{% stylesheets
filter='cssrewrite'
- 'js/packages/extjs6/build/classic/theme-neptune-touch/resources/theme-neptune-touch-all.css'
- 'js/packages/extjs6/build/packages/ux/classic/neptune/resources/ux-all.css'
+ 'js/packages/extjs6/build/classic/theme-crisp/resources/theme-crisp-all.css'
+ 'js/packages/extjs6/build/packages/ux/classic/crisp/resources/ux-all.css'
'js/packages/extjs6/build/packages/charts/classic/neptune/resources/charts-all.css'
'@PartKeeprFrontendBundle/Resources/public/css/PartKeepr.css'
%}
diff --git a/src/PartKeepr/PartBundle/Controller/PartAttachmentController.php b/src/PartKeepr/PartBundle/Controller/PartAttachmentController.php
@@ -0,0 +1,15 @@
+<?php
+namespace PartKeepr\PartBundle\Controller;
+
+use PartKeepr\UploadedFileBundle\Controller\FileController;
+
+class PartAttachmentController extends FileController
+{
+ /**
+ * @inheritdoc
+ */
+ protected function getEntityClass()
+ {
+ return "PartKeepr\\PartBundle\\Entity\\PartAttachment";
+ }
+}
diff --git a/src/PartKeepr/PartBundle/Entity/Part.php b/src/PartKeepr/PartBundle/Entity/Part.php
@@ -1,13 +1,12 @@
<?php
namespace PartKeepr\PartBundle\Entity;
+use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use PartKeepr\DoctrineReflectionBundle\Annotation\TargetService;
use PartKeepr\FootprintBundle\Entity\Footprint;
-use Doctrine\Common\Collections\ArrayCollection;
use PartKeepr\Part\Exceptions\CategoryNotAssignedException;
use PartKeepr\Part\Exceptions\StorageLocationNotAssignedException;
-use PartKeepr\Part\PartAttachment;
use PartKeepr\Part\PartImage;
use PartKeepr\PartKeepr;
use PartKeepr\StorageLocationBundle\Entity\StorageLocation;
@@ -28,12 +27,14 @@ class Part extends BaseEntity
/**
* The category of the part
* @ORM\ManyToOne(targetEntity="PartKeepr\PartBundle\Entity\PartCategory")
+ *
* @var PartCategory
*/
private $category;
/**
* The part's name
+ *
* @ORM\Column
* @Groups({"default"})
* @var string
@@ -44,6 +45,7 @@ class Part extends BaseEntity
* The part's short description
* @ORM\Column(type="string",nullable=true)
* @Groups({"default"})
+ *
* @var string
*/
private $description;
@@ -68,6 +70,7 @@ class Part extends BaseEntity
/**
* Defines the storage location of this part
* @ORM\ManyToOne(targetEntity="PartKeepr\StorageLocationBundle\Entity\StorageLocation")
+ *
* @var StorageLocation
*/
private $storageLocation;
@@ -75,6 +78,7 @@ class Part extends BaseEntity
/**
* Holds the manufacturers which can manufacture this part
* @ORM\OneToMany(targetEntity="PartKeepr\Part\PartManufacturer",mappedBy="part",cascade={"persist", "remove"})
+ *
* @var ArrayCollection
*/
private $manufacturers;
@@ -82,6 +86,7 @@ class Part extends BaseEntity
/**
* Holds the distributors from where we can buy the part
* @ORM\OneToMany(targetEntity="PartKeepr\Part\PartDistributor",mappedBy="part",cascade={"persist", "remove"})
+ *
* @var ArrayCollection
*/
private $distributors;
@@ -89,13 +94,16 @@ class Part extends BaseEntity
/**
* Holds the part images
* @ORM\OneToMany(targetEntity="PartKeepr\Part\PartImage",mappedBy="part",cascade={"persist", "remove"})
+ *
* @var PartImage
*/
private $images;
/**
* Holds the part attachments
- * @ORM\OneToMany(targetEntity="PartKeepr\Part\PartAttachment",mappedBy="part",cascade={"persist", "remove"})
+ * @ORM\OneToMany(targetEntity="PartKeepr\PartBundle\Entity\PartAttachment",mappedBy="part",cascade={"persist", "remove"})
+ * @Groups({"default"})
+ *
* @var PartAttachment
*/
private $attachments;
@@ -109,6 +117,7 @@ class Part extends BaseEntity
/**
* The stock level. Note that this is a cached value, because it makes our summary queries easier.
+ *
* @todo It would be nice if we could get rid of that.
* @ORM\Column(type="integer")
* @Groups({"default"})
@@ -137,6 +146,7 @@ class Part extends BaseEntity
/**
* The stock level history
* @ORM\OneToMany(targetEntity="PartKeepr\Stock\StockEntry",mappedBy="part",cascade={"persist", "remove"})
+ *
* @var ArrayCollection
*/
private $stockLevels;
@@ -144,6 +154,7 @@ class Part extends BaseEntity
/**
* The parameters for this part
* @ORM\OneToMany(targetEntity="PartKeepr\PartParameter\PartParameter",mappedBy="part",cascade={"persist", "remove"})
+ *
* @var ArrayCollection
*/
private $parameters;
@@ -151,6 +162,7 @@ class Part extends BaseEntity
/**
* The part status for this part
* @ORM\Column(type="string",nullable=true)
+ *
* @var string
*/
private $status;
@@ -158,6 +170,7 @@ class Part extends BaseEntity
/**
* Defines if the part needs review
* @ORM\Column(type="boolean")
+ *
* @var boolean
*/
private $needsReview;
@@ -165,6 +178,7 @@ class Part extends BaseEntity
/**
* Defines the condition of the part
* @ORM\Column(type="string",nullable=true)
+ *
* @var string
*/
private $partCondition;
@@ -172,6 +186,7 @@ class Part extends BaseEntity
/**
* The create date+time for this part
* @ORM\Column(type="datetime",nullable=true)
+ *
* @var \DateTime
*/
private $createDate;
@@ -184,6 +199,7 @@ class Part extends BaseEntity
/**
* The internal part number
* @ORM\Column(type="string",nullable=true)
+ *
* @var string
*/
private $internalPartNumber;
@@ -201,6 +217,7 @@ class Part extends BaseEntity
/**
* Sets the name for this part
+ *
* @param string $name The part's name
*/
public function setName($name)
@@ -210,6 +227,7 @@ class Part extends BaseEntity
/**
* Returns the name of this part
+ *
* @return string The part name
*/
public function getName()
@@ -219,6 +237,7 @@ class Part extends BaseEntity
/**
* Sets the internal part number for this part
+ *
* @param string $partNumber
*/
public function setInternalPartNumber($partNumber)
@@ -228,6 +247,7 @@ class Part extends BaseEntity
/**
* Returns the internal part number for this part
+ *
* @return string the internal part number
*/
public function getInternalPartNumber()
@@ -237,6 +257,7 @@ class Part extends BaseEntity
/**
* Sets the description for this part
+ *
* @param string $description The part's short description
*/
public function setDescription($description)
@@ -246,6 +267,7 @@ class Part extends BaseEntity
/**
* Returns the short description of this part
+ *
* @return string The part description
*/
public function getDescription()
@@ -278,7 +300,9 @@ class Part extends BaseEntity
/**
* Sets the average price for this unit
+ *
* @todo Is this actually used?
+ *
* @param float $price The price to set
*/
public function setAveragePrice($price)
@@ -296,6 +320,7 @@ class Part extends BaseEntity
/**
* Sets the review flag
+ *
* @param boolean $bReview True if the part needs review, false otherwise
*/
public function setReviewFlag($bReview)
@@ -305,6 +330,7 @@ class Part extends BaseEntity
/**
* Returns the review flag
+ *
* @return boolean True if the part needs review, false otherwise
*/
public function getReviewFlag()
@@ -314,6 +340,7 @@ class Part extends BaseEntity
/**
* Sets the condition for this part
+ *
* @param string $partCondition The part's condition
*/
public function setCondition($partCondition)
@@ -323,6 +350,7 @@ class Part extends BaseEntity
/**
* Returns the condition of this part
+ *
* @return string The part condition
*/
public function getCondition()
@@ -337,6 +365,7 @@ class Part extends BaseEntity
* Only positive values are allowed.
*
* @param int $minStockLevel A minimum stock level, only values >= 0 are allowed.
+ *
* @throws \PartKeepr\Util\Exceptions\OutOfRangeException If the passed stock level is not in range (>=0)
*/
public function setMinStockLevel($minStockLevel)
@@ -411,6 +440,7 @@ class Part extends BaseEntity
/**
* Sets the comment for this part
+ *
* @param string $comment The comment for this part
*/
public function setComment($comment)
@@ -420,6 +450,7 @@ class Part extends BaseEntity
/**
* Returns the comment for this part
+ *
* @return string The comment
*/
public function getComment()
@@ -429,6 +460,7 @@ class Part extends BaseEntity
/**
* Returns the distributors array
+ *
* @return ArrayCollection the distributors
*/
public function getDistributors()
@@ -438,6 +470,7 @@ class Part extends BaseEntity
/**
* Returns the part images array
+ *
* @return ArrayCollection the part images
*/
public function getImages()
@@ -447,6 +480,7 @@ class Part extends BaseEntity
/**
* Returns the part attachments array
+ *
* @return ArrayCollection the part attachments
*/
public function getAttachments()
@@ -456,6 +490,7 @@ class Part extends BaseEntity
/**
* Returns the manufacturers array
+ *
* @return ArrayCollection the manufacturers
*/
public function getManufacturers()
@@ -465,6 +500,7 @@ class Part extends BaseEntity
/**
* Returns the parameters assigned to this part
+ *
* @return array An array of PartParameter objects
*/
public function getParameters()
@@ -475,6 +511,7 @@ class Part extends BaseEntity
/**
* Returns the stock level of this part. This is a real-time function which
* actually creates a query over the StockEntry table.
+ *
* @return int The stock level
*/
public function getStockLevel()
@@ -483,13 +520,16 @@ class Part extends BaseEntity
$query->setParameter("part", $this);
$count = $query->getSingleScalarResult();
- if ($count == null)
+ if ($count == null) {
$count = 0;
+ }
+
return $count;
}
/**
* Sets the create date for this part
+ *
* @param \DateTime $dateTime The create date+time
*/
private function setCreateDate(\DateTime $dateTime)
@@ -499,6 +539,7 @@ class Part extends BaseEntity
/**
* Returns the create date
+ *
* @return \DateTime The create date+time
*/
public function getCreateDate()
@@ -509,6 +550,7 @@ class Part extends BaseEntity
/**
* Sets the status for this part. A status is any string describing the status,
* e.g. "new", "used", "broken" etc.
+ *
* @param string $status The status
*/
public function setStatus($status)
@@ -518,6 +560,7 @@ class Part extends BaseEntity
/**
* Returns the status for this part.
+ *
* @return string The status
*/
public function getStatus()
@@ -589,6 +632,7 @@ class Part extends BaseEntity
* Checks if the requirements for database persisting are given.
*
* For a list of exceptions, see
+ *
* @see PartKeepr\Part.Part::onPrePersist()
*
* @ORM\PreUpdate
@@ -603,11 +647,12 @@ class Part extends BaseEntity
* Returns a string representation of the part
*
* @param none
+ *
* @return string The name and the ID of the part
*/
public function __toString()
{
- return $this->getName() . " (" . $this->getId() . ")";
+ return $this->getName()." (".$this->getId().")";
}
}
diff --git a/src/PartKeepr/PartBundle/Entity/PartAttachment.php b/src/PartKeepr/PartBundle/Entity/PartAttachment.php
@@ -0,0 +1,70 @@
+<?php
+namespace PartKeepr\PartBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+use PartKeepr\UploadedFileBundle\Entity\UploadedFile;
+
+/**
+ * Holds a part attachment
+ *
+ * @ORM\Entity
+ **/
+class PartAttachment extends UploadedFile
+{
+ /**
+ * Defines if the attachment is an image.
+ * @ORM\Column(type="boolean",nullable=true)
+ *
+ * @var boolean
+ */
+ private $isImage;
+
+ /**
+ * Creates a new part attachment
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ $this->setType("PartAttachment");
+ $this->isImage = null;
+ }
+
+ /**
+ * The part object
+ * @ORM\ManyToOne(targetEntity="PartKeepr\PartBundle\Entity\Part", inversedBy="attachments")
+ *
+ * @var Part
+ */
+ private $part = null;
+
+ /**
+ * Sets the part
+ *
+ * @param Part $part The part to set
+ */
+ public function setPart(Part $part)
+ {
+ $this->part = $part;
+ }
+
+ /**
+ * Returns the part
+ *
+ * @return Part the part
+ */
+ public function getPart()
+ {
+ return $this->part;
+ }
+
+ /**
+ * Returns if the attachment is an image or not.
+ *
+ * @return True if the attachment is an image, false otherwise
+ */
+ public function isImage()
+ {
+ //@todo: Reimplement check if attachment is an image
+ return false;
+ }
+}
diff --git a/src/backend/PartKeepr/Part/PartAttachment.php b/src/backend/PartKeepr/Part/PartAttachment.php
@@ -1,71 +0,0 @@
-<?php
-namespace PartKeepr\Part;
-
-use Doctrine\ORM\Mapping as ORM;
-use PartKeepr\PartBundle\Entity\Part;
-use PartKeepr\UploadedFileBundle\Entity\UploadedFile;
-
-/**
- * Holds a part attachment
- *
- * @ORM\Entity
- **/
-class PartAttachment extends UploadedFile
-{
- /**
- * Defines if the attachment is an image.
- * @ORM\Column(type="boolean",nullable=true)
- *
- * @var boolean
- */
- private $isImage;
-
- /**
- * Creates a new part attachment
- */
- public function __construct()
- {
- parent::__construct();
- $this->setType("PartAttachment");
- $this->isImage = null;
- }
-
- /**
- * The part object
- * @ORM\ManyToOne(targetEntity="PartKeepr\PartBundle\Entity\Part", inversedBy="attachments")
- *
- * @var Part
- */
- private $part = null;
-
- /**
- * Sets the part
- *
- * @param Part $part The part to set
- */
- public function setPart(Part $part)
- {
- $this->part = $part;
- }
-
- /**
- * Returns the part
- *
- * @return Part the part
- */
- public function getPart()
- {
- return $this->part;
- }
-
- /**
- * Returns if the attachment is an image or not.
- *
- * @return True if the attachment is an image, false otherwise
- */
- public function isImage()
- {
- //@todo: Reimplement check if attachment is an image
- return false;
- }
-}
diff --git a/src/backend/PartKeepr/Part/PartManager.php b/src/backend/PartKeepr/Part/PartManager.php
@@ -1,488 +0,0 @@
-<?php
-namespace PartKeepr\Part;
-
-use PartKeepr\Logger\Logger;
-
-use PartKeepr\UploadedFileBundle\Entity\TempUploadedFile,
- PartKeepr\Manager\ManagerFilter,
- Doctrine\ORM\QueryBuilder,
- PartKeepr\PartParameter\PartParameter,
- PartKeepr\Manager\AbstractManager,
- PartKeepr\UnitBundle\Entity\Unit,
- PartKeepr\SiPrefixBundle\Entity\SiPrefix,
- PartKeepr\Part\PartDistributor,
- PartKeepr\Part\PartManufacturer,
- PartKeepr\StorageLocationBundle\Entity\StorageLocation,
- PartKeepr\StorageLocation\StorageLocationManager,
- PartKeepr\PartBundle\Entity\Part,
- Doctrine\ORM\Query,
- PartKeepr\PartUnit\PartUnitManager,
- PartKeepr\DistributorBundle\Entity\Distributor,
- PartKeepr\ManufacturerBundle\Entity\Manufacturer,
- \PartKeepr\FootprintBundle\Entity\FootprintManager,
- PartKeepr\Session\SessionManager,
- PartKeepr\Stock\StockEntry,
- PartKeepr\Util\Singleton,
- \PartKeepr\FootprintBundle\Entity\Footprint,
- PartKeepr\PartKeepr,
- \PartKeepr\PartBundle\Entity\PartCategoryManager,
- PartKeepr\Manufacturer\ManufacturerManager;
-
-class PartManager extends AbstractManager {
-
- /**
- * Returns the FQCN for the target entity to operate on.
- * @return string The FQCN, e.g. PartKeepr\Part
- */
- public function getEntityName () {
- return 'PartKeepr\PartBundle\Entity\Part';
- }
-
- /**
- * Returns all fields which need to appear in the getList ResultSet.
- * @return array An array of all fields which should be returned
- */
- public function getQueryFields () {
- return array("name", "description", "averagePrice", "status", "needsReview", "createDate", "id", "stockLevel",
- "minStockLevel", "comment", "st.id AS storageLocation_id", "c.categoryPath AS categoryPath",
- "st.name as storageLocationName", "f.id AS footprint_id", "f.name AS footprintName",
- "c.id AS category", "c.name AS categoryName", "pu.id AS partUnit", "pu.name AS partUnitName",
- "pu.shortName AS partUnitShortName", "pu.is_default AS partUnitDefault", "partCondition"
- );
- }
-
- /**
- * Returns the default sort field
- *
- * @return string The default sort field
- */
- public function getDefaultSortField () {
- return "dateTime";
- }
-
- /**
- * Appends various join tables to the result set
- *
- * (non-PHPdoc)
- * @see PartKeepr\Manager.AbstractManager::applyCustomQuery()
- */
- protected function applyCustomQuery (QueryBuilder $qb, ManagerFilter $filter) {
- /**
- * Pull in additional tables
- */
- $qb ->join("q.storageLocation", "st")
- ->leftJoin("q.footprint", "f")
- ->join("q.category", "c")
- ->leftJoin("q.partUnit", "pu");
-
- // Apply special handling for non-direct fields in relations, where the frontend has no idea about.
- foreach ($filter->getSorters() as $sorter) {
- switch ($sorter->getSortField()) {
- case "q.categoryPath":
- $sorter->setSortField("c.categoryPath");
- break;
- case "q.storageLocationName":
- $sorter->setSortField("st.name");
- break;
- case "q.footprintName":
- $sorter->setSortField("f.name");
- break;
- default:
- break;
- }
- }
-
- }
-
- /**
- * Processes the result after it was retrieved. In the default configuration, it returns an array result, or
- * if no query fields are specified, it tries to serialize all objects.
- */
- protected function getResult (Query $query) {
- $result = parent::getResult($query);
-
- $partIds = array();
- foreach ($result as $key => $item) {
- $partIds[] = $item["id"];
- }
-
- $attachmentCounts = $this->getAttachmentCounts($partIds);;
- $projects = $this->getProjects($partIds);
-
- foreach ($result as $key => $item) {
- if (array_key_exists($item["id"], $attachmentCounts)) {
- $result[$key]["attachmentCount"] = $attachmentCounts[$item["id"]];
- } else {
- $result[$key]["attachmentCount"] = 0;
- }
-
- if (array_key_exists($item["id"], $projects)) {
- $result[$key]["projects"] = implode(", ", $projects[$item["id"]]);
- }
-
- $result[$key]["createDate"] = $result[$key]["createDate"]->format("Y-m-d H:i:s");
-
- $part = Part::loadById($item["id"]);
- $result[$key]["attachments"] = $part->serializeChildren($part->getAttachments());
- }
-
- return $result;
- }
-
- /**
- * Returns a list of projects for a list of part ids.
- *
- * @param $partIds Array an array of part ids to get the project names for
- * @return Array an array where the key is the part id and the value is an array of project names
- */
- private function getProjects (array $partIds) {
- if (count($partIds) == 0) {
- return array();
- }
-
- $dql2 = "SELECT DISTINCT pr.id, pr.name, part.id FROM PartKeepr\Project\Project pr JOIN pr.parts ppart JOIN ppart.part part WHERE ppart.part IN (:partids)";
- $projectQuery = PartKeepr::getEM()->createQuery($dql2);
- $projectQuery->setParameter("partids", $partIds);
-
- $projects = array();
-
- foreach ($projectQuery->getResult() as $projectResult) {
- if (!array_key_exists($projectResult["id"], $projects)) {
- $projects[$projectResult["id"]] = array();
- }
- $projects[$projectResult["id"]][] = $projectResult["name"];
- }
-
- return $projects;
- }
-
- /**
- * Returns a list of attachment counts for a list of part ids.
- *
- * @param $partIds Array an array of part ids to get the attachment counts for
- * @return Array an array where the key is the part id and the value is the attachment count
- */
- private function getAttachmentCounts (array $partIds) {
- if (count($partIds) == 0) {
- return array();
- }
-
- $dql = "SELECT p.id, COUNT(pa) AS cnt FROM PartKeepr\Part\PartAttachment pa JOIN pa.part p WHERE pa.part IN ";
- $dql .= "(:partids) GROUP BY pa.part, p.id";
-
- $partAttachmentQuery = PartKeepr::getEM()->createQuery($dql);
- $partAttachmentQuery->setParameter("partids", $partIds);
-
- $attachmentCounts = array();
-
- foreach ($partAttachmentQuery->getResult() as $attachmentResult) {
- $attachmentCounts[$attachmentResult["id"]] = intval($attachmentResult["cnt"]);
- }
-
- return $attachmentCounts;
- }
-
- public function addOrUpdatePart ($aParameters) {
-
- if (!array_key_exists("quantity", $aParameters)) {
- $aParameters["quantity"] = 0;
- }
-
- if ($aParameters["part"] !== null) {
- try {
- $part = $this->getPart($aParameters["part"]);
- } catch (\Exception $e) {
- $part = new Part();
- $user = SessionManager::getCurrentSession()->getUser();
-
- $stock = new StockEntry($part, $aParameters["quantity"], $user);
- PartKeepr::getEM()->persist($stock);
- }
- } else {
- $part = new Part();
-
- $user = SessionManager::getCurrentSession()->getUser();
-
- $stock = new StockEntry($part, $aParameters["quantity"], $user);
- PartKeepr::getEM()->persist($stock);
- }
-
- if (array_key_exists("name", $aParameters)) {
- $part->setName($aParameters["name"]);
- }
-
- if (array_key_exists("description", $aParameters)) {
- $part->setDescription($aParameters["description"]);
- }
-
- if (array_key_exists("minstock", $aParameters)) {
- $part->setMinStockLevel($aParameters["minstock"]);
- }
-
- if (array_key_exists("comment", $aParameters)) {
- $part->setComment($aParameters["comment"]);
- }
-
- if (array_key_exists("footprint", $aParameters)) {
-
- if ($aParameters["footprint"] === null) {
- $part->setFootprint(null);
- } else {
- $footprint = FootprintManager::getInstance()->getOrCreateFootprint($aParameters["footprint"]);
- $part->setFootprint($footprint);
- }
- }
-
- if (array_key_exists("storagelocation", $aParameters)) {
- $storageLocation = StorageLocationManager::getInstance()->getOrCreateStorageLocation($aParameters["storagelocation"]);
- $part->setStorageLocation($storageLocation);
- }
-
- if (array_key_exists("category", $aParameters)) {
- $category = PartCategoryManager::getInstance()->getCategory($aParameters["category"]);
- $part->setCategory($category->getNode());
- }
-
- /* Process linked changes */
- if (array_key_exists("distributorChanges", $aParameters)) {
- if (is_array($aParameters["distributorChanges"])) {
- $this->processDistributorChanges($part, $aParameters["distributorChanges"]);
- }
- }
-
- if (array_key_exists("manufacturerChanges", $aParameters)) {
- if (is_array($aParameters["manufacturerChanges"])) {
- $this->processManufacturerChanges($part, $aParameters["manufacturerChanges"]);
- }
- }
-
- if (array_key_exists("parameterChanges", $aParameters)) {
- if (is_array($aParameters["parameterChanges"])) {
- $this->processParameterChanges($part, $aParameters["parameterChanges"]);
- }
- }
-
- if (array_key_exists("attachmentChanges", $aParameters)) {
- if (is_array($aParameters["attachmentChanges"])) {
- $this->processAttachmentChanges($part, $aParameters["attachmentChanges"]);
- }
- }
-
- if (array_key_exists("partUnit", $aParameters)) {
- if ($aParameters["partUnit"] === null || $aParameters["partUnit"] === 0) {
- $part->setPartUnit(null);
- } else {
- $part->setPartUnit(PartUnitManager::getInstance()->getPartUnit($aParameters["partUnit"]));
- }
- }
-
-
- PartKeepr::getEM()->persist($part);
- PartKeepr::getEM()->flush();
-
- }
-
- private function processParameterChanges (\PartKeepr\PartBundle\Entity\Part $part, Array $data) {
- if (array_key_exists("updates", $data)) {
- foreach ($data["updates"] as $record) {
- foreach ($part->getParameters() as $partParameter) {
- if ($partParameter->getId() == $record["id"]) {
- $partParameter->setName($record["name"]);
- $partParameter->setDescription($record["description"]);
- $partParameter->setValue($record["value"]);
- $partParameter->setSiPrefix(SiPrefix::loadById($record["siprefix_id"]));
- $partParameter->setUnit(Unit::loadById($record["unit_id"]));
- break;
- }
- }
- }
- }
-
- if (array_key_exists("removals", $data)) {
- foreach ($data["removals"] as $record) {
- foreach ($part->getParameters() as $partParameter) {
- if ($partParameter->getId() == $record["id"]) {
- PartKeepr::getEM()->remove($partParameter);
- $part->getParameters()->removeElement($partParameter);
- break;
- }
- }
- }
- }
-
- if (array_key_exists("inserts", $data)) {
- foreach ($data["inserts"] as $record) {
- $partParameter = new PartParameter();
- $partParameter->setPart($part);
-
- $partParameter->setName($record["name"]);
- $partParameter->setDescription($record["description"]);
- $partParameter->setValue($record["value"]);
- $partParameter->setSiPrefix(SiPrefix::loadById($record["siprefix_id"]));
- $partParameter->setUnit(Unit::loadById($record["unit_id"]));
-
- $part->getParameters()->add($partParameter);
- }
- }
- }
-
- private function processDistributorChanges (\PartKeepr\PartBundle\Entity\Part $part, Array $data) {
- if (array_key_exists("updates", $data)) {
- foreach ($data["updates"] as $record) {
- foreach ($part->getDistributors() as $partDistributor) {
- if ($partDistributor->getId() == $record["id"]) {
- $partDistributor->setOrderNumber($record["orderNumber"]);
- $partDistributor->setDistributor(Distributor::loadById($record["distributor_id"]));
- $partDistributor->setPackagingUnit($record["packagingUnit"]);
- break;
- }
- }
- }
- }
-
- if (array_key_exists("removals", $data)) {
- foreach ($data["removals"] as $record) {
- foreach ($part->getDistributors() as $partDistributor) {
- if ($partDistributor->getId() == $record["id"]) {
- PartKeepr::getEM()->remove($partDistributor);
- $part->getDistributors()->removeElement($partDistributor);
- break;
- }
- }
- }
- }
-
- if (array_key_exists("inserts", $data)) {
- foreach ($data["inserts"] as $record) {
- $distributor = new PartDistributor($part, Distributor::loadById($record["distributor_id"]));
- $distributor->setOrderNumber($record["orderNumber"]);
- $distributor->setPackagingUnit($record["packagingUnit"]);
-
- $part->getDistributors()->add($distributor);
- }
- }
- }
-
- private function processManufacturerChanges (Part $part, Array $data) {
- if (array_key_exists("updates", $data)) {
- foreach ($data["updates"] as $record) {
- foreach ($part->getManufacturers() as $partManufacturer) {
- if ($partManufacturer->getId() == $record["id"]) {
- $partManufacturer->setPartNumber($record["partNumber"]);
- $partManufacturer->setManufacturer(Manufacturer::loadById($record["manufacturer_id"]));
- break;
- }
- }
- }
- }
-
- if (array_key_exists("removals", $data)) {
- foreach ($data["removals"] as $record) {
- foreach ($part->getManufacturers() as $partManufacturer) {
- if ($partManufacturer->getId() == $record["id"]) {
- PartKeepr::getEM()->remove($partManufacturer);
- $part->getManufacturers()->removeElement($partManufacturer);
- break;
- }
- }
- }
- }
-
- if (array_key_exists("inserts", $data)) {
- foreach ($data["inserts"] as $record) {
- $manufacturer = new PartManufacturer($part, Manufacturer::loadById($record["manufacturer_id"]));
- $manufacturer->setPartNumber($record["partNumber"]);
-
- $part->getManufacturers()->add($manufacturer);
- }
- }
- }
-
- private function processAttachmentChanges (Part $part, Array $data) {
- if (array_key_exists("updates", $data)) {
- foreach ($data["updates"] as $record) {
- foreach ($part->getAttachments() as $partAttachment) {
- if ($partAttachment->getId() == $record["id"]) {
- $partAttachment->setDescription($record["description"]);
- break;
- }
- }
- }
- }
-
- if (array_key_exists("removals", $data)) {
- foreach ($data["removals"] as $record) {
- foreach ($part->getAttachments() as $partAttachment) {
- if ($partAttachment->getId() == $record["id"]) {
- PartKeepr::getEM()->remove($partAttachment);
- $part->getAttachments()->removeElement($partAttachment);
- break;
- }
- }
- }
- }
-
- if (array_key_exists("inserts", $data)) {
- foreach ($data["inserts"] as $record) {
- $attachment = new PartAttachment();
- $attachment->setPart($part);
- $attachment->setDescription($record["description"]);
-
- $file = TempUploadedFile::loadById($record["tmp_id"]);
-
- $attachment->replace($file->getFilename());
- $attachment->setOriginalFilename($file->getOriginalFilename());
-
- $part->getAttachments()->add($attachment);
- }
- }
- }
-
- public function deletePart ($id) {
- $part = PartManager::getInstance()->getPart($id);
-
- PartKeepr::getEM()->remove($part);
- PartKeepr::getEM()->flush();
- }
-
- public function getPart ($id) {
- $part = PartKeepr::getEM()->find("PartKeepr\Part\Part", $id);
-
- return $part;
- }
-
- /**
- * Returns the overall part count currently existing.
- * @param boolean $withPrice Only consider parts with a price
- * @return int The amount of parts in the database
- */
- public function getPartCount ($withPrice = false) {
- $dql = "SELECT COUNT(p.id) FROM PartKeepr\PartBundle\Entity\Part p";
-
- if ($withPrice === true) {
- $dql .= " WHERE p.averagePrice IS NOT NULL";
- }
-
- return PartKeepr::getEM()->createQuery($dql)->getSingleScalarResult();
- }
-
- /**
- * Returns the total price for all parts. Only parts with a price are calculated.
- * @return float The total price
- */
- public function getTotalPrice () {
- $dql = "SELECT SUM(p.averagePrice * p.stockLevel) FROM PartKeepr\PartBundle\Entity\Part p";
-
- return PartKeepr::getEM()->createQuery($dql)->getSingleScalarResult();
- }
-
- /**
- * Returns the average price for all parts. Only parts with a price are calculated.
- * @return float The average price
- */
- public function getAveragePrice () {
- $dql = "SELECT AVG(p.averagePrice) FROM PartKeepr\PartBundle\Entity\Part p";
-
- return PartKeepr::getEM()->createQuery($dql)->getSingleScalarResult();
- }
-}
diff --git a/src/backend/PartKeepr/Part/PartService.php b/src/backend/PartKeepr/Part/PartService.php
@@ -1,363 +0,0 @@
-<?php
-namespace PartKeepr\Part;
-
-use PartKeepr\AuthBundle\Entity\User;
-use PartKeepr\Manager\ManagerFilter;
-use PartKeepr\PartBundle\Entity\Part;
-use \PartKeepr\PartBundle\Entity\PartCategory;
-use \PartKeepr\PartBundle\Entity\PartCategoryManager;
-use PartKeepr\PartKeepr;
-use PartKeepr\Service\RestfulService;
-use PartKeepr\Service\Service;
-use PartKeepr\Session\SessionManager;
-use PartKeepr\Stock\StockEntry;
-
-class PartService extends Service implements RestfulService {
- public function get () {
- if ($this->hasParameter("id")) {
- return array("data" => PartManager::getInstance()->getPart($this->getParameter("id"))->serialize());
- } else {
-
- $filter = new ManagerFilter($this);
- $filter->setFilterCallback(array($this, "filterCallback"));
-
- return PartManager::getInstance()->getList($filter);
- }
- }
-
- /**
- * Advanced filtering for the list
- * @param QueryBuilder The $queryBuilder
- */
- public function filterCallback ($queryBuilder) {
-
- /**
- * Applies text-based filtering
- */
- if ($this->hasParameter("query") && $this->getParameter("query") != "") {
-
- // Special case: If the user passes id:<number>, we retrieve that number only.
- // This is
-
- $additionalResults = array();
-
- $regExp = "id:[0-9]+";
- if (preg_match_all("/id:[0-9]+/", $this->getParameter("query"), $pregResults) === 1) {
- foreach ($pregResults as $match) {
- foreach ($match as $result) {
- $additionalResults[] = str_replace("id:", "", $result);
- }
- }
- }
-
- $fulltextSearch = new PartFulltextSearch($this->getParameter("query"));
- $fulltextSearchResults = $fulltextSearch->query();
-
- $ids = array_merge($fulltextSearchResults, $additionalResults);
-
- $queryBuilder->andWhere("q.id IN (".implode(",", $ids).")");
-
- }
-
- /**
- * Applies filtering by the storage location id
- */
- if ($this->getParameter("storageLocation") !== null) {
- $queryBuilder->andWhere("st.id = :storageLocation");
- $queryBuilder->setParameter("storageLocation", $this->getParameter("storageLocation"));
- }
-
- // We need that join multiple times. Not exactly nice, as this should get pulled in only when needed.
- // @todo Refactor so that this join only gets inside when needed
- $queryBuilder->leftJoin("q.distributors", "di");
-
- if ($this->getParameter("distributor") !== null) {
- $queryBuilder->leftJoin("di.distributor", "did");
- $queryBuilder->andWhere("did.id = :distributor");
- $queryBuilder->setParameter("distributor", $this->getParameter("distributor"));
- }
-
- if ($this->getParameter("manufacturer") !== null) {
- $queryBuilder->leftJoin("q.manufacturers", "ma");
- $queryBuilder->leftJoin("ma.manufacturer", "mam");
- $queryBuilder->andWhere("mam.id = :manufacturer");
- $queryBuilder->setParameter("manufacturer", $this->getParameter("manufacturer"));
- }
-
- if ($this->getParameter("footprint") !== null) {
- $queryBuilder->andWhere("f.id = :footprintId");
- $queryBuilder->setParameter("footprintId", $this->getParameter("footprint"));
- }
-
- /**
- * Filter by the category id and set the category mode
- *
- */
- $category = intval($this->getParameter("category", 0));
-
- if ($category !== 0) {
- /* Fetch all children */
- if ($this->getParameter("categoryScope") == "selected") {
- $queryBuilder->andWhere("q.category = :category");
- $queryBuilder->setParameter("category", $category);
- } else {
- $childs = PartCategoryManager::getInstance()->getChildNodes($category);
- $childs[] = $category;
- $queryBuilder->andWhere("q.category IN (".implode(",", $childs).")");
- }
- }
-
- /**
- * Filter by the stock mode
- */
- switch ($this->getParameter("stockMode")) {
- case "all":
- break;
- case "zero":
- $queryBuilder->andWhere("q.stockLevel = 0");
- break;
- case "nonzero":
- $queryBuilder->andWhere("q.stockLevel > 0");
- break;
- case "below":
- $queryBuilder->andWhere("q.stockLevel < q.minStockLevel");
- break;
- }
-
- /**
- * Query by the distributor's order number
- */
- if ($this->getParameter("distributorOrderNumber")) {
- $queryBuilder->andWhere("LOWER(di.orderNumber) LIKE :orderNumber");
- $queryBuilder->setParameter("orderNumber", "%".strtolower($this->getParameter("distributorOrderNumber"))."%");
- }
-
- /**
- * Filter by the price
- */
- if ($this->getParameter("withoutPrice") === true || $this->getParameter("withoutPrice") === "true") {
- $queryBuilder->andWhere("q.averagePrice IS NULL");
- }
-
- if ($this->getParameter("createDateRestriction") !== "") {
- try {
- $dateTime = new \DateTime($this->getParameter("createDate"));
- $date = $dateTime->format("Y-m-d");
-
- switch ($this->getParameter("createDateRestriction")) {
- case ">":
- $queryBuilder->andWhere("q.createDate > :createDate");
- $queryBuilder->setParameter("createDate", $date);
- break;
- case "<":
- $queryBuilder->andWhere("q.createDate < :createDate");
- $queryBuilder->setParameter("createDate", $date);
- break;
- case "=":
- $queryBuilder->andWhere("q.createDate > :createDate AND q.createDate < :createDate2");
- $queryBuilder->setParameter("createDate", $date. " 00:00:00");
- $queryBuilder->setParameter("createDate2", $date. " 23:59:59");
- break;
- default:
- break;
- }
- } catch (\Exception $e) {
- // Do nothing for now
- }
- }
-
- if ($this->getParameter("withoutStockRemovals", false) === true || $this->getParameter("withoutStockRemovals", false) === "true") {
- $q = PartKeepr::getEM()->createQueryBuilder();
- $q->select("p.id")->from("PartKeepr\Part\Part", "p")->leftJoin("p.stockLevels", "sl")->where("sl.stockLevel < 0");
- $query = $q->getQuery();
-
- $result = $query->getResult();
- $filter = array();
- foreach ($result as $res) {
- $filter[] = $res["id"];
- }
-
- $queryBuilder->andWhere("q.id NOT IN (".implode(",", $filter).")");
- }
-
- /**
- * Query by the review flag
- */
- if ($this->getParameter("needsReview") === true || $this->getParameter("needsReview") === "true") {
- $queryBuilder->andWhere("q.needsReview = true");
- }
-
- /**
- * Query by the status
- */
- if ($this->getParameter("status")) {
- $queryBuilder->andWhere("LOWER(q.status) LIKE :status");
- $queryBuilder->setParameter("status", "%".strtolower($this->getParameter("status"))."%");
- }
-
- /**
- * Query by the condition
- */
- if ($this->getParameter("condition")) {
- $queryBuilder->andWhere("LOWER(q.partCondition) LIKE :condition");
- $queryBuilder->setParameter("condition", "%".strtolower($this->getParameter("condition"))."%");
- }
- }
-
- /**
- * (non-PHPdoc)
- * @see PartKeepr\Service.RestfulService::create()
- */
- public function create () {
- $entity = PartManager::getInstance()->createEntity($this->getParameters());
-
- if ($this->getParameter("initialStockLevel") > 0) {
- try {
- $user = User::loadById($this->getParameter("initialStockLevelUser"));
- } catch (\Exception $e) {
- $user = SessionManager::getCurrentSession()->getUser();
- }
-
- $stock = new StockEntry($entity, intval($this->getParameter("initialStockLevel")), $user);
-
- if ($this->getParameter("initialStockLevelPricePerItem") == true) {
- $price = floatval($this->getParameter("initialStockLevelPrice"));
- } else {
- $price = floatval($this->getParameter("initialStockLevelPrice")) / $this->getParameter("initialStockLevel");
- }
-
- if ($price != 0) {
- $stock->setPrice($price);
- }
-
- PartKeepr::getEM()->persist($stock);
- PartKeepr::getEM()->flush();
-
- $entity->updateStockLevel();
- PartKeepr::getEM()->flush();
- }
-
- return array("data" => $entity->serialize());
- }
-
- /**
- * (non-PHPdoc)
- * @see PartKeepr\Service.RestfulService::update()
- */
- public function update () {
- $entity = PartManager::getInstance()->getEntity($this->getParameter("id"));
- $entity->deserialize($this->getParameters());
-
- PartKeepr::getEM()->flush();
-
- return array("data" => $entity->serialize());
- }
-
-
- public function destroy () {
- throw new \Exception("Not yet implemented");
- }
-
- public function getPartParameterNames () {
- $dql = "SELECT pp.name FROM PartKeepr\PartParameter\PartParameter pp GROUP BY pp.name";
- $query = PartKeepr::getEM()->createQuery($dql);
-
- return array("data" => $query->getArrayResult());
- }
-
- public function movePart () {
- $this->requireParameter("targetCategory");
-
- if ($this->getParameter("parts", false) !== false) {
- /* We are moving multiple parts */
- foreach ($this->getParameter("parts") as $part) {
- $part = Part::loadById($part);
- $category = PartCategory::loadById($this->getParameter("targetCategory"));
-
- $part->setCategory($category);
- }
- } else {
- $part = Part::loadById($this->getParameter("part"));
- $category = PartCategory::loadById($this->getParameter("targetCategory"));
-
- $part->setCategory($category);
-
- }
-
- PartKeepr::getEM()->flush();
- }
-
- public function addStock () {
- $part = PartManager::getInstance()->getPart($this->getParameter("part"));
-
- $user = SessionManager::getCurrentSession()->getUser();
-
- $stock = new StockEntry($part, intval($this->getParameter("stock")), $user);
-
- $price = floatval($this->getParameter("price"));
-
- if ($price != 0) {
- $stock->setPrice($price);
- }
-
- if ($this->hasParameter("comment")) {
- $stock->setComment($this->getParameter("comment"));
- }
-
- PartKeepr::getEM()->persist($stock);
- PartKeepr::getEM()->flush();
-
- $part->updateStockLevel();
-
- PartKeepr::getEM()->flush();
-
- return array("data" => $part->serialize());
- }
-
- public function deleteStock () {
- $part = PartManager::getInstance()->getPart($this->getParameter("part"));
-
- $user = SessionManager::getCurrentSession()->getUser();
-
- $stock = new StockEntry($part, 0-intval($this->getParameter("stock")), $user);
-
- PartKeepr::getEM()->persist($stock);
- PartKeepr::getEM()->flush();
-
- $part->updateStockLevel();
-
- PartKeepr::getEM()->flush();
-
- return array("data" => $part->serialize());
- }
-
- public function massDeleteStock () {
- $data = $this->getParameter("removals");
-
- $updateStockLevels = array();
-
- foreach ($data as $item) {
- $part = PartManager::getInstance()->getPart($item["part"]);
- $user = SessionManager::getCurrentSession()->getUser();
-
- $stock = new StockEntry($part, 0-intval($item["amount"]), $user);
- $stock->setComment($item["comment"]);
- PartKeepr::getEM()->persist($stock);
-
- $updateStockLevels[$item["part"]] = $part;
- }
-
- PartKeepr::getEM()->flush();
-
- foreach ($updateStockLevels as $part) {
- $part->updateStockLevel();
- }
-
- PartKeepr::getEM()->flush();
- return array();
- }
-
- public function deletePart () {
- PartManager::getInstance()->deletePart($this->getParameter("part"));
- }
-}-
\ No newline at end of file
diff --git a/src/backend/PartKeepr/PartKeepr.php b/src/backend/PartKeepr/PartKeepr.php
@@ -164,7 +164,7 @@ class PartKeepr {
'PartKeepr\Part\PartManufacturer',
'PartKeepr\Part\PartDistributor',
'PartKeepr\Part\PartImage',
- 'PartKeepr\Part\PartAttachment',
+ 'PartKeepr\PartBundle\Entity\PartAttachment',
'PartKeepr\PartBundle\Entity\PartCategory',
'PartKeepr\Printing\PageBasicLayout\PageBasicLayout',
diff --git a/src/backend/PartKeepr/Setup/Migration/PartDB/PartMigration.php b/src/backend/PartKeepr/Setup/Migration/PartDB/PartMigration.php
@@ -3,7 +3,7 @@ namespace PartKeepr\Setup\Migration\PartDB;
use PartKeepr\PartKeepr,
PartKeepr\PartBundle\Entity\Part,
- PartKeepr\Part\PartAttachment,
+ PartKeepr\PartBundle\Entity\PartAttachment,
PartKeepr\Part\PartDistributor,
PartKeepr\Part\PartManager,
PartKeepr\Stock\StockEntry,
diff --git a/src/backend/PartKeepr/System/SystemService.php b/src/backend/PartKeepr/System/SystemService.php
@@ -2,103 +2,111 @@
namespace PartKeepr\System;
use PartKeepr\Util\Configuration,
- PartKeepr\Service\Service,
- PartKeepr\PartKeepr,
- PartKeepr\CronLogger\CronLoggerManager,
- PartKeepr\Util\OS\OperatingSystem;
-
-class SystemService extends Service {
- /**
- * Returns a list of system information records.
- *
- * Please note that it is not defined which information is returned; the result
- * should be seen as "informational" to the system operator, not for automated purposes.
- */
- public function getSystemInformation () {
- $aData = array();
-
- $aData[] = new SystemInformationRecord("Doctrine ORM", \Doctrine\ORM\Version::VERSION, "Libraries");
- $aData[] = new SystemInformationRecord("Doctrine DBAL", \Doctrine\DBAL\Version::VERSION, "Libraries");
-
- $aData[] = new SystemInformationRecord("PHP Version", phpversion(), "System");
-
- $os = new OperatingSystem();
-
- $aData[] = new SystemInformationRecord("Operating System Type", $os->getPlatform(), "System");
- $aData[] = new SystemInformationRecord("Operating System Release", $os->getRelease(), "System");
-
- $aData[] = new SystemInformationRecord("memory_limit", ini_get("memory_limit"), "PHP");
- $aData[] = new SystemInformationRecord("post_max_size", ini_get("post_max_size"), "PHP");
- $aData[] = new SystemInformationRecord("upload_max_filesize", ini_get("upload_max_filesize"), "PHP");
- $aData[] = new SystemInformationRecord("allow_url_fopen", ini_get("allow_url_fopen"), "PHP");
- $aData[] = new SystemInformationRecord("max_execution_time", ini_get("max_execution_time"), "PHP");
-
- $queryCache = get_class(PartKeepr::getEM()->getConfiguration()->getQueryCacheImpl());
- $metadataCache = get_class(PartKeepr::getEM()->getConfiguration()->getMetadataCacheImpl());
-
- $aData[] = new SystemInformationRecord("Query Cache Implementation", $queryCache, "PHP");
- $aData[] = new SystemInformationRecord("Metadata Cache Implementation", $metadataCache, "PHP");
-
-
- $aData[] = new SystemInformationRecord("PartKeepr Version", PartKeepr::getVersion(), "PartKeepr");
-
-
- foreach (Configuration::getOptions() as $key => $value) {
-
- // Hide passwords
- if ($key == "partkeepr.database.password" || $key == "partkeepr.migration.partdb.password") {
- $value = "<hidden>";
- }
-
- $aData[] = new SystemInformationRecord($key, $value, "PartKeepr Configuration Information");
- }
-
- return array("data" => $aData);
- }
-
- /**
- * Returns the database schema status.
- *
- * This method is usuall called once the user logs in, and alerts him if the schema is not up-to-date.
- *
- * Returns either status incomplete if the schema is not up-to-date, or complete if everything is OK.
- */
- public function getSystemStatus () {
-
- if (Configuration::getOption("partkeepr.cronjobs.disablecheck", false) === true) {
- // Skip cronjob tests
- $inactiveCronjobs = array();
- } else {
- $inactiveCronjobs = CronLoggerManager::getInstance()->getInactiveCronjobs();
- }
-
-
- return array("data" =>
- array(
- "inactiveCronjobCount" => count($inactiveCronjobs),
- "inactiveCronjobs" => $inactiveCronjobs,
- "schemaStatus" => $this->getSchemaStatus()));
- }
-
- /**
- * Checks if the schema is up-to-date. If yes, it returns "complete", if not, it returns "incomplete".
- *
- * @param none
- * @return string Either "complete" or "incomplete"
- */
- protected function getSchemaStatus () {
- $metadatas = PartKeepr::getEM()->getMetadataFactory()->getAllMetadata();
-
- $schemaTool = new \Doctrine\ORM\Tools\SchemaTool(PartKeepr::getEM());
-
- $queries = $schemaTool->getUpdateSchemaSql($metadatas, true);
-
- if (count($queries) > 0) {
- return "incomplete";
- } else {
- return "complete";
- }
- }
-
-
+ PartKeepr\Service\Service,
+ PartKeepr\PartKeepr,
+ PartKeepr\CronLogger\CronLoggerManager,
+ PartKeepr\Util\OS\OperatingSystem;
+
+class SystemService extends Service
+{
+ /**
+ * Returns a list of system information records.
+ *
+ * Please note that it is not defined which information is returned; the result
+ * should be seen as "informational" to the system operator, not for automated purposes.
+ */
+ public function getSystemInformation()
+ {
+ $aData = array();
+
+ $aData[] = new SystemInformationRecord("Doctrine ORM", \Doctrine\ORM\Version::VERSION, "Libraries");
+ $aData[] = new SystemInformationRecord("Doctrine DBAL", \Doctrine\DBAL\Version::VERSION, "Libraries");
+
+ $aData[] = new SystemInformationRecord("PHP Version", phpversion(), "System");
+
+ $os = new OperatingSystem();
+
+ $aData[] = new SystemInformationRecord("Operating System Type", $os->getPlatform(), "System");
+ $aData[] = new SystemInformationRecord("Operating System Release", $os->getRelease(), "System");
+
+ $aData[] = new SystemInformationRecord("memory_limit", ini_get("memory_limit"), "PHP");
+ $aData[] = new SystemInformationRecord("post_max_size", ini_get("post_max_size"), "PHP");
+ $aData[] = new SystemInformationRecord("upload_max_filesize", ini_get("upload_max_filesize"), "PHP");
+ $aData[] = new SystemInformationRecord("allow_url_fopen", ini_get("allow_url_fopen"), "PHP");
+ $aData[] = new SystemInformationRecord("max_execution_time", ini_get("max_execution_time"), "PHP");
+
+ $queryCache = get_class(PartKeepr::getEM()->getConfiguration()->getQueryCacheImpl());
+ $metadataCache = get_class(PartKeepr::getEM()->getConfiguration()->getMetadataCacheImpl());
+
+ $aData[] = new SystemInformationRecord("Query Cache Implementation", $queryCache, "PHP");
+ $aData[] = new SystemInformationRecord("Metadata Cache Implementation", $metadataCache, "PHP");
+
+
+ $aData[] = new SystemInformationRecord("PartKeepr Version", PartKeepr::getVersion(), "PartKeepr");
+
+
+ foreach (Configuration::getOptions() as $key => $value) {
+
+ // Hide passwords
+ if ($key == "partkeepr.database.password" || $key == "partkeepr.migration.partdb.password") {
+ $value = "<hidden>";
+ }
+
+ $aData[] = new SystemInformationRecord($key, $value, "PartKeepr Configuration Information");
+ }
+
+ return array("data" => $aData);
+ }
+
+ /**
+ * Returns the database schema status.
+ *
+ * This method is usuall called once the user logs in, and alerts him if the schema is not up-to-date.
+ *
+ * Returns either status incomplete if the schema is not up-to-date, or complete if everything is OK.
+ */
+ public function getSystemStatus()
+ {
+
+ if (Configuration::getOption("partkeepr.cronjobs.disablecheck", false) === true) {
+ // Skip cronjob tests
+ $inactiveCronjobs = array();
+ } else {
+ $inactiveCronjobs = CronLoggerManager::getInstance()->getInactiveCronjobs();
+ }
+
+
+ return array(
+ "data" =>
+ array(
+ "inactiveCronjobCount" => count($inactiveCronjobs),
+ "inactiveCronjobs" => $inactiveCronjobs,
+ "schemaStatus" => $this->getSchemaStatus(),
+ ),
+ );
+ }
+
+ /**
+ * Checks if the schema is up-to-date. If yes, it returns "complete", if not, it returns "incomplete".
+ *
+ * @param none
+ *
+ * @return string Either "complete" or "incomplete"
+ */
+ protected function getSchemaStatus()
+ {
+ $metadatas = PartKeepr::getEM()->getMetadataFactory()->getAllMetadata();
+
+ $schemaTool = new \Doctrine\ORM\Tools\SchemaTool(PartKeepr::getEM());
+
+ $queries = $schemaTool->getUpdateSchemaSql($metadatas, true);
+
+ if (count($queries) > 0) {
+ return "incomplete";
+ } else {
+ return "complete";
+ }
+ }
+
+
}
\ No newline at end of file