utilize elementMap for parsing DateTime string input argument for REPORT method

This commit is contained in:
Arthur Schiwon 2016-01-26 12:40:05 +01:00
parent 11ae468c89
commit 2027bf2686
1 changed files with 8 additions and 6 deletions

View File

@ -34,6 +34,7 @@ use Sabre\DAV\Xml\Element\Response;
use Sabre\DAV\Xml\Response\MultiStatus;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
use Sabre\Xml\Reader;
use Sabre\Xml\Writer;
/**
@ -45,7 +46,7 @@ class CommentsPlugin extends ServerPlugin {
const REPORT_PARAM_LIMIT = '{http://owncloud.org/ns}limit';
const REPORT_PARAM_OFFSET = '{http://owncloud.org/ns}offset';
const REPORT_PARAM_TIMESTAMP = '{http://owncloud.org/ns}datetime';
const REPORT_PARAM_DATETIME = '{http://owncloud.org/ns}datetime';
/** @var ICommentsManager */
protected $commentsManager;
@ -90,6 +91,11 @@ class CommentsPlugin extends ServerPlugin {
$writer->write($value->format('Y-m-d H:m:i'));
};
$this->server->xml->elementMap[self::REPORT_PARAM_DATETIME] = function(Reader $reader) {
$element = $reader->parseInnerTree();
return empty($element) ? null : new \DateTime($element);
};
$this->server->on('report', [$this, 'onReport']);
$this->server->on('method:POST', [$this, 'httpPost']);
}
@ -143,7 +149,7 @@ class CommentsPlugin extends ServerPlugin {
$acceptableParameters = [
$this::REPORT_PARAM_LIMIT,
$this::REPORT_PARAM_OFFSET,
$this::REPORT_PARAM_TIMESTAMP
$this::REPORT_PARAM_DATETIME
];
$ns = '{' . $this::NS_OWNCLOUD . '}';
foreach($report as $parameter) {
@ -153,10 +159,6 @@ class CommentsPlugin extends ServerPlugin {
$args[str_replace($ns, '', $parameter['name'])] = $parameter['value'];
}
if(!is_null($args['datetime'])) {
$args['datetime'] = new \DateTime($args['datetime']);
}
$results = $node->findChildren($args['limit'], $args['offset'], $args['datetime']);
$responses = [];