Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: lexo
- * Date: 9/13/18
- * Time: 11:49 AM
- */
- require_once("ripcord.php");
- /**
- * Class odoo
- */
- class odoo {
- public $uid = Null;
- private $models = Null;
- private $url=False;
- private $db=False;
- private $username=False;
- private $password=False;
- /**
- * odoo constructor.
- */
- function __construct($url,$db, $username, $password)
- {
- $this->url = $url;
- $this->db = $db;
- $this->username = $username;
- $this->password = $password;
- if(!empty($this->url)){
- $common = ripcord::client("$this->url/xmlrpc/2/common");
- $this->uid = $common->authenticate($this->db, $this->username, $this->password, array());
- $this->models = ripcord::client("$this->url/xmlrpc/2/object");
- }
- }
- /**
- * @param $model
- * @param $data
- * @param bool $multiple
- * @return bool|mixed
- */
- public function create($model,$data, $multiple=False){
- $create_data = $multiple? $data:[$data];
- $created_id = $this->execute(
- $model,
- 'create', // Function name
- $create_data
- );
- if(is_int($created_id)){
- return $created_id;
- }
- else{
- return False;
- }
- }
- /**
- * @param $model
- * @param $conditions
- * @param $data
- * @return bool|mixed
- */
- public function update($model,$conditions,$data){
- $id = $this->findOne($model,$conditions);
- if($id){
- $updated = $this->execute( $model, 'write',
- array(array($id), $data));
- // return $updated;
- return $id;
- } else{
- return False;
- }
- }
- /**
- * @param $model
- * @param $conditions
- * @return mixed
- */
- public function find($model,$conditions){
- $result = $this->execute(
- $model, 'search',
- [$conditions]);
- return $result;
- }
- /**
- * @param $model
- * @param $conditions
- * @return mixed
- */
- public function findOne($model,$conditions){
- $result = $this->execute(
- $model, 'search',
- [$conditions],
- ['limit'=> 1]);
- return end($result);
- }
- /**
- * @param $model
- * @param $conditions
- * @return mixed
- */
- public function read($model, $conditions){
- $ids = $this->find($model,$conditions);
- $records = $this->execute(
- $model, 'search_read', [$conditions]);
- return $records;
- }
- /**
- * @param $model
- * @param $conditions
- * @return mixed
- */
- public function readOne($model, $conditions){
- $id = $this->findOne($model,$conditions);
- $records = $this->execute($model, 'search_read', [$conditions]);
- return end($records);
- }
- /**
- * @param $model
- * @param $action
- * @param array $conditions
- * @param array $options
- * @return mixed
- */
- private function execute($model, $action, $conditions=[],$options=[]){
- $res = $this->models->execute_kw($this->db, $this->uid, $this->password,
- $model, $action, $conditions,$options);
- return $res;
- }
- }
Add Comment
Please, Sign In to add comment