当前位置: 首页>>代码示例>>PHP>>正文


PHP MetaModel::EnumStates方法代码示例

本文整理汇总了PHP中MetaModel::EnumStates方法的典型用法代码示例。如果您正苦于以下问题:PHP MetaModel::EnumStates方法的具体用法?PHP MetaModel::EnumStates怎么用?PHP MetaModel::EnumStates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MetaModel的用法示例。


在下文中一共展示了MetaModel::EnumStates方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: GraphvizLifecycle

/**
 * Helper to generate a Graphviz code for displaying the life cycle of a class
 * @param string $sClass The class to display
 * @return string The Graph description in Graphviz/Dot syntax   
 */
function GraphvizLifecycle($sClass)
{
    $sDotFileContent = "";
    $sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
    if (empty($sStateAttCode)) {
        //$oPage->p("no lifecycle for this class");
    } else {
        $aStates = MetaModel::EnumStates($sClass);
        $aStimuli = MetaModel::EnumStimuli($sClass);
        $sDotFileContent .= "digraph finite_state_machine {\r\n\tgraph [bgcolor = \"transparent\"];\r\n\trankdir=LR;\r\n\tsize=\"12,12\"\r\n\tnode [ fontname=Verdana style=filled fillcolor=\"#ffffff\" ];\r\n\tedge [ fontname=Verdana ];\r\n";
        $aStatesLinks = array();
        foreach ($aStates as $sStateCode => $aStateDef) {
            $aStatesLinks[$sStateCode] = array('in' => 0, 'out' => 0);
        }
        foreach ($aStates as $sStateCode => $aStateDef) {
            $sStateLabel = MetaModel::GetStateLabel($sClass, $sStateCode);
            $sStateDescription = MetaModel::GetStateDescription($sClass, $sStateCode);
            foreach (MetaModel::EnumTransitions($sClass, $sStateCode) as $sStimulusCode => $aTransitionDef) {
                $aStatesLinks[$sStateCode]['out']++;
                $aStatesLinks[$aTransitionDef['target_state']]['in']++;
                $sStimulusLabel = $aStimuli[$sStimulusCode]->GetLabel();
                $sTargetStateLabel = MetaModel::GetStateLabel($sClass, $aTransitionDef['target_state']);
                $sDotFileContent .= "\t{$sStateCode} -> {$aTransitionDef['target_state']} [ label=\"" . GraphvizEscape($sStimulusLabel) . "\"];\n";
            }
        }
        foreach ($aStates as $sStateCode => $aStateDef) {
            if ($aStatesLinks[$sStateCode]['out'] > 0 || $aStatesLinks[$sStateCode]['in'] > 0) {
                // Show only reachable states
                $sStateLabel = str_replace(' ', '\\n', MetaModel::GetStateLabel($sClass, $sStateCode));
                if ($aStatesLinks[$sStateCode]['in'] == 0 || $aStatesLinks[$sStateCode]['out'] == 0) {
                    // End or Start state, make it look different
                    $sDotFileContent .= "\t{$sStateCode} [ shape=doublecircle,label=\"" . GraphvizEscape($sStateLabel) . "\"];\n";
                } else {
                    $sDotFileContent .= "\t{$sStateCode} [ shape=circle,label=\"" . GraphvizEscape($sStateLabel) . "\"];\n";
                }
            }
        }
        $sDotFileContent .= "}\n";
    }
    return $sDotFileContent;
}
开发者ID:leandroborgeseng,项目名称:bhtm,代码行数:46,代码来源:graphviz.php

示例2: GetExpectedAttributes

 public function GetExpectedAttributes($sCurrentState, $sStimulus, $bOnlyNewOnes)
 {
     $aTransitions = $this->EnumTransitions();
     $aStimuli = MetaModel::EnumStimuli(get_class($this));
     if (!isset($aTransitions[$sStimulus])) {
         // Invalid stimulus
         throw new ApplicationException(Dict::Format('UI:Error:Invalid_Stimulus_On_Object_In_State', $sStimulus, $this->GetName(), $this->GetStateLabel()));
     }
     $aTransition = $aTransitions[$sStimulus];
     $sTargetState = $aTransition['target_state'];
     $aTargetStates = MetaModel::EnumStates(get_class($this));
     $aTargetState = $aTargetStates[$sTargetState];
     $aCurrentState = $aTargetStates[$this->GetState()];
     $aExpectedAttributes = $aTargetState['attribute_list'];
     $aCurrentAttributes = $aCurrentState['attribute_list'];
     $aComputedAttributes = array();
     foreach ($aExpectedAttributes as $sAttCode => $iExpectCode) {
         if (!array_key_exists($sAttCode, $aCurrentAttributes)) {
             $aComputedAttributes[$sAttCode] = $iExpectCode;
         } else {
             if (!($aCurrentAttributes[$sAttCode] & (OPT_ATT_HIDDEN | OPT_ATT_READONLY))) {
                 $iExpectCode = $iExpectCode & ~(OPT_ATT_MUSTPROMPT | OPT_ATT_MUSTCHANGE);
                 // Already prompted/changed, reset the flags
             }
             //TODO: better check if the attribute is not *null*
             if ($iExpectCode & OPT_ATT_MANDATORY && $this->Get($sAttCode) != '') {
                 $iExpectCode = $iExpectCode & ~OPT_ATT_MANDATORY;
                 // If the attribute is present, then no need to request its presence
             }
             $aComputedAttributes[$sAttCode] = $iExpectCode;
         }
         $aComputedAttributes[$sAttCode] = $aComputedAttributes[$sAttCode] & ~(OPT_ATT_READONLY | OPT_ATT_HIDDEN);
         // Don't care about this form now
         if ($aComputedAttributes[$sAttCode] == 0) {
             unset($aComputedAttributes[$sAttCode]);
         }
     }
     return $aComputedAttributes;
 }
