Skip to content

Commit

Permalink
Merge pull request #1 from italolelis/master
Browse files Browse the repository at this point in the history
Novas funcionalidades de PDF e padronização da PSR-0
  • Loading branch information
italolelis committed Jan 21, 2014
2 parents 9731cc7 + f240e50 commit 9f22043
Show file tree
Hide file tree
Showing 56 changed files with 1,371 additions and 725 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
11 changes: 8 additions & 3 deletions composer.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
{
"name": "umbrella/simpletablereport",
"description": "PHP Simple Table Report. Export data as tables to PDF, CSV, Excel, etc...",
"license": "APL",
"license": "MIT",
"authors": [
{
"name": "kelsoncm",
"email": "[email protected]"
},
{
"name": "Ítalo Lelis",
"email": "[email protected]"
}
],
"require": {

},
"autoload": {
"classmap": ["./src"]
"psr-0": {
"Umbrella\\SimpleReport": "src/"
}
}
}
8 changes: 4 additions & 4 deletions config.ini
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; this is an INI file
[section]
simpletablereport.configurationClassName = BaseConfiguration
simpletablereport.configurationClassName = Umbrella\SimpleReport\BaseConfiguration

simpletablereport.decimaltype.precision = 3;
simpletablereport.decimaltype.separator = '.';
Expand All @@ -26,10 +26,10 @@ simpletablereport.timestamptype.toformat = d/m/Y H:i:s

simpletablereport.xlsxrenderer.sample = sample.excel.zip

simpletablereport.htmlrenderer.documentbody.start = '<!DOCTYPE html><html><head><title></title><meta charset="UTF-8"></head><body>'
simpletablereport.htmlrenderer.documentbody.end = '</body></html>'
simpletablereport.htmlrenderer.documentbody.start = ''
simpletablereport.htmlrenderer.documentbody.end = ''

simpletablereport.htmlrenderer.table.start = '<table>'
simpletablereport.htmlrenderer.table.start = '<table border="1">'
simpletablereport.htmlrenderer.table.end = '</table>'

simpletablereport.htmlrenderer.table.head.start = '<thead>'
Expand Down
Empty file modified phpunit.xml
100644 → 100755
Empty file.
Empty file modified sample.excel.zip
100644 → 100755
Empty file.
239 changes: 129 additions & 110 deletions ...simpletablereport/api/FieldDefinition.php → ...ella/SimpleReport/Api/FieldDefinition.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,110 +1,129 @@
<?php

/*
* Copyright 2013 kelsoncm.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
*
* @author kelsoncm
*/
class FieldDefinition {

private static $loadedFieldsTypes = array();

private $fieldName;
private $fieldType;
private $fieldSize;
private $fieldWidth;
private $fieldOrder;
private $fieldCaption;

function __construct($fieldName, $fieldCaption, $fieldType=FieldType::STRING, $fieldSize=null, $fieldWidth=null) {
$this->fieldName = $fieldName;
$this->fieldType = $fieldType;
$this->fieldSize = $fieldSize;
$this->fieldWidth = $fieldWidth;
$this->fieldCaption = $fieldCaption;
}

public function getFieldName() {
return $this->fieldName;
}

public function getFieldType() {
return $this->fieldType;
}

public function getFieldTypeInstance($strategy = '') {
$key = "{$this->fieldType}, {$strategy}";
if (!isset(FieldDefinition::$loadedFieldsTypes[$key])) {
FieldDefinition::$loadedFieldsTypes[$key] = $this->createFieldType($this->fieldType, $strategy);
}
return FieldDefinition::$loadedFieldsTypes[$key];
}

public function getFieldSize() {
return $this->fieldSize;
}

public function getFieldWidth() {
return $this->fieldWidth;
}

public function getFieldOrder() {
return $this->fieldOrder;
}

public function getFieldCaption() {
return $this->fieldCaption;
}

public function setFieldName($fieldName) {
$this->fieldName = $fieldName;
}

public function setFieldType($fieldType) {
$this->fieldType = $fieldType;
}

public function setFieldSize($fieldSize) {
$this->fieldSize = $fieldSize;
}

public function setFieldWidth($fieldWidth) {
$this->fieldWidth = $fieldWidth;
}

public function setFieldOrder($fieldOrder) {
$this->fieldOrder = $fieldOrder;
}

public function setFieldCaption($fieldCaption) {
$this->fieldCaption = $fieldCaption;
}

protected function createFieldType($fieldTypeName, $strategy) {
$classnameBase = ucfirst(strtolower($fieldTypeName)) . 'Type';
$classnameConcrete = ucfirst(strtolower($strategy)) . $classnameBase;
if (class_exists($classnameConcrete,true)) {
return new $classnameConcrete(array());
} elseif(class_exists($classnameBase,true)) {
return new $classnameBase(array());
} else {
throw new Exception("Field class don't exists for field type '{$fieldTypeName}'.");
}
}

}
<?php

