Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Chumper committed Sep 5, 2013
0 parents commit 3ac3738
Show file tree
Hide file tree
Showing 14 changed files with 388 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor
composer.phar
composer.lock
.DS_Store
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: php

php:
- 5.3
- 5.4
- 5.5

before_script:
- curl -s http://getcomposer.org/installer | php
- php composer.phar install --dev

script: phpunit
26 changes: 26 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "chumper/datatable",
"description": "",
"authors": [
{
"name": "Nils Plaschke",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.3.0",
"illuminate/support": "4.0.x",
"illuminate/view": "4.0.x",
"illuminate/foundation": "4.0.*"
},
"require-dev": {
"phpunit/phpunit": "3.7.*",
"mockery/mockery": "dev-master"
},
"autoload": {
"psr-0": {
"Chumper\\Datatable": "src/"
}
},
"minimum-stability": "dev"
}
18 changes: 18 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
6 changes: 6 additions & 0 deletions src/Chumper/Datatable/Api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php namespace Chumper\Datatable;


class Api {

}
17 changes: 17 additions & 0 deletions src/Chumper/Datatable/Datatable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php namespace Chumper\Datatable;

use Illuminate\Database\Query\Builder;

class Datatable {

public function api(Builder $builder)
{
return new Api($builder);
}

public function table()
{
return new Table;
}

}
43 changes: 43 additions & 0 deletions src/Chumper/Datatable/DatatableServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php namespace Chumper\Datatable;

use Illuminate\Support\ServiceProvider;
use View;

class DatatableServiceProvider extends ServiceProvider {

/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;

public function boot()
{
$this->package('chumper/datatable');
}

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app['datatable'] = $this->app->share(function($app)
{
return new Datatable;
});
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('datatable');
}

}
14 changes: 14 additions & 0 deletions src/Chumper/Datatable/Facades/Datatable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php namespace Chumper\Datatable\Facades;

use Illuminate\Support\Facades\Facade;

class Datatable extends Facade {

/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor() { return 'datatable'; }

}
88 changes: 88 additions & 0 deletions src/Chumper/Datatable/Table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php namespace Chumper\Datatable;


use Exception;
use View;


class Table {

private $columns = array();
private $options = array();
private $data = array();

public function addColumn()
{
foreach (func_get_args() as $title)
{
if(is_array($title))
{
foreach ($title as $arrayTitle)
{
$this->columns[] = $arrayTitle;
}
}
else
$this->columns[] = $title;
}
return $this;
}

public function countColumns()
{
return count($this->columns);
}

public function setOptions()
{
if(func_num_args() == 2)
{
$this->options[func_get_arg(0)] = func_get_arg(1);
}
else if(func_num_args() == 1 && is_array(func_get_arg(0)))
{
foreach (func_get_arg(0) as $key => $option)
{
$this->options[$key] = $option;
}
}
else
throw new Exception('Invalid number of options provided for the method "setOptions"');
return $this;
}

public function setData(array $data)
{
$this->data = $data;
return $this;
}

public function setUrl($url)
{
$this->options['sAjaxSource'] = $url;
$this->options['bServerSide'] = true;
return $this;
}

public function getOptions()
{
return $this->options;
}

public function getData()
{
return $this->data;
}

public function render($view = null)
{
if(is_null($view))
$view = 'datatable::template';

return View::make($view,array(
'options' => $this->getOptions(),
'data' => $this->getData(),
'columns' => $this->columns,
));
}
}
28 changes: 28 additions & 0 deletions src/views/template.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<table id="users" class="table table-bordered responsive">
<colgroup>
<col class="con1" />
</colgroup>
<thead>
<tr>
<th class="head1">Last</th>
<th class="head1">Last</th>
<th class="head1">Last</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script type="text/javascript">
jQuery(document).ready(function(){
// dynamic table
jQuery('#users').dataTable({
"sPaginationType": "full_numbers",
"bProcessing": false,
"bServerSide": true,
"sAjaxSource": "{{ URL::to('auth/users/table') }}"
//"fnDrawCallback": function(oSettings) {
// jQuery.uniform.update();
//}
});
});
</script>
Empty file added tests/.gitkeep
Empty file.
11 changes: 11 additions & 0 deletions tests/ApiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
use Chumper\Datatable\Api;

class ApiTest extends PHPUnit_Framework_TestCase {

public function testDummy()
{

}

}
29 changes: 29 additions & 0 deletions tests/DatatableTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Chumper\Datatable\Datatable;

class DatatableTest extends PHPUnit_Framework_TestCase {

/**
* @var Datatable
*/
private $dt;

protected function setUp()
{
$this->dt = new Datatable;
$this->mock = Mockery::mock('Illuminate\Database\Query\Builder');
}

public function testReturnInstances()
{
$api = $this->dt->api($this->mock);

$this->assertInstanceOf('Chumper\Datatable\Api', $api);

$table = $this->dt->table();

$this->assertInstanceOf('Chumper\Datatable\Table', $table);
}

}
Loading

0 comments on commit 3ac3738

Please sign in to comment.