/** * @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(); }
<?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();