Beispiel #1
0
 /**
  * Build and load the item execution environment.
  * 
  * @param core_kernel_classes_Resource $processExecution
  * @param core_kernel_classes_Resource $item
  * @param core_kernel_classes_Resource $test
  * @param core_kernel_classes_Resource $delivery
  * @param core_kernel_classes_Resource $user
  * 
  * @return array
  */
 protected function createExecutionEnvironment(core_kernel_classes_Resource $processExecution, core_kernel_classes_Resource $item, core_kernel_classes_Resource $test, core_kernel_classes_Resource $delivery, core_kernel_classes_Resource $user)
 {
     $executionEnvironment = array();
     foreach (func_get_args() as $arg) {
         if (is_null($arg)) {
             return $executionEnvironment;
         }
     }
     //we build the data to give to the item
     $executionEnvironment = array('token' => $this->createToken(), 'localNamespace' => rtrim(common_ext_NamespaceManager::singleton()->getLocalNamespace()->getUri(), '#'), CLASS_PROCESS_EXECUTIONS => array('uri' => $processExecution->getUri(), RDFS_LABEL => $processExecution->getLabel()), TAO_ITEM_CLASS => array('uri' => $item->getUri(), RDFS_LABEL => $item->getLabel()), TAO_TEST_CLASS => array('uri' => $test->getUri(), RDFS_LABEL => $test->getLabel()), TAO_DELIVERY_CLASS => array('uri' => $delivery->getUri(), RDFS_LABEL => $delivery->getLabel()), TAO_SUBJECT_CLASS => array('uri' => $user->getUri(), RDFS_LABEL => $user->getLabel(), PROPERTY_USER_LOGIN => (string) $user->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_USER_LOGIN)), PROPERTY_USER_FIRSTNAME => (string) $user->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_USER_FIRSTNAME)), PROPERTY_USER_LASTNAME => (string) $user->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_USER_LASTNAME))));
     $session = PHPSession::singleton();
     $session->setAttribute(self::ENV_VAR_NAME . '_' . tao_helpers_Uri::encode($user->getUri()), $executionEnvironment);
     return $executionEnvironment;
 }
 public static function getBaseUrl(core_kernel_classes_Resource $serviceDefinition)
 {
     try {
         $url = common_cache_FileCache::singleton()->get(self::CACHE_PREFIX_URL . urlencode($serviceDefinition->getUri()));
     } catch (common_cache_NotFoundException $e) {
         $serviceDefinitionUrl = $serviceDefinition->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_SUPPORTSERVICES_URL));
         if ($serviceDefinitionUrl instanceof core_kernel_classes_Literal) {
             $serviceUrl = $serviceDefinitionUrl->literal;
         } else {
             if ($serviceDefinitionUrl instanceof core_kernel_classes_Resource) {
                 // hack nescessary since fully qualified urls are considered to be resources
                 $serviceUrl = $serviceDefinitionUrl->getUri();
             } else {
                 throw new common_exception_InconsistentData('Invalid service definition url for ' . $serviceDefinition->getUri());
             }
         }
         // Remove the parameters because they are only for show, and they are actualy encoded in the variables
         $urlPart = explode('?', $serviceUrl);
         $url = $urlPart[0];
         common_cache_FileCache::singleton()->put($url, self::CACHE_PREFIX_URL . urlencode($serviceDefinition->getUri()));
     }
     if ($url[0] == '/') {
         //create absolute url (prevent issue when TAO installed on a subfolder
         $url = ROOT_URL . ltrim($url, '/');
     }
     return $url;
 }
