| Current Path : /var/www/v3.cesa.co.za/src/UserBundle/Services/ |
| Current File : /var/www/v3.cesa.co.za/src/UserBundle/Services/UserLevelManager.php |
<?php
namespace App\UserBundle\Services;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Monolog\Logger;
use App\UserBundle\Entity\UserLevel;
use App\UserBundle\Entity\UserList;
/**
* User List Old manager
*
* @author Otto Saayman <otto@igotafrica.com>
* @package UserBundle
* @subpackage UserLevel
* @version 0.0.1
*/
final class UserLevelManager {
/**
* 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 User
*
* @return UserLevel
*/
public function find($id) {
if (strlen($id) <= 0) {
return null;
}
return $this->em->getRepository(UserLevel::class)->find($id);
}
/**
* Get a User by parameters
*
* @param array $params
* @return UserLevel
*/
public function findOneBy($params) {
return $this->em->getRepository(UserLevel::class)->findOneBy($params);
}
/**
* Get a User by parameters
*
* @param array $params
* @return array
*/
public function findBy($params) {
return $this->em->getRepository(UserLevel::class)->findBy($params);
}
/**
* Get all Users
*
* @return array
*/
public function findAll() {
return $this->em->getRepository(UserLevel::class)->findAll();
}
/**
* Save a User
*
* @params UserLevel $userLevel
* @return UserLevel
*/
public function save(UserLevel &$userLevel) {
$this->em->persist($userLevel);
$this->em->flush();
return $userLevel;
}
/**
* Link a User to an access level
*
* @params UserList $userList
* @params integer $userLevelId
* @return UserLevel
*/
public function linkUser(UserList &$userList, $userLevelId) {
$mustAdd = true;
foreach ($userList->getUserLevel() as $userLevelTest) {
if ($userLevelTest->getId() == $userLevelId) {
$mustAdd = false;
}
}
if ($mustAdd) {
$userLevel = $this->findOneBy(array('user_level_id' => $userLevelId));
if (!is_object($userLevel)) {
return;
}
$userLevel->addUserList($userList);
$this->save($userLevel);
}
}
}