public function updateStatus(StatusStructure $structure, $bit, array $properties) { $databox = $structure->getDatabox(); $this->provider->updateStatus($structure, $bit, $properties); // note : cache->save(...) should be ok but it crashes some callers, ex. adding a sb (?) $this->cache->delete($this->get_cache_key($databox->get_sbas_id())); return $structure; }
public function updateStatus(StatusStructure $statusStructure, $bit, array $properties) { $databox = $statusStructure->getDatabox(); if (false === $statusStructure->hasStatus($bit)) { $statusStructure->setStatus($bit, []); } $doc = $databox->get_dom_structure(); if (!$doc) { return false; } $xpath = $databox->get_xpath_structure(); $entries = $xpath->query('/record/statbits'); if ($entries->length == 0) { $statbits = $doc->documentElement->appendChild($doc->createElement('statbits')); } else { $statbits = $entries->item(0); } if ($statbits) { $entries = $xpath->query('/record/statbits/bit[@n=' . $bit . ']'); if ($entries->length >= 1) { foreach ($entries as $k => $sbit) { if ($p = $sbit->previousSibling) { if ($p->nodeType == XML_TEXT_NODE && $p->nodeValue == '\\n\\t\\t') { $p->parentNode->removeChild($p); } } $sbit->parentNode->removeChild($sbit); } } $sbit = $statbits->appendChild($doc->createElement('bit')); if ($n = $sbit->appendChild($doc->createAttribute('n'))) { $n->value = $bit; } if ($labOn = $sbit->appendChild($doc->createAttribute('labelOn'))) { $labOn->value = $properties['labelon']; } if ($searchable = $sbit->appendChild($doc->createAttribute('searchable'))) { $searchable->value = $properties['searchable']; } if ($printable = $sbit->appendChild($doc->createAttribute('printable'))) { $printable->value = $properties['printable']; } if ($labOff = $sbit->appendChild($doc->createAttribute('labelOff'))) { $labOff->value = $properties['labeloff']; } foreach ($properties['labels_off'] as $code => $label) { $labelTag = $sbit->appendChild($doc->createElement('label')); $switch = $labelTag->appendChild($doc->createAttribute('switch')); $switch->value = 'off'; $codeTag = $labelTag->appendChild($doc->createAttribute('code')); $codeTag->value = $code; $labelTag->appendChild($doc->createTextNode($label)); } foreach ($properties['labels_on'] as $code => $label) { $labelTag = $sbit->appendChild($doc->createElement('label')); $switch = $labelTag->appendChild($doc->createAttribute('switch')); $switch->value = 'on'; $codeTag = $labelTag->appendChild($doc->createAttribute('code')); $codeTag->value = $code; $labelTag->appendChild($doc->createTextNode($label)); } } $databox->saveStructure($doc); $status = $statusStructure->getStatus($bit); $status['labelon'] = $properties['labelon']; $status['labeloff'] = $properties['labeloff']; $status['searchable'] = (bool) $properties['searchable']; $status['printable'] = (bool) $properties['printable']; if (!isset($properties['img_on'])) { $status['img_on'] = null; } if (!isset($properties['img_off'])) { $status['img_off'] = null; } $statusStructure->setStatus($bit, $status); return $statusStructure; }