Skip to content

Commit

Permalink
Merge pull request #188 from ThaDafinser/imonteiro-master
Browse files Browse the repository at this point in the history
style: align + strike
  • Loading branch information
ThaDafinser committed Jul 15, 2015
2 parents 48298af + ad6f2e5 commit 0db898a
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 3 deletions.
2 changes: 2 additions & 0 deletions autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
'ZfcDatagrid\Column\Style\BackgroundColor' => __DIR__ . '/src/ZfcDatagrid/Column/Style/BackgroundColor.php',
'ZfcDatagrid\Column\Style\Bold' => __DIR__ . '/src/ZfcDatagrid/Column/Style/Bold.php',
'ZfcDatagrid\Column\Style\Color' => __DIR__ . '/src/ZfcDatagrid/Column/Style/Color.php',
'ZfcDatagrid\Column\Style\Align' => __DIR__ . '/src/ZfcDatagrid/Column/Style/Align.php',
'ZfcDatagrid\Column\Style\Strikethrough' => __DIR__ . '/src/ZfcDatagrid/Column/Style/Strikethrough.php',
'ZfcDatagrid\Column\Style\Italic' => __DIR__ . '/src/ZfcDatagrid/Column/Style/Italic.php',
'ZfcDatagrid\Column\Type\AbstractType' => __DIR__ . '/src/ZfcDatagrid/Column/Type/AbstractType.php',
'ZfcDatagrid\Column\Type\DateTime' => __DIR__ . '/src/ZfcDatagrid/Column/Type/DateTime.php',
Expand Down
2 changes: 2 additions & 0 deletions docs/03. Columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ In this part, we will learn the following:
* Bold
* Color
* Italic
* Align
* Strikethrough
* Applying Style
* Column Data Formatters
* Email
Expand Down
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ If you are looking for some information that is not listed in the documentation,
* Bold
* Color
* Italic
* Align
* Strikethrough
* Applying Style
5. [Column Data Formatters](/docs/03. Columns.md#column-data-formatters)
* Email
Expand Down
61 changes: 61 additions & 0 deletions src/ZfcDatagrid/Column/Style/Align.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
namespace ZfcDatagrid\Column\Style;

class Align extends AbstractStyle
{
/**
*
* @var string
*/
public static $LEFT = 'left';

/**
*
* @var string
*/
public static $RIGHT = 'right';

/**
*
* @var string
*/
public static $CENTER = 'center';

/**
*
* @var string
*/
public static $JUSTIFY= 'justify';

/**
*
* @var string
*/
protected $alignment;

public function __construct($alignment = self::LEFT)
{
$this->setAlignment($alignment);
}

/**
*
* @param string $alignment
* @return self
*/
public function setAlignment($alignment)
{
$this->alignment = $alignment;

return $this;
}

/**
*
* @return string
*/
public function getAlignment()
{
return $this->alignment;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ public function __invoke($row, array $cols, AbstractAction $rowClickAction = nul
case 'ZfcDatagrid\Column\Style\BackgroundColor':
$cssStyles[] = 'background-color: #' . $style->getRgbHexString();
break;
case 'ZfcDatagrid\Column\Style\Align':
$cssStyles[] = 'text-align: '.$style->getAlignment();
break;
case 'ZfcDatagrid\Column\Style\Strikethrough':
$value = '<s>'.$value.'</s>';
break;
default:
throw new \InvalidArgumentException('Not defined style: "' . get_class($style) . '"');
break;
Expand Down
4 changes: 4 additions & 0 deletions src/ZfcDatagrid/Renderer/JqGrid/View/Helper/Columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ private function getStyles(Column\AbstractColumn $col)
// do NOTHING! this is done by loadComplete event...
// At this stage jqgrid haven't created the columns...
break;

case 'ZfcDatagrid\Column\Style\Align':
$styleString = 'cellvalue = \'<span style="text-align: '.$style->getAlignment().';">\' + cellvalue + \'</span>\';';
break;

default:
throw new \Exception('Not defined style: "' . get_class($style) . '"');
Expand Down
22 changes: 22 additions & 0 deletions src/ZfcDatagrid/Renderer/PHPExcel/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PHPExcel_Style_Color;
use PHPExcel_Style_Fill;
use PHPExcel_Worksheet_PageSetup;
use PHPExcel_Style_Alignment;
use Zend\Http\Headers;
use Zend\Http\Response\Stream as ResponseStream;
use ZfcDatagrid\Renderer\AbstractExport;
Expand Down Expand Up @@ -122,6 +123,27 @@ public function execute()
],
]);
break;

case 'ZfcDatagrid\Column\Style\Align':
switch ($style->getAlignment()) {
case \ZfcDatagrid\Column\Style\Align::$RIGHT:
$columnStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
break;
case \ZfcDatagrid\Column\Style\Align::$LEFT:
$columnStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
break;
case \ZfcDatagrid\Column\Style\Align::$CENTER:
$columnStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
break;
case \ZfcDatagrid\Column\Style\Align::$JUSTIFY:
$columnStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
break;
default:
//throw new \Exception('Not defined yet: "'.get_class($style->getAlignment()).'"');
break;
}

break;

case 'ZfcDatagrid\Column\Style\Strikethrough':
$columnStyle->getFont()->setStrikethrough(true);
Expand Down
50 changes: 47 additions & 3 deletions src/ZfcDatagrid/Renderer/TCPDF/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ class Renderer extends AbstractExport
* @var TCPDF
*/
protected $pdf;

/**
*
* @var Alignment
*/
protected $alignment = 'L';

public function getName()
{
Expand Down Expand Up @@ -267,7 +273,7 @@ protected function printTableHeader()
$label = $this->getTranslator()->translate($col->getLabel());

// Do not wrap header labels, it will look very ugly, that's why max height is set to 7!
$pdf->MultiCell($col->getWidth(), 7, $label, 1, 'L', true, 2, $x, $y, true, 0, false, true, 7);
$pdf->MultiCell($col->getWidth(), 7, $label, 1, $this->getTextAlignment(), true, 2, $x, $y, true, 0, false, true, 7);
}
}

