vendor/pimcore/pimcore/models/Document/Listing/Dao.php line 37

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace Pimcore\Model\Document\Listing;
  15. use Doctrine\DBAL\Query\QueryBuilder as DoctrineQueryBuilder;
  16. use Pimcore\Model;
  17. use Pimcore\Model\Document;
  18. use Pimcore\Model\Listing\Dao\QueryBuilderHelperTrait;
  19. /**
  20.  * @internal
  21.  *
  22.  * @property \Pimcore\Model\Document\Listing $model
  23.  */
  24. class Dao extends Model\Listing\Dao\AbstractDao
  25. {
  26.     use QueryBuilderHelperTrait;
  27.     /**
  28.      * Loads a list of objects (all are an instance of Document) for the given parameters an return them
  29.      *
  30.      * @return array
  31.      */
  32.     public function load()
  33.     {
  34.         $documents = [];
  35.         $select $this->getQueryBuilder(['documents.id''documents.type']);
  36.         $documentsData $this->db->fetchAllAssociative((string) $select$this->model->getConditionVariables(), $this->model->getConditionVariableTypes());
  37.         foreach ($documentsData as $documentData) {
  38.             if ($documentData['type']) {
  39.                 if ($doc Document::getById($documentData['id'])) {
  40.                     $documents[] = $doc;
  41.                 }
  42.             }
  43.         }
  44.         $this->model->setDocuments($documents);
  45.         return $documents;
  46.     }
  47.     /**
  48.      * @param string|string[]|null $columns
  49.      *
  50.      * @return DoctrineQueryBuilder
  51.      */
  52.     public function getQueryBuilder(...$columns): DoctrineQueryBuilder
  53.     {
  54.         $queryBuilder $this->db->createQueryBuilder();
  55.         $queryBuilder->select(...$columns)->from('documents');
  56.         $this->applyListingParametersToQueryBuilder($queryBuilder);
  57.         return $queryBuilder;
  58.     }
  59.     /**
  60.      * Loads a list of document ids for the specicifies parameters, returns an array of ids
  61.      *
  62.      * @return int[]
  63.      */
  64.     public function loadIdList()
  65.     {
  66.         $queryBuilder $this->getQueryBuilder(['documents.id']);
  67.         $documentIds $this->db->fetchFirstColumn((string) $queryBuilder$this->model->getConditionVariables(), $this->model->getConditionVariableTypes());
  68.         return array_map('intval'$documentIds);
  69.     }
  70.     /**
  71.      * @return array
  72.      */
  73.     public function loadIdPathList()
  74.     {
  75.         $queryBuilder $this->getQueryBuilder(['documents.id''CONCAT(documents.path, documents.key) as path']);
  76.         $documentIds $this->db->fetchAllAssociative((string) $queryBuilder$this->model->getConditionVariables(), $this->model->getConditionVariableTypes());
  77.         return $documentIds;
  78.     }
  79.     /**
  80.      * @return int
  81.      */
  82.     public function getCount()
  83.     {
  84.         if ($this->model->isLoaded()) {
  85.             return count($this->model->getDocuments());
  86.         } else {
  87.             $idList $this->loadIdList();
  88.             return count($idList);
  89.         }
  90.     }
  91.     /**
  92.      * @return int
  93.      */
  94.     public function getTotalCount()
  95.     {
  96.         $queryBuilder $this->getQueryBuilder();
  97.         $this->prepareQueryBuilderForTotalCount($queryBuilder'documents.id');
  98.         $amount = (int) $this->db->fetchOne((string) $queryBuilder$this->model->getConditionVariables(), $this->model->getConditionVariableTypes());
  99.         return $amount;
  100.     }
  101. }