Commit 804126e1 authored by ericksho-ipre's avatar ericksho-ipre

todo listo, falta ver si eliminaremos o no las preguntas

parent cf0c6559
...@@ -46,7 +46,8 @@ ...@@ -46,7 +46,8 @@
<li><a href="{{path('event_index')}}">Eventos</a></li> <li><a href="{{path('event_index')}}">Eventos</a></li>
{% endif %} {% endif %}
{% if is_granted('ROLE_STUDENT') and not is_granted('ROLE_ADMIN') %} {% if is_granted(['ROLE_STUDENT','ROLE_PROFESSOR']) and not is_granted('ROLE_ADMIN') %}
<li><a href="{{path('event_find')}}">Buscar evento</a></li>
{% endif %} {% endif %}
</ul> </ul>
......
{% extends 'base.html.twig' %}
{% block body %}
<center><h1>Buscar evento</h1></center>
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}
{% endblock %}
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
<td> <td>
<a href="{{ path('event_show', { 'id': event.id }) }}" class="btn btn-xs btn-primary">ver</a> <a href="{{ path('event_show', { 'id': event.id }) }}" class="btn btn-xs btn-primary">ver</a>
<a href="{{ path('event_edit', { 'id': event.id }) }}" class="btn btn-xs btn-primary">editar</a> <a href="{{ path('event_edit', { 'id': event.id }) }}" class="btn btn-xs btn-primary">editar</a>
<a href="{{ path('question_event', { 'id': event.id }) }}" class="btn btn-xs btn-primary">participar</a>
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
......
{% extends 'base.html.twig' %} {% extends 'base.html.twig' %}
{% block body %} {% block body %}
<h1>Evento {{ event.name }}</h1> <center><h1>Evento {{ event.name }}</h1></center>
<div id="questions"> <div id="questions">
...@@ -10,9 +10,10 @@ ...@@ -10,9 +10,10 @@
<form> <form>
<div class="form-group"> <div class="form-group">
<label for="exampleInputEmail1">Nueva pregunta</label> <label for="exampleInputEmail1">Nueva pregunta</label>
<textarea class="form-control" rows="3" id="new_question"></textarea> <textarea class="form-control" rows="3" onkeypress="checkQuestionLength()" id="new_question"></textarea>
<div id="question-alert"><kbd> La pregunta debe tener al menos 10 caracteres</kbd></div>
</div> </div>
<input type="button" class="btn btn-primary" value="Preguntar" onclick="submitQuestion()"> <input type="button" class="btn btn-primary" disabled id="preguntar" value="Preguntar" onclick="submitQuestion()">
</form> </form>
{% endblock %} {% endblock %}
...@@ -24,10 +25,26 @@ ...@@ -24,10 +25,26 @@
updateQuestions(); updateQuestions();
}; };
// window.setInterval(function(){ window.setInterval(function(){
// /// call your function here /// call your function here
// updateQuestions(); updateQuestions();
// }, 3000); }, 3000);
function checkQuestionLength()
{
var question = $('#new_question').val();
if(question.length < 9)
{
$('#preguntar').prop("disabled", true);
$('#question-alert').show();
}
else
{
$('#preguntar').prop("disabled", false);
$('#question-alert').hide();
}
}
var allQuestions = null; var allQuestions = null;
function updateQuestions() function updateQuestions()
...@@ -39,17 +56,19 @@ ...@@ -39,17 +56,19 @@
$.each(response, function(index, value){ $.each(response, function(index, value){
if($('#q'+index).length == 0) if($('#q'+index).length == 0)
{ {
$('#questions').append(''+ var newQuestion = '<div data-sort="'+value[2]+'" id="q'+index+'" class="question-div panel panel-info">'+
'<div data-sort="'+value[2]+'" id="q'+index+'" class="question-div panel panel-info">'+
'<div class="inline-ble">'+ '<div class="inline-ble">'+
'<div class="date-asked left-col"><small>'+value[4]+'</small></div>'+ '<div class="date-asked left-col"><small>'+value[4]+'</small></div>'+
'<div class="buttons right-col">'+ '<div class="buttons right-col">';
'<button type="button" class="btn btn-default btn-xs likes-button" qid="'+index+'" onclick="upvote(this)"><div class="n-lovers">'+value[0]+'</div><span class="glyphicon glyphicon-thumbs-up" aria-hidden="true"></span></button>'+ {% if is_granted('ROLE_PROFESSOR') %}
newQuestion += '<a class="btn btn-xs btn-default likes-button" target="_blank" href="/question/'+index+'" role="button"><span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span></a>';
{% endif %}
newQuestion += '<button type="button" class="btn btn-default btn-xs likes-button" qid="'+index+'" onclick="upvote(this)"><div class="n-lovers">'+value[0]+'</div><span class="glyphicon glyphicon-thumbs-up" aria-hidden="true"></span></button>'+
'</div>'+ '</div>'+
'</div>'+ '</div>'+
'<h5>'+value[3]+'</h5>'+ '<h5>'+value[3]+'</h5>'+
'</div>' '</div>'
); $('#questions').append(newQuestion);
} }
else else
{ {
...@@ -67,24 +86,22 @@ ...@@ -67,24 +86,22 @@
function submitQuestion() function submitQuestion()
{ {
//disable
$('form :input').prop("disabled", true);
var question = $('#new_question').val(); var question = $('#new_question').val();
$('#new_question').val(null);
if(question) if(question.length < 9)
{
checkQuestionLength();
return;
}
$.post("{{ path('question_ask', { 'id': event.id }) }}", $.post("{{ path('question_ask', { 'id': event.id }) }}",
{question: question}, {question: question},
function(response) function(response)
{ {
updateQuestions(); updateQuestions();
$('#new_question').val(null);
}, },
"json"); "json");
//enable all
$('form :input').prop("disabled", false);
} }
function upvote(question) function upvote(question)
......
{% extends 'base.html.twig' %} {% extends 'base.html.twig' %}
{% block body %} {% block body %}
<h1>Question</h1> <h1>Pregunta</h1>
<table> <table class="table">
<tbody> <tbody>
<tr> <tr>
<th>Id</th> <th>Pregunta</th>
<td>{{ question.id }}</td> <td>{{ question.question }}</td>
</tr> </tr>
<tr> <tr>
<th>Question</th> <th>Fecha</th>
<td>{{ question.question }}</td> <td>{% if question.asked %}{{ question.asked|date('d-m-Y H:m:s') }}{% endif %}</td>
</tr> </tr>
<tr> <tr>
<th>Asked</th> <th>Preguntador</th>
<td>{% if question.asked %}{{ question.asked|date('Y-m-d') }}{% endif %}</td> <td><a href="{{ path('user_show', { 'id': question.asker.id }) }}">{{ question.asker.getShowName }}</a></td>
</tr>
<tr>
<th>IP de donde se preguntó</th>
<td>{{ question.askerip }}</td>
</tr>
<tr>
<th>Likes</th>
<td>
{{ question.nLovers }}
</td>
</tr>
<tr>
<th>Lovers</th>
<td>
<ul>
{% for lover in question.lovers %}
<li><a href="{{ path('user_show', { 'id': lover.id }) }}">{{ lover.getShowName }}</a></li>
{% endfor %}
</ul>
</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<ul>
<li>
<a href="{{ path('question_index') }}">Back to the list</a>
</li>
<li>
<a href="{{ path('question_edit', { 'id': question.id }) }}">Edit</a>
</li>
<li>
{{ form_start(delete_form) }}
<input type="submit" value="Delete">
{{ form_end(delete_form) }}
</li>
</ul>
{% endblock %} {% endblock %}
...@@ -26,21 +26,37 @@ security: ...@@ -26,21 +26,37 @@ security:
role_hierarchy: role_hierarchy:
ROLE_ADMIN: [ROLE_STUDENT, ROLE_PROFESSOR, ROLE_TEACHER_ASSISTANT] ROLE_ADMIN: [ROLE_STUDENT, ROLE_PROFESSOR]
access_control: access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/login_check$, roles: [ROLE_STUDENT, ROLE_PROFESSOR, ROLE_TEACHER_ASSISTANT] } - { path: ^/login_check$, roles: [ROLE_STUDENT, ROLE_PROFESSOR] }
#- { path: ^/user/$, roles: ROLE_ADMIN } - { path: ^/user/$, roles: ROLE_ADMIN }
#- { path: ^/user/[0-9]+$, roles: [ROLE_STUDENT, ROLE_PROFESSOR, ROLE_TEACHER_ASSISTANT] } - { path: ^/user/[0-9]+$, roles: [ROLE_STUDENT, ROLE_PROFESSOR] }
#- { path: ^/user/new$, roles: ROLE_ADMIN } - { path: ^/user/new$, roles: ROLE_ADMIN }
#- { path: ^/user/[0-9]+/edit$, roles: ROLE_ADMIN } - { path: ^/user/[0-9]+/edit$, roles: ROLE_ADMIN }
#- { path: ^/role/$, roles: [ROLE_ADMIN] } - { path: ^/role/$, roles: [ROLE_ADMIN] }
#- { path: ^/role/[0-9]+$, roles: [ROLE_ADMIN] } - { path: ^/role/[0-9]+$, roles: [ROLE_ADMIN] }
#- { path: ^/role/new$, roles: ROLE_ADMIN } - { path: ^/role/new$, roles: ROLE_ADMIN }
#- { path: ^/role/[0-9]+/edit$, roles: [ROLE_ADMIN] } - { path: ^/role/[0-9]+/edit$, roles: [ROLE_ADMIN] }
- { path: ^/event/$, roles: ROLE_ADMIN }
- { path: ^/event/[0-9]+$, roles: ROLE_PROFESSOR }
- { path: ^/event/find$, roles: [ROLE_STUDENT, ROLE_PROFESSOR] }
- { path: ^/event/new$, roles: ROLE_ADMIN }
- { path: ^/event/[0-9]+/edit$, roles: ROLE_ADMIN }
- { path: ^/question/$, roles: ROLE_ADMIN }
- { path: ^/question/[0-9]+$, roles: ROLE_ADMIN }
- { path: ^/question/new$, roles: [ROLE_STUDENT, ROLE_PROFESSOR] }
- { path: ^/question/[0-9]+/edit$, roles: ROLE_ADMIN }
- { path: ^/question/event/[0-9]+$, roles: [ROLE_STUDENT, ROLE_PROFESSOR] }
- { path: ^/question/ask/[0-9]+$, roles: [ROLE_STUDENT, ROLE_PROFESSOR] }
- { path: ^/question/love/[0-9]+$, roles: [ROLE_STUDENT, ROLE_PROFESSOR] }
- { path: ^/question/hate/[0-9]+$, roles: [ROLE_STUDENT, ROLE_PROFESSOR] }
- { path: ^/question/get/[0-9]+$, roles: [ROLE_STUDENT, ROLE_PROFESSOR] }
providers: providers:
our_db_provider: our_db_provider:
......
...@@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; ...@@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
/** /**
* Event controller. * Event controller.
...@@ -24,8 +25,12 @@ class EventController extends Controller ...@@ -24,8 +25,12 @@ class EventController extends Controller
public function indexAction() public function indexAction()
{ {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$currentUser = $this->get('security.token_storage')->getToken()->getUser();
$events = $em->getRepository('AppBundle:Event')->findAll(); if($this->get('security.authorization_checker')->isGranted('ROLE_ADMIN'))
$events = $em->getRepository('AppBundle:Event')->findAll();
else
$events = $em->getRepository('AppBundle:Event')->findByOwner($currentUser);
return $this->render('event/index.html.twig', array( return $this->render('event/index.html.twig', array(
'events' => $events, 'events' => $events,
...@@ -61,6 +66,33 @@ class EventController extends Controller ...@@ -61,6 +66,33 @@ class EventController extends Controller
)); ));
} }
/**
* finds a event entity.
*
* @Route("/find", name="event_find")
* @Method({"GET", "POST"})
*/
public function findAction(Request $request)
{
$form = $this->createFormBuilder()
->add('hashtag')
->add('save', SubmitType::class, ['label' => 'Buscar'])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$hashtag = $form->get("hashtag")->getData();
$em = $this->getDoctrine()->getManager();
$event = $em->getRepository('AppBundle:Event')->findOneByHashtag($hashtag);
return $this->redirectToRoute('question_event', array('id' => $event->getId()));
}
return $this->render('event/find.html.twig', array(
'form' => $form->createView(),
));
}
/** /**
* Finds and displays a event entity. * Finds and displays a event entity.
* *
...@@ -85,6 +117,13 @@ class EventController extends Controller ...@@ -85,6 +117,13 @@ class EventController extends Controller
*/ */
public function editAction(Request $request, Event $event) public function editAction(Request $request, Event $event)
{ {
$currentUser = $this->get('security.token_storage')->getToken()->getUser();
if( !$this->get('security.authorization_checker')->isGranted('ROLE_ADMIN') AND $currentUser->getId() != $event->getOwner()->getId() )
{
return $this->redirectToRoute('event_index');
}
$deleteForm = $this->createDeleteForm($event); $deleteForm = $this->createDeleteForm($event);
$editForm = $this->createForm('AppBundle\Form\EventType', $event); $editForm = $this->createForm('AppBundle\Form\EventType', $event);
$editForm->handleRequest($request); $editForm->handleRequest($request);
......
...@@ -32,7 +32,7 @@ class Question ...@@ -32,7 +32,7 @@ class Question
/** /**
* @var \DateTime * @var \DateTime
* *
* @ORM\Column(name="asked", type="date") * @ORM\Column(name="asked", type="datetime")
*/ */
private $asked; private $asked;
......
...@@ -16,6 +16,7 @@ class EventType extends AbstractType ...@@ -16,6 +16,7 @@ class EventType extends AbstractType
$builder $builder
->add('name', null,array('label' => 'Nombre')) ->add('name', null,array('label' => 'Nombre'))
->add('hashtag', null,array('label' => 'Hashtag')) ->add('hashtag', null,array('label' => 'Hashtag'))
->add('open', null,array('label' => 'Abierto'))
; ;
}/** }/**
* {@inheritdoc} * {@inheritdoc}
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace AppBundle\Repository; namespace AppBundle\Repository;
use AppBundle\Entity\User;
/** /**
* UserRepository * UserRepository
* *
...@@ -10,4 +12,31 @@ namespace AppBundle\Repository; ...@@ -10,4 +12,31 @@ namespace AppBundle\Repository;
*/ */
class UserRepository extends \Doctrine\ORM\EntityRepository class UserRepository extends \Doctrine\ORM\EntityRepository
{ {
public function createFromSidingData($data, $em)
{
$user = new User();
$user->setRut($data['rut']);
$user->setName($data['name']);
$user->setLastName($data['lastname']);
$user->setMail($data['mail']);
$user->setPassword(bin2hex(random_bytes(8)));
$user->setSex($data['sexo']);
switch ($data['rol']) {
case 'profesor':
$role = $em->getRepository('AppBundle:Role')->findOneByRole('ROLE_PROFESSOR');
$user->addUserRole($role);
break;
default:
$role = $em->getRepository('AppBundle:Role')->findOneByRole('ROLE_STUDENT');
$user->addUserRole($role);
break;
}
$em->persist($user);
$em->flush();
return $user;
}
} }
...@@ -49,7 +49,7 @@ class MultiAuthenticator implements SimpleFormAuthenticatorInterface ...@@ -49,7 +49,7 @@ class MultiAuthenticator implements SimpleFormAuthenticatorInterface
$user->getRoles() $user->getRoles()
); );
} }
/*else else
{ {
$data = $this->siding->getUserData($rut); $data = $this->siding->getUserData($rut);
...@@ -65,7 +65,7 @@ class MultiAuthenticator implements SimpleFormAuthenticatorInterface ...@@ -65,7 +65,7 @@ class MultiAuthenticator implements SimpleFormAuthenticatorInterface
); );
}*/ }
} }
throw new CustomUserMessageAuthenticationException('Las credenciales presentadas no son válidas'); throw new CustomUserMessageAuthenticationException('Las credenciales presentadas no son válidas');
} }
......
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