Пример #1
0
 public function send()
 {
     $content = $this->_content;
     $status = $this->_status;
     $response = new \Symfony\Component\HttpFoundation\JsonResponse($content, $status);
     $response->send();
 }
Пример #2
0
/**
 * Sends a response as json with a status code.
 *
 * @param array $data
 * @param int $status
 */
function respondJson($data = [], $status = HTTP_OK)
{
    $encoded = utf8_encode_array($data);
    $response = new Symfony\Component\HttpFoundation\JsonResponse($encoded, $status);
    $response->setEncodingOptions(JSON_NUMERIC_CHECK);
    $response->send();
}
Пример #3
0
 public function eventsAction()
 {
     $from = $this->get('request')->get('from');
     $until = $this->get('request')->get('to');
     $eventList = array();
     if (\is_numeric($from) && $from > 0 && \is_numeric($until) && $until > 0) {
         $from = $from / 1000;
         $from = \DateTime::createFromFormat('U', $from);
         $until = $until / 1000;
         $until = \DateTime::createFromFormat('U', $until);
         if ($from && $until) {
             $em = $this->get('doctrine.orm.symbb_entity_manager');
             $query = $em->createQuery('SELECT
                     e
                 FROM 
                     SymbbExtensionCalendarBundle:Event e
                 WHERE 
                     e.startDate >= :from AND 
                     e.startDate <= :until AND
                     e.post > 0
                 ORDER BY 
                     e.startDate, e.name ASC')->setParameter('from', $from->format('Y-m-d H:i:s'))->setParameter('until', $until->format('Y-m-d H:i:s'));
             $events = $query->getResult();
             $user = $this->get('symbb.core.user.manager');
             $userGroups = $user->getCurrentUser()->getGroups();
             foreach ($events as $event) {
                 $post = $event->getPost();
                 $groups = $event->getGroups();
                 $check = false;
                 foreach ($groups as $group) {
                     foreach ($userGroups as $userGroup) {
                         if ($userGroup->getId() == $group->getId()) {
                             $check = true;
                             break;
                         }
                     }
                     if ($check) {
                         break;
                     }
                 }
                 if ($post && $check) {
                     $topic = $post->getTopic();
                     $url = $this->generateUrl('symbb_forum_topic_show', array('name' => $topic->getSeoName(), 'id' => $topic->getId()));
                     $url = $url . '#' . $post->getSeoName() . '-' . $post->getId();
                     $start = $event->getStartDate()->getTimestamp();
                     $start = $start * 1000;
                     $end = $event->getEndDate()->getTimestamp();
                     $end = $end * 1000;
                     $eventList[] = array('id' => $event->getId(), 'title' => $event->getName(), 'url' => $url, 'start' => $start, 'end' => $end);
                 }
             }
         }
     }
     $data = array('success' => 1, 'result' => $eventList);
     $response = new \Symfony\Component\HttpFoundation\JsonResponse();
     $response->setData($data);
     return $response;
 }
 /**
  * @Route("/two", name="practice_two")
  * @Template("AcmeDemoBundle:Practice:index.html.twig")
  */
 public function practiceTwoAction(Request $request)
 {
     $numA = $request->query->get('numA', 0);
     $numB = $request->query->get('numB', 0);
     if ($numA * $numB > 100) {
         return $this->redirect($this->generateUrl('practice_one', array('someNumber' => 2)));
     } elseif ($numA < 0 && $numB < 0) {
         throw $this->createNotFoundException('Both numers are lower then zero');
     } else {
         if ($numA + $numB > 10) {
             $result = new \Symfony\Component\HttpFoundation\JsonResponse();
             $result->setData(array('result' => $numA + $numB));
             return $result;
         }
     }
     return array('someNumber' => $numA - $numB);
 }
 public function sendEmailAction(Request $request)
 {
     if ($request->isXmlHttpRequest()) {
         $data = array();
         $response = new \Symfony\Component\HttpFoundation\JsonResponse();
         $username = $request->request->get('username');
         /** @var $user UserInterface */
         $user = $this->container->get('fos_user.user_manager')->findUserByUsernameOrEmail($username);
         if (null === $user) {
             $data['message'] = $this->trans('resetting.request.invalid_username', array('%username%' => $username));
             $response->setData($data)->setStatusCode(400);
             return $response;
         }
         if ($user->isPasswordRequestNonExpired($this->container->getParameter('fos_user.resetting.token_ttl'))) {
             $data['message'] = $this->trans('resetting.password_already_requested', array());
             $response->setData($data)->setStatusCode(400);
             return $response;
         }
         if (null === $user->getConfirmationToken()) {
             /** @var $tokenGenerator \FOS\UserBundle\Util\TokenGeneratorInterface */
             $tokenGenerator = $this->container->get('fos_user.util.token_generator');
             $user->setConfirmationToken($tokenGenerator->generateToken());
         }
         $this->container->get('fos_user.mailer')->sendResettingEmailMessage($user);
         $user->setPasswordRequestedAt(new \DateTime());
         $this->container->get('fos_user.user_manager')->updateUser($user);
         $data['message'] = $this->trans('resetting.check_email', array('%email%' => $username));
         $response->setData($data);
         return $response;
     } else {
         return parent::sendEmailAction($request);
     }
 }
Пример #6
0
 protected function executeSaveLayout()
 {
     if ($this->isXHR()) {
         $layout = psm_POST('layout', 0);
         $this->getUser()->setUserPref('status_layout', $layout);
         $response = new \Symfony\Component\HttpFoundation\JsonResponse();
         $response->setData(array('layout' => $layout));
         return $response;
     }
 }
Пример #7
0
 /**
  * @Route("{clave}/adiciona-a-favoritos/", name="addToFavs", options={"expose":true})
  * @Method("POST")
  */
 public function addToFavsAction($clave)
 {
     $ft = $this->get('session')->get('favs');
     if (is_array($ft)) {
         if (!in_array($clave, $ft['clvs'])) {
             $ft['clvs'][] = trim($clave);
         }
     } else {
         $ft = array('cant' => 1, 'clvs' => array(trim($clave)));
     }
     $ft['cant'] = count($ft['clvs']);
     $this->get('session')->set('favs', $ft);
     $respuesta = new \Symfony\Component\HttpFoundation\JsonResponse();
     return $respuesta->setData($ft['cant']);
 }
Пример #8
0
    $helper = new \Helper\Helper();
    $name = $helper->convertBase64ToTmpFile($photo);
    $url = $request->getScheme() . '://' . $request->getHost() . '/share/' . $name;
    $response = new \Symfony\Component\HttpFoundation\JsonResponse(['url' => $url]);
    $response->send();
});
$app->post('/authTwitter', function () {
    session_start();
    $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
    $_SESSION['image'] = $request->request->get('photo');
    $_SESSION['text'] = $request->request->get('text');
    $connection = new \Abraham\TwitterOAuth\TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
    $request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => TWITTER_OAUTH_ENDPOINT));
    $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
    $authURL = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
    $response = new \Symfony\Component\HttpFoundation\JsonResponse(['url' => $authURL]);
    $response->send();
});
$app->get('/shareTwitter', function () {
    session_start();
    $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
    $_SESSION['oauth_token'] = $request->query->get('oauth_token');
    $_SESSION['oauth_verifier'] = $request->query->get('oauth_verifier');
    $connection = new \Abraham\TwitterOAuth\TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
    $access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $_SESSION['oauth_verifier']));
    $_SESSION['oauth_token'] = $access_token['oauth_token'];
    $_SESSION['oauth_token_secret'] = $access_token['oauth_token_secret'];
    $_SESSION['twitter_user_id'] = $access_token['user_id'];
    $connection = new \Abraham\TwitterOAuth\TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
    $imageURL = $_SESSION['image'];
    $photo = $connection->upload('media/upload', ['media' => $imageURL]);
