m_oPage = $oPage; $this->m_sClass = $sClass; if (empty($sTargetState)) { $sTargetState = MetaModel::GetDefaultState($sClass); } $this->m_sTargetState = $sTargetState; $this->m_aWizardSteps = $this->ComputeWizardStructure(); } public function GetObjectClass() { return $this->m_sClass; } public function GetTargetState() { return $this->m_sTargetState; } public function GetWizardStructure() { return $this->m_aWizardSteps; } /** * Displays one step of the wizard */ public function DisplayWizardStep($aStep, $iStepIndex, &$iMaxInputId, &$aFieldsMap, $bFinishEnabled = false, $aArgs = array()) { if ($iStepIndex == 1) // one big form that contains everything, to make sure that the uploaded files are posted too { $this->m_oPage->add("
\n"); } /** * Compute the order of the fields & pages in the wizard * @param $oPage iTopWebPage The current page (used to display error messages) * @param $sClass string Name of the class * @param $sStateCode string Code of the target state of the object * @return hash Two dimensional array: each element represents the list of fields for a given page */ protected function ComputeWizardStructure() { $aWizardSteps = array( 'mandatory' => array(), 'optional' => array()); $aFieldsDone = array(); // Store all the fields that are already covered by a previous step of the wizard $aStates = MetaModel::EnumStates($this->m_sClass); if ( (!empty($this->m_sTargetState)) && (count($aStates[$this->m_sTargetState]['attribute_list']) > 0) ) { // Check all the fields that *must* be included in the wizard for this // particular target state $aFields = array(); foreach($aStates[$this->m_sTargetState]['attribute_list'] as $sAttCode => $iOptions) { $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode); $sAttLabel = $oAttDef->GetLabel(); if ($iOptions & (OPT_ATT_MANDATORY | OPT_ATT_MUSTCHANGE | OPT_ATT_MUSTPROMPT)) { $aPrerequisites = $oAttDef->GetPrerequisiteAttributes(); $aFields[$sAttCode] = array(); foreach($aPrerequisites as $sCode) { $aFields[$sAttCode][$sCode] = ''; } } } // Now use the dependencies between the fields to order them while(count($aFields) > 0) { $aCurrentStep = array(); foreach($aFields as $sAttCode => $aDependencies) { // All fields with no remaining dependencies can be entered at this // step of the wizard if (count($aDependencies) == 0) { $aCurrentStep[] = $sAttCode; $aFieldsDone[$sAttCode] = ''; unset($aFields[$sAttCode]); // Remove this field from the dependencies of the other fields foreach($aFields as $sUpdatedCode => $aDummy) { // remove the dependency unset($aFields[$sUpdatedCode][$sAttCode]); } } } if (count($aCurrentStep) == 0) { // This step of the wizard would contain NO field ! echo "Error: Circular reference in the dependencies between the fields."; print_r($aFields); break; } $aWizardSteps['mandatory'][] = $aCurrentStep; } } // Now computes the steps to fill the optional fields $sStateAttCode = MetaModel::GetStateAttributeCode($this->m_sClass); $aFields = array(); // reset foreach(MetaModel::ListAttributeDefs($this->m_sClass) as $sAttCode=>$oAttDef) { $iOptions = (isset($aStates[$this->m_sTargetState]['attribute_list'][$sAttCode])) ? $aStates[$this->m_sTargetState]['attribute_list'][$sAttCode] : 0; if ( ($sStateAttCode != $sAttCode) && (!$oAttDef->IsExternalField()) && (($iOptions & (OPT_ATT_HIDDEN | OPT_ATT_READONLY)) == 0) && (!isset($aFieldsDone[$sAttCode])) ) { // 'State', external fields, read-only and hidden fields // and fields that are already listed in the wizard // are removed from the 'optional' part of the wizard $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode); $aPrerequisites = $oAttDef->GetPrerequisiteAttributes(); $aFields[$sAttCode] = array(); foreach($aPrerequisites as $sCode) { if (!isset($aFieldsDone[$sCode])) { // retain only the dependencies that were not covered // in the 'mandatory' part of the wizard $aFields[$sAttCode][$sCode] = ''; } } } } // Now use the dependencies between the fields to order them while(count($aFields) > 0) { $aCurrentStep = array(); foreach($aFields as $sAttCode => $aDependencies) { // All fields with no remaining dependencies can be entered at this // step of the wizard if (count($aDependencies) == 0) { $aCurrentStep[] = $sAttCode; $aFieldsDone[$sAttCode] = ''; unset($aFields[$sAttCode]); // Remove this field from the dependencies of the other fields foreach($aFields as $sUpdatedCode => $aDummy) { // remove the dependency unset($aFields[$sUpdatedCode][$sAttCode]); } } } if (count($aCurrentStep) == 0) { // This step of the wizard would contain NO field ! $oPage->add("Error: Circular reference in the dependencies between the fields."); print_r($aFields); break; } $aWizardSteps['optional'][] = $aCurrentStep; } return $aWizardSteps; } } ?>