Esempio n. 1
0
 /**
  * @dataProvider screenProvider
  */
 public function testHeaderResponse(Screen $screen)
 {
     $header = $this->getFunctionMock(__NAMESPACE__, 'header');
     $header->expects($this->once())->with($this->equalTo('Content-type: application/json'));
     $remote = new Remote($screen);
     $remote->getResponse(null, true, true);
 }
 /**
  * @Route("/hello", name="hello")
  */
 public function helloAction(Request $request)
 {
     $screen = new Screen("Hello Word");
     $name = $request->query->get('name');
     $screen->addChild(new Text("Hi {$name}!"));
     $remote = new Remote($screen);
     return $remote->getSymfonyResponse();
 }
 /**
  * @Route("/view")
  */
 public function documentAction(Request $request)
 {
     if (Remote::isOptionsRequest()) {
         return Remote::getCORSSymfonyResponse();
     }
     $secret = $request->get('identifier');
     /** @var Doc $doc */
     $doc = $this->getDoctrine()->getManager()->getRepository('AppShedExtensionsSpreadsheetMapsBundle:Doc')->findOneBy(['itemsecret' => $secret]);
     if (!$doc) {
         $screen = new Screen('Error');
         $screen->addChild(new HTML('You must setup the extension before using it'));
         return (new Remote($screen))->getSymfonyResponse();
     }
     $address = strtolower($doc->getAddress() ?: 'address');
     try {
         $document = $this->getDocument($doc->getKey(), $this->getFilterString($doc->getFilters(), $request));
         //This screen will have a list of the markers in Address column
         $screen = new Map($document->getTitle());
         //For each row of the table
         foreach ($document as $entry) {
             $index = true;
             $lines = $entry->getCustom();
             //Each of the columns of the row
             foreach ($lines as $customEntry) {
                 $name = $customEntry->getColumnName();
                 $value = $customEntry->getText();
                 //If the name of a column ends with a '-' then we dont show it
                 if ((strlen($name) - 1 == strpos($name, '-')) == false) {
                     if ($index == true) {
                         //This screen will have all the values across the row
                         $innerScreen = new Screen($value);
                         $index = false;
                     } else {
                         if (!empty($value)) {
                             if ($name == $address) {
                                 $geo = $this->geoService->getGeo($value);
                                 if ($geo) {
                                     $marker = new Marker($address, $value, $geo['lng'], $geo['lat']);
                                     $marker->setScreenLink($innerScreen);
                                     $screen->addChild($marker);
                                 }
                             }
                             $innerScreen->addChild(new HTML($value));
                         }
                     }
                 }
             }
         }
         return (new Remote($screen))->getSymfonyResponse();
     } catch (\Exception $e) {
         $screen = new Screen('Error');
         $screen->addChild(new HTML('There was an error reading'));
         $screen->addChild(new Text($e->getMessage()));
         $this->logger->error('Problem reading a spreadsheet', ['exception' => $e]);
         return (new Remote($screen))->getSymfonyResponse();
     }
 }
 /**
  * @Route("/document")
  * @Route("/document/")
  */
 public function documentAction(Request $request)
 {
     if (Remote::isOptionsRequest()) {
         return Remote::getCORSSymfonyResponse();
     }
     $rowData = $this->cleanData(Remote::getRequestVariables());
     $secret = $request->get('identifier');
     $em = $this->getDoctrine()->getManager();
     /** @var Doc $doc */
     $doc = $em->getRepository('AppShedExtensionsSpreadsheetBundle:Doc')->findOneBy(['itemsecret' => $secret]);
     if (!$doc) {
         $screen = new Screen('Error');
         $screen->addChild(new HTML('You must setup the extension before using it'));
         return (new Remote($screen))->getSymfonyResponse();
     }
     try {
         $existingTitles = $this->getColumnTitles($doc->getKey());
         $store = false;
         foreach ($rowData as $titleName => $value) {
             if (!in_array($titleName, $existingTitles)) {
                 $store = true;
                 $this->addTitle($titleName, $doc->getKey());
                 $existingTitles[] = $titleName;
             }
         }
         if ($store) {
             $doc->setTitles(array_unique($existingTitles));
             $em->flush();
         }
         foreach ($existingTitles as $titleName) {
             if (!isset($rowData[$titleName])) {
                 $rowData[$titleName] = '';
             }
         }
         if (count($rowData) > 0) {
             $this->getSpreadsheets()->insertRow($rowData, $doc->getKey(), 1);
         }
     } catch (\Exception $e) {
         $screen = new Screen('Error');
         $screen->addChild(new HTML('There was an error storing'));
         $screen->addChild(new Text($e->getMessage()));
         $this->logger->error('Problem accessing a spreadsheet', ['exception' => $e, 'rowData' => $rowData]);
         return (new Remote($screen))->getSymfonyResponse();
     }
     $screen = new Screen('Saved');
     $screen->addChild(new HTML("Your record has been saved"));
     return (new Remote($screen))->getSymfonyResponse();
 }
 /**
  * @Route("/write", name="write")
  * @Method({"GET", "POST"})
  */
 public function appshedAction(Request $request)
 {
     $view = $this->getView($request);
     if (!$view->getId()) {
         $screen = new Screen("Error");
         $screen->addChild(new Text("You must setup the view first"));
         return (new Remote($screen))->getSymfonyResponse();
     }
     $store = $view->getStore();
     $data = Remote::getRequestVariables();
     $systemFields = $this->container->getParameter('data_system_fields');
     foreach (array_keys($data) as $key) {
         if (in_array($key, $systemFields)) {
             unset($data[$key]);
             continue;
         }
         if (is_array($data[$key])) {
             $data[$key] = '[' . implode(', ', $data[$key]) . ']';
         }
     }
     $cols = array_keys($data);
     if (!count($cols)) {
         $screen = new Screen("Error");
         $screen->addChild(new Text("You must send some data"));
         return (new Remote($screen))->getSymfonyResponse();
     }
     //Add any new columns to the store
     $newColumns = array_diff($cols, $store->getColumns());
     if (count($newColumns)) {
         $store->setColumns(array_merge($store->getColumns(), $newColumns));
     }
     //Create new data obj
     $dataO = new Data();
     $dataO->setColumns($cols);
     $dataO->setData($data);
     $dataO->setStore($store);
     $em = $this->getDoctrine()->getManager();
     $em->persist($dataO);
     $em->flush();
     $screen = new Screen($view->getTitle() ?: "Thank you");
     $screen->addChild(new Text($view->getMessage() ?: "Your entry has been saved"));
     return (new Remote($screen))->getSymfonyResponse();
 }
Esempio n. 6
0
<?php

require __DIR__ . '/../build/appshed-api.phar';
use AppShed\Remote\Element\Screen\Map;
use AppShed\Remote\Element\Item\Marker;
use AppShed\Remote\HTML\Remote;
if (Remote::isOptionsRequest()) {
    Remote::getCORSResponseHeaders();
}
$screen = new Map('Map Screen');
$screen->addChild(new Marker('Hi there', 'hello', 32, 49));
$remote = new Remote($screen);
$remote->getResponse();