Server IP : 127.0.0.2 / Your IP : 18.221.248.199 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/app/ExternalClass/ |
Upload File : |
<?php /** * (c) Jacob Steringa <jacobsteringa@gmail.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace App\ExternalClass; use Zend\Http\Client as HttpClient; use Zend\XmlRpc\Client as XmlRpcClient; /** * Odoo is an PHP client for the xmlrpc api of Odoo, formerly known as OpenERP. * This client should be compatible with version 6 and up of Odoo/OpenERP. * * This client is inspired on the OpenERP api from simbigo and uses a more or * less similar API. Instead of an own XmlRpc class, it relies on the XmlRpc * and Xml libraries from ZF. * * @author Jacob Steringa <jacobsteringa@gmail.com> */ class Odoo { /** * Host to connect to * * @var string */ protected $host; /** * Unique identifier for current user * * @var integer */ protected $uid; /** * Current users username * * @var string */ protected $user; /** * Current database * * @var string */ protected $database; /** * Password for current user * * @var string */ protected $password; /** * XmlRpc Client * * @var XmlRpcClient */ protected $client; /** * XmlRpc endpoint * * @var string */ protected $path; /** * Optional custom http client to initialize the XmlRpcClient with * * @var HttpClient */ protected $httpClient; /** * Odoo constructor * * @param string $host The url * @param string $database The database to log into * @param string $user The username * @param string $password Password of the user * @param HttpClient $httpClient An optional custom http client to initialize the XmlRpcClient with */ public function __construct($host, $database, $user, $password, HttpClient $httpClient = null) { $this->host = $host; $this->database = $database; $this->user = $user; $this->password = $password; $this->httpClient = $httpClient; } /** * Get version * * @return array Odoo version */ public function version() { $response = $this->getClient('common')->call('version'); return $response; } /** * Get timezone * * @return string Current timezone */ public function timezone() { $params = array( $this->database, $this->user, $this->password ); return $this->getClient('common')->call('timezone_get', $params); } /** * Search models * * @param string $model Model * @param array $data Array of criteria * @param integer $offset Offset * @param integer $limit Max results * * @return array Array of model id's */ public function search($model, $data, $offset = 0, $limit = 100) { $params = $this->buildParams(array( $model, 'search', $data, $offset, $limit )); $response = $this->getClient('object')->call('execute', $params); return $response; } /** * Create model * * @param string $model Model * @param array $data Array of fields with data (format: ['field' => 'value']) * * @return integer Created model id */ public function create($model, $data) { $params = $this->buildParams(array( $model, 'create', $data )); $response = $this->getClient('object')->call('execute', $params); return $response; } /** * Read model(s) * * @param string $model Model * @param array $ids Array of model id's * @param array $fields Index array of fields to fetch, an empty array fetches all fields * * @return array An array of models */ public function read($model, $ids, $fields = array()) { $params = $this->buildParams(array( $model, 'read', $ids, $fields )); $response = $this->getClient('object')->call('execute', $params); return $response; } /** * Update model(s) * * @param string $model Model * @param array $ids Array of model id's * @param array $fields A associative array (format: ['field' => 'value']) * * @return array */ public function write($model, $ids, $fields) { $params = $this->buildParams(array( $model, 'write', $ids, $fields )); $response = $this->getClient('object')->call('execute', $params); return $response; } /** * Unlink model(s) * * @param string $model Model * @param array $ids Array of model id's * * @return boolean True is successful */ public function unlink($model, $ids) { $params = $this->buildParams(array( $model, 'unlink', $ids )); return $this->getClient('object')->call('execute', $params); } /** * Get report for model * * @param string $model Model * @param array $ids Array of id's, for this method it should typically be an array with one id * @param string $type Report type * * @return mixed A report file */ public function getReport($model, $ids, $type = 'qweb-pdf') { $params = $this->buildParams(array( $model, $ids, array( 'model' => $model, 'id' => $ids[0], 'report_type' => $type ) )); $client = $this->getClient('report'); $reportId = $client->call('report', $params); $state = false; while (!$state) { $report = $client->call( 'report_get', $this->buildParams(array($reportId)) ); $state = $report['state']; if (!$state) { sleep(1); } } return base64_decode($report['result']); } /** * Return last request * * @return string */ public function getLastRequest() { return $this->getClient()->getLastRequest(); } /** * Return last response * * @return string */ public function getLastResponse() { return $this->getClient()->getLastResponse(); } /** * Set custom http client * * @param HttpClient $httpClient */ public function setHttpClient(HttpClient $httpClient) { $this->httpClient = $httpClient; } /** * Build parameters * * @param array $params Array of params to append to the basic params * * @return array */ protected function buildParams(array $params) { return array_merge(array( $this->database, $this->uid(), $this->password ), $params); } /** * Get XmlRpc Client * * This method returns an XmlRpc Client for the requested endpoint. * If no endpoint is specified or if a client for the requested endpoint is * already initialized, the last used client will be returned. * * @param null|string $path The api endpoint * * @return XmlRpcClient */ protected function getClient($path = null) { if ($path === null) { return $this->client; } if ($this->path === $path) { return $this->client; } $this->path = $path; $this->client = new XmlRpcClient($this->host . '/' . $path, $this->httpClient); // The introspection done by the Zend XmlRpc client is probably specific // to Zend XmlRpc servers. To prevent polution of the Odoo logs with errors // resulting from this introspection calls we disable it. $this->client->setSkipSystemLookup(true); return $this->client; } /** * Get uid * * @return int $uid */ protected function uid() { if ($this->uid === null) { $client = $this->getClient('common'); $this->uid = $client->call('login', array( $this->database, $this->user, $this->password )); } return $this->uid; } }