Beispiel #3
0
 /**
  * Short description of method getValue
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource resource
  * @param  Column column
  * @return string
  */
 public function getValue(core_kernel_classes_Resource $resource, tao_models_classes_table_Column $column)
 {
     $returnValue = (string) '';
     $result = $resource->getOnePropertyValue($column->getProperty());
     $returnValue = $result instanceof core_kernel_classes_Resource ? $result->getLabel() : (string) $result;
     return (string) $returnValue;
 }
 /**
  * Short description of method getElseActivity
  *
  * @access public
  * @author Lionel Lecaque, <*****@*****.**>
  * @param  Resource rule
  * @return core_kernel_classes_Resource
  */
 public function getElseActivity(core_kernel_classes_Resource $rule)
 {
     $returnValue = null;
     $elseProperty = new core_kernel_classes_Property(PROPERTY_TRANSITIONRULES_ELSE);
     $returnValue = $rule->getOnePropertyValue($elseProperty);
     return $returnValue;
 }
 /**
  * (non-PHPdoc)
  * @see taoTests_models_classes_TestModel::onTestModelSet()
  */
 public function deleteContent(core_kernel_classes_Resource $test)
 {
     $content = $test->getOnePropertyValue(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP));
     if (!is_null($content)) {
         $content->delete();
         $test->removePropertyValue(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP), $content);
     }
 }
 /**
  * Get user mail value
  * @param core_kernel_classes_Resource $user
  * @return string | null
  */
 public function getUserMail(\core_kernel_classes_Resource $user)
 {
     $userMailProperty = new \core_kernel_classes_Property(PROPERTY_USER_MAIL);
     $result = (string) $user->getOnePropertyValue($userMailProperty);
     if (!$result || !filter_var($result, FILTER_VALIDATE_EMAIL)) {
         $result = null;
     }
     return $result;
 }
 protected function logoutUser()
 {
     if (!is_null($this->currentUser)) {
         $loginProperty = new core_kernel_classes_Property(PROPERTY_USER_LOGIN);
         $this->out("logout " . $this->currentUser->getOnePropertyValue($loginProperty) . ' "' . $this->currentUser->getUri() . '"', true);
         $this->userService->logout();
         $this->currentUser = null;
     }
 }
 public function getValue($rowId, $columnId, $data = null)
 {
     $returnValue = null;
     if (isset($this->data[$rowId])) {
         //return values:
         if (isset($this->data[$rowId][$columnId])) {
             $returnValue = $this->data[$rowId][$columnId];
         }
     } else {
         if (common_Utils::isUri($rowId)) {
             $processInstance = new core_kernel_classes_Resource($rowId);
             //TODO: property uris need to be set in the constant files:
             $unit = $processInstance->getOnePropertyValue(TranslationProcessHelper::getProperty('unitUri'));
             $countryCode = $processInstance->getOnePropertyValue(TranslationProcessHelper::getProperty('CountryCOde'));
             $langCode = $processInstance->getOnePropertyValue(TranslationProcessHelper::getProperty('LanguageCode'));
             $this->data[$rowId] = array('unit' => is_null($unit) ? 'n/a' : $unit->getLabel(), 'country' => $countryCode instanceof core_kernel_classes_Literal ? $countryCode->literal : 'n/a', 'language' => $langCode instanceof core_kernel_classes_Literal ? $langCode->literal : 'n/a');
             if (isset($this->data[$rowId][$columnId])) {
                 $returnValue = $this->data[$rowId][$columnId];
             }
         }
     }
     return $returnValue;
 }
 /**
  * Short description of method getValue
  *
  * @access public
  * @author Somsack Sipasseuth, <*****@*****.**>
  * @param  string rowId
  * @param  string columnId
  * @param  string data
  * @return mixed
  */
 public function getValue($rowId, $columnId, $data = null)
 {
     $returnValue = null;
     $user = new core_kernel_classes_Resource($rowId);
     $prop = new core_kernel_classes_Property($columnId);
     $res = $user->getOnePropertyValue($prop);
     if (is_null($res)) {
         $returnValue = '';
     } elseif ($res instanceof core_kernel_classes_Resource) {
         $returnValue = $res->getLabel();
     } else {
         $returnValue = (string) $res;
     }
     return $returnValue;
 }
 /**
  * Used to create the form elements and bind them to the form instance
  *
  * @access protected
  * @return mixed
  */
 protected function initElements()
 {
     //create file upload form box
     $fileElt = \tao_helpers_form_FormFactory::getElement('source', 'AsyncFile');
     $fileElt->setDescription(__("Add a media file"));
     if (isset($_POST['import_sent_file'])) {
         $fileElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     } else {
         $fileElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty', array('message' => '')));
     }
     $fileElt->addValidators(array(\tao_helpers_form_FormFactory::getValidator('FileSize', array('max' => \tao_helpers_Environment::getFileUploadLimit()))));
     $this->form->addElement($fileElt);
     $langService = \tao_models_classes_LanguageService::singleton();
     $dataUsage = new \core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_DATA);
     $dataLang = \common_session_SessionManager::getSession()->getDataLanguage();
     $dataLang = 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . $dataLang;
     if (!is_null($this->instanceUri)) {
         $instance = new \core_kernel_classes_Resource($this->instanceUri);
         $lang = $instance->getOnePropertyValue(new \core_kernel_classes_Property(MEDIA_LANGUAGE));
         if ($lang instanceof \core_kernel_classes_Resource) {
             $dataLang = $lang->getUri();
         }
     }
     $langOptions = array();
     foreach ($langService->getAvailableLanguagesByUsage($dataUsage) as $lang) {
         $langOptions[\tao_helpers_Uri::encode($lang->getUri())] = $lang->getLabel();
     }
     $langElt = \tao_helpers_form_FormFactory::getElement('lang', 'Combobox');
     $langElt->setValue(\tao_helpers_Uri::encode($dataLang));
     $langElt->setOptions($langOptions);
     $this->form->addElement($langElt);
     $this->form->createGroup('options', __('Media Options'), array($langElt));
     $fileSentElt = \tao_helpers_form_FormFactory::getElement('import_sent_file', 'Hidden');
     $fileSentElt->setValue(1);
     $this->form->addElement($fileSentElt);
     if (!is_null($this->instanceUri)) {
         $instanceElt = \tao_helpers_form_FormFactory::getElement('instanceUri', 'Hidden');
         $instanceElt->setValue($this->instanceUri);
         $this->form->addElement($instanceElt);
     }
 }
 /**
  * (non-PHPdoc)
  * @see tao_actions_form_Instance::initElements()
  */
 protected function initElements()
 {
     parent::initElements();
     $elementId = tao_helpers_Uri::encode(TAO_ITEM_MODEL_PROPERTY);
     $ele = $this->form->getElement($elementId);
     $ele->feed();
     $modelUri = $ele->getEvaluatedValue();
     if (empty($modelUri)) {
         // remove deprecated models
         $statusProperty = new core_kernel_classes_Property(TAO_ITEM_MODEL_STATUS_PROPERTY);
         $options = array();
         foreach ($ele->getOptions() as $optUri => $optLabel) {
             $model = new core_kernel_classes_Resource(tao_helpers_Uri::decode($optUri));
             $status = $model->getOnePropertyValue($statusProperty);
             if (!is_null($status) && $status->getUri() != TAO_ITEM_MODEL_STATUS_DEPRECATED) {
                 $options[$optUri] = $optLabel;
             }
         }
         $ele->setOptions($options);
         if (count($options) === 1) {
             reset($options);
             $ele->setValue(key($options));
         }
     } else {
         // replace radio with hidden element
         $this->form->removeElement($elementId);
         $itemModelElt = tao_helpers_form_FormFactory::getElement($elementId, 'Hidden');
         $itemModelElt->setValue($modelUri);
         $this->form->addElement($itemModelElt);
         // display model label
         $model = new core_kernel_classes_Resource($modelUri);
         $itemModelLabelElt = tao_helpers_form_FormFactory::getElement('itemModelLabel', 'Label');
         $itemModelLabelElt->setDescription(__('Item Model'));
         $itemModelLabelElt->setValue($model->getLabel());
         $this->form->addElement($itemModelLabelElt);
     }
 }
 /**
  * returns an array with the defined default values for the
  * service definition's parameters
  * 
  * @param core_kernel_classes_Resource $serviceDefinition
  */
 public function setDefaultParameters(core_kernel_classes_Resource $serviceCall)
 {
     $serviceDefinition = $this->getServiceDefinition($serviceCall);
     $processService = wfAuthoring_models_classes_ProcessService::singleton();
     $processService->deleteActualParameters($serviceCall);
     $defaultConstProp = new core_kernel_classes_Property(PROPERTY_FORMALPARAMETER_DEFAULTCONSTANTVALUE);
     $params = $serviceDefinition->getPropertyValues(new core_kernel_classes_Property(PROPERTY_SERVICESDEFINITION_FORMALPARAMIN));
     foreach ($params as $paramUri) {
         $param = new core_kernel_classes_Resource($paramUri);
         $default = $param->getOnePropertyValue($defaultConstProp);
         if (!is_null($default)) {
             $processService->setActualParameter($serviceCall, $param, $default, PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN, PROPERTY_ACTUALPARAMETER_CONSTANTVALUE);
         }
     }
     $defaultVariableProp = new core_kernel_classes_Property(PROPERTY_FORMALPARAMETER_DEFAULTPROCESSVARIABLE);
     $params = $serviceDefinition->getPropertyValues(new core_kernel_classes_Property(PROPERTY_SERVICESDEFINITION_FORMALPARAMIN));
     foreach ($params as $paramUri) {
         $param = new core_kernel_classes_Resource($paramUri);
         $default = $param->getOnePropertyValue($defaultVariableProp);
         if (!is_null($default)) {
             $processService->setActualParameter($serviceCall, $param, $default, PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN, PROPERTY_ACTUALPARAMETER_PROCESSVARIABLE);
         }
     }
 }
 /**
  * Short description of method getItemModel
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource item
  * @return core_kernel_classes_Resource
  */
 public function getItemModel(core_kernel_classes_Resource $item)
 {
     $returnValue = null;
     $itemModel = $item->getOnePropertyValue($this->itemModelProperty);
     if ($itemModel instanceof core_kernel_classes_Resource) {
         $returnValue = $itemModel;
     }
     return $returnValue;
 }
 /**
  * Short description of method createTransitionRule
  *
  * @access private
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource connector
  * @param  Expression expression
  * @return core_kernel_classes_Resource
  */
 private function createTransitionRule(core_kernel_classes_Resource $connector, core_kernel_rules_Expression $expression)
 {
     $returnValue = null;
     $transitionRule = $connector->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_TRANSITIONRULE));
     if (empty($transitionRule) || $transitionRule == null) {
         //create an instance of transition rule:
         $transitionRuleClass = new core_kernel_classes_Class(CLASS_TRANSITIONRULES);
         $transitionRule = $transitionRuleClass->createInstance();
         //Associate the newly created transition rule to the connector:
         $connector->editPropertyValues(new core_kernel_classes_Property(PROPERTY_CONNECTORS_TRANSITIONRULE), $transitionRule->getUri());
     }
     if (empty($expression)) {
         common_Logger::e('condition is not an instance of ressource : ' . $expression);
     } else {
         //delete old condition:
         $oldCondition = $transitionRule->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_RULE_IF));
         if (!is_null($oldCondition)) {
             $this->deleteCondition($oldCondition);
         }
         $transitionRule->editPropertyValues(new core_kernel_classes_Property(PROPERTY_RULE_IF), $expression);
     }
     $returnValue = $transitionRule;
     return $returnValue;
 }
 /**
  * Returns the activityExecutions of a ProcessInstance
  * in order of execution
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource process
  * @return array
  */
 public static function getActivityExecutions(core_kernel_classes_Resource $process)
 {
     $returnValue = array();
     $prop = new core_kernel_classes_Property(PROPERTY_PROCESSINSTANCES_ACTIVITYEXECUTIONS);
     $activities = $process->getPropertyValues($prop);
     $nextmap = array();
     $previous = new core_kernel_classes_Property(PROPERTY_ACTIVITY_EXECUTION_PREVIOUS);
     $ordered = array();
     foreach ($activities as $activity) {
         $activityRessource = new core_kernel_classes_Resource($activity);
         $predecessor = $activityRessource->getOnePropertyValue($previous);
         if (is_null($predecessor)) {
             $currenturi = $activity;
             $returnValue[] = new core_kernel_classes_Resource($activity);
         } else {
             $nextmap[$predecessor->getUri()] = $activity;
         }
     }
     while (!empty($nextmap)) {
         $nexturi = $nextmap[$currenturi];
         $returnValue[] = new core_kernel_classes_Resource($nexturi);
         unset($nextmap[$currenturi]);
         $currenturi = $nexturi;
     }
     return (array) $returnValue;
 }
 /**
  * Short description of method getStatus
  *
  * @access public
  * @author Somsack Sipasseuth, <*****@*****.**>
  * @param  Resource processExecution
  * @return core_kernel_classes_Resource
  */
 public function getStatus(core_kernel_classes_Resource $processExecution)
 {
     $returnValue = null;
     $returnValue = $this->getCache(__METHOD__, array($processExecution));
     if (empty($returnValue)) {
         try {
             $status = $processExecution->getOnePropertyValue($this->processInstancesStatusProp);
             if (!is_null($status)) {
                 switch ($status->getUri()) {
                     case INSTANCE_PROCESSSTATUS_RESUMED:
                     case INSTANCE_PROCESSSTATUS_STARTED:
                     case INSTANCE_PROCESSSTATUS_FINISHED:
                     case INSTANCE_PROCESSSTATUS_PAUSED:
                     case INSTANCE_PROCESSSTATUS_CLOSED:
                         $returnValue = $status;
                         break;
                 }
             }
             $this->setCache(__METHOD__, array($processExecution), $returnValue);
         } catch (Exception $e) {
             throw new common_Exception('fail to retrieve processExecution Status : ' . $processExecution);
         }
     }
     return $returnValue;
 }
 /**
  * (non-PHPdoc)
  *
  * @see \oat\tao\model\media\MediaBrowser::download
  */
 public function download($link)
 {
     // get the media link from the resource
     $resource = new \core_kernel_classes_Resource(\tao_helpers_Uri::decode($link));
     $fileLink = $resource->getOnePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK));
     if (is_null($fileLink)) {
         throw new \tao_models_classes_FileNotFoundException($link);
     }
     $fileLink = $fileLink instanceof \core_kernel_classes_Resource ? $fileLink->getUri() : (string) $fileLink;
     $fileManagement = FileManager::getFileManagementModel();
     $filePath = $fileManagement->retrieveFile($fileLink);
     return $filePath;
 }
 /**
  * @param \core_kernel_classes_Resource $delivery
  * @throws \common_Exception
  * @return \core_kernel_classes_Resource new delivery resource
  */
 private function compileDelivery(\core_kernel_classes_Resource $delivery)
 {
     $testProperty = new \core_kernel_classes_Property('http://www.tao.lu/Ontologies/TAODelivery.rdf#AssembledDeliveryOrigin');
     $classProperty = new \core_kernel_classes_Property(RDF_TYPE);
     $test = $delivery->getOnePropertyValue($testProperty);
     $destinationClass = new \core_kernel_classes_Class($delivery->getOnePropertyValue($classProperty)->getUri());
     $deliveryCreationReport = SimpleDeliveryFactory::create($destinationClass, $test, $delivery->getLabel());
     if ($deliveryCreationReport->getType() == \common_report_Report::TYPE_ERROR) {
         \common_Logger::i('Unable to recompile delivery execution' . $delivery->getUri());
         throw new \common_Exception($deliveryCreationReport->getMessage());
     }
     /** @var \core_kernel_classes_Resource $newDelivery */
     $newDelivery = $deliveryCreationReport->getData();
     foreach (self::$propertiesToCopy as $propertyToCopy) {
         $propertyToCopy = new \core_kernel_classes_Property($propertyToCopy);
         $val = $delivery->getOnePropertyValue($propertyToCopy);
         if ($val) {
             $newDelivery->setPropertyValue($propertyToCopy, $val);
         }
     }
     $this->addPrefixToLabel($delivery);
     return $newDelivery;
 }
 public function findJoinFromActivityForward(core_kernel_classes_Resource $activity)
 {
     $returnValue = null;
     //put the activity being searched in an array to prevent searching from it again in case of back connection
     $this->checkedActivities[] = $activity->getUri();
     $connectorClass = new core_kernel_classes_Class(CLASS_CONNECTORS);
     $connector = $activity->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_STEP_NEXT));
     if (!is_null($connector)) {
         if (in_array($connector->getUri(), array_keys($this->checkedConnectors))) {
             continue;
         } else {
             $this->checkedConnectors[$connector->getUri()] = $connector;
         }
         //get the type of the connector:
         $connectorType = $connector->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_TYPE));
         if ($connectorType instanceof core_kernel_classes_Resource) {
             switch ($connectorType->getUri()) {
                 case INSTANCE_TYPEOFCONNECTORS_JOIN:
                     //parallel connector found:
                     if ($this->jump == 0) {
                         return $returnValue = $connector;
                     } else {
                         $this->jump--;
                     }
                     break;
                 case INSTANCE_TYPEOFCONNECTORS_PARALLEL:
                     //increment the class attribute $this->jump
                     $this->jump++;
                     break;
             }
         }
         //if the wanted join connector has not be found (i.e. no value returned so far):
         //get the nextActivitiesCollection and recursively execute the same function ON ONLY ONE of the next parallel branch, but both banches in case of a conditionnal connector
         $nextActivitiesCollection = $connector->getPropertyValuesCollection(new core_kernel_classes_Property(PROPERTY_STEP_NEXT));
         $cardinalityService = wfEngine_models_classes_ActivityCardinalityService::singleton();
         foreach ($nextActivitiesCollection->getIterator() as $nextActivity) {
             if ($cardinalityService->isCardinality($nextActivity)) {
                 $nextActivity = $cardinalityService->getDestination($nextActivity);
             }
             //if the nextActivity happens to have already been checked, jump it
             if (in_array($nextActivity->getUri(), $this->checkedActivities)) {
                 continue;
             } else {
                 $joinConnector = $this->findJoinFromActivityForward($nextActivity);
                 if ($joinConnector instanceof core_kernel_classes_Resource) {
                     //found it:
                     if ($this->jump != 0) {
                         throw new Exception('parallel connector returned while the "jump value" is not null (' . $this->jump . ')');
                     }
                     return $returnValue = $joinConnector;
                 }
             }
         }
     }
     return $returnValue;
     //null
 }
 /**
  * save the related items from the checkbox tree or from the sequence box
  * @return void
  */
 public function saveItems()
 {
     if (!tao_helpers_Request::isAjax()) {
         throw new Exception("wrong request mode");
     }
     $saved = false;
     $candidates = tao_helpers_form_GenerisTreeForm::getSelectedInstancesFromPost();
     foreach ($this->getRequestParameters() as $key => $value) {
         if (preg_match("/^instance_/", $key)) {
             $candidates[] = tao_helpers_Uri::decode($value);
         }
     }
     $items = array();
     foreach ($candidates as $uri) {
         $item = new core_kernel_classes_Resource($uri);
         $itemModel = $item->getOnePropertyValue(new core_kernel_classes_Property(TAO_ITEM_MODEL_PROPERTY));
         $supported = false;
         if (!is_null($itemModel)) {
             foreach ($itemModel->getPropertyValues(new core_kernel_classes_Property(TAO_ITEM_MODELTARGET_PROPERTY)) as $targeturi) {
                 if ($targeturi == TAO_ITEM_ONLINE_TARGET) {
                     $supported = true;
                     break;
                 }
             }
         }
         if ($supported) {
             array_push($items, $item);
         } else {
             throw new common_Exception($item->getLabel() . ' cannot be added to a test');
         }
     }
     if ($this->service->setTestItems($this->getCurrentInstance(), $items)) {
         $saved = true;
     }
     $this->returnJson(array('saved' => $saved));
 }
 /**
  * Check whether this Eligibility can by-pass the proctor authorization
  * @param Resource $eligibility
  * @return boolean true if the elligility can by-pass the proctor authorization
  */
 public function canByPassProctor(Resource $eligibility)
 {
     $canByPass = $eligibility->getOnePropertyValue(new Property(self::PROPERTY_BYPASSPROCTOR_URI));
     return !is_null($canByPass) ? $canByPass->getUri() == self::BOOLEAN_TRUE : false;
 }
 /**
  * Short description of method getConnectorsByActivity
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource activity
  * @param  array option
  * @param  boolean isConnector
  * @return array
  */
 public function getConnectorsByActivity(core_kernel_classes_Resource $activity, $option = array(), $isConnector = false)
 {
     $returnValue = array();
     //prev: the connectors that links to the current activity
     //next: the connector (should be unique for an activiy that is not a connector itself) that follows the current activity
     $returnValue = array('prev' => array(), 'next' => array());
     if (empty($option)) {
         //the default option: select all connectors
         $option = array('prev', 'next');
     } else {
         $option = array_map('strtolower', $option);
     }
     $connectorsClass = new core_kernel_classes_Class(CLASS_CONNECTORS);
     if (in_array('prev', $option)) {
         $previousConnectors = $connectorsClass->searchInstances(array(PROPERTY_STEP_NEXT => $activity->getUri()), array('like' => false, 'recursive' => 0));
         foreach ($previousConnectors as $connector) {
             if (!is_null($connector)) {
                 if ($connector instanceof core_kernel_classes_Resource) {
                     $returnValue['prev'][$connector->getUri()] = $connector;
                 }
             }
         }
     }
     if (in_array('next', $option)) {
         $connector = $activity->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_STEP_NEXT));
         if ($connector instanceof core_kernel_classes_Resource) {
             $returnValue['next'][$connector->getUri()] = $connector;
         }
     }
     return (array) $returnValue;
 }
 /**
  * Short description of method getCode
  *
  * @access public
  * @author Somsack Sipasseuth, <*****@*****.**>
  * @param  Resource variable
  * @return string
  */
 public function getCode(core_kernel_classes_Resource $variable)
 {
     $returnValue = (string) '';
     $returnValue = $variable->getOnePropertyValue($this->codeProperty);
     return (string) $returnValue;
 }
 /**
  * Short description of method getTransitionRule
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource connector
  * @return core_kernel_classes_Resource
  */
 public function getTransitionRule(core_kernel_classes_Resource $connector)
 {
     $returnValue = null;
     $ruleProp = new core_kernel_classes_Property(PROPERTY_CONNECTORS_TRANSITIONRULE);
     $returnValue = $connector->getOnePropertyValue($ruleProp);
     return $returnValue;
 }
 public static function nextActivityElements(core_kernel_classes_Resource $connector, $type, $allowCreation = true, $includeConnectors = true, $optionsWidget = 'Combobox')
 {
     $returnValue = array();
     $authorizedOptionsWidget = array('Combobox', 'Checkbox');
     if (!in_array($optionsWidget, $authorizedOptionsWidget)) {
         throw new Exception('Wrong type of widget');
         return $returnValue;
     }
     $idPrefix = '';
     $nextActivity = null;
     $propTransitionRule = new core_kernel_classes_Property(PROPERTY_CONNECTORS_TRANSITIONRULE);
     $propNextActivities = new core_kernel_classes_Property(PROPERTY_STEP_NEXT);
     //find the next activity if available
     switch (strtolower($type)) {
         case 'next':
             $nextActivityCollection = $connector->getPropertyValuesCollection($propNextActivities);
             foreach ($nextActivityCollection->getIterator() as $activity) {
                 if ($activity instanceof core_kernel_classes_Resource) {
                     $nextActivity = $activity;
                     //we take the last one...(note: there should be only one though)
                 }
             }
             $idPrefix = 'next';
             break;
         case 'then':
             $transitionRuleCollection = $connector->getPropertyValuesCollection($propTransitionRule);
             foreach ($transitionRuleCollection->getIterator() as $transitionRule) {
                 if ($transitionRule instanceof core_kernel_classes_Resource) {
                     foreach ($transitionRule->getPropertyValuesCollection(new core_kernel_classes_Property(PROPERTY_TRANSITIONRULES_THEN))->getIterator() as $then) {
                         if ($then instanceof core_kernel_classes_Resource) {
                             $nextActivity = $then;
                         }
                     }
                 }
             }
             $idPrefix = 'then';
             break;
         case 'else':
             $transitionRuleCollection = $connector->getPropertyValuesCollection($propTransitionRule);
             foreach ($transitionRuleCollection->getIterator() as $transitionRule) {
                 if ($transitionRule instanceof core_kernel_classes_Resource) {
                     foreach ($transitionRule->getPropertyValuesCollection(new core_kernel_classes_Property(PROPERTY_TRANSITIONRULES_ELSE))->getIterator() as $else) {
                         if ($else instanceof core_kernel_classes_Resource) {
                             $nextActivity = $else;
                         }
                     }
                 }
             }
             $idPrefix = 'else';
             break;
         case 'parallel':
             $nextActivity = array();
             $nextActivityCollection = $connector->getPropertyValuesCollection($propNextActivities);
             foreach ($nextActivityCollection->getIterator() as $cardinality) {
                 if ($cardinality instanceof core_kernel_classes_Resource) {
                     $nextActivity[] = $cardinality;
                 }
             }
             $idPrefix = 'parallel';
             break;
         case 'join':
             // should only have one following activity
             $nextActivity = $connector->getOnePropertyValue($propNextActivities);
             $idPrefix = $type;
             break;
         default:
             throw new Exception("unknown type for the next activity");
     }
     $activityOptions = array();
     $connectorOptions = array();
     if ($allowCreation) {
         //create the activity label element (used only in case of new activity craetion)
         $elementActivityLabel = tao_helpers_form_FormFactory::getElement($idPrefix . "_activityLabel", 'Textbox');
         $elementActivityLabel->setDescription(__('Label'));
         //add the "creating" option
         $activityOptions["newActivity"] = __("create new activity");
         $connectorOptions["newConnector"] = __("create new connector");
     }
     //the activity associated to the connector:
     $referencedActivity = $connector->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_ACTIVITYREFERENCE));
     //mandatory property value, initiated at the connector creation
     if ($referencedActivity instanceof core_kernel_classes_Resource) {
         $processDefClass = new core_kernel_classes_Class(CLASS_PROCESS);
         $processes = $processDefClass->searchInstances(array(PROPERTY_PROCESS_ACTIVITIES => $referencedActivity->getUri()), array('like' => false));
         if (count($processes) > 0) {
             $process = array_shift($processes);
             if (!empty($process)) {
                 //get list of activities and connectors for the current process:
                 $connectorClass = new core_kernel_classes_Class(CLASS_CONNECTORS);
                 $processAuthoringService = wfAuthoring_models_classes_ProcessService::singleton();
                 $activities = $processAuthoringService->getActivitiesByProcess($process);
                 foreach ($activities as $activityTemp) {
                     //include activities options:
                     $encodedUri = tao_helpers_Uri::encode($activityTemp->getUri());
                     $activityOptions[$encodedUri] = $activityTemp->getLabel();
                     if (strtolower($type) == 'parallel') {
                         $elementHidden = tao_helpers_form_FormFactory::getElement("{$encodedUri}_num_hidden", 'Hidden');
                         $returnValue[$idPrefix . '_' . $activityTemp->getUri()] = $elementHidden;
                     }
                     //include connectors options:
                     if ($includeConnectors) {
                         $connectors = $connectorClass->searchInstances(array(PROPERTY_CONNECTORS_ACTIVITYREFERENCE => $activityTemp->getUri()), array('like' => false));
                         foreach ($connectors as $connectorTemp) {
                             if ($connector->getUri() != $connectorTemp->getUri()) {
                                 $connectorOptions[tao_helpers_Uri::encode($connectorTemp->getUri())] = $connectorTemp->getLabel();
                             }
                         }
                     }
                 }
             }
         }
     }
     //create the description element
     $elementDescription = tao_helpers_form_FormFactory::getElement($idPrefix, 'Free');
     $elementDescription->setValue(strtoupper($type) . ' :');
     //create the activity select element:
     $elementActivities = tao_helpers_form_FormFactory::getElement($idPrefix . "_activityUri", $optionsWidget);
     $elementActivities->setDescription(__('Activity'));
     $elementActivities->setOptions($activityOptions);
     $elementChoice = null;
     $elementConnectors = null;
     if ($includeConnectors) {
         //the default radio button to select between the 3 possibilities:
         $elementChoice = tao_helpers_form_FormFactory::getElement($idPrefix . "_activityOrConnector", 'Radiobox');
         $elementChoice->setDescription(__('Activity or Connector'));
         $options = array("activity" => __("Activity"), "connector" => __("Connector"));
         $elementChoice->setOptions($options);
         //create the connector select element:
         $elementConnectors = tao_helpers_form_FormFactory::getElement($idPrefix . "_connectorUri", $optionsWidget);
         $elementConnectors->setDescription(__('Connector'));
         $elementConnectors->setOptions($connectorOptions);
     }
     if (!empty($nextActivity)) {
         if (is_array($nextActivity) && $optionsWidget == 'Checkbox') {
             if (strtolower($type) == 'parallel') {
                 $cardinalityService = wfEngine_models_classes_ActivityCardinalityService::singleton();
                 foreach ($nextActivity as $cardinality) {
                     $activity = $cardinalityService->getDestination($cardinality);
                     $number = $cardinalityService->getCardinality($cardinality);
                     if (isset($returnValue[$idPrefix . '_' . $activity->getUri()])) {
                         $returnValue[$idPrefix . '_' . $activity->getUri()]->setValue($number instanceof core_kernel_classes_Resource ? tao_helpers_Uri::encode($number->getUri()) : intval($number));
                     }
                     $elementActivities->setValue($activity->getUri());
                     //no need for tao_helpers_Uri::encode
                 }
             } else {
                 foreach ($nextActivity as $activity) {
                     $elementActivities->setValue($activity->getUri());
                     //no need for tao_helpers_Uri::encode
                 }
             }
         } elseif ($nextActivity instanceof core_kernel_classes_Resource) {
             $aService = wfEngine_models_classes_ActivityService::singleton();
             if ($aService->isActivity($nextActivity)) {
                 if ($includeConnectors) {
                     $elementChoice->setValue("activity");
                 }
                 $elementActivities->setValue($nextActivity->getUri());
                 //no need for tao_helpers_Uri::encode
             }
             $conmectorService = wfEngine_models_classes_ConnectorService::singleton();
             if ($conmectorService->isConnector($nextActivity) && $includeConnectors) {
                 $elementChoice->setValue("connector");
                 $elementConnectors->setValue($nextActivity->getUri());
             }
         }
     }
     //put all elements in the return value:
     $returnValue[$idPrefix . '_description'] = $elementDescription;
     if ($includeConnectors) {
         $returnValue[$idPrefix . '_choice'] = $elementChoice;
     }
     $returnValue[$idPrefix . '_activities'] = $elementActivities;
     if ($allowCreation) {
         $returnValue[$idPrefix . '_label'] = $elementActivityLabel;
     }
     if ($includeConnectors) {
         $returnValue[$idPrefix . '_connectors'] = $elementConnectors;
     }
     return $returnValue;
 }
 /**
  * Test the tokens into a parallel process
  */
 public function testVirtualParallelJoinProcess()
 {
     error_reporting(E_ALL);
     $t_start = microtime(true);
     //init services
     $activityService = wfEngine_models_classes_ActivityService::singleton();
     $processVariableService = wfEngine_models_classes_VariableService::singleton();
     $authoringService = wfAuthoring_models_classes_ProcessService::singleton();
     $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
     $activityExecutionService->cache = (bool) self::SERVICE_CACHE;
     //process definition
     $processDefinitionClass = new core_kernel_classes_Class(CLASS_PROCESS);
     $processDefinition = $processDefinitionClass->createInstance('PJ processForUnitTest_' . date(DATE_ISO8601), 'created for the unit test of process execution');
     $this->assertNotNull($processDefinition);
     /*
     		                +---------------+
     		                |  activity 0   |
     		                +-------+-------+
     		                        |
     		                    +---v---+
     		                    |  c 0  |   split
     		                    +--+-+--+
     		                       | |
     		          3  +---------+ +---------+  unit_var_12345678
     		             |                     |
     		     +-------v--------+    +-------v------+
     		     |   activity 1   |    |  activity 2  |
     		     +-------+--------+    +--------+-----+
     		             |                      |
     		             +--------+    +--------+
     		                   +--v----v--+
     		                   |   c 2    |    join
     		                   +----+-----+
     		                        |
     		                +-------v--------+
     		                |  activity 3    |
     		                +----------------+
     */
     //activities definitions
     $activity0 = $authoringService->createActivity($processDefinition, 'activity0');
     $this->assertNotNull($activity0);
     $connector0 = null;
     $authoringService->setFirstActivity($processDefinition, $activity0);
     $connector0 = $authoringService->createConnector($activity0);
     $connectorParallele = new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_PARALLEL);
     $authoringService->setConnectorType($connector0, $connectorParallele);
     $this->assertNotNull($connector0);
     $parallelActivity1 = $authoringService->createActivity($processDefinition, 'activity1');
     $this->assertNotNull($parallelActivity1);
     $roleRestrictedUser = new core_kernel_classes_Resource(INSTANCE_ACL_ROLE_RESTRICTED_USER);
     $activityService->setAcl($parallelActivity1, $roleRestrictedUser, $this->testUserRole);
     //!!! it is mendatory to set the role restricted user ACL mode to make this parallel process test case work
     $connector1 = null;
     $connector1 = $authoringService->createConnector($parallelActivity1);
     $this->assertNotNull($connector1);
     $parallelActivity2 = $authoringService->createActivity($processDefinition, 'activity2');
     $this->assertNotNull($parallelActivity2);
     $activityService->setAcl($parallelActivity2, $roleRestrictedUser, $this->testUserRole);
     //!!! it is mendatory to set the role restricted user ACL mode to make this parallel process test case work
     $connector2 = null;
     $connector2 = $authoringService->createConnector($parallelActivity2);
     $this->assertNotNull($connector2);
     //define parallel activities, first branch with constant cardinality value, while the second listens to a process variable:
     $parallelCount1 = 3;
     $parallelCount2 = 5;
     $parallelCount2_processVar_key = 'unit_var_' . time();
     $parallelCount2_processVar = $processVariableService->createProcessVariable('Var for unit test', $parallelCount2_processVar_key);
     $prallelActivitiesArray = array($parallelActivity1->getUri() => $parallelCount1, $parallelActivity2->getUri() => $parallelCount2_processVar);
     $result = $authoringService->setParallelActivities($connector0, $prallelActivitiesArray);
     $this->assertTrue($result);
     //set several split variables:
     $splitVariable1_key = 'unit_split_var1_' . time();
     $splitVariable1 = $processVariableService->createProcessVariable('Split Var1 for unit test', $splitVariable1_key);
     $splitVariable2_key = 'unit_split_var2_' . time();
     $splitVariable2 = $processVariableService->createProcessVariable('Split Var2 for unit test', $splitVariable2_key);
     $splitVariablesArray = array($parallelActivity1->getUri() => array($splitVariable1), $parallelActivity2->getUri() => array($splitVariable1, $splitVariable2));
     $connectorService = wfAuthoring_models_classes_ConnectorService::singleton();
     $connectorService->setSplitVariables($connector0, $splitVariablesArray);
     $prallelActivitiesArray[$parallelActivity2->getUri()] = $parallelCount2;
     $joinActivity = $authoringService->createActivity($processDefinition, 'activity3');
     //join parallel Activity 1 and 2 to "joinActivity"
     $connector1 = wfAuthoring_models_classes_ConnectorService::singleton()->createJoin(array($parallelActivity1, $parallelActivity2), $joinActivity);
     /*
     $authoringService->createJoinActivity($connector1, $joinActivity, '', $parallelActivity1);
     $authoringService->createJoinActivity($connector2, $joinActivity, '', $parallelActivity2);
     */
     //run the process
     $processExecName = 'Test Parallel Process Execution';
     $processExecComment = 'created for processExecustionService test case by ' . __METHOD__;
     $processInstance = $this->service->createProcessExecution($processDefinition, $processExecName, $processExecComment);
     $this->assertTrue($this->service->checkStatus($processInstance, 'started'));
     $this->out(__METHOD__, true);
     $this->out("<strong>Forward transitions:</strong>", true);
     $previousActivityExecution = null;
     $numberActivities = 2 + $parallelCount1 + $parallelCount2;
     $createdUsers = array();
     $loginProperty = new core_kernel_classes_Property(PROPERTY_USER_LOGIN);
     for ($i = 1; $i <= $numberActivities; $i++) {
         $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
         $countActivities = count($activitieExecs);
         $activity = null;
         $activityExecution = null;
         if ($countActivities > 1) {
             //select one of the available activities in the parallel branch:
             foreach ($activitieExecs as $activityExecUri => $activityExec) {
                 if (!$activityExecutionService->isFinished($activityExec)) {
                     $activityDefinition = $activityExecutionService->getExecutionOf($activityExec);
                     $activityUri = $activityDefinition->getUri();
                     if (isset($prallelActivitiesArray[$activityUri])) {
                         if ($prallelActivitiesArray[$activityUri] > 0) {
                             $prallelActivitiesArray[$activityUri]--;
                             $activityExecution = $activityExec;
                             $activity = $activityDefinition;
                             break;
                         }
                     }
                 }
             }
         } else {
             if ($countActivities == 1) {
                 $activityExecution = reset($activitieExecs);
                 $activity = $activityExecutionService->getExecutionOf($activityExecution);
             } else {
                 $this->fail('no current activity definition found for the iteration ' . $i);
             }
         }
         $this->out("<strong> Iteration {$i} :</strong>", true);
         $this->out("<strong>" . (is_null($activity) ? 'null' : $activity->getLabel()) . "</strong> (among {$countActivities})");
         //issue : no activity found for the last iteration...
         //init execution
         $activityExecution = $this->service->initCurrentActivityExecution($processInstance, $activityExecution, $this->currentUser);
         $this->assertNotNull($activityExecution);
         if ($i == 1) {
             //set value of the parallel thread:
             $processVariableService->push($parallelCount2_processVar_key, $parallelCount2);
             //set some values to the split variables:
             $values1 = array();
             for ($j = 1; $j <= $parallelCount1; $j++) {
                 $values1[] = 'A' . $j;
             }
             $values2 = array();
             for ($j = 1; $j <= $parallelCount2; $j++) {
                 $values2[] = 'B' . $j;
             }
             $processVariableService->push($splitVariable1_key, serialize($values1));
             $processVariableService->push($splitVariable2_key, serialize($values2));
         } else {
             //check dispatched value:
             //				$value1 = $processVariableService->get($splitVariable1_key);
             //				$value2 = $processVariableService->get($splitVariable2_key);
             //				var_dump($value1, $value2);
         }
         $activityExecStatus = $activityExecutionService->getStatus($activityExecution);
         $this->assertNotNull($activityExecStatus);
         $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_STARTED);
         //transition to next activity
         $this->out("current user: "******"' . $this->currentUser->getUri() . '"');
         $this->out("performing transition ...");
         //transition to next activity
         $performed = $this->service->performTransition($processInstance, $activityExecution);
         if (!$performed) {
             $this->out('transition failed.');
         }
         $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel());
         $this->out("process status: " . $this->service->getStatus($processInstance)->getLabel());
         //try undoing the transition:
         switch ($i) {
             case 1:
                 $this->assertTrue($this->service->undoForwardTransition($processInstance, $activityExecution));
                 $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
                 $this->assertEquals(count($activitieExecs), 1);
                 $activityBis = $activityExecutionService->getExecutionOf(reset($activitieExecs));
                 $this->assertTrue($activity->getUri() == $activityBis->getUri());
                 $transitionResult = $this->service->performTransition($processInstance, $activityExecution);
                 break;
             case 1 + $parallelCount1:
                 $this->assertFalse($this->service->undoForwardTransition($processInstance, $activityExecution));
                 $history = $this->service->getExecutionHistory($processInstance);
                 $this->assertEquals(count($history), 2 * ($parallelCount1 + $parallelCount2) + 1);
                 //activity 1, 2(closed), 2, 3 and 4
                 $this->assertFalse($this->service->undoForwardTransition($processInstance, new core_kernel_classes_Resource(reset($history))));
                 $this->assertNotNull($previousActivityExecution);
                 $this->assertFalse($this->service->undoForwardTransition($processInstance, $previousActivityExecution));
                 break;
             case 1 + $parallelCount1 + $parallelCount2:
                 $this->assertTrue($this->service->undoForwardTransition($processInstance, $activityExecution));
                 $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
                 $this->assertEquals(count($activitieExecs), $parallelCount1 + $parallelCount2);
                 $transitionResult = $this->service->performTransition($processInstance, $activityExecution);
                 break;
         }
         $previousActivityExecution = $activityExecution;
         if ($this->service->isPaused($processInstance)) {
             //Login another user to execute parallel branch
             $this->userService->logout();
             $this->out("logout " . $this->currentUser->getOnePropertyValue($loginProperty) . ' "' . $this->currentUser->getUri() . '"', true);
             list($usec, $sec) = explode(" ", microtime());
             $login = '******' . $i . '-' . $usec;
             $pass = '******';
             $userData = array(PROPERTY_USER_LOGIN => $login, PROPERTY_USER_PASSWORD => core_kernel_users_Service::getPasswordHash()->encrypt($pass), PROPERTY_USER_DEFLG => 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . DEFAULT_LANG, PROPERTY_USER_UILG => 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . DEFAULT_LANG, PROPERTY_USER_ROLES => INSTANCE_ROLE_WORKFLOW, RDFS_LABEL => $login);
             if (!$this->userService->loginAvailable($login)) {
                 $this->fail('test login already taken');
             }
             $otherUser = $this->testUserClass->createInstanceWithProperties($userData);
             $createdUsers[$otherUser->getUri()] = $otherUser;
             if ($this->userService->loginUser($login, $pass)) {
                 $this->currentUser = $this->userService->getCurrentUser();
                 $this->out("new user logged in: " . $this->currentUser->getOnePropertyValue($loginProperty) . ' "' . $this->currentUser->getUri() . '"');
             } else {
                 $this->fail("unable to login user {$login}");
             }
         }
     }
     $this->assertTrue($this->service->isFinished($processInstance));
     $this->assertTrue($this->service->resume($processInstance));
     $this->out("<strong>Backward transitions:</strong>", true);
     //		var_dump($this->service->getAllActivityExecutions($processInstance));
     $j = 0;
     $iterationNumber = 2;
     while ($j < $iterationNumber) {
         $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
         $activityExecution = null;
         $activity = null;
         switch ($j) {
             case 0:
                 $this->assertEquals(count($activitieExecs), 1);
                 //check
                 $activityExecution = reset($activitieExecs);
                 $activity = $activityExecutionService->getExecutionOf($activityExecution);
                 break;
             case 1:
                 $this->assertEquals(count($activitieExecs), $parallelCount1 + $parallelCount2);
                 //check
                 $activity = $parallelActivity2;
                 foreach ($this->service->getCurrentActivityExecutions($processInstance, $activity) as $activityExec) {
                     if ($activityExecutionService->getActivityExecutionUser($activityExec)->getUri() == $this->currentUser->getUri()) {
                         $activityExecution = $activityExec;
                     }
                 }
                 if (is_null($activityExecution)) {
                     $activity = $parallelActivity1;
                     foreach ($this->service->getCurrentActivityExecutions($processInstance, $activity) as $activityExec) {
                         if ($activityExecutionService->getActivityExecutionUser($activityExec)->getUri() == $this->currentUser->getUri()) {
                             $activityExecution = $activityExec;
                         }
                     }
                 }
                 $this->assertNotNull($activityExecution);
                 break;
         }
         $this->out("<strong>" . $activity->getLabel() . "</strong>", true);
         //init execution
         $activityExecution = $this->service->initCurrentActivityExecution($processInstance, $activityExecution, $this->currentUser);
         $this->assertNotNull($activityExecution);
         $activityExecStatus = $activityExecutionService->getStatus($activityExecution);
         $this->assertNotNull($activityExecStatus);
         $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_RESUMED);
         $this->out("current user: "******"' . $this->currentUser->getUri() . '"');
         $this->out("performing transition ...");
         //transition to next activity
         $transitionResult = $this->service->performBackwardTransition($processInstance, $activityExecution);
         if ($j == 0) {
             $this->assertTrue(count($transitionResult) > 0);
         } else {
             if ($j == $iterationNumber - 1) {
                 //var_dump($transitionResult);
                 $this->assertFalse($transitionResult);
             }
         }
         $processStatus = $this->service->getStatus($processInstance);
         $this->assertNotNull($processStatus);
         $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel());
         $this->out("process status: " . $processStatus->getLabel());
         $this->assertEquals($processStatus->getUri(), INSTANCE_PROCESSSTATUS_PAUSED);
         $j++;
     }
     $this->out("<strong>Forward transitions again:</strong>", true);
     $currentActivityExecutions = $this->service->getCurrentActivityExecutions($processInstance);
     $currentActivityExecutionsCount = count($currentActivityExecutions);
     $this->assertEquals($currentActivityExecutionsCount, $parallelCount1 + $parallelCount2);
     for ($i = 0; $i < $currentActivityExecutionsCount; $i++) {
         $currentActivityExecution = array_pop($currentActivityExecutions);
         $user = $activityExecutionService->getActivityExecutionUser($currentActivityExecution);
         $activityDefinition = $activityExecutionService->getExecutionOf($currentActivityExecution);
         $this->assertNotNull($user);
         $this->assertNotNull($activityDefinition);
         if (!is_null($user) && !is_null($activityDefinition)) {
             $this->userService->logout();
             $this->out("logout " . $this->currentUser->getOnePropertyValue($loginProperty) . ' "' . $this->currentUser->getUri() . '"', true);
             $login = (string) $user->getUniquePropertyValue($loginProperty);
             $pass = '******';
             if ($this->userService->loginUser($login, $pass)) {
                 $this->currentUser = $this->userService->getCurrentUser();
                 $this->out("new user logged in: " . $this->currentUser->getOnePropertyValue($loginProperty) . ' "' . $this->currentUser->getUri() . '"');
             } else {
                 $this->fail("unable to login user {$login}<br>");
             }
             $iterationNo = $i + 1;
             $this->out("<strong>Iteration {$iterationNo}: " . $activityDefinition->getLabel() . "</strong>", true);
             //execute activity:
             $activityExecution = $this->service->initCurrentActivityExecution($processInstance, $currentActivityExecution, $this->currentUser);
             $this->assertNotNull($activityExecution);
             $activityExecStatus = $activityExecutionService->getStatus($activityExecution);
             $this->assertNotNull($activityExecStatus);
             $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_RESUMED);
             //transition to next activity
             $this->out("current user: "******"' . $this->currentUser->getUri() . '"');
             $this->out("performing transition ...");
             //transition to next activity
             $this->service->performTransition($processInstance, $activityExecution);
             $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel());
             $this->out("process status: " . $this->service->getStatus($processInstance)->getLabel());
             //try undoing the transition:
             if ($i < $currentActivityExecutionsCount - 1) {
                 $this->assertFalse($this->service->undoForwardTransition($processInstance, $activityExecution));
             }
         }
     }
     //try undoing the transition:
     $this->assertTrue($this->service->undoForwardTransition($processInstance, $activityExecution));
     $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
     $this->assertEquals(count($activitieExecs), $parallelCount1 + $parallelCount2);
     $transitionResult = $this->service->performTransition($processInstance, $activityExecution);
     $this->assertEquals(count($transitionResult), 1);
     $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
     $this->assertEquals(count($activitieExecs), 1);
     $activityExecution = reset($activitieExecs);
     $activity = $activityExecutionService->getExecutionOf($activityExecution);
     $this->assertEquals($activity->getUri(), $joinActivity->getUri());
     $this->out("<strong>Executing last activity: " . $activity->getLabel() . "</strong>", true);
     //init execution
     $activityExecution = $this->service->initCurrentActivityExecution($processInstance, $activityExecution, $this->currentUser);
     $this->assertNotNull($activityExecution);
     $activityExecStatus = $activityExecutionService->getStatus($activityExecution);
     $this->assertNotNull($activityExecStatus);
     $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_STARTED);
     //transition to next activity
     $this->out("current user: "******"' . $this->currentUser->getUri() . '"');
     $this->out("performing transition ...");
     //transition to next activity
     $this->service->performTransition($processInstance, $activityExecution);
     $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel());
     $this->out("process status: " . $this->service->getStatus($processInstance)->getLabel());
     $this->assertTrue($this->service->isFinished($processInstance));
     $t_end = microtime(true);
     $duration = $t_end - $t_start;
     $this->out('Elapsed time: ' . $duration . 's', true);
     $this->out('deleting created resources:', true);
     //delete process exec:
     $this->assertTrue($this->service->deleteProcessExecution($processInstance));
     //delete processdef:
     $this->assertTrue($authoringService->deleteProcess($processDefinition));
     $parallelCount2_processVar->delete();
     //delete created users:
     foreach ($createdUsers as $createdUser) {
         $this->out('deleting ' . $createdUser->getLabel() . ' "' . $createdUser->getUri() . '"');
         $this->assertTrue($this->userService->removeUser($createdUser));
     }
     if (!is_null($this->currentUser)) {
         $this->userService->logout();
         $this->userService->removeUser($this->currentUser);
     }
 }
 /**
  * Short description of method connectorNode
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource connector
  * @param  string nodeClass
  * @param  boolean recursive
  * @return array
  */
 public function connectorNode(core_kernel_classes_Resource $connector, $nodeClass = '', $recursive = false)
 {
     $returnValue = array();
     $connectorData = array();
     $connectorService = wfEngine_models_classes_ConnectorService::singleton();
     //		$activityService = wfEngine_models_classes_ActivityService::singleton();
     //type of connector:
     //if not null, get the information on the next activities. Otherwise, return an "empty" connector node, indicating that the node has just been created, i.e. at the same time as an activity
     $connectorType = $connector->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_TYPE), false);
     if (is_null($connectorType)) {
         //create default connector node:
         $returnValue = $this->addNodePrefix($this->defaultConnectorNode($connector), $nodeClass);
         return $returnValue;
     } else {
         //if it is a conditional type
         if ($connectorType->getUri() == INSTANCE_TYPEOFCONNECTORS_CONDITIONAL) {
             //get the rule
             $connectorRule = $connector->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_TRANSITIONRULE), false);
             if (!is_null($connectorRule)) {
                 //continue getting connector data:
                 $connectorData[] = $this->conditionNode($connectorRule);
                 //get the "THEN"
                 $then = $connectorRule->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_TRANSITIONRULES_THEN), false);
                 if (!is_null($then)) {
                     $portData = array('id' => 0, 'label' => 'then', 'multiplicity' => 1);
                     if ($connectorService->isConnector($then)) {
                         $connectorActivityReference = $then->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_ACTIVITYREFERENCE))->getUri();
                         if ($connectorActivityReference == $this->currentActivity->getUri() && !in_array($then->getUri(), $this->addedConnectors)) {
                             if ($recursive) {
                                 $connectorData[] = $this->connectorNode($then, 'then', true, $portData);
                             } else {
                                 $connectorData[] = $this->activityNode($then, 'then', false, $portData);
                             }
                         } else {
                             $connectorData[] = $this->activityNode($then, 'then', true, $portData);
                         }
                     } else {
                         $connectorData[] = $this->activityNode($then, 'then', true, $portData);
                     }
                 }
                 //same for the "ELSE"
                 $else = $connectorRule->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_TRANSITIONRULES_ELSE), false);
                 if (!is_null($else)) {
                     $portData = array('id' => 1, 'label' => 'else', 'multiplicity' => 1);
                     if ($connectorService->isConnector($else)) {
                         $connectorActivityReference = $else->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_ACTIVITYREFERENCE))->getUri();
                         if ($connectorActivityReference == $this->currentActivity->getUri() && !in_array($else->getUri(), $this->addedConnectors)) {
                             if ($recursive) {
                                 $connectorData[] = $this->connectorNode($else, 'else', true, $portData);
                             } else {
                                 $connectorData[] = $this->activityNode($else, 'else', false, $portData);
                             }
                         } else {
                             $connectorData[] = $this->activityNode($else, 'else', true, $portData);
                         }
                     } else {
                         $connectorData[] = $this->activityNode($else, 'else', true, $portData);
                     }
                 }
             }
         } elseif ($connectorType->getUri() == INSTANCE_TYPEOFCONNECTORS_SEQUENCE) {
             $next = $connector->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_STEP_NEXT), false);
             if (!is_null($next)) {
                 $connectorData[] = $this->activityNode($next, 'next', true);
                 //the default portData array will do
             }
         } elseif ($connectorType->getUri() == INSTANCE_TYPEOFCONNECTORS_PARALLEL) {
             $cardinalityService = wfEngine_models_classes_ActivityCardinalityService::singleton();
             $variableService = wfEngine_models_classes_VariableService::singleton();
             $nextActivitiesCollection = $connector->getPropertyValuesCollection(new core_kernel_classes_Property(PROPERTY_STEP_NEXT));
             $portId = 0;
             foreach ($nextActivitiesCollection->getIterator() as $nextActivity) {
                 if ($cardinalityService->isCardinality($nextActivity)) {
                     $activity = $cardinalityService->getDestination($nextActivity);
                     $cardinality = $cardinalityService->getCardinality($nextActivity);
                     $number = $cardinality instanceof core_kernel_classes_Resource ? '^' . $variableService->getCode($cardinality) : $cardinality;
                     $connectorData[] = $this->activityNode($activity, 'next', true, array('id' => $portId, 'multiplicity' => $number, 'label' => $activity->getLabel()), "(count : {$number})");
                     $portId++;
                 }
             }
         } elseif ($connectorType->getUri() == INSTANCE_TYPEOFCONNECTORS_JOIN) {
             $next = $connector->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_STEP_NEXT), false);
             if (!is_null($next)) {
                 $connectorData[] = $this->activityNode($next, 'next', true);
                 //the default portData array will do
             }
         } else {
             throw new Exception("unknown connector type: {$connectorType->getLabel()} for connector {$connector->getUri()}");
         }
         if (empty($portInfo)) {
             $portInfo = array('id' => 0, 'label' => 'next', 'multiplicity' => 1);
         } else {
             if (!isset($portInfo['id'])) {
                 $portInfo['id'] = 0;
             }
             if (!isset($portInfo['id'])) {
                 $portInfo['label'] = 'next';
             }
             if (!isset($portInfo['id'])) {
                 $portInfo['multiplicity'] = 1;
             }
         }
         //add to data
         $returnValue = array('data' => $connectorType->getLabel() . ":" . $connector->getLabel(), 'attributes' => array('id' => tao_helpers_Uri::encode($connector->getUri()), 'class' => 'node-connector'), 'type' => trim(strtolower($connectorType->getLabel())), 'port' => $nodeClass, 'portData' => $portInfo);
         $returnValue = self::addNodePrefix($returnValue, $nodeClass);
         if (!empty($connectorData)) {
             $returnValue['children'] = $connectorData;
         }
         $this->addedConnectors[] = $connector->getUri();
     }
     return (array) $returnValue;
 }
 /**
  * Delete the content of a QTI test
  * @param core_kernel_classes_Resource $test
  * @throws common_exception_Error
  */
 public function deleteContent(core_kernel_classes_Resource $test)
 {
     $content = $test->getOnePropertyValue(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP));
     if (!is_null($content)) {
         $file = new core_kernel_file_File($content);
         try {
             $path = $file->getAbsolutePath();
             if (is_dir($path)) {
                 if (!tao_helpers_File::delTree($path)) {
                     throw new common_exception_Error("Unable to remove test content directory located at '" . $file->getAbsolutePath() . "'.");
                 }
             }
         } catch (common_Exception $e) {
             // Empty file...
         }
         $file->delete();
         $test->removePropertyValue(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP), $file);
     }
 }
