Get the total number of entities

@param KModelContext $context A model context object

@return string  The output of the view
199064
protected function _actionCount(KModelContext $context)
    {
        $context->query->columns('COUNT(*)');
        $context->query->table(array('tbl' => $this->getTable()->getName()));

        $this->_buildQueryJoins($context->query);
        $this->_buildQueryWhere($context->query);

        return $this->getTable()->count($context->query);
    }
1287518
public function fetchEntity(AnCommandContext $context)
    {
        $context->append(array(
            'identity_scope' => array(),
        ));

        $identifiable_key = $this->getIdentifiableKey();

        if ($values = $this->$identifiable_key) {
            $scope = AnConfig::unbox($context->identity_scope);

            $values = AnConfig::unbox($values);

            $scope[$identifiable_key] = $values;

            if (is_array($values)) {
                $mode = AnDomain::FETCH_ENTITY_SET;
            } else {
                $mode = AnDomain::FETCH_ENTITY;
            }

            $query = $this->getRepository()->getQuery();

            $query->where($scope);

            $entity = $this->getRepository()->fetch($query, $mode);

            if (empty($entity)) {
                $exception = new LibBaseControllerExceptionNotFound('Resource Not Found');

                //see if the entity exits or not
                if ($query->disableChain()->fetch()) {
                    if ($this->viewer && !$this->viewer->guest()) {
                        $exception = new LibBaseControllerExceptionForbidden('Forbidden');
                    } else {
                        $exception = new LibBaseControllerExceptionNotFound('Not Found');
                    }
                }

                throw $exception;
            }

            $this->setItem($entity);

            return $entity;
        }
    }
886880
public function count($mode = null)
    {
        if ($this->data == null) {
            $ret = $this->client->get($this->url, $this->query);
            $this->data = $ret->getData();
        }
        return (int) ($this->data['_total_items'] ?? $this->data['total_items'] ?? 0);
    }
1094944
protected function _afterEdit(KControllerContextInterface $context)
    {
        $name   = $this->getMixer()->getIdentifier()->name;

        foreach ($context->result as $entity)
        {
            if ($entity->getStatus() !== KDatabase::STATUS_FAILED)
            {
                if ($name === $this->_category_entity)
                {
                    if (($entity->old_enabled !== $entity->enabled) || ($entity->old_access !== $entity->access))
                    {
                        $category_context = 'com_'.$this->_package.'.'.$this->_category_entity;

                        $this->_getDispatcher()->trigger('onFinderAfterSave', array($category_context, $entity, false));
                    }
                } else {
                    $this->_getDispatcher()->trigger('onFinderAfterSave', array($this->_event_context, $entity, false));
                }
            }
        }
    }
1120161
protected function _getEntity(KModelEntityInterface $entity)
    {
        $method = '_get'.ucfirst($entity->getIdentifier()->name);

        if ($method !== '_getEntity' && method_exists($this, $method)) {
            $data = $this->$method($entity);
        } else {
            $data = $entity->toArray();
        }

        if (!empty($this->_fields)) {
            $data = array_intersect_key($data, array_merge(array('links' => 'links'), array_flip($this->_fields)));
        }

        if (!isset($data['links'])) {
            $data['links'] = array();
        }

        if (!isset($data['links']['self']))
        {
            $data['links']['self'] = array(
                'href' => (string) $this->_getEntityRoute($entity),
                'type' => 'application/json; version=1.0',
            );
        }

        return $data;
    }
459996
public function getIssuesCount (ContextSpecificationInterface $filter = null)
	{
		$count = count($this->issues);

		foreach ($this->getChildren($filter) as $child)
		{
			$count += $child->getIssuesCount($filter);
		}

		return $count;
	}
1363935
public function fetchEntity(AnCommandContext $context)
    {
        if ($context->action == 'addphoto') {
            if ($context->data->id) {
                $this->id = $context->data->id;
            }

            //clone the context so it's not touched
            $set = $this->__call('fetchEntity', array($context));

            if (!$set) {
                $context->setError(null);
                //if the action is addphoto and there are no sets then create an set
                $set = $this->add($context);
            }

            return $set;
        } else {
            return $this->__call('fetchEntity', array($context));
        }
    }
59083
public function getNumberOfElements(): ?int
    {
        $this->checkRepository();

        return $this->_em->createQueryBuilder()
            ->select('count(a)')
            ->from($this->getEntityName(), 'a')
            ->getQuery()
            ->getSingleScalarResult()
        ;
    }
1374676
final public function count()
    {
        if(!isset($this->_count))
        {
            $context = $this->getContext();
            $context->count = null;

            if ($this->invokeCommand('before.count', $context) !== false)
            {
                $context->count = $this->_actionCount($context);
                $this->invokeCommand('after.count', $context);
            }

            $this->_count = KObjectConfig::unbox($context->count);
        }

        return $this->_count;
    }
1329197
public function getSeoPageContext($context)
    {
        if (isset($this->seoPagesContext[$context])) {
            return $this->seoPagesContext[$context];
        }
        $contextTemplate = $this->findOneBy(['context' => $context]);

        if ($contextTemplate) {
            $this->seoPagesContext[$context] = $contextTemplate;

            return $this->seoPagesContext[$context];
        }

        return null;
    }
245369
private function getExtraWithContextMerged(array $context = [])
    {
        $extra = $this->getExtra();
        if (!empty($context)) {
            $extra = array_merge($extra, $context);
        }

        return $extra;
    }
395563
public function inContext($context)
    {
        $length = count($this->context);

        return $length < 2 ? false : $this->context[$length - 1] === $context;
    }
1216115
public function count()
    {
        $this->throwIfContextInvalid();

        $this->reloadQueryAdapter();
        $results = $this->activeQuery->fetch();

        $this->resetCurrentQuery();

        return count($results);
    }
416160
public function context($context = NULL)
	{
		if ( ! func_num_args())
		{
			return $this->_context;
		}
		$this->_context = $context;
		return $this;
	}
390429
protected function totalAmountResourceCallable()
    {
        return function () {
            $idKey = $this->getDataModel()->getKeyName();

            return $this->getDataModel()->query()->count([$idKey]);
        };
    }
833713
protected function _actionEdit(KControllerContextInterface $context)
    {
        if(!$context->result instanceof KModelEntityInterface) {
            $entities = $this->getModel()->fetch();
        } else {
            $entities = $context->result;
        }

        if(count($entities))
        {
            foreach($entities as $entity) {
                $entity->setProperties($context->request->data->toArray());
            }

            //Only set the reset content status if the action explicitly succeeded
            if($entities->save() === true) {
                $context->response->setStatus(KHttpResponse::RESET_CONTENT);
            }
        }
        else throw new KControllerExceptionResourceNotFound('Resource could not be found');

        return $entities;
    }
1187060
public function get_loaded_count( $exact = true ) {
		if ( ! $exact && ! isset( $this->_list ) ) {
			if ( ! isset( $this->_count ) ) {
				$this->_count = 0;
				foreach ( $this->get_namespaces() as $namespace ) {
					$this->_count += count( $this->app->utility->scan_dir_namespace_class( $this->namespace_to_dir( $namespace ) ) );
				}
			}

			return $this->_count;
		}

		return count( $this->get_class_list() );
	}