Expand Down Expand Up @@ -361,16 +367,36 @@ protected function printTableRow(array $row, $rowHeight)
$text = '<del>' . $text . '</del>';
$isHtml = true;
break;

case 'ZfcDatagrid\Column\Style\Align':
switch ($style->getAlignment()) {
case \ZfcDatagrid\Column\Style\Align::$RIGHT:
$this->setTextAlignment('R');
break;
case \ZfcDatagrid\Column\Style\Align::$LEFT:
$this->setTextAlignment('L');
break;
case \ZfcDatagrid\Column\Style\Align::$CENTER:
$this->setTextAlignment('C');
break;
case \ZfcDatagrid\Column\Style\Align::$JUSTIFY:
$this->setTextAlignment('J');
break;
default:
//throw new \Exception('Not defined yet: "'.get_class($style->getAlignment()).'"');
break;
}
break;

default:
throw new \Exception('Not defined yet: "' . get_class($style) . '"');
break;
}
}
}

// MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0, $valign='T', $fitcell=false)
$pdf->MultiCell($col->getWidth(), $rowHeight, $text, 1, 'L', $backgroundColor, 1, $x, $y, true, 0, $isHtml);
$pdf->MultiCell($col->getWidth(), $rowHeight, $text, 1, $this->getTextAlignment(), $backgroundColor, 1, $x, $y, true, 0, $isHtml);
}
}

Expand Down Expand Up @@ -468,4 +494,22 @@ protected function setBackgroundColor(array $rgb)
$pdf = $this->getPdf();
$pdf->SetFillColor($rgb['red'], $rgb['green'], $rgb['blue']);
}

/**
*
* @param string $alignment
*/
public function setTextAlignment($alignment)
{
$this->alignment = $alignment;
}

/**
*
* @return string
*/
public function getTextAlignment()
{
return $this->alignment;
}
}
17 changes: 17 additions & 0 deletions tests/ZfcDatagridTest/Column/Style/StrikethroughTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
namespace ZfcDatagridTest\Column\Style;

use PHPUnit_Framework_TestCase;
use ZfcDatagrid\Column\Style;

/**
* @group Column
* @covers ZfcDatagrid\Column\Style\Strikethrough
*/
class StrikethroughTest extends PHPUnit_Framework_TestCase
{
public function testCanCreateInstance()
{
$strikethrough = new Style\Strikethrough();
}
}
4 changes: 4 additions & 0 deletions view/zfc-datagrid/renderer/jqGrid/layout.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ foreach($this->rowStyles as $style){
case 'ZfcDatagrid\Column\Style\BackgroundColor':
$css = '\'background-color\', \'#' . $style->getRgbHexString().'\'';
break;

case 'ZfcDatagrid\Column\Style\Align':
$css = '\'text-align\'' . $style->getAlignment();
break;

default:
throw new \Exception('Not defined yet: "' . get_class($style) . '"');
Expand Down

0 comments on commit 0db898a

Please sign in to comment.