Neos\ContentRepository\Domain\Repository\NodeDataRepository::countByWorkspace PHP Метод

countByWorkspace() публичный Метод

Note: Also counts removed nodes
public countByWorkspace ( Workspace $workspace ) : integer
$workspace Neos\ContentRepository\Domain\Model\Workspace The containing workspace
Результат integer The number of nodes found
    public function countByWorkspace(Workspace $workspace)
    {
        $query = $this->createQuery();
        $nodesInDatabase = $query->matching($query->equals('workspace', $workspace))->execute()->count();
        $nodesInMemory = 0;
        /** @var $node NodeData */
        foreach ($this->addedNodes as $node) {
            if ($node->getWorkspace()->getName() === $workspace->getName()) {
                $nodesInMemory++;
            }
        }
        return $nodesInDatabase + $nodesInMemory;
    }

Usage Example

 /**
  * Returns the number of nodes in this workspace.
  *
  * If $includeBaseWorkspaces is enabled, also nodes of base workspaces are
  * taken into account. If it is disabled (default) then the number of nodes
  * is the actual number (+1) of changes related to its base workspaces.
  *
  * A node count of 1 means that no changes are pending in this workspace
  * because a workspace always contains at least its Root Node.
  *
  * @return integer
  * @api
  */
 public function getNodeCount()
 {
     return $this->nodeDataRepository->countByWorkspace($this);
 }