Пример #9
0
 /**
  * @Route("borrar-foto-del-registro/{clave}/", name="admin-delOneFotoReg", options={"expose":true})
  * @Method({"POST"})
  */
 public function delOneFotoRegAction(Request $req, $clave)
 {
     $resp = array('resp' => TRUE, 'msg' => 'Foto Eliminada', 'cont' => array(), 'rec' => FALSE);
     $asset = realpath($this->getParameter('kernel.root_dir') . '/../web');
     $fotoEliminar = $req->request->get('foto-del');
     if (file_exists($asset . '/data/' . $clave . '.json')) {
         $registro = json_decode(file_get_contents($asset . '/data/' . $clave . '.json'), TRUE);
         //comensamos a eliminar las fotos del sistema de archivos
         if (file_exists($asset . '/fotos/lg/' . $fotoEliminar)) {
             unlink($asset . '/fotos/lg/' . $fotoEliminar);
         }
         if (file_exists($asset . '/fotos/sm/' . $fotoEliminar)) {
             unlink($asset . '/fotos/sm/' . $fotoEliminar);
         }
         if (file_exists($asset . '/fotos/xs/' . $fotoEliminar)) {
             unlink($asset . '/fotos/xs/' . $fotoEliminar);
         }
         //Buscamos y eliminamos la foto de la base de datos
         $rota = count($registro['fotos']['sec']);
         for ($f = 0; $f < $rota; $f++) {
             if ($registro['fotos']['sec'][$f] == $fotoEliminar) {
                 $registro['fotos']['sec'][$f] = 'Foto ' . ($f + 1);
                 file_put_contents($asset . '/data/' . $clave . '.json', json_encode($registro), LOCK_EX);
                 $cambiarPrincipal = $registro['fotos']['pri'] == $fotoEliminar ? TRUE : FALSE;
                 //Si es principal simplemente se sustituye por la primera que queda.
                 if ($cambiarPrincipal) {
                     if (count($registro['fotos']['sec']) > 0) {
                         if (file_exists($asset . '/fotos/xs/' . $registro['fotos']['sec'][0])) {
                             $registro['fotos']['pri'] = $registro['fotos']['sec'][0];
                         } else {
                             $registro['fotos']['pri'] = 'fotografia-principal';
                         }
                     } else {
                         $registro['fotos']['pri'] = 'fotografia-principal';
                     }
                     //Corroboramos que no sea un producto RECOMENDADO
                     $regRec = json_decode(file_get_contents($asset . '/data/__rec__.json'), TRUE);
                     if ($regRec['clave'] == $clave) {
                         try {
                             file_put_contents($asset . '/data/__rec__.json', json_encode($registro), LOCK_EX);
                             $resp['cont'] = array('nombre' => $registro['nombre'], 'datos' => $registro['compresion'], 'foto' => $registro['fotos']['pri'], 'clave' => $registro['clave']);
                             $resp['rec'] = TRUE;
                         } catch (Exception $ex) {
                             $resp['resp'] = FALSE;
                             $resp['msg'] = 'Error desconocido, Intentalo Nuevamente...';
                         }
                     }
                 }
             }
         }
     } else {
         $resp['resp'] = FALSE;
         $resp['msg'] = 'No se encontro el Archivo';
     }
     $respuesta = new \Symfony\Component\HttpFoundation\JsonResponse();
     return $respuesta->setData($resp);
 }