Beispiel #29
0
 public function getPropertyFileInfo()
 {
     $data = array('name' => __('(empty)'));
     if ($this->hasRequestParameter('uri') && $this->hasRequestParameter('propertyUri')) {
         $uri = tao_helpers_Uri::decode($this->getRequestParameter('uri'));
         $propertyUri = tao_helpers_Uri::decode($this->getRequestParameter('propertyUri'));
         $instance = new core_kernel_classes_Resource($uri);
         $file = $instance->getOnePropertyValue(new core_kernel_classes_Property($propertyUri));
         if (!is_null($file) && $file instanceof core_kernel_classes_Resource && core_kernel_file_File::isFile($file)) {
             $data = $this->getFileInfo($file->getUri());
         }
     }
     echo json_encode($data);
 }
 /**
  * Returns the implementation of an items test model
  * 
  * @param core_kernel_classes_Resource $test
  * @return taoTests_models_classes_TestModel
  */
 public function getTestModelImplementation(core_kernel_classes_Resource $testModel)
 {
     if (empty($testModel)) {
         throw new common_exception_NoImplementation(__FUNCTION__ . ' called on a NULL testModel');
     }
     $classname = (string) $testModel->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_TESTMODEL_IMPLEMENTATION));
     if (empty($classname)) {
         throw new common_exception_NoImplementation('No implementation found for testmodel ' . $testModel->getUri());
     }
     if (!class_exists($classname) || !in_array('taoTests_models_classes_TestModel', class_implements($classname))) {
         throw new common_exception_Error('Test model service ' . $classname . ' not found, or not compatible for test model ' . $testModel->getUri());
     }
     return new $classname();
 }