public function create()
 {
     $descricoes = $this->request->getPost('descricao');
     $nomes = $this->request->getPost('nomes');
     $id_projeto = $this->request->getPost('projeto_id');
     $anexo_ids = [];
     foreach ($this->request->getUploadedFiles() as $i => $file) {
         $anexo = new Anexo();
         $anexo->setDescricao($descricoes[$i]);
         $anexo->setNome($nomes[$i]);
         $anexo->setOriginal($file->getName());
         $anexo->setCaminho(UPLOAD_PATH);
         if (!$anexo->validation() || !$anexo->save()) {
             throw new \Exception(PostResponse::createModelErrorMessages($anexo), StatusCodes::ERRO_CLI);
         }
         $novoNome = UPLOAD_PATH . "anexo_" . $anexo->getId() . "." . $file->getExtension();
         $anexo->setCaminho($novoNome);
         $anexo->save();
         $projeto_anexo = new ProjetoAnexos();
         $projeto_anexo->setIdAnexo($anexo->getId());
         $projeto_anexo->setIdProjeto($id_projeto);
         if (!$projeto_anexo->save()) {
             throw new \Exception(PostResponse::createModelErrorMessages($projeto_anexo), StatusCodes::ERRO_CLI);
         }
         $anexo_ids[] = $anexo->getId();
         $file->moveTo($novoNome);
     }
     return PostResponse::createResponse(true, count($anexo_ids) . " anexos adicionados com sucesso");
 }
Example #2
0
 public function getAnexos()
 {
     $query = ProjetoAnexos::query()->columns(['id_anexo as id', 'nome', 'descricao', 'caminho', 'original'])->join('wsGerProj\\Models\\Anexo')->where('id_projeto = :id_projeto:')->bind(['id_projeto' => $this->getId()]);
     return $query->execute();
 }