PHP code example of kdrmklabs / ticket-bundle

1. Go to this page and download the library: Download kdrmklabs/ticket-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kdrmklabs / ticket-bundle example snippets


// file: app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Kdrmklabs\Bundle\TicketBundle\KdrmklabsTicketBundle(),
        // ...
        // Your application bundles
    );
}

// file: src/AppBundle/Listener/DoctrineExtensionListener.php

namespace AppBundle\Listener;

use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class DoctrineExtensionListener implements ContainerAwareInterface
{
    /**
     * @var ContainerInterface
     */
    protected $container;

    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }

    public function onLateKernelRequest(GetResponseEvent $event)
    {
        $translatable = $this->container->get('gedmo.listener.translatable');
        $translatable->setTranslatableLocale($event->getRequest()->getLocale());
    }

    public function onKernelRequest(GetResponseEvent $event)
    {
        $securityContext = $this->container->get('security.context', ContainerInterface::NULL_ON_INVALID_REFERENCE);
        if (null !== $securityContext && null !== $securityContext->getToken() && $securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
            $loggable = $this->container->get('gedmo.listener.loggable');
            $loggable->setUsername($securityContext->getToken()->getUsername());
        }
    }
}

// file: 

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * User
 *
 * @ORM\Table(name="user")
 * @ORM\Entity
 */
class User implements \Kdrmklabs\Bundle\TicketBundle\Model\UserInterface
{
    public function getId(){
        
    }
}


/**
* @Route("/create")
*/
public function createAction() {
   $kdrmklabs_ticket_service = $this->get('kdrmklabs_ticket.ticket_service');
   $ticket = $kdrmklabs_ticket_service->createTicket("message", "subject", 1, 1, 1);

   return $this->redirectToRoute('kdrmklabs_ticket_show', array('id' => $ticket->getId()));
}

createTicket(
    string $initial_message, 
    string $subject, 
    int|Kdrmklabs\Bundle\TicketBundle\Model\UserInterface|AppBundle\Entity\User $user, 
    int|Kdrmklabs\Bundle\TicketBundle\Entity\TicketCategory $category,
    int|Kdrmklabs\Bundle\TicketBundle\Entity\TicketStatus $status 
    [, int $dateAdded])

/**
* @Route("/delete/{id}")
*/
public function deleteAction($id) {
   $kdrmklabs_ticket_service = $this->get('kdrmklabs_ticket.ticket_service');
   $kdrmklabs_ticket_service->deleteTicket($id);

   return $this->redirectToRoute('kdrmklabs_ticket_index');
}

deleteTicket( int|Kdrmklabs\Bundle\TicketBundle\Entity\Ticket $ticket)

/**
* @Route("/reply/{id}")
*/
public function replyAction($id) {
   $kdrmklabs_ticket_service = $this->get('kdrmklabs_ticket.ticket_service');
   $ticket = $kdrmklabs_ticket_service->replyTicket($id, 1, "reply");

   return $this->redirectToRoute('kdrmklabs_ticket_show', array('id' => $ticket->getId()));
}

replyTicket(
    int|Kdrmklabs\Bundle\TicketBundle\Entity\Ticket $ticket, 
    int|Kdrmklabs\Bundle\TicketBundle\Model\UserInterface|AppBundle\Entity\User $user, 
    string $message
    [, int $dateAdded])

/**
* @Route("/show/{id}", name="kdrmklabs_ticket_show")
* @Template()
*/
public function showAction($id) {
   $kdrmklabs_ticket_service = $this->get('kdrmklabs_ticket.ticket_service');
   $ticket = $kdrmklabs_ticket_service->getTicket($id);

   return array('ticket' => $ticket);
}

getTicket( int|string $id_ticket )

/**
* @Route("/", name="kdrmklabs_ticket_index")
* @Template()
*/
public function indexAction(Request $request) {
   $kdrmklabs_ticket_service = $this->get('kdrmklabs_ticket.ticket_service');
   $query = $kdrmklabs_ticket_service->getTickets(); // get all tickets

   $paginator = $this->get('knp_paginator');
   $pagination = $paginator->paginate(
       $query->getQuery(),
       $request->query->get('page', 1),
       10
   );

   return array('pagination' => $pagination);
}

getTickets(
        [ int|Kdrmklabs\Bundle\TicketBundle\Model\UserInterface|AppBundle\Entity\User $author,
        int|Kdrmklabs\Bundle\TicketBundle\Entity\TicketCategory $category,
        int|Kdrmklabs\Bundle\TicketBundle\Entity\TicketStatus $status 
        int $from_datetime,
        int $to_datetime,
        boolean $closed ]
    )

/**
* @Route("/close/{id}")
*/
public function closeAction($id){
   $kdrmklabs_ticket_service = $this->get('kdrmklabs_ticket.ticket_service');
   $kdrmklabs_ticket_service->closeTicket($id);

   return $this->redirectToRoute('kdrmklabs_ticket_index');
}

closeTicket( id|string $id_ticket )

// access to UserInterface from controller
$this->get('kdrmklabs_ticket.user_repository')->find($id_user);

namespace Kdrmklabs\Bundle\TicketBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;

class DefaultController extends Controller {

    /**
     * @Route("/", name="kdrmklabs_ticket_index")
     * @Template()
     */
    public function indexAction(Request $request) {
        $kdrmklabs_ticket_service = $this->get('kdrmklabs_ticket.ticket_service');
        $query = $kdrmklabs_ticket_service->getTickets();

        $paginator = $this->get('knp_paginator');
        $pagination = $paginator->paginate(
            $query->getQuery(),
            $request->query->get('page', 1),
            10
        );
        
        return array('pagination' => $pagination);
    }

    /**
     * @Route("/create")
     */
    public function createAction() {
        $id_user = 1;
        $id_category = 1;
        $id_status = 1;
        $kdrmklabs_ticket_service = $this->get('kdrmklabs_ticket.ticket_service');
        $ticket = $kdrmklabs_ticket_service->createTicket("message", "subject", $id_user, $id_category, $id_status);
        
        return $this->redirectToRoute('kdrmklabs_ticket_show', array('id' => $ticket->getId()));
    }

    /**
     * @Route("/show/{id}", name="kdrmklabs_ticket_show")
     * @Template()
     */
    public function showAction($id) {
        $kdrmklabs_ticket_service = $this->get('kdrmklabs_ticket.ticket_service');
        $ticket = $kdrmklabs_ticket_service->getTicket($id);

        return array('ticket' => $ticket);
    }

    /**
     * @Route("/reply/{id}")
     */
    public function replyAction($id) {
        $id_user = 1;
        $kdrmklabs_ticket_service = $this->get('kdrmklabs_ticket.ticket_service');
        $ticket = $kdrmklabs_ticket_service->replyTicket($id, $id_user, "reply");
        
        return $this->redirectToRoute('kdrmklabs_ticket_show', array('id' => $ticket->getId()));
    }

    /**
     * @Route("/delete/{id}")
     */
    public function deleteAction($id) {
        $kdrmklabs_ticket_service = $this->get('kdrmklabs_ticket.ticket_service');
        $kdrmklabs_ticket_service->deleteTicket($id);
        
        return $this->redirectToRoute('kdrmklabs_ticket_index');
    }

    /**
     * @Route("/close/{id}")
     */
    public function closeAction($id){
        $kdrmklabs_ticket_service = $this->get('kdrmklabs_ticket.ticket_service');
        $kdrmklabs_ticket_service->closeTicket($id);
        
        return $this->redirectToRoute('kdrmklabs_ticket_index');
    }
}

$ php composer.phar update gedmo/doctrine-extensions