Пример #10
0
 /**
  * @Route("{id}/editando-usuario/", name="adGt-gestEditUsers", options={"expose":true})
  * @ParamConverter("user", class="AppBundle:Users", options={"mapping":{"id":"id"}})
  * @Method({"POST"})
  */
 public function gestEditUserAction(\AppBundle\Entity\Users $user)
 {
     $newObj = array();
     if ($user) {
         $newObj['id'] = $user->getId();
         $newObj['username'] = $user->getUsername();
         $newObj['email'] = $user->getEmail();
     }
     $respuesta = new \Symfony\Component\HttpFoundation\JsonResponse();
     return $respuesta->setData($newObj);
 }
Пример #11
0
 /**
  * Creates a Symfony response object to simplify using the API in Symfony or frameworks that use the
  * HttpFoundation component
  *
  * @param \AppShed\Remote\HTML\Settings $settings
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function getSymfonyResponse($settings = null)
 {
     $headers = static::getCORSResponseHeaders();
     if (static::isOptionsRequest()) {
         return new \Symfony\Component\HttpFoundation\Response('', 200, $headers);
     }
     if (!$settings) {
         $settings = $this->getSettings();
     }
     $data = $this->getResponseObject($settings);
     $data['remote'] = ['url' => $settings->getFetchUrl(), 'refreshAfter' => $this->refreshAfter];
     $data['remote'][$settings->getFetchUrl()] = $data['settings']['main'];
     $response = new \Symfony\Component\HttpFoundation\JsonResponse($data, 200, $headers);
     if ($callback = $this->getCallback()) {
         $response->setCallback($callback);
     }
     return $response;
 }
Пример #12
0
<?php

include_once __DIR__ . '/vendor/autoload.php';
/** @var \Swagger\Annotations\Swagger $swagger */
$swagger = \Swagger\scan([__DIR__ . '/examples/api/controller', __DIR__ . '/examples/api/model']);
$wrapper = new \Ovr\Swagger\SwaggerWrapper($swagger);
$operation = $wrapper->getOperationByName('getUserById');
//dump($operation);
$response = new \Symfony\Component\HttpFoundation\JsonResponse();
$response->setData(['data' => (object) ['id' => 1, 'name' => 'Test']]);
$wrapper->assertHttpResponseForOperation($response, $operation);
Пример #13
0
 /**
  * Ajax
  * Metodo para obtener el contenido de los archivos MD de Como afiliarme
  *
  * @Route("dame-documento/", name="front-getDocsComoAfil", options={"expose":true})
  * @Method({"POST"})
  */
 public function getDocsComoAfil(Request $req)
 {
     $resp = array('res' => FALSE, 'msg' => 'Ocurrio un Error inesperado, intenlalo nuevamente, por favor.', 'cont' => array());
     if ($req->request->has('getQ')) {
         $fileName = $req->request->get('getQ');
         $intoPath = $this->container->get('roots_mds')->getRootComoAfiliarme();
         $path = realpath($intoPath . '/' . $fileName . '.md');
         if (file_exists($path)) {
             $resp['cont'] = $this->container->get('markdown.parser')->transformMarkdown(file_get_contents($path));
             $resp['res'] = TRUE;
             $resp['msg'] = 'Ok';
         } else {
             $resp['msg'] = 'El Archivo solicitado no existe.';
         }
     }
     $respuesta = new \Symfony\Component\HttpFoundation\JsonResponse();
     return $respuesta->setData($resp);
 }