Selects records by multiple ids.

@param string|array $ids
@param array        $options
@param array        $criteria

@return mixed
@throws BatchException
6131
public static function selectByIds($ids, array $options = [], array $criteria = [])
    {
        $criteria = static::cleanCriteria($criteria);
        if (empty($criteria)) {
            $criteria['select'] = ['*'];
        }

        if (is_array($ids)) {
            $ids = implode(',', $ids);
        }

        $pk = static::getPrimaryKeyStatic();
        if (!empty($ids)) {
            $idsPhrase = " $pk IN ($ids) ";

            $condition = array_get($criteria, 'condition');

            if (!empty($condition)) {
                $condition .= ' AND ' . $idsPhrase;
            } else {
                $condition = $idsPhrase;
            }

            $criteria['condition'] = $condition;
        }

        $data = static::selectByRequest($criteria, $options);

        $data = static::cleanResult($data, array_get($criteria, 'select'));
        if (!is_array($ids)) {
            $ids = explode(',', $ids);
        }
        if (count($data) != count($ids)) {
            $out = [];
            $continue = array_get_bool($options, ApiOptions::CONTINUES);
            foreach ($ids as $index => $id) {
                $found = false;
                foreach ($data as $record) {
                    if ($id == array_get($record, $pk)) {
                        $out[$index] = $record;
                        $found = true;
                        break;
                    }
                }
                if (!$found) {
                    $out[$index] = new NotFoundException("Record with identifier '$id' not found.");
                    if (!$continue) {
                        break;
                    }
                }
            }

            throw new BatchException($out, 'Batch Error: Not all requested records could be retrieved.');
        }

        return $data;
    }
1261356
public function remove(array $criteria = [], array $options = [])
    {
        $this->createChunksIndex();

        $matchingFiles = parent::find($criteria, ['_id' => 1]);
        $ids = [];
        foreach ($matchingFiles as $file) {
            $ids[] = $file['_id'];
        }
        $this->chunks->remove(['files_id' => ['$in' => $ids]], ['justOne' => false] + $options);
        return parent::remove(['_id' => ['$in' => $ids]], ['justOne' => false] + $options);
    }
333325
public function selectColByIdsPreserveIds(array $ids = array(), $columnName = 'id')
    {
        if (empty($ids)) {
            return array();
        }

        $_query = $this->getSelectQueryByIds($ids);
        $_columnIndexId = $this->_getColumnIndexInSelectQuery($this->getIdentityColumn());
        $_columnIndex = $this->_getColumnIndexInSelectQuery($columnName);

        if ($_columnIndex === false || $_columnIndexId === false) {
            throw new \InvalidArgumentException(get_called_class() . '::' . __FUNCTION__ . '() Invalid column name given as second parametter. "' . $columnName . '" given');
        }

        $_stmt1 = $this->db->getAdapter()->query($_query);
        $columnIndexId = $_stmt1->fetchAll(Zend_Db::FETCH_COLUMN, $_columnIndexId);

        $_stmt2 = $this->db->getAdapter()->query($_query);
        $columnIndex = $_stmt2->fetchAll(Zend_Db::FETCH_COLUMN, $_columnIndex);
        $res = array_combine($columnIndexId, $columnIndex);
        if ($res !== false) {
            return $res;
        } else {
            throw new \RuntimeException("Not same count between ID and selected COLUMN");
        }
    }
113913
public function childCount($id, array $options = [])
	{
		$options['for'] = $id;

		$query = $this->findChildren($this->_table->find(), $options);

		return $query->count();
	}
425570
public function findByIds(array $ids): array
    {
        $result = [];
        if (count($ids) > 0) {
            $queryBuilder = $this->entityManager->createQueryBuilder();
            $queryBuilder->select('i')
                         ->from(Item::class, 'i')
                         ->andWhere('i.id IN (:ids)')
                         ->setParameter('ids', array_values($ids));

            $result = $queryBuilder->getQuery()->getResult();
        }
        return $result;
    }
96556
public function findMany($ids, array $columns = ['*'])
    {
        if (empty($ids)) {
            return $this->model->newCollection();
        }

        $this->getBuilder()->whereIn($this->getModel()->getQualifiedKeyName(), $ids);

        return $this->get($columns);
    }
1046574
public function update(array $data, array $criteria = [], array $options = []) {
		return $this->getAdapter()->update(
			$this->getTableName(),
			$criteria,
			$data,
			$options
		);
	}
216675
public function findByIds($ids)
    {
        $query = $this->createQueryBuilder('m')
            ->where('m.id IN (:ids)')
            ->andWhere('m.status = :status')
            ->setParameters(array(
                'ids' => $ids,
                'status' => 1,
            ))
            ->getQuery()
        ;

        return $query->getResult();
    }
