/** * Returns a list of footprint 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 footprint id */ public function getFootprintAttachments($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { $qb = PartKeepr::getEM()->createQueryBuilder(); $qb->select("st")->from("PartKeepr\\Footprint\\FootprintAttachment", "st")->leftJoin('st.footprint', "fp"); if ($filter != "") { $footprint = Footprint::loadById($filter); $qb = $qb->where("st.footprint = :footprint"); $qb->setParameter("footprint", $footprint); } 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("PartKeepr\\Footprint\\FootprintAttachment", "st"); if ($filter != "") { $totalQueryBuilder = $totalQueryBuilder->where("st.footprint = :footprint"); $totalQueryBuilder->setParameter("footprint", $footprint); } $totalQuery = $totalQueryBuilder->getQuery(); $aData = array(); foreach ($result as $item) { $aData[] = $item->serialize(); } return array("data" => $aData, "totalCount" => $totalQuery->getSingleScalarResult()); }
public function moveFootprint() { $this->requireParameter("targetCategory"); $this->requireParameter("id"); $footprint = Footprint::loadById($this->getParameter("id")); $category = FootprintCategory::loadById($this->getParameter("targetCategory")); $footprint->setCategory($category); PartKeepr::getEM()->flush(); }
/** * (non-PHPdoc) * @see PartKeepr\Service.RestfulService::create() */ public function create() { $this->requireParameter("tmp_id"); $this->requireParameter("footprint_id"); $tmpImage = TempUploadedFile::loadById($this->getParameter("tmp_id")); $file = new FootprintAttachment(); $footprint = Footprint::loadById($this->getParameter("footprint_id")); $file->setFootprint($footprint); $file->replace($tmpImage->getFilename()); $file->setOriginalFilename($tmpImage->getOriginalFilename()); $file->setDescription($this->getParameter("description")); PartKeepr::getEM()->persist($file); PartKeepr::getEM()->flush(); return $file->serialize(); }
/** * Deserializes the part * @param array $parameters The array with the parameters to set */ public function deserialize(array $parameters) { foreach ($parameters as $key => $value) { switch ($key) { case "name": $this->setName($value); break; case "description": $this->setDescription($value); break; case "comment": $this->setComment($value); break; case "internalPartNumber": $this->setInternalPartNumber($value); break; case "footprint": if ($value === 0) { $this->setFootprint(null); } else { try { $footprint = Footprint::loadById($value); $this->setFootprint($footprint); } catch (\Exception $e) { // No footprint was found. Ignore it. } } break; case "minStockLevel": $this->setMinStockLevel($value); break; case "partUnit": $partUnit = PartUnit::loadById($value); $this->setPartUnit($partUnit); break; case "category": $category = PartCategory::loadById($value); $this->setCategory($category); break; case "status": $this->setStatus($value); break; case "storageLocation": $storageLocation = StorageLocation::loadById($value); $this->setStorageLocation($storageLocation); break; case "manufacturers": $this->deserializeChildren($value, $this->getManufacturers(), "PartKeepr\\Part\\PartManufacturer"); foreach ($this->getManufacturers() as $manufacturer) { $manufacturer->setPart($this); } break; case "distributors": $this->deserializeChildren($value, $this->getDistributors(), "PartKeepr\\Part\\PartDistributor"); foreach ($this->getDistributors() as $distributor) { $distributor->setPart($this); } break; case "parameters": $this->deserializeChildren($value, $this->getParameters(), "PartKeepr\\PartParameter\\PartParameter"); foreach ($this->getParameters() as $parameter) { $parameter->setPart($this); } break; case "needsReview": $this->setReviewFlag($value); break; case "partCondition": $this->setCondition($value); break; case "attachments": $this->deserializeChildren($value, $this->getAttachments(), "PartKeepr\\Part\\PartAttachment"); foreach ($this->getAttachments() as $attachment) { $attachment->setPart($this); } break; } } }
/** * Finds or creates a footprint by name. * * @param mixed $footprint Either the ID or the footprint's name to find */ public function getOrCreateFootprint($footprint) { try { $footprint = Footprint::loadById($footprint); return $footprint; } catch (EntityNotFoundException $e) { } $dql = "SELECT f FROM PartKeepr\\Footprint\\Footprint f WHERE f.name = :name"; $query = PartKeepr::getEM()->createQuery($dql); $query->setParameter("name", $footprint); try { $footprint = $query->getSingleResult(); return $footprint; } catch (\Exception $e) { } $fp = new Footprint(); $fp->setName($footprint); PartKeepr::getEM()->persist($fp); return $fp; }