Пример #1
0
 /**
  * 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;
         }
     }
 }
Пример #2
0
 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();
 }