Skip to content

Commit

Permalink
inital checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaDafinser committed Jul 24, 2014
1 parent 2d66753 commit 55d2e56
Show file tree
Hide file tree
Showing 14 changed files with 1,513 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
/**
* Needed if not installed with composer
*/
require_once __DIR__ . '/src/ZfcDatagrid/Module.php';
14 changes: 14 additions & 0 deletions autoload_classmap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
// Generated by ZF2's ./bin/classmap_generator.php
return array(
'ZfcDatagridExamples\Controller\CategoryController' => __DIR__ . '/src/ZfcDatagridExamples/Controller/CategoryController.php',
'ZfcDatagridExamples\Controller\MinimalController' => __DIR__ . '/src/ZfcDatagridExamples/Controller/MinimalController.php',
'ZfcDatagridExamples\Controller\PersonController' => __DIR__ . '/src/ZfcDatagridExamples/Controller/PersonController.php',
'ZfcDatagridExamples\Controller\PersonDoctrine2Controller' => __DIR__ . '/src/ZfcDatagridExamples/Controller/PersonDoctrine2Controller.php',
'ZfcDatagridExamples\Controller\PersonZendController' => __DIR__ . '/src/ZfcDatagridExamples/Controller/PersonZendController.php',
'ZfcDatagridExamples\Data\Doctrine2' => __DIR__ . '/src/ZfcDatagridExamples/Data/Doctrine2.php',
'ZfcDatagridExamples\Data\PhpArray' => __DIR__ . '/src/ZfcDatagridExamples/Data/PhpArray.php',
'ZfcDatagridExamples\Data\ZendSelect' => __DIR__ . '/src/ZfcDatagridExamples/Data/ZendSelect.php',
'ZfcDatagridExamples\Module' => __DIR__ . '/src/ZfcDatagridExamples/Module.php',
'ZfcDatagridTest\ModuleTest' => __DIR__ . '/tests/ZfcDatagridExamplesTest/ModuleTest.php',
);
165 changes: 165 additions & 0 deletions config/module.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?php
return array(

'service_manager' => array(

'invokables' => array(
// Datasources
'zfcDatagrid.examples.data.phpArray' => 'ZfcDatagridExamples\Data\PhpArray',
'zfcDatagrid.examples.data.doctrine2' => 'ZfcDatagridExamples\Data\Doctrine2',
'zfcDatagrid.examples.data.zendSelect' => 'ZfcDatagridExamples\Data\ZendSelect'
)
),

'controllers' => array(
'invokables' => array(
'ZfcDatagridExamples\Controller\Person' => 'ZfcDatagridExamples\Controller\PersonController',
'ZfcDatagridExamples\Controller\PersonDoctrine2' => 'ZfcDatagridExamples\Controller\PersonDoctrine2Controller',
'ZfcDatagridExamples\Controller\PersonZend' => 'ZfcDatagridExamples\Controller\PersonZendController',
'ZfcDatagridExamples\Controller\Minimal' => 'ZfcDatagridExamples\Controller\MinimalController',
'ZfcDatagridExamples\Controller\Category' => 'ZfcDatagridExamples\Controller\CategoryController'
)
),

'router' => array(
'routes' => array(
'ZfcDatagrid' => array(
'type' => 'Literal',
'options' => array(
'route' => '/zfcDatagrid',
'defaults' => array(
'__NAMESPACE__' => 'ZfcDatagridExamples\Controller',
'controller' => 'person',
'action' => 'bootstrap'
)
),

'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*'
),
'defaults' => array()
),

'may_terminate' => true,
'child_routes' => array(
'wildcard' => array(
'type' => 'Wildcard',

'may_terminate' => true,
'child_routes' => array(
'wildcard' => array(
'type' => 'Wildcard'
)
)
)
)
)
)
)
)
),

'console' => array(
'router' => array(
'routes' => array(
'datagrid-person' => array(
'options' => array(
'route' => 'datagrid person [--page=] [--items=] [--filterBys=] [--filterValues=] [--sortBys=] [--sortDirs=]',
'defaults' => array(
'controller' => 'ZfcDatagridExamples\Controller\Person',
'action' => 'console'
)
)
),

'datagrid-category' => array(
'options' => array(
'route' => 'datagrid category [--page=] [--items=] [--filterBys=] [--filterValues=] [--sortBys=] [--sortDirs=]',
'defaults' => array(
'controller' => 'ZfcDatagridExamples\Controller\Category',
'action' => 'console'
)
)
)
)
)
),

