Skip to content

Commit

Permalink
Mejorado diseño RMR.
Browse files Browse the repository at this point in the history
  • Loading branch information
augusthur committed Apr 2, 2015
1 parent bb18cff commit 30023e7
Show file tree
Hide file tree
Showing 21 changed files with 236 additions and 146 deletions.
13 changes: 7 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions config/schema-create.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@
$table->timestamps();
});

Capsule::schema()->create('poderes', function($table) {
$table->engine = 'InnoDB';

$table->increments('id');
$table->integer('patrulla_id')->unsigned();
$table->string('accion');

$table->foreign('patrulla_id')->references('id')->on('patrullas')->onDelete('cascade');

$table->timestamps();
});

Capsule::schema()->create('categorias', function($table) {
$table->engine = 'InnoDB';

Expand Down
2 changes: 2 additions & 0 deletions config/schema-drop.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ function superDelete($path) {
echo '11 ';
Capsule::schema()->dropIfExists('moderadores');
echo '12 ';
Capsule::schema()->dropIfExists('poderes');
echo '12.1 ';
Capsule::schema()->dropIfExists('patrullas');
echo '13 ';
Capsule::schema()->dropIfExists('contactos');
Expand Down
5 changes: 5 additions & 0 deletions config/schema-fill.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
$patrulla->descripcion = 'Los moderadores.';
$patrulla->save();

$poder = new Poder;
$poder->accion = 'admConteni';
$poder->patrulla()->associate($patrulla);
$poder->save();

$moderador = new Moderador;
$moderador->usuario()->associate($usuario);
$moderador->patrulla()->associate($patrulla);
Expand Down
1 change: 0 additions & 1 deletion controllers/AdminCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class AdminCtrl extends Controller {

public function verOrganismos() {
$req = $this->request;
$vdt = Paginator::validate($req->get());
$url = $req->getUrl().$req->getPath();
$paginator = new Paginator(Organismo::query(), $url, $vdt->getData());
$organismos = $paginator->rows;
Expand Down
16 changes: 3 additions & 13 deletions controllers/ContenidoCtrl.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
<?php use Augusthur\Validation as Validate;

class ContenidoCtrl extends Controller {
class ContenidoCtrl extends RMRController {

use RestTrait;

private $ordenables = array('id', 'puntos', 'created_at');
private $filtrables = array('id', 'puntos');

public function getRepresentation($conneg) {
if (substr($conneg, 0, 16) == 'application/json') {
return new JsonRepr();
} else {
throw new BearableException('Petición de formato de contenido no disponible.', 406);
}
}
protected $mediaTypes = array('json');
protected $properties = array('id', 'puntos', 'created_at');

public function queryModel() {
return Contenido::query();
Expand Down
4 changes: 4 additions & 0 deletions controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public function __get($name) {
return $this->app->$name;
}

public function __set($name, $value) {
return $this->app->$name = $value;
}

public function __call($name, $args) {
return call_user_func_array(array($this->app, $name), $args);
}
Expand Down
12 changes: 12 additions & 0 deletions controllers/OrganismoCtrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php use Augusthur\Validation as Validate;

class OrganismoCtrl extends RMRController {

protected $mediaTypes = array('json');
protected $properties = array('id', 'nombre', 'cupo', 'funcionarios_count');

public function queryModel() {
return Organismo::query();
}

}
16 changes: 3 additions & 13 deletions controllers/PartidoCtrl.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
<?php use Augusthur\Validation as Validate;

class PartidoCtrl extends Controller {
class PartidoCtrl extends RMRController {

use RestTrait;

private $ordenables = array('id', 'nombre', 'acronimo', 'fecha_fundacion', 'created_at');
private $filtrables = array('id', 'nombre', 'acronimo');

public function getRepresentation($conneg) {
if (substr($conneg, 0, 16) == 'application/json') {
return new JsonRepr();
} else {
return new ViewRepr();
}
}
protected $mediaTypes = array('json', 'view');
protected $properties = array('id', 'nombre', 'acronimo', 'fecha_fundacion', 'created_at');

public function queryModel() {
return Partido::query();
Expand Down
44 changes: 44 additions & 0 deletions controllers/RMRController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php use Augusthur\Validation as Validate;

abstract class RMRController extends Controller {

protected $mediaTypes = array();
protected $properties = array();

abstract public function queryModel();

public function listar() {
$req = $this->request;
$repr = $this->negotiateContent($req->headers->get('ACCEPT'));
$queryMaker = new QueryMaker($this->queryModel(), $req->get());
$queryMaker->addFilters($this->properties);
$queryMaker->addSorters($this->properties);
$url = $req->getUrl().$req->getPath();
$paginator = new Paginator($queryMaker->query, $url, $queryMaker->params);
$repr->shwCollection($this, $paginator);
}

public function ver($id) {
$req = $this->request;
$repr = $this->negotiateContent($req->headers->get('ACCEPT'));
$vdt = new Validate\QuickValidator(array($this, 'notFound'));
$vdt->test($id, new Validate\Rule\NumNatural());
$resource = $this->queryModel()->findOrFail($id);
$repr->shwResource($this, $resource);
}

public function negotiateContent($accept) {
if (substr($accept, 0, 16) == 'application/json') {
$this->response->headers->set('Content-Type', 'application/json; charset=UTF-8');
$this->api = true;
$repr = new JsonRepr();
} else {
$repr = new ViewRepr();
}
if (!in_array($repr->getName(), $this->mediaTypes)) {
throw new BearableException('Petición de formato de contenido no disponible.', 406);
}
return $repr;
}

}
28 changes: 0 additions & 28 deletions controllers/RestTrait.php

This file was deleted.

16 changes: 3 additions & 13 deletions controllers/UsuarioCtrl.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
<?php use Augusthur\Validation as Validate;

class UsuarioCtrl extends Controller {
class UsuarioCtrl extends RMRController {

use RestTrait;

private $ordenables = array('id', 'nombre', 'apellido', 'es_funcionario', 'es_jefe', 'puntos', 'created_at');
private $filtrables = array('id', 'nombre', 'apellido', 'es_funcionario', 'es_jefe', 'puntos');

public function getRepresentation($conneg) {
if (substr($conneg, 0, 16) == 'application/json') {
return new JsonRepr();
} else {
throw new BearableException('Petición de formato de contenido no disponible.', 406);
}
}
protected $mediaTypes = array('json');
protected $properties = array('id', 'nombre', 'apellido', 'es_funcionario', 'es_jefe', 'puntos', 'created_at');

public function queryModel() {
return Usuario::query();
Expand Down
2 changes: 1 addition & 1 deletion models/Organismo.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Organismo extends Eloquent {
//$table = 'organismos';

protected $dates = ['deleted_at'];
protected $visible = array('id', 'nombre', 'cupo', 'funcionarios_count', 'imagen');
protected $visible = array('id', 'nombre', 'cupo', 'funcionarios_count');
protected $appends = array('funcionarios_count');

public function funcionarios() {
Expand Down
4 changes: 4 additions & 0 deletions models/Patrulla.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ public function moderadores() {
return $this->hasMany('Moderador');
}

public function poderes() {
return $this->hasMany('Poder');
}

}
12 changes: 12 additions & 0 deletions models/Poder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php use Illuminate\Database\Eloquent\Model as Eloquent;

class Poder extends Eloquent {

protected $table = 'poderes';
protected $visible = array('id', 'accion', 'patrulla_id', 'created_at', 'updated_at');

public function patrulla() {
return $this->belongsTo('Patrulla');
}

}
Loading

0 comments on commit 30023e7

Please sign in to comment.