{@inheritdoc}

@param  callable $condition
@return int
353779
public function find_last_index( $condition ) {
		$index = -1;

		for ( $i = count( $this->elements ) - 1; $i >= 0; $i-- ) {
			if ( call_user_func( $condition, $this->elements[ $i ] ) ) {
				$index = $i;
				break;
			}
		}

		return $index;
	}
967771
public function dbCount($table, $condition = '')
    {
        $result = Eresus_CMS::getLegacyKernel()->db->count($this->__table($table), $condition);

        return $result;
    }
677843
protected function resolveConditionalLogic($condition)
    {
        $renderer = $this->getActionRenderer();
        if ($renderer && is_callable([ $renderer, $condition ])) {
            return !!$renderer->{$condition}();
        } elseif (is_callable([ $this, $condition ])) {
            return !!$this->{$condition}();
        } elseif (is_callable($condition)) {
            return !!$condition();
        } elseif ($renderer) {
            return !!$renderer->renderTemplate($condition);
        } elseif ($this->view()) {
            return !!$this->renderTemplate($condition);
        }

        return !!$condition;
    }
913484
public function count( $conditions = array() )
	{
		$conditions	= $this->getConditionQuery( $conditions, FALSE, TRUE, TRUE );					//  render WHERE clause if needed, foreign cursored, allow functions
		$conditions	= $conditions ? ' WHERE '.$conditions : '';
		$query	= 'SELECT COUNT(`%s`) as count FROM %s%s';
		$query	= sprintf( $query, $this->primaryKey, $this->getTableName(), $conditions );
		return (int) $this->dbc->query( $query )->fetch( \PDO::FETCH_OBJ )->count;
	}
356929
public function id(array $condition)
    {
        $user_id = $this->user->getId();
        return $this->compare($user_id, $condition['value'], $condition['operator']);
    }
978799
public function possible($condition) {
      $query = $this->buildStrategyCondition($condition, Possible::create());
      return $this->process($query);
    }
1201423
public function createCondition(array $condition): ConditionInterface
    {
        foreach ($this->conditionNameToConditionClassMap as $conditionName => $conditionClass) {
            if (isset($condition[$conditionName])) {
                return new $conditionClass($condition['command'], $condition[$conditionName]);
            }
        }

        throw new ConditionNotFoundException(sprintf('Condition could not be found, available conditions are: %s', implode(', ', $this->conditionNameToConditionClassMap)));
    }
530439
public function indexOf(callable $callback) {
    foreach ($this->nodes as $i => $node) {
      if ($callback($node)) {
        return $i;
      }
    }
    return -1;
  }
451930
public function when($condition, callable $call, callable $notCall = null)
    {
        if (is_callable($condition)) {
            $result = call_user_func($condition);
        } else {
            $result = $condition;
        }
        if ($result) {
            call_user_func_array($call, [$this]);
        } else {
            if ($notCall) {
                call_user_func_array($notCall, [$this]);
            }
        }
        return $this;
    }
233676
protected function assertCondition($record, $condition)
    {
        $left = $condition[0];
        $op = $condition[1];
        $right = $condition[2];

        switch ($op) {
            case '=':
                $value = $this->getRecordField($record, $left);
                return $value == $right;

            case '==':
                $value = $this->getRecordField($record, $left);
                return $value === $right;

            case '!=':
                $value = $this->getRecordField($record, $left);
                return $value != $right;

            case '!==':
                $value = $this->getRecordField($record, $left);
                return $value !== $right;

            case '<':
                $value = $this->getRecordField($record, $left);
                return $value < $right;

            case '>':
                $value = $this->getRecordField($record, $left);
                return $value > $right;

            default:
                throw new Exception('Operator ['.$op.'] is not supported');
        }
    }
1022478
public function deleteBy($condition = null)
	{
		if( !is_null($condition) )
		{
			$this->filterBy($condition);
		}
		$matched = $this->load();
		array_each(
			$matched,
			function($model)
			{ /** @var Lib_Model_Db $model */
				$model->delete();
			}
		);
		return !empty($matched);
	}
