Ejemplo n.º 1
0
 /**
  * This function handles the addressbook-query REPORT
  *
  * This report is used by the client to filter an addressbook based on a
  * complex query.
  *
  * @param Xml\Request\AddressBookQueryReport $report
  * @return void
  */
 protected function addressbookQueryReport($report)
 {
     $depth = $this->server->getHTTPDepth(0);
     if ($depth == 0) {
         $candidateNodes = [$this->server->tree->getNodeForPath($this->server->getRequestUri())];
         if (!$candidateNodes[0] instanceof ICard) {
             throw new ReportNotSupported('The addressbook-query report is not supported on this url with Depth: 0');
         }
     } else {
         $candidateNodes = $this->server->tree->getChildren($this->server->getRequestUri());
     }
     $contentType = $report->contentType;
     if ($report->version) {
         $contentType .= '; version=' . $report->version;
     }
     $vcardType = $this->negotiateVCard($contentType);
     $validNodes = [];
     foreach ($candidateNodes as $node) {
         if (!$node instanceof ICard) {
             continue;
         }
         $blob = $node->get();
         if (is_resource($blob)) {
             $blob = stream_get_contents($blob);
         }
         if (!$this->validateFilters($blob, $report->filters, $report->test)) {
             continue;
         }
         $validNodes[] = $node;
         if ($report->limit && $report->limit <= count($validNodes)) {
             // We hit the maximum number of items, we can stop now.
             break;
         }
     }
     $result = [];
     foreach ($validNodes as $validNode) {
         if ($depth == 0) {
             $href = $this->server->getRequestUri();
         } else {
             $href = $this->server->getRequestUri() . '/' . $validNode->getName();
         }
         list($props) = $this->server->getPropertiesForPath($href, $report->properties, 0);
         if (isset($props[200]['{' . self::NS_CARDDAV . '}address-data'])) {
             $props[200]['{' . self::NS_CARDDAV . '}address-data'] = $this->convertVCard($props[200]['{' . self::NS_CARDDAV . '}address-data'], $vcardType);
         }
         $result[] = $props;
     }
     $prefer = $this->server->getHTTPPrefer();
     $this->server->httpResponse->setStatus(207);
     $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
     $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer');
     $this->server->httpResponse->setBody($this->server->generateMultiStatus($result, $prefer['return'] === 'minimal'));
 }
Ejemplo n.º 2
0
 /**
  * principalPropertySearchReport
  *
  * This method is responsible for handing the
  * {DAV:}principal-property-search report. This report can be used for
  * clients to search for groups of principals, based on the value of one
  * or more properties.
  *
  * @param string $path
  * @param Xml\Request\PrincipalPropertySearchReport $report
  * @return void
  */
 protected function principalPropertySearchReport($path, Xml\Request\PrincipalPropertySearchReport $report)
 {
     if ($report->applyToPrincipalCollectionSet) {
         $path = null;
     }
     if ($this->server->getHttpDepth('0') !== 0) {
         throw new BadRequest('Depth must be 0');
     }
     $result = $this->principalSearch($report->searchProperties, $report->properties, $path, $report->test);
     $prefer = $this->server->getHTTPPrefer();
     $this->server->httpResponse->setStatus(207);
     $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
     $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer');
     $this->server->httpResponse->setBody($this->server->generateMultiStatus($result, $prefer['return'] === 'minimal'));
 }