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

/atk4-addons/mvc/SelectGrid.php

https://github.com/mahimarathore/mahi
PHP | 72 lines | 58 code | 2 blank | 12 comment | 2 complexity | 5e20504146634cc3c2b08cf5bd863afb MD5 | raw file
Possible License(s): AGPL-3.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * SelectGrid
  4. * AJAX based class
  5. * Created on 09.10.2006 by *Camper* (camper@adevel.com)
  6. */
  7. class SelectGrid extends Grid{
  8. protected $selected=array();
  9. function init(){
  10. parent::init();
  11. //restoring selected
  12. //$this->addHook('post-submit', array($this, 'getSelected'), 1);
  13. $this->getSelected();
  14. if($_GET['save_selected']){
  15. $r=explode(',',$_GET['selected']);
  16. $sel=array();
  17. foreach($r as $i=>$v){
  18. list($id,$selected)=explode(':',$v);
  19. $sel[$id]=$selected;
  20. }
  21. $this->processSelection($sel);
  22. }
  23. }
  24. function getSelected($id=null){
  25. if(!$this->selected)$this->selected = $this->recall('selected', array());
  26. return (is_null($id)?$this->selected:$this->selected[$id]);
  27. }
  28. /**
  29. * changes selected status of the row
  30. */
  31. function select($id){
  32. $this->selected[$id]=($this->selected[$id]=='Y'?'N':'Y');
  33. $this->memorize('selected', $this->selected);
  34. }
  35. function setSelected($selected){
  36. $this->selected=array_merge($this->selected,$selected);
  37. $this->memorize('selected', $this->selected);
  38. }
  39. function format_checkbox($field){
  40. $this->current_row[$field] = '<input type="checkbox" id="cb_'.
  41. $this->current_row['id'].'" name="cb_'.$this->current_row['id'].
  42. '" value="'.$this->current_row['id'].'"'.
  43. ($this->selected[$this->current_row['id']]=='Y'?" checked ":" ").'" onclick="'.
  44. $this->onClick($field).'" />';
  45. $this->setTDParam($field,'width','10');
  46. $this->setTDParam($field,'align','center');
  47. }
  48. function onClick($field){
  49. // return $this->add('Ajax')->loadRegionURL('cb_'.$this->current_row['id'],
  50. //return "alert('".$this->api->url(null,array('cb'=>$this->current_row['id']))."')";
  51. return str_replace('"',"'",$this->ajax()->executeUrl(
  52. $this->api->url(null,array('cb'=>$this->current_row['id']))
  53. )->getString());
  54. }
  55. function format_assigned($field){
  56. $this->current_row[$field] = ($this->assignmentExists($this->current_row['id']))?"Yes":"No";
  57. if($this->current_row[$field] == 'Yes')$this->current_row[$field] = "<b>".$this->current_row[$field]."</b>";
  58. }
  59. function assignmentExists($id){
  60. return false;
  61. }
  62. /**
  63. * Override this method to perform any updates to DB, etc
  64. *
  65. * @param $selected array of IDs selected
  66. */
  67. function processSelection($selected){
  68. $this->memorize('selected',$selected);
  69. }
  70. }