diff --git a/classes/Basictypes/Boolean.php b/classes/Basictypes/Boolean.php index bbb78b7..f2d8808 100644 --- a/classes/Basictypes/Boolean.php +++ b/classes/Basictypes/Boolean.php @@ -27,7 +27,7 @@ public function setValue($value){ return $this->value; } public function __toString(){ - return $this->value?"true":"false"; + return $this->value?"Да":"Нет"; } public function LogicalToXSD(){ return $this->value?"true":"false"; diff --git a/classes/TestApp/Document.php b/classes/TestApp/Document.php index bbed4a4..c192b21 100644 --- a/classes/TestApp/Document.php +++ b/classes/TestApp/Document.php @@ -58,7 +58,7 @@ class TestApp_Document extends Adaptor_XMLBase implements Adaptor_Array { /** * Удален * - * @var string + * @var Basictypes_Boolean */ private $deleted; /** @@ -127,7 +127,7 @@ public function toXmlWriter(XMLWriter &$xw,$xmlname=NULL,$xmlns=NULL,$mode=Adapt if($this->modifyUid!==NULL) {$xw->writeElement("modifyUid",$this->modifyUid);} if($this->deleteDate!==NULL) {$xw->writeElement("deleteDate",$this->deleteDate->LogicalToXSD());} if($this->deleteUid!==NULL) {$xw->writeElement("deleteUid",$this->deleteUid);} - if($this->deleted!==NULL) {$xw->writeElement("deleted",$this->deleted);} + if($this->deleted!==NULL) {$xw->writeElement("deleted",$this->deleted->__toString());} if($this->containerId!==NULL) {$xw->writeElement("containerId",$this->containerId);} if($this->containerType!==NULL) {$xw->writeElement("containerType",$this->containerType);} if($this->chapterPath!==NULL) {$xw->writeElement("chapterPath",$this->chapterPath);} @@ -158,7 +158,7 @@ public function fromXmlReader(XMLReader &$xr){ case "modifyUid": $this->modifyUid=$xsinil?NULL:$xr->readString(); break; case "deleteDate": $this->deleteDate=$xsinil?NULL:new Basictypes_DateTime($xr->readString(),Adaptor_DataType::XSD); break; case "deleteUid": $this->deleteUid=$xsinil?NULL:$xr->readString(); break; - case "deleted": $this->deleted=$xsinil?NULL:$xr->readString(); break; + case "deleted": $this->deleted=$xsinil?NULL:new Basictypes_Boolean($xr->readString()); break; case "containerId": $this->containerId=$xsinil?NULL:$xr->readString(); break; case "containerType": $this->containerType=$xsinil?NULL:$xr->readString(); break; case "chapterPath": $this->chapterPath=$xsinil?NULL:$xr->readString(); break; @@ -186,7 +186,7 @@ public function fromArray($row,$mode=Adaptor_DataType::XSD){ if(isset($row["modifyUid"])) $this->modifyUid=$row["modifyUid"]; if(isset($row["deleteDate"])) $this->deleteDate=new Basictypes_DateTime($row["deleteDate"],$mode); if(isset($row["deleteUid"])) $this->deleteUid=$row["deleteUid"]; - if(isset($row["deleted"])) $this->deleted=$row["deleted"]; + if(isset($row["deleted"])) $this->deleted=new Basictypes_Boolean($row["deleted"]); if(isset($row["containerId"])) $this->containerId=$row["containerId"]; if(isset($row["containerType"])) $this->containerType=$row["containerType"]; if(isset($row["chapterPath"])) $this->chapterPath=$row["chapterPath"]; diff --git a/classes/TestApp/DocumentListRequest.php b/classes/TestApp/DocumentListRequest.php index 3602025..30a1f50 100644 --- a/classes/TestApp/DocumentListRequest.php +++ b/classes/TestApp/DocumentListRequest.php @@ -22,6 +22,13 @@ class TestApp_DocumentListRequest extends Adaptor_XMLBase { */ public $dateEnd; + /** + * Наименование + * + * @var string + */ + public $name = NULL; + /** * Формат вывода * @@ -48,6 +55,7 @@ public function toXmlWriter(XMLWriter &$xw,$xmlname=NULL,$xmlns=NULL,$mode=Adapt if ($mode&Adaptor_XML::STARTELEMENT) $xw->startElementNS(NULL,$xmlname,$xmlns); if($this->dateStart!==NULL) {$xw->writeElement("dateStart",$this->dateStart->LogicalToXSD());} if($this->dateEnd!==NULL) {$xw->writeElement("dateEnd",$this->dateEnd->LogicalToXSD());} + if($this->name!==NULL) {$xw->writeElement("name",$this->name);} if($this->outputFormat!==NULL) {$xw->writeElement("outputFormat",$this->outputFormat);} if ($mode&Adaptor_XML::ENDELEMENT) $xw->endElement(); } @@ -66,6 +74,13 @@ public function fromXmlReader(XMLReader &$xr){ switch($xr->localName){ case "dateStart": $this->dateStart=$xsinil?NULL:new Basictypes_Date($xr->readString(),Adaptor_DataType::XSD); break; case "dateEnd": $this->dateEnd=$xsinil?NULL:new Basictypes_Date($xr->readString(),Adaptor_DataType::XSD); break; + case "name": + if ($xsinil) $this->name = NULL; + else { + $name = $xr->readString(); + $this->name = empty($name) ? NULL : $name; + } + break; case "outputFormat": $this->outputFormat=$xsinil?NULL:$xr->readString(); break; } }elseif($xr->nodeType==XMLReader::END_ELEMENT&&$root==$xr->localName){ diff --git a/web/documentList.php b/web/documentList.php index dffc7f7..6af41c8 100644 --- a/web/documentList.php +++ b/web/documentList.php @@ -15,25 +15,81 @@ $xw->openMemory(); $xw->setIndent(TRUE); $xw->startDocument("1.0", "UTF-8"); -$xw->writePi("xml-stylesheet", "type=\"text/xsl\" href=\"stylesheets/TestApp/DocumentList.xsl\""); -$xw->startElementNS(NULL, "DocumentListResponse", "urn:ru:ilb:meta:TestApp:DocumentListResponse"); -$req->toXmlWriter($xw); -// Если есть входные данные, проведем вычисления и выдадим ответ -if (!$hreq->isEmpty()) { - $pdo=new PDO("mysql:host=localhost;dbname=testapp","testapp","1qazxsw2",array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); + +if ($req->outputFormat == 'pdf') { + $xw->startElementNS(NULL, "DocumentListResponse", "urn:ru:ilb:meta:TestApp:DocumentListResponse"); + $req->toXmlWriter($xw); + if (!$hreq->isEmpty()) documentWriter($xw, $req); + $xw->endElement(); + $xw->endDocument(); + + $xml = $xw->flush(); + + $xmldom = new DOMDocument(); + $xmldom->loadXML($xml); + $xsldom = new DomDocument(); + $xsldom->load("stylesheets/TestApp/DocumentListFO.xsl"); + $proc = new XSLTProcessor(); + $proc->importStyleSheet($xsldom); + $xml = $proc->transformToXML($xmldom); + + $url = "https://demo01.ilb.ru/fopservlet/fopservlet"; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/xml")); + curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); + $res = curl_exec($ch); + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + if ($code != 200) { + throw new Exception($res . PHP_EOL . $url . " " . curl_error($ch), 450); + } + curl_close($ch); + + $headers = array( + "Content-Type: application/pdf", + "Content-Disposition: inline; filename*=UTF-8''" . "DocumentList.pdf" //TODO + ); + + foreach ($headers as $h) { + header($h); + } + + echo $res; +} +else { + $xw->writePi("xml-stylesheet", "type=\"text/xsl\" href=\"stylesheets/TestApp/DocumentList.xsl\""); + $xw->startElementNS(NULL, "DocumentListResponse", "urn:ru:ilb:meta:TestApp:DocumentListResponse"); + $req->toXmlWriter($xw); + // Если есть входные данные, проведем вычисления и выдадим ответ + if (!$hreq->isEmpty()) documentWriter($xw, $req); + $xw->endElement(); + $xw->endDocument(); + + $xml = $xw->flush(); + + //Вывод ответа клиенту + header("Content-Type: text/xml"); + echo $xml; +} + +function documentWriter(XMLWriter &$xw, $req) { + $pdo=new PDO("mysql:host=localhost;dbname=testapp;charset=utf8","testapp","1qazxsw2",array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); //prior to PHP 5.3.6, the charset option was ignored. If you're running an older version of PHP, you must do it like this: //$pdo->exec("set names utf8"); + $query = "SELECT * FROM document WHERE (docDate BETWEEN :dateStart AND :dateEnd)"; $query = "SELECT * FROM document WHERE docDate BETWEEN :dateStart AND :dateEnd"; + if ($req->name !== NULL) { + $query .= " AND (displayName LIKE '%{$req->name}%');"; + } $sth=$pdo->prepare($query); - $sth->execute(array(":dateStart"=>$req->dateStart,":dateEnd"=>$req->dateEnd)); + $statement = array(":dateStart"=>$req->dateStart,":dateEnd"=>$req->dateEnd); + $sth->execute($statement); while($row=$sth->fetch(PDO::FETCH_ASSOC)) { $doc = new TestApp_Document(); $doc->fromArray($row); $doc->toXmlWriter($xw); } -} -$xw->endElement(); -$xw->endDocument(); -//Вывод ответа клиенту -header("Content-Type: text/xml"); -echo $xw->flush(); +} \ No newline at end of file diff --git a/web/schemas/TestApp/DocumentListRequest.xsd b/web/schemas/TestApp/DocumentListRequest.xsd index 8ed58ec..4e02344 100644 --- a/web/schemas/TestApp/DocumentListRequest.xsd +++ b/web/schemas/TestApp/DocumentListRequest.xsd @@ -11,6 +11,7 @@ + diff --git a/web/stylesheets/TestApp/DocumentList.xsl b/web/stylesheets/TestApp/DocumentList.xsl index c175070..271faf6 100644 --- a/web/stylesheets/TestApp/DocumentList.xsl +++ b/web/stylesheets/TestApp/DocumentList.xsl @@ -48,7 +48,27 @@ -
+
+ +
+
+ Формат вывода + + + +
+
@@ -59,10 +79,15 @@ Документы с по + , содержащие в названии "" + Дата Наименование + Ключевые слова + Удален @@ -74,6 +99,12 @@ + + + + + + diff --git a/web/stylesheets/TestApp/DocumentListFO.xsl b/web/stylesheets/TestApp/DocumentListFO.xsl new file mode 100644 index 0000000..80b5b4b --- /dev/null +++ b/web/stylesheets/TestApp/DocumentListFO.xsl @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + Документы с + по + + , содержащие в названии "" + + + + + + + + + + + Дата + + + Наименование + + + Ключевые слова + + + Удален + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file