124 lines
4.7 KiB
PHP
124 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace Cadoles\CoreBundle\Controller;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
use Symfony\Component\HttpFoundation\Session\Session;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\Form\FormError;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
|
use Symfony\Component\Console\Input\ArrayInput;
|
|
use Symfony\Component\Console\Output\BufferedOutput;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Ramsey\Uuid\Uuid;
|
|
use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|
|
|
use Cadoles\CoreBundle\Entity\User;
|
|
use Cadoles\CoreBundle\Entity\UserGroup;
|
|
use Cadoles\CoreBundle\Entity\UserModo;
|
|
use Cadoles\CoreBundle\Entity\Niveau01;
|
|
use Cadoles\CoreBundle\Entity\Niveau02;
|
|
use Cadoles\WebsocketBundle\Entity\Message;
|
|
|
|
use Cadoles\CoreBundle\Form\UserType;
|
|
|
|
|
|
class RestController extends Controller
|
|
{
|
|
|
|
public function userAction($key, $login, Request $request)
|
|
{
|
|
// Vérification de la clé
|
|
$realkey = $this->getParameter("apikeyninegate");
|
|
if($key!=$realkey) {
|
|
$output["error"]="error key";
|
|
return new Response(json_encode($output), 400);
|
|
}
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
$output = [];
|
|
|
|
// Récupérer l'utilisateur
|
|
$user=$em->getRepository('CadolesCoreBundle:User')->findOneBy(["username"=>$login]);
|
|
if(!$user) {
|
|
$output["error"]="user not exist";
|
|
return new Response(json_encode($output), 400);
|
|
}
|
|
|
|
// Format de sortie
|
|
$output["user"] = [];
|
|
$output["bookmarks"] = [];
|
|
$output["items"] = [];
|
|
$output["itemcategorys"] = [];
|
|
|
|
$bookmarks=null;
|
|
$items=null;
|
|
$itemcategorys=null;
|
|
$weburl="https://".$this->getParameter("weburl")."/".$this->getParameter("alias")."/";
|
|
|
|
$em->getRepository("CadolesPortalBundle:Item")->getUserItems($user,$bookmarks,$items,$itemcategorys,null,3);
|
|
|
|
// Construction de la réponse
|
|
$output["user"]["firstname"] = $user->getFirstname();
|
|
$output["user"]["lasttname"] = $user->getLastname();
|
|
$output["user"]["email"] = $user->getEmail();
|
|
$output["user"]["avatar"] = $weburl."uploads/avatar/".$user->getAvatar();
|
|
$output["user"]["niveau01"] = $user->getNiveau01()->getLabel();
|
|
$output["user"]["niveau02"] = ($user->getNiveau02()?$user->getNiveau02()->getLabel():null);
|
|
|
|
if($bookmarks) {
|
|
foreach($bookmarks as $bookmark) {
|
|
$tmp=[];
|
|
$tmp["id"] = $bookmark->getId();
|
|
$tmp["title"] = $bookmark->getTitle();
|
|
$tmp["url"] = $bookmark->getUrl();
|
|
$tmp["target"] = $bookmark->getTarget();
|
|
$tmp["order"] = 0;
|
|
$tmp["color"] = ($bookmark->getColor()?$bookmark->getColor():$this->get('session')->get('color')["main"]);
|
|
$tmp["icon"] = $weburl.($bookmark->getIcon()?$bookmark->getIcon()->getLabel():"uploads/icon/icon_pin.png");
|
|
|
|
array_push($output["bookmarks"],$tmp);
|
|
}
|
|
}
|
|
|
|
if($items) {
|
|
foreach($items as $item) {
|
|
$tmp=[];
|
|
$tmp["id"] = $item->getId();
|
|
$tmp["title"] = $item->getTitle();
|
|
$tmp["url"] = $item->getUrl();
|
|
$tmp["target"] = $item->getTarget();
|
|
$tmp["order"] = $item->getRoworder();
|
|
$tmp["color"] = ($item->getColor()?$item->getColor():$this->get('session')->get('color')["main"]);
|
|
$tmp["icon"] = $weburl.($item->getIcon()?$item->getIcon()->getLabel():"uploads/icon/icon_pin.png");
|
|
$tmp["essential"] = $item->getEssential();
|
|
$tmp["category"] = $item->getItemcategory()->getId();
|
|
|
|
array_push($output["items"],$tmp);
|
|
}
|
|
}
|
|
|
|
if($itemcategorys) {
|
|
foreach($itemcategorys as $itemcategory) {
|
|
$tmp=[];
|
|
$tmp["id"] = $itemcategory->getId();
|
|
$tmp["title"] = $itemcategory->getLabel();
|
|
$tmp["order"] = $itemcategory->getRoworder();
|
|
$tmp["color"] = ($itemcategory->getColor()?$itemcategory->getColor():$this->get('session')->get('color')["main"]);
|
|
|
|
array_push($output["itemcategorys"],$tmp);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Retour
|
|
return new Response(json_encode($output), 200);
|
|
}
|
|
|
|
}
|