PageRenderTime 48ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/atk4-addons/mvc/MVCGrid.php

https://github.com/mahimarathore/mahi
PHP | 76 lines | 66 code | 2 blank | 8 comment | 8 complexity | eaa249179588b75198b797cc1accef41 MD5 | raw file
Possible License(s): AGPL-3.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. *
  4. * @author Camper (camper@agiletech.ie) on 29.01.2010
  5. */
  6. class MVCGrid extends Grid{
  7. // THIS IS CORRECT BEHAVOR. ESCAPE TEXT, BUT LEAVE HTML ALONE
  8. function format_text($field){
  9. $this->current_row[$field] = htmlentities_utf8($this->current_row[$field]);
  10. }
  11. function format_real($field){
  12. $this->current_row[$field]=(float)$this->current_row[$field];
  13. $this->setTDParam($field,'align','right');
  14. }
  15. function setController($name){
  16. parent::setController($name);
  17. $this->dq=$this->controller->view_dsql($this->name);
  18. $this->api->addHook('pre-render',array($this->controller,'execQuery'));
  19. $this->processSorting();
  20. $this->controller->initLister();
  21. //$this->dq->debug();
  22. return $this;
  23. }
  24. function processSorting(){
  25. if($this->sortby){
  26. $desc=false;
  27. $order=$this->sortby;
  28. if(substr($this->sortby,0,1)=='-'){
  29. $desc=true;
  30. $order=substr($order,1);
  31. }
  32. if(!$this->sortby_db){
  33. $this->getController()->setOrder($this->name,$order,$desc);
  34. }
  35. }
  36. //we always need to calc rows
  37. $this->dq->calc_found_rows();
  38. return $this;
  39. }
  40. function addColumnMVC($field_name,$type=null){
  41. $field=$this->getController()->getModel()->getField($field_name);
  42. if(is_null($field))throw new Exception_InitError("Field '$field_name' is not defined in the ".
  43. get_class($this->getController()->getModel())." model");
  44. if(is_null($type))$type=$this->getController()->formatType($field->datatype(),'grid',$field_name);
  45. if($field_name=='locked')return
  46. parent::addColumn('locked','locked','');
  47. if($field_name=='id')$type='text';
  48. $r=parent::addColumn($type,$field_name,$field->caption());
  49. //echo get_class($field) . '<br />';
  50. if($field->sortable())
  51. $r->makeSortable();
  52. return $r;
  53. }
  54. function addColumnPlain($type,$name=null,$descr=null,$color=null){
  55. return $this->addColumn($type,$name,$descr,$color);
  56. }
  57. function addSelectable($field){
  58. $this->js_widget=null;
  59. $this->js(true)
  60. ->_load('ui.atk4_checkboxes')
  61. ->atk4_checkboxes(array('dst_field'=>$field));
  62. $this->addColumnPlain('checkbox','selected');
  63. $this->addOrder()
  64. ->useArray($this->columns)
  65. ->move('selected','first')
  66. ->now();
  67. }
  68. function hasColumn($name){
  69. return isset($this->columns[$name])?$this->columns[$name]:false;
  70. }
  71. function _performDelete($id){
  72. $this->getController()->loadData($id)->delete();
  73. }
  74. }