Skip to content

Commit

Permalink
added Extended functionality for better handling user and Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
liuggio committed Jun 19, 2012
1 parent 17d5ab7 commit 3ce1a83
Show file tree
Hide file tree
Showing 40 changed files with 435 additions and 320 deletions.
1 change: 1 addition & 0 deletions Controller/Admin/TicketAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Liuggio\HelpDeskBundle\Controller\Admin;

use Sonata\AdminBundle\Controller\CRUDController as Controller;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

class TicketAdminController extends Controller
{
Expand Down
10 changes: 4 additions & 6 deletions Controller/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ public function createAction()
$form->bindRequest($request);

if ($form->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$em = $this->getDoctrine()->getManager();
$comment = $form->getData();
$form = $this->getRequest()->get('liuggio_HelpDeskBundle_commenttype');
$ticket_id = $form['ticket'];
$ticket = $em->getRepository('LiuggioHelpDeskBundle:Ticket')->find($ticket_id);
if (!$ticket) {
throw $this->createNotFoundException('Unable to find Ticket entity.');
}

$state_pending = $em->getRepository('\Liuggio\HelpDeskBundle\Entity\TicketState')
->findOneByCode(\Liuggio\HelpDeskBundle\Entity\TicketState::STATE_PENDING);

Expand All @@ -45,15 +44,14 @@ public function createAction()
}

$ticket->setState($state_pending);
//Set the createdBy user
$entity->setCreatedBy($user);
$em->persist($ticket);
//Set the createdBy user
$comment->setCreatedBy($user);
$comment->setTicket($ticket);
$em->persist($comment);
$em->flush();

$em->flush();
return $this->redirect($this->generateUrl('ticket_show', array('id' => $ticket_id)));

}

