| Current Path : /var/www/v3.cesa.co.za/src/ContentBundle/Services/ |
| Current File : /var/www/v3.cesa.co.za/src/ContentBundle/Services/FormTypeManager.php |
<?php
namespace App\ContentBundle\Services;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Monolog\Logger;
use App\ContentBundle\Entity\FormType;
/**
* Form Types manager
*
* @author Otto Saayman <otto@igotafrica.com>
* @package ContentBundle
* @subpackage Form Types
* @version 0.0.1
*/
final class FormTypeManager {
/**
* Service Container
* @var object
*/
private $container = null;
/**
* Entity manager
* @var object
*/
private $em;
/**
* Class construct
*
* @param ContainerInterface $container
* @param Logger $logger
* @return void
*/
public function __construct(
ContainerInterface $container) {
$this->setContainer($container);
$this->setEm($container->get('doctrine')->getManager('default'));
return;
}
/**
* Get Container
*
* @return ContainerInterface $container
*/
public function getContainer() {
return $this->container;
}
/**
* Set Container
*
* @param ContainerInterface $container
* @return void
*/
public function setContainer($container) {
$this->container = $container;
}
/**
* Get Entity Manager
*
* @return string
*/
public function getEm() {
return $this->em;
}
/**
* Set Container
*
* @param string $em
* @return void
*/
public function setEm($em) {
$this->em = $em;
}
/**
* Get a form type
*
* @param string $id
* @return FormType
*/
public function find($id) {
return $this->getEm()->getRepository(FormType::class)->find($id);
}
/**
* Check if exists and load if not for given Form Type
*
* @param string $formTypeName
* @return FormType
*/
public function checkAndLoad($formTypeName) {
$formType = $this->em->getRepository(FormType::class)->findOneBy(array('type_name' => $formTypeName));
if (!is_object($formType)) {
$formType = new FormType();
$formType->setTypeName($formTypeName);
$this->getEm()->persist($formType);
$this->getEm()->flush();
}
return $formType;
}
}