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