IsoImageSelect.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\VmCreate\Fields;
  3. use MGProvision\Proxmox\v2\repository\FileRepository;
  4. use MGProvision\Proxmox\v2\repository\StorageRepository;
  5. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  6. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  7. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
  8. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\AjaxFields\Select;
  9. class IsoImageSelect extends Select implements ClientArea
  10. {
  11. use ProductService;
  12. use ApiService;
  13. public function prepareAjaxData()
  14. {
  15. session_write_close();
  16. //default node
  17. if($this->getRequestValue('location')){
  18. $defaultNode = $this->getRequestValue('location');
  19. }else{
  20. $defaultNode = $this->getNode()->getNode();
  21. }
  22. $storageRepository = new StorageRepository();
  23. $storageRepository->findByNodes([$defaultNode])
  24. ->findEnabed();
  25. $storages = $storageRepository->fetchAsArray();
  26. $isoRepository = new FileRepository();
  27. $isoRepository->findByNodes([$defaultNode])
  28. ->findByStorages($storages);
  29. $isoRepository->findIso();
  30. foreach ($isoRepository->fetch() as $entity)
  31. {
  32. if ($this->configuration()->isPermissionIsoImages() && !in_array($entity->getVolid(), $this->configuration()->getPermissionIsoImages()))
  33. {
  34. continue;
  35. }
  36. $this->availableValues[]=[
  37. "key" => $entity->getVolid(),
  38. "value" => $entity->getFriendlyName(),
  39. ];
  40. }
  41. }
  42. }