/**
  * Funkce vracející pole s identifikací dostupných minerů
  * @param string $datasourceType - typ databáze, ke které se vztahují dané minery
  * @return array
  */
 public function getAvailableMinerTypes($datasourceType = null)
 {
     $minerTypes = Miner::getTypes($datasourceType);
     $resultArr = [];
     if (!empty($minerTypes)) {
         foreach ($minerTypes as $minerType => $minerTypeName) {
             if ($this->miningDriverFactory->getMinerUrl($minerType) != '') {
                 $resultArr[$minerType] = $minerTypeName;
             }
         }
     }
     return $resultArr;
 }
 /**
  * Formulář pro zadání údajů pro přístup k minerům
  * @return Form
  */
 public function createComponentMinersForm()
 {
     $form = new Form();
     $allowDriverCloud = $form->addSelect('allow_driverCloud', 'Allow Cloud backend:', [0 => 'no', 1 => 'yes']);
     $allowDriverCloud->addCondition(Form::EQUAL, 1)->toggle('driverCloudServer', true)->toggle('dataServiceServer', true)->toggle('preprocessingServiceServer', true);
     $form->addText('driverCloudServer', 'Miner URL:')->setOption('id', 'driverCloudServer')->addConditionOn($allowDriverCloud, Form::EQUAL, 1)->setRequired('You have to input the address of Cloud backend!')->addRule(function (TextInput $textInput) {
         try {
             return $this->miningDriverFactory->checkMinerServerState(Miner::TYPE_CLOUD, $textInput->value);
         } catch (\Exception $e) {
             return false;
         }
     }, 'The Cloud backend is not accessible! Please check the configuration.');
     $form->addText('dataServiceServer', 'Data service URL:')->setOption('id', 'dataServiceServer')->addConditionOn($allowDriverCloud, Form::EQUAL, 1)->setRequired('You have to input the address of the Data service!');
     $form->addText('preprocessingServiceServer', 'Preprocessing service URL:')->setOption('id', 'preprocessingServiceServer')->setAttribute('class', 'withSpace')->addConditionOn($allowDriverCloud, Form::EQUAL, 1)->setRequired('You have to input the address of the Preprocessing service!');
     $allowDriverR = $form->addSelect('allow_driverR', 'Allow R backend:', [0 => 'no', 1 => 'yes']);
     $allowDriverR->addCondition(Form::EQUAL, 1)->toggle('driverRServer', true);
     $form->addText('driverRServer', 'R backend URL:')->setOption('id', 'driverRServer')->setAttribute('class', 'withSpace')->addConditionOn($allowDriverR, Form::EQUAL, 1)->setRequired('You have to input the address of R backend!')->addRule(function (TextInput $textInput) {
         try {
             return $this->miningDriverFactory->checkMinerServerState(Miner::TYPE_R, $textInput->value);
         } catch (\Exception $e) {
             return false;
         }
     }, 'The R backend is not accessible! Please check the configuration.');
     $allowDriverLM = $form->addSelect('allow_driverLM', 'Allow LISp-Miner backend (LM-Connect):', [0 => 'no', 1 => 'yes']);
     $allowDriverLM->addCondition(Form::EQUAL, 1)->toggle('driverLMServer', true);
     $form->addText('driverLMServer', 'LM-Connect backend URL:')->setOption('id', 'driverLMServer')->setAttribute('class', 'withSpace')->addConditionOn($allowDriverLM, Form::EQUAL, 1)->setRequired('You have to input the address of LISp-Miner backend!')->addRule(function (TextInput $textInput) {
         try {
             return $this->miningDriverFactory->checkMinerServerState(Miner::TYPE_LM, $textInput->value);
         } catch (\Exception $e) {
             return false;
         }
     }, 'The LISp-Miner backend is not accessible! Please check the configuration.');
     $form->addSubmit('submit', 'Save & continue')->onClick[] = function (SubmitButton $submitButton) {
         $values = $submitButton->form->getValues(true);
         $filesManager = $this->createFilesManager();
         $configManager = $this->createConfigManager();
         if (!($values['allow_driverLM'] || $values['allow_driverR'] || $values['allow_driverCloud'])) {
             $submitButton->form->addError('You have to configure at least one data mining backend!');
             return;
         }
         //region Cloud backend
         if ($values['allow_driverCloud']) {
             $urlArr = parse_url($values['driverCloudServer']);
             if (function_exists('http_build_url')) {
                 $serverUrl = http_build_url($urlArr, HTTP_URL_STRIP_PATH | HTTP_URL_STRIP_QUERY);
             } else {
                 $serverUrl = $urlArr['scheme'] . '://' . $urlArr['host'] . (!empty($urlArr['port']) ? ':' . $urlArr['port'] : '');
             }
             $minerPath = (!empty($urlArr['path']) ? rtrim($urlArr['path'], '/') : '') . (!empty($urlArr['query']) ? '?' . $urlArr['query'] : '');
             $configArr = ['server' => $serverUrl, 'minerUrl' => $minerPath, 'importsDirectory' => $filesManager->getPath('writable', 'directories', 'importsCloud', true)];
             $configManager->data['parameters']['databases']['limited']['api'] = rtrim($values['dataServiceServer'], '/');
             $configManager->data['parameters']['databases']['unlimited']['api'] = rtrim($values['dataServiceServer'], '/');
             $configManager->data['parameters']['databases']['limited']['preprocessingApi'] = rtrim($values['preprocessingServiceServer'], '/');
             $configManager->data['parameters']['databases']['unlimited']['preprocessingApi'] = rtrim($values['preprocessingServiceServer'], '/');
         } else {
             $configArr = ['server' => ''];
         }
         $configManager->data['parameters']['miningDriverFactory']['driver_cloud'] = $configArr;
         //endregion Cloud backend
         //region R backend
         if ($values['allow_driverR']) {
             $urlArr = parse_url($values['driverRServer']);
             if (function_exists('http_build_url')) {
                 $serverUrl = http_build_url($urlArr, HTTP_URL_STRIP_PATH | HTTP_URL_STRIP_QUERY);
             } else {
                 $serverUrl = $urlArr['scheme'] . '://' . $urlArr['host'] . (!empty($urlArr['port']) ? ':' . $urlArr['port'] : '');
             }
             $minerPath = (!empty($urlArr['path']) ? rtrim($urlArr['path'], '/') : '') . (!empty($urlArr['query']) ? '?' . $urlArr['query'] : '');
             $configArr = ['server' => $serverUrl, 'minerUrl' => $minerPath, 'importsDirectory' => $filesManager->getPath('writable', 'directories', 'importsR', true)];
         } else {
             $configArr = ['server' => ''];
         }
         $configManager->data['parameters']['miningDriverFactory']['driver_r'] = $configArr;
         //endregion R backend
         //region LM backend
         if ($values['allow_driverLM']) {
             $configArr = ['server' => $values['driverLMServer'], 'importsDirectory' => $filesManager->getPath('writable', 'directories', 'importsLM', true)];
         } else {
             $configArr = ['server' => ''];
         }
         $configManager->data['parameters']['miningDriverFactory']['driver_lm'] = $configArr;
         //endregion LM backend
         $configManager->saveConfig();
         $this->redirect($this->getNextStep('miners'));
     };
     return $form;
 }