Inheritance: extends Pimcore\Model\Listing\AbstractListing, implements Zend_Paginator_Adapter_Interface, implements Zend_Paginator_AdapterAggregate, implements Iterator
示例#1
0
 /**
  * @static
  * @param array $types
  * @return void
  */
 public static function assets($types = null)
 {
     if (empty($types)) {
         $types = array("folder", "image", "text", "audio", "video", "document", "archive", "unknown");
     }
     $list = new Asset\Listing();
     $list->setCondition("type IN ('" . implode("','", $types) . "')");
     self::loadToCache($list);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // get all thumbnails
     $dir = Asset\Image\Thumbnail\Config::getWorkingDir();
     $thumbnails = array();
     $files = scandir($dir);
     foreach ($files as $file) {
         if (strpos($file, ".xml")) {
             $thumbnails[] = str_replace(".xml", "", $file);
         }
     }
     $allowedThumbs = array();
     if ($input->getOption("thumbnails")) {
         $allowedThumbs = explode(",", $input->getOption("thumbnails"));
     }
     // get only images
     $conditions = array("type = 'image'");
     if ($input->getOption("parent")) {
         $parent = Asset::getById($input->getOption("parent"));
         if ($parent instanceof Asset\Folder) {
             $conditions[] = "path LIKE '" . $parent->getFullPath() . "/%'";
         } else {
             $this->writeError($input->getOption("parent") . " is not a valid asset folder ID!");
             exit;
         }
     }
     $list = new Asset\Listing();
     $list->setCondition(implode(" AND ", $conditions));
     $total = $list->getTotalCount();
     $perLoop = 10;
     for ($i = 0; $i < ceil($total / $perLoop); $i++) {
         $list->setLimit($perLoop);
         $list->setOffset($i * $perLoop);
         $images = $list->load();
         foreach ($images as $image) {
             foreach ($thumbnails as $thumbnail) {
                 if (empty($allowedThumbs) && !$input->getOption("system") || in_array($thumbnail, $allowedThumbs)) {
                     if ($input->getOption("force")) {
                         $image->clearThumbnail($thumbnail);
                     }
                     $this->output->writeln("generating thumbnail for image: " . $image->getFullpath() . " | " . $image->getId() . " | Thumbnail: " . $thumbnail . " : " . formatBytes(memory_get_usage()));
                     $this->output->writeln("generated thumbnail: " . $image->getThumbnail($thumbnail));
                 }
             }
             if ($input->getOption("system")) {
                 $thumbnail = Asset\Image\Thumbnail\Config::getPreviewConfig();
                 if ($input->getOption("force")) {
                     $image->clearThumbnail($thumbnail->getName());
                 }
                 $this->output->writeln("generating thumbnail for image: " . $image->getFullpath() . " | " . $image->getId() . " | Thumbnail: System Preview (tree) : " . formatBytes(memory_get_usage()));
                 $this->output->writeln("generated thumbnail: " . $image->getThumbnail($thumbnail));
             }
         }
         \Pimcore::collectGarbage();
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // disable versioning
     Version::disable();
     // get all thumbnails
     $thumbnails = [];
     $list = new Asset\Video\Thumbnail\Config\Listing();
     $items = $list->load();
     foreach ($items as $item) {
         $thumbnails[] = $item->getName();
     }
     $allowedThumbs = array();
     if ($input->getOption("thumbnails")) {
         $allowedThumbs = explode(",", $input->getOption("thumbnails"));
     }
     // get only images
     $conditions = array("type = 'video'");
     if ($input->getOption("parent")) {
         $parent = Asset::getById($input->getOption("parent"));
         if ($parent instanceof Asset\Folder) {
             $conditions[] = "path LIKE '" . $parent->getFullPath() . "/%'";
         } else {
             $this->writeError($input->getOption("parent") . " is not a valid asset folder ID!");
             exit;
         }
     }
     $list = new Asset\Listing();
     $list->setCondition(implode(" AND ", $conditions));
     $total = $list->getTotalCount();
     $perLoop = 10;
     for ($i = 0; $i < ceil($total / $perLoop); $i++) {
         $list->setLimit($perLoop);
         $list->setOffset($i * $perLoop);
         $videos = $list->load();
         foreach ($videos as $video) {
             foreach ($thumbnails as $thumbnail) {
                 if (empty($allowedThumbs) && !$input->getOption("system") || in_array($thumbnail, $allowedThumbs)) {
                     $this->output->writeln("generating thumbnail for video: " . $video->getFullpath() . " | " . $video->getId() . " | Thumbnail: " . $thumbnail . " : " . formatBytes(memory_get_usage()));
                     $video->getThumbnail($thumbnail);
                     $this->waitTillFinished($video->getId(), $thumbnail);
                 }
             }
             if ($input->getOption("system")) {
                 $this->output->writeln("generating thumbnail for video: " . $video->getFullpath() . " | " . $video->getId() . " | Thumbnail: System Preview : " . formatBytes(memory_get_usage()));
                 $thumbnail = Asset\Video\Thumbnail\Config::getPreviewConfig();
                 $video->getThumbnail($thumbnail);
                 $this->waitTillFinished($video->getId(), $thumbnail);
             }
         }
     }
 }
示例#4
0
$allowedThumbs = array();
if ($opts->getOption("thumbnails")) {
    $allowedThumbs = explode(",", $opts->getOption("thumbnails"));
}
// get only images
$conditions = array("type = 'image'");
if ($opts->getOption("parent")) {
    $parent = Asset::getById($opts->getOption("parent"));
    if ($parent instanceof Asset\Folder) {
        $conditions[] = "path LIKE '" . $parent->getFullPath() . "/%'";
    } else {
        echo $opts->getOption("parent") . " is not a valid asset folder ID!\n";
        exit;
    }
}
$list = new Asset\Listing();
$list->setCondition(implode(" AND ", $conditions));
$total = $list->getTotalCount();
$perLoop = 10;
for ($i = 0; $i < ceil($total / $perLoop); $i++) {
    $list->setLimit($perLoop);
    $list->setOffset($i * $perLoop);
    $images = $list->load();
    foreach ($images as $image) {
        foreach ($thumbnails as $thumbnail) {
            if (empty($allowedThumbs) && !$opts->getOption("system") || in_array($thumbnail, $allowedThumbs)) {
                if ($opts->getOption("force")) {
                    $image->clearThumbnail($thumbnail);
                }
                echo "generating thumbnail for image: " . $image->getFullpath() . " | " . $image->getId() . " | Thumbnail: " . $thumbnail . " : " . formatBytes(memory_get_usage()) . " \n";
                echo "generated thumbnail: " . $image->getThumbnail($thumbnail) . "\n";
示例#5
0
 /**
  * Get a list of the sibling assets
  *
  * @return array
  */
 public function getSiblings()
 {
     if ($this->siblings === null) {
         $list = new Asset\Listing();
         // string conversion because parentId could be 0
         $list->addConditionParam("parentId = ?", (string) $this->getParentId());
         $list->addConditionParam("id != ?", $this->getId());
         $list->setOrderKey("filename");
         $list->setOrder("asc");
         $this->siblings = $list->load();
     }
     return $this->siblings;
 }
示例#6
0
 public function assetThumbnailListAction()
 {
     // try to get the tag where the parent folder is specified
     $parentFolder = $this->document->getElement("parentFolder");
     if ($parentFolder) {
         $parentFolder = $parentFolder->getElement();
     }
     if (!$parentFolder) {
         // default is the home folder
         $parentFolder = Asset::getById(1);
     }
     // get all children of the parent
     $list = new Asset\Listing();
     $list->setCondition("path like ?", $parentFolder->getFullpath() . "%");
     $this->view->list = $list;
 }
 public function gridProxyAction()
 {
     if ($this->getParam("data")) {
         if ($this->getParam("xaction") == "update") {
             //TODO probably not needed
         }
     } else {
         $db = \Pimcore\Resource::get();
         // get list of objects
         $folder = Asset::getById($this->getParam("folderId"));
         $start = 0;
         $limit = 20;
         $orderKey = "id";
         $order = "ASC";
         if ($this->getParam("limit")) {
             $limit = $this->getParam("limit");
         }
         if ($this->getParam("start")) {
             $start = $this->getParam("start");
         }
         if ($this->getParam("dir")) {
             $order = $this->getParam("dir");
         }
         if ($this->getParam("sort")) {
             $orderKey = $this->getParam("sort");
             if ($orderKey == "fullpath") {
                 $orderKey = array("path", "filename");
             }
         }
         $conditionFilters = array();
         if ($this->getParam("only_direct_children") == "true") {
             $conditionFilters[] = "parentId = " . $folder->getId();
         } else {
             $conditionFilters[] = "path LIKE '" . ($folder->getFullPath() == "/" ? "/%'" : $folder->getFullPath() . "/%'");
         }
         $conditionFilters[] = "type != 'folder'";
         $filterJson = $this->getParam("filter");
         if ($filterJson) {
             $filters = \Zend_Json::decode($filterJson);
             foreach ($filters as $filter) {
                 $operator = "=";
                 if ($filter["type"] == "string") {
                     $operator = "LIKE";
                 } else {
                     if ($filter["type"] == "numeric") {
                         if ($filter["comparison"] == "lt") {
                             $operator = "<";
                         } else {
                             if ($filter["comparison"] == "gt") {
                                 $operator = ">";
                             } else {
                                 if ($filter["comparison"] == "eq") {
                                     $operator = "=";
                                 }
                             }
                         }
                     } else {
                         if ($filter["type"] == "date") {
                             if ($filter["comparison"] == "lt") {
                                 $operator = "<";
                             } else {
                                 if ($filter["comparison"] == "gt") {
                                     $operator = ">";
                                 } else {
                                     if ($filter["comparison"] == "eq") {
                                         $operator = "=";
                                     }
                                 }
                             }
                             $filter["value"] = strtotime($filter["value"]);
                         } else {
                             if ($filter["type"] == "list") {
                                 $operator = "=";
                             } else {
                                 if ($filter["type"] == "boolean") {
                                     $operator = "=";
                                     $filter["value"] = (int) $filter["value"];
                                 }
                             }
                         }
                     }
                 }
                 // system field
                 $value = $filter["value"];
                 if ($operator == "LIKE") {
                     $value = "%" . $value . "%";
                 }
                 $field = "`" . $filter["field"] . "` ";
                 if ($filter["field"] == "fullpath") {
                     $field = "CONCAT(path,filename)";
                 }
                 $conditionFilters[] = $field . $operator . " " . $db->quote($value);
             }
         }
         $list = new Asset\Listing();
         $condition = implode(" AND ", $conditionFilters);
         $list->setCondition($condition);
         $list->setLimit($limit);
         $list->setOffset($start);
         $list->setOrder($order);
         $list->setOrderKey($orderKey);
         $list->load();
         $assets = array();
         foreach ($list->getAssets() as $asset) {
             /** @var $asset Asset */
             $filename = PIMCORE_ASSET_DIRECTORY . "/" . $asset->getFullPath();
             $size = filesize($filename);
             $assets[] = array("id" => $asset->getid(), "type" => $asset->getType(), "fullpath" => $asset->getFullPath(), "creationDate" => $asset->getCreationDate(), "modificationDate" => $asset->getModificationDate(), "size" => formatBytes($size), "idPath" => $data["idPath"] = Element\Service::getIdPath($asset));
         }
         $this->_helper->json(array("data" => $assets, "success" => true, "total" => $list->getTotalCount()));
     }
 }
示例#8
0
 /**
  * @param $item \Pimcore\Model\Asset
  * @param int $nr
  * @return string
  * @throws \Exception
  */
 public static function getUniqueKey($item, $nr = 0)
 {
     $list = new Listing();
     $key = \Pimcore\File::getValidFilename($item->getKey());
     if (!$key) {
         throw new \Exception("No item key set.");
     }
     if ($nr) {
         if ($item->getType() == 'folder') {
             $key = $key . '_' . $nr;
         } else {
             $keypart = substr($key, 0, strrpos($key, '.'));
             $extension = str_replace($keypart, '', $key);
             $key = $keypart . '_' . $nr . $extension;
         }
     }
     $parent = $item->getParent();
     if (!$parent) {
         throw new \Exception("You have to set a parent folder to determine a unique Key");
     }
     if (!$item->getId()) {
         $list->setCondition('parentId = ? AND `filename` = ? ', [$parent->getId(), $key]);
     } else {
         $list->setCondition('parentId = ? AND `filename` = ? AND id != ? ', [$parent->getId(), $key, $item->getId()]);
     }
     $check = $list->loadIdList();
     if (!empty($check)) {
         $nr++;
         $key = self::getUniqueKey($item, $nr);
     }
     return $key;
 }