partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 8dbe4ce4f3c862813ab7353f6ab390107087705a
parent e400db356ff1f7bb1ae6c4b310e11d16062d892a
Author: Felicitus <felicitus@felicitus.org>
Date:   Thu, 29 Dec 2011 08:54:20 +0100

Added project attachments

Diffstat:
Msrc/backend/de/RaumZeitLabor/PartKeepr/Project/Project.php | 26+++++++++++++++++++++++++-
Asrc/backend/de/RaumZeitLabor/PartKeepr/Project/ProjectAttachment.php | 105+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backend/de/RaumZeitLabor/PartKeepr/ProjectAttachment/ProjectAttachmentManager.php | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backend/de/RaumZeitLabor/PartKeepr/ProjectAttachment/ProjectAttachmentService.php | 107+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/frontend/file.php | 7++++++-
Msrc/frontend/js/Components/Footprint/FootprintAttachmentGrid.js | 6+++---
Csrc/frontend/js/Components/Footprint/FootprintAttachmentGrid.js -> src/frontend/js/Components/Project/ProjectAttachmentGrid.js | 0
Msrc/frontend/js/Components/Project/ProjectEditor.js | 20+++++++++++++++++++-
Msrc/frontend/js/Models/Project.js | 3++-
Asrc/frontend/js/Models/ProjectAttachment.js | 15+++++++++++++++
10 files changed, 352 insertions(+), 7 deletions(-)

diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/Project/Project.php b/src/backend/de/RaumZeitLabor/PartKeepr/Project/Project.php @@ -36,11 +36,20 @@ class Project extends BaseEntity implements Serializable, Deserializable { */ private $description; + /** + * Holds the project attachments + * @OneToMany(targetEntity="de\RaumZeitLabor\PartKeepr\Project\ProjectAttachment",mappedBy="project",cascade={"persist", "remove"}) + * @var ProjectAttachment + */ + private $attachments; + + /** * Constructs a new project */ public function __construct () { $this->parts = new \Doctrine\Common\Collections\ArrayCollection(); + $this->attachments = new \Doctrine\Common\Collections\ArrayCollection(); } /** @@ -99,6 +108,14 @@ class Project extends BaseEntity implements Serializable, Deserializable { } /** + * Returns the attachments for this project + * @return ArrayCollection The attachments + */ + public function getAttachments () { + return $this->attachments; + } + + /** * (non-PHPdoc) * @see de\RaumZeitLabor\PartKeepr\Util.Serializable::serialize() */ @@ -107,7 +124,8 @@ class Project extends BaseEntity implements Serializable, Deserializable { "id" => $this->getId(), "name" => $this->getName(), "description" => $this->getDescription(), - "parts" => $this->serializeChildren($this->getParts()), + "parts" => $this->serializeChildren($this->getParts()), + "attachments" => $this->serializeChildren($this->getAttachments()) ); } @@ -130,6 +148,12 @@ class Project extends BaseEntity implements Serializable, Deserializable { $part->setProject($this); } break; + case "attachments": + $this->deserializeChildren($value, $this->getAttachments(), "de\RaumZeitLabor\PartKeepr\Project\ProjectAttachment"); + foreach ($this->getAttachments() as $attachment) { + $attachment->setProject($this); + } + break; } } } diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/Project/ProjectAttachment.php b/src/backend/de/RaumZeitLabor/PartKeepr/Project/ProjectAttachment.php @@ -0,0 +1,104 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Project; +use de\RaumZeitLabor\PartKeepr\Util\Deserializable; + +use de\RaumZeitLabor\PartKeepr\Util\Serializable; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\UploadedFile\UploadedFile; + +/** + * Holds a project attachment + * @Entity + **/ +class ProjectAttachment extends UploadedFile implements Serializable, Deserializable { + /** + * The description of this attachment + * @Column(type="text") + * @var string + */ + private $description; + + /** + * Creates a new project attachment + */ + public function __construct () { + parent::__construct(); + $this->setType("ProjectAttachment"); + } + /** + * The project object + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\Project\Project") + * @var Project + */ + private $project = null; + + /** + * Sets the project + * @param Project $project The project to set + */ + public function setProject (Project $project) { + $this->project = $project; + } + + /** + * Returns the roject + * @return Project the project + */ + public function getProject () { + return $this->project; + } + + /** + * Sets the description for this attachment + * @param string $description The attachment description + */ + public function setDescription ($description) { + $this->description = $description; + } + + /** + * Returns the description for this attachment + * @return string The description + */ + public function getDescription () { + return $this->description; + } + + /** + * + * Serializes this project attachment + * @return array The serialized project attachment + */ + public function serialize () { + return array( + "id" => $this->getId(), + "project_id" => $this->getProject()->getId(), + "originalFilename" => $this->getOriginalFilename(), + "mimetype" => $this->getMimetype(), + "extension" => $this->getExtension(), + "size" => $this->getSize(), + "description" => $this->getDescription()); + } + + /** + * Deserializes the project attachment + * @param array $parameters The array with the parameters to set + */ + public function deserialize (array $parameters) { + if (array_key_exists("id", $parameters)) { + if (substr($parameters["id"], 0, 4) === "TMP:") { + $this->replaceFromTemporaryFile($parameters["id"]); + } + } + + foreach ($parameters as $key => $value) { + switch ($key) { + case "description": + $this->setDescription($value); + break; + } + } + } +}+ \ No newline at end of file diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/ProjectAttachment/ProjectAttachmentManager.php b/src/backend/de/RaumZeitLabor/PartKeepr/ProjectAttachment/ProjectAttachmentManager.php @@ -0,0 +1,69 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\ProjectAttachment; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Util\Singleton, + de\RaumZeitLabor\PartKeepr\Project\Project, + de\RaumZeitLabor\PartKeepr\PartKeepr; + +class ProjectAttachmentManager extends Singleton { + /** + * Returns a list of project attachments + * + * @param int $start Start of the list, default 0 + * @param int $limit Number of users to list, default 10 + * @param string $sort The field to sort by, default "name" + * @param string $dir The direction to sort (ASC or DESC), default ASC + * @param string $filter The project id + */ + public function getProjectAttachments ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { + + $qb = PartKeepr::getEM()->createQueryBuilder(); + $qb->select("st")->from("de\RaumZeitLabor\PartKeepr\Project\ProjectAttachment","st") + ->leftJoin('st.project', "fp"); + + if ($filter != "") { + $project = Project::loadById($filter); + $qb = $qb->where("st.project = :project"); + $qb->setParameter("project", $project); + } + + if ($limit > -1) { + $qb->setMaxResults($limit); + $qb->setFirstResult($start); + } + + $qb->orderBy("st.".$sort, $dir); + + $query = $qb->getQuery(); + + $result = $query->getResult(); + + $totalQueryBuilder = PartKeepr::getEM()->createQueryBuilder(); + $totalQueryBuilder->select("COUNT(st.id)")->from("de\RaumZeitLabor\PartKeepr\Project\ProjectAttachment","st"); + + + + if ($filter != "") { + $totalQueryBuilder = $totalQueryBuilder->where("st.project = :project"); + $totalQueryBuilder->setParameter("project", $project); + } + + $totalQuery = $totalQueryBuilder->getQuery(); + + $aData = array(); + foreach ($result as $item) { + $aData[] = $item->serialize(); + } + return array("data" => $aData, "totalCount" => $totalQuery->getSingleScalarResult()); + } + + /** + * Returns a project attachment by id + * @param int $id The project attachment id + */ + public function getProjectAttachment ($id) { + return ProjectAttachment::loadById($id); + } + +}+ \ No newline at end of file diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/ProjectAttachment/ProjectAttachmentService.php b/src/backend/de/RaumZeitLabor/PartKeepr/ProjectAttachment/ProjectAttachmentService.php @@ -0,0 +1,106 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\ProjectAttachment; +use de\RaumZeitLabor\PartKeepr\Project\ProjectAttachment; + +use de\RaumZeitLabor\PartKeepr\UploadedFile\TempUploadedFile; + +use de\RaumZeitLabor\PartKeepr\Service\RestfulService; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Service\Service; +use de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Project\Project, + de\RaumZeitLabor\PartKeepr\Session\SessionManager; + +class ProjectAttachmentService extends Service implements RestfulService { + /** + * (non-PHPdoc) + * @see de\RaumZeitLabor\PartKeepr\Service.RestfulService::get() + */ + public function get () { + if ($this->hasParameter("id")) { + return ProjectAttachmentManager::getInstance()->getProjectAttachment($this->getParameter("id"))->serialize(); + } else { + if ($this->hasParameter("sort")) { + $tmp = json_decode($this->getParameter("sort"), true); + + $aSortParams = $tmp[0]; + } else { + $aSortParams = array( + "property" => "id", + "direction" => "ASC"); + } + + $filter = ""; + + if ($this->hasParameter("filter")) { + $tmp = json_decode($this->getParameter("filter"), true); + + foreach ($tmp as $item) { + if (array_key_exists("property", $item)) { + if ($item["property"] == "project_id") { + if (array_key_exists("value", $item)) { + $filter = $item["value"]; + } + } + } + } + } + return ProjectAttachmentManager::getInstance()->getProjectAttachments( + $this->getParameter("start", $this->getParameter("start", 0)), + $this->getParameter("limit", $this->getParameter("limit", 25)), + $this->getParameter("sortby", $aSortParams["property"]), + $this->getParameter("dir", $aSortParams["direction"]), + $filter); + } + } + + /** + * (non-PHPdoc) + * @see de\RaumZeitLabor\PartKeepr\Service.RestfulService::create() + */ + public function create () { + $this->requireParameter("tmp_id"); + $this->requireParameter("project_id"); + + $tmpImage = TempUploadedFile::loadById($this->getParameter("tmp_id")); + + $file = new ProjectAttachment(); + + $project = Project::loadById($this->getParameter("project_id")); + + $file->setProject($project); + $file->replace($tmpImage->getFilename()); + $file->setOriginalFilename($tmpImage->getOriginalFilename()); + $file->setDescription($this->getParameter("description")); + PartKeepr::getEM()->persist($file); + PartKeepr::getEM()->flush(); + + return $file->serialize(); + } + + /** + * (non-PHPdoc) + * @see de\RaumZeitLabor\PartKeepr\Service.RestfulService::update() + */ + public function update () { + + } + + /** + * (non-PHPdoc) + * @see de\RaumZeitLabor\PartKeepr\Service.RestfulService::destroy() + */ + public function destroy () { + $this->requireParameter("id"); + + $file = ProjectAttachment::loadById($this->getParameter("id")); + + PartKeepr::getEM()->remove($file); + PartKeepr::getEM()->flush(); + + return array("data" => null); + } + +}+ \ No newline at end of file diff --git a/src/frontend/file.php b/src/frontend/file.php @@ -1,6 +1,7 @@ <?php namespace de\RaumZeitLabor\PartKeepr\Frontend; use de\RaumZeitLabor\PartKeepr\Footprint\FootprintAttachment; +use de\RaumZeitLabor\PartKeepr\Project\ProjectAttachment; use de\RaumZeitLabor\PartKeepr\Part\PartAttachment; @@ -32,7 +33,11 @@ if (substr($id, 0, 4) === "TMP:") { case "FootprintAttachment": case "PartKeepr.FootprintAttachment": $file = FootprintAttachment::loadById($id); - break; + break; + case "ProjectAttachment": + case "PartKeepr.ProjectAttachment": + $file = ProjectAttachment::loadById($id); + break; default: $file = null; // Add default image? diff --git a/src/frontend/js/Components/Footprint/FootprintAttachmentGrid.js b/src/frontend/js/Components/Footprint/FootprintAttachmentGrid.js @@ -1,6 +1,6 @@ -Ext.define('PartKeepr.FootprintAttachmentGrid', { +Ext.define('PartKeepr.ProjectAttachmentGrid', { extend: 'PartKeepr.AttachmentGrid', - alias: 'widget.FootprintAttachmentGrid', + alias: 'widget.ProjectAttachmentGrid', - model: "PartKeepr.FootprintAttachment" + model: "PartKeepr.ProjectAttachment" }); \ No newline at end of file diff --git a/src/frontend/js/Components/Footprint/FootprintAttachmentGrid.js b/src/frontend/js/Components/Project/ProjectAttachmentGrid.js diff --git a/src/frontend/js/Components/Project/ProjectEditor.js b/src/frontend/js/Components/Project/ProjectEditor.js @@ -61,6 +61,19 @@ Ext.define('PartKeepr.ProjectEditor', { items: this.partGrid }); + this.attachmentGrid = Ext.create("PartKeepr.ProjectAttachmentGrid", { + width: '100%', + border: true + }); + + var container2 = Ext.create("Ext.form.FieldContainer", { + fieldLabel: i18n("Attachments"), + labelWidth: 110, + layout: 'fit', + flex: 1, + items: this.attachmentGrid + }); + this.items = [{ xtype: 'textfield', name: 'name', @@ -72,7 +85,8 @@ Ext.define('PartKeepr.ProjectEditor', { fieldLabel: i18n("Project Description"), height: 70 }, - container + container, + container2 ]; this.callParent(); @@ -103,6 +117,7 @@ Ext.define('PartKeepr.ProjectEditor', { */ _onItemSaved: function (record) { this.partGrid.bindStore(record.parts()); + this.attachmentGrid.bindStore(record.attachments()); }, /** * Bind the store as soon as the view was rendered. @@ -112,5 +127,8 @@ Ext.define('PartKeepr.ProjectEditor', { onEditStart: function () { var store = this.record.parts(); this.partGrid.bindStore(store); + + var store2 = this.record.attachments(); + this.attachmentGrid.bindStore(store2); } }); \ No newline at end of file diff --git a/src/frontend/js/Models/Project.js b/src/frontend/js/Models/Project.js @@ -10,7 +10,8 @@ Ext.define("PartKeepr.Project", { { name: 'user_id', type: 'int'} ], hasMany: [ - { model: 'PartKeepr.ProjectPart', name: 'parts'} + { model: 'PartKeepr.ProjectPart', name: 'parts'}, + { model: 'PartKeepr.ProjectAttachment', name: 'attachments' } ], proxy: PartKeepr.getRESTProxy("Project"), getRecordName: function () { diff --git a/src/frontend/js/Models/ProjectAttachment.js b/src/frontend/js/Models/ProjectAttachment.js @@ -0,0 +1,14 @@ +Ext.define("PartKeepr.ProjectAttachment", { + extend: "Ext.data.Model", + fields: [ + { id: 'id', name: 'id', type: 'string' }, + { name: 'originalFilename', type: 'string' }, + { name: 'project_id', type: 'int' }, + { name: 'mimetype', type: 'string' }, + { name: 'extension', type: 'string' }, + { name: 'description', type: 'string' }, + { name: 'size', type: 'string' } + ], + belongsTo: { type: 'belongsTo', model: 'PartKeepr.Project', primaryKey: 'id', foreignKey: 'project_id'}, + proxy: PartKeepr.getRESTProxy("ProjectAttachment") +});+ \ No newline at end of file