get specific model by $criteria

@param array $criteria
@param bool  $withTrash
@return null|object|static
341859
final public static function findBy(array $criteria, bool $withTrash = false)
    {
        $criteria = self::criteriaWithSoftDelete($criteria, $withTrash);
        $instance = static::getRepository()
            ->findOneBy($criteria);
        // use this to avoid lint error in idea
        if ($instance instanceof static) {
            return $instance;
        } else {
            return null;
        }
    }
397031
protected function with($with = null, $mode = self::MODE_OR)
    {
        if ($with instanceof GenericCollection) {
            $with = $with->toArray();
        }

        if (is_array($with)) {
            return $this->andWith((array) $with, $mode);
        }

        return $with;
    }
30567
public function loadAll(array $criteria = array(), array $orderBy = null, $limit = null, $offset = null)
    {
        $pool       = $this->manager->getPool();
        $manager_id = $this->class->getManagerIdentifier();

        $models = array();
        foreach ($this->class->getFieldManagerNames() as $manager) {
            $models[$manager] = $this->class->getFieldMapping($manager)->getName();
        }

        $data = $pool->getManager($manager_id)->getRepository($models[$manager_id])->findBy($criteria, $orderBy, $limit, $offset);

        if (empty($data)) {
            return array();
        }

        $builder = new ModelBuilder($this->manager, $this->uow, $this->class);

        return $builder->buildAll($data, $manager_id);
    }
22899
private function GetWhereSQL($criteria)
	{
		$ands = $criteria->GetAnds();
		$ors = $criteria->GetOrs();
		
		// TODO: this all needs to move to the criteria object so it will recurse properly  ....
		$where = $this->RemoveWherePrefix($criteria->GetWhere());
		
		if (count($ands))
		{
			$wdelim = ($where) ? " and " : "";
			foreach($ands as $c)
			{
				$tmp = $c->GetWhere();
				$buff = $this->RemoveWherePrefix($tmp);
				if ($buff)
				{
					$where .= $wdelim . $buff;
					$wdelim = " and ";
				}
			}
		}
		
		if (count($ors))
		{
			$where = trim($where) ? "(" . $where . ")" : ""; // no primary criteria.  kinda strange
			$wdelim = $where ? " or " : "";
				
			foreach($ors as $c)
			{
				$tmp = $c->GetWhere();
				$buff = $this->RemoveWherePrefix($tmp);
				if ($buff)
				{
					$where .= $wdelim . "(" . $buff . ")";
					$wdelim = " or ";
				}
			}
		}
		
		// .. end of stuff that should be in criteria	

		// prepend the "where" onto the statement
		if ($where) $where = " where (" . trim($where) . ") ";
		
		return $where;
	}
1204613
public function findOneBy(array $criteria)
    {
        $documents = $this->findBy($criteria, null, 1);

        return $documents->isEmpty() ? null : $documents->first();
    }
1229415
public function matching(Criteria $criteria)
    {
        $visitor = new QueryExpressionVisitor($this->createQueryBuilder());
        $queryBuilder = $this->createQueryBuilder();

        if ($criteria->getWhereExpression() !== null) {
            $expr = $visitor->dispatch($criteria->getWhereExpression());
            $queryBuilder->setQueryArray($expr->getQuery());
        }

        if ($criteria->getMaxResults() !== null) {
            $queryBuilder->limit($criteria->getMaxResults());
        }

        if ($criteria->getFirstResult() !== null) {
            $queryBuilder->skip($criteria->getFirstResult());
        }

        if ($criteria->getOrderings() !== null) {
            $queryBuilder->sort($criteria->getOrderings());
        }

        // @TODO: wrap around a specialized Collection for efficient count on large collections
        return new ArrayCollection($queryBuilder->getQuery()->execute()->toArray());
    }
336627
public function retrieve($criteria)
    {
        if ($criteria instanceof SearchBuilder) {
            $criteria = $criteria->getParams();
        }

        if (!is_array($criteria)) {
            throw new LoggerException('$criteria has to be of type array of SearchBuilder');
        }

        try {
            $this->registerErrorHandler();

            $request = new RequestDescriptor();

            $request->setUrl($this->buildUrl('/api/notifications?criteria=' . urlencode(json_encode($criteria))));
            $request->setMethod('GET');

            $return = $this->send($request, ApiRequestOption::NO_RESPONSE);

            $this->restoreErrorHandler();

            return $return;
        } catch (\Exception $e) {
            $this->writeToExceptionLogFile($e->getMessage());
            $this->restoreErrorHandler();
        }
    }
852719
public function getAnalyticsViewsForm($withPortfolioSelect = false)
    {
        return new AnalyticsViewsType($this->translator, $this->securityTokenStorage->getToken()->getUser(), $withPortfolioSelect);
    }
