/** * Generates XML string for a given $item object * * @param \eZ\Publish\Core\FieldType\Page\Parts\Item $item * @param \DOMDocument $dom * * @return boolean|\DOMElement */ protected function generateItemXmlString(Parts\Item $item, DOMDocument $dom) { $itemNode = $dom->createElement('item'); foreach ($item->getState() as $attrName => $attrValue) { switch ($attrName) { case 'action': if ($attrValue !== null) { $itemNode->setAttribute('action', $attrValue); } break; case 'contentId': $this->addNewNotEmptyXmlElement($dom, $itemNode, 'object_id', $attrValue); break; case 'locationId': $this->addNewNotEmptyXmlElement($dom, $itemNode, 'node_id', $attrValue); break; case 'priority': $this->addNewNotEmptyXmlElement($dom, $itemNode, 'priority', $attrValue); break; case 'publicationDate': $this->addNewNotEmptyXmlElement($dom, $itemNode, 'ts_publication', $attrValue); break; case 'visibilityDate': $this->addNewNotEmptyXmlElement($dom, $itemNode, 'ts_visible', $attrValue); break; case 'hiddenDate': $this->addNewNotEmptyXmlElement($dom, $itemNode, 'ts_hidden', $attrValue); break; case 'rotationUntilDate': $this->addNewNotEmptyXmlElement($dom, $itemNode, 'rotation_until', $attrValue); break; case 'movedTo': $this->addNewNotEmptyXmlElement($dom, $itemNode, 'moved_to', $attrValue); break; case 'attributes': foreach ($attrValue as $arrayItemKey => $arrayItemValue) { $this->addNewNotEmptyXmlElement($dom, $itemNode, $arrayItemKey, $arrayItemValue); } break; } } return $itemNode; }
/** * Converts the given $item into a plain hash format. * * @param \eZ\Publish\Core\FieldType\Page\Parts\Item $item * * @return array */ protected function convertItemToHash(Item $item) { $hash = array(); foreach ($item->getState() as $propName => $propValue) { switch ($propName) { case 'blockId': case 'contentId': case 'locationId': case 'priority': case 'movedTo': case 'action': if ($propValue !== null) { $hash[$propName] = $propValue; } break; case 'attributes': if ($propValue !== null && $propValue !== array()) { $hash['attributes'] = $propValue; } break; case 'publicationDate': case 'visibilityDate': case 'hiddenDate': case 'rotationUntilDate': if ($propValue !== null) { /* @var $propValue \DateTime */ $hash[$propName] = $propValue->format(\DateTime::RFC850); } break; } } return $hash; }