public function isMember($project, $member)
 {
     try {
         $projeto = $this->project->find($project);
         foreach ($projeto->members as $m) {
             if ($m->id == $member) {
                 return true;
             }
         }
         return false;
     } catch (ValidatorException $e) {
         return response()->json(['error' => true, 'message' => $e->getMessageBag()]);
     } catch (ModelNotFoundException $e) {
         return response()->json(['error' => true, 'message1' => $e->getMessage(), 'message2' => 'Projeto ID ' . $project . ' nao encontrado.']);
     }
 }
 public function deleteOrFail($project_id)
 {
     if (Project::find($project_id)) {
         return $this->find($project_id)->delete();
     }
     return "Error: project not found";
 }
 public function findMemberAssociation($project_id, $user_id)
 {
     // assume-se que o project_id ja foi checado na camada de servico
     $project = Project::find($project_id);
     foreach ($project->memberAssociations as $pm) {
         if ($pm->user_id == $user_id) {
             return $pm;
         }
     }
     return null;
 }
 public function destroy($id)
 {
     try {
         //Buscando dados do Projeto
         $projects = new Project();
         $p = $projects->where('client_id', $id)->get();
         //removendo notas do projeto
         $notes = new ProjectNote();
         foreach ($p as $project) {
             $notes->where('project_id', $project->id)->delete();
         }
         //removendo projeto
         $projects->where('client_id', $id)->delete();
         //removendo client
         $this->repository->find($id)->delete();
         return json_encode(['success' => 'user removed']);
     } catch (\Exception $e) {
         return json_encode(['error' => 'Project not found', 'msg' => $e->getMessage()]);
     }
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $project_id = $request->route('project') ? $request->route('project') : $request->all()['project_id'];
     $user_id = \Authorizer::getResourceOwnerId();
     if (is_null(Project::find($project_id))) {
         return Errors::invalidId($project_id);
     }
     if (!$this->repository->isMember($project_id, $user_id)) {
         return Errors::basic('Acesso negado! Você não é membro deste projeto.');
     }
     return $next($request);
 }
 public function find($project_id, $member_id)
 {
     $pm = ProjectMember::find($member_id);
     if (is_null($pm)) {
         return Errors::invalidId($member_id);
     }
     if (is_null(Project::find($project_id))) {
         return Errors::invalidId($project_id);
     }
     if ($pm->project_id != $project_id) {
         return Errors::basic("Falha. Projeto " . $project_id . " nao possui membro " . $member_id);
     }
     return $this->repository->find($member_id);
 }
Пример #7
0
 public function find($project_id, $note_id)
 {
     $note = ProjectNote::find($note_id);
     if (is_null($note)) {
         return Errors::invalidId($note_id);
     }
     if (is_null(Project::find($project_id))) {
         return Errors::invalidId($project_id);
     }
     if ($note->project_id != $project_id) {
         return Errors::basic("Falha. Projeto " . $project_id . " nao possui a nota " . $note_id);
     }
     return $this->repository->find($note_id);
 }
Пример #8
0
 public function find($project_id, $task_id)
 {
     $task = ProjectTask::find($task_id);
     if (is_null($task)) {
         return Errors::invalidId($task_id);
     }
     if (is_null(Project::find($project_id))) {
         return Errors::invalidId($project_id);
     }
     if ($task->project_id != $project_id) {
         return Errors::basic("Falha. Projeto " . $project_id . " nao possui a tarefa " . $task_id);
     }
     return $this->repository->find($task_id);
 }
Пример #9
0
 public static function boot()
 {
     parent::boot();
     Project::deleting(function ($project) {
         foreach ($project->notes as $notes) {
             $notes->delete();
         }
         foreach ($project->members as $members) {
             $members->delete();
         }
         foreach ($project->tasks as $task) {
             $task->delete();
         }
     });
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('project_members')->delete();
     for ($i = 1;; $i++) {
         if ($i > 50) {
             break;
         }
         for (;;) {
             $projectId = \CodeProject\Entities\Project::all()->lists('id')->random(1);
             $userId = \CodeProject\Entities\User::all()->lists('id')->random(1);
             if (\CodeProject\Entities\ProjectMember::where('project_id', $projectId)->where('member_id', $userId)->count() == 0) {
                 \CodeProject\Entities\ProjectMember::create(['project_id' => $projectId, 'member_id' => $userId]);
                 break;
             }
         }
     }
 }
