protected static function getCallOfServiceParameterElements(core_kernel_classes_Resource $serviceDefinition, core_kernel_classes_Resource $callOfService, $paramType) { $returnValue = array(); //array(); if (empty($paramType) || empty($serviceDefinition)) { return $returnValue; } $formalParameterType = ''; $actualParameterInOutType = ''; $formalParameterName = ''; $formalParameterSuffix = ''; if (strtolower($paramType) == "formalparameterin") { $formalParameterType = PROPERTY_SERVICESDEFINITION_FORMALPARAMIN; $actualParameterInOutType = PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN; $formalParameterName = __('Input Parameters'); $formalParameterSuffix = '_IN'; } elseif (strtolower($paramType) == "formalparameterout") { $formalParameterType = PROPERTY_SERVICESDEFINITION_FORMALPARAMOUT; $actualParameterInOutType = PROPERTY_CALLOFSERVICES_ACTUALPARAMETEROUT; $formalParameterName = __('Output Parameters'); $formalParameterSuffix = '_OUT'; } else { throw new Exception("unsupported formalParameter type : {$paramType}"); } //get the other parameter input elements $collection = null; $collection = $serviceDefinition->getPropertyValuesCollection(new core_kernel_classes_Property($formalParameterType)); if ($collection->count() > 0) { //start creating the BLOC of form element $descriptionElement = tao_helpers_form_FormFactory::getElement($paramType, 'Free'); $descriptionElement->setValue("<b>{$formalParameterName} :</b>"); $returnValue[$paramType] = $descriptionElement; } $actualParamClass = new core_kernel_classes_Class(CLASS_ACTUALPARAMETER); foreach ($collection->getIterator() as $formalParam) { if ($formalParam instanceof core_kernel_classes_Resource) { //create a form element: $inputName = $formalParam->getLabel(); //which will be equal to $actualParam->getLabel(); $inputUri = $formalParam->getUri(); // $inputUri = ""; $inputValue = ""; //get current value: //find actual param first! $actualParamValue = ''; $actualParamFromFormalParam = new core_kernel_classes_ContainerCollection(new common_Object(__METHOD__)); $actualParamFromFormalParamArray = $actualParamClass->searchInstances(array(PROPERTY_ACTUALPARAMETER_FORMALPARAMETER => $formalParam->getUri()), array('like' => false, 'recursive' => 0)); foreach ($actualParamFromFormalParamArray as $actualParam) { $actualParamFromFormalParam->add($actualParam); } $actualParamFromCallOfServices = $callOfService->getPropertyValuesCollection(new core_kernel_classes_Property($actualParameterInOutType)); //make an intersect with $collection = $callOfService->getPropertyValuesCollection(new core_kernel_classes_Property(PROPERTY_CALLOFSERVICES_ACTUALPARAMETEROUT)); $actualParamCollection = $actualParamFromFormalParam->intersect($actualParamFromCallOfServices); if (!$actualParamCollection->isEmpty()) { foreach ($actualParamCollection->getIterator() as $actualParam) { if ($actualParam instanceof core_kernel_classes_Resource) { //the actual param associated to the formal parameter of THE call of services has been found! //check the type of actual parameter: $inParameterProcessVariable = $actualParam->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_ACTUALPARAMETER_PROCESSVARIABLE)); //a resource $inParameterConstant = $actualParam->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_ACTUALPARAMETER_CONSTANTVALUE)); if (!is_null($inParameterProcessVariable)) { //the type is a processvariable so must be a resource: if (!$inParameterProcessVariable instanceof core_kernel_classes_Resource) { throw new common_Exception("the process variable set as the value of the parameter '" . $actualParam->getLabel() . "' is not a resource"); } $paramType = 'processvariable'; $inputValue = $inParameterProcessVariable->getUri(); } elseif (!is_null($inParameterConstant)) { //the type is a constant: $paramType = 'constant'; if ($inParameterConstant instanceof core_kernel_classes_Literal) { $inputValue = $inParameterConstant->literal; } else { if ($inParameterConstant instanceof core_kernel_classes_Resource) { $inputValue = $inParameterConstant->getUri(); //encode?? } } } else { //the type is not specified yet: } break; //stop as one iteration: there normally should be only one actual parameter set for a given formal parameter } } } if (empty($inputValue)) { //if no value set yet, try finding the default value (literal only! or url that are considered as a literal) $defaultConstantValue = $formalParam->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_FORMALPARAMETER_DEFAULTCONSTANTVALUE)); $defaultProcessVariable = $formalParam->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_FORMALPARAMETER_DEFAULTPROCESSVARIABLE)); $defaultValue = ''; if (!is_null($defaultProcessVariable)) { if ($defaultProcessVariable instanceof core_kernel_classes_Resource) { $defaultValue = $defaultProcessVariable->getUri(); //the case a url } else { throw new Exception('the process variable must be a resource'); } if (!empty($defaultValue)) { //the input value has been set as the default one: $paramType = 'processvariable'; $inputValue = $defaultValue; } } elseif (!is_null($defaultConstantValue)) { if ($defaultConstantValue instanceof core_kernel_classes_Literal) { $defaultValue = $defaultConstantValue->literal; } else { if ($defaultConstantValue instanceof core_kernel_classes_Resource) { $defaultValue = $defaultConstantValue->getUri(); //the case a url } } if (!empty($defaultValue)) { //the input value has been set as the default one: $paramType = 'constant'; $inputValue = $defaultValue; } } } $elementId = tao_helpers_Uri::encode($inputUri) . $formalParameterSuffix; $elementChoiceId = $elementId . '_choice'; $elementInputId = $elementId . '_constant'; $elementVarId = $elementId . '_var'; //element of type "free": $element = tao_helpers_form_FormFactory::getElement($elementId, 'Free'); $element->setValue($inputName . ': '); //set the choice element (radiobox: constant/processVariable: $elementChoice = tao_helpers_form_FormFactory::getElement($elementChoiceId, 'Radiobox'); $elementChoice->setDescription(' '); $options = array("constant" => __("Constant"), "processvariable" => __("Process Variable")); $elementChoice->setOptions($options); $elementChoice->setValue($paramType); //element input: $elementInput = tao_helpers_form_FormFactory::getElement($elementInputId, 'Textbox'); $elementInput->setDescription(' '); //element choice of process var (range: all or selected only?): $elementVar = tao_helpers_form_FormFactory::getElement($elementVarId, 'ComboBox'); $elementVar->setDescription(' '); $processVariables = array(); $processVariables = array('none' => ' '); $range = new core_kernel_classes_Class(CLASS_PROCESSVARIABLES); foreach ($range->getInstances(true) as $rangeInstance) { $processVariables[tao_helpers_Uri::encode($rangeInstance->getUri())] = $rangeInstance->getLabel(); } $elementVar->setOptions($processVariables); //set value here: if ($paramType == 'constant') { $elementInput->setValue($inputValue); } elseif ($paramType == 'processvariable') { $elementVar->setValue($inputValue); } $returnValue[$elementId] = $element; $returnValue[$elementChoiceId] = $elementChoice; $returnValue[$elementInputId] = $elementInput; $returnValue[$elementVarId] = $elementVar; } } return $returnValue; }