Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 13, 2012
Adrian Jones adrianj98 added bandTest Case 0992a7f
Commits on Dec 16, 2012
Adrian Jones adrianj98 rename components to match xml namings
Signed-off-by: Adrian Jones <adrianj1998@hotmail.com>
4dce50e
6 class/parser/JasperBand.php
View
@@ -16,7 +16,7 @@
* @author adrian
*/
-class JasperBand extends JasperObject {
+class Jasper_band extends JasperObject {
protected $_height;
protected $_isSplitAllowed;
@@ -42,9 +42,9 @@ public function parseElements($xml_path) {
$elementName = 'Jasper_'.$k;
if (class_exists($elementName))
- $element = new $elementName();
+ $element = new $elementName($this);
else
- $element = new JasperElement();
+ $element = new Jasper_reportElement($this);
$element->type = $k;
$element->parse($out);
$this->addElement($element);
33 class/parser/JasperElement.php
View
@@ -10,7 +10,7 @@
*
* @author adrian
*/
-class JasperElement extends JasperObject {
+class Jasper_reportElement extends JasperObject {
function getInt($value,$def=0)
{
@@ -26,6 +26,11 @@ function getString($value,$def='')
return (string)$value;
}
+
+ function __construct($parent) {
+ $this->parent = $parent;
+ parent::__construct();
+ }
function getBool($value,$def=false)
{
if (!isset($value))
@@ -47,7 +52,7 @@ function getBool($value,$def=false)
protected $_fillcolor = array("r" => 255, "g" => 255, "b" => 255);
protected $_stretchoverflow = "true";
protected $_printoverflow = "false";
-
+ protected $_printWhenExpression = '';
function parse($data)
{
@@ -56,7 +61,7 @@ function parse($data)
$this->y = $this->getInt($data->reportElement["y"]);
$this->width = $this->getInt($data->reportElement["width"]);
/** allow forground color "forecolor" */
-
+ $this->printWhenExpression = $this->getString($data->reportElement->printWhenExpression);
//reportElement
if (isset($data->reportElement["forecolor"])) {
$this->textcolor = array("r" => hexdec(substr($data->reportElement["forecolor"], 1, 2)), "g" => hexdec(substr($data->reportElement["forecolor"], 3, 2)), "b" => hexdec(substr($data->reportElement["forecolor"], 5, 2)));
@@ -76,15 +81,24 @@ function parse($data)
}
}
+
+ function layout()
+ {
+ // if visible
+
+ }
}
-class JasperBox extends JasperElement
+class Jasper_box extends Jasper_reportElement
{
//box
- protected $_border = 0;
+ protected $_border = 0;
protected $_drawcolor = array("r" => 0, "g" => 0, "b" => 0);
-
+ function layout()
+ {
+ parent::layout();
+ }
function parse($data)
{
parent::parse($data) ;
@@ -99,7 +113,7 @@ function parse($data)
}
-class JasperText extends JasperBox
+class Jasper_textElement extends Jasper_box
{
//textElement
@@ -110,7 +124,10 @@ class JasperText extends JasperBox
protected $_font = "helvetica";
protected $_fontstyle = '';
-
+ function getTextSize($text)
+ {
+
+ }
function parse($data)
{
parent::parse($data) ;
24 class/parser/JasperElements.php
View
@@ -10,7 +10,7 @@
*
* @author adrian
*/
-class Jasper_staticText extends JasperText {
+class Jasper_staticText extends Jasper_textElement {
protected $_text = "";
@@ -27,7 +27,7 @@ public function parse($data) {
// $this->report->pointer[] = array("type" => "SetFont", "font" => $font, "fontstyle" => $fontstyle, "fontsize" => $fontsize, "hidden_type" => "font");
//"height"=>$data->reportElement["height"]
//### UTF-8 characters, a must for me.
- $txtEnc = ($data->text);
+ $txtEnc = (string)($data->text);
$this->text = $$txtEnc;
@@ -38,7 +38,12 @@ public function parse($data) {
//### End of modification, below is the original line
// $this->report->pointer[]=array("type"=>"MultiCell","width"=>$data->reportElement["width"],"height"=>$height,"txt"=>$data->text,"border"=>$border,"align"=>$align,"fill"=>$fill,"hidden_type"=>"statictext","soverflow"=>$stretchoverflow,"poverflow"=>$printoverflow,"rotation"=>$rotation);
}
-
+ function layout()
+ {
+ parent::layout();
+
+ $this->getTextSize($this->text);
+ }
}
/**
@@ -46,7 +51,7 @@ public function parse($data) {
*
* @todo hyperlinks need to be covered
*/
-class Jasper_textField extends JasperText {
+class Jasper_textField extends Jasper_textElement {
protected $_textFieldExpression = "";
@@ -55,15 +60,20 @@ public function parse($data) {
parent::parse($data);
- $this->textFieldExpression = $data->textFieldExpression;
+ $this->textFieldExpression = (string) $data->textFieldExpression;
+ }
+ function layout()
+ {
+ parent::layout();
+ $text = ''; //need get text expression
+ $this->getTextSize($text);
}
-
}
/**
*
* @link http://jasperforge.org/uploads/publish/jasperreportswebsite/trunk/schema.reference.html#group
*/
-class Japser_group extends JasperElement {
+class Japser_group extends Jasper_reportElement {
public $_groupFooter;
public $_groupHeader;
191 tests/class/parser/JasperBandTest.php
View
@@ -0,0 +1,191 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../../class/parser/JasperBand.php';
+
+/**
+ * Test class for JasperBand.
+ * Generated by PHPUnit on 2012-08-25 at 15:23:15.
+ */
+class JasperBandTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @var JasperBand
+ */
+ protected $object;
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp() {
+ $this->object = new Jasper_band();
+ }
+
+ /**
+ * Tears down the fixture, for example, closes a network connection.
+ * This method is called after a test is executed.
+ */
+ protected function tearDown() {
+
+ }
+
+ /**
+ * @covers JasperBand::addElement
+ * @todo Implement testAddElement().
+ */
+ public function testAddElement() {
+ // Remove the following lines when you implement this test.
+ $this->markTestIncomplete(
+ 'This test has not been implemented yet.'
+ );
+ }
+
+ /**
+ * @covers JasperBand::parse
+ * @todo Implement testParse().
+ */
+ public function testParse() {
+
+ $xml = simplexml_load_string($this->testBand);
+
+ $this->object->parse($xml);
+ $this->assertEquals('177',$this->object->height);
+ $this->assertEquals('Stretch',$this->object->splitType);
+ $this->assertEmpty($this->object->isSplitAllowed);
+
+ }
+
+ /**
+ * @covers JasperBand::parseElements
+ * @todo Implement testParseElements().
+ */
+ public function testParseElements() {
+ // Remove the following lines when you implement this test.
+ $this->markTestIncomplete(
+ 'This test has not been implemented yet.'
+ );
+ }
+
+
+
+ public $testBand = '<pageHeader>
+ <band height="177" splitType="Stretch">
+ <textField>
+ <reportElement style="Column header" x="492" y="14" width="66" height="26" forecolor="#000000">
+ <printWhenExpression><![CDATA[$P{printType} == ( "quote" )]]></printWhenExpression>
+ </reportElement>
+ <textElement/>
+ <textFieldExpression><![CDATA[$F{sample2_date}]]></textFieldExpression>
+ </textField>
+ <textField>
+ <reportElement x="478" y="78" width="69" height="20"/>
+ <textElement>
+ <font isBold="true"/>
+ </textElement>
+ <textFieldExpression><![CDATA[$F{sample2_docno}]]></textFieldExpression>
+ </textField>
+ <textField>
+ <reportElement x="5" y="78" width="238" height="20"/>
+ <textElement>
+ <font size="12" isBold="true"/>
+ </textElement>
+ <textFieldExpression><![CDATA[$F{sample2_companyname}]]></textFieldExpression>
+ </textField>
+ <textField>
+ <reportElement x="5" y="98" width="238" height="20"/>
+ <textElement/>
+ <textFieldExpression><![CDATA[$F{sample2_address}]]></textFieldExpression>
+ </textField>
+ <textField>
+ <reportElement x="478" y="118" width="69" height="20"/>
+ <textElement/>
+ <textFieldExpression><![CDATA[$F{sample2_terms}]]></textFieldExpression>
+ </textField>
+ <staticText>
+ <reportElement x="243" y="78" width="52" height="20"/>
+ <textElement/>
+ <text><![CDATA[PO No :]]></text>
+ </staticText>
+ <staticText>
+ <reportElement x="423" y="98" width="52" height="20"/>
+ <textElement/>
+ <text><![CDATA[PO Date :]]></text>
+ </staticText>
+ <staticText>
+ <reportElement x="423" y="118" width="52" height="20"/>
+ <textElement/>
+ <text><![CDATA[Terms :]]></text>
+ </staticText>
+ <image>
+ <reportElement x="2" y="0" width="65" height="65"/>
+ <imageExpression><![CDATA["./simitlogo.jpg"]]></imageExpression>
+ </image>
+ <staticText>
+ <reportElement x="204" y="118" width="185" height="20"/>
+ <textElement textAlignment="Center">
+ <font size="14" isBold="true" isUnderline="true"/>
+ </textElement>
+ <text><![CDATA[Purchase Order]]></text>
+ </staticText>
+ <staticText>
+ <reportElement x="74" y="5" width="288" height="19" forecolor="#D6D6D6"/>
+ <textElement>
+ <font size="12" isBold="true"/>
+ </textElement>
+ <text><![CDATA[Sim IT Sdn Bhd]]></text>
+ </staticText>
+ <staticText>
+ <reportElement x="74" y="24" width="325" height="19"/>
+ <textElement/>
+ <text><![CDATA[10B-1, Jalan Mawar 4, 81900 Kota Tinggi, Johor, Malaysia]]></text>
+ </staticText>
+ <staticText>
+ <reportElement x="74" y="43" width="473" height="20"/>
+ <textElement/>
+ <text><![CDATA[Tel: 078835330, Fax: 078835330 Website: http://www.simit.com.my Email: sales@simit.com.my]]></text>
+ </staticText>
+ <staticText>
+ <reportElement x="0" y="157" width="22" height="20"/>
+ <textElement textAlignment="Center">
+ <font size="12" isBold="true" isUnderline="true"/>
+ </textElement>
+ <text><![CDATA[No]]></text>
+ </staticText>
+ <staticText>
+ <reportElement x="22" y="157" width="258" height="20"/>
+ <textElement textAlignment="Center">
+ <font size="12" isBold="true" isUnderline="true"/>
+ </textElement>
+ <text><![CDATA[Item]]></text>
+ </staticText>
+ <staticText>
+ <reportElement x="352" y="157" width="87" height="20"/>
+ <textElement textAlignment="Center">
+ <font size="12" isBold="true" isUnderline="true"/>
+ </textElement>
+ <text><![CDATA[Qty]]></text>
+ </staticText>
+ <staticText>
+ <reportElement x="439" y="157" width="100" height="20"/>
+ <textElement textAlignment="Center">
+ <font size="12" isBold="true" isUnderline="true"/>
+ </textElement>
+ <text><![CDATA[Amount]]></text>
+ </staticText>
+ <staticText>
+ <reportElement x="280" y="157" width="72" height="20"/>
+ <textElement textAlignment="Center">
+ <font size="12" isBold="true" isUnderline="true"/>
+ </textElement>
+ <text><![CDATA[Unit Price]]></text>
+ </staticText>
+ <textField>
+ <reportElement x="343" y="66" width="100" height="20"/>
+ <textElement/>
+ <textFieldExpression><![CDATA[$F{sample2_date}]]></textFieldExpression>
+ </textField>
+ </band>
+ </pageHeader>';
+}
+
+

No commit comments for this range

Something went wrong with that request. Please try again.