Skip to content

Commit

Permalink
Merge pull request #15 from vkuzmov/stats-widget-query
Browse files Browse the repository at this point in the history
Query added to stats widget
  • Loading branch information
yanev committed May 30, 2014
2 parents 5f29bce + f62150e commit 1af0430
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions classes/Kohana/Stats/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ abstract class Kohana_Stats_Widget {
protected $_id;
protected $_range;
protected $_options = array();
protected $_query = array();

public function __construct($id, Tart_Date_Range $range = NULL)
{
Expand All @@ -32,12 +33,12 @@ public function title($title = NULL)
return $this->_title;
}


public function options($key = NULL, $value = NULL)
{
if ($key === NULL)
return $this->_options;

if (is_array($key))
{
$this->_options = $key;
Expand All @@ -46,10 +47,10 @@ public function options($key = NULL, $value = NULL)
{
if ($value === NULL)
return Arr::get($this->_options, $key);

$this->_options[$key] = $value;
}

return $this;
}

Expand Down Expand Up @@ -81,7 +82,7 @@ public static function percent_diff($a, $b)
$b = $b instanceof Jam_Price ? $b->amount() : $b;

return ($b > 0) ? (($a - $b) / $b) * 100 : 0;
}
}

public static function to_percent($a, $b)
{
Expand Down Expand Up @@ -113,6 +114,16 @@ public function cache($mode = NULL)
return $this->_cache;
}

public function query($query = NULL)
{
if ($query !== NULL)
{
$this->_query = $query;
return $this;
}
return $this->_query;
}

public function cache_key()
{
return substr(sha1(($this->range() ? $this->range()->render() : '').$this->id()), 0, 8);
Expand Down

0 comments on commit 1af0430

Please sign in to comment.