My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
<?php


function AddAutoCompleteToFields(Bvb_Grid_Event $event)
{

$subject = $event->getSubject();
$script = "$(document).ready(function() {";
foreach ($subject->getVisibleFields() as $name) {
$script .= "$(\"input#filter_$name\").autocomplete({focus: function(event, ui) "
. "{document.getElementById('filter_$name').value = ui.item.value },"
. " source: '{$subject->getAutoCompleteUrlForFilter($name)}'});\n";
}
$script .= "});";

$subject->getView()->headScript()->appendScript($script);
}

function my_callback(Bvb_Grid_Event $event)
{
/*
$subject = $event->getSubject();

$dateFieldName_to = $subject->getParam('dateFieldName_to');
$subject->setParam('dateFieldName[to]',$dateFieldName_to);
$subject->removeParam('dateFieldName_to');//This line is optional. You may need this value. I don't know you code.
*/
#Others here....

}

/**
* @author mascker
*/

include 'application/models/Model.php';


function people ($id, $value, $select)
{
$select->where('Population>?', $value);
}


function filterContinent ($id, $value, $select)
{
$select->where('Continent=?', $value);
}

class SiteController extends Zend_Controller_Action
{

private $_db;

function teste()
{
echo "<pre>";

print_r(func_get_args());

echo '<br><br><br><br><br>';
die();
}

/**
* If a action don't exist, just redirect to the basic
*
* @param string $name
* @param array $var
*/
public function __call ($name, $var)
{
$this->_redirect('default/site/basic', array('exit' => 1));
return false;
}


public function dojoAction ()
{

$grid = $this->grid();

$grid->addFiltersRenderDir( 'Bvb/Grid/Filters/Render/Dojo', 'Bvb_Grid_Filters_Render_Dojo');

$select = $this->_db->select()->from('Country', array('Code','Name', 'Continent', 'Population', 'LocalName', 'GovernmentForm'))->order('Code ASC');
$grid->query($select);

$filters = new Bvb_Grid_Filters();
$filters->addFilter('date', array('render'=>'date'));
$filters->addFilter('Population', array('render'=>'number'));
$filters->addFilter('status', array('distinct' => array('field' => 'status', 'name' => 'status'),'render'=>'select'));
$grid->addFilters($filters);

$this->view->pages = $grid->deploy();
$this->render('index');
}


/**
* I think this is needed for something. can't remember
*
*/
public function init ()
{
Zend_Dojo::enableView($this->view);

$this->view->url = Zend_Registry::get('config')->site->url;
$this->view->action = $this->getRequest()->getActionName();
header('Content-Type: text/html; charset=ISO-8859-1');
$this->_db = Zend_Registry::get('db');
Bvb_Grid_Deploy_Ofc::$url = Zend_Registry::get('config')->site->url;
}


/**
* Same as __call
*
*/
public function indexAction ()
{
$this->_forward('basic');
}


public function formAction ()
{
$grid = $this->grid();
$grid->query($this->_db->select()->from(array('iu'=>'form')));
$form = new Bvb_Grid_Form();
$form->setBulkAdd(2)->setAdd(true)->setEdit(true)->setBulkDelete(true)->setBulkEdit(true)->setDelete(true)->setAddButton(true);
$grid->setForm($form);
$this->view->pages = $grid->deploy();
$this->render('index');
}


public function form1Action ()
{
$grid = $this->grid();
$grid->query($this->_db->select()->from('form'));
$form = new Bvb_Grid_Form();
$form->setBulkAdd(5)->setAdd(true)->setEdit(true)->setBulkDelete(true)->setBulkEdit(true)->setDelete(true)->setAddButton(true);
$form->setUseVerticalInputs(false);
$grid->setForm($form);
$this->view->pages = $grid->deploy();
$this->render('index');
}


/**
* Show the source code for this controller
*
*/
public function codeAction ()
{
$this->render('code');
}


/**
* Simplify the datagrid creation process
* @return Bvb_Grid_Deploy_Table
*/
public function grid ($id = '')
{
$view = new Zend_View();
$view->setEncoding('ISO-8859-1');
$config = new Zend_Config_Ini('./application/grids/grid.ini', 'production');
$grid = Bvb_Grid::factory('Table', $config, $id);
$grid->setEscapeOutput(false);
$grid->setExport(array( 'xml','csv','excel','pdf'));
$grid->setView($view);


#$grid->saveParamsInSession(true);
#$grid->setCache(array('enable' => array('form'=>false,'db'=>false), 'instance' => Zend_Registry::get('cache'), 'tag' => 'grid'));
return $grid;
}


/**
* A simple usage of advanced filters. Every time you change a filter, the system automatically
*runs a query to the others filters, making sure they don't allow you to filter for a record that is not in the database
*/
public function filtersAction ()
{

$grid = $this->grid('ois');

$grid->setSource(new Bvb_Grid_Source_Zend_Select($this->_db->select()->from('Country', array('Name', 'Continent', 'Population', 'LifeExpectancy', 'GovernmentForm', 'HeadOfState'))));

$filters = new Bvb_Grid_Filters();
$filters->addFilter('Name', array('distinct' => array('field' => 'Name', 'name' => 'Name', 'order' => 'field desc')));
$filters->addFilter('Continent', array('distinct' => array('field' => 'Continent', 'name' => 'Continent')));
$filters->addFilter('LifeExpectancy', array('render' => 'number', 'distinct' => array('field' => 'LifeExpectancy', 'name' => 'LifeExpectancy')));
$filters->addFilter('GovernmentForm', array('distinct' => array('field' => 'GovernmentForm', 'name' => 'GovernmentForm')));
$filters->addFilter('HeadOfState');
$filters->addFilter('Population', array('render' => 'number'));


$grid->addFilters($filters);


$grid->addExternalFilter('new_filter', 'people');
$grid->addExternalFilter('filter_country', 'filterContinent');

$this->view->pages = $grid->deploy();
$this->render('index');
}


public function pdfAction ()
{

$grid = $this->grid();
$grid->setSource(new Bvb_Grid_Source_Zend_Select($this->_db->select()->from('message')));
$this->view->pages = $grid->deploy();
$this->render('index');
}

public function dateAction ()
{

$grid = $this->grid();

$grid->setSource(new Bvb_Grid_Source_Zend_Select($this->_db->select()->from('bugs', array('bug_status', 'status', 'date', 'time'))));

$filters = new Bvb_Grid_Filters();
$filters->addFilter('date', array('render' => 'date'));

$grid->addFilters($filters);

$this->view->pages = $grid->deploy();
$this->render('index');
}


/**
* Adding extra columns to a datagrid. They can be at left or right.
* Also notice that you can use fields values to populate the fields by surrounding the field name with {{}}
*
*/
public function extraAction ()
{

$grid = $this->grid();

$select = $this->_db->select()->from(array('c' => 'Country'), array('country' => 'Name', 'Continent', 'Population', 'GovernmentForm', 'HeadOfState'))->join(array('ct' => 'City'), 'c.Capital = ct.ID', array('city' => 'Name'));

$grid->setSource(new Bvb_Grid_Source_Zend_Select($select));

$grid->updateColumn('country', array('title' => 'Country (Capital)', 'class' => 'hideInput', 'decorator' => '{{country}} <em>({{city}})</em>'));
$grid->updateColumn('city', array('title' => 'Capital', 'hidden' => 1));
$grid->updateColumn('Continent', array('title' => 'Continent'));
$grid->updateColumn('Population', array('title' => 'Population', 'class' => 'width_80'));
$grid->updateColumn('LifeExpectancy', array('title' => 'Life E.', 'class' => 'width_50'));
$grid->updateColumn('GovernmentForm', array('title' => 'Government Form'));
$grid->updateColumn('HeadOfState', array('title' => 'Head Of State', 'hidden' => 1));

$grid->setPdfGridColumns(array('Continent','Population'));


$right = new Bvb_Grid_Extra_Column();
$right->setPosition('right')->setName('Right')->setDecorator("<input class='input_p'type='text' value=\"{{Population}}\" size=\"3\" name='number[]'>");

$left = new Bvb_Grid_Extra_Column();
$left->setPosition('left')->setName('Left')->setDecorator("<input type='checkbox' name='number[]'>");

$grid->addExtraColumns($right, $left);


$row = new Bvb_Grid_Extra_Rows();
$row->addRow('beforePagination', array(array('content' => '<button class="addRecord" type="button" onClick="if(confirm(\'Please confirm you wish to approve all.\')){window.location=\'/admin/campaigns/approveall\'};return false;">Approve All</button>', 'colspan' => 6, 'class' => 'r')));
$grid->addExtraRows($row);

#$grid->addExtraColumn($grid->getExtraColumn('Left'));

$this->view->pages = $grid->deploy();
$this->render('index');
}


public function csvAction ()
{

$grid = $this->grid();
$grid->setSource(new Bvb_Grid_Source_Csv('media/files/grid.csv'));
$grid->setSqlExp(array('Population' => array('functions' => array('SUM'), 'value' => 'Population')));

$form = new Bvb_Grid_Form();
#$form->setIsPerformCrudAllowed(false);
$form->setAdd(1)->setEdit(1)->setDelete(1)->setAddButton(1);
#$form->addElement('text','my');



$grid->setForm($form);

$this->view->pages = $grid->deploy();
$this->render('index');
}


public function jsonAction ()
{

$grid = $this->grid();
$grid->setSource(new Bvb_Grid_Source_Json('media/files/json.json', 'rows'));
$this->view->pages = $grid->deploy();
$this->render('index');
}


public function feedAction ()
{

$grid = $this->grid();
$grid->setSource(new Bvb_Grid_Source_Xml('http://zfdatagrid.com/feed/', 'channel,item'));

$grid->setRecordsPerPage(10);

$grid->updateColumn('title', array('decorator' => '<a href="{{link}}">{{title}}</a>', 'style' => 'width:200px;'));
$grid->updateColumn('pubDate', array('class' => 'width_200'));

$grid->setGridColumns(array('title', 'comments', 'pubDate'));

$this->view->pages = $grid->deploy();
$this->render('index');
}


/**
* The 'most' basic example.
*/
public function openAction ()
{
$grid = $this->grid();


$this->view->pages = $grid->deploy();
$this->render('index');
}


static function callback()
{
echo "<pre>";
print_r(func_get_args());
die();
}



public function pgsqlAction()
{
$grid = $this->grid();
$select = $this->_db->select()->from('tb_nivel');
$grid->query($select);

$form = new Bvb_Grid_Form();
$form->setAdd(true)->setEdit(true)->setDelete(true)->setAddButton(true);
$grid->setForm($form);

$grid->listenEvent('crud.before_insert', create_function('$event', 'print_r($event->getParams());die();'));

$this->view->pages = $grid->deploy();
$this->render('index');
}

/**
* The 'most' basic example.
*/
public function horizontalAction ()
{
$grid = $this->grid();
$select = $this->_db->select()->from('Country', array('Code','Name', 'Continent', 'Population', 'LocalName'))->order('Code ASC');
$grid->query($select);

$grid->setRecordsPerPage(7);
$grid->setNoFilters(1);
$grid->setNoOrder(1);

$grid->setTemplate('horizontal', 'table');
$this->view->pages = $grid->deploy();
$this->render('index');
}

/**
* The 'most' basic example.
*/
public function basicAction ()
{
$grid = $this->grid();
$select = $this->_db->select()->from('Country', array('Code','Name', 'Continent', 'Population', 'LocalName', 'GovernmentForm'))->order('Code ASC');
#$grid->setSource(new Bvb_Grid_Source_Zend_Select($select));
$grid->query($select);

#$grid->getSelect()->columns(array('calc'=>" CONCAT(Name,'')"));
#$grid->setSqlExp(array('calc' => array('functions' => array('LENGTH'))));
$grid->setUseKeyEventsOnFilters(true);

#$grid->setShowOrderImages(false);

#$grid->setShowFiltersInExport(array('User'=>'Barcelos'));
#$grid->setDefaultFiltersValues(array('Continent'=>'Europe'));
#$grid->setAlwaysShowOrderArrows(false);
#$grid->setDefaultFiltersValues(array('Population'=>'12'));

#$grid->setDeployOptions(array('title'=>'My Custom Title','subtitle'=>date('Y-m-d')));

#$grid->saveParamsInSession(true);

#$grid->placePageAtRecord('PRT','green');
#$grid->updateColumn('Name',array('searchType'=>'sqlExp','searchSqlExp'=>'Name !={{value}} '));


#$grid->listenEvent('grid.init_deploy', create_function('$event', 'echo "It works!!!!".$event->getName();die();'));
$grid->listenEvent('grid.init_deploy', 'AddAutoCompleteToFields');

#$grid->updateCOlumn('Name',array('callback'=>array('function'=>array($this,'callback'),'params'=>array('{{Name}}'))));

#$grid->setDeployOption('title', 'Barcelos');

#$grid->setCsvGridColumns(array('Name','Population'));

$this->view->pages = $grid->deploy();
$this->render('index');
}


public function referenceAction ()
{

$grid = $this->grid();
$grid->setSource(new Bvb_Grid_Source_Zend_Table(new Products()));

$form = new Bvb_Grid_Form();
$form->setAdd(true)->setEdit(true)->setDelete(true);
$grid->setForm($form);

$this->view->pages = $grid->deploy();

$this->render('index');
}


public function multiAction ()
{
$grid = $this->grid('a');
$select = $this->_db->select()->from('Country', array('Name', 'Continent', 'Population', 'LocalName', 'GovernmentForm'));
$grid->query($select);
$this->view->pages = $grid->deploy();

$grid2 = $this->grid('b');
$select2 = $this->_db->select()->from('Country', array('Name', 'Continent', 'Population', 'GovernmentForm'));
$grid2->query($select2);
$grid2->setTemplate('outside', 'table');
$grid2->setRecordsPerPage(10);
$this->view->pages2 = $grid2->deploy();

$this->render('index');
}


public function detailAction ()
{

$grid = $this->grid();
$select = $this->_db->select()->from('Country',array('Code','Name', 'Continent', 'Population', 'LocalName', 'GovernmentForm'));
$grid->query($select);

$grid->setDetailColumns();



$this->view->pages = $grid->deploy();

$this->render('index');
}


public function columnsAction ()
{

$grid = $this->grid();
$select = $this->_db->select()->from('Country', array('Name', 'Continent', 'Population', 'LocalName', 'GovernmentForm'));
#$grid->setSource(new Bvb_Grid_Source_Zend_Select($select));
$grid->query($select);


$rows = new Bvb_Grid_Extra_Rows();
$rows->addRow('beforeHeader', array('', array('colspan' => 1, 'class' => 'myclass', 'content' => 'my content'), array('colspan' => 2, 'class' => 'myotherclass', 'content' => 'some '), array('colspan' => 1, 'class' => 'myclass', 'content' => 'flowers:) ')));
$rows->addRow('beforePagination', array(array('colspan' => 5, 'content' => "This is an extra row added before pagination")));
$grid->addExtraRows($rows);


$this->view->pages = $grid->deploy();

$this->render('index');
}


public function conditionalAction ()
{

$grid = $this->grid();
$select = $this->_db->select()->from('Country', array('Name', 'Continent', 'Population', 'LocalName', 'GovernmentForm','Region'));
$grid->query($select);

$grid->setClassCellCondition('Population', "'{{Population}}' > 200000", "red", 'green');
#$grid->setClassRowCondition("'{{Population}}' > 20000", "green", 'red');

#$grid->updateColumn('Continent',array('hRow'=>true));

$grid->setRecordsPerPage(15);
$grid->setRecordsPerPage(5);
$grid->setPaginationInterval(array(10 => 10, 20 => 20, 50 => 50, 100 => 100));

#$grid->setTableGridColumns(array('Name', 'Continent', 'Population', 'LocalName', 'GovernmentForm'));

$grid->setShowFiltersInExport(true);

$grid->setSqlExp(array('Population' => array('functions' => array('SUM'),'decorator'=>'Total: {{result}}')));

$this->view->pages = $grid->deploy();

$this->render('index');
}


public function massAction ()
{

if ( $this->getRequest()->isPost() ) {
echo "<pre>";
print_r($this->_getAllParams());
die();
}

$grid = $this->grid();
$select = $this->_db->select()->from('Country');
$grid->query($select);


$actions = new Bvb_Grid_Mass_Actions();
// $actions->setMassActions(array(array('url' => $grid->getUrl(),
// 'caption' => 'Remove (Nothing will happen)',
// 'confirm' => 'Are you sure?'),
// array('url' => $grid->getUrl() . '/nothing/happens',
// 'caption' => 'Some other action',
// 'confirm' => 'Another confirmation message?')));

$actions->addMassAction($grid->getUrl().'/option/delete', 'Delete', 'Are you sure?');
$actions->addMassAction($grid->getUrl(), 'Print');

$grid->setMassActions($actions);

$grid->setRecordsPerPage(15);
$grid->setPaginationInterval(array(10 => 10, 20 => 20, 50 => 50, 100 => 100));
$grid->setTableGridColumns(array('Name', 'Continent', 'Population', 'LocalName', 'GovernmentForm'));
$grid->setSqlExp(array('Population' => array('functions' => array('SUM'))));

$this->view->pages = $grid->deploy();

$this->render('index');
}

public function arrayAction ()
{
$grid = $this->grid();
$array = array(array('Alex', '12', 'M'), array('David', '1', 'M'), array('David', '2', 'M'), array('David', '3', 'M'), array('Richard', '3', 'M'), array('Lucas', '3', 'M'));

$source = new Bvb_Grid_Source_Array($array, array('name', 'age', 'sex'));
$source->setPrimaryKey(array('age'));

$grid->setDetailColumns(array('age','name'));

$grid->setSource($source);

#$grid->setMassActions(array(array('url' => $grid->getUrl(), 'caption' => 'Remove (Nothing will happen)', 'confirm' => 'Are you sure?'), array('url' => $grid->getUrl() . '/nothing/happens', 'caption' => 'Some other action', 'confirm' => 'Another confirmation message?')));

$this->view->pages = $grid->deploy();

$this->render('index');
}


public function ajaxAction ()
{
$grid = $this->grid();
$select = $this->_db->select()->from('Country');
$grid->query($select);
$grid->setAjax('ajax_grid');
$grid->setTableGridColumns(array('Name', 'Continent', 'Population', 'LocalName', 'GovernmentForm'));
$this->view->pages = $grid->deploy();
$this->render('index');
}


public function joinsAction ()
{

$grid = $this->grid();
$select = $this->_db->select()->from(array('c' => 'Country'), array('country' => 'Name', 'Code', 'Continent', 'Population', 'GovernmentForm', 'HeadOfState'))->join(array('ct' => 'City'), 'c.Capital = ct.ID', array('city' => 'Name'));
$grid->query($select);

$form = new Bvb_Grid_Form();
$form->setAdd(1)->setEdit(1)->setDelete(1)->setAddButton(1);
$form->setFieldsBasedOnQuery(true);
$grid->setForm($form);


$this->view->pages = $grid->deploy();
$this->render('index');
}


public function unionAction ()
{

$grid = $this->grid();

$sql1 = $this->_db->select()->from('Country', array('Continent', 'Code'))->limit(12);
$sql2 = $this->_db->select()->from('City', array('Name', 'District'))->limit(12);

$select = $this->_db->select()->union(array($sql1, $sql2))->order('Name DESC');

$t = $select->query()->fetchAll();

echo "<pre>";
print_r($t);
die();


$grid->query($select);

$this->view->pages = $grid->deploy();
$this->render('index');
}

public function mcrudAction ()
{
$grid = $this->grid('a');
$grid->query(new Bugs());
$grid->setColumnsHidden(array('bug_id', 'time', 'verified_by','next'));
$form = new Bvb_Grid_Form();
$form->setAdd(true)->setEdit(true)->setDelete(true)->setAddButton(true)->setSaveAndAddButton(true);
$grid->setForm($form);
$this->view->pages = $grid->deploy();


$grid2 = $this->grid('b');
$grid2->setSource(new Bvb_Grid_Source_Zend_Select($this->_db->select()->from('City')));
$form = new Bvb_Grid_Form();
$form->setAdd(true)->setEdit(true)->setDelete(true)->setAddButton(true)->setSaveAndAddButton(true);
$grid2->setForm($form);
$this->view->pages2 = $grid2->deploy();

$this->render('index');
}

/**
* Using a model
*/
public function crudAction ()
{

$grid = $this->grid();
$b = new Bugs();
$grid->setSource(new Bvb_Grid_Source_Zend_Table($b));
$grid->setColumnsHidden(array('bug_id', 'time', 'verified_by','next'));

$form = new Bvb_Grid_Form();
$form->setFormTitle('Manage Records');
$form->setAdd(true)->setEdit(true)->setDelete(true)->setAddButton(true)->setSaveAndAddButton(true);

#$grid->setDetailColumns();

$grid->setForm($form);

$grid->setDeleteConfirmationPage(true);
$this->view->pages = $grid->deploy();

$this->render('index');
}


/**
* This demonstrates how easy it is for us to use our own templates (Check the grid function at the page top)
*
*/
public function templateAction ()
{
$grid = $this->grid();
$grid->setSource(new Bvb_Grid_Source_Zend_Select($this->_db->select()->from('City')));
$grid->setNoFilters(1)->setRecordsPerPage(14)->setTemplate('outside', 'table');
$this->view->pages = $grid->deploy();
$this->render('index');
}


/**
* This example allow you to create an horizontal row, for every distinct value from a field
*
*/
public function hrowAction ()
{

$grid = $this->grid();
$grid->setSource(new Bvb_Grid_Source_Zend_Select($this->_db->select()->from('Country', array('Name', 'Continent', 'Population', 'LifeExpectancy', 'GovernmentForm', 'HeadOfState'))->limit(1000)->order('Continent ASC')));
$grid->setNoFilters(1);
$grid->setNoOrder(1);

$grid->setRecordsPerPage(1200);

$grid->updateColumn('Name', array('title' => 'Country'));
$grid->updateColumn('Continent', array('title' => 'Continent', 'hRow' => 1));
$grid->updateColumn('Population', array('title' => 'Population', 'class' => 'width_80'));
$grid->updateColumn('LifeExpectancy', array('title' => 'Life E.', 'class' => 'width_50', 'decorator' => '<b>{{LifeExpectancy}}</b>'));
$grid->updateColumn('GovernmentForm', array('title' => 'Government Form'));
$grid->updateColumn('HeadOfState', array('title' => 'Head Of State'));

$grid->setSqlExp(array('Population' => array('functions' => array('SUM'))));


$extra = new Bvb_Grid_Extra_Column();
$extra->position('right')->name('Right')->decorator("<input class='input_p'type='text' value=\"{{Population}}\" size=\"3\" name='number[]'>");

$esquerda = new Bvb_Grid_Extra_Column();
$esquerda->position('left')->name('Left')->decorator("<input type='checkbox' name='number[]'>");

$grid->addExtraColumns($extra, $esquerda);


$this->view->pages = $grid->deploy();
$this->render('index');
}


public function ofcAction ()
{

$this->view->graphs = $allowedGraphs = array('line', 'bar', 'bar_glass', 'bar_3d', 'bar_filled', 'pie', 'mixed');

$type = $this->_getParam('type');


if ( ! in_array($type, $allowedGraphs) ) {
$type = 'bar_glass';
}

$this->getRequest()->setParam('_exportTo', 'ofc');

$grid = $this->grid();
$grid->setExport(array('ofc'));


if ( $type == 'pie' ) {
$grid->addValues('Population', array('set_colours' => array('#000000', '#999999', '#BBBBBB', '#FFFFFF')));
} elseif ( $type == 'mixed' ) {
$grid->addValues('GNP', array('set_colour' => '#FF0000', 'set_key' => 'Gross National Product', 'chartType' => 'Bar_Glass'));
$grid->addValues('SurfaceArea', array('set_colour' => '#00FF00', 'set_key' => 'Surface', 'chartType' => 'line'));
} else {
$grid->addValues('GNP', array('set_colour' => '#00FF00', 'set_key' => 'Gross National Product'));
$grid->addValues('SurfaceArea', array('set_colour' => '#0000FF', 'set_key' => 'Surface'));
}

$grid->setXLabels('Name');

$grid->setSource(new Bvb_Grid_Source_Zend_Select($this->_db->select()->from('Country', array('Population', 'Name', 'GNP', 'SurfaceArea'))->where('Continent=?', 'Europe')->where('Population>?', 5000000)->where(new Zend_Db_Expr('length(Name)<10'))->order(new Zend_Db_Expr('RAND()'))->limit(10)));

$grid->setChartType($type);

$this->view->pages = $grid->deploy();
$this->render('index');
}


/**
* If you don't like to work with array when adding columns, you can work by dereferencing objects
*
*/
public function columnAction ()
{

$grid = $this->grid();
$grid->setSource(new Bvb_Grid_Source_Zend_Select($this->_db->select()->from(array('c' => 'Country'), array('Country' => 'Name', 'Continent', 'Population', 'GovernmentForm', 'HeadOfState'))->join(array('ct' => 'City'), 'c.Capital = ct.ID', array('Capital' => 'Name'))));
$grid->setRecordsPerPage(15);

$cap = new Bvb_Grid_Column('Country');
$cap->title('Country (Capital)')->class('width_150')->decorator('{{Country}} <em>({{Capital}})</em>');

$name = new Bvb_Grid_Column('Name');
$name->title('Capital')->hidden(1);

$continent = new Bvb_Grid_Column('Continent');
$continent->title('Continent');

$population = new Bvb_Grid_Column('Population');
$population->title('Population')->class('width_80');

$governmentForm = new Bvb_Grid_Column('GovernmentForm');
$governmentForm->title('Government Form');

$headState = new Bvb_Grid_Column('HeadOfState');
$headState->title('Head Of State');

$grid->updateColumns($cap, $name, $continent, $population, $governmentForm, $headState);

$this->view->pages = $grid->deploy();
$this->render('index');
}

}

Change log

r1813 by bento.vilas.boas on Jul 15, 2011   Diff
Deploy interface updated width __construct
Go to: 
Project members, sign in to write a code review

Older revisions

r1808 by bento.vilas.boas on Jul 14, 2011   Diff
New option for extra columns 'order'.

order for column. use in conjunction
with position

...
r1805 by bento.vilas.boas on Jul 14, 2011   Diff
Extra Columns methods update
r1798 by bento.vilas.boas on Jul 2, 2011   Diff
controller update
All revisions of this file

File info

Size: 27506 bytes, 814 lines

File properties

svn:executable
*
Powered by Google Project Hosting