1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-17 00:22:51 +01:00
invoiceninja/app/Http/Controllers/ProjectController.php

114 lines
3.2 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
2016-11-29 18:47:26 +01:00
2017-01-30 20:40:43 +01:00
namespace App\Http\Controllers;
use App\Http\Requests\CreateProjectRequest;
use App\Http\Requests\ProjectRequest;
use App\Http\Requests\UpdateProjectRequest;
use App\Models\Client;
use App\Ninja\Datatables\ProjectDatatable;
use App\Ninja\Repositories\ProjectRepository;
use App\Services\ProjectService;
2016-11-29 18:47:26 +01:00
use Auth;
use Input;
use Session;
2017-01-30 20:40:43 +01:00
use View;
2016-11-29 18:47:26 +01:00
class ProjectController extends BaseController
{
protected $projectRepo;
protected $projectService;
protected $entityType = ENTITY_PROJECT;
public function __construct(ProjectRepository $projectRepo, ProjectService $projectService)
{
$this->projectRepo = $projectRepo;
$this->projectService = $projectService;
}
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
return View::make('list_wrapper', [
'entityType' => ENTITY_PROJECT,
'datatable' => new ProjectDatatable(),
'title' => trans('texts.projects'),
]);
}
public function getDatatable($expensePublicId = null)
{
$search = Input::get('sSearch');
$userId = Auth::user()->filterId();
return $this->projectService->getDatatable($search, $userId);
}
public function create(ProjectRequest $request)
{
$data = [
'project' => null,
'method' => 'POST',
'url' => 'projects',
'title' => trans('texts.new_project'),
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(),
'clientPublicId' => $request->client_id,
];
return View::make('projects.edit', $data);
}
public function edit(ProjectRequest $request)
{
$project = $request->entity();
$data = [
'project' => $project,
'method' => 'PUT',
'url' => 'projects/' . $project->public_id,
'title' => trans('texts.edit_project'),
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(),
'clientPublicId' => $project->client ? $project->client->public_id : null,
];
return View::make('projects.edit', $data);
}
public function store(CreateProjectRequest $request)
{
2016-12-15 13:17:10 +01:00
$project = $this->projectService->save($request->input());
2016-11-29 18:47:26 +01:00
Session::flash('message', trans('texts.created_project'));
return redirect()->to($project->getRoute());
}
public function update(UpdateProjectRequest $request)
{
2016-12-15 13:17:10 +01:00
$project = $this->projectService->save($request->input(), $request->entity());
2016-11-29 18:47:26 +01:00
Session::flash('message', trans('texts.updated_project'));
return redirect()->to($project->getRoute());
}
public function bulk()
{
$action = Input::get('action');
$ids = Input::get('public_id') ? Input::get('public_id') : Input::get('ids');
$count = $this->projectService->bulk($ids, $action);
if ($count > 0) {
$field = $count == 1 ? "{$action}d_project" : "{$action}d_projects";
$message = trans("texts.$field", ['count' => $count]);
Session::flash('message', $message);
}
return redirect()->to('/projects');
}
}