2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
2016-05-01 14:04:55 +02:00
|
|
|
|
2017-03-02 17:02:48 +01:00
|
|
|
use App\Models\Client;
|
2017-03-02 20:55:41 +01:00
|
|
|
use App\Models\Project;
|
2017-03-02 17:02:48 +01:00
|
|
|
|
2017-01-30 17:05:31 +01:00
|
|
|
class TaskRequest extends EntityRequest
|
|
|
|
{
|
2016-05-01 14:04:55 +02:00
|
|
|
protected $entityType = ENTITY_TASK;
|
2017-03-01 21:03:15 +01:00
|
|
|
|
|
|
|
public function sanitize()
|
|
|
|
{
|
|
|
|
$input = $this->all();
|
|
|
|
|
2017-09-25 16:26:22 +02:00
|
|
|
/*
|
2017-09-25 12:53:50 +02:00
|
|
|
// check if we're creating a new client
|
|
|
|
if ($this->client_id == '-1') {
|
|
|
|
$client = [
|
|
|
|
'name' => trim($this->client_name),
|
|
|
|
];
|
|
|
|
if (Client::validate($client) === true) {
|
|
|
|
$client = app('App\Ninja\Repositories\ClientRepository')->save($client);
|
|
|
|
$input['client_id'] = $this->client_id = $client->public_id;
|
|
|
|
}
|
|
|
|
}
|
2017-09-25 16:26:22 +02:00
|
|
|
*/
|
|
|
|
|
2017-03-01 21:03:15 +01:00
|
|
|
// check if we're creating a new project
|
2017-03-02 20:55:41 +01:00
|
|
|
if ($this->project_id == '-1') {
|
|
|
|
$project = [
|
2017-03-02 19:07:08 +01:00
|
|
|
'name' => trim($this->project_name),
|
2017-09-24 16:04:32 +02:00
|
|
|
'client_id' => Client::getPrivateId($this->client_id ?: $this->client),
|
2017-03-02 20:55:41 +01:00
|
|
|
];
|
|
|
|
if (Project::validate($project) === true) {
|
|
|
|
$project = app('App\Ninja\Repositories\ProjectRepository')->save($project);
|
|
|
|
$input['project_id'] = $project->public_id;
|
|
|
|
} else {
|
|
|
|
$input['project_id'] = null;
|
|
|
|
}
|
2017-03-01 21:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->replace($input);
|
|
|
|
|
|
|
|
return $this->all();
|
|
|
|
}
|
2017-01-30 17:05:31 +01:00
|
|
|
}
|