vendor/pimcore/pimcore/models/Asset/Listing.php line 30

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\Asset;
  15. use Pimcore\Model;
  16. use Pimcore\Model\Paginator\PaginateListingInterface;
  17. /**
  18.  * @method Model\Asset[] load()
  19.  * @method Model\Asset current()
  20.  * @method int getTotalCount()
  21.  * @method int getCount()
  22.  * @method int[] loadIdList()
  23.  * @method \Pimcore\Model\Asset\Listing\Dao getDao()
  24.  * @method onCreateQueryBuilder(?callable $callback)
  25.  */
  26. class Listing extends Model\Listing\AbstractListing implements PaginateListingInterface
  27. {
  28.     /**
  29.      * @return Model\Asset[]
  30.      */
  31.     public function getAssets()
  32.     {
  33.         return $this->getData();
  34.     }
  35.     /**
  36.      * @param Model\Asset[] $assets
  37.      *
  38.      * @return static
  39.      */
  40.     public function setAssets($assets)
  41.     {
  42.         return $this->setData($assets);
  43.     }
  44.     /**
  45.      *
  46.      * Methods for AdapterInterface
  47.      */
  48.     /**
  49.      * @return int
  50.      */
  51.     public function count()
  52.     {
  53.         return $this->getTotalCount();
  54.     }
  55.     /**
  56.      * @param int $offset
  57.      * @param int $itemCountPerPage
  58.      *
  59.      * @return Model\Asset[]
  60.      */
  61.     public function getItems($offset$itemCountPerPage)
  62.     {
  63.         $this->setOffset($offset);
  64.         $this->setLimit($itemCountPerPage);
  65.         return $this->load();
  66.     }
  67.     /**
  68.      * @internal
  69.      *
  70.      * @param Model\User $user
  71.      *
  72.      * @return static
  73.      */
  74.     public function filterAccessibleByUser(Model\User $user)
  75.     {
  76.         if (!$user->isAdmin()) {
  77.             $userIds $user->getRoles();
  78.             $userIds[] = $user->getId();
  79.             $condition '(
  80.                 (SELECT list FROM users_workspaces_asset WHERE userId IN ('.implode(','$userIds).') AND LOCATE(CONCAT(path,filename),cpath)=1 ORDER BY LENGTH(cpath) DESC, FIELD(userId, '.$user->getId().') DESC, list DESC LIMIT 1)=1
  81.                 or
  82.                 (SELECT list FROM users_workspaces_asset WHERE userId IN ('.implode(','$userIds).') AND LOCATE(cpath,CONCAT(path,filename))=1 ORDER BY LENGTH(cpath) DESC, FIELD(userId, '.$user->getId().') DESC, list DESC LIMIT 1)=1
  83.             )';
  84.             $this->addConditionParam($condition);
  85.         }
  86.         return $this;
  87.     }
  88. }