Skip to content

Commit

Permalink
excel export example
Browse files Browse the repository at this point in the history
excel export example
  • Loading branch information
BigAndini committed Mar 5, 2015
1 parent 749d027 commit 1aee37f
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 6 deletions.
1 change: 1 addition & 0 deletions config/autoload/bjyauthorize.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@

/* Admin */
#['controller' => 'Admin\Controller\Admin', 'action' => 'index', 'roles' => ['admin']],
['controller' => 'Admin\Controller\Test', 'roles' => ['admin']],
['controller' => 'Admin\Controller\Admin', 'roles' => ['admin']],
['controller' => 'Admin\Controller\PriceLimit', 'roles' => ['admin']],
['controller' => 'Admin\Controller\Product', 'roles' => ['admin']],
Expand Down
15 changes: 15 additions & 0 deletions module/Admin/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
'Admin\Controller\Role' => 'Admin\Controller\RoleController',
'Admin\Controller\Order' => 'Admin\Controller\OrderController',
'Admin\Controller\Bankaccount' => 'Admin\Controller\BankaccountController',
'Admin\Controller\Test' => 'Admin\Controller\TestController',
),
),
'navigation' => array(
Expand Down Expand Up @@ -148,6 +149,20 @@
),
'may_terminate' => true,
'child_routes' => array(
'test' => array(
'type' => 'segment',
'options' => array(
'route' => '/test[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Admin\Controller\Test',
'action' => 'index',
),
),
),
'tax' => array(
'type' => 'segment',
'options' => array(
Expand Down
2 changes: 0 additions & 2 deletions module/Admin/src/Admin/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ public function indexAction()
{
return new ViewModel();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ProductPackageController extends AbstractActionController {

public function indexAction()
{
return $this->$this->notFoundAction();
return $this->notFoundAction();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ProductVariantController extends AbstractActionController
{
public function indexAction()
{
return $this->$this->notFoundAction();
return $this->notFoundAction();
}

public function addAction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ProductVariantValueController extends AbstractActionController
{
public function indexAction()
{
return $this->$this->notFoundAction();
return $this->notFoundAction();
}

public function viewAction()
Expand Down
79 changes: 79 additions & 0 deletions module/Admin/src/Admin/Controller/TestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

namespace Admin\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use ersEntity\Entity;
use Admin\Form;
use Admin\Service;

class TestController extends AbstractActionController {
public function indexAction() {
return $this->notFoundAction();
}

public function exportXlsAction()
{
set_time_limit( 0 );

$em = $this
->getServiceLocator()
->get('Doctrine\ORM\EntityManager');
$orders = $em->getRepository("ersEntity\Entity\Order")
->findBy(array(), array('created' => 'ASC'));

$filename = getcwd() . "/tmp/excel-" . date( "m-d-Y" ) . ".xls";
$realPath = realpath( $filename );
if ( false === $realPath ) {
touch( $filename );
chmod( $filename, 0644 );
}
$filename = realpath( $filename );

$finalData = array();
foreach ($orders as $order) {
$finalData[] = array(
utf8_decode($order->getId()),
utf8_decode($order->getCode()->getValue()),
utf8_decode($order->getPurchaser()->getPrename()),
utf8_decode($order->getPurchaser()->getSurname()),
utf8_decode($order->getCreated()->format('d.m.Y H:i:s')),
);
}
$handle = fopen( $filename, "w" );
if(!$handle) {
error_log('unable to open file '.$filename);
exit();
}
foreach ($finalData as $finalRow) {
fputcsv( $handle, $finalRow, "\t" );
}
fclose($handle);
#$this->_helper->layout->disableLayout();
#$this->_helper->viewRenderer->setNoRender();
/*$this->getResponse()->setRawHeader( "Content-Type: application/vnd.ms-excel; charset=UTF-8" )
->setRawHeader( "Content-Disposition: attachment; filename=excel.xls" )
->setRawHeader( "Content-Transfer-Encoding: binary" )
->setRawHeader( "Expires: 0" )
->setRawHeader( "Cache-Control: must-revalidate, post-check=0, pre-check=0" )
->setRawHeader( "Pragma: public" )
->setRawHeader( "Content-Length: " . filesize( $filename ) )
->sendResponse();
readfile( $filename ); exit();*/

$response = new \Zend\Http\Response();
$response->getHeaders()
->addHeaderLine('Content-Type', 'application/vnd.ms-excel; charset=utf-8')
->addHeaderLine('Content-Disposition', 'attachment; filename=orders-'.date('Ymd\THis').'.xls')
->addHeaderLine('Content-Length', filesize($filename));
$response->setContent(file_get_contents($filename));
return $response;
}
}
2 changes: 1 addition & 1 deletion module/PreReg/src/PreReg/Controller/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class PaymentController extends AbstractActionController {
public function indexAction() {
$this->$this->notFoundAction();
$this->notFoundAction();
}
/*
* display long description of payment type
Expand Down

0 comments on commit 1aee37f

Please sign in to comment.