Skip to content

Commit

Permalink
add players and teams to posts
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Petrash committed May 1, 2017
1 parent f597e05 commit db9268c
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Volley/FaceBundle/Entity/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class Post
* @ORM\ManyToMany(targetEntity="Volley\StatBundle\Entity\Team", inversedBy="posts")
* @ORM\JoinTable(name="posts_teams")
**/
protected $teams;
private $teams;


/**
Expand Down
38 changes: 35 additions & 3 deletions src/Volley/FaceBundle/Form/PostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Tetranz\Select2EntityBundle\Form\Type\Select2EntityType;

class PostType extends AbstractType
{
Expand Down Expand Up @@ -96,9 +97,40 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('imageSource', null, [
'label' => 'Post Image Source'
])
->add('teams')
->add('persons')
;
// ->add('teams')
// ->add('persons');
->add('teams', Select2EntityType::class, [
'label' => false,
'multiple' => true,
'remote_route' => 'stat_team_json',
'class' => 'Volley\StatBundle\Entity\Team',
'primary_key' => 'id',
'minimum_input_length' => 2,
'page_limit' => 10,
'allow_clear' => true,
'delay' => 250,
'cache' => true,
'cache_timeout' => 60000, // if 'cache' is true
'language' => 'uk',
'placeholder' => "Введіть назву команди",
'attr' => ['width'=>'100%']
])
->add('persons', Select2EntityType::class, [
'label' => false,
'multiple' => true,
'remote_route' => 'stat_person_json',
'class' => 'Volley\StatBundle\Entity\Person',
'primary_key' => 'id',
'minimum_input_length' => 2,
'page_limit' => 10,
'allow_clear' => true,
'delay' => 250,
'cache' => true,
'cache_timeout' => 60000, // if 'cache' is true
'language' => 'uk',
'placeholder' => "Введіть ім'я гравця, тренера або працівника команди",
'attr' => ['width'=>'100%']
]);
}

/**
Expand Down
19 changes: 19 additions & 0 deletions src/Volley/FaceBundle/Resources/public/js/custom/post.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
function resizeSelect () {
jQuery('select[id^=\'volley_bundle_facebundle_post_persons\']').select2entity({width: '100%'})
jQuery('select[id^=\'volley_bundle_facebundle_post_teams\']').select2entity({width: '100%'})
jQuery('li.select2-search').width('100%');
jQuery('input.select2-search__field').width('100%');
}

jQuery(document).ready(function() {
// datepicker
jQuery('#volley_bundle_facebundle_post_published').datetimepicker({
//defaultDate:new Date(),
format:'Y-m-d H:i:s'
});

// select2 resize init and resize
jQuery('a[href="#refs"]').on('click', function (event) {
resizeSelect()
})
jQuery('a[href="#refs"]').on('show.bs.tab', function (event) {
resizeSelect()
})
jQuery('a[href="#refs"]').on('shown.bs.tab', function (event) {
resizeSelect()
})
});
3 changes: 3 additions & 0 deletions src/Volley/FaceBundle/Resources/views/Post/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@
{% block scripts %}
{{ parent() }}
<script type="text/javascript" src="{{ asset('bundles/volleyface/js/custom/jquery.datetimepicker.js') }}"></script>
<script type="text/javascript" src="{{ asset('bundles/volleyface/bower_components/select2/dist/js/select2.full.min.js') }}"></script>
<script src="{{ asset('bundles/tetranzselect2entity/js/select2entity.js') }}"></script>
<script type="text/javascript" src="{{ asset('js/custom/post.js') }}"></script>
{% endblock %}

{% block styles %}
{{ parent() }}
<link rel="stylesheet" href="{{ asset('bundles/volleyface/css/jquery.datetimepicker.css') }}" type="text/css" />
<link rel="stylesheet" href="{{ asset('bundles/volleyface/bower_components/select2/dist/css/select2.min.css') }}" type="text/css"/>
{% endblock %}
3 changes: 3 additions & 0 deletions src/Volley/FaceBundle/Resources/views/Post/new.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@
{% block scripts %}
{{ parent() }}
<script type="text/javascript" src="{{ asset('bundles/volleyface/js/custom/jquery.datetimepicker.js') }}"></script>
<script type="text/javascript" src="{{ asset('bundles/volleyface/bower_components/select2/dist/js/select2.full.min.js') }}"></script>
<script src="{{ asset('bundles/tetranzselect2entity/js/select2entity.js') }}"></script>
<script type="text/javascript" src="{{ asset('js/custom/post.js') }}"></script>
{% endblock %}

{% block styles %}
{{ parent() }}
<link rel="stylesheet" href="{{ asset('bundles/volleyface/css/jquery.datetimepicker.css') }}" type="text/css" />
<link rel="stylesheet" href="{{ asset('bundles/volleyface/bower_components/select2/dist/css/select2.min.css') }}" type="text/css"/>
{% endblock %}
19 changes: 19 additions & 0 deletions src/Volley/StatBundle/Controller/TeamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Volley\StatBundle\Controller;

use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
Expand Down Expand Up @@ -117,6 +118,24 @@ public function newAction()
);
}

/**
* Get Teams json
*
* @param Request $request
* @Route("/json", name="stat_team_json")
* @Method("GET")
*
* @return JsonResponse
*/
public function getTeamsByNameAction(Request $request)
{
$q = $request->query->get('q',' ');
$em = $this->getDoctrine()->getManager();
$teams = $em->getRepository('VolleyStatBundle:Team')->findByName($q);
return JsonResponse::create($teams);
}

/**
* Finds and displays a Team entity.
*
Expand Down
1 change: 0 additions & 1 deletion src/Volley/StatBundle/Entity/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,6 @@ public function getTeams()
*/
public function addPost(Post $posts)
{
$posts->addPerson($this);
$this->posts[] = $posts;

return $this;
Expand Down
6 changes: 6 additions & 0 deletions src/Volley/StatBundle/Entity/Roster.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ class Roster
*/
protected $roster_persons;

/**
* @ORM\OneToMany(targetEntity="TeamSeason", mappedBy="roster", cascade={"persist"}, orphanRemoval=true)
*/
protected $teams_seasons;


function __construct()
{
$this->current = false;
$this->roster_persons = new ArrayCollection();
$this->teams_seasons = new ArrayCollection();
}

/**
Expand Down
12 changes: 9 additions & 3 deletions src/Volley/StatBundle/Entity/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
* Team
*
* @ORM\Table(name="stat_team")
* @ORM\Entity
* @ORM\Entity(repositoryClass="Volley\StatBundle\Entity\TeamRepository")
* @ORM\HasLifecycleCallbacks()
*/
class Team
class Team implements \JsonSerializable
{
/**
* @var integer
Expand Down Expand Up @@ -339,7 +340,6 @@ public function removeRound(\Volley\StatBundle\Entity\Round $rounds)
*/
public function addPost(Post $posts)
{
$posts->addTeam($this);
$this->posts[] = $posts;

return $this;
Expand Down Expand Up @@ -780,5 +780,11 @@ function __toString()
return $this->getName();
}


public function jsonSerialize()
{
return [
'id' => $this->getId(),
'text' => $this->__toString()
];
}
}
20 changes: 20 additions & 0 deletions src/Volley/StatBundle/Entity/TeamRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,24 @@ public function findByTournaments(array $tournaments) {
->orderBy('s.id','ASC')
->getQuery()->getResult();
}

/**
* * Get team by query
*
* @param $q
* @return array
*/
public function findByName($q)
{
$qb = $this->createQueryBuilder('t');
return $qb->select('t')
->andWhere($qb->expr()->orX(
$qb->expr()->like('t.name', $qb->expr()->literal('%' . $q . '%'))
))
->orderBy('t.name', 'ASC')
->setFirstResult(0)
->setMaxResults(10)
->getQuery()->getResult();

}
}

0 comments on commit db9268c

Please sign in to comment.