开发者ID:besmirzanaj,项目名称:itop-code,代码行数:39,代码来源:cmdbabstract.class.inc.php

示例3: GetRenderContent


//.........这里部分代码省略.........
             }
             break;
         default:
             // Check rights
             // New / Modify
             $bIsModifyAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) && $oReflectionClass->IsSubclassOf('cmdbAbstractObject');
             $bIsBulkModifyAllowed = !MetaModel::IsAbstract($sClass) && UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_MODIFY, $oSet) && $oReflectionClass->IsSubclassOf('cmdbAbstractObject');
             $bIsBulkDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_DELETE, $oSet);
             if (isset($aExtraParams['link_attr'])) {
                 $id = $aExtraParams['object_id'];
                 $sTargetAttr = $aExtraParams['target_attr'];
                 $oAttDef = MetaModel::GetAttributeDef($sClass, $sTargetAttr);
                 $sTargetClass = $oAttDef->GetTargetClass();
                 $bIsDeleteAllowed = UserRights::IsActionAllowed($sClass, UR_ACTION_DELETE, $oSet);
                 if ($bIsModifyAllowed) {
                     $aActions['UI:Menu:Add'] = array('label' => Dict::S('UI:Menu:Add'), 'url' => "{$sRootUrl}pages/{$sUIPage}?operation=modify_links&class={$sClass}&link_attr=" . $aExtraParams['link_attr'] . "&target_class={$sTargetClass}&id={$id}&addObjects=true{$sContext}");
                 }
                 if ($bIsBulkModifyAllowed) {
                     $aActions['UI:Menu:Manage'] = array('label' => Dict::S('UI:Menu:Manage'), 'url' => "{$sRootUrl}pages/{$sUIPage}?operation=modify_links&class={$sClass}&link_attr=" . $aExtraParams['link_attr'] . "&target_class={$sTargetClass}&id={$id}{$sContext}");
                 }
                 //if ($bIsBulkDeleteAllowed) { $aActions[] = array ('label' => 'Remove All...', 'url' => "#"); }
             } else {
                 // many objects in the set, possible actions are: new / modify all / delete all
                 if ($bIsCreationAllowed) {
                     $aActions['UI:Menu:New'] = array('label' => Dict::S('UI:Menu:New'), 'url' => "{$sRootUrl}pages/{$sUIPage}?operation=new&class={$sClass}{$sContext}{$sDefault}");
                 }
                 if ($bIsBulkModifyAllowed) {
                     $aActions['UI:Menu:ModifyAll'] = array('label' => Dict::S('UI:Menu:ModifyAll'), 'url' => "{$sRootUrl}pages/{$sUIPage}?operation=select_for_modify_all&class={$sClass}&filter=" . urlencode($sFilter) . "{$sContext}");
                 }
                 if ($bIsBulkDeleteAllowed) {
                     $aActions['UI:Menu:BulkDelete'] = array('label' => Dict::S('UI:Menu:BulkDelete'), 'url' => "{$sRootUrl}pages/{$sUIPage}?operation=select_for_deletion&filter=" . urlencode($sFilter) . "{$sContext}");
                 }
                 // Stimuli
                 $aStates = MetaModel::EnumStates($sClass);
                 // Do not perform time consuming computations if there are too may objects in the list
                 $iLimit = MetaModel::GetConfig()->Get('complex_actions_limit');
                 if (count($aStates) > 0 && ($iLimit == 0 || $oSet->Count() < $iLimit)) {
                     // Life cycle actions may be available... if all objects are in the same state
                     //
                     // Group by <state>
                     $oGroupByExp = new FieldExpression(MetaModel::GetStateAttributeCode($sClass), $this->m_oFilter->GetClassAlias());
                     $aGroupBy = array('__state__' => $oGroupByExp);
                     $aQueryParams = array();
                     if (isset($aExtraParams['query_params'])) {
                         $aQueryParams = $aExtraParams['query_params'];
                     }
                     $sSql = $this->m_oFilter->MakeGroupByQuery($aQueryParams, $aGroupBy);
                     $aRes = CMDBSource::QueryToArray($sSql);
                     if (count($aRes) == 1) {
                         // All objects are in the same state...
                         $sState = $aRes[0]['__state__'];
                         $aTransitions = Metamodel::EnumTransitions($sClass, $sState);
                         if (count($aTransitions)) {
                             $this->AddMenuSeparator($aActions);
                             $aStimuli = Metamodel::EnumStimuli($sClass);
                             foreach ($aTransitions as $sStimulusCode => $aTransitionDef) {
                                 $oSet->Rewind();
                                 // As soon as the user rights implementation will browse the object set,
                                 // then we might consider using OptimizeColumnLoad() here
                                 $iActionAllowed = UserRights::IsStimulusAllowed($sClass, $sStimulusCode, $oSet);
                                 $iActionAllowed = get_class($aStimuli[$sStimulusCode]) == 'StimulusUserAction' ? $iActionAllowed : UR_ALLOWED_NO;
                                 switch ($iActionAllowed) {
                                     case UR_ALLOWED_YES:
                                     case UR_ALLOWED_DEPENDS:
                                         $aActions[$sStimulusCode] = array('label' => $aStimuli[$sStimulusCode]->GetLabel(), 'url' => "{$sRootUrl}pages/UI.php?operation=select_bulk_stimulus&stimulus={$sStimulusCode}&state={$sState}&class={$sClass}&filter=" . urlencode($sFilter) . "{$sContext}");
                                         break;
开发者ID:henryavila,项目名称:itop,代码行数:67,代码来源:displayblock.class.inc.php

示例4: ComputeWizardStructure

 /**
  * 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);
     $sStateAttCode = MetaModel::GetStateAttributeCode($this->m_sClass);
     $aMandatoryAttributes = array();
     // Some attributes are always mandatory independently of the state machine (if any)
     foreach (MetaModel::GetAttributesList($this->m_sClass) as $sAttCode) {
         $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode);
         if (!$oAttDef->IsExternalField() && !$oAttDef->IsNullAllowed() && $oAttDef->IsWritable() && $sAttCode != $sStateAttCode) {
             $aMandatoryAttributes[$sAttCode] = OPT_ATT_MANDATORY;
         }
     }
     // Now check the attributes that are mandatory in the specified state
     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) {
             if (isset($aMandatoryAttributes[$sAttCode]) && $aMandatoryAttributes[$sAttCode] & (OPT_ATT_MANDATORY | OPT_ATT_MUSTCHANGE | OPT_ATT_MUSTPROMPT)) {
                 $aMandatoryAttributes[$sAttCode] |= $iOptions;
             } else {
                 $aMandatoryAttributes[$sAttCode] = $iOptions;
             }
         }
     }
     // Check all the fields that *must* be included in the wizard
     // i.e. all mandatory, must-change or must-prompt fields that are
     // not also read-only or hidden.
     // Some fields may be required (null not allowed) from the database
     // perspective, but hidden or read-only from the user interface perspective
     $aFields = array();
     foreach ($aMandatoryAttributes as $sAttCode => $iOptions) {
         if ($iOptions & (OPT_ATT_MANDATORY | OPT_ATT_MUSTCHANGE | OPT_ATT_MUSTPROMPT) && !($iOptions & (OPT_ATT_READONLY | OPT_ATT_HIDDEN))) {
             $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode);
             $aPrerequisites = $oAttDef->GetPrerequisiteAttributes();
             $aFields[$sAttCode] = array();
             foreach ($aPrerequisites as $sCode) {
                 $aFields[$sAttCode][$sCode] = '';
             }
         }
     }
     // Now use the dependencies between the fields to order them
     // Start from the order of the 'details'
     $aList = MetaModel::FlattenZlist(MetaModel::GetZListItems($this->m_sClass, 'details'));
     $index = 0;
     $aOrder = array();
     foreach ($aFields as $sAttCode => $void) {
         $aOrder[$sAttCode] = 999;
         // At the end of the list...
     }
     foreach ($aList as $sAttCode) {
         if (array_key_exists($sAttCode, $aFields)) {
             $aOrder[$sAttCode] = $index;
         }
         $index++;
     }
     foreach ($aFields as $sAttCode => $aDependencies) {
         // All fields with no remaining dependencies can be entered at this
         // step of the wizard
         if (count($aDependencies) > 0) {
             $iMaxPos = 0;
             // Remove this field from the dependencies of the other fields
             foreach ($aDependencies as $sDependentAttCode => $void) {
                 // position the current field after the ones it depends on
                 $iMaxPos = max($iMaxPos, 1 + $aOrder[$sDependentAttCode]);
             }
         }
     }
     asort($aOrder);
     $aCurrentStep = array();
     foreach ($aOrder as $sAttCode => $rank) {
         $aCurrentStep[] = $sAttCode;
         $aFieldsDone[$sAttCode] = '';
     }
     $aWizardSteps['mandatory'][] = $aCurrentStep;
     // Now computes the steps to fill the optional fields
     $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
//.........这里部分代码省略.........
开发者ID:leandroborgeseng,项目名称:bhtm,代码行数:101,代码来源:uiwizard.class.inc.php

示例5: ApplicationException

 $aStimuli = MetaModel::EnumStimuli($sClass);
 $sMessage = '';
 $sSeverity = 'ok';
 $bDisplayDetails = true;
 if (!isset($aTransitions[$sStimulus])) {
     throw new ApplicationException(Dict::Format('UI:Error:Invalid_Stimulus_On_Object_In_State', $sStimulus, $oObj->GetName(), $oObj->GetStateLabel()));
 }
 if (!utils::IsTransactionValid($sTransactionId)) {
     $sMessage = Dict::S('UI:Error:ObjectAlreadyUpdated');
     $sSeverity = 'info';
 } else {
     $sActionLabel = $aStimuli[$sStimulus]->GetLabel();
     $sActionDetails = $aStimuli[$sStimulus]->GetDescription();
     $aTransition = $aTransitions[$sStimulus];
     $sTargetState = $aTransition['target_state'];
     $aTargetStates = MetaModel::EnumStates($sClass);
     $aTargetState = $aTargetStates[$sTargetState];
     $aExpectedAttributes = $aTargetState['attribute_list'];
     $aDetails = array();
     $aErrors = array();
     foreach ($aExpectedAttributes as $sAttCode => $iExpectCode) {
         $iFlags = $oObj->GetAttributeFlags($sAttCode);
         if ($iExpectCode & (OPT_ATT_MUSTCHANGE | OPT_ATT_MUSTPROMPT) || $oObj->Get($sAttCode) == '') {
             $paramValue = utils::ReadPostedParam("attr_{$sAttCode}", '', 'raw_data');
             if ($iFlags & OPT_ATT_SLAVE && $paramValue != $oObj->Get($sAttCode)) {
                 $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
                 $aErrors[] = Dict::Format('UI:AttemptingToChangeASlaveAttribute_Name', $oAttDef->GetLabel());
                 unset($aExpectedAttributes[$sAttCode]);
             }
         }
     }
开发者ID:kira8565,项目名称:ITOP203-ZHCN,代码行数:31,代码来源:UI.php

示例6: GetAttributeFlags

 public static function GetAttributeFlags($sClass, $sState, $sAttCode)
 {
     $iFlags = 0;
     // By default (if no life cycle) no flag at all
     $sStateAttCode = self::GetStateAttributeCode($sClass);
     if (!empty($sStateAttCode)) {
         $aStates = MetaModel::EnumStates($sClass);
         if (!array_key_exists($sState, $aStates)) {
             throw new CoreException("Invalid state '{$sState}' for class '{$sClass}', expecting a value in {" . implode(', ', array_keys($aStates)) . "}");
         }
         $aCurrentState = $aStates[$sState];
         if (array_key_exists('attribute_list', $aCurrentState) && array_key_exists($sAttCode, $aCurrentState['attribute_list'])) {
             $iFlags = $aCurrentState['attribute_list'][$sAttCode];
         }
     }
     return $iFlags;
 }
开发者ID:henryavila,项目名称:itop,代码行数:17,代码来源:metamodel.class.php

示例7: ExecOperation

 /**
  * Enumerate services delivered by this class
  * @param string $sVersion The version (e.g. 1.0) supported by the services
  * @return RestResult The standardized result structure (at least a message)
  * @throws Exception in case of internal failure.	 
  */
 public function ExecOperation($sVersion, $sVerb, $aParams)
 {
     $oResult = new RestResultWithObjects();
     switch ($sVerb) {
         case 'core/create':
             RestUtils::InitTrackingComment($aParams);
             $sClass = RestUtils::GetClass($aParams, 'class');
             $aFields = RestUtils::GetMandatoryParam($aParams, 'fields');
             $aShowFields = RestUtils::GetFieldList($sClass, $aParams, 'output_fields');
             $bExtendedOutput = RestUtils::GetOptionalParam($aParams, 'output_fields', '*') == '*+';
             $oObject = RestUtils::MakeObjectFromFields($sClass, $aFields);
             $oObject->DBInsert();
             $oResult->AddObject(0, 'created', $oObject, $aShowFields, $bExtendedOutput);
             break;
         case 'core/update':
             RestUtils::InitTrackingComment($aParams);
             $sClass = RestUtils::GetClass($aParams, 'class');
             $key = RestUtils::GetMandatoryParam($aParams, 'key');
             $aFields = RestUtils::GetMandatoryParam($aParams, 'fields');
             $aShowFields = RestUtils::GetFieldList($sClass, $aParams, 'output_fields');
             $bExtendedOutput = RestUtils::GetOptionalParam($aParams, 'output_fields', '*') == '*+';
             $oObject = RestUtils::FindObjectFromKey($sClass, $key);
             RestUtils::UpdateObjectFromFields($oObject, $aFields);
             $oObject->DBUpdate();
             $oResult->AddObject(0, 'updated', $oObject, $aShowFields, $bExtendedOutput);
             break;
         case 'core/apply_stimulus':
             RestUtils::InitTrackingComment($aParams);
             $sClass = RestUtils::GetClass($aParams, 'class');
             $key = RestUtils::GetMandatoryParam($aParams, 'key');
             $aFields = RestUtils::GetMandatoryParam($aParams, 'fields');
             $aShowFields = RestUtils::GetFieldList($sClass, $aParams, 'output_fields');
             $bExtendedOutput = RestUtils::GetOptionalParam($aParams, 'output_fields', '*') == '*+';
             $sStimulus = RestUtils::GetMandatoryParam($aParams, 'stimulus');
             $oObject = RestUtils::FindObjectFromKey($sClass, $key);
             RestUtils::UpdateObjectFromFields($oObject, $aFields);
             $aTransitions = $oObject->EnumTransitions();
             $aStimuli = MetaModel::EnumStimuli(get_class($oObject));
             if (!isset($aTransitions[$sStimulus])) {
                 // Invalid stimulus
                 $oResult->code = RestResult::INTERNAL_ERROR;
                 $oResult->message = "Invalid stimulus: '{$sStimulus}' on the object " . $oObject->GetName() . " in state '" . $oObject->GetState() . "'";
             } else {
                 $aTransition = $aTransitions[$sStimulus];
                 $sTargetState = $aTransition['target_state'];
                 $aStates = MetaModel::EnumStates($sClass);
                 $aTargetStateDef = $aStates[$sTargetState];
                 $aExpectedAttributes = $aTargetStateDef['attribute_list'];
                 $aMissingMandatory = array();
                 foreach ($aExpectedAttributes as $sAttCode => $iExpectCode) {
                     if ($iExpectCode & OPT_ATT_MANDATORY && $oObject->Get($sAttCode) == '') {
                         $aMissingMandatory[] = $sAttCode;
                     }
                 }
                 if (count($aMissingMandatory) == 0) {
                     // If all the mandatory fields are already present, just apply the transition silently...
                     if ($oObject->ApplyStimulus($sStimulus)) {
                         $oObject->DBUpdate();
                         $oResult->AddObject(0, 'updated', $oObject, $aShowFields, $bExtendedOutput);
                     }
                 } else {
                     // Missing mandatory attributes for the transition
                     $oResult->code = RestResult::INTERNAL_ERROR;
                     $oResult->message = 'Missing mandatory attribute(s) for applying the stimulus: ' . implode(', ', $aMissingMandatory) . '.';
                 }
             }
             break;
         case 'core/get':
             $sClass = RestUtils::GetClass($aParams, 'class');
             $key = RestUtils::GetMandatoryParam($aParams, 'key');
             $aShowFields = RestUtils::GetFieldList($sClass, $aParams, 'output_fields');
             $bExtendedOutput = RestUtils::GetOptionalParam($aParams, 'output_fields', '*') == '*+';
             $oObjectSet = RestUtils::GetObjectSetFromKey($sClass, $key);
             while ($oObject = $oObjectSet->Fetch()) {
                 $oResult->AddObject(0, '', $oObject, $aShowFields, $bExtendedOutput);
             }
             $oResult->message = "Found: " . $oObjectSet->Count();
             break;
         case 'core/delete':
             $sClass = RestUtils::GetClass($aParams, 'class');
             $key = RestUtils::GetMandatoryParam($aParams, 'key');
             $bSimulate = RestUtils::GetOptionalParam($aParams, 'simulate', false);
             $oObjectSet = RestUtils::GetObjectSetFromKey($sClass, $key);
             $aObjects = $oObjectSet->ToArray();
             $this->DeleteObjects($oResult, $aObjects, $bSimulate);
             break;
         case 'core/get_related':
             $oResult = new RestResultWithRelations();
             $sClass = RestUtils::GetClass($aParams, 'class');
             $key = RestUtils::GetMandatoryParam($aParams, 'key');
             $sRelation = RestUtils::GetMandatoryParam($aParams, 'relation');
             $iMaxRecursionDepth = RestUtils::GetOptionalParam($aParams, 'depth', 20);
             $sDirection = RestUtils::GetOptionalParam($aParams, 'direction', null);
             $bEnableRedundancy = RestUtils::GetOptionalParam($aParams, 'redundancy', false);
//.........这里部分代码省略.........
开发者ID:henryavila,项目名称:itop,代码行数:101,代码来源:restservices.class.inc.php

示例8: DisplayLifecycle

/**
 * Helper for the lifecycle details of a given class
 */
function DisplayLifecycle($oPage, $sClass)
{
    $sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
    if (empty($sStateAttCode)) {
        $oPage->p(Dict::S('UI:Schema:NoLifeCyle'));
    } else {
        $aStates = MetaModel::EnumStates($sClass);
        $aStimuli = MetaModel::EnumStimuli($sClass);
        $oPage->add("<img src=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/graphviz.php?class={$sClass}\">\n");
        $oPage->add("<h3>" . Dict::S('UI:Schema:LifeCycleTransitions') . "</h3>\n");
        $oPage->add("<ul>\n");
        foreach ($aStates as $sStateCode => $aStateDef) {
            $sStateLabel = MetaModel::GetStateLabel($sClass, $sStateCode);
            $sStateDescription = MetaModel::GetStateDescription($sClass, $sStateCode);
            $oPage->add("<li title=\"code: {$sStateCode}\">{$sStateLabel} <span style=\"color:grey;\">({$sStateCode}) {$sStateDescription}</span></li>\n");
            $oPage->add("<ul>\n");
            foreach (MetaModel::EnumTransitions($sClass, $sStateCode) as $sStimulusCode => $aTransitionDef) {
                $sStimulusLabel = $aStimuli[$sStimulusCode]->GetLabel();
                $sTargetStateLabel = MetaModel::GetStateLabel($sClass, $aTransitionDef['target_state']);
                if (count($aTransitionDef['actions']) > 0) {
                    $sActions = " <em>(" . implode(', ', $aTransitionDef['actions']) . ")</em>";
                } else {
                    $sActions = "";
                }
                $oPage->add("<li><span style=\"color:red;font-weight=bold;\">{$sStimulusLabel}</span> =&gt; {$sTargetStateLabel} {$sActions}</li>\n");
            }
            $oPage->add("</ul>\n");
        }
        $oPage->add("</ul>\n");
        $oPage->add("<h3>" . Dict::S('UI:Schema:LifeCyleAttributeOptions') . "</h3>\n");
        $oPage->add("<ul>\n");
        foreach ($aStates as $sStateCode => $aStateDef) {
            $sStateLabel = MetaModel::GetStateLabel($sClass, $sStateCode);
            $sStateDescription = MetaModel::GetStateDescription($sClass, $sStateCode);
            $oPage->add("<li title=\"code: {$sStateCode}\">{$sStateLabel} <span style=\"color:grey;\">({$sStateCode}) {$sStateDescription}</span></li>\n");
            if (count($aStates[$sStateCode]['attribute_list']) > 0) {
                $oPage->add("<ul>\n");
                foreach ($aStates[$sStateCode]['attribute_list'] as $sAttCode => $iOptions) {
                    $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
                    $sAttLabel = $oAttDef->GetLabel();
                    $aOptions = array();
                    if ($iOptions & OPT_ATT_HIDDEN) {
                        $aOptions[] = Dict::S('UI:Schema:LifeCycleHiddenAttribute');
                    }
                    if ($iOptions & OPT_ATT_READONLY) {
                        $aOptions[] = Dict::S('UI:Schema:LifeCycleReadOnlyAttribute');
                    }
                    if ($iOptions & OPT_ATT_MANDATORY) {
                        $aOptions[] = Dict::S('UI:Schema:LifeCycleMandatoryAttribute');
                    }
                    if ($iOptions & OPT_ATT_MUSTCHANGE) {
                        $aOptions[] = Dict::S('UI:Schema:LifeCycleAttributeMustChange');
                    }
                    if ($iOptions & OPT_ATT_MUSTPROMPT) {
                        $aOptions[] = Dict::S('UI:Schema:LifeCycleAttributeMustPrompt');
                    }
                    if (count($aOptions)) {
                        $sOptions = implode(', ', $aOptions);
                    } else {
                        $sOptions = "";
                    }
                    $oPage->add("<li><span style=\"color:purple;font-weight=bold;\">{$sAttLabel}</span> {$sOptions}</li>\n");
                }
                $oPage->add("</ul>\n");
            } else {
                $oPage->p("<em>" . Dict::S('UI:Schema:LifeCycleEmptyList') . "</em>");
            }
        }
        $oPage->add("</ul>\n");
    }
}
开发者ID:kira8565,项目名称:ITOP203-ZHCN,代码行数:74,代码来源:schema.php

示例9: MakeDictionaryTemplate

function MakeDictionaryTemplate($sModules = '', $sLanguage = 'EN US')
{
    $sRes = '';
    Dict::SetDefaultLanguage($sLanguage);
    $aAvailableLanguages = Dict::GetLanguages();
    $sDesc = $aAvailableLanguages[$sLanguage]['description'];
    $sLocalizedDesc = $aAvailableLanguages[$sLanguage]['localized_description'];
    $sRes .= "// Dictionary conventions\n";
    $sRes .= htmlentities("// Class:<class_name>\n", ENT_QUOTES, 'UTF-8');
    $sRes .= htmlentities("// Class:<class_name>+\n", ENT_QUOTES, 'UTF-8');
    $sRes .= htmlentities("// Class:<class_name>/Attribute:<attribute_code>\n", ENT_QUOTES, 'UTF-8');
    $sRes .= htmlentities("// Class:<class_name>/Attribute:<attribute_code>+\n", ENT_QUOTES, 'UTF-8');
    $sRes .= htmlentities("// Class:<class_name>/Attribute:<attribute_code>/Value:<value>\n", ENT_QUOTES, 'UTF-8');
    $sRes .= htmlentities("// Class:<class_name>/Attribute:<attribute_code>/Value:<value>+\n", ENT_QUOTES, 'UTF-8');
    $sRes .= htmlentities("// Class:<class_name>/Stimulus:<stimulus_code>\n", ENT_QUOTES, 'UTF-8');
    $sRes .= htmlentities("// Class:<class_name>/Stimulus:<stimulus_code>+\n", ENT_QUOTES, 'UTF-8');
    $sRes .= "\n";
    // Note: I did not use EnumCategories(), because a given class maybe found in several categories
    // Need to invent the "module", to characterize the origins of a class
    if (strlen($sModules) == 0) {
        $aModules = array('bizmodel', 'core/cmdb', 'gui', 'application', 'addon/userrights', 'monitoring');
    } else {
        $aModules = explode(', ', $sModules);
    }
    $sRes .= "//////////////////////////////////////////////////////////////////////\n";
    $sRes .= "// Note: The classes have been grouped by categories: " . implode(', ', $aModules) . "\n";
    $sRes .= "//////////////////////////////////////////////////////////////////////\n";
    foreach ($aModules as $sCategory) {
        $sRes .= "//////////////////////////////////////////////////////////////////////\n";
        $sRes .= "// Classes in '{$sCategory}'\n";
        $sRes .= "//////////////////////////////////////////////////////////////////////\n";
        $sRes .= "//\n";
        $sRes .= "\n";
        foreach (MetaModel::GetClasses($sCategory) as $sClass) {
            if (!MetaModel::HasTable($sClass)) {
                continue;
            }
            $bNotInDico = false;
            $bNotImportant = true;
            $sClassRes = "//\n";
            $sClassRes .= "// Class: {$sClass}\n";
            $sClassRes .= "//\n";
            $sClassRes .= "\n";
            $sClassRes .= "Dict::Add('{$sLanguage}', '{$sDesc}', '{$sLocalizedDesc}', array(\n";
            $sClassRes .= MakeDictEntry("Class:{$sClass}", MetaModel::GetName_Obsolete($sClass), $sClass, $bNotInDico);
            $sClassRes .= MakeDictEntry("Class:{$sClass}+", MetaModel::GetClassDescription_Obsolete($sClass), '', $bNotImportant);
            foreach (MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) {
                if ($sAttCode == 'friendlyname') {
                    continue;
                }
                // Skip this attribute if not originaly defined in this class
                if (MetaModel::GetAttributeOrigin($sClass, $sAttCode) != $sClass) {
                    continue;
                }
                $sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}", $oAttDef->GetLabel_Obsolete(), $sAttCode, $bNotInDico);
                $sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}+", $oAttDef->GetDescription_Obsolete(), '', $bNotImportant);
                if ($oAttDef instanceof AttributeEnum) {
                    if (MetaModel::GetStateAttributeCode($sClass) == $sAttCode) {
                        foreach (MetaModel::EnumStates($sClass) as $sStateCode => $aStateData) {
                            if (array_key_exists('label', $aStateData)) {
                                $sValue = $aStateData['label'];
                            } else {
                                $sValue = MetaModel::GetStateLabel($sClass, $sStateCode);
                            }
                            if (array_key_exists('description', $aStateData)) {
                                $sValuePlus = $aStateData['description'];
                            } else {
                                $sValuePlus = MetaModel::GetStateDescription($sClass, $sStateCode);
                            }
                            $sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}/Value:{$sStateCode}", $sValue, '', $bNotInDico);
                            $sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}/Value:{$sStateCode}+", $sValuePlus, '', $bNotImportant);
                        }
                    } else {
                        foreach ($oAttDef->GetAllowedValues() as $sKey => $value) {
                            $sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}/Value:{$sKey}", $value, '', $bNotInDico);
                            $sClassRes .= MakeDictEntry("Class:{$sClass}/Attribute:{$sAttCode}/Value:{$sKey}+", $value, '', $bNotImportant);
                        }
                    }
                }
            }
            foreach (MetaModel::EnumStimuli($sClass) as $sStimulusCode => $oStimulus) {
                $sClassRes .= MakeDictEntry("Class:{$sClass}/Stimulus:{$sStimulusCode}", $oStimulus->GetLabel_Obsolete(), '', $bNotInDico);
                $sClassRes .= MakeDictEntry("Class:{$sClass}/Stimulus:{$sStimulusCode}+", $oStimulus->GetDescription_Obsolete(), '', $bNotImportant);
            }
            $sClassRes .= "));\n";
            $sClassRes .= "\n";
            $sRes .= $sClassRes;
        }
    }
    return $sRes;
}
开发者ID:leandroborgeseng,项目名称:bhtm,代码行数:91,代码来源:ajax.toolkit.php

示例10: MakeStimulusForm

/**
 * Create form to apply a stimulus
 * @param WebPage $oP The current web page
 * @param Object $oObj The target object
 * @param String $sStimulusCode Stimulus that will be applied
 * @param Array $aEditAtt List of attributes to edit
 * @return void
 */
function MakeStimulusForm(WebPage $oP, $oObj, $sStimulusCode, $aEditAtt)
{
    static $bHasStimulusForm = false;
    $sDialogId = $sStimulusCode . "_dialog";
    $sFormId = $sStimulusCode . "_form";
    $sCancelButtonLabel = Dict::S('UI:Button:Cancel');
    $oP->add('<div id="' . $sDialogId . '" style="display: none;">');
    $sClass = get_class($oObj);
    $oP->add('<form id="' . $sFormId . '" method="post">');
    $sTransactionId = utils::GetNewTransactionId();
    $oP->add("<input type=\"hidden\" id=\"transaction_id\" name=\"transaction_id\" value=\"{$sTransactionId}\">\n");
    $oP->add("<input type=\"hidden\" name=\"class\" value=\"{$sClass}\">");
    $oP->add("<input type=\"hidden\" name=\"id\" value=\"" . $oObj->GetKey() . "\">");
    $oP->add("<input type=\"hidden\" name=\"operation\" value=\"update_request\">");
    $oP->add("<input type=\"hidden\" id=\"stimulus_to_apply\" name=\"apply_stimulus\" value=\"{$sStimulusCode}\">\n");
    $aTransitions = $oObj->EnumTransitions();
    $aStimuli = MetaModel::EnumStimuli($sClass);
    if (!isset($aTransitions[$sStimulusCode])) {
        // Invalid stimulus
        throw new ApplicationException(Dict::Format('UI:Error:Invalid_Stimulus_On_Object_In_State', $sStimulusCode, $oObj->GetName(), $oObj->GetStateLabel()));
    }
    // Compute the attribute flags in the target state
    $aTransition = $aTransitions[$sStimulusCode];
    $sTargetState = $aTransition['target_state'];
    $aTargetStates = MetaModel::EnumStates($sClass);
    $aTargetState = $aTargetStates[$sTargetState];
    $aExpectedAttributes = $aTargetState['attribute_list'];
    foreach ($aEditAtt as $sAttCode) {
        $sValue = $oObj->Get($sAttCode);
        $sDisplayValue = $oObj->GetEditValue($sAttCode);
        $aArgs = array('this' => $oObj, 'formPrefix' => '');
        $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
        $sInputId = 'input_' . $sAttCode;
        $iFlags = array_key_exists($sAttCode, $aExpectedAttributes) ? $aExpectedAttributes[$sAttCode] : 0;
        $sHTMLValue = "<span id=\"field_{$sStimulusCode}_{$sInputId}\">" . cmdbAbstractObject::GetFormElementForField($oP, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', $iFlags, $aArgs) . '</span>';
        $oP->add('<h1>' . MetaModel::GetLabel($sClass, $sAttCode) . '</h1>');
        $oP->add($sHTMLValue);
    }
    $oP->add('</form>');
    $oP->add('</div>');
    if (!$bHasStimulusForm) {
        $bHasStimulusForm = true;
        $oP->add_script(<<<EOF

function RunStimulusDialog(sStimulusCode, sTitle, sOkButtonLabel)
{
\tvar sWidth = 'auto';
\tif (sStimulusCode == 'ev_reopen')
\t{
\t\t// Avoid having a dialog spanning the complete width of the window
\t\t// just because it contains a CaseLog entry
\t\tsWidth = '80%';
\t}
\t\t\t\t
\t\$('#'+sStimulusCode+'_dialog').dialog({
\t\theight: 'auto',
\t\twidth: sWidth,
\t\tmodal: true,
\t\ttitle: sTitle,
\t\tbuttons: [
\t\t{ text: sOkButtonLabel, click: function() {
\t\t\t\$(this).find('#'+sStimulusCode+'_form').submit();
\t\t} },
\t\t{ text: "{$sCancelButtonLabel}", click: function() {
\t\t\t\$(this).dialog( "close" );
\t\t} }
\t\t]
\t});
\t// Start the validation
\tCheckFields(sStimulusCode+'_form', false);
\t\$('#'+sStimulusCode+'_form').submit( function() {
\t\treturn OnSubmit(sStimulusCode+'_form');
\t});
}
EOF
);
    }
}
开发者ID:leandroborgeseng,项目名称:bhtm,代码行数:86,代码来源:index.php

示例11: test_object_lifecycle

 function test_object_lifecycle()
 {
     echo "<h4>Test object lifecycle</h4>";
     self::DumpVariable(MetaModel::GetStateAttributeCode("cmdbContact"));
     self::DumpVariable(MetaModel::EnumStates("cmdbContact"));
     self::DumpVariable(MetaModel::EnumStimuli("cmdbContact"));
     foreach (MetaModel::EnumStates("cmdbContact") as $sStateCode => $aStateDef) {
         echo "<p>Transition from <strong>{$sStateCode}</strong></p>\n";
         self::DumpVariable(MetaModel::EnumTransitions("cmdbContact", $sStateCode));
     }
     $oObj = MetaModel::GetObject("cmdbContact", 18);
     echo "Current state: " . $oObj->GetState() . "... let's go to school...";
     self::DumpVariable($oObj->EnumTransitions());
     $oObj->ApplyStimulus("toschool");
     echo "New state: " . $oObj->GetState() . "... let's get older...";
     self::DumpVariable($oObj->EnumTransitions());
     $oObj->ApplyStimulus("raise");
     echo "New state: " . $oObj->GetState() . "... let's try to go further... (should give an error)";
     self::DumpVariable($oObj->EnumTransitions());
     $oObj->ApplyStimulus("raise");
     // should give an error
 }
开发者ID:besmirzanaj,项目名称:itop-code,代码行数:22,代码来源:testlist.inc.php

示例12: ExecOperation

 /**
  * Enumerate services delivered by this class
  * @param string $sVersion The version (e.g. 1.0) supported by the services
  * @return RestResult The standardized result structure (at least a message)
  * @throws Exception in case of internal failure.	 
  */
 public function ExecOperation($sVersion, $sVerb, $aParams)
 {
     $oResult = new RestResultWithObjects();
     switch ($sVerb) {
         case 'core/create':
             RestUtils::InitTrackingComment($aParams);
             $sClass = RestUtils::GetClass($aParams, 'class');
             $aFields = RestUtils::GetMandatoryParam($aParams, 'fields');
             $aShowFields = RestUtils::GetFieldList($sClass, $aParams, 'output_fields');
             $bExtendedOutput = RestUtils::GetOptionalParam($aParams, 'output_fields', '*') == '*+';
             $oObject = RestUtils::MakeObjectFromFields($sClass, $aFields);
             $oObject->DBInsert();
             $oResult->AddObject(0, 'created', $oObject, $aShowFields, $bExtendedOutput);
             break;
         case 'core/update':
             RestUtils::InitTrackingComment($aParams);
             $sClass = RestUtils::GetClass($aParams, 'class');
             $key = RestUtils::GetMandatoryParam($aParams, 'key');
             $aFields = RestUtils::GetMandatoryParam($aParams, 'fields');
             $aShowFields = RestUtils::GetFieldList($sClass, $aParams, 'output_fields');
             $bExtendedOutput = RestUtils::GetOptionalParam($aParams, 'output_fields', '*') == '*+';
             $oObject = RestUtils::FindObjectFromKey($sClass, $key);
             RestUtils::UpdateObjectFromFields($oObject, $aFields);
             $oObject->DBUpdate();
             $oResult->AddObject(0, 'updated', $oObject, $aShowFields, $bExtendedOutput);
             break;
         case 'core/apply_stimulus':
             RestUtils::InitTrackingComment($aParams);
             $sClass = RestUtils::GetClass($aParams, 'class');
             $key = RestUtils::GetMandatoryParam($aParams, 'key');
             $aFields = RestUtils::GetMandatoryParam($aParams, 'fields');
             $aShowFields = RestUtils::GetFieldList($sClass, $aParams, 'output_fields');
             $bExtendedOutput = RestUtils::GetOptionalParam($aParams, 'output_fields', '*') == '*+';
             $sStimulus = RestUtils::GetMandatoryParam($aParams, 'stimulus');
             $oObject = RestUtils::FindObjectFromKey($sClass, $key);
             RestUtils::UpdateObjectFromFields($oObject, $aFields);
             $aTransitions = $oObject->EnumTransitions();
             $aStimuli = MetaModel::EnumStimuli(get_class($oObject));
             if (!isset($aTransitions[$sStimulus])) {
                 // Invalid stimulus
                 $oResult->code = RestResult::INTERNAL_ERROR;
                 $oResult->message = "Invalid stimulus: '{$sStimulus}' on the object " . $oObject->GetName() . " in state '" . $oObject->GetState() . "'";
             } else {
                 $aTransition = $aTransitions[$sStimulus];
                 $sTargetState = $aTransition['target_state'];
                 $aStates = MetaModel::EnumStates($sClass);
                 $aTargetStateDef = $aStates[$sTargetState];
                 $aExpectedAttributes = $aTargetStateDef['attribute_list'];
                 $aMissingMandatory = array();
                 foreach ($aExpectedAttributes as $sAttCode => $iExpectCode) {
                     if ($iExpectCode & OPT_ATT_MANDATORY && $oObject->Get($sAttCode) == '') {
                         $aMissingMandatory[] = $sAttCode;
                     }
                 }
                 if (count($aMissingMandatory) == 0) {
                     // If all the mandatory fields are already present, just apply the transition silently...
                     if ($oObject->ApplyStimulus($sStimulus)) {
                         $oObject->DBUpdate();
                         $oResult->AddObject(0, 'updated', $oObject, $aShowFields, $bExtendedOutput);
                     }
                 } else {
                     // Missing mandatory attributes for the transition
                     $oResult->code = RestResult::INTERNAL_ERROR;
                     $oResult->message = 'Missing mandatory attribute(s) for applying the stimulus: ' . implode(', ', $aMissingMandatory) . '.';
                 }
             }
             break;
         case 'core/get':
             $sClass = RestUtils::GetClass($aParams, 'class');
             $key = RestUtils::GetMandatoryParam($aParams, 'key');
             $aShowFields = RestUtils::GetFieldList($sClass, $aParams, 'output_fields');
             $bExtendedOutput = RestUtils::GetOptionalParam($aParams, 'output_fields', '*') == '*+';
             $oObjectSet = RestUtils::GetObjectSetFromKey($sClass, $key);
             while ($oObject = $oObjectSet->Fetch()) {
                 $oResult->AddObject(0, '', $oObject, $aShowFields, $bExtendedOutput);
             }
             $oResult->message = "Found: " . $oObjectSet->Count();
             break;
         case 'core/delete':
             $sClass = RestUtils::GetClass($aParams, 'class');
             $key = RestUtils::GetMandatoryParam($aParams, 'key');
             $bSimulate = RestUtils::GetOptionalParam($aParams, 'simulate', false);
             $oObjectSet = RestUtils::GetObjectSetFromKey($sClass, $key);
             $aObjects = $oObjectSet->ToArray();
             $this->DeleteObjects($oResult, $aObjects, $bSimulate);
             break;
         case 'core/get_related':
             $oResult = new RestResultWithRelations();
             $sClass = RestUtils::GetClass($aParams, 'class');
             $key = RestUtils::GetMandatoryParam($aParams, 'key');
             $sRelation = RestUtils::GetMandatoryParam($aParams, 'relation');
             $iMaxRecursionDepth = RestUtils::GetOptionalParam($aParams, 'depth', 20);
             $oObjectSet = RestUtils::GetObjectSetFromKey($sClass, $key);
             $aIndexByClass = array();
//.........这里部分代码省略.........
开发者ID:kira8565,项目名称:ITOP203-ZHCN,代码行数:101,代码来源:restservices.class.inc.php


注:本文中的MetaModel::EnumStates方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。