Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion classes/Basictypes/Boolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
8 changes: 4 additions & 4 deletions classes/TestApp/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class TestApp_Document extends Adaptor_XMLBase implements Adaptor_Array {
/**
* Удален
*
* @var string
* @var Basictypes_Boolean
*/
private $deleted;
/**
Expand Down Expand Up @@ -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);}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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"];
Expand Down
15 changes: 15 additions & 0 deletions classes/TestApp/DocumentListRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ class TestApp_DocumentListRequest extends Adaptor_XMLBase {
*/
public $dateEnd;

/**
* Наименование
*
* @var string
*/
public $name = NULL;

/**
* Формат вывода
*
Expand All @@ -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();
}
Expand All @@ -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){
Expand Down
82 changes: 69 additions & 13 deletions web/documentList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
1 change: 1 addition & 0 deletions web/schemas/TestApp/DocumentListRequest.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<xsd:sequence>
<xsd:element name="dateStart" type="xsd:date"/>
<xsd:element name="dateEnd" type="xsd:date"/>
<xsd:element name="name" type="xsd:string" minOccurs="0" nillable="true"/>
<xsd:element name="outputFormat" minOccurs="0" default="html">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
Expand Down
33 changes: 32 additions & 1 deletion web/stylesheets/TestApp/DocumentList.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,27 @@
<input size="10" type="text" name="dateEnd-0" value="{$req/req:dateEnd}"/>
</label>
</div>
<div>
<div style="margin-top: 10px;">
<label title="Наименование">
Наименование
<input type="text" name="name-0" value="{$req/req:name}"/>
</label>
</div>
<div style="margin-top: 10px;">
<span>Формат вывода
<label style="margin-right: 5px;">
<input type="radio" name="outputFormat-0" value="html">
<xsl:attribute name="checked"/>
</input>
html
</label>
<label style="margin-right: 5px;">
<input type="radio" name="outputFormat-0" value="pdf"/>
pdf
</label>
</span>
</div>
<div style="margin-top: 10px;">
<button type="submit">Отправить</button>
</div>
</fieldset>
Expand All @@ -59,10 +79,15 @@
Документы с
<xsl:value-of select="req:DocumentListRequest/req:dateStart"/> по
<xsl:value-of select="req:DocumentListRequest/req:dateEnd"/>
<xsl:if test="req:DocumentListRequest/req:name"><!--
-->, содержащие в названии "<xsl:value-of select="req:DocumentListRequest/req:name"/>"
</xsl:if>
</caption>
<tr>
<th>Дата</th>
<th>Наименование</th>
<th>Ключевые слова</th>
<th>Удален</th>
</tr>
<xsl:for-each select="obj:Document">
<tr>
Expand All @@ -74,6 +99,12 @@
<xsl:value-of select="obj:displayName"/>
</a>
</td>
<td>
<xsl:value-of select="obj:keywords"/>
</td>
<td>
<xsl:value-of select="obj:deleted"/>
</td>
</tr>
</xsl:for-each>
</table>
Expand Down
81 changes: 81 additions & 0 deletions web/stylesheets/TestApp/DocumentListFO.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:obj="urn:ru:ilb:meta:TestApp:Document"
xmlns:res="urn:ru:ilb:meta:TestApp:DocumentListResponse"
xmlns:req="urn:ru:ilb:meta:TestApp:DocumentListRequest"
exclude-result-prefixes="xsl fo obj res req">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" font-family="Liberation Serif" font-size="10pt" language="en">
<fo:layout-master-set>
<fo:simple-page-master master-name="A4Form" page-height="29.7cm" page-width="21cm" margin="1cm 1.5cm 1cm 1.5cm">
<fo:region-body />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4Form" initial-page-number="1">
<fo:flow flow-name="xsl-region-body" font-size="8pt" font-family="Liberation Serif">
<fo:block-container width="175mm" border-bottom-style="solid" border-width="thin" space-after="2mm">
<xsl:apply-templates />
</fo:block-container>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="res:DocumentListResponse">
<fo:block space-after="2mm">
<xsl:text>Документы с </xsl:text>
<xsl:value-of select="req:DocumentListRequest/req:dateStart"/> по
<xsl:value-of select="req:DocumentListRequest/req:dateEnd"/>
<xsl:if test="req:DocumentListRequest/req:name"><!--
-->, содержащие в названии "<xsl:value-of select="req:DocumentListRequest/req:name"/>"
</xsl:if>
</fo:block>
<fo:table table-layout="fixed" width="175mm">
<fo:table-column column-width="25mm"/>
<fo:table-column column-width="100mm"/>
<fo:table-column column-width="25mm"/>
<fo:table-column column-width="25mm"/>
<fo:table-body>
<fo:table-row text-align="center" font-weight="bold" border-top-style="solid" border-bottom-style="solid" border-width="thin">
<fo:table-cell>
<fo:block>Дата</fo:block>
</fo:table-cell>
<fo:table-cell text-align="left">
<fo:block>Наименование</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>Ключевые слова</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>Удален</fo:block>
</fo:table-cell>
</fo:table-row>
<xsl:for-each select="obj:Document">
<fo:table-row text-align="center">
<fo:table-cell text-align="center">
<fo:block>
<xsl:value-of select="obj:docDate"/>
</fo:block>
</fo:table-cell>
<fo:table-cell text-align="left">
<fo:block>
<xsl:value-of select="obj:displayName"/>
</fo:block>
</fo:table-cell>
<fo:table-cell text-align="center">
<fo:block>
<xsl:value-of select="obj:keywords"/>
</fo:block>
</fo:table-cell>
<fo:table-cell text-align="center">
<fo:block>
<xsl:value-of select="obj:deleted"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</xsl:template>
</xsl:stylesheet>