|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* AnimeDb package. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Peter Gribanov <[email protected]> |
|
6
|
|
|
* @copyright Copyright (c) 2011, Peter Gribanov |
|
7
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 GPL v3 |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace AnimeDb\Bundle\AppBundle\Form\Type\Field\LocalPath; |
|
10
|
|
|
|
|
11
|
|
|
use Symfony\Component\Form\AbstractType; |
|
12
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
13
|
|
|
use AnimeDb\Bundle\AppBundle\Util\Filesystem; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Local path choice form. |
|
17
|
|
|
*/ |
|
18
|
|
|
class Choice extends AbstractType |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @param FormBuilderInterface $builder |
|
22
|
|
|
* @param array $options |
|
23
|
|
|
*/ |
|
24
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
|
25
|
|
|
{ |
|
26
|
|
|
$builder |
|
27
|
|
|
->add('path', 'text', [ |
|
28
|
|
|
'label' => 'Path', |
|
29
|
|
|
'required' => true, |
|
30
|
|
|
'attr' => [ |
|
31
|
|
|
'placeholder' => Filesystem::getUserHomeDir(), |
|
32
|
|
|
], |
|
33
|
|
|
]) |
|
34
|
|
|
->setMethod('GET'); |
|
35
|
|
|
|
|
36
|
|
|
// choice the disc letter in Windows |
|
37
|
|
|
if (defined('PHP_WINDOWS_VERSION_BUILD') && |
|
38
|
|
|
extension_loaded('com_dotnet') && |
|
39
|
|
|
($fs = new \COM('Scripting.FileSystemObject')) |
|
40
|
|
|
) { |
|
41
|
|
|
// types: Unknown, Removable, Fixed, Network, CD-ROM, RAM Disk |
|
42
|
|
|
$choices = []; |
|
43
|
|
|
foreach ($fs->Drives as $drive) { |
|
44
|
|
|
$drive = $fs->GetDrive($drive); |
|
45
|
|
|
if ($drive->DriveType == 3) { |
|
46
|
|
|
$name = $drive->Sharename; |
|
47
|
|
|
} elseif ($drive->IsReady) { |
|
48
|
|
|
$name = $drive->VolumeName; |
|
49
|
|
|
} else { |
|
50
|
|
|
$name = '[Drive not ready]'; |
|
51
|
|
|
} |
|
52
|
|
|
$choices[$drive->DriveLetter] = $drive->DriveLetter.': '.$name; |
|
53
|
|
|
} |
|
54
|
|
|
$builder->add('letter', 'choice', ['choices' => $choices]); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return string |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getName() |
|
62
|
|
|
{ |
|
63
|
|
|
return 'local_path_popup'; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|