/**
* The ZF2 DbAdapter + Doctrine2 connection is must for examples!
*/
'zfcDatagrid_dbAdapter' => array(
'driver' => 'Pdo_Sqlite',
'database' => __DIR__ . '/../src/ZfcDatagrid/Examples/Data/examples.sqlite'
),

'doctrine' => array(
'connection' => array(
'orm_zfcDatagrid' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver',
'params' => array(
'charset' => 'utf8',
'path' => __DIR__ . '/../src/ZfcDatagrid/Examples/Data/examples.sqlite'
)
)
),

'configuration' => array(
'orm_zfcDatagrid' => array(
'metadata_cache' => 'array',
'query_cache' => 'array',
'result_cache' => 'array',
'driver' => 'orm_zfcDatagrid',
'generate_proxies' => true,
'proxy_dir' => 'data/ZfcDatagrid/Proxy',
'proxy_namespace' => 'ZfcDatagrid\Proxy',
'filters' => array()
)
),

'driver' => array(
'ZfcDatagrid_Driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(
__DIR__ . '/../src/ZfcDatagrid/Examples/Entity'
)
),

'orm_zfcDatagrid' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\DriverChain',
'drivers' => array(
'ZfcDatagridExamples\Entity' => 'ZfcDatagrid_Driver'
)
)
),

// now you define the entity manager configuration
'entitymanager' => array(
// This is the alternative config
'orm_zfcDatagrid' => array(
'connection' => 'orm_zfcDatagrid',
'configuration' => 'orm_zfcDatagrid'
)
),

'eventmanager' => array(
'orm_crawler' => array()
),

'sql_logger_collector' => array(
'orm_crawler' => array()
),

'entity_resolver' => array(
'orm_crawler' => array()
)
)
);
178 changes: 178 additions & 0 deletions src/ZfcDatagridExamples/Controller/CategoryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<?php
namespace ZfcDatagridExamples\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use ZfcDatagrid\Column;
use ZfcDatagrid\Column\Type;
use ZfcDatagrid\Example\Form\CategoryFilterForm;
use Zend\View\Model\ViewModel;
use Zend\View\Model\JsonModel;

