Commit 3bcfbf85 authored by dj3c1t's avatar dj3c1t

source forms

parent b12fb1f8
......@@ -125,8 +125,16 @@ class SourceController extends Controller {
}
public function addAction(Request $request, $sourceType) {
$sm = $this->get('sourceml.source_manager');
$em = $this->get('doctrine')->getManager();
$authorRepo = $em->getRepository("Dj3c1tSourceMLBundle:Author");
if(!$authorRepo->findByUser($this->getUser())) {
$this->get('session')->getFlashBag()->add(
"info",
"Vous devez ajouter un auteur avant d'ajouter une source"
);
return $this->redirect($this->get('router')->generate('account_author_add'));
}
$sm = $this->get('sourceml.source_manager');
$source = new Source();
if(!($SourceType = $sm->getSourceType($sourceType))) {
throw new \Exception("can't find '".$sourceType."' source type");
......@@ -180,6 +188,15 @@ class SourceController extends Controller {
}
public function addReferenceAction(Request $request, $sourceType) {
$em = $this->get('doctrine')->getManager();
$authorRepo = $em->getRepository("Dj3c1tSourceMLBundle:Author");
if(!$authorRepo->findByUser($this->getUser())) {
$this->get('session')->getFlashBag()->add(
"info",
"Vous devez ajouter un auteur avant d'ajouter une source"
);
return $this->redirect($this->get('router')->generate('account_author_add'));
}
$sm = $this->get('sourceml.source_manager');
if(!$sm->canOpenUrl()) {
$this->get('session')->getFlashBag()->add(
......
......@@ -20,6 +20,7 @@ class SourceType extends AbstractType {
private $em;
private $sm;
private $sourceRepo;
private $licenceRepo;
private $source;
private $isNew;
......@@ -33,6 +34,7 @@ class SourceType extends AbstractType {
$this->em = $this->container->get('doctrine')->getManager();
$this->sm = $this->container->get('sourceml.source_manager');
$this->sourceRepo = $this->em->getRepository("Dj3c1tSourceMLBundle:Source");
$this->licenceRepo = $this->em->getRepository("Dj3c1tSourceMLBundle:Licence");
if(!($this->user = $this->container->get('security.token_storage')->getToken()->getUser())) {
throw new \Exception("user must be logged in to access source form");
}
......@@ -92,14 +94,21 @@ class SourceType extends AbstractType {
'mapped' => false,
)
);
$builder->add(
'licence',
'entity',
array(
'class' => 'Dj3c1tSourceMLBundle:Licence',
'label' => 'Licence',
)
);
if(
$this->licenceRepo->createQueryBuilder('l')
->select('COUNT(l)')
->getQuery()->getSingleScalarResult()
) {
$builder->add(
'licence',
'entity',
array(
'class' => 'Dj3c1tSourceMLBundle:Licence',
'label' => 'Licence',
)
);
}
}
$compositionType = null;
$compositionLabel = "";
......@@ -126,27 +135,31 @@ class SourceType extends AbstractType {
|| !isset($composition)
|| $this->sm->userCan("contribute", $composition)
) {
$builderParams = array(
'class' => 'Dj3c1tSourceMLBundle:Source',
'label' => $compositionLabel,
'mapped' => false,
'choices' => $this->sourceRepo->getSourceQuery(
if(
$compositions = $this->sourceRepo->getSourceQuery(
array(
"user" => $this->user,
"sourceType" => $compositionType->getName(),
"isReference" => false,
)
)->getResult(),
'required' => false,
);
if(isset($composition)) {
$builderParams["data"] = $composition;
)->getResult()
) {
$builderParams = array(
'class' => 'Dj3c1tSourceMLBundle:Source',
'label' => $compositionLabel,
'mapped' => false,
'choices' => $compositions,
'required' => false,
);
if(isset($composition)) {
$builderParams["data"] = $composition;
}
$builder->add(
'composition',
'entity',
$builderParams
);
}
$builder->add(
'composition',
'entity',
$builderParams
);
}
}
$builder->addEventListener(
......@@ -212,8 +225,11 @@ class SourceType extends AbstractType {
$this->em->remove($sourceAuthor);
}
}
if(!($author = $form->get('author')->getData())) {
throw new \Exception("source author is required");
}
$sourceAuthor = new SourceAuthor();
$sourceAuthor->setAuthor($form->get('author')->getData());
$sourceAuthor->setAuthor($author);
$sourceAuthor->setSource($this->source);
$sourceAuthor->setAuthorRole($this->sm->getAuthorRole("admin"));
$sourceAuthor->setIsValid(true);
......
......@@ -30,7 +30,7 @@
<div class="error">{{ form_errors(form.author) }}</div>
{{ form_widget(form.author, {attr: {class: 'form-control', style: 'width: auto'}}) }}
</div>
{% if sourceType != 'album' %}
{% if form.offsetExists('composition') %}
<div class="form-group">
{{ form_label(form.composition) }}
<div class="error">{{ form_errors(form.composition) }}</div>
......@@ -42,11 +42,13 @@
<div class="error">{{ form_errors(form.title) }}</div>
{{ form_widget(form.title, {attr: {class: 'form-control'}}) }}
</div>
{% if form.offsetExists('licence') %}
<div class="form-group">
{{ form_label(form.licence) }}
<div class="error">{{ form_errors(form.licence) }}</div>
{{ form_widget(form.licence, {attr: {class: 'form-control', style: 'width: auto'}}) }}
</div>
{% endif %}
<div class="form-group">
{{ form_label(form.description) }}
<div class="error">{{ form_errors(form.description) }}</div>
......
......@@ -116,11 +116,13 @@
<div class="error">{{ form_errors(form.title) }}</div>
{{ form_widget(form.title, {attr: {class: 'form-control'}}) }}
</div>
{% if form.offsetExists('licence') %}
<div class="form-group">
{{ form_label(form.licence) }}
<div class="error">{{ form_errors(form.licence) }}</div>
{{ form_widget(form.licence, {attr: {class: 'form-control', style: 'width: auto'}}) }}
</div>
{% endif %}
<div class="form-group">
{{ form_label(form.description) }}
<div class="error">{{ form_errors(form.description) }}</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment