Example #1
0
 /**
  * Sets up the SI prefixes
  */
 public function setupSiPrefixes()
 {
     $count = 0;
     $skipped = 0;
     $data = Setup::loadYAML(self::SIPREFIX_DATA_FILE);
     foreach ($data as $prefixName => $prefixData) {
         if (!SiPrefixManager::getInstance()->siPrefixExists($prefixName)) {
             $prefix = new SiPrefix();
             $prefix->setPrefix($prefixName);
             $prefix->setPower($prefixData["power"]);
             $prefix->setSymbol($prefixData["symbol"]);
             $this->entityManager->persist($prefix);
             $count++;
         } else {
             $skipped++;
         }
     }
     $this->entityManager->flush();
     $this->logMessage(sprintf("Imported %d Si Prefixes, skipped %d", $count, $skipped));
 }
Example #2
0
 /**
  * Deserializes the part parameter
  * @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 "value":
                 $this->setValue($value);
                 break;
             case "siprefix_id":
                 $prefix = SiPrefix::loadById($value);
                 $this->setSiPrefix($prefix);
                 break;
             case "unit_id":
                 $unit = Unit::loadById($value);
                 $this->setUnit($unit);
                 break;
         }
     }
 }
Example #3
0
 /**
  * Deserializes the unit
  * @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 "symbol":
                 $this->setSymbol($value);
                 break;
             case "prefixes":
                 $prefixes = $this->getPrefixes();
                 $prefixes->clear();
                 foreach ($value as $prefix) {
                     $prefix = SiPrefix::loadById($prefix["id"]);
                     $prefixes->add($prefix);
                 }
                 break;
         }
     }
 }
Example #4
0
 private function processParameterChanges(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);
         }
     }
 }