178936
public function with($with)
    {
        if (is_string($with)) {
            if (strpos($with, ',') === false) {
                $with = [$with];
            } else {
                $with = (array)preg_split('#[\s,]+#', $with, -1, PREG_SPLIT_NO_EMPTY);
            }
        }

        $with = $this->_with ? array_merge($this->_with, $with) : $with;

        foreach ($with as $k => $v) {
            $name = is_string($k) ? $k : $v;
            if (($pos = strpos($name, '.')) === false) {
                continue;
            }
            $parent_name = substr($name, 0, $pos);
            $child_name = substr($name, $pos + 1);
            if (!isset($with[$parent_name])) {
                continue;
            }

            $parent_value = $with[$parent_name];
            if (!$parent_value instanceof QueryInterface) {
                $with[$parent_name] = $this->relationsManager->getQuery($this->_model, $parent_name, $parent_value);
            }

            $with[$parent_name]->with(is_int($k) ? [$child_name] : [$child_name => $v]);
            unset($with[$k]);
        }

        $this->_with = $with;

        return $this;
    }
1056965
public static function findOneEntityByCriteria(array $criteria = [], array $exclude = [])
    {
        $class = static::class;

        /** @var EntityRepository $obj_collection */
        $obj_collection = new $class();
        $obj_collection->setLimit(1);

        foreach ($criteria as $k => $v) {
            $obj_collection->addSimpleWhereField($k, $v);
        }

        foreach ($exclude as $k => $v) {
            $obj_collection->addWhereFieldIsNot($k, $v);
        }

        return $obj_collection->getFirstObjectFromCollection();
    }
898711
public function find($criteria=null)
	{
		if($this->_parent===null) // root element
		{
			$query=new CJoinQuery($this,$criteria);
			$this->_finder->baseLimited=($criteria->offset>=0 || $criteria->limit>=0);
			$this->buildQuery($query);
			$this->_finder->baseLimited=false;
			$this->runQuery($query);
		}
		elseif(!$this->_joined && !empty($this->_parent->records)) // not joined before
		{
			$query=new CJoinQuery($this->_parent);
			$this->_joined=true;
			$query->join($this);
			$this->buildQuery($query);
			$this->_parent->runQuery($query);
		}

		foreach($this->children as $child) // find recursively
			$child->find();

		foreach($this->stats as $stat)
			$stat->query();
	}
1207099
private function factoryCallableCriteria($criteria)
    {
        if (!$this->isCallable($criteria)) {
            $criteria = function ($element, $key) use ($criteria) {
                return $element->fetch($criteria);
            };
        }

        return $criteria;
    }
947881
public function findWhere($criteria, $returnType = Table::RETURN_MODEL) {
        if (!is_array($criteria)) {
            $criteria = array($criteria);
        }
        $return = $this->select($criteria, $returnType);
        if (is_a($return, 'DBScribe\Table')) $return = $return->execute();
        return $return;
    }
588936
public function getURI(array $criteria)
    {
        $uris = $this->getURIs($criteria);

        return $uris->count() > 0
            ? $uris->first()
            : false;
    }
786450
protected function findWithCriteria(array $criteria, array $orderBy = null, $limit = null, $offset = null)
    {
        $qb = $this->getLoadQuery();
        foreach ($criteria as $col => $val) {
            if (is_array($val)) {
                $qb->andWhere($this->getAlias() . ".$col IN(:$col)");
                $qb->setParameter(":$col", $val, Connection::PARAM_INT_ARRAY);
            } else {
                $qb->andWhere($this->getAlias() . ".$col = :$col");
                $qb->setParameter(":$col", $val);
            }
        }
        if ($orderBy) {
            $qb->orderBy($orderBy[0], $orderBy[1]);
        }
        if ($limit) {
            $qb->setMaxResults($limit);
        }
        if ($offset) {
            $qb->setFirstResult($offset);
        }

        return $qb;
    }
869852
public function findOneBy(array $criteria, ?array $orderBy = null)
    {
        $criteria = $this->mapCriteriaSetUuidsToStrings($criteria);
        $entity   = $this->entityRepository->findOneBy($criteria, $orderBy);
        if (null === $entity) {
            return null;
        }
        if ($entity instanceof EntityInterface) {
            $this->initialiseEntity($entity);

            return $entity;
        }
    }
612110
public function findWhereNotIn($attribute, $values, $columns = ['*'], $with = [])
    {
        $values   = $this->castRequest($values);
        $cacheKey = $this->generateKey([$attribute, $values, $columns, $with]);

        return $this->cacheResults(get_called_class(), __FUNCTION__, $cacheKey, function () use ($attribute, $values, $columns, $with) {
            return $this->model->with($with)
                ->whereNotIn($attribute, $values)
                ->get($columns);
        });
    }