public function createFile(array $data)
 {
     $project = $this->repository->skipPresenter()->find($data['project_id']);
     $projectFile = $project->files()->create($data);
     $arquivo = $projectFile->id . "." . $data['extension'];
     \Storage::put($arquivo, \File::get($data['file']));
 }
 public function createFile(array $data)
 {
     $project = $this->repository->skipPresenter()->find($data['project_id']);
     //dd($project);
     $projectFile = $project->files()->create($data);
     $this->storage->put($projectFile->id . "." . $data['extension'], $this->filesystem->get($data['file']));
 }
예제 #3
0
 private function checkProjectPermissions($projectId)
 {
     $this->repository->skipPresenter(true);
     if ($this->checkProjectOwner($projectId) or $this->checkProjectMember($projectId)) {
         $this->repository->skipPresenter(false);
         return true;
     }
     return false;
 }
예제 #4
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $user_id = \Authorizer::getResourceOwnerId();
     $project_id = $request->project;
     $projects = $this->repository->skipPresenter()->findWhere(['id' => $project_id, 'owner_id' => $user_id]);
     if (count($projects) == false) {
         return ['error' => 'Access forbidden'];
     }
     return $next($request);
 }
 public function create(array $data)
 {
     try {
         $this->validator->with($data)->passesOrFail();
         $project = $this->projectRepository->skipPresenter()->find($data['project_id']);
         $projectTask = $project->tasks()->create($data);
         return $projectTask;
     } catch (ValidatorException $e) {
         return ['error' => true, 'message' => $e->getMessageBag()];
     }
 }
 /**
  * @param array $data
  *
  * @return array
  * @throws \Prettus\Validator\Exceptions\ValidatorException
  */
 public function create(array $data)
 {
     try {
         $this->validator->with($data)->passesOrFail(ValidatorInterface::RULE_CREATE);
         $project = $this->projectRepository->skipPresenter()->find($data['project_id']);
         $projectFile = $project->files()->create($data);
         $this->storage->put($projectFile->id . '.' . $data['extension'], $this->filesystem->get($data['file']));
         return $projectFile;
     } catch (ValidatorException $e) {
         return ['error' => true, 'message' => $e->getMessageBag()];
     }
 }
