Advertisement
Guest User

Untitled

a guest
Jun 29th, 2012
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.28 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Builds the report.
  5.  */
  6. class ImageReport extends AbstractReport {
  7.    
  8.     /**
  9.      * The reply.
  10.      *  
  11.      * @var DOMDocument
  12.      */
  13.     protected $response;
  14.    
  15.     /**
  16.      * The root element of the reply.
  17.      *
  18.      * @var DOMElement
  19.      */
  20.     protected $actions;
  21.    
  22.     /**
  23.      * Creates a document and adds root element.
  24.      */
  25.     public function __construct() {                              
  26.        
  27.         $this->response = new DOMDocument();
  28.         $this->response->formatOutput = true;
  29.          
  30.         $this->actions = $this->response->createElement('actions');        
  31.         $this->response->appendChild($this->actions);
  32.        
  33.     }
  34.    
  35.  
  36.    
  37.     /**
  38.      * Adds an entry to the report
  39.      * @param ImageAction $imageAction
  40.      * @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)
  41.      */
  42.     public function add(ImageAction $imageAction, array $success) {
  43.  
  44.         $imageTag = $this->response->createElement($imageAction->getAction());
  45.        
  46.         $attrUuid = $this->response->createAttribute('actionUuid');
  47.         $attrShortId = $this->response->createAttribute('actionShortid');
  48.        
  49.         $attrUuid->value = $imageAction->getActionUuid();
  50.         $attrShortId->value = $imageAction->getActionShortId();
  51.        
  52.         $imageTag->appendChild($attrShortId);
  53.         $imageTag->appendChild($attrUuid);
  54.        
  55.         foreach ($imageAction->getImages() as $mappedImage) {
  56.                        
  57.             $reply = $this->response->createElement('reply');
  58.             $attrSuccess = $this->response->createAttribute('success');
  59.            
  60.             if(isset($success[$mappedImage->getUuid()])) { 
  61.         $result = $success[$mappedImage->getUuid()];
  62.                 if(isset($result[0]) && is_bool($result[0])) {
  63.                     $attrSuccess->value = $result[0] ? 'true' : 'false';;
  64.                 } else {
  65.                     $attrSuccess->value = 'false';
  66.                 }
  67.                
  68.                 if(isset($result[1]) && is_string($result[1])) {
  69.                      $textReplyMessage = $this->response->createTextNode($result[1]);
  70.                      $reply->appendChild($textReplyMessage);
  71.                 }
  72.                
  73.             } else {
  74.                 $attrSuccess->value = 'false';
  75.             }
  76.            
  77.            
  78.             $reply->appendChild($attrSuccess);  
  79.  
  80.             $imageElement = $this->response->createElement('images');
  81.             $attrImgUuid = $this->response->createAttribute('uuid');
  82.             $attrImgName = $this->response->createAttribute('name');
  83.            
  84.             $attrImgUuid->value = $mappedImage->getUuid();
  85.             $attrImgName->value = $mappedImage->getName();
  86.            
  87.             $imageElement->appendChild($reply);                
  88.             $imageTag->appendChild($imageElement);
  89.         }
  90.        
  91.         $this->actions->appendChild($imageTag);  
  92.        
  93.     }
  94.    
  95.     public function output($logReport = FALSE) {
  96.          
  97.         $response = $this->response->saveXML();
  98.        
  99.         if($logReport) {
  100.             $this->log($response, 'ImageReport');
  101.         }
  102.        
  103.         return $response;
  104.     }  
  105.    
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement