Exemplo n.º 1
0
 /**
  * This function retrieves a resource descriptor for a specified resource at $path on the server.
  * If you wish to supply information to the input controls you can supply the data to the $p and $pl arguments.
  *
  * @param string $path
  * @param bool $fileData - set to true if you wish to receive the binary data of the resource (i.e: with images)
  * @param string $ic_get_query_data - the datasource to query
  * @param string $p - single select parameters | example: array(parameter_name, value)
  * @param string $pl - multi select parameters | example: array(parameter_name, array(value1, value2, value3))
  * @return \Jasper\ResourceDescriptor
  */
 public function getResource($path, $fileData = false, $ic_get_query_data = null, $p = null, $pl = null)
 {
     $url = $this->restUrl . '/resource' . $path;
     $suffix = $fileData ? http_build_query(array('fileData' => 'true')) : null;
     $suffix .= http_build_query(array('IC_GET_QUERY_DATA' => $ic_get_query_data));
     if (!empty($p)) {
         $suffix .= http_build_query($p);
     }
     if (!empty($pl)) {
         $param = array_shift($pl);
         if (!empty($suffix)) {
             $suffix .= '&';
         }
         // http_build_query will take the numerical array and transfer the index keys ([0], [1], etc) into text
         // for the URL. This is undesirable in this scenario, so we use a regular expression to remove the indices
         $suffix .= preg_replace('/%5B([0-9]{1,})%5D/', null, http_build_query(array('PL_' . $param => $pl)));
     }
     if (!empty($suffix)) {
         $url .= '?' . $suffix;
     }
     $data = $this->prepAndSend($url, array(200), 'GET', null, true);
     if ($fileData === true) {
         return $data;
     } else {
         return ResourceDescriptor::createFromXML($data);
     }
 }
Exemplo n.º 2
0
 /**
  * This class method is used to construct a ResourceDescriptor object by providing the XML for that object.
  *
  * @param string $xml - XML String defining ResourceDescriptor
  * @return ResourceDescriptor
  */
 public static function createFromXML($xml)
 {
     $sxi = new \SimpleXMLIterator($xml);
     $temp = new self((string) $sxi->attributes()->name, (string) $sxi->attributes()->wsType, (string) $sxi->attributes()->uriString, (string) $sxi->attributes()->isNew);
     $desc = !empty($sxi->description) ? (string) $sxi->description : null;
     $label = !empty($sxi->label) ? (string) $sxi->label : null;
     $date = !empty($sxi->creationDate) ? (string) $sxi->creationDate : null;
     $temp->setLabel($label);
     $temp->setDescription($desc);
     $temp->setCreationDate($date);
     foreach ($sxi->resourceDescriptor as $nestRd) {
         $temp->children[] = ResourceDescriptor::createFromXML($nestRd->asXML());
     }
     foreach ($sxi->resourceProperty as $prop) {
         $temp->properties[] = ResourceProperty::createFromXML($prop->asXML());
     }
     return $temp;
 }