return $this->render('LiuggioHelpDeskBundle:Comment:new.html.twig', array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Comment controller.
*
*/
class CommentAdminController extends Controller
class CommentOperatorController extends Controller
{
/**
* Creates a new Comment entity.
Expand All @@ -28,7 +28,7 @@ public function createAction()
$form->bindRequest($request);

if ($form->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$em = $this->getDoctrine()->getManager();
$comment = $form->getData();
$form = $this->getRequest()->get('liuggio_HelpDeskBundle_commenttype');
$ticket_id = $form['ticket'];
Expand Down
5 changes: 2 additions & 3 deletions Controller/TicketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public function showAction($id)
$comment = $this->get('liuggio_help_desk.ticket.manager')
->createComment();

$comment->setCreatedBy($user);
$ticket_form = $this->createForm(new CloseTicketType($entity->getId()));
$comment_form = $this->createForm(new CommentType($entity->getId()), $comment);
if ($entity->getState()->getCode() == TicketState::STATE_CLOSED) {
Expand Down Expand Up @@ -178,7 +177,7 @@ public function createAction()
*/
public function closeAction($id)
{
$em = $this->getDoctrine()->getEntityManager();
$em = $this->getDoctrine()->getManager();
$entity = $this->get('liuggio_help_desk.ticket.manager')
->getTicketRepository()
->find($id);
Expand Down Expand Up @@ -230,7 +229,7 @@ public function rateAction()
$ticket_id = $formData['ticket_id'];
$rate_val = $formData['rate'];

$em = $this->getDoctrine()->getEntityManager();
$em = $this->getDoctrine()->getManager();

$entity = $this->get('liuggio_help_desk.ticket.manager')
->getTicketRepository()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Liuggio\HelpDeskBundle\Exception;


class TicketAdminController extends Controller
class TicketOperatorController extends Controller
{
/**
* Lists all Ticket entities.
Expand Down Expand Up @@ -52,14 +52,18 @@ public function indexAction($state = Ticket::STATE_OPEN)
$ticketRepository = $this->get('liuggio_help_desk.ticket.manager')
->getTicketRepository();


$tickets = $ticketRepository->findTicketsByStatesAndOperator($user, $states, $request_pattern);
$categoryRepo = $this->get('liuggio_help_desk_category.manager')->getEntityRepository();

$categories = $categoryRepo->findByOperator($user);

// @TODO Pagination
return $this->render('LiuggioHelpDeskBundle:TicketAdmin:index.html.twig', array(
return $this->render('LiuggioHelpDeskBundle:TicketOperator:index.html.twig', array(
'entities' => $tickets,
'form' => $form->createView(),
'state' => $state
'state' => $state,
'categories' => $categories
));

}
Expand All @@ -72,7 +76,7 @@ public function indexAction($state = Ticket::STATE_OPEN)
public function showAction($id)
{
$operator = $this->get('security.context')->getToken()->getUser();
$em = $this->getDoctrine()->getEntityManager();
$em = $this->getDoctrine()->getManager();
$entity = $ticketRepository = $this->get('liuggio_help_desk.ticket.manager')
->getTicketRepository()
->find($id);
Expand All @@ -93,11 +97,11 @@ public function showAction($id)
$comment_form = $this->createForm(new CommentType($entity->getId()), $comment);
//Closed is logic maybe into Manager
if ($entity->getState()->getCode() == TicketState::STATE_CLOSED) {
return $this->render('LiuggioHelpDeskBundle:TicketAdmin:show_closed.html.twig', array(
return $this->render('LiuggioHelpDeskBundle:TicketOperator:show_closed.html.twig', array(
'entity' => $entity,
));
} else {
return $this->render('LiuggioHelpDeskBundle:TicketAdmin:show_open.html.twig', array(
return $this->render('LiuggioHelpDeskBundle:TicketOperator:show_open.html.twig', array(
'entity' => $entity,
'comment_create_admin' => $comment_form->createView()
));
Expand Down
25 changes: 21 additions & 4 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,29 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('liuggio_help_desk');
$rootNode = $treeBuilder->root('liuggio_help_desk')->children();
$rootNode
->scalarNode('object_manager')->defaultValue('doctrine.orm.default_entity_manager')->end()

// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.
->arrayNode('class')
->addDefaultsIfNotSet()
->children()
->scalarNode('user')->isRequired()->end()
->scalarNode('ticket')->defaultValue('Application\\Liuggio\\HelpDeskBundle\\Entity\\Ticket')->end()
->scalarNode('comment')->defaultValue('Application\\Liuggio\\HelpDeskBundle\\Entity\\Comment')->end()
->scalarNode('category')->defaultValue('Application\\Liuggio\\HelpDeskBundle\\Entity\\Category')->end()
->end()
->end()

->arrayNode('email')
->addDefaultsIfNotSet()
->children()
->scalarNode('sender')->isRequired()->end()
->scalarNode('subject_prefix')->defaultValue('[help desk]')->end()
->end()
->end();

return $treeBuilder;
}

}
97 changes: 97 additions & 0 deletions DependencyInjection/LiuggioHelpDeskExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

use Sonata\EasyExtendsBundle\Mapper\DoctrineCollector;
/**
* This is the class that loads and manages your bundle configuration
*
Expand All @@ -24,5 +25,101 @@ public function load(array $configs, ContainerBuilder $container)

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');

$container->setAlias('liuggio_help_desk.object_manager', $config['object_manager']);
$this->registerDoctrineMapping($config);
$this->registerParameters($container, $config);
}

/**
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
* @param array $config
*/
public function registerParameters(ContainerBuilder $container, array $config)
{
$container->setParameter('liuggio_help_desk.ticket.class', $config['class']['ticket']);
$container->setParameter('liuggio_help_desk.comment.class', $config['class']['comment']);
$container->setParameter('liuggio_help_desk.category.class', $config['class']['category']);
$container->setParameter('liuggio_help_desk.email.sender', $config['email']['sender']);
$container->setParameter('liuggio_help_desk.email.subject_prefix', $config['email']['subject_prefix']);
}

/**
* @param array $config
*/
public function registerDoctrineMapping(array $config)
{
if (!class_exists($config['class']['ticket'])) {
return;
}

$collector = DoctrineCollector::getInstance();
/*
* Comment has manyToOne with Ticket
* manyToOne with User
* */

$collector->addAssociation($config['class']['comment'], 'mapManyToOne', array(
'fieldName' => 'ticket',
'targetEntity' => $config['class']['ticket']
));
$collector->addAssociation($config['class']['comment'], 'mapManyToOne', array(
'fieldName' => 'createdBy',
'targetEntity' => $config['class']['user']
));
/*
* Ticket has oneToMany with Comment
* manyToOne with Category
* manyToOne with User
* */
$collector->addAssociation($config['class']['ticket'], 'mapOneToMany', array(
'fieldName' => 'comments',
'targetEntity' => $config['class']['comment'],
'cascade' => array(
'remove',
'persist',
'refresh',
'merge',
'detach',
),
'mappedBy' => 'ticket',
'orphanRemoval' => false,
));

$collector->addAssociation($config['class']['ticket'], 'mapManyToOne', array(
'fieldName' => 'category',
'targetEntity' => $config['class']['category']
));

$collector->addAssociation($config['class']['ticket'], 'mapManyToOne', array(
'fieldName' => 'createdBy',
'targetEntity' => $config['class']['user']
));


/**
*
* Category has manyToMany with User
*
*/
$collector->addAssociation($config['class']['category'], 'mapManyToMany', array(
'fieldName' => 'operators',
'targetEntity' => $config['class']['user'],
'joinTable' => array(
'name' => 'ticket__category_user',
'joinColumns' => array(
array(
'name' => 'Category_id',
'referencedColumnName' => 'id'
),
),
'inverseJoinColumns' => array(
array(
'name' => 'User_id',
'referencedColumnName' => 'id'
),
),
),
));
}
}
Loading

0 comments on commit 3ce1a83

Please sign in to comment.