/** * Converts the list of selected "choices" into a list of "modules": take into account the selected and the mandatory modules * @param hash $aInfo Info about the "choice" array('options' => array(...), 'alternatives' => array(...)) * @param hash $aSelectedChoices List of selected choices array('name' => 'selected_value_id') * @param hash $aModules Return parameter: List of selected modules array('module_id' => true) * @param string $sParentId Used for recursion * @return void */ protected function GetSelectedModules($aInfo, $aSelectedChoices, &$aModules, $sParentId = '', $sDisplayChoices = '') { if ($sParentId == '') { // Check once (before recursing) that the hidden modules are selected foreach (SetupUtils::AnalyzeInstallation($this->oWizard) as $sModuleId => $aModule) { if ($sModuleId != ROOT_MODULE) { if ($aModule['category'] == 'authentication' || !$aModule['visible']) { $aModules[$sModuleId] = true; } } } } $aOptions = isset($aInfo['options']) ? $aInfo['options'] : array(); foreach ($aOptions as $index => $aChoice) { $sChoiceId = $sParentId . self::$SEP . $index; if (isset($aChoice['mandatory']) && $aChoice['mandatory'] || isset($aSelectedChoices[$sChoiceId]) && $aSelectedChoices[$sChoiceId] == $sChoiceId) { $sDisplayChoices .= '<li>' . $aChoice['title'] . '</li>'; if (isset($aChoice['modules'])) { foreach ($aChoice['modules'] as $sModuleId) { $aModules[$sModuleId] = true; // store the Id of the selected module } } // Recurse only for selected choices if (isset($aChoice['sub_options'])) { $sDisplayChoices .= '<ul>'; $sDisplayChoices = $this->GetSelectedModules($aChoice['sub_options'], $aSelectedChoices, $aModules, $sChoiceId, $sDisplayChoices); $sDisplayChoices .= '</ul>'; } $sDisplayChoices .= '</li>'; } $index++; } $aAlternatives = isset($aInfo['alternatives']) ? $aInfo['alternatives'] : array(); $sChoiceName = null; foreach ($aAlternatives as $index => $aChoice) { $sChoiceId = $sParentId . self::$SEP . $index; if ($sChoiceName == null) { $sChoiceName = $sChoiceId; } if (isset($aChoice['mandatory']) && $aChoice['mandatory'] || isset($aSelectedChoices[$sChoiceName]) && $aSelectedChoices[$sChoiceName] == $sChoiceId) { $sDisplayChoices .= '<li>' . $aChoice['title'] . '</li>'; if (isset($aChoice['modules'])) { foreach ($aChoice['modules'] as $sModuleId) { $aModules[$sModuleId] = true; // store the Id of the selected module } } // Recurse only for selected choices if (isset($aChoice['sub_options'])) { $sDisplayChoices .= '<ul>'; $sDisplayChoices = $this->GetSelectedModules($aChoice['sub_options'], $aSelectedChoices, $aModules, $sChoiceId, $sDisplayChoices); $sDisplayChoices .= '</ul>'; } $sDisplayChoices .= '</li>'; } $index++; } if ($sParentId == '') { // Last pass (after all the user's choices are turned into "selected" modules): // Process 'auto_select' modules for modules that are not already selected $aAvailableModules = SetupUtils::AnalyzeInstallation($this->oWizard); do { // Loop while new modules are added... $bModuleAdded = false; foreach ($aAvailableModules as $sModuleId => $aModule) { if ($sModuleId != ROOT_MODULE && !array_key_exists($sModuleId, $aModules) && isset($aModule['auto_select'])) { try { $bSelected = false; SetupInfo::SetSelectedModules($aModules); eval('$bSelected = (' . $aModule['auto_select'] . ');'); } catch (Exception $e) { $sDisplayChoices .= '<li><b>Warning: auto_select failed with exception (' . $e->getMessage() . ') for module "' . $sModuleId . '"</b></li>'; $bSelected = false; } if ($bSelected) { $aModules[$sModuleId] = true; // store the Id of the selected module $bModuleAdded = true; } } } } while ($bModuleAdded); } return $sDisplayChoices; }
/** * Called by the setup process to initializes the list of selected modules. Do not call this method * from an 'auto_select' rule * @param hash $aModules * @return void */ static function SetSelectedModules($aModules) { self::$aSelectedModules = $aModules; }
/** * @param array $server * @param bool $expected * @dataProvider isAvailableDataProvider */ public function testIsAvailable($server, $expected) { $info = new SetupInfo($server); $this->assertEquals($expected, $info->isAvailable()); }