src/Document/Areabrick/Downloads.php line 40

Open in your IDE?
  1. <?php
  2. namespace App\Document\Areabrick;
  3. use Pimcore\Extension\Document\Areabrick\AbstractTemplateAreabrick;
  4. use Pimcore\Model\Document\Editable\Area\Info;
  5. class Downloads extends AbstractTemplateAreabrick
  6. {
  7.     public function action(Info $info)
  8.     {
  9.         $dateien = [];
  10.         if ( $info->getDocumentElement('downloads') ) {
  11.             $downies $info->getDocumentElement('downloads')->getData();
  12.             if ( $downies ) {
  13.                 foreach ( $downies as $key => $val ) {
  14.                     $tmp \Pimcore\Model\Asset::getByPath($val);
  15.                     //dd($tmp);
  16.                     $title $tmp->getMetadata("title");
  17.                     if ( $title == '' $title $tmp->getFilename();
  18.                     
  19.                     $mime explode('.',$tmp->getFilename());
  20.                     $mime strtoupper(end($mime));
  21.                     $type $tmp->getType();
  22.                     $dateien[$key]['title'] = $title;
  23.                     $dateien[$key]['type'] = $type;
  24.                     $dateien[$key]['mimetype'] = $mime;
  25.                     $dateien[$key]['bytes'] = $this->format_filesize($tmp->getFilesize());
  26.                     $dateien[$key]['path'] = $tmp;
  27.                 }
  28.             }
  29.         }
  30.         return $info->setParam('downloads'$dateien);
  31.     }
  32.     private function format_filesize($B$D=2){
  33.         $S 'kMGTPEZY';
  34.         $F floor((strlen($B) - 1) / 3);
  35.         return sprintf("%.{$D}f"$B/pow(1024$F)).' '.@$S[$F-1].'B';
  36.     }
  37.     
  38.     public function getName()
  39.     {
  40.         return 'Downloads';
  41.     }
  42.     public function getDescription()
  43.     {
  44.         return '';
  45.     }
  46.     public function getTemplateLocation()
  47.     {
  48.         return static::TEMPLATE_LOCATION_GLOBAL;
  49.     }
  50.     
  51.     public function needsReload(): bool
  52.     {
  53.         // optional
  54.         // here you can decide whether adding this bricks should trigger a reload
  55.         // in the editing interface, this could be necessary in some cases. default=false
  56.         return false;
  57.     }
  58.     // returns a custom html wrapper element (return an empty string if you don't want a wrapper element)
  59.     public function getHtmlTagOpen(Info $info)
  60.     {
  61.         return '';
  62.     }
  63.     public function getHtmlTagClose(Info $info)
  64.     {
  65.         return '';
  66.     }
  67. }