1062453
public function findBy(array $criteria = [], array $orders = [], $limit = null, $offset = null): array
    {
        $options = [];

        if ($orders) {
            foreach ($orders as $field => &$dir) {
                if ($dir === 'ASC') {
                    $dir = 1;
                } elseif ($dir === 'DESC') {
                    $dir = -1;
                }

            }
            $options['sort'] = $orders;
        }

        if ($limit !== null) {
            $options['limit'] = $limit;
        }

        if ($offset !== null) {
            $options['skip'] = $offset;
        }

        $options['projection'] = [];

        /** @var Cursor $cursor */
        $cursor = $this->collection->find($criteria, $options);

        $ids = [];

        $data = iterator_to_array($cursor);

        array_walk($data, function($value, $key) use (&$ids) {
            $ids[] = $value['_id'];
        });

        return $this->findByIds($ids);
    }
521874
public function queryDocument($collection, $sql, array $params = [], array $options = [])
    {
        $this->setOptions($options);
        $doc = new Document($this->client, $this->database, $collection);
        $doc->setHeaders($this->getHeaders());
        $rs = $doc->query($sql, $params);
        $this->checkResponse($rs);
        unset($rs['_curl_info']);

        return $rs;
    }
1163829
public static function batchCreateCoupons($id, $params = null, $options = null)
    {
        $url = static::classUrl() . '/' . $id . '/coupons';
        return static::_directRequest('post', $url, $params, $options);
    }
1014750
public function select(array $configs, $options)
    {
        $label = (!empty($options['name']) ? ucwords($options['name']) : '');

        return '
        <div class="input-field">
        '.parent::plainSelect(array_merge([
            'id' => $this->genId($label),
        ], $configs), $options).(empty($label) | (substr($label, 0,
                1) == '_') ? '' : '<label for="'.$label.'">'.$this->inputToRead($label).'</label>').'
        </div>
         ';
    }
1354755
public function select(array $criteria = array(),
            $return = Table::RETURN_MODEL) {
        if (!$this->checkExists()) {
            return ($this->delayExecute) ? $this : new ArrayCollection();
        }

        $this->current = self::OP_SELECT;

        $this->query = 'SELECT ' . $this->prepareColumns();
        $this->query .= ' FROM `' . $this->name . '`' . $this->processJoins();

        $this->where($criteria);

        $this->setExpectedResult($return, true);
        if ($this->delayExecute) {
            return $this;
        }
        return $this->execute();
    }
356065
public function findByIds(array $ids)
    {
        $ids = $this->getRepository()->idsToMongo($ids);
        return $this->mergeCriteria(array('_id' => array('$in' => $ids)));
    }
283
public function find($criteria = array())
    {
        if (!is_array($criteria)) {
            $criteria = array(
                '$id' => $criteria,
            );
        }

        // wrap criteria as NObject instance to make sure it can be override by hooks
        $criteria = new NObject($criteria);

        $this->applyHook('searching', $criteria);
        $cursor = $this->connection->query($this, $criteria->toArray());
        $this->applyHook('searched', $cursor);

        return $cursor;
    }
1245685
protected function createSelectQuery(array $fields = [], array $criteria = [], array $orderBy = [], $distinct = true)
	{
		if ($this->objectManager instanceof \Doctrine\ORM\EntityManager) {
			/** @var \Doctrine\ORM\QueryBuilder $builder */
			$builder = $this->objectManager->createQueryBuilder();
			$builder->select(empty($fields) ? 'p' : 'p.' . implode(', p.', $fields));
			
			if (true === $distinct) {
				$builder->distinct();
			}
			
			$builder->from($this->className, 'p')
					->setFirstResult($this->getItemOffset())
					->setMaxResults($this->itemPerPage);
			
			foreach ($orderBy as $key => $value) {
				$builder->orderBy(sprintf('p.%s', $key), $value);
			}
		} elseif ($this->objectManager instanceof \Doctrine\ODM\MongoDB\DocumentManager) {
			/** @var \Doctrine\ODM\MongoDB\Query\Builder $builder */
			$builder = $this->objectManager->createQueryBuilder($this->className);
			
			if (false === empty($fields)) {
				$builder->select($fields);
			}
			
			$builder->skip($this->getItemOffset())
					->limit($this->itemPerPage);
			
			foreach ($orderBy as $key => $value) {
				$builder->sort($key, $value);
			}
		} else {
			throw new ObjectManagerNotSupportedException(sprintf('Doctrine object manager class "%s" is not supported.', get_class($this->objectManager)));
		}
		
		$this->qbHandler->applyExprFromArray($builder, 'p', $criteria);
		
		return $builder->getQuery();
	}
894004
public function getByCriteria($criteria, $fieldName)
    {
        /** @var Statement $statement */
        $queryBuilder = $this->getSelectQueryBuilder();
        $queryBuilder->where($fieldName . " = :criteria");
        $queryBuilder->setParameter('criteria', $criteria);

        $statement = $queryBuilder->execute();
        $rows      = $statement->fetchAll();
        $this->prepareResults($rows);
        return $rows;
    }