Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for request context options #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions src/Odoo.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Project: Laradoo.
* User: Edujugon
Expand Down Expand Up @@ -121,6 +122,13 @@ class Odoo
*/
protected $fields;

/**
* request context
*
* @var array
*/
protected $context;


/**
* Create a new Odoo instance
Expand Down Expand Up @@ -172,9 +180,15 @@ public function can($permission, $model, $withExceptions = false)
{
if (!is_array($permission)) $permission = [$permission];

$can = collect($this->object->execute_kw($this->db, $this->uid, $this->password,
$model, 'check_access_rights',
$permission, array('raise_exception' => $withExceptions)));
$can = collect($this->object->execute_kw(
$this->db,
$this->uid,
$this->password,
$model,
'check_access_rights',
$permission,
array('raise_exception' => $withExceptions)
));

return $this->makeResponse($can, 0, 'boolean');
}
Expand Down Expand Up @@ -230,6 +244,19 @@ public function fields($fields)
return $this;
}

/**
* Set request context.
*
* @param array $context
* @return $this
*/
public function context($context)
{
$this->context = is_array($context) ? $context : func_get_args();

return $this;
}

/**
* Get the ids of the models.
*
Expand Down Expand Up @@ -273,7 +300,6 @@ public function count($model)
$this->resetParams('condition');

return $this->makeResponse($result, 0);

}

/**
Expand All @@ -294,12 +320,12 @@ public function get($model)
if (is_string($ids))
throw new OdooException($ids);

$params = $this->buildParams('fields');
$params = $this->buildParams('fields', 'context');

$result = $this->call($model, $method, [$ids->toArray()], $params);

//Reset params for future queries.
$this->resetParams('fields');
$this->resetParams('fields', 'context');

return $this->makeResponse($result);
}
Expand Down Expand Up @@ -442,7 +468,7 @@ public function call($params)
func_get_args()
);

return collect(call_user_func_array([$this->object,'execute_kw'], $args));
return collect(call_user_func_array([$this->object, 'execute_kw'], $args));
}

/**
Expand Down Expand Up @@ -636,7 +662,6 @@ private function auth($db, $username, $password, array $array = [])
else
throw new OdooException('Unsuccessful Authorization');
}

}


Expand All @@ -653,7 +678,6 @@ private function setApiEndPoint($endPoint)
throw new OdooException('You must provide the odoo host by host setter method');

return $this->host . $this->suffix . $endPoint;

}

/**
Expand Down