Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Builds the report.
- */
- class ImageReport extends AbstractReport {
- /**
- * The reply.
- *
- * @var DOMDocument
- */
- protected $response;
- /**
- * The root element of the reply.
- *
- * @var DOMElement
- */
- protected $actions;
- /**
- * Creates a document and adds root element.
- */
- public function __construct() {
- $this->response = new DOMDocument();
- $this->response->formatOutput = true;
- $this->actions = $this->response->createElement('actions');
- $this->response->appendChild($this->actions);
- }
- /**
- * Adds an entry to the report
- * @param ImageAction $imageAction
- * @param array $success key is the image uuid (that is connected to language), value is an array with [0] success (bool) and [1] reply (string)
- */
- public function add(ImageAction $imageAction, array $success) {
- $imageTag = $this->response->createElement($imageAction->getAction());
- $attrUuid = $this->response->createAttribute('actionUuid');
- $attrShortId = $this->response->createAttribute('actionShortid');
- $attrUuid->value = $imageAction->getActionUuid();
- $attrShortId->value = $imageAction->getActionShortId();
- $imageTag->appendChild($attrShortId);
- $imageTag->appendChild($attrUuid);
- foreach ($imageAction->getImages() as $mappedImage) {
- $reply = $this->response->createElement('reply');
- $attrSuccess = $this->response->createAttribute('success');
- if(isset($success[$mappedImage->getUuid()])) {
- $result = $success[$mappedImage->getUuid()];
- if(isset($result[0]) && is_bool($result[0])) {
- $attrSuccess->value = $result[0] ? 'true' : 'false';;
- } else {
- $attrSuccess->value = 'false';
- }
- if(isset($result[1]) && is_string($result[1])) {
- $textReplyMessage = $this->response->createTextNode($result[1]);
- $reply->appendChild($textReplyMessage);
- }
- } else {
- $attrSuccess->value = 'false';
- }
- $reply->appendChild($attrSuccess);
- $imageElement = $this->response->createElement('images');
- $attrImgUuid = $this->response->createAttribute('uuid');
- $attrImgName = $this->response->createAttribute('name');
- $attrImgUuid->value = $mappedImage->getUuid();
- $attrImgName->value = $mappedImage->getName();
- $imageElement->appendChild($reply);
- $imageTag->appendChild($imageElement);
- }
- $this->actions->appendChild($imageTag);
- }
- public function output($logReport = FALSE) {
- $response = $this->response->saveXML();
- if($logReport) {
- $this->log($response, 'ImageReport');
- }
- return $response;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement