Helix Installation   Getting Started   Reference Documentation   Global Functions   Quick Start
ModulesClassesFunctions
 

Class Reference

class datagrid extends obj

Hide Inherited MembersUser Interface
Description
No description.
 
Constants
No constants.
 
Properties
protected_column_count[ datagrid ]
protected_columns[ datagrid ]
protected_current_page[ datagrid ]
protected_data[ datagrid ]
protected_default_limit[ datagrid ]
protected_dirty[ obj ]
protected_limit[ datagrid ]
protected_limit_param[ datagrid ]
protected_next_offset[ datagrid ]
protected_offset[ datagrid ]
protected_options[ datagrid ]
protected_page_count[ datagrid ]
protected_prev_offset[ datagrid ]
publicproperty_objects_array[ obj ]
protected_record_array[ datagrid ]
protected_record_count[ datagrid ]
 
Methods
public__construct ( data )[ datagrid ]
Parameters
optionaldata
Code
019  public function __construct($__data=null)
020  {
021      $this->_data = is_object($__data) ? $__data : new set($__data);
022      $this->_columns = array();
023      $this->default_limit = defined("PAGING_ROWS_PER_PAGE") ? PAGING_ROWS_PER_PAGE : 20;
024      $this->options["hide-dirty-properties"] = true;
025      $this->options["replace-underscores"] = true;
026      $this->options["start-with-underscore"] = false;
027      $this->options["ignore-numeric-columns"] = true;
028      $this->options["format-column-headers"] = true;
029      $this->options["disable-paging"] = false;
030      $this->setup_columns();
031  }
publicformat_column ( column )[ datagrid ]
Parameters
requiredcolumn
Code
069  public function format_column($__column)
070  {
071      $column = $__column;
072      if (is_true($this->options["format-column-headers"]))
073      {
074          $column = is_true($this->options["replace-underscores"]) ? str_ireplace("_"," ",$column) : $column;
075          $column = is_true($this->options["start-with-underscore"]) ? preg_replace('/^_(.+)$/i','$1',$column) : $column;
076          $column = ucwords($column);
077      }
078      return $column;
079  }
public__get ( p )[ obj ]
Parameters
requiredp
Code
007  public function __get($p)
008  {
009      $methods = get_class_methods($this);
010      $properties = get_object_vars($this);
011      if (in_array("get_$p",$methods))
012      {
013          return $this->{"get_$p"}();
014      }
015      else if (array_key_exists("_$p",$properties))
016      {
017          return $this->{"_$p"};
018      }
019      else if (in_array("get_" . substr($p,strpos($p,"_")+1), $methods))
020      {
021          return $this->{"get_" . substr($p,strpos($p,"_")+1)}(substr($p,0,strpos($p,"_")));
022      }
023      else
024      {
025          trigger_error("This object [" . get_class($this) . ":$this->id] has no private property '_$p' for the requested public property '$p'",E_USER_WARNING);
026          return null;
027      }
028  }
publicget_array ( )[ obj ]
Parameters
No parameters for this method
Code
096  public function get_array()
097  {
098      return get_object_vars($this);
099  }
publicget_classname ( )[ obj ]
Parameters
No parameters for this method
Code
086  public function get_classname()
087  {
088      return get_class($this);
089  }
publicget_column_list ( )[ datagrid ]
Parameters
No parameters for this method
Code
047  public function get_column_list()
048  {
049      $columns = array();
050      if (is_array($this->columns))
051      {
052          foreach ($this->columns as $column)
053          {
054              $column = trim($column);
055              if (is_true($this->options["hide-dirty-properties"]) && preg_match('/_dirty$/i',$column))
056              {
057                  continue;
058              }
059              else if (is_true($this->options["ignore-numeric-columns"]) && is_numeric($column))
060              {
061                  continue;
062              }
063              $columns[$column] = $this->format_column($column);
064          }
065      }
066      return $columns;
067  }
publicget_dirty ( )[ obj ]
Parameters
No parameters for this method
Code
063  public function get_dirty()
064  {
065      if ($this->id === 0)
066      {
067          $this->_dirty = true;
068      }
069      else
070      {
071          foreach (get_object_vars($this) as $k=>$v)
072          {
073              if ($this->_dirty)
074              {
075                  break;
076              }
077              if (preg_match('/_dirty$/',$k))
078              {
079                  $this->_dirty = $this->_dirty || $v;
080              }
081          }
082      }
083      return $this->_dirty;
084  }
publicget_json ( )[ obj ]
Parameters
No parameters for this method
Code
101  public function get_json()
102  {
103      $class = new ReflectionClass($this->classname);
104      $methods = $class->getMethods();
105      usort($methods,"sort_reflection_objects");
106      $accessors = array();
107      foreach ($methods as $index=>$method)
108      {
109          $declarer = $method->getDeclaringClass()->name;
110          if (preg_match('/^(get|set|)_(.+)$/',$method->name,$matches))
111          {
112              $accessor = $matches[2];
113              $getset = $matches[1];
114              eval("\$accessors[\$accessor] = \$this->".$accessor.";");
115          }
116      }
117      //return json_encode($this->get_array());
118      return json_encode($accessors);
119  }
publicget_properties ( )[ obj ]
Parameters
No parameters for this method
Code
121  public function get_properties()
122  {
123      return array_keys($this->array);
124  }
protectedget_string ( )[ obj ]
Parameters
No parameters for this method
Code
091  protected function get_string()
092  {
093      return method_exists($this,"__toString") ? $this->__toString() : null;
094  }
publicrender ( )[ datagrid ]
Parameters
No parameters for this method
Code
081  public function render()
082  {
083      $this->columns = is_null($this->columns) ? (count($this->records)==0 ? null : array_keys((is_array($this->records[0]) ? $this->records[0] : $this->records[0]->array))) : (is_string($this->columns) ? explode(",",$this->columns) : (is_array($this->columns) ? $this->columns : null));
084      table::open(null,null,"datagrid");
085          $this->render_header();
086          $this->render_data();
087      table::close();
088  }
publicrender_data ( )[ datagrid ]
Parameters
No parameters for this method
Code
102  public function render_data()
103  {
104      $offset = intval($this->offset)>0 ? $this->offset : 0;
105      $limit = intval($this->limit)>0 ? $this->limit : $this->default_limit;
106      $records = array_slice($this->records,$offset,$limit,true);
107      foreach ($records as $record)
108      {
109          $data = is_array($record) ? $record : $record->array;
110          tr::open(null,null,"datagrid-row");
111          foreach ($this->column_list as $column=>$header)
112          {
113              $value = array_key_exists($column,$data) ? $data[$column] : (array_key_exists("_{$column}",$data) ? $data["_{$column}"] : null);
114              td::open(null,null,null,null,"datagrid-cell");
115                  echo $value;
116              td::close();
117          }
118          tr::close();
119      }
120  }
publicrender_header ( )[ datagrid ]
Parameters
No parameters for this method
Code
090  public function render_header()
091  {
092      tr::open(null,null,"datagrid-row datagrid-header-row");
093      foreach ($this->column_list as $column=>$header)
094      {
095          th::open(null,null,null,null,"datagrid-cell datagrid-title-cell");
096              echo $header;
097          th::close();
098      }
099      tr::close();
100  }
publicrender_paging_bar ( )[ datagrid ]
Parameters
No parameters for this method
Code
122  public function render_paging_bar()
123  {
124      $this->page_count = ceil(count($this->records)/$this->limit);
125      $current_page = ceil($offset/$limit) + 1;
126      $next_offset = $offset+$limit>=$episode_count ? $offset : $offset+$limit;
127      $prev_offset = $offset-$limit<0 ? 0 : $offset-$limit;
128      tr::open(null,null,"datagrid-paging-bar-row");
129          td::open($num_columns,null,null,null,"datagrid-paging-bar-cell");
130              div::open(null,null,"datagrid-paging-bar");
131                  a::open(WEBROOT . "episodes/{$podcast->urlname}/{$prev_offset}{$limit_param}",null,"border:none;","prev");
132                      echo "<<";
133                  a::close();
134                  for ($i=1; $i<=$num_pages; $i++)
135                  {
136                      $classname = $i==$current_page ? "current-page" : "";
137                      $page_offset = ($i-1)*$limit;
138                      a::open(WEBROOT . "episodes/{$podcast->urlname}/{$page_offset}{$limit_param}",null,null,$classname);
139                          echo $i;
140                      a::close();
141                  }
142                  a::open("",null,"width:{$padding}px;","padding",null,null,"return false;");
143                      nbsp();
144                  a::close();
145                  a::open(WEBROOT . "episodes/{$podcast->urlname}/{$next_offset}{$limit_param}",null,null,"next");
146                      echo ">>";
147                  a::close();
148              div::close();
149          td::close();
150      tr::close();
151  }
public__set ( p , v )[ obj ]
Parameters
requiredp
requiredv
Code
030  public function __set($p,$v)
031  {
032      $methods = get_class_methods($this);
033      $properties = get_object_vars($this);
034      if (in_array("set_$p",$methods))
035      {
036          $this->{"set_$p"}($v);
037      }
038      else if (array_key_exists("_$p",$properties))
039      {
040          if (!preg_match('/_dirty$/',$p) && property_exists($this,"_{$p}_dirty"))
041          {
042              if (is_object($this->{"_$p"}))
043              {
044                  $this->{"_$p"}->dirty = true;
045              }
046              else
047              {
048                  $this->{"_{$p}_dirty"} = $this->{$p}==$v ? false : true;
049              }
050          }
051          $this->{"_$p"} = $v;
052      }
053      else if (in_array("set_" . substr($p,strpos($p,"_")+1), $methods))
054      {
055          $this->{"set_" . substr($p,strpos($p,"_")+1)}($v,substr($p,0,strpos($p,"_")));
056      }
057      else
058      {
059          trigger_error("This object [" . get_class($this) . ":$this->id] has no private property '_$p' for the requested public property '$p'",E_USER_WARNING);
060      }
061  }
publicset_data ( v )[ datagrid ]
Parameters
requiredv
Code
033  public function set_data($__v)
034  {
035      $this->_data = is_array($__v) ? new set($__v) : (is_object($__v) ? $__v : new set());
036      $this->setup_columns();
037  }
publicsetup_columns ( )[ datagrid ]
Parameters
No parameters for this method
Code
039  public function setup_columns()
040  {
041      foreach ($this->data->keys as $index=>$key)
042      {
043          $this->_columns[$key];
044      }
045  }
public__toString ( )[ datagrid ]
Parameters
No parameters for this method
Code
153  public function __toString()
154  {
155      return $this->render();
156  }
 
Accessors
publicarray[ obj ]
Code
096  public function get_array()
097  {
098      return get_object_vars($this);
099  }
publicclassname[ obj ]
Code
086  public function get_classname()
087  {
088      return get_class($this);
089  }
publiccolumn_list[ datagrid ]
Code
047  public function get_column_list()
048  {
049      $columns = array();
050      if (is_array($this->columns))
051      {
052          foreach ($this->columns as $column)
053          {
054              $column = trim($column);
055              if (is_true($this->options["hide-dirty-properties"]) && preg_match('/_dirty$/i',$column))
056              {
057                  continue;
058              }
059              else if (is_true($this->options["ignore-numeric-columns"]) && is_numeric($column))
060              {
061                  continue;
062              }
063              $columns[$column] = $this->format_column($column);
064          }
065      }
066      return $columns;
067  }
publicdata[ datagrid ]
Code
033  public function set_data($__v)
034  {
035      $this->_data = is_array($__v) ? new set($__v) : (is_object($__v) ? $__v : new set());
036      $this->setup_columns();
037  }
publicdirty[ obj ]
Code
063  public function get_dirty()
064  {
065      if ($this->id === 0)
066      {
067          $this->_dirty = true;
068      }
069      else
070      {
071          foreach (get_object_vars($this) as $k=>$v)
072          {
073              if ($this->_dirty)
074              {
075                  break;
076              }
077              if (preg_match('/_dirty$/',$k))
078              {
079                  $this->_dirty = $this->_dirty || $v;
080              }
081          }
082      }
083      return $this->_dirty;
084  }
publicjson[ obj ]
Code
101  public function get_json()
102  {
103      $class = new ReflectionClass($this->classname);
104      $methods = $class->getMethods();
105      usort($methods,"sort_reflection_objects");
106      $accessors = array();
107      foreach ($methods as $index=>$method)
108      {
109          $declarer = $method->getDeclaringClass()->name;
110          if (preg_match('/^(get|set|)_(.+)$/',$method->name,$matches))
111          {
112              $accessor = $matches[2];
113              $getset = $matches[1];
114              eval("\$accessors[\$accessor] = \$this->".$accessor.";");
115          }
116      }
117      //return json_encode($this->get_array());
118      return json_encode($accessors);
119  }
publicproperties[ obj ]
Code
121  public function get_properties()
122  {
123      return array_keys($this->array);
124  }
publicstring[ obj ]
Code
091  protected function get_string()
092  {
093      return method_exists($this,"__toString") ? $this->__toString() : null;
094  }
Get Helix PHP Framework at SourceForge.net. Fast, secure and Free Open Source software downloads