Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimruhs committed Nov 3, 2019
0 parents commit 59e5a8b
Show file tree
Hide file tree
Showing 71 changed files with 5,314 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
253 changes: 253 additions & 0 deletions Classes/Controller/AddressController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
<?php
namespace WSR\Myleaflet\Controller;

use TYPO3\CMS\Core\Utility\GeneralUtility;


/***************************************************************
* Copyright notice
*
* (c) Joachim Ruhs 2018
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

/**
* AddressController
*/
class AddressController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
public function initializeObject() {
// $this->_GP = $this->request->getArguments();
$configuration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$this->conf['storagePid'] = $configuration['persistence']['storagePid'];
}

/**
* AddressRepository
*
* @var \WSR\Myleaflet\Domain\Repository\AddressRepository
*/
protected $addressRepository;


/**
* Inject a addressRepository to enable DI
*
* @param \WSR\Myleaflet\Domain\Repository\AddressRepository $addressRepository
* @return void
*/
public function injectAddressRepository(\WSR\Myleaflet\Domain\Repository\AddressRepository $addressRepository) {
$this->addressRepository = $addressRepository;
}




/**
* typo3CategoryRepository
*
* @var \TYPO3\CMS\Extbase\Domain\Repository\CategoryRepository
*/
protected $typo3CategoryRepository;

/**
* Inject a categoryRepository to enable DI
*
* @param \TYPO3\CMS\Extbase\Domain\Repository\CategoryRepository $typo3CategoryRepository
* @return void
*/
public function injectTypo3CategoryRepository(\TYPO3\CMS\Extbase\Domain\Repository\CategoryRepository $typo3CategoryRepository) {
$this->typo3CategoryRepository = $typo3CategoryRepository;
}




/**
* categoryRepository
*
* @var \WSR\Myleaflet\Domain\Repository\CategoryRepository
*/
protected $categoryRepository;

/**
* Inject a categoryRepository to enable DI
*
* @param \WSR\Myleaflet\Domain\Repository\CategoryRepository $categoryRepository
* @return void
*/
public function injectCategoryRepository(\WSR\Myleaflet\Domain\Repository\CategoryRepository $categoryRepository) {
$this->categoryRepository = $categoryRepository;
}





/**
* action show
*
* @return void
*/
public function showAction()
{
$this->_GP = $this->request->getArguments();

if ($this->_GP['locationUid']) {// called from list link
$address = $this->addressRepository->findByUid(intval($this->_GP['locationUid']));
}
else {
$address = $this->addressRepository->findByUid(intval($this->settings['singleViewUid']));
}
$this->view->assign('address', $address);
}

/**
* action list
*
* @return void
*/
public function listAction()
{
$addresses = $this->addressRepository->findAll();
$this->view->assign('addresses', $addresses);
}

/*
* build the category tree
*
* @var array $elements
* @var int $parentId
*
* @return array
*/
function buildTree(array &$elements, $parentId = 0) {
$branch = array();
foreach ($elements as &$element) {
if ($element['parent'] == $parentId) {
$children = $this->buildTree($elements, $element['uid']);
if ($children) {
$element['children'] = $children;
}
$branch[$element['uid']] = $element;
unset($element);
}
}
return $branch;
}




/**
* action ajaxSearch
*
* @return void
*/
public function ajaxSearchAction()
{

/*********************************************************/
// alternative geocoder
//https://nominatim.openstreetmap.org/search/elzstr.%2010%20rheinhausen?format=json&addressdetails=1&limit=1&polygon_svg=1//
// $addressData = $this->get_webpage($apiURL);

//krexx($latLon);

// $addresses = $this->addressRepository->findAll();

/*
$radius = 1000;
$storagePid = $this->conf['storagePid'];
$limit = 300;
$page = 0;
$addresses = $this->addressRepository->findLocationsInRadius($latLon, $radius, $categories, $storagePid, $limit, $page, $orderBy = 'distance');
$categories = $this->categoryRepository->findAll();
*/

// Get the default Settings
$customStoragePid = $this->conf['storagePid'];
$querySettings = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings');

$querySettings->setRespectStoragePage(true);
$querySettings->setStoragePageIds(array($customStoragePid));

$addresses = $this->addressRepository->findAll();



$this->categoryRepository->setDefaultQuerySettings($querySettings);
$categories = $this->categoryRepository->findAll();


for($i = 0; $i < count($categories); $i++) {

// process only sys_categories of storagePid
if (! GeneralUtility::inList($customStoragePid, $categories[$i]->getPid())) continue;

$arr[$i]['uid']= $categories[$i]->getUid();
if ($categories[$i]->getParent()) {
$arr[$i]['parent'] = $categories[$i]->getParent()->getUid();
} else $arr[$i]['parent'] = 0;

$arr[$i]['title'] = $categories[$i]->getTitle();
}
$categories = $this->buildTree($arr);




//Krexx($addresses);
$this->view->assign('L', $GLOBALS['TSFE']->config['config']['language']);
$this->view->assign('id' , $GLOBALS['TSFE']->id);
$this->view->assign('categories' , $categories);
$this->view->assign('addresses' , $addresses);
$this->view->assign('locationsCount', count($addresses));

}


function get_webpage($url) {
//global $db;
if (ini_get('allow_url_fopen'))
$this->conf['useCurl'] = 0;
else
$this->conf['useCurl'] = 1;

if ($this->conf['useCurl']) {
$sessions = curl_init();
curl_setopt($sessions, CURLOPT_URL, $url);
curl_setopt($sessions, CURLOPT_HEADER, 0);
curl_setopt($sessions, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($sessions);
curl_close($sessions);
} else {
// $data = t3lib_div::getUrl($url);
$data = \TYPO3\CMS\Core\Utility\GeneralUtility::getURL($url);
}
return $data;
}




}
Loading

0 comments on commit 59e5a8b

Please sign in to comment.