2015-05-05 20:33:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Gist\Controller;
|
|
|
|
|
|
|
|
use Silex\Application;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2015-05-05 22:04:04 +02:00
|
|
|
use Gist\Form\CreateGistForm;
|
2015-05-06 14:11:00 +02:00
|
|
|
use Gist\Model\Gist;
|
2015-05-05 20:33:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class HomeController
|
2015-05-05 22:04:04 +02:00
|
|
|
* @author Simon Vieille <simon@deblan.fr>
|
2015-05-05 20:33:05 +02:00
|
|
|
*/
|
2015-05-07 13:49:31 +02:00
|
|
|
class EditController extends Controller
|
2015-05-05 20:33:05 +02:00
|
|
|
{
|
2015-05-06 20:35:30 +02:00
|
|
|
public function createAction(Request $request, Application $app)
|
2015-05-05 20:33:05 +02:00
|
|
|
{
|
2015-05-05 23:24:37 +02:00
|
|
|
$data = array(
|
|
|
|
'type' => 'xml',
|
|
|
|
'cipher' => 'no',
|
|
|
|
);
|
|
|
|
|
|
|
|
$form = new CreateGistForm($app['form.factory'], $app['translator'], $data);
|
2015-05-05 22:06:02 +02:00
|
|
|
$form = $form->build();
|
2015-05-05 22:04:04 +02:00
|
|
|
|
2015-05-05 23:24:37 +02:00
|
|
|
if ($request->isMethod('post')) {
|
|
|
|
$form->submit($request);
|
|
|
|
|
|
|
|
if ($form->isValid()) {
|
2015-05-06 20:35:30 +02:00
|
|
|
$gist = $app['gist']->create(new Gist(), $form->getData());
|
2015-05-05 23:24:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-05 22:04:04 +02:00
|
|
|
return $app['twig']->render(
|
|
|
|
'Home/index.html.twig',
|
|
|
|
array(
|
2015-05-06 20:35:30 +02:00
|
|
|
'gist' => isset($gist) ? $gist : null,
|
2015-05-05 22:04:04 +02:00
|
|
|
'form' => $form->createView(),
|
|
|
|
)
|
|
|
|
);
|
2015-05-05 20:33:05 +02:00
|
|
|
}
|
2015-05-07 13:49:31 +02:00
|
|
|
|
|
|
|
public function cloneAction(Request $request, Application $app, $gist, $commit)
|
|
|
|
{
|
|
|
|
$viewOptions = $this->getViewOptions($request, $app, $gist, $commit);
|
|
|
|
|
|
|
|
if (is_array($viewOptions)) {
|
|
|
|
return $app['twig']->render('View/view.html.twig', $viewOptions);
|
|
|
|
} else {
|
|
|
|
return $this->notFoundResponse($app);
|
|
|
|
}
|
|
|
|
}
|
2015-05-05 20:33:05 +02:00
|
|
|
}
|