/*
* Copyright 2013 kelsoncm.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Umbrella\SimpleReport\Api;

use Exception;

/**
*
* @author kelsoncm
*/
class FieldDefinition
{

private static $loadedFieldsTypes = array();
private $fieldName;
private $fieldType;
private $fieldSize;
private $fieldWidth;
private $fieldOrder;
private $fieldCaption;

function __construct($fieldName, $fieldCaption, $fieldType = FieldType::STRING, $fieldSize = null, $fieldWidth = null)
{
$this->fieldName = $fieldName;
$this->fieldType = $fieldType;
$this->fieldSize = $fieldSize;
$this->fieldWidth = $fieldWidth;
$this->fieldCaption = $fieldCaption;
}

public function getFieldName()
{
return $this->fieldName;
}

public function getFieldType()
{
return $this->fieldType;
}

public function getFieldTypeInstance($strategy = '')
{
$key = "{$this->fieldType}, {$strategy}";
if (!isset(FieldDefinition::$loadedFieldsTypes[$key])) {
FieldDefinition::$loadedFieldsTypes[$key] = $this->createFieldType($this->fieldType, $strategy);
}
return FieldDefinition::$loadedFieldsTypes[$key];
}

public function getFieldSize()
{
return $this->fieldSize;
}

public function getFieldWidth()
{
return $this->fieldWidth;
}

public function getFieldOrder()
{
return $this->fieldOrder;
}

public function getFieldCaption()
{
return $this->fieldCaption;
}

public function setFieldName($fieldName)
{
$this->fieldName = $fieldName;
}

public function setFieldType($fieldType)
{
$this->fieldType = $fieldType;
}

public function setFieldSize($fieldSize)
{
$this->fieldSize = $fieldSize;
}

public function setFieldWidth($fieldWidth)
{
$this->fieldWidth = $fieldWidth;
}

public function setFieldOrder($fieldOrder)
{
$this->fieldOrder = $fieldOrder;
}

public function setFieldCaption($fieldCaption)
{
$this->fieldCaption = $fieldCaption;
}

protected function createFieldType($fieldTypeName, $strategy)
{
$classnameBase = ucfirst(strtolower($fieldTypeName)) . 'Type';
$classnameConcrete = ucfirst(strtolower($strategy)) . $classnameBase;
if (class_exists($classnameConcrete, true)) {
return new $classnameConcrete(array());
} elseif (class_exists($classnameBase, true)) {
return new $classnameBase(array());
} else {
throw new Exception("Field class don't exists for field type '{$fieldTypeName}'.");
}
}

}
19 changes: 12 additions & 7 deletions src/simpletablereport/api/FieldSet.php → src/Umbrella/SimpleReport/Api/FieldSet.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,28 @@
* limitations under the License.
*/

namespace Umbrella\SimpleReport\Api;

/**
*
* @author kelsoncm
*/
class FieldSet extends ArrayIterator {

class FieldSet extends \ArrayIterator
{

protected $fieldcount = 0;

function __construct() {

function __construct()
{
parent::__construct(array());
}

public function addField($fieldName, $fieldCaption, $fieldType, $fieldSize=null, $fieldWidth=null) {

public function addField($fieldName, $fieldCaption, $fieldType, $fieldSize = null, $fieldWidth = null)
{
$fieldDefinition = new FieldDefinition($fieldName, $fieldCaption, $fieldType, $fieldSize, $fieldWidth);
$fieldDefinition->setFieldOrder($this->count());
parent::append($fieldDefinition);
return $this;
}

}
28 changes: 16 additions & 12 deletions src/simpletablereport/api/FieldType.php → src/Umbrella/SimpleReport/Api/FieldType.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,40 @@
* limitations under the License.
*/

namespace Umbrella\SimpleReport\Api;

/**
* Description of FieldType
*
* @author kelsoncm <[email protected]>
*/
abstract class FieldType {

abstract class FieldType
{

const STRING = 'STRING';

const DATE = 'DATE';
const TIME = 'TIME';
const TIMESTAMP = 'TIMESTAMP';

const INTEGER = 'INTEGER';
const FLOAT = 'FLOAT';
const DECIMAL = 'DECIMAL';
const MONEY = 'MONEY';

protected $options;
protected $typeprefix;

function __construct($options) {

function __construct($options)
{
$this->options = $options;
}

public function render($value){

public function render($value)
{
return $this->format($this->toPrimitiveType($value));
}

public function getOption($optionName) {

public function getOption($optionName)
{
if (isset($this->options["simpletablereport.{$this->typeprefix}.{$optionName}"])) {
return $this->options["simpletablereport.{$this->typeprefix}.{$optionName}"];
} elseif (isset($this->options["simpletablereport.{$optionName}"])) {
Expand All @@ -56,6 +60,6 @@ public function getOption($optionName) {
}

public abstract function format($value);
public abstract function toPrimitiveType($value);

public abstract function toPrimitiveType($value);
}
Loading

0 comments on commit 9f22043

Please sign in to comment.