src/Twig/AppExtension.php line 151

Open in your IDE?
  1. <?php 
  2. namespace App\Twig;
  3. use Twig\Extension\AbstractExtension;
  4. use Pimcore\Model\Document;
  5. use Pimcore\Model\Site;
  6. use Twig\TwigFunction;
  7. use Symfony\Component\Intl\Countries;
  8. use Pimcore\Bundle\EcommerceFrameworkBundle\FilterService\ListHelper;
  9. use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\ProductList\ProductListInterface;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Twig\TwigFilter;
  12. use App\Model\DataObject\CategoryAlcoholType;
  13. use PHPExcel;
  14. use Carbon\Carbon;
  15. use ZipArchive;
  16. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  17. class AppExtension extends AbstractExtension
  18. {
  19.     private $filterService;
  20.     public function __construct(ListHelper $filterService) {
  21.         $this->filterService $filterService;
  22.     }
  23.     public function getFunctions()
  24.     {
  25.         return [
  26.             new TwigFunction('checkbox', [$this'renderCheckbox']),
  27.             new TwigFunction('addhttp', [$this'addhttp']),
  28.             new TwigFunction('getNavStartNode', [$this'getNavStartNode']),
  29.             new TwigFunction('setCookie', [$this'setCookie']),
  30.             new TwigFunction('getRegionBundle', [$this'getRegionBundle']),
  31.             new TwigFunction('getDigitalMarketingList', [$this'getDigitalMarketingList']),
  32.             new TwigFunction('getsubCategories', [$this'getsubCategories']),
  33.             new TwigFunction('getFilterDefinitions', [$this'getFilterDefinitions']),
  34.             new TwigFunction('getProductList', [$this'getProductList']),
  35.             new TwigFunction('basename', [$this'basenameFilter']),
  36.             new TwigFunction('getValueIndex', [$this'getValueIndex']),
  37.             new TwigFunction('getBrand', [$this'getBrand']),
  38.             new TwigFunction('numeric', [$this'isNumeric']),
  39.             new TwigFunction('get_object_vars', [$this'getObjectVars']),
  40.             new TwigFunction('getSort', [$this'sort']),
  41.             new TwigFunction('getValueIndex2', [$this'getValueIndex2']),
  42.             new TwigFunction('getFilterType', [$this'getFilterType']),
  43.             new TwigFunction('check_file_exists', [$this'check_file_exists']),
  44.             new TwigFunction('create_directory', [$this'create_directory']),
  45.             new TwigFunction('getDate', [$this'getDate']),
  46.             new TwigFunction('create_download_file', [$this'create_download_file']),
  47.             new TwigFunction('create_zip', [$this'create_zip']),
  48.             new TwigFunction('get_class_methods', [$this'getClassMethods']),
  49.             new TwigFunction('isInstanceof', [$this'isInstanceof']),
  50.             new TwigFunction('format_bytes', [$this'formatBytes']),
  51.             new TwigFunction('document_icon', [$this'getDocumentIcon']),
  52.         ];
  53.     }
  54.     /** @return array<int, TwigFilter> */
  55.     public function getFilters(): array
  56.     {
  57.         return [
  58.             new TwigFilter('int', function ($value) {
  59.                 return (int) $value;
  60.             }),
  61.             new TwigFilter('float', function ($value) {
  62.                 return (float) $value;
  63.             }),
  64.             new TwigFilter('string', function ($value) {
  65.                 return (string) $value;
  66.             }),
  67.             new TwigFilter('bool', function ($value) {
  68.                 return (bool) $value;
  69.             }),
  70.             new TwigFilter('array', function (object $value) {
  71.                 return (array) $value;
  72.             }),
  73.             new TwigFilter('object', function (array $value) {
  74.                 return (object) $value;
  75.             }),
  76.             new TwigFilter('range', function ($start$end$step 1) {
  77.                 return range($start$end$step);
  78.             }),
  79.             
  80.         ];
  81.     }
  82.     public function check_file_exists($file)
  83.     {
  84.         return file_exists($file);
  85.     }
  86.     public function create_directory($file)
  87.     {
  88.         return mkdir($file0777true);
  89.     }
  90.     public function getObjectVars($object)
  91.     {
  92.         return get_object_vars($object);
  93.     }
  94.     /**
  95.      * @var string $value
  96.      * @return string
  97.      */
  98.     public function basenameFilter($value$suffix '')
  99.     {
  100.        return basename($value$suffix);
  101.     }
  102.     public function renderCheckbox($name)
  103.     {
  104.         // return the HTML code for a checkbox with the given name
  105.         return '<input type="checkbox" name="' $name '">';
  106.     }
  107.     public function addhttp($url) {
  108.         if (!preg_match("~^(?:f|ht)tps?://~i"$url)) {
  109.             $url "https://" $url;
  110.         }
  111.         return $url;
  112.     }
  113.     public function getNavStartNode(): Document
  114.     {
  115.         if (Site::isSiteRequest()) {
  116.             $site Site::getCurrentSite();
  117.             return $site->getRootDocument();
  118.         } else {
  119.             return Document::getById(1);
  120.         }
  121.     }
  122.     public function setCookie($referal): void
  123.     {
  124.         $urlBaseName basename(parse_url($referalPHP_URL_PATH));
  125.         if ($urlBaseName !== 'sign-in') {
  126.             setcookie("isvalidemail"'false'2147483647'/');
  127.         }
  128.     }
  129.     public function getRegionBundle($countryName): string
  130.     {
  131.         return Countries::getName($countryName);
  132.     }
  133.     
  134.     public function getDigitalMarketingList($country): array
  135.     {
  136.         $list = new \Pimcore\Model\DataObject\DigitalMarketing\Listing();
  137.         $list->setOrderKey("name");
  138.         $list->setOrder("asc");
  139.         $list->setCondition(" `CountryAvailabilityList` LIKE '%" $country->getId() . "%'");
  140.         $list->setLimit(1);
  141.         return $list->getObjects();
  142.     }
  143.     public function getsubCategories(): array
  144.     {
  145.         $subCategories CategoryAlcoholType::getTopLevelCategories();
  146.         return $subCategories;
  147.     }
  148.     public function getFilterDefinitions(){
  149.         $filterDefinition2 \Pimcore\Model\DataObject\FilterDefinition::getByPath("/filter-definitions/default");
  150.         return $filterDefinition2;
  151.     }
  152.     public function getProductList($filterDefinition2,$request){
  153.         $params array_merge($request->query->all(), $request->attributes->all());
  154.         $products2 \Pimcore\Bundle\EcommerceFrameworkBundle\Factory::getInstance()->getIndexService()->getProductListForCurrentTenant();
  155.         $filterService2 \Pimcore\Bundle\EcommerceFrameworkBundle\Factory::getInstance()->getFilterService();                   
  156.         $this->filterService->setupProductList($filterDefinition2$products2$params,  $filterService2true);
  157.         $products2->setVariantMode(ProductListInterface::VARIANT_MODE_VARIANTS_ONLY);
  158.         return $products2;
  159.     }
  160.     public function getValueIndex($filterDefinition2,$products2)
  161.     {
  162.         $values= [];
  163.         $valuesIndex = array();
  164.         if (!empty($products2)) {
  165.             foreach ($filterDefinition2->getFilters() as $filter) {
  166.                 $rawValues $products2->getGroupByValues("parentCategoryids"true);
  167.                 foreach($rawValues as $v) {
  168.                   $values[$v['value']] = array('value' => $v['value'], "count" => $v['count']);
  169.                 }
  170.                 // resort values
  171.                 
  172.                 if ($values) {
  173.                   foreach($values as $entry){
  174.                     $ids explode(",",$entry['value']);
  175.                     foreach ($ids as $id) {
  176.                       if (!empty($id)) {
  177.                         if (array_key_exists($id$valuesIndex)) {
  178.                           $valuesIndex$id ] += $entry['count'];
  179.                         } else {
  180.                           $valuesIndex$id ] = $entry['count'];
  181.                         }
  182.                       }
  183.                     } 
  184.                   }
  185.                 }
  186.               } 
  187.         }
  188.         
  189.         return $valuesIndex;
  190.     }
  191.     public function getBrand($filteritem$brands$num$country){
  192.         if (is_numeric($filteritem) || preg_match('#[^A-Za-z0-9 ]#'$filteritem) === 1) {
  193.             if (!$num) {
  194.                 $num true;
  195.                 $brands->setCondition(" BrandName REGEXP '^[1-9|(|)]' AND `CountryAvailabilityList` LIKE '%" $country->getId() . "%'");
  196.                 $filteritem "[1-9]";
  197.             }
  198.         } else {
  199.             $brands->setCondition(" BrandName LIKE " $brands->quote($filteritem "%") . " AND `CountryAvailabilityList` LIKE '%" $country->getId() . "%'");
  200.         }
  201.         return $brands->load();
  202.     }
  203.     public function isNumeric($value)
  204.     {
  205.         return is_numeric($value);
  206.     }
  207.     public function sort($values){
  208.         @usort($values, function($left$right) {
  209.             $object \Pimcore\Model\DataObject\AbstractObject::getById($left["value"]);
  210.             if($object) {
  211.                 $nameLeft $object->getName();
  212.             }
  213.     
  214.             $object \Pimcore\Model\DataObject\AbstractObject::getById($right["value"]);
  215.             if($object) {
  216.                 $nameRight $object->getName();
  217.             }
  218.     
  219.             return strcmp($nameLeft$nameRight);
  220.     
  221.         });
  222.     
  223.         if(count($values) == 0) {
  224.             return;
  225.         }
  226.     }
  227.     public function getValueIndex2($values){
  228.         $valuesIndex = [];
  229.         foreach($values as $entry)
  230.             {
  231.                 $valuesIndex$entry['value'] ] = $entry['count'];
  232.             }
  233.             
  234.         return $valuesIndex;    
  235.     }
  236.     public function getFilterType() {
  237.         return \Pimcore\Bundle\EcommerceFrameworkBundle\FilterService\FilterType\AbstractFilterType::EMPTY_STRING;
  238.     }
  239.     function create_download_file($order) {
  240.         
  241.         $objPHPExcel = new Spreadsheet();
  242.         // Set properties
  243.         $objPHPExcel->getProperties()->setCreator("BeamSuntory");
  244.         $objPHPExcel->getProperties()->setLastModifiedBy("BeamSuntory");
  245.         $objPHPExcel->getProperties()->setTitle("Products Download");
  246.         $objPHPExcel->getProperties()->setSubject("Products Download");
  247.         $objPHPExcel->getProperties()->setDescription("Products Download");
  248.         $objPHPExcel->setActiveSheetIndex(0);
  249.         $objPHPExcel->getActiveSheet()->SetCellValue('A1''ObjectType');
  250.         $objPHPExcel->getActiveSheet()->SetCellValue('B1''Brand');
  251.         $objPHPExcel->getActiveSheet()->SetCellValue('C1''BrandExtensionName');
  252.         $objPHPExcel->getActiveSheet()->SetCellValue('D1''BrandExtensionNameTrademark');
  253.         $objPHPExcel->getActiveSheet()->SetCellValue('E1''BottleSize');
  254.         $objPHPExcel->getActiveSheet()->SetCellValue('F1''BrandExtensionDiscontinued');
  255.         $objPHPExcel->getActiveSheet()->SetCellValue('G1''Proof');
  256.         $objPHPExcel->getActiveSheet()->SetCellValue('H1''ABV');
  257.         $objPHPExcel->getActiveSheet()->SetCellValue('I1''ShortDescription');
  258.         $objPHPExcel->getActiveSheet()->SetCellValue('J1''FullDescription');
  259.         $objPHPExcel->getActiveSheet()->SetCellValue('K1''Aging');
  260.         $objPHPExcel->getActiveSheet()->SetCellValue('L1''BottlePhoto');
  261.         $objPHPExcel->getActiveSheet()->SetCellValue('M1''LifestylePhotoList');
  262.         $objPHPExcel->getActiveSheet()->SetCellValue('N1''OriginCountry');
  263.         $objPHPExcel->getActiveSheet()->SetCellValue('O1''OriginRegion');
  264.         $objPHPExcel->getActiveSheet()->SetCellValue('P1''AlcoholType');
  265.         $objPHPExcel->getActiveSheet()->SetCellValue('Q1''FlavoringType');
  266.         $objPHPExcel->getActiveSheet()->SetCellValue('R1''PricingSegment');
  267.         $objPHPExcel->getActiveSheet()->SetCellValue('S1''WhyBuy1');
  268.         $objPHPExcel->getActiveSheet()->SetCellValue('T1''WhyBuy2');
  269.         $objPHPExcel->getActiveSheet()->SetCellValue('U1''WhyBuy3');
  270.         $objPHPExcel->getActiveSheet()->SetCellValue('B1''WhyBuy4');
  271.         $objPHPExcel->getActiveSheet()->SetCellValue('W1''WhyBuy5');
  272.         $objPHPExcel->getActiveSheet()->SetCellValue('X1''WhyBuy6');
  273.         $objPHPExcel->getActiveSheet()->SetCellValue('Y1''WhyBuy7');
  274.         $objPHPExcel->getActiveSheet()->SetCellValue('Z1''WhyBuy8');
  275.         $objPHPExcel->getActiveSheet()->SetCellValue('AA1''Keywords1');
  276.         $objPHPExcel->getActiveSheet()->SetCellValue('AB1''Keywords2');
  277.         $objPHPExcel->getActiveSheet()->SetCellValue('AC1''Keywords3');
  278.         $objPHPExcel->getActiveSheet()->SetCellValue('AD1''Keywords4');
  279.         $objPHPExcel->getActiveSheet()->SetCellValue('AE1''Keywords5');
  280.         $objPHPExcel->getActiveSheet()->SetCellValue('AF1''Keywords6');
  281.         $objPHPExcel->getActiveSheet()->SetCellValue('AG1''Keywords7');
  282.         $objPHPExcel->getActiveSheet()->SetCellValue('AH1''Keywords8');
  283.         $objPHPExcel->getActiveSheet()->SetCellValue('AI1''Keywords9');
  284.         $objPHPExcel->getActiveSheet()->SetCellValue('AJ1''Keywords10');
  285.         $objPHPExcel->getActiveSheet()->SetCellValue('AK1''BSIID');
  286.         $objPHPExcel->getActiveSheet()->SetCellValue('AL1''modificationDate');
  287.         $objPHPExcel->getActiveSheet()->SetCellValue('AM1''creationDate');
  288.         
  289.         $counter 1;
  290.         foreach ($order->getItems() as $item) {
  291.             $counter++;
  292.             $product $item->getProduct();
  293.            
  294.             $this->create_excel_row($objPHPExcel$product"BrandExtension"$counter);
  295.             $sizeVariants $product->getSizeVariants();
  296.             if ($sizeVariants) {
  297.                 foreach($sizeVariants as $variant) {
  298.                     $counter++;
  299.                     $this->create_excel_row ($objPHPExcel$variant"BottleVariant"$counter);
  300.                 }
  301.             }
  302.         }
  303.         $objPHPExcel->getActiveSheet()->setTitle('Products Download');
  304.         //$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
  305.         $objWriter \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($objPHPExcel'Xlsx');
  306.         $objWriter->save($_SERVER['DOCUMENT_ROOT'] . "/downloads/excel/Products_Download_" $order->getId() . ".xls");
  307.         return $_SERVER['DOCUMENT_ROOT'] . "/downloads/excel/Products_Download_" $order->getId() . ".xls";
  308.     }
  309.     function create_excel_row($objPHPExcel,$product,$producttype,$counter) {
  310.         $brandname "";
  311.         $brandextname "";
  312.         $brandextensionnametrademark "";
  313.         $bottlesize "";
  314.         $BrandExtensionDiscontinued "";
  315.         $proof "";
  316.         $abv "";
  317.         $shortdesc "";
  318.         $fulldesc "";
  319.         $region  ="";
  320.         $country "";
  321.         $alcoholtype "";
  322.         $aging "";
  323.         $lifestylephotos "";
  324.         $bottlephotos "";
  325.         $bottleGTIN "";
  326.         $bottleBottleMaterial "";
  327.         $bottleBottleHeight "";
  328.         $bottleBottleWidth "";
  329.         $bottleBottleDepth "";
  330.         $bottleBottleWeight "";
  331.         $flv "";
  332.         $seg "";
  333.         if ($producttype == "BrandExtension") {
  334.             $brandextname $product->getBrandExtensionName();
  335.             $brandextensionnametrademark $product->getBrandExtensionNameTrademark();
  336.             $brand $product->getBrand();
  337.             if ($brand$brandname $brand[0]->getObject()->getBrandName();
  338.             if ($product->getBrandExtensionDiscontinued()) $BrandExtensionDiscontinued "1";
  339.             $proof $product->getProof();
  340.             $abv $product->getABV();
  341.             $shortdesc $product->getShortDescription();
  342.             $fulldesc $product->getFullDescription();
  343.             //Country Origin
  344.             $region $product->getOriginRegion();
  345.             $country $product->getOriginCountry(); 
  346.             $countrydic $product->getClass()->getFieldDefinition("OriginCountry")->getOptions();
  347.             
  348.             if (!empty($countrydic)) {
  349.                 foreach($countrydic as $countrydicitem) {
  350.                     if($countrydicitem['value']==$country) { $country $countrydicitem['key']; break;}
  351.                 }
  352.             }
  353.             
  354.             //Aging
  355.             $aging $product->getAging();
  356.             //Pricing Segment
  357.             $segs $product->getPricingSegment();
  358.             if ($segs) foreach ($segs as $seg) {break;}
  359.             if ($seg$seg $seg->getObject();
  360.             //Flavoring Type
  361.             $flvs $product->getFlavoringType();
  362.             if ($flvs) foreach ($flvs as $flv) {break;}
  363.             if ($flv$flv $flv->getObject();
  364.             if ($flv$flv $flv->getFlavoringType();
  365.             $categories $product->getCategories();
  366.             if ($categories) foreach ($categories as $category) {break;} 
  367.             if ($category$alcoholtype $category->getAlcoholType();
  368.             //Get all the lifesize
  369.             if ($product->getLifestylePhotoList()) {
  370.                 foreach($product->getLifestylePhotoList()->getItems() as $item) { 
  371.                     if (!empty($lifestylephotos)) $lifestylephotos .= ",";
  372.                     $lifestylephotos .= $item->getPhotoLifestyle()->getFullPath();
  373.                 }
  374.             }
  375.         } else {
  376.             $bottlesize $product->getBottleSize();
  377.             //Get all the bottle-size photos
  378.             $bottlephoto $product->getBottlePhoto();
  379.             if ($bottlephoto$bottlephotos $bottlephoto->getFullPath();
  380.         }
  381.         $objPHPExcel->getActiveSheet()->SetCellValue('A' $counter$producttype);
  382.         $objPHPExcel->getActiveSheet()->SetCellValue('B' $counter$brandname);
  383.         $objPHPExcel->getActiveSheet()->SetCellValue('C' $counter$brandextname);
  384.         $objPHPExcel->getActiveSheet()->SetCellValue('D' $counter$brandextensionnametrademark);
  385.         $objPHPExcel->getActiveSheet()->SetCellValue('E' $counter$bottlesize);
  386.         $objPHPExcel->getActiveSheet()->SetCellValue('F' $counter$BrandExtensionDiscontinued);
  387.         $objPHPExcel->getActiveSheet()->SetCellValue('G' $counter,  $proof);
  388.         $objPHPExcel->getActiveSheet()->SetCellValue('H' $counter$abv);
  389.         $objPHPExcel->getActiveSheet()->SetCellValue('I' $counter$shortdesc);
  390.         $objPHPExcel->getActiveSheet()->SetCellValue('J' $counter$fulldesc);
  391.         $objPHPExcel->getActiveSheet()->SetCellValue('K' $counter$aging);
  392.         $objPHPExcel->getActiveSheet()->SetCellValue('L' $counter$bottlephotos);
  393.         $objPHPExcel->getActiveSheet()->SetCellValue('M' $counter$lifestylephotos);
  394.         $objPHPExcel->getActiveSheet()->SetCellValue('N' $counter$country);
  395.         $objPHPExcel->getActiveSheet()->SetCellValue('O' $counter$region);
  396.         $objPHPExcel->getActiveSheet()->SetCellValue('P' $counter$alcoholtype);
  397.         $objPHPExcel->getActiveSheet()->SetCellValue('Q' $counter$flv);
  398.         $objPHPExcel->getActiveSheet()->SetCellValue('R' $counter$seg);
  399.         $buyAlpha = array("S","T","U","V","W","X","Y","Z");
  400.         for($i=1;$i<=8;$i++) {
  401.             if ($producttype == "BrandExtension") {
  402.                 $whybuy "getWhyBuy" $i;
  403.                 $whybuys $product->$whybuy();
  404.                 if (is_null($whybuys)) {
  405.                     $whybuys "";
  406.                 }
  407.                 $objPHPExcel->getActiveSheet()->SetCellValue($buyAlpha[$i-1] . $counter$whybuys);
  408.             } else {
  409.                 $objPHPExcel->getActiveSheet()->SetCellValue($buyAlpha[$i-1] . $counter"");
  410.             }
  411.         }
  412.         $keyAlpha = array("A","B","C","D","E","F","G","H","I","J");
  413.         for($i=1;$i<=10;$i++) {
  414.             if ($producttype == "BrandExtension") {
  415.                 $keyword "getKeywords" $i;
  416.                 $kwords $product->$keyword();
  417.                 if (is_null($kwords)) {
  418.                     $keywords "";
  419.                 }
  420.                 $objPHPExcel->getActiveSheet()->SetCellValue('A'$keyAlpha[$i-1] . $counter$kwords);
  421.             } else {
  422.                 $objPHPExcel->getActiveSheet()->SetCellValue('A'$keyAlpha[$i-1] . $counter"");
  423.             }
  424.         }
  425.         
  426.         $objPHPExcel->getActiveSheet()->SetCellValue('AK' $counter$product->getId());
  427.         $create_date Carbon::createFromTimestamp($product->getcreationDate());
  428.         $create_date $create_date->format("YYYY/MM/dd");
  429.         $modify_date Carbon::createFromTimestamp($product->getmodificationDate());
  430.         $modify_date $modify_date->format("YYYY/MM/dd");
  431.         $objPHPExcel->getActiveSheet()->SetCellValue('AL' $counter$modify_date);
  432.         $objPHPExcel->getActiveSheet()->SetCellValue('AM' $counter$create_date);
  433.     }
  434.     public function getDate($date) {
  435.         return  Carbon::instance($date);
  436.     }
  437.     /**
  438.      * @param $var
  439.      * @param $instance
  440.      * @return bool
  441.      */
  442.     public function isInstanceof($var$instance) {
  443.         return  $var instanceof $instance;
  444.     }
  445.     function create_zip($files = array(),$destination '',$overwrite false) {
  446.         //if the zip file already exists and overwrite is false, return false
  447.         if(file_exists($destination)) { 
  448.             $overwrite true
  449.         } else {
  450.             $overwrite false
  451.         }
  452.         //vars
  453.         $valid_files = array();
  454.         //if files were passed in...
  455.         if(is_array($files)) {
  456.             //cycle through each file
  457.             foreach($files as $file) {
  458.                 //make sure the file exists
  459.                 if (preg_match('#excel#'$file) !== 1) {
  460.                     $file $_SERVER['DOCUMENT_ROOT'] . "/website/var/assets" $file;
  461.                 } 
  462.                 if(file_exists($file)) {
  463.                     $valid_files[] = $file;
  464.                 }
  465.             }
  466.         }
  467.            //if we have good files...
  468.         if(count($valid_files)) {
  469.             //create the archive
  470.             $zip = new ZipArchive();
  471.             if($zip->open($destination,$overwrite ZIPARCHIVE::OVERWRITE ZIPARCHIVE::CREATE) !== true) {
  472.                 return false;
  473.             }
  474.             //add the files
  475.             foreach($valid_files as $file) {
  476.                 $new_filename substr($file,strrpos($file,'/') + 1);
  477.                 if (preg_match('#bottle-photos#'$file) === 1) {
  478.                     $new_filename "/product-media/bottle-photos/" $new_filename;
  479.                 } else if (preg_match('#lifestyle-photos#'$file) === 1) {
  480.                     $new_filename "/product-media/lifestyle-photos/" $new_filename;
  481.                 }
  482.                 $zip->addFile($file,$new_filename);
  483.             }
  484.             //debug
  485.             //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
  486.             
  487.             //close the zip -- done!
  488.             $zip->close();
  489.             
  490.             //check to make sure the file exists
  491.             return file_exists($destination);
  492.         }
  493.         else
  494.         {
  495.             return false;
  496.         }
  497.     }
  498.     public function getClassMethods($object){
  499.         return get_class_methods($object);
  500.     }
  501.     public function formatBytes($bytes$precision 2)
  502.     {
  503.         if ($bytes 1024) {
  504.             return $bytes.' B';
  505.         } elseif ($bytes 1048576) {
  506.             return round($bytes 1024$precision).' KB';
  507.         } elseif ($bytes 1073741824) {
  508.             return round($bytes 1048576$precision).' MB';
  509.         } else {
  510.             return round($bytes 1073741824$precision).' GB';
  511.         }
  512.     }
  513.     public function getDocumentIcon($mimeType)
  514.     {
  515.         // Mapping MIME types to Font Awesome icon classes
  516.         $icons = [
  517.             'application/pdf' => 'fas fa-file-pdf',
  518.             'application/msword' => 'fas fa-file-word',
  519.             'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'fas fa-file-word',
  520.             'application/vnd.ms-excel' => 'fas fa-file-excel',
  521.             'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'fas fa-file-excel',
  522.             'application/vnd.ms-powerpoint' => 'fas fa-file-powerpoint',
  523.             'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'fas fa-file-powerpoint',
  524.             'text/plain' => 'fas fa-file-alt',
  525.             'image/jpeg' => 'fas fa-file-image',
  526.             'image/png' => 'fas fa-file-image',
  527.             'application/zip' => 'fas fa-file-archive',
  528.             'application/x-rar-compressed' => 'fas fa-file-archive',
  529.             // Add more MIME types and corresponding icons as needed
  530.         ];
  531.         return $icons[$mimeType] ?? 'fas fa-file'// Default icon
  532.     }
  533. }