Skip to content

Commit

Permalink
Merge pull request #3 from Sberned/release/1.0.9
Browse files Browse the repository at this point in the history
Release 1.0.9
  • Loading branch information
R0gnar authored Nov 14, 2016
2 parents 8a923b9 + ba25434 commit 8c7c57a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Sberned/RestORM/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function limit($per_page, $page)
public function getLink(): string
{
return $this->link . "?" . $this->getFields() . $this->getIncludes() . $this->getOrdering() . $this->pagination .
'&' . $this->getWhereis();
'&' . $this->getWhereis();
}

/**
Expand Down
57 changes: 43 additions & 14 deletions src/Sberned/RestORM/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Jsonable;
use ArrayAccess;
use Illuminate\Support\Collection;
use JsonSerializable;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Arr;
Expand Down Expand Up @@ -142,7 +143,7 @@ private function insertThis()

$newQuery = new Builder($this->className, $this->getUrl(), $this->getLink(), 'POST', true, $this->attributes);
$res = $newQuery->send();
$className = $this->className;
$className = $this->alias_list;
$data = $this->convertToObject($res->$className);

if(!empty($data)) {
Expand Down Expand Up @@ -207,7 +208,7 @@ public function get(array $columns = [])
$newQuery = new Builder($this->className, $this->getUrl(), $this->getLink(), 'get', true, []);
$newQuery->setValues($this->_values);
$res = $newQuery->send();
$className = $this->url;
$className = $this->alias_list;

return collect($res->$className);
}
Expand All @@ -225,7 +226,7 @@ public function all(array $columns = [])
$newQuery = new Builder($this->className, $this->getUrl(), $this->getLink(), 'get', true, []);
$newQuery->setValues($this->_values);
$res = $newQuery->send();
$className = $this->url;
$className = $this->alias_list;

return collect($res->$className);
}
Expand Down Expand Up @@ -279,8 +280,12 @@ public function paginate($limit, $page)
* @param array $select
* @return mixed
*/
public function addSelect(array $select)
public function addSelect($select)
{
if (!is_array($select)) {
$select = func_get_args();
}

$this->_values['Select'] = $select;

return $this;
Expand All @@ -294,20 +299,20 @@ public function addSelect(array $select)
* @param string $boolean
* @return mixed
*/
public function addWhere($column, $operator = '=', $value = null, $fulltext_search = false, $boolean = 'and')
public function addWhere($column, $operator = '=', $value = null)
{
if ($fulltext_search) {
$prefix = '@';
} else {
$prefix = '';
if (count(func_get_args()) == 2) {
$value = $operator;
$operator = '=';
}

switch ($operator) {
case '==' || '=':
$this->setWhere($column, $value, $prefix);
case '=':
$this->setWhere($column, $value, '');
break;
case '<>' || '!=':

case '<>':
case '!=':
$this->setWhere($column, $value, '^');
break;
case '<':

Expand All @@ -320,6 +325,9 @@ public function addWhere($column, $operator = '=', $value = null, $fulltext_sear
break;
case '>=':

break;
case 'like':
$this->setWhere($column, $value . ':*', '@');
break;
}

Expand All @@ -328,6 +336,10 @@ public function addWhere($column, $operator = '=', $value = null, $fulltext_sear

public function addWhereIn($column, $values)
{
if ($values instanceof Collection) {
$values = $values->all();
}

$values = array_filter($values, function($value) {
return $value > 0;
});
Expand Down Expand Up @@ -364,6 +376,10 @@ public function limit($per_page = 15, $page = 1)
*/
public function addWith($array)
{
if (!is_array($array)) {
$array = func_get_args();
}

if(is_array($array)){
foreach ($array as $arr) {
$this->_values['With'][] = $arr;
Expand All @@ -375,6 +391,11 @@ public function addWith($array)
return $this;
}

public function addSearch($query)
{
return $this->addWhere('search', $query . ':*');
}

/**
* @return string
*/
Expand Down Expand Up @@ -415,8 +436,12 @@ public static function getCallClass()
/**
* @param array $query
*/
public function setSelect(array $query)
public function setSelect($query)
{
if (!is_array($query)) {
$query = func_get_args();
}

$this->_values['Select'] = $query;
}

Expand Down Expand Up @@ -586,6 +611,10 @@ public function __call($name, $arguments)
return call_user_func_array([$this, 'findOne'], $arguments);
}

if ($name == 'findMany') {
return call_user_func_array([$this, 'findMany'], $arguments);
}

$method = 'add' . ucfirst($name);
if (!method_exists($this, $method)) {
throw new \Exception('Method ' . $method . ' does not exists');
Expand Down

0 comments on commit 8c7c57a

Please sign in to comment.