Пример #11
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     /*Desativa chave etrangeira*/
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     \CodeProject\Entities\ProjectTask::truncate();
     \CodeProject\Entities\ProjectMember::truncate();
     \CodeProject\Entities\ProjectNote::truncate();
     \CodeProject\Entities\Project::truncate();
     \CodeProject\Entities\Client::truncate();
     \CodeProject\Entities\User::truncate();
     $this->call(UserTableSeeder::class);
     $this->call(ClientTableSeeder::class);
     $this->call(ProjectTableSeeder::class);
     $this->call(ProjectNoteTableSeeder::class);
     $this->call(ProjectMembersTableSeeder::class);
     $this->call(ProjectTasksTableSeeder::class);
     /*ativa chave estrangeira*/
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
 }
Пример #12
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     Project::truncate();
     User::truncate();
     Client::truncate();
     ProjectNote::truncate();
     ProjectTask::truncate();
     ProjectMember::truncate();
     OauthClient::truncate();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     $this->call(ClientTableSeeder::class);
     $this->call(UserTableSeeder::class);
     $this->call(ProjectTableSeeder::class);
     $this->call(ProjectNoteTableSeeder::class);
     $this->call(ProjectTaskTableSeeder::class);
     $this->call(ProjectMemberTableSeeder::class);
     $this->call(OauthClientSeeder::class);
     Model::reguard();
 }
Пример #13
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     DB::statement('SET foreign_key_checks = 0');
     ProjectNote::truncate();
     ProjectTask::truncate();
     ProjectMember::truncate();
     ProjectFile::truncate();
     Project::truncate();
     Client::truncate();
     User::truncate();
     OAuthClient::truncate();
     DB::statement('SET foreign_key_checks = 1');
     $this->call(UserTableSeeder::class);
     $this->call(ClientTableSeeder::class);
     $this->call(ProjectTableSeeder::class);
     $this->call(ProjectNoteTableSeeder::class);
     $this->call(ProjectMemberTableSeeder::class);
     $this->call(ProjectTaskTableSeeder::class);
     $this->call(OAuthClientTableSeeder::class);
     Model::reguard();
 }
Пример #14
0
 public function createFile(array $data)
 {
     try {
         $this->validator->with($data)->passesOrFail();
         $project = Project::find($data['project_id']);
         if (is_null($project)) {
             return Errors::invalidId($data['project_id']);
         }
         $user_id = \Authorizer::getResourceOwnerId();
         if (!$this->projectRepository->isMember($data['project_id'], $user_id)) {
             return Errors::basic('Acesso negado. Você não é membro do projeto selecionado.');
         }
         $data['extension'] = $data['file']->getClientOriginalExtension();
         $projectFile = $this->repository->create($data);
         $nome = $projectFile->id . "." . $data['extension'];
         $arquivo = $this->filesystem->get($data['file']);
         $this->storage->put($nome, $arquivo);
         return ['message' => 'Arquivo criado'];
     } catch (ValidatorException $e) {
         return Errors::basic($e->getMessageBag());
     }
 }
Пример #15
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     \CodeProject\Entities\Project::truncate();
     factory(\CodeProject\Entities\Project::class, 5)->create();
 }
 public function delete($id)
 {
     $entity = Project::find($id);
     if (is_null($entity)) {
         return Errors::invalidId($id);
     }
     foreach ($entity->tasks as $task) {
         $this->projectTaskService->delete($task->id);
     }
     foreach ($entity->notes as $note) {
         $this->projectNoteService->delete($note->id);
     }
     foreach ($entity->memberAssociations as $pm) {
         $this->projectMemberService->delete($pm->id);
     }
     $this->repository->delete($id);
     return ['message' => "Registro deletado!"];
 }
 public function includeClient(Project $project)
 {
     return $this->collection($project->client()->get(), new ProjectClientTransformer());
 }
Пример #18
0
 public function removeMember($project_id, $member_id)
 {
     $project = Project::find($project_id);
     if (is_null($project)) {
         return Errors::invalidId($project_id);
     }
     if (is_null(User::find($member_id))) {
         return Errors::invalidId($member_id);
     }
     if ($member_id == $project->owner_id) {
         return Errors::basic("Não é possível remover o dono do projeto.");
     }
     $pm = $this->repository->findMemberAssociation($project_id, $member_id);
     if (is_null($pm)) {
         return Errors::basic("Este usuário não é membro do projeto.");
     }
     return $this->projectMemberService->delete($pm->id);
 }
Пример #19
0
<?php

