private function GetCurrentCollection() { $uri = preg_split('@/@', CommonController::GetCurrentUri(), NULL, PREG_SPLIT_NO_EMPTY); $CollectionId = $uri[Count($uri) - 1]; $WSCtrl = new WebServicesController(); return $WSCtrl->Call("Collection", "GET", [$CollectionId]); }
public function IsAuthorized() { $uri = CommonController::GetCurrentUri(); $explUri = explode("/", $uri); $id = $explUri[count($explUri) - 1]; $repo = CommonController::$EntityManager->getRepository('user'); $entity = $repo->find($id); if ($entity !== null) { $this->user = $entity; return true; } return false; }
public function DoGet() { $uri = CommonController::GetCurrentUri(); $explUri = explode("/", $uri); $id = isset($explUri[array_search('Collection', $explUri) + 1]) ? $explUri[array_search('Collection', $explUri) + 1] : null; /** @var EntityManager $em */ $em = CommonController::$EntityManager; if (is_null($id)) { $entities = $em->getRepository('collection')->findBy(array('idUser' => $this->userId)); $collections = array(); /** @var \Collection $entity */ foreach ($entities as $entity) { array_push($collections, array("idCollection" => $entity->getIdCollection(), "label" => $entity->getLabel())); } return json_encode($collections); } else { /** @var \Collection $collection */ $collection = $em->getRepository("Collection")->find($id); if (!is_null($collection) && $collection->getIdUser()->getIdUser() == $this->userId) { $audios = $em->getRepository("audio")->findBy(array("idCollection" => $collection->getIdCollection())); $children = $em->getRepository("Collection")->findBy(array("idParent" => $collection->getIdParent())); $formatedAudio = array(); $formatedChildren = array(); if ($audios > 0) { /** @var \Audio $audio */ foreach ($audios as $audio) { array_push($formatedAudio, array("id" => $audio->getIdAudio(), "label" => $audio->getLabel())); } } else { if ($children > 0) { /** @var \Collection $child */ foreach ($children as $child) { array_push($formatedChildren, array("id" => $child->getIdCollection(), "label" => $child->getLabel())); } } } return json_encode(array("collection" => array("id" => $collection->getIdCollection(), "label" => $collection->getLabel(), "description" => $collection->getDescription()), "audios" => $formatedAudio, "children" => $formatedChildren)); } return null; } }
public function DoPost() { $uri = CommonController::GetCurrentUri(); $explUri = explode("/", $uri); $id = $explUri[count($explUri) - 2]; $repo = CommonController::$EntityManager->getRepository('audio'); $audio = $repo->find($id); if ($audio !== null) { $UserRepo = CommonController::$EntityManager->getRepository('User'); $user = $UserRepo->find('00000000001'); if ($user !== null) { $Listening = new \Listening(); $Listening->setDatetime(new \DateTime("now")); $Listening->setIdAudio($audio); $Listening->setIdUser($user); $Listening->setState($explUri[count($explUri) - 1]); CommonController::$EntityManager->persist($Listening); CommonController::$EntityManager->flush(); return true; } } return false; }
<?php /** * Created by PhpStorm. * User: Arthur * Date: 01/10/2015 * Time: 17:27 */ require_once __DIR__ . '/bootstrap.php'; use src\controllers\CommonController; use src\controllers\WebServicesController; use src\webServices; $WSCtrl = new WebServicesController(); $uri = CommonController::GetCurrentUri(); $explodedUri = preg_split('@/@', CommonController::GetCurrentUri(), NULL, PREG_SPLIT_NO_EMPTY); echo $WSCtrl->Process($explodedUri[1]);