/** * @return mixed */ public function render() { $availableSites = Site::getAvailableSites(); $currentSite = $this->moduleDataStorageService->loadModuleData()->getSite(); $hasSites = is_array($availableSites) && count($availableSites) > 0; $this->templateVariableContainer->add('availableSites', $availableSites); $this->templateVariableContainer->add('currentSite', $currentSite); $this->templateVariableContainer->add('hasSites', $hasSites); $output = $this->renderChildren(); $this->templateVariableContainer->remove('hasSites'); $this->templateVariableContainer->remove('currentSite'); $this->templateVariableContainer->remove('availableSites'); return $output; }
public function render() { $this->tag->addAttribute('onchange', 'jumpToUrl(document.URL + \'&tx_solr_tools_solradministration[action]=setSite&tx_solr_tools_solradministration[site]=\'+this.options[this.selectedIndex].value,this);'); $sites = Site::getAvailableSites(); $currentSite = $this->moduleDataStorageService->loadModuleData()->getSite(); $options = ''; foreach ($sites as $site) { $selectedAttribute = ''; if ($site == $currentSite) { $selectedAttribute = ' selected="selected"'; } $options .= '<option value="' . $site->getRootPageId() . '"' . $selectedAttribute . '>' . $site->getLabel() . '</option>'; } $this->tag->setContent($options); return '<div class="docheader-funcmenu siteSelector"><label>Site: </label>' . $this->tag->render() . '</div>'; }
/** * @param $site */ protected function setSiteAndResetCore($site) { $this->moduleData->setSite($site); // when switching the site, reset the core $this->moduleData->setCore(''); $this->moduleDataStorageService->persistModuleData($this->moduleData); }
/** * Renders a core select field * * @return string */ public function render() { $this->tag->addAttribute('onchange', 'jumpToUrl(document.URL + \'&tx_solr_tools_solradministration[action]=setCore&tx_solr_tools_solradministration[core]=\'+this.options[this.selectedIndex].value,this);'); $currentSite = $this->moduleDataStorageService->loadModuleData()->getSite(); $currentCore = $this->moduleDataStorageService->loadModuleData()->getCore(); $connectionManager = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\ConnectionManager'); $cores = $connectionManager->getConnectionsBySite($currentSite); if (empty($currentCore)) { $currentCore = $cores[0]; } $options = ''; foreach ($cores as $core) { $selectedAttribute = ''; if ($core->getPath() == $currentCore) { $selectedAttribute = ' selected="selected"'; } $options .= '<option value="' . $core->getPath() . '"' . $selectedAttribute . '>' . $core->getPath() . '</option>'; } $this->tag->setContent($options); return '<div class="coreSelector"><label>Select Core: </label>' . $this->tag->render() . '</div>'; }
/** * Initializes resources commonly needed for several actions * * @return void */ protected function initializeAction() { try { $this->site = $this->request->getArgument('site'); } catch (NoSuchArgumentException $nsae) { $sites = \tx_solr_Site::getAvailableSites(); $site = array_shift($sites); $this->site = $site; $this->request->setArgument('site', $site); $moduleData = $this->moduleDataStorageService->loadModuleData(); $moduleData->setSite($site); $this->moduleDataStorageService->persistModuleData($moduleData); } }
/** * Finds the Solr connection to use for the currently selected core. * * @return \ApacheSolrForTypo3\Solr\SolrService Solr connection */ protected function getSelectedCoreSolrConnection() { $currentCoreConnection = null; $solrConnections = $this->connectionManager->getConnectionsBySite($this->site); $currentCore = $this->moduleDataStorageService->loadModuleData()->getCore(); foreach ($solrConnections as $solrConnection) { if ($solrConnection->getPath() == $currentCore) { $currentCoreConnection = $solrConnection; break; } } if (is_null($currentCoreConnection)) { // when switching sites $currentCore is empty and nothing matched // fall back to the connection's first core $currentCoreConnection = $solrConnections[0]; } return $currentCoreConnection; }
/** * Initializes resources commonly needed for several actions * * @return void */ protected function initializeAction() { try { $site = $this->request->getArgument('site'); if (is_numeric($site)) { $siteRootPageId = $this->request->getArgument('site'); $this->site = \Tx_Solr_Site::getSiteByPageId($siteRootPageId); } else { if ($site instanceof \Tx_Solr_Site) { $this->site = $site; } } } catch (NoSuchArgumentException $nsae) { $sites = \Tx_Solr_Site::getAvailableSites(); $site = array_shift($sites); $this->site = $site; } $this->request->setArgument('site', $this->site); $moduleData = $this->moduleDataStorageService->loadModuleData(); $moduleData->setSite($this->site); $this->moduleDataStorageService->persistModuleData($moduleData); }
/** * Sets the core to work with. * * @param string $core The core path to use * @param string $module Module to forward to after setting the core * @return void */ public function setCoreAction($core, $module = 'Overview') { $this->moduleData->setCore($core); $this->moduleDataStorageService->persistModuleData($this->moduleData); $this->forwardToModule($module); }