public static function ProcessUsePerfRequest($xml)
 {
     $intuitel_elements = IntuitelController::getIntuitelXML($xml);
     $userPerfs = IntuitelXMLSerializer::get_required_element($intuitel_elements, 'UsePerf');
     // OUTPUT Inmediate Response
     $response = IntuitelXMLSerializer::getIntuitelXMLTemplate();
     $adaptor = Intuitel::getAdaptorInstanceForCourse();
     foreach ($userPerfs as $useperf) {
         $uid = IntuitelXMLSerializer::get_required_attribute($useperf, 'uId');
         $mid = IntuitelXMLSerializer::get_required_attribute($useperf, 'mId');
         $loPerfs = $useperf->LoPerf;
         $user_id = new UserId((string) $uid);
         try {
             $user = $adaptor->getNativeUserFromUId($user_id);
         } catch (UnknownUserException $ex) {
             $user = null;
         }
         $useperf_xml = $response->addChild('UsePerf', null, INTUITEL_LMS_NAMESPACE_URI);
         $useperf_xml->addAttribute('uId', $uid);
         $useperf_xml->addAttribute('mId', $mid);
         if ($loPerfs->count() == 0) {
             // If loId-attribute is left blank, the LMS returns all available LO scores
             if ($user == null) {
                 //the user id is not known
                 $LoPerf_xml = $useperf_xml->addChild('LoPerf', null, INTUITEL_LMS_NAMESPACE_URI);
                 $LoPerf_xml->addAttribute('loId', '');
                 $LoPerf_xml->addAttribute('mId', $mid);
                 $score_xml = $LoPerf_xml->addChild('Score', null, INTUITEL_LMS_NAMESPACE_URI);
                 $score_xml->addAttribute('type', 'internal');
                 $score_xml->addAttribute('value', 'learnerUnknown');
             } else {
                 //all data for every LO should be returned, need all loIds of the Intuitel enabled courses in which the user is registered
                 // list of intuitel courses in which the user is student
                 $listCourseLO = Intuitel::getAdaptorInstanceForCourse()->getCoursesEnrolled($user_id);
                 // get the learning objects of those courses
                 $listLO = array();
                 foreach ($listCourseLO as $intuitelCourse) {
                     $adaptor = Intuitel::getAdaptorInstanceForCourseLOId($intuitelCourse->loId);
                     $listLO = array_merge($listLO, $adaptor->findLOAll());
                 }
                 //TODO check: if no objects in courses or not enrolled in any course, what is the message to deliver?
                 if (count($listLO) > 0) {
                     foreach ($listLO as $lo) {
                         $use_data = $adaptor->getUseData($lo, intval($user->id));
                         $loId = $lo->getloId();
                         //TODO this code that creates the xml message is the same to the one in the ELSE, should be unified.
                         $LoPerf_xml = $useperf_xml->addChild('LoPerf', null, INTUITEL_LMS_NAMESPACE_URI);
                         $LoPerf_xml->addAttribute('loId', $loId);
                         if (isset($use_data['completion'])) {
                             $score_xml = $LoPerf_xml->addChild('Score', null, INTUITEL_LMS_NAMESPACE_URI);
                             $score_xml->addAttribute('type', 'completion');
                             $score_xml->addAttribute('value', $use_data['completion']);
                         }
                         if ($use_data['accessed'] === true) {
                             $score_xml = $LoPerf_xml->addChild('Score', null, INTUITEL_LMS_NAMESPACE_URI);
                             $score_xml->addAttribute('type', 'accessed');
                             $score_xml->addAttribute('value', 'true');
                         } else {
                             $score_xml = $LoPerf_xml->addChild('Score', null, INTUITEL_LMS_NAMESPACE_URI);
                             $score_xml->addAttribute('type', 'accessed');
                             $score_xml->addAttribute('value', 'false');
                         }
                         if (isset($use_data['grade'])) {
                             $grade = IntuitelController::get_scaled_grade($use_data['grade'], $use_data['grademin'], $use_data['grademax']);
                             //$response.="<Score type=\"grade\" value=\"".$grade."\"/>";
                             $score_xml = $LoPerf_xml->addChild('Score', null, INTUITEL_LMS_NAMESPACE_URI);
                             $score_xml->addAttribute('type', 'grade');
                             $score_xml->addAttribute('value', $grade);
                         }
                         if (isset($use_data['seenPercentage'])) {
                             //$response.="<Score type=\"seenPercentage\" value=\"".$use_data['seenPercentage']."\"/>";
                             $score_xml = $LoPerf_xml->addChild('Score', null, INTUITEL_LMS_NAMESPACE_URI);
                             $score_xml->addAttribute('type', 'seenPercentage');
                             $score_xml->addAttribute('value', $use_data['seenPercentage']);
                         }
                     }
                 }
             }
         } else {
             //CASE B loids are provided
             foreach ($loPerfs as $loPerf) {
                 $loId = IntuitelXMLSerializer::get_required_attribute($loPerf, 'loId');
                 $loId = new LOId($loId);
                 // get LO from LoId
                 try {
                     $lo = IntuitelAdaptor::createLO($loId);
                 } catch (UnknownLOException $ex) {
                     $lo = null;
                 } catch (UnknownIDException $ex) {
                     $lo = null;
                 }
                 //$response.="<LoPerf loId=\"$loId\">";
                 $LoPerf_xml = $useperf_xml->addChild('LoPerf', null, INTUITEL_LMS_NAMESPACE_URI);
                 $LoPerf_xml->addAttribute('loId', $loId);
                 if ($user != null && $lo != null) {
                     $use_data = $adaptor->getUseData($lo, intval($user->id));
                     if (isset($use_data['completion'])) {
                         //$response.="<Score type=\"completion\" value=\"".$use_data['completion']."\"/>";
                         $score_xml = $LoPerf_xml->addChild('Score', null, INTUITEL_LMS_NAMESPACE_URI);
                         $score_xml->addAttribute('type', 'completion');
                         $score_xml->addAttribute('value', $use_data['completion']);
                     }
                     if ($use_data['accessed']) {
                         //$response.="<Score type=\"accessed\" value=\"true\"/>";
                         $score_xml = $LoPerf_xml->addChild('Score', null, INTUITEL_LMS_NAMESPACE_URI);
                         $score_xml->addAttribute('type', 'accessed');
                         $score_xml->addAttribute('value', 'true');
                     } else {
                         //$response.="<Score type=\"accessed\" value=\"false\"/>";
                         $score_xml = $LoPerf_xml->addChild('Score', null, INTUITEL_LMS_NAMESPACE_URI);
                         $score_xml->addAttribute('type', 'accessed');
                         $score_xml->addAttribute('value', 'false');
                     }
                     if (isset($use_data['grade'])) {
                         $grade = IntuitelController::get_scaled_grade($use_data['grade'], $use_data['grademin'], $use_data['grademax']);
                         //$response.="<Score type=\"grade\" value=\"".$grade."\"/>";
                         $score_xml = $LoPerf_xml->addChild('Score', null, INTUITEL_LMS_NAMESPACE_URI);
                         $score_xml->addAttribute('type', 'grade');
                         $score_xml->addAttribute('value', $grade);
                     }
                     if (isset($use_data['seenPercentage'])) {
                         //$response.="<Score type=\"seenPercentage\" value=\"".$use_data['seenPercentage']."\"/>";
                         $score_xml = $LoPerf_xml->addChild('Score', null, INTUITEL_LMS_NAMESPACE_URI);
                         $score_xml->addAttribute('type', 'seenPercentage');
                         $score_xml->addAttribute('value', $use_data['seenPercentage']);
                     }
                 }
                 if ($user == null) {
                     // 								$response.="<Score type=\"internal\" value=\"learnerUnknown\" />";
                     $score_xml = $LoPerf_xml->addChild('Score', null, INTUITEL_LMS_NAMESPACE_URI);
                     $score_xml->addAttribute('type', 'internal');
                     $score_xml->addAttribute('value', 'learnerUnknown');
                 }
                 if ($lo == null) {
                     // 								$response.="<Score type=\"internal\" value=\"loIdUnknown\" />";
                     $score_xml = $LoPerf_xml->addChild('Score', null, INTUITEL_LMS_NAMESPACE_URI);
                     $score_xml->addAttribute('type', 'internal');
                     $score_xml->addAttribute('value', 'loIdUnknown');
                 }
                 // 							$response.="</LoPerf>";
             }
             // end foreach loPerf
         }
         // end else CASE B
         // 				$response.="</UsePerf>";
     }
     //end foreach user
     // 			$response.= "</INTUITEL>";
     return IntuitelXMLSerializer::formatXmlString($response->asXML());
 }