/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
$factory->define(CodeProject\Entities\User::class, function (Faker\Generator $faker) {
    return ['name' => $faker->name, 'email' => strtolower($faker->email), 'password' => bcrypt('123456'), 'remember_token' => str_random(10)];
});
$factory->define(CodeProject\Entities\Client::class, function (Faker\Generator $faker) {
    return ['name' => $faker->name, 'responsible' => $faker->name, 'email' => strtolower($faker->email), 'phone' => $faker->phoneNumber, 'address' => $faker->address, 'obs' => $faker->sentence];
});
$factory->define(CodeProject\Entities\Project::class, function (Faker\Generator $faker) {
    return ['owner_id' => \CodeProject\Entities\User::all()->lists('id')->random(1), 'client_id' => \CodeProject\Entities\Client::all()->lists('id')->random(1), 'name' => $faker->sentence, 'description' => $faker->text(400), 'progress' => $faker->numberBetween(0, 100), 'status' => $faker->numberBetween(0, 2), 'due_date' => $faker->dateTimeAD($min = 'now')];
});
$factory->define(CodeProject\Entities\ProjectNote::class, function (Faker\Generator $faker) {
    return ['project_id' => \CodeProject\Entities\Project::all()->lists('id')->random(1), 'title' => $faker->sentence, 'note' => $faker->text(400)];
});
$factory->define(CodeProject\Entities\ProjectTask::class, function (Faker\Generator $faker) {
    return ['project_id' => \CodeProject\Entities\Project::all()->lists('id')->random(1), 'name' => $faker->sentence, 'start_date' => $faker->dateTimeAD($max = 'now'), 'due_date' => $faker->dateTimeAD($min = 'now'), 'status' => $faker->numberBetween(0, 2)];
});
 public function transform(Project $project)
 {
     return ['id' => $project->id, 'name' => $project->name, 'description' => $project->description, 'progress' => $project->progress, 'status' => $project->status, 'due_date' => $project->getDueDate()];
 }
Пример #21
0
<?php

/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
$factory->define(CodeProject\Entities\User::class, function (Faker\Generator $faker) {
    return ['name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt(str_random(10)), 'remember_token' => str_random(10)];
});
$factory->define(CodeProject\Entities\Client::class, function (Faker\Generator $faker) {
    return ['name' => $faker->name, 'responsible' => $faker->name, 'email' => $faker->email, 'phone' => $faker->phoneNumber, 'address' => $faker->address, 'obs' => $faker->sentence];
});
$factory->define(CodeProject\Entities\Project::class, function (Faker\Generator $faker) {
    return ['owner_id' => \CodeProject\Entities\User::all()->lists('id')->random(1), 'client_id' => \CodeProject\Entities\Client::all()->lists('id')->random(1), 'name' => $faker->name, 'description' => $faker->sentence, 'progress' => $faker->NumberBetween(0, 100), 'status' => $faker->numberBetween(1, 3), 'due_date' => $faker->dateTime];
});
$factory->define(CodeProject\Entities\ProjectNote::class, function (Faker\Generator $faker) {
    return ['project_id' => \CodeProject\Entities\Project::all()->lists('id')->random(1), 'title' => $faker->word, 'note' => $faker->paragraph];
});
$factory->define(CodeProject\Entities\ProjectTask::class, function (Faker\Generator $faker) {
    return ['project_id' => \CodeProject\Entities\Project::all()->lists('id')->random(1), 'name' => $faker->word, 'start_date' => $faker->dateTime, 'due_date' => $faker->dateTime, 'status' => $faker->numberBetween(1, 2)];
});
$factory->define(CodeProject\Entities\ProjectMember::class, function (Faker\Generator $faker) {
    return ['project_id' => \CodeProject\Entities\Project::all()->lists('id')->random(1), 'user_id' => \CodeProject\Entities\User::all()->lists('id')->random(1)];
});
Пример #22
0
 public function includeClient(Project $project)
 {
     $client = $project->client()->find($project->client_id);
     return $this->item($client, new ClientTransformer());
 }
    }
    return ['owner_id' => $faker->randomElement($o), 'client_id' => $faker->randomElement($c), 'name' => $faker->word, 'description' => $faker->sentence, 'progress' => rand(1, 100), 'status' => rand(1, 3), 'due_date' => $faker->dateTime('now')];
});
$factory->define(ProjectNote::class, function (Generator $faker) {
    $project = Project::all()->lists('id');
    foreach ($project as $value) {
        $p[] = $value;
    }
    return ['project_id' => $faker->randomElement($p), 'title' => $faker->title, 'note' => $faker->paragraph];
});
$factory->define(ProjectTask::class, function (Generator $faker) {
    $project = Project::all()->lists('id');
    foreach ($project as $value) {
        $p[] = $value;
    }
    return ['project_id' => $faker->randomElement($p), 'name' => $faker->word, 'start_date' => $faker->dateTime('now'), 'due_date' => $faker->dateTime('now'), 'status' => rand(1, 3)];
});
$factory->define(ProjectMembers::class, function (Generator $faker) {
    $project = Project::all()->lists('id');
    foreach ($project as $value) {
        $p[] = $value;
    }
    $user = User::all()->lists('id');
    foreach ($user as $value) {
        $u[] = $value;
    }
    return ['project_id' => $faker->randomElement($p), 'user_id' => $faker->randomElement($u)];
});
$factory->define(OauthClients::class, function (Generator $faker) {
    return ['id' => $faker->md5, 'secret' => $faker->text(10), 'name' => $faker->name];
});
Пример #24
0
|
*/
$factory->define(CodeProject\Entities\User::class, function (Faker\Generator $faker) {
    /*
    return [
        'name' => $faker->name,
        'email' => $faker->email,
        'password' => bcrypt(str_random(10)),
        'remember_token' => str_random(10),
    ];
    */
    return ['name' => 'Renato', 'email' => '*****@*****.**', 'password' => bcrypt(12345), 'remember_token' => str_random(10)];
});
$factory->define(CodeProject\Entities\Client::class, function (Faker\Generator $faker) {
    return ['name' => $faker->name, 'responsible' => $faker->name, 'email' => $faker->email, 'phone' => $faker->phoneNumber, 'address' => $faker->address, 'obs' => $faker->sentence()];
});
$factory->define(CodeProject\Entities\Project::class, function (Faker\Generator $faker) {
    return ['owner_id' => \CodeProject\Entities\User::orderByRaw("RAND()")->first()->getKey(), 'client_id' => \CodeProject\Entities\Client::orderByRaw("RAND()")->first()->getKey(), 'name' => $faker->name, 'description' => $faker->sentence(), 'progress' => $faker->randomDigitNotNull, 'status' => $faker->randomDigitNotNull, 'due_date' => $faker->dateTime];
});
$factory->define(CodeProject\Entities\ProjectNote::class, function (Faker\Generator $faker) {
    return ['project_id' => \CodeProject\Entities\Project::orderByRaw("RAND()")->first()->getKey(), 'title' => $faker->word, 'note' => $faker->paragraph];
});
$factory->define(CodeProject\Entities\ProjectTask::class, function (Faker\Generator $faker) {
    return ['project_id' => \CodeProject\Entities\Project::orderByRaw("RAND()")->first()->getKey(), 'name' => $faker->name, 'status' => $faker->randomDigitNotNull, 'start_date' => $faker->dateTime, 'due_date' => $faker->dateTime];
});
$factory->define(CodeProject\Entities\ProjectMember::class, function (Faker\Generator $faker) {
    return ['project_id' => \CodeProject\Entities\Project::orderByRaw("RAND()")->first()->getKey(), 'user_id' => \CodeProject\Entities\User::orderByRaw("RAND()")->first()->getKey()];
});
$factory->define(CodeProject\Entities\OAuth2::class, function (Faker\Generator $faker) {
    return ['id' => md5(rand(10000, 999999)), 'name' => md5(rand(10000, 999999)), 'secret' => md5(rand(10000, 999999))];
});
Пример #25
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::statement("SET foreign_key_checks = 0");
     \CodeProject\Entities\Project::truncate();
     factory(\CodeProject\Entities\Project::class, 10)->create();
 }
 public function transform(Project $project)
 {
     return ['id' => $project->id, 'project' => $project->name, 'description' => $project->description, 'progress' => $project->progress, 'status' => $project->status, 'due_date' => $project->due_date, 'client' => $project->client()->first()->name];
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Project::truncate();
     factory(Project::class, 10)->create();
 }