class CategoryController extends AbstractActionController
{

/**
*
* @return \ZfcDatagrid\Datagrid
*/
private function getGrid()
{
/* @var $grid \ZfcDatagrid\Datagrid */
$grid = $this->getServiceLocator()->get('ZfcDatagrid\Datagrid');
$grid->setTitle('Categories');
$grid->setDefaultItemsPerPage(5);
$grid->setDataSource($this->getServiceLocator()
->get('zfcDatagrid.examples.data.phpArray')
->getCategorys());

$col = new Column\Select('id');
$col->setIdentity();
$grid->addColumn($col);

$colParentId = new Column\Select('parentId');
$colParentId->setHidden(true);
$grid->addColumn($colParentId);

$colHasChildren = new Column\Select('hasChildren');
$colHasChildren->setHidden(true);
$grid->addColumn($colHasChildren);

$colTags = new Column\Select('tags');
$colTags->setLabel('Tags');
$colTags->setHidden(true);
$colTags->setWidth(30);
$colTags->setType(new Type\PhpArray());
$grid->addColumn($colTags);

$toggle = new Column\Action\Button();
$toggle->setLabel('+');
$toggle->addShowOnValue($colHasChildren, 'y');
$toggle->setAttribute('onclick', 'console.log($(this).parent().parent().attr(\'id\'));$.get(\'/zfcDatagrid/category/tree\', function (data) {
console.log(this);
$.each(data.data, function (index, value) {
$(\'#'.$grid->getId().'\').jqGrid(\'addRowData\', value.idConcated, value, \'after\', 5);
});
});');

$col = new Column\Action();
$col->setLabel(' ');
$col->setUniqueId('expandAction');
$col->addAction($toggle);
$grid->addColumn($col);

$col = new Column\Select('name');
$col->setLabel('Name');
$col->setWidth(50);
$col->setSortDefault(1);
$col->setRendererParameter('formatter', '
function (cellvalue, options, rowObject) {
var valuePrint = cellvalue;
$.each(rowObject.'.$colTags->getUniqueId().', function (index, value) {
valuePrint += \' <span class="label">\' + value + \'</span>\';
});
return valuePrint;
}
', 'jqGrid');
$grid->addColumn($col);

$toggle = new Column\Action\Button();
$toggle->setLabel('other action...');
$toggle->addShowOnValue($colHasChildren, 'y');
$toggle->setAttribute('onclick', 'alert(\'clicked\');');

$col = new Column\Action();
// $col->setLabel('A');
$col->addAction($toggle);
$grid->addColumn($col);

return $grid;
}

/**
* Simple bootstrap table
*
* @return \ZfcDatagrid\Controller\ViewModel
*/
public function bootstrapAction()
{
$grid = $this->getGrid();
// $grid->setRendererName('bootstrapTable');
$grid->render();

return $grid->getResponse();
}

public function jqgridAction()
{
// $form = new CategoryFilterForm();

$viewModel = new ViewModel();

$grid = $this->getGrid();
$grid->setRendererName('jqGrid');
$grid->setUserFilterDisabled(true);

$grid->render();

return $grid->getResponse();
}

public function consoleAction()
{
$viewModel = new ViewModel();

$grid = $this->getGrid();
$grid->render();

return $grid->getResponse();
}

/**
* Get the tree data from a record
*/
public function treeAction()
{
$data = array();
$data[] = array(
'id' => 10,
'idParent' => '',
'hasChildren' => 'n',
'name' => 'blubb',
'tags' => array('Tag1', 'tag2...'),
'expandAction' => '',
'action' => '',
'idConcated' => 'blubb'
);

$viewModel = new JsonModel();
$viewModel->setVariable('data', $data);

return $viewModel;

return '
[
{"id":1,"parentId":"","hasChildren":"y","name":"Root","tags":["Tag1","Tag2"," Martin"," ZfcDatagrid"],"expandAction":"","action":"\u003Ca class=\u0022btn\u0022 href=\u0022#\u0022 onclick=\u0022alert(\u0027clicked\u0027);\u0022\u003Eblubb\u003C\/a\u003E","idConcated":"1"}
,{"id":5,"parentId":"","hasChildren":"y","name":"Root2","tags":[""],"expandAction":"", action":"\u003Ca class=\u0022btn\u0022 href=\u0022#\u0022 onclick=\u0022alert(\u0027clicked\u0027);\u0022\u003Eblubb\u003C\/a\u003E","idConcated":"5"}
,{"id":6,"parentId":5,"hasChildren":"n","name":"Second level of Root2","tags":[""],"expandAction":"","action":"","idConcated":"6"}
,{"id":2,"parentId":1,"hasChildren":"y","name":"Second level: entry 1","tags":["Tag1","Root"," Root2"],"expandAction":"","action":"\u003Ca class=\u0022btn\u0022 href=\u0022#\u0022 onclick=\u0022alert(\u0027clicked\u0027);\u0022\u003Eblubb\u003C\/a\u003E","idConcated":"2"}
,{"id":3,"parentId":2,"hasChildren":"n","name":"Third level: entry 1","tags":["cool"," stuff"],"expandAction":"","action":"","idConcated":"3"}
];
';
/*
* var myData= [
{"id":1,"parentId":"","hasChildren":"y","name":"&nbsp;&nbsp;&nbsp;&nbsp;<i class=\"icon-leaf\"></i> asdf <b>test</b>","action": "","idConcated":"10"}
,{"id":5,"parentId":"","hasChildren":"y","name":"&nbsp;&nbsp;&nbsp;&nbsp;asdf2","action":"","idConcated":"50"}
,{"id":6,"parentId":5,"hasChildren":"n","name":"&nbsp;&nbsp;&nbsp;&nbsp;asdf3 level of Root2","action":"","idConcated":"60"} ,{"id":2,"parentId":1,"hasChildren":"y","name":"&nbsp;&nbsp;&nbsp;&nbsp;asdf4 level: entry 1","action":"","idConcated":"20"} ,{"id":3,"parentId":2,"hasChildren":"n","name":"&nbsp;&nbsp;&nbsp;&nbsp;asdf5 level: entry 1","action":"","idConcated":"30"}
];
$.each(myData, function (index, value) {
$('#defaultGrid').jqGrid('addRowData', value.idConcated, value, 'after', 5);
});
//$('#defaultGrid').jqGrid('addRowData', 'idConcated', myData, 'first', 5);
*/
}
}
Loading

0 comments on commit 55d2e56

Please sign in to comment.