Exemple #1
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);
			}
		}
	}