594620
private function prepareCondition($condition)
    {
        if (!is_array($condition)) {
            $condition = ['in' => [$condition]];
        }

        $conditionKeys = array_keys($condition);

        if (is_integer(current($conditionKeys))) {
            $condition = ['in' => $condition];
        }

        foreach ($condition as $key => $value) {
            if (!isset($this->mappedConditions[$key]) && !in_array($key, $this->rangeConditions)) {
                throw new \LogicException("Condition {$key} is not supported.");
            }

            if (isset($this->mappedConditions[$key])) {
                $condition[$this->mappedConditions[$key]] = $value;
                unset($condition[$key]);
            }

            if (in_array($key, $this->negativeConditions)) {
                $condition['negative'] = true;
            }
        }

        return $condition;
    }
1023166
public function one(string $condition = '', array $params = []) {
        $this->model->builder->select('*')
            ->from($this->model->tableName);
        if ($condition) {
            $this->model->builder->where($condition, $params);
        }
        $r = $this->model->builder->limit(1)
            ->query();
        if (!is_array($r) || 0 === count($r)) {
            return null;
        }
        return $this->model->setup($r[0]);
    }
241075
public function count($table, $condition = false, $group = false, $rows = false)
	{
        Eresus_Kernel::log(__METHOD__, LOG_NOTICE, 'This method is deprecated');
		$q = Eresus_DB::getHandler()->createSelectQuery();
		$e = $q->expr;

		$q->select($q->alias($e->count('*'), 'count'));
        $q->from($table);

		if ($condition)
		{
			$q->where($condition);
		}

		if ($group)
		{
			$q->groupBy($group);
		}

		$result = $q->fetchAll();
		if ($rows)
		{
			return count($result);
		}
		else
		{
			return intval($result[0]['count']);
		}
	}
1189628
public static function getListByCondition($condition = '', $params = [], $order = 'group_id desc', $page = 1, $pageSize = 20)
    {
        $pagination = new Pagination();
        $pagination->setPage($page);
        $pagination->setPageSize($pageSize);
        $pagination->totalCount = static::find()->andWhere($condition, $params)->count(1);
        $list = static::find()
            ->andWhere($condition, $params)
            ->offset($pagination->getOffset() - $pagination->getPageSize())
            ->limit($pagination->getPageSize())
            ->orderBy($order)
            ->asArray()
            ->all();

        return [
            'paginationObj' => $pagination,
            'pagination' => [
                'currentPage' => $page,
                'pageSize' => $pageSize,
                'pageCount' => $pagination->getPageCount(),
                'totalCount' => $pagination->totalCount,
            ],
            'list' => $list,
        ];
    }
690831
public function seek($condition = array(), $order=array()){
		$where = array();
		$orderBy = array();
		foreach ($condition as $key=>$value){
			if ($value!=NULL && is_object($value) && get_class($value)==NotSet::class){
				// nuevo. el campo no está establecido
			}else{
				$where[] = sprintf("`%s` = %s", $key, $this->getColumn($key)->sqlVal($value));
			}
		}
		foreach ($order as $key=>$value){
			$orderBy[] = sprintf("`%s` %s", $key, $value);
		}
		if (count($where)>0){
			$sWhere = " WHERE ".implode(' and ', $where);
		}else{
			$sWhere = "";
		}
		if (count($orderBy)>0){
			$sOrder = " ORDER BY ".implode(',', $orderBy);
		}else{
			$sOrder = "";
		}
		$sSql = sprintf("SELECT * FROM `%s` %s %s LIMIT 0,1", $this->getTableName(), $sWhere, $sOrder);
		$rows = $this->model->getRecords($sSql);
		if (count($rows)>0){
			return $this->fromRowToModelRow($rows[0]);
		}else{
			//return NULL;
			throw new \Exception("Registro no localizado");
		}
	}
1217526
public static function counts($condition = null, $params = null, $distinct=false) {
        return static::dao()->count(
            $condition,
            $params,
            $distinct
        );
    }