Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A very-nearly-finished stats tracker
- Loading branch information
1 parent
a5144fd
commit 2baf933
Showing
24 changed files
with
491 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
class Test_bootstrap | ||
class Test_bootstrap extends CI_Controller | ||
{ | ||
public function index() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
class TrackerPresenter extends Presenter | ||
{ | ||
public function __construct($object, $name = FALSE) | ||
{ | ||
parent::__construct($object, $name); | ||
|
||
$this->ci =& get_instance(); | ||
} | ||
|
||
public function values() | ||
{ | ||
if (!isset($this->values)) | ||
{ | ||
$this->ci->load->model('value_model', 'value'); | ||
$this->values = $this->ci->value->getManyForTracker($this->tracker->id); | ||
} | ||
|
||
return $this->values; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,9 @@ | ||
<?php | ||
|
||
class Tracker_TablePresenter extends Presenter | ||
class Tracker_TablePresenter extends TrackerPresenter | ||
{ | ||
public function values() | ||
{ | ||
$this->ci =& get_instance(); | ||
|
||
if (!isset($this->values)) | ||
{ | ||
$this->ci->load->model('value_model', 'value'); | ||
$this->values = $this->ci->value->getManyForTracker($this->tracker->id); | ||
} | ||
|
||
return $this->values; | ||
} | ||
|
||
public function display() | ||
{ | ||
$html = "<table>\n\t"; | ||
$html .= "<thead>\n\t\t"; | ||
$html .= "<tr><th>Value</th><th>When</th></tr>\n\t"; | ||
$html .= "</thead>\n\t"; | ||
$html .= "<tbody>\n\t\t"; | ||
|
||
$values = $this->values(); | ||
|
||
foreach ($values as $value) | ||
{ | ||
$html .= "<tr><td>" . $value[1] . "</td><td>" . $value[0] . "</td></tr>\n\t\t"; | ||
} | ||
|
||
$html .= "</tbody>\n"; | ||
$html .= "</table>"; | ||
|
||
return $html; | ||
return $this->ci->load->view('presenters/table', array( 'data' => $this->values() ), TRUE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,44 @@ | ||
<?php | ||
|
||
class Tracker_VisitsPresenter extends Presenter { } | ||
class Tracker_VisitsPresenter extends TrackerPresenter | ||
{ | ||
public $dataTableHeaders = array( 'Day', 'Visits' ); | ||
|
||
public function display() | ||
{ | ||
return $this->ci->load->view('presenters/visits', array( 'data' => $this->values() ), TRUE); | ||
} | ||
|
||
public function dataTableHeader() | ||
{ | ||
return '[ \'' . implode("', '", $this->dataTableHeaders) . '\' ],'; | ||
} | ||
|
||
public function dataTableData() | ||
{ | ||
$dataStr = ''; | ||
$data = $this->values(); | ||
$dayCounts = array(); | ||
|
||
foreach ($data as $value) | ||
{ | ||
$day = date('Y-m-d', strtotime($value[0])); | ||
|
||
if (isset($dayCounts[$day])) | ||
{ | ||
$dayCounts[$day]++; | ||
} | ||
else | ||
{ | ||
$dayCounts[$day] = 1; | ||
} | ||
} | ||
|
||
foreach ($dayCounts as $day => $count) | ||
{ | ||
$dataStr .= "[ '" . $day . "', " . $count . " ],"; | ||
} | ||
|
||
return substr($dataStr, 0, strlen($dataStr) - 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
class TrackerPresenterTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public function testConstructorFetchesCI() | ||
{ | ||
$pre = new TrackerPresenter(new stdClass); | ||
|
||
$this->assertEquals(get_instance(), $pre->ci); | ||
} | ||
|
||
public function testGrabsValues() | ||
{ | ||
$data = array( 1, 2, 3 ); | ||
$obj = (object)array( 'id' => 'website_visits' ); | ||
$pre = new TrackerPresenter($obj, 'tracker'); | ||
|
||
$pre->ci =& get_instance(); | ||
$pre->ci->value = Mockery::mock('Value_model'); | ||
$pre->ci->value->shouldReceive('getManyForTracker') | ||
->once() | ||
->with('website_visits') | ||
->andReturn($data); | ||
|
||
$this->assertEquals($data, $pre->values()); | ||
$this->assertEquals($data, $pre->values()); | ||
} | ||
} |
Oops, something went wrong.