Example #1
0
	private function setUnitData (Unit $unit) {
		$unit->setName($this->getParameter("name"));
		$unit->setSymbol($this->getParameter("symbol"));
	}
Example #2
0
	$prefix->setSymbol($data["symbol"]);
	
	$aSiPrefixes[] = $prefix;
	PartKeepr::getEM()->persist($prefix);
	
}

PartKeepr::getEM()->flush();

/* Add units */
$data = \Symfony\Component\Yaml\Yaml::load("../setup/data/units.yaml");

$aUnits = array();

foreach ($data as $unitName => $data) {
	$unit = new Unit();
	$unit->setName($unitName);
	$unit->setSymbol($data["symbol"]);
	
	if (array_key_exists("prefixes", $data)) {
		if (!is_array($data["prefixes"])) {
			echo "Obacht ".$unitName." ist falsch\n";
		}
		foreach ($data["prefixes"] as $prefix) {
			foreach ($aSiPrefixes as $siPrefix) {
				if ($siPrefix->getSymbol() == $prefix) {
					$unit->getPrefixes()->add($siPrefix);		
				}
			}
		}
	}
Example #3
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);
			}
		}
	}