public static function Redirect($ctrl, $action = "Index", $param = null) { if (!is_null($param)) { throw new \Exception("Not Implemented"); } header("Location: " . CommonController::GetLink($ctrl, $action)); }
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: 30/09/2015 * Time: 07:38 */ use src\controllers\CommonController; use Doctrine\ORM\Tools\Setup; use Doctrine\ORM\EntityManager; require_once "vendor/autoload.php"; $isDevMode = true; $config = Setup::createXMLMetadataConfiguration(array(__DIR__ . "/src/xml"), $isDevMode); $connectionParams = array('dbname' => 'audio', 'user' => 'root', 'password' => '', 'host' => 'localhost', 'driver' => 'pdo_mysql'); $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); $entityManager = EntityManager::create($conn, $config); Twig_Autoloader::register(); $loader = new Twig_Loader_Filesystem('./src/views'); $twig = new Twig_Environment($loader, array('cache' => false)); CommonController::Initialize($twig, $entityManager);
public static function Redirect($ctrl, $action = "Index", $param = null) { header("Location: " . CommonController::GetLink($ctrl, $action, $param)); }
public function Show404() { CommonController::SetView("home", "404", []); CommonController::Display(true); }
public function GetCollection($id) { if (CommonController::IsAuthentified()) { $wSCtrl = new WebServicesController(); $response = $wSCtrl->Call("Collection", "GET", ["id" => $id]); return json_decode($response, true); } return null; }
<?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]);