/** * Run the database seeds. * * @return void */ public function run() { // ID 1 \VisualAppeal\Connect\Project::create(['company_id' => 2, 'title' => 'New software', 'website' => 'http://ibm.com', 'repository' => 'https://github.com/IBM/ibm.github.io', 'bugtracker' => 'https://github.com/IBM/ibm.github.io/issues', 'started_at' => '2014-10-10 14:12:56', 'completed_at' => '2015-03-09 21:51:01']); // ID 2 \VisualAppeal\Connect\Project::create(['company_id' => 2, 'title' => 'Javascript Christmas Tree', 'started_at' => '2014-12-24 12:13:14']); // ID 1 \VisualAppeal\Connect\ProjectPhase::create(['project_id' => 2, 'title' => 'Requirements Specification', 'number' => 1, 'started_at' => '2014-12-25 12:13:14', 'completed_at' => '2014-12-26 12:13:14']); // ID 2 \VisualAppeal\Connect\ProjectPhase::create(['project_id' => 2, 'title' => 'Functional Specification', 'number' => 2, 'started_at' => '2014-12-27 12:13:14', 'completed_at' => '2014-12-28 12:13:14']); // ID 3 \VisualAppeal\Connect\ProjectPhase::create(['project_id' => 2, 'title' => 'Contract', 'number' => 3, 'started_at' => '2014-12-29 12:13:14', 'planed_completed_at' => date('Y-m-d H:i:s', time() + 3600 * 24)]); // ID 4 \VisualAppeal\Connect\ProjectPhase::create(['project_id' => 2, 'number' => 4, 'title' => 'Implementation']); // ID 5 \VisualAppeal\Connect\ProjectPhase::create(['project_id' => 2, 'number' => 5, 'title' => 'Testing']); // ID 1 \VisualAppeal\Connect\ProjectCompanyDepartment::create(['project_id' => 2, 'company_department_id' => 1]); // ID 2 \VisualAppeal\Connect\ProjectCompanyDepartment::create(['project_id' => 2, 'company_department_id' => 2]); // ID 1 \VisualAppeal\Connect\ProjectClient::create(['project_id' => 2, 'client_id' => 1]); // ID 1 \VisualAppeal\Connect\ProjectPhaseDocument::create(['project_phase_id' => 3, 'title' => 'Contract', 'content' => "## Contract\n\nThat is the contract.", 'created_at' => date('Y-m-d H:i:s', time() - 3600 * 7.1), 'updated_at' => date('Y-m-d H:i:s', time() - 3600 * 7.1)]); // ID 2 \VisualAppeal\Connect\ProjectPhaseDocument::create(['project_phase_id' => 3, 'parent_project_phase_document_id' => 1, 'title' => 'Contract', 'content' => "## Contract\n\nThat is the contract.\n\n### Payment\n\nPay now!", 'type' => 'history', 'created_at' => date('Y-m-d H:i:s', time() - 3600 * 3.8), 'updated_at' => date('Y-m-d H:i:s', time() - 3600 * 3.8)]); // ID 3 \VisualAppeal\Connect\ProjectPhaseDocument::create(['project_phase_id' => 3, 'parent_project_phase_document_id' => 1, 'title' => 'Contract', 'content' => "## Contract\n\nThat is the contract.\n\n### Payment\n\nPay later...", 'type' => 'history', 'created_at' => date('Y-m-d H:i:s', time() - 3600), 'updated_at' => date('Y-m-d H:i:s', time() - 3600)]); // ID 1 \VisualAppeal\Connect\ProjectPhaseDocumentComment::create(['project_phase_document_id' => 1, 'content' => 'I *love* the contract!', 'created_at' => date('Y-m-d H:i:s', time() - 3600), 'updated_at' => date('Y-m-d H:i:s', time() - 3600)]); // ID 2 \VisualAppeal\Connect\ProjectPhaseDocumentComment::create(['project_phase_document_id' => 1, 'content' => 'Me too', 'created_at' => date('Y-m-d H:i:s', time() - 1800), 'updated_at' => date('Y-m-d H:i:s', time() - 1600)]); }
/** * Test that a ProjectClient can be deleted via interface. */ public function testDeleteForm() { $admin = $this->createSuperuser(); $this->be($admin); $project = $this->createProject(); $projectClient = $this->createProjectClient($project); $this->call('GET', route('project.show', ['project' => $project->id])); $this->assertResponseOk(); $response = $this->call('DELETE', route('project.client.destroy', ['project' => $project->id, 'client' => $projectClient->client_id]), ['_token' => Session::token()]); $this->assertRedirectedToRoute('project.show', ['project' => $project->id]); $this->assertEquals(0, \VisualAppeal\Connect\ProjectClient::count()); }
/** * Delete client. * * @param int $projectId * @param int $clientId * * @return Response */ public function destroy($projectId, $clientId) { $client = ProjectClient::where('project_id', '=', $projectId)->where('client_id', '=', $clientId)->firstOrFail(); $client->delete(); return redirect()->route('project.show', ['project' => $projectId]); }
/** * Register events. * * @param \Illuminate\Contracts\Events\Dispatcher $events * @return void */ public function boot(DispatcherContract $events) { parent::boot($events); /** * Users */ // Create client with user User::created(function (User $user) { // Save ID of user who created the client $client = new Client(); if (\Sentry::check()) { $client->user_id = \Sentry::getUser()->id; } $client->save(); // Save ID of the client in the user model $user->client_id = $client->id; $user->save(); }); // Client about to be created Client::creating(function (Client $client) { if (\Sentry::check()) { $client->user_id = \Sentry::getUser()->id; } }); // ClientProfile about to be created ClientProfile::creating(function (ClientProfile $clientProfile) { if (\Sentry::check()) { $clientProfile->user_id = \Sentry::getUser()->id; } }); // ClientComment about to be created ClientComment::creating(function (ClientComment $clientComment) { if (\Sentry::check()) { $clientComment->user_id = \Sentry::getUser()->id; } }); /** * Tasks */ // User assigned user to task TaskClient::created(function (TaskClient $taskClient) { Notification::notify(['from_user_id' => $taskClient->user_id, 'to_user_id' => $taskClient->client->user->id, 'icon' => 'tasks', 'message' => 'notification.task.assigned', 'message_parameters' => ['task' => $taskClient->task->title], 'url' => 'task.view', 'url_parameters' => ['id' => $taskClient->task->id]]); }); // User assigned user to job TaskJobClient::created(function (TaskJobClient $taskJobClient) { Notification::notify(['from_user_id' => $taskJobClient->user_id, 'to_user_id' => $taskJobClient->client->user->id, 'icon' => 'tasks', 'message' => 'notification.task.job.assigned', 'message_parameters' => ['job' => $taskJobClient->job->title, 'task' => $taskJobClient->job->task->title], 'url' => 'task.job.view', 'url_parameters' => ['id' => $taskJobClient->job->id]]); }); // User created new job for task TaskJob::created(function (TaskJob $taskJob) { foreach ($taskJob->task->clients as $client) { if (!isset($client->user->id)) { continue; } Notification::notify(['from_user_id' => $taskJob->user_id, 'to_user_id' => $client->user->id, 'icon' => 'tasks', 'message' => 'notification.task.job.created', 'message_parameters' => ['job' => $taskJob->title, 'task' => $taskJob->task->title], 'url' => 'task.job.view', 'url_parameters' => ['id' => $taskJob->id]]); } }); // Task about to be created Task::creating(function (Task $task) { if (\Sentry::check()) { $task->user_id = \Sentry::getUser()->id; } }); // Task user assignment about to be created TaskClient::creating(function (TaskClient $taskClient) { if (\Sentry::check()) { $taskClient->user_id = \Sentry::getUser()->id; } }); // Job about to be created TaskJob::creating(function (TaskJob $taskJob) { if (\Sentry::check()) { $taskJob->user_id = \Sentry::getUser()->id; } }); // Job user assignment about to be created TaskJobClient::creating(function (TaskJobClient $taskJobClient) { if (\Sentry::check()) { $taskJobClient->user_id = \Sentry::getUser()->id; } }); /** * Companies */ // Company about to be created Company::creating(function (Company $company) { if (\Sentry::check()) { $company->user_id = \Sentry::getUser()->id; } }); // Company department about to be created CompanyDepartment::creating(function (CompanyDepartment $companyDepartment) { if (\Sentry::check()) { $companyDepartment->user_id = \Sentry::getUser()->id; } }); // Company user about to be created CompanyClient::creating(function (CompanyClient $companyClient) { if (\Sentry::check()) { $companyClient->user_id = \Sentry::getUser()->id; } }); // Company profile about to be created CompanyProfile::creating(function (CompanyProfile $companyProfile) { if (\Sentry::check()) { $companyProfile->user_id = \Sentry::getUser()->id; } }); /** * Invoices */ // Save user ID for the invoice Invoice::creating(function (Invoice $invoice) { if (\Sentry::check()) { $invoice->user_id = \Sentry::getUser()->id; } }); // Final invoices cannot be updated Invoice::updating(function (Invoice $invoice) { if ($invoice->final) { return false; } }); // Save user ID for the invoice item InvoiceItem::creating(function (InvoiceItem $invoiceItem) { if (\Sentry::check()) { $invoiceItem->user_id = \Sentry::getUser()->id; } }); // Items of final invoices cannot be updated InvoiceItem::updating(function (InvoiceItem $invoiceItem) { if ($invoiceItem->invoice->final) { return false; } }); // Save user ID for the recurring invoice InvoiceRecurring::creating(function (InvoiceRecurring $invoiceRecurring) { if (\Sentry::check()) { $invoiceRecurring->user_id = \Sentry::getUser()->id; } }); // Save user ID for the split invoice InvoiceSplit::creating(function (InvoiceSplit $invoiceSplit) { if (\Sentry::check()) { $invoiceSplit->user_id = \Sentry::getUser()->id; } }); /** * Projects */ // Save user ID for the Project Project::creating(function (Project $project) { if (\Sentry::check()) { $project->user_id = \Sentry::getUser()->id; } }); // Save user ID for the ProjectProfile ProjectProfile::creating(function (ProjectProfile $projectProfile) { if (\Sentry::check()) { $projectProfile->user_id = \Sentry::getUser()->id; } }); // Save user ID for the ProjectClient ProjectClient::creating(function (ProjectClient $projectClient) { if (\Sentry::check()) { $projectClient->user_id = \Sentry::getUser()->id; } }); // Save user ID for the ProjectCompanyDepartment ProjectCompanyDepartment::creating(function (ProjectCompanyDepartment $projectCompanyDepartment) { if (\Sentry::check()) { $projectCompanyDepartment->user_id = \Sentry::getUser()->id; } }); // Save user ID for the ProjectPhase ProjectPhase::creating(function (ProjectPhase $projectPhase) { if (\Sentry::check()) { $projectPhase->user_id = \Sentry::getUser()->id; } }); // Save user ID for the ProjectPhaseDocument ProjectPhaseDocument::creating(function (ProjectPhaseDocument $projectPhaseDocument) { if (\Sentry::check()) { $projectPhaseDocument->user_id = \Sentry::getUser()->id; } }); // Save user ID for the ProjectPhaseDocumentComment ProjectPhaseDocumentComment::creating(function (ProjectPhaseDocumentComment $projectPhaseDocumentComment) { if (\Sentry::check()) { $projectPhaseDocumentComment->user_id = \Sentry::getUser()->id; } }); }
/** * Create a random ProjectClient relation. * * @param int VisualAppeal\Connect\Project $project (Default: null, newly created) * @param int VisualAppeal\Connect\Client $client (Default: null, newly created) * * @return VisualAppeal\Connect\ProjectClient */ public function createProjectClient($project = null, $client = null) { $project = $project ?: $this->createProject(); $client = $client ?: $this->createClient(); return \VisualAppeal\Connect\ProjectClient::create(['project_id' => $project->id, 'client_id' => $client->id]); }