예제 #7
0
 public function deleteFile($project_id, $file_id)
 {
     $project = $this->repository->skipPresenter()->find($project_id);
     if ($project) {
         $projectFile = $project->files->find($file_id);
         if ($projectFile) {
             $this->storage->delete($projectFile->id . '.' . $projectFile->extension);
             $projectFile->delete($file_id);
         } else {
             return ['error' => true, 'message' => 'Arquivo não encontrado'];
         }
     }
 }
 public function create(array $data)
 {
     try {
         $this->fileValidator->with($data)->passesOrFail();
         $project = $this->projectRepository->skipPresenter()->find($data['project_id']);
         $projectFile = $project->files()->create($data);
         $this->storage->put($projectFile->getFileName(), $this->fileSystem->get($data['file']));
         return ['error' => false, 'message' => 'Arquivo inserido com sucesso!'];
     } catch (ValidatorException $e) {
         $error = $e->getMessageBag();
         return ['error' => true, 'message' => "Erro ao enviar o arquivo, alguns campos são obrigatórios!", 'messages' => $error->getMessages()];
     }
 }
 public function deleteFile($idProject, $idFile)
 {
     try {
         // $projectFile = $this->repository->skipPresenter()->with(['files'])->find($idFile);
         /*
          * Busco o File do project e acesso o files que está relacionando no Project buscando o file
          */
         $projectFile = $this->repository->skipPresenter()->find($idProject)->files()->find($idFile);
         //pega no nome do arquivo e extensão para deletar da pasta
         $nomeFile = $idFile . "." . $projectFile->extension;
         //deleta da pasta
         $this->filesystem->delete($nomeFile);
         //return response()->json(['error' => false,'message' => "ProjectFile {$idFile} deleted"]);
     } catch (ModelNotFoundException $ex) {
         return $this->notFound($idFile);
     }
     //deleta o file da tabela
     try {
         $this->repository->skipPresenter()->find($idProject)->files()->detach($idFile);
     } catch (ModelNotFoundException $e) {
         try {
             $this->repository->skipPresenter()->find($idProject)->files()->detach($idFile);
             return response()->json(['error' => false, 'message' => "ProjectFile {$idFile} deleted"]);
         } catch (ModelNotFoundException $e) {
             return response()->json(['error' => true, 'message' => "ProjectFile {$idFile} not found"]);
         }
     }
 }
 public function create(array $data)
 {
     // diversos serviços
     // enviar email
     // disparar notificacao
     try {
         //dd($data);
         $this->validator->with($data)->passesOrFail(ValidatorInterface::RULE_CREATE);
         $project = $this->projectRepository->skipPresenter()->find($data['project_id']);
         $projectFile = $project->files()->create($data);
         $this->storage->put($projectFile->getFileName(), $this->filesystem->get($data['file']));
         return $projectFile;
     } catch (ValidatorException $e) {
         return ['error' => true, 'message' => $e->getMessageBag()];
     }
 }
 /**
  * @param $projectId
  *
  * @return array
  */
 public function showMembers($projectId)
 {
     try {
         return $this->repository->skipPresenter()->find($projectId)->members;
     } catch (ValidatorException $e) {
         return ['error' => true, 'message' => $e->getMessageBag()];
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $project = $this->repository->find($id);
     if ($project) {
         $files = $this->repository->skipPresenter()->find($id)->files;
         foreach ($files as $file) {
             $this->fileService->delete($id, $file->id);
         }
         if ($this->repository->delete($id)) {
             return ['success' => true];
         } else {
             return ['success' => false];
         }
     } else {
         return ['success' => false, 'msg' => "Project not found!"];
     }
 }
예제 #13
0
 public function removeMember(array $data)
 {
     try {
         $project = $this->repositoy->skipPresenter()->find($data['id']);
         $user = $this->user->find($data['$memberId']);
         $project->members()->detach($user);
     } catch (\Exception $e) {
         return ['error' => true, 'message' => $e->getMessage()];
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     try {
         $this->repository->skipPresenter()->find($id)->delete();
     } catch (QueryException $e) {
         return $this->erroMsgm('Projeto não pode ser apagado pois existe um ou mais clientes vinculados a ele.');
     } catch (ModelNotFoundException $e) {
         return $this->erroMsgm('Projeto não encontrado.');
     } catch (NoActiveAccessTokenException $e) {
         return $this->erroMsgm('Usuário não está logado.');
     } catch (\Exception $e) {
         return $this->erroMsgm('Ocorreu um erro ao excluir o projeto.');
     }
 }
예제 #15
0
 public function deleteFile($project_id, $file_id)
 {
     try {
         $project = $this->repository->skipPresenter()->find($project_id);
         $file = $project->files->find($file_id);
         if ($file) {
             $file->delete();
             $this->storage->delete($file_id . '.jpg');
         } else {
             return array('error' => 'true', 'message' => 'File does not exist');
         }
     } catch (ModelNotFoundException $e) {
         return ['error' => true, 'message' => $e->getMessage()];
     }
 }
예제 #16
0
 public function deleteFile($projectId, $fileId)
 {
     // Busca o arquivo
     $file = $this->repository->skipPresenter()->find($projectId)->files->find($fileId);
     // Caso não encontre, retorna erro
     if ($file == null) {
         return ['error' => true, 'message' => 'File not found!'];
     }
     // Pega o nome do arquivo e deleta do filesystem
     $fileName = $file->project_id . '_' . $file->id . '.' . $file->extension;
     $this->storage->delete($fileName);
     // Deleta o arquivo do banco de dados
     if ($file->delete()) {
         return ['message' => 'File deleted success'];
     }
 }
예제 #17
0
 public function deleteFile($projectId)
 {
     // recupera somente os Files
     $files = $this->repository->skipPresenter()->find($projectId)->files;
     //dd($files);
     $deletar = [];
     foreach ($files as $file) {
         $path = $file->id . '.' . $file->extension;
         // deletar da bd
         if ($file->delete($file->id)) {
             $deletar[] = $path;
         }
     }
     //dd($deletar);
     $r = $this->storage->delete($deletar);
     if ($r) {
         return ['error' => false];
     } else {
         return ['error' => true];
     }
 }
예제 #18
0
 public function createFile(array $data)
 {
     $project = $this->repository->skipPresenter()->find($data['project_id']);
     $projectFile = $project->files()->create($data);
     $this->storage->put($projectFile->id . "." . $data['extension'], $this->filesystem->get($data['file']));
     /*try {
           $this->validator->with($data)->passesOrFail();
           return $this->repository->create($data);
       }
       catch(ValidatorException $e) {
           return [
               'error' => true,
               'message' => $e->getMessageBag()
           ];
       }
       catch(ModelNotFoundException $e) {
           return [
               'error' => true,
               'message' => $e->getMessage()
           ];
       }*/
 }
예제 #19
0
 public function showMembers($id)
 {
     $project = $this->repository->skipPresenter()->find($id);
     $members = $project->members()->get();
     return $members;
 }
 public function find($id)
 {
     //return $this->repository->with(['owner', 'client'])->find($id);
     return $this->repository->skipPresenter(false)->with(['owner', 'client'])->find($id);
 }
 public function delete($id)
 {
     $projectTask = $this->repository->skipPresenter()->find($id);
     return $projectTask->delete();
 }