<?php
namespace ApplicationBundle\Controller;
use ApplicationBundle\Modules\Authentication\Constants\UserConstants; use ApplicationBundle\Modules\Api\Constants\ApiConstants;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class GenericController extends Controller
{
public function cleanUtf8($data)
{
if (is_array($data)) {
return array_map([$this, 'cleanUtf8'], $data);
}
if (is_string($data)) {
return mb_convert_encoding($data, 'UTF-8', 'UTF-8');
}
return $data;
}
/**
* Returns the logged user id
*
* @param object $req
*
* @return integer
*/
public function loggedUserId($req)
{
$session = $req->getSession();
return $session->get(UserConstants::USER_ID);
}
/**
* Returns the logged user type
*
* @param object $req
*
* @return integer
*/
public function loggedUserType($req)
{
$session = $req->getSession();
return $session->get(UserConstants::USER_TYPE);
}
/**
* Returns the logged user login id
*
* @param object $req
*
* @return integer
*/
public function getLoggedUserLoginId($req)
{
$session = $req->getSession();
return $session->get(UserConstants::USER_LOGIN_ID);
}
public function getLoggedUserCompanyId($req)
{
$session = $req->getSession();
return $session->get(UserConstants::USER_COMPANY_ID);
}
public function getSysUser($id)
{
$em = $this->getDoctrine()->getManager();
$user = $em -> getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(['userId'=>$id]);
return $user;
}
}