Пример #28
0
<?php

/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
$factory->define(CodeProject\Entities\User::class, function (Faker\Generator $faker) {
    return ['name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt(str_random(10)), 'remember_token' => str_random(10)];
});
$factory->define(CodeProject\Entities\Client::class, function (Faker\Generator $faker) {
    return ['name' => $faker->name, 'responsible' => $faker->name, 'email' => $faker->email, 'phone' => $faker->phoneNumber, 'address' => $faker->address, 'obs' => $faker->sentence];
});
$factory->define(CodeProject\Entities\Project::class, function (Faker\Generator $faker) {
    return ['owner_id' => rand(1, 10), 'client_id' => rand(1, 10), 'name' => $faker->word, 'description' => $faker->sentence, 'progress' => rand(1, 100), 'status' => rand(1, 3), 'due_date' => $faker->dateTime('now')];
});
$factory->define(CodeProject\Entities\ProjectNote::class, function (Faker\Generator $faker) {
    return ['project_id' => rand(1, 10), 'title' => $faker->word, 'note' => $faker->paragraph];
});
$factory->define(CodeProject\Entities\ProjectMember::class, function (Faker\Generator $faker) {
    return ['project_id' => rand(1, 10), 'user_id' => rand(1, 10)];
});
$factory->define(CodeProject\Entities\ProjectTask::class, function (Faker\Generator $faker) {
    return ['project_id' => \CodeProject\Entities\Project::all()->lists('id')->random(1), 'name' => $faker->word, 'start_date' => $faker->dateTime, 'due_date' => $faker->dateTime, 'status' => $faker->word];
});