get('odoo'); } return $db->createCommand($this->from, 'search_read', $this->options, $this->mapping) ->execute(); } /** * Executes the query and returns a single row of result. * * @param Connection $db the database connection used to execute the query. * If this parameter is not given, the `db` application component will be used. * * @return array|bool the first row (in terms of an array) of the query result. False is returned if the query * results in nothing. */ public function one($db = null) { $result = $this->all($db); if (empty($result)) { return null; } else { return $result[ 0 ]; } } /** * Returns the number of records. * * @param string $q the COUNT expression. Defaults to '*'. * @param Connection $db the database connection used to execute the query. * If this parameter is not given, the `db` application component will be used. * * @return int number of records. */ public function count($q = '*', $db = null) { /** * @var Connection $db */ if (empty($db)) { $db = \Yii::$app->get('odoo'); } return ( new Command( [ 'db' => $db, ] ) )->count('product.product', $this->options, $this->mapping); } /** * Returns a value indicating whether the query result contains any row of data. * * @param Connection $db the database connection used to execute the query. * If this parameter is not given, the `db` application component will be used. * * @return bool whether the query result contains any row of data. */ public function exists($db = null) { if ($this->count('*', $db)) { return true; } else { return false; } } /** * @param array $fields * * @return \artbox\odoo\components\Query */ public function select(array $fields) { $this->mapping[ 'fields' ] = $fields; return $this; } /** * @param $model * * @return \artbox\odoo\components\Query */ public function from($model) { $this->from = $model; return $this; } /** * @param array $mapping * * @return \artbox\odoo\components\Query */ public function mapping(array $mapping) { $this->mapping = $mapping; return $this; } /** * @param array $mapping * * @return \artbox\odoo\components\Query */ public function addMapping(array $mapping) { if (is_array($this->mapping)) { $this->mapping = array_merge($this->mapping, $mapping); } else { $this->mapping = $mapping; } return $this; } /** * @param int|null $offset * * @return \artbox\odoo\components\Query */ public function offset($offset) { $this->mapping[ 'offset' ] = $offset; return $this; } /** * @param int|null $limit * * @return \artbox\odoo\components\Query */ public function limit($limit) { $this->mapping[ 'limit' ] = $limit; return $this; } /** * @param array|string $condition * * @return \artbox\odoo\components\Query */ public function where($condition) { $this->options[ 0 ][] = $condition; return $this; } /** * @param array|string $condition * * @return \artbox\odoo\components\Query */ public function andWhere($condition) { return $this->where($condition); } }