Base
This commit is contained in:
31
app/Definition/Controller.php
Normal file
31
app/Definition/Controller.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace App\Definition;
|
||||
|
||||
trait Controller
|
||||
{
|
||||
protected static $default;
|
||||
|
||||
public static function index()
|
||||
{
|
||||
$action = get('a');
|
||||
if ($action == null) {
|
||||
$action = get('action');
|
||||
}
|
||||
if ($action != null) {
|
||||
$ref = new \ReflectionMethod(self::class, $action);
|
||||
if (method_exists(self::class, $action) and $ref->isPublic()) {
|
||||
|
||||
return self::{$action}();
|
||||
}
|
||||
}
|
||||
if (self::$default == null and \method_exists(self::class, 'setDefault')) {
|
||||
self::setDefault();
|
||||
}
|
||||
if (self::$default == null) {
|
||||
header('Location: .');
|
||||
return;
|
||||
}
|
||||
return self::$default;
|
||||
}
|
||||
}
|
||||
?>
|
38
app/Definition/hasEstado.php
Normal file
38
app/Definition/hasEstado.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace App\Definition;
|
||||
|
||||
use Stringy\Stringy;
|
||||
|
||||
trait hasEstado
|
||||
{
|
||||
public function estados()
|
||||
{
|
||||
$table = $this->getTable();
|
||||
$self = Stringy::create(get_class($this));
|
||||
$ns = $self->substr(0, $self->indexOfLast('\\'));
|
||||
$self = $self->substr($self->indexOfLast('\\') + 1);
|
||||
$column = $self->underscored();
|
||||
$class = $ns . '\\Estado' . $self;
|
||||
if (substr($table, -1, 1) == 's') {
|
||||
$column .= '_id';
|
||||
}
|
||||
|
||||
return $this->has_many($class, $column)->findMany();
|
||||
}
|
||||
public function estado()
|
||||
{
|
||||
$table = $this->getTable();
|
||||
$self = Stringy::create(get_class($this));
|
||||
$ns = $self->substr(0, $self->indexOfLast('\\'));
|
||||
$self = $self->substr($self->indexOfLast('\\') + 1);
|
||||
$column = $self->underscored();
|
||||
$class = $ns . '\\Estado' . $self;
|
||||
if (substr($table, -1, 1) == 's') {
|
||||
$column .= '_id';
|
||||
}
|
||||
|
||||
$id = $this->has_many($class, $column)->max('id');
|
||||
return $this->has_many($class, $column)->findOne($id);
|
||||
}
|
||||
}
|
||||
?>
|
20
app/Definition/hasRUT.php
Normal file
20
app/Definition/hasRUT.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace App\Definition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Aldarien
|
||||
* @property int rut
|
||||
* @property char dv
|
||||
*
|
||||
*/
|
||||
trait hasRUT
|
||||
{
|
||||
protected static $_id_column = 'rut';
|
||||
|
||||
public function fullRut()
|
||||
{
|
||||
return format('rut', $this->rut) . '-' . $this->dv;
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user