<?php
namespace App\Entity;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Security;
use Smt\CoreBundle\Service\SmtApi;
/**
* Corporate Client
*
* @author jairo.erazo
*/
class Client{
private $Lo_SmtApi;
private $Lo_Security;
private $o_Session;
public function __construct(SmtApi $Ao_SmtApi, Security $security, SessionInterface $session){
$this->Lo_SmtApi = $Ao_SmtApi;
$this->Lo_Security = $security;
$this->o_Session = $session;
}
/*
* Die Funktion speichert die Daten des Kundes im SMT School
*/
public function setClient($Ao_Data) {
$Ls_EndPoint = 'ClientsTool/setClient';
$La_Data['Form'] = $Ao_Data;
$Lo_Header = 'Cookie: ' . $this->o_Session->get('core/a_Person/LoginHeaders/Set-Cookie');
$Ls_Data = json_encode($La_Data);
$Ls_Answer = $this->Lo_SmtApi->callApi('POST', $Ls_EndPoint, $Ls_Data, true, $Lo_Header);
return json_decode($Ls_Answer);
}
/*
* Die Funktion schikt die Daten des Kundes
*/
public function getClient($Ai_ClientId, $Ai_AddressRoleID) {
$Ls_EndPoint = 'ClientsTool/getClient';
$La_Data = [
"i_ClientId" => $Ai_ClientId,
"i_AddressRoleID" => $Ai_AddressRoleID
];
$Lo_Header = 'Cookie: ' . $this->o_Session->get('core/a_Person/LoginHeaders/Set-Cookie');
$Ls_Answer = $this->Lo_SmtApi->callApi('GET', $Ls_EndPoint, $La_Data, true, $Lo_Header);
return json_decode($Ls_Answer);
}
/*
* Die Funktion schikt die ClientID, die zu einem User gehört
*/
public function getClientIDFromAgent($Ai_AgentPersonID) {
$Ls_EndPoint = 'ClientsTool/getClientIDFromAgent';
$La_Data = [
"Li_PersonID" => $Ai_AgentPersonID
];
$Lo_Header = 'Cookie: ' . $this->o_Session->get('core/a_Person/LoginHeaders/Set-Cookie');
$Ls_Answer = $this->Lo_SmtApi->callApi('GET', $Ls_EndPoint, $La_Data, true, $Lo_Header);
$Lo_Answer = json_decode($Ls_Answer);
$Lo_ClientID = json_encode($Lo_Answer->Result);
return $Lo_ClientID;
}
/*
* Die Funktion schikt die Client IDs, die zu einem User gehört
*/
public function getClientsPersonIDFromAgent($Ai_AgentPersonID) {
$Li_AgentId = $Ai_AgentPersonID;
if ($Ai_AgentPersonID == 'user') {
$Lo_User = $this->Lo_Security->getUser();
$Li_AgentId = $Lo_User->getPersonID();
} // if
$Ls_EndPoint = 'ClientsTool/getClientsIDFromAgent';
$La_Data = [
"Li_PersonID" => $Li_AgentId
];
$Lo_Header = 'Cookie: ' . $this->o_Session->get('core/a_Person/LoginHeaders/Set-Cookie');
$Ls_Answer = $this->Lo_SmtApi->callApi('GET', $Ls_EndPoint, $La_Data, true, $Lo_Header);
$Lo_Answer = json_decode($Ls_Answer);
return $Lo_Answer->Result;
}
/*
* Die Funktion schikt die Client-Liste, die zu einem User gehört
*/
public function getAgentCompanies($Ai_AgentPersonID, $Ai_AddressRoleID) {
$Li_AgentId = $Ai_AgentPersonID;
if ($Ai_AgentPersonID == 'user') {
$Lo_User = $this->Lo_Security->getUser();
$Li_AgentId = $Lo_User->getPersonID();
} // if
$Ls_EndPoint = 'ClientsTool/getCompaniesFromAgentPersonID';
$La_Data = [
"i_PersonID" => $Li_AgentId,
"i_AddressRoleID" => $Ai_AddressRoleID
];
$Lo_Header = 'Cookie: ' . $this->o_Session->get('core/a_Person/LoginHeaders/Set-Cookie');
$Ls_Answer = $this->Lo_SmtApi->callApi('GET', $Ls_EndPoint, $La_Data, true, $Lo_Header);
return json_decode($Ls_Answer);
}
/*
* Die Funktion schikt eine Liste der Kunden
*/
public function searchClient($As_ClientName, $Ai_AddressRoleID) {
$Ls_EndPoint = 'SalesTool/searchClient';
$Lo_User = $this->Lo_Security->getUser();
$Li_PersonID = $Lo_User->getPersonID();
$La_WordsSearch = explode(" ", $As_ClientName);
$La_Data = [
"a_WordsSearch" => $La_WordsSearch,
"i_PersonID" => $Li_PersonID,
"i_AddressRoleID" => $Ai_AddressRoleID
];
$Ls_Data = json_encode($La_Data);
$Lo_Header = 'Cookie: ' . $this->o_Session->get('core/a_Person/LoginHeaders/Set-Cookie');
$Ls_Answer = $this->Lo_SmtApi->callApi('POST', $Ls_EndPoint, $Ls_Data, true, $Lo_Header);
return json_decode($Ls_Answer);
}
/*
* Die Funktion schikt eine Liste von gebuchte Kurse
*/
public function getClientCourses($Ai_ClientId, $As_CourseGroup, $Ai_AddressRoleID) {
$Ls_ApiUrl = 'ClientsTool/getClientCourses';
$Lo_User = $this->Lo_Security->getUser();
$Li_PersonID = $Lo_User->getPersonID();
$La_Data = [
"i_ClientID" => $Ai_ClientId,
"s_CourseGroup" => $As_CourseGroup,
"i_PersonID" => $Li_PersonID,
"i_AddressRoleID" => $Ai_AddressRoleID
];
$Lo_Header = 'Cookie: ' . $this->o_Session->get('core/a_Person/LoginHeaders/Set-Cookie');
$Ls_Answer = $this->Lo_SmtApi->callApi('GET', $Ls_ApiUrl, $La_Data, true, $Lo_Header);
return json_decode($Ls_Answer);
}
/*
* Die Funktion schikt die Details von einem Kurs
*/
public function getClientCourseDetails($Ai_CourseId, $Ai_AddressRoleID) {
$Ls_ApiUrl = 'ClientsTool/getClientCourseDetails';
$Lo_User = $this->Lo_Security->getUser();
$Li_PersonID = $Lo_User->getPersonID();
$La_Data = [
"i_CourseId" => $Ai_CourseId,
"i_PersonID" => $Li_PersonID,
"i_AddressRoleID" => $Ai_AddressRoleID
];
$Lo_Header = 'Cookie: ' . $this->o_Session->get('core/a_Person/LoginHeaders/Set-Cookie');
$Ls_Answer = $this->Lo_SmtApi->callApi('GET', $Ls_ApiUrl, $La_Data, true, $Lo_Header);
return json_decode($Ls_Answer);
}
/*
* Die Funktion schickt die Liste von Mitarbeiteranfragen
*/
public function getEmployeeRequest($Ai_ClientId, $Ai_AddressRoleID)
{
$Ls_ApiUrl = 'ClientsTool/employeeRequest';
$Lo_User = $this->Lo_Security->getUser();
$Li_PersonID = $Lo_User->getPersonID();
$La_Data = [
"i_ClientId" => $Ai_ClientId,
"i_PersonID" => $Li_PersonID,
"i_AddressRoleID" => $Ai_AddressRoleID
];
$Lo_Header = 'Cookie: ' . $this->o_Session->get('core/a_Person/LoginHeaders/Set-Cookie');
$Ls_Answer = $this->Lo_SmtApi->callApi('GET', $Ls_ApiUrl, $La_Data, true, $Lo_Header);
return json_decode($Ls_Answer);
}
/*
* Die Funktion schickt die Liste von Mitarbeiteranfragen
*/
public function getCourseRequest($Ai_ClientId, $Ai_AddressRoleID)
{
$Ls_ApiUrl = 'ClientsTool/courseRequests';
$Lo_User = $this->Lo_Security->getUser();
$Li_PersonID = $Lo_User->getPersonID();
$La_Data = [
"i_ClientId" => $Ai_ClientId,
"i_PersonID" => $Li_PersonID,
"i_AddressRoleID" => $Ai_AddressRoleID
];
$Lo_Header = 'Cookie: ' . $this->o_Session->get('core/a_Person/LoginHeaders/Set-Cookie');
$Ls_Answer = $this->Lo_SmtApi->callApi('GET', $Ls_ApiUrl, $La_Data, true, $Lo_Header);
return json_decode($Ls_Answer);
}
/*
* Die Funktion abbrecht die Kursangrafe
*/
public function cancelCourseRequest($Ao_RequestData) {
$Ls_EndPoint = 'ClientsTool/cancelCourseRequest';
$La_Data['o_RequestData'] = $Ao_RequestData;
$Lo_User = $this->Lo_Security->getUser();
$Li_PersonID = $Lo_User->getPersonID();
$La_Data['i_PersonID'] = $Li_PersonID;
$Lo_Header = 'Cookie: ' . $this->o_Session->get('core/a_Person/LoginHeaders/Set-Cookie');
$Ls_Data = json_encode($La_Data);
$Ls_Answer = $this->Lo_SmtApi->callApi('POST', $Ls_EndPoint, $Ls_Data, true, $Lo_Header);
return json_decode($Ls_Answer);
}
/*
* Die Funktion bestätigt die Kursangrafe
*/
public function acceptCourseRequest($Ao_RequestData) {
$Ls_EndPoint = 'ClientsTool/acceptCourseRequest';
$La_Data['o_RequestData'] = $Ao_RequestData;
$Lo_User = $this->Lo_Security->getUser();
$Li_PersonID = $Lo_User->getPersonID();
$La_Data['i_PersonID'] = $Li_PersonID;
$Lo_Header = 'Cookie: ' . $this->o_Session->get('core/a_Person/LoginHeaders/Set-Cookie');
$Ls_Data = json_encode($La_Data);
$Ls_Answer = $this->Lo_SmtApi->callApi('POST', $Ls_EndPoint, $Ls_Data, true, $Lo_Header);
return json_decode($Ls_Answer);
}
/*
* Die Funktion addiert eine Firma zu einem Kurs
*/
public function bookAsCompany($Ao_BookingData) {
$Ls_EndPoint = 'ClientsTool/bookAsCompany';
$Lo_User = $this->Lo_Security->getUser();
$La_Data['o_BookingData'] = $Ao_BookingData;
$La_Data['i_PersonID'] = $Lo_User->getPersonID();
$Lo_Header = 'Cookie: ' . $this->o_Session->get('core/a_Person/LoginHeaders/Set-Cookie');
$Ls_Data = json_encode($La_Data);
$Ls_Answer = $this->Lo_SmtApi->callApi('POST', $Ls_EndPoint, $Ls_Data, true, $Lo_Header);
return json_decode($Ls_Answer);
}
/*
* Die Funktion schickt die AgentID einer Firma
*/
public function getAgentIDFromClient($Ai_ClientId)
{
$Ls_ApiUrl = 'ClientsTool/getAgentIDFromClient';
$Lo_User = $this->Lo_Security->getUser();
$Li_PersonID = $Lo_User->getPersonID();
$La_Data = [
"i_ClientId" => $Ai_ClientId,
"i_PersonID" => $Li_PersonID
];
$Lo_Header = 'Cookie: ' . $this->o_Session->get('core/a_Person/LoginHeaders/Set-Cookie');
$Ls_Answer = $this->Lo_SmtApi->callApi('GET', $Ls_ApiUrl, $La_Data, true, $Lo_Header);
return json_decode($Ls_Answer);
}
/*
* Die Funktion listClientCourseParticipants schickt die Liste von Participants eines Kurs einer Firma
*/
public function listClientCourseParticipants($Ai_CourseId, $Ai_ClientID, $Ai_AddressRoleID)
{
$Ls_ApiUrl = 'ClientsTool/clientCourseParticipants';
$Lo_User = $this->Lo_Security->getUser();
$Li_PersonID = $Lo_User->getPersonID();
$La_Data = [
"i_CourseID" => $Ai_CourseId,
"i_PersonID" => $Li_PersonID,
"i_ClientID" => intval($Ai_ClientID),
"i_AddressRoleID" => $Ai_AddressRoleID
];
$Lo_Header = 'Cookie: ' . $this->o_Session->get('core/a_Person/LoginHeaders/Set-Cookie');
$Ls_Answer = $this->Lo_SmtApi->callApi('GET', $Ls_ApiUrl, $La_Data, true, $Lo_Header);
return json_decode($Ls_Answer);
}
/*
* Die Funktion hinzufügt einen Mitarbeiter
*/
public function addEmployee($Ao_RequestData) {
$Ls_EndPoint = 'ClientsTool/addEmployee';
$La_Data['o_RequestData'] = $Ao_RequestData;
$Lo_User = $this->Lo_Security->getUser();
$Li_PersonID = $Lo_User->getPersonID();
$La_Data['i_PersonID'] = $Li_PersonID;
$Lo_Header = 'Cookie: ' . $this->o_Session->get('core/a_Person/LoginHeaders/Set-Cookie');
$Ls_Data = json_encode($La_Data);
$Ls_Answer = $this->Lo_SmtApi->callApi('POST', $Ls_EndPoint, $Ls_Data, true, $Lo_Header);
return json_decode($Ls_Answer);
}
/*
* Die Funktion löscht einen Mitarbeiter
*/
public function removeEmployee($Ao_RequestData) {
$Ls_EndPoint = 'ClientsTool/removeEmployee';
$La_Data['o_RequestData'] = $Ao_RequestData;
$Lo_User = $this->Lo_Security->getUser();
$Li_PersonID = $Lo_User->getPersonID();
$La_Data['i_PersonID'] = $Li_PersonID;
$Lo_Header = 'Cookie: ' . $this->o_Session->get('core/a_Person/LoginHeaders/Set-Cookie');
$Ls_Data = json_encode($La_Data);
$Ls_Answer = $this->Lo_SmtApi->callApi('POST', $Ls_EndPoint, $Ls_Data, true, $Lo_Header);
return json_decode($Ls_Answer);
}
}