Merge branch 'develop'
This commit is contained in:
@ -1,13 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Aldarien\Common\Factory;
|
namespace Aldarien\Common\Factory;
|
||||||
|
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface as Container;
|
||||||
use \ORM as ORM;
|
use \ORM as ORM;
|
||||||
use \Model as BaseFactory;
|
use \Model as BaseFactory;
|
||||||
|
|
||||||
class Model {
|
class Model {
|
||||||
protected $container;
|
protected $container;
|
||||||
public function __construct(ContainerInterface $container) {
|
public function __construct(Container $container) {
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,12 +29,17 @@ class Model {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
protected $columns;
|
protected $columns;
|
||||||
|
/**
|
||||||
|
* <column>, [<column1>, <column2>, ...]
|
||||||
|
* string | array(array)
|
||||||
|
* <column>: [<name>, *<alias>, *<type>]
|
||||||
|
*/
|
||||||
public function select($columns): Model {
|
public function select($columns): Model {
|
||||||
if ($this->columns == null) {
|
if ($this->columns == null) {
|
||||||
$this->columns = [];
|
$this->columns = [];
|
||||||
}
|
}
|
||||||
if (!is_array($columns)) {
|
if (!is_array($columns)) {
|
||||||
$columns = [$columns];
|
$columns = [[$columns]];
|
||||||
}
|
}
|
||||||
$this->columns = array_merge($this->columns, $columns);
|
$this->columns = array_merge($this->columns, $columns);
|
||||||
return $this;
|
return $this;
|
||||||
@ -43,12 +48,21 @@ class Model {
|
|||||||
if ($this->columns == null or count($this->columns) == 0) {
|
if ($this->columns == null or count($this->columns) == 0) {
|
||||||
return $orm;
|
return $orm;
|
||||||
}
|
}
|
||||||
foreach ($this->columns as $column => $alias) {
|
foreach ($this->columns as $column) {
|
||||||
if (is_numeric($column)) {
|
if (is_string($column)) {
|
||||||
$orm = $orm->select($alias);
|
$column = [$column];
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
$orm = $orm->select($column, $alias);
|
$alias = $column['alias'] ?? $column[1] ?? $column[0];
|
||||||
|
$method = 'select';
|
||||||
|
if (count($column) > 2 or isset($column['type'])) {
|
||||||
|
$type = $column['type'] ?? $column[2] ?? '';
|
||||||
|
switch ($type) {
|
||||||
|
case 'expr':
|
||||||
|
$method .= 'Expr';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$orm = $orm->{$method}($column, $alias);
|
||||||
}
|
}
|
||||||
return $orm;
|
return $orm;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ class RelationNode {
|
|||||||
$source = implode('.', [$this->source->table, $this->source->key]);
|
$source = implode('.', [$this->source->table, $this->source->key]);
|
||||||
$destination = implode('.', [$this->destination->table, $this->destination->key]);
|
$destination = implode('.', [$this->destination->table, $this->destination->key]);
|
||||||
$method = str_replace([' '], ['_'], strtolower($this->join));
|
$method = str_replace([' '], ['_'], strtolower($this->join));
|
||||||
$output = $factory->{$method}([$this->destination->table, [$destination, $source, $this->relation]]);
|
$output = $factory->{$method}([[$this->destination->table, $destination, $source, $this->relation]]);
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,13 +46,13 @@ class Relationship {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
public function build(): ModelFactory {
|
public function build(): ModelFactory {
|
||||||
$output = $factory->find($this->start->class);
|
$output = $this->factory->find($this->start->class);
|
||||||
foreach ($this->nodes as $node) {
|
foreach ($this->nodes as $node) {
|
||||||
$output = $node->build($output);
|
$output = $node->build($output);
|
||||||
}
|
}
|
||||||
$output = $output->where([
|
$output = $output->where([
|
||||||
implode('.', [$this->condition->table, $this->condition->key]),
|
[implode('.', [$this->condition->table, $this->condition->key]),
|
||||||
$this->condition->value
|
$this->condition->value]
|
||||||
]);
|
]);
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user