Symfony - VALIDACIÓN "NO ME GUARDA"

 
Vista:
sin imagen de perfil

VALIDACIÓN "NO ME GUARDA"

Publicado por Manuel (1 intervención) el 28/03/2017 20:10:33
En la excepción cuando recibe el id que en realidad existe no me dice nada (es decir que si valida pero NUNCA guarda) y cuando escribo un id que no existe me manda el error (osea que no existe)
EL PUNTO SOLO ES ESE QUE NO ME GUARDA EL REGISTRO
SI YA VERIFICO QUE NO EXISTE PORQUE NO LO GUARDA?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
 
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;
 
class CreateVacancyCommand extends Command
{
    private $input;
    private $output;
    private $pais;
    private $faker;
    private $title = '';
    private $description = '';
    private $idOfCompany = 1;
    private $vacante;
 
    protected function configure()
    {
        $this
            ->setName('app:create-vacancy')
            ->setDescription('Creates new vacancies')
            ->setHelp("This command allows you to create new vacancies into test.jobomas.com")
            ->addOption('countryAbrev',
                'c',
                InputOption::VALUE_REQUIRED,
                'Set the country Abreviation for the companies')
            ->addOption('numberOfCompany',
                'e',
                InputArgument::OPTIONAL,
                'Set the company id to create a vacancy')
            ->addOption('title',
                't',
                InputArgument::OPTIONAL,
                'Set the title for the vacancy')
            ->addOption('description',
                'd',
                InputArgument::OPTIONAL,
                'Set the description for the vacancy');
    }
 
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->input = $input;
        $this->output = $output;
        $io = new SymfonyStyle($input, $output);
        $this->idOfCompany = '';
        $this->title = '';
        $this->description = '';
        $countryAbrev = $this->getCountryAbrev();
        $company = $this->getCompany();
        $noInteraction = $this->getNoInteractiveMode();
        if (!empty($noInteraction)) {
            $this->idOfCompany = $this->getIdCompany();
            $this->title = $this->getTitleArg();
            $this->description = $this->getDescriptionArg();
        } else {
            list($countryAbrev, $company, $this->idOfCompany, $this->title, $this->description)
                = $this->getInteractiveMode($input, $output, $io);
        }
        if (empty($countryAbrev)) {
            $io->caution('You must set the countryAbrev option');
            return;
        }
        $results = [];
        $pais = $this->getLocalInformation($countryAbrev);
        $infoCompany = $this->getInformationCompanies($company);
 
            $vac = $this->createVacante($pais, $infoCompany, $this->title, $this->description);
 
        if ($vac) {
            $results[] = 'Name of Vacante: ' . $this->title . ' Description: ' . $this->description;
        }
        if (!empty($results)) {
            $io->success($results);
        }
    }
 
    private function getLocalInformation($countryAbrev)
    {
        $this->pais = PaisEmpresa::find_by_abreviatura($countryAbrev);
        if (!empty($this->pais)) {
            $lang = strtolower($this->pais->lang);
            $lang = $lang == 'sp' ? 'es' : $lang;
            $lang = $lang == 'po' ? 'pt' : $lang;
            $lang = $lang . '_' . strtoupper($lang);
            $this->faker = Faker\Factory::create($lang);
        } else {
            throw new Exception("Invalid country Abreviation", 1);
        }
        return $this->pais;
    }
 
    private function getInformationCompanies($company)
    {
        $this->idOfCompany = Empresa::find_by_id($company);
        if (!empty($this->idOfCompany)) {
            $this->vacante = Vacante::nuevoRegistro();
        } else {
            throw new Exception("Company Non-existent", 1);
        }
        return $this->idOfCompany;
    }
 
    private function getInteractiveMode($input, $output, $io)
    {
        $helper = $this->getHelper('question');
        $io->title('<options=bold;fg=blue>PAIS DE LA INFORMACION A PROPORCIONAR</>');
        $countryAbrevQuestion = new Question('Set the country for the company[mx]: ',
            'mx');
        $countryAbrev = trim($helper->ask($input, $output, $countryAbrevQuestion));
        $io->title('<options=bold;fg=blue>CREACION DE VACANTE</>');
        $idOfCompanyQuestion = new Question('Set Id of Company to create Vacancy: ',
            1, '/^[0-9]{1,}$/');
        $idOfCompany = $helper->ask($input, $output, $idOfCompanyQuestion);
        $titleQuestion = new Question('Set a title for the vacancy: ', '');
        $title = $helper->ask($input, $output, $titleQuestion);
        $descriptionQuestion = new Question('Set a description for the vacancy: ', '');
        $description = $helper->ask($input, $output, $descriptionQuestion);
        return [$countryAbrev, $idOfCompany, $title, $description];
    }
 
    private function createVacante()
    {
        //$this->vacante = new Vacante();
        $this->title = trim($this->title);
        $this->description = trim($this->description);
        $numero = range(1, 10);
        $edad = range(18, 60);
        $this->vacante->nombre_del_puesto = !empty($this->title) ? $this->title : $this->faker->jobTitle;
        $this->vacante->idempresas = $this->idOfCompany;
        $this->vacante->idpaises = $this->pais->id;
        $this->vacante->empresa = Empresa::find_by_id('nombre');
        //$vacante->idprovincia = PaisEmpresa::getProvinciasByIdPais($this->pais->id);
        $this->vacante->vacantes = $numero[array_rand($numero)];
        $this->vacante->descripcion_del_aviso = !empty($this->description) ? $this->description : $this->faker->realText;
        $this->vacante->email = $this->faker->email;
        $this->vacante->fecha_de_publicacion = date('Y-m-d');
        $this->vacante->edad_requerida = $edad[array_rand($edad)];
        $this->vacante->lugar_de_residencia_requerido = utf8_decode($this->faker->city);
        $this->vacante->orden = utf8_decode($this->faker->word);
        try {
            $this->vacante->save(false);
            $success = $this->vacante;
        } catch (Exception $e) {
            trigger_error($e->getMessage(), E_USER_ERROR);
        }
        return $success;
    }
 
    private function getIdCompany()
    {
        return $this->input->getOption('numberOfCompany');
    }
 
    private function getNoInteractiveMode()
    {
        return $this->input->getOption("no-interaction");
    }
 
    private function getCountryAbrev()
    {
        return $this->input->getOption('countryAbrev');
    }
 
    private function getCompany()
    {
        return $this->input->getOption('numberOfCompany');
    }
 
    private function getTitleArg()
    {
        return $this->input->getOption('title');
    }
 
    private function getDescriptionArg()
    {
        return $this->input->getOption('description');
    }
}


Seleccion_002
Seleccion_001
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder