Ejemplo n.º 1
0
 function getINTUITELInteractionsPre2_7(array $native_user_ids = null, CourseLO $course = null, $from = null, $to = null, $filter_offline_users = true)
 {
     global $DB;
     $native_courseids = array();
     $native_userids = array();
     $interactionEvents = array();
     if ($native_user_ids != null) {
         $native_userids = $native_user_ids;
     }
     $adaptor = Intuitel::getAdaptorInstance();
     if ($course == null) {
         // retrieve all intuitel enabled courses
         $courses = $adaptor->getIntuitelEnabledCourses();
     } else {
         $courses = array($course);
     }
     // Collect course ids and user ids.
     foreach ($courses as $course) {
         $native_courseids[] = Intuitel::getIDFactory()->getIdfromLoId($course->getloId());
         if ($native_user_ids == null) {
             //get all users enrolled in the different intuitel enabled courses
             $native_userids = array_merge($native_userids, $adaptor->getUsersEnrolled($course));
         }
     }
     if ($filter_offline_users) {
         //filter out those users who are not currently online
         $native_activeuserids = block_intuitel_get_online_users($native_userids);
     } else {
         $native_activeuserids = $native_userids;
     }
     if ($from === null) {
         $fromsql = 0;
     } else {
         $fromsql = $from;
     }
     // Retrieve from database the events using $fromsql.
     if (!empty($native_activeuserids)) {
         list($insql, $inparams) = $DB->get_in_or_equal($native_activeuserids);
         list($insqlCourses, $inparamsCourse) = $DB->get_in_or_equal($native_courseids);
         if ($to == null) {
             //not upper limit of time
             $params = array_merge($inparamsCourse, array('from' => $fromsql), $inparams);
             $sql = "SELECT * FROM {log} WHERE course {$insqlCourses} AND time >= ?  AND userid {$insql} AND module = 'INTUITEL' ORDER BY time ASC";
         } else {
             $params = array_merge($inparamsCourse, array('from' => $fromsql, 'to' => $to), $inparams);
             $sql = "SELECT * FROM {log} WHERE course {$insqlCourses} AND time >= ? and time <= ? AND userid {$insql} AND module = 'INTUITEL' ORDER BY time ASC";
         }
         $events = $DB->get_records_sql($sql, $params);
         foreach ($events as $event) {
             $userId = intuitel::getIDFactory()->getUserId($event->userid);
             $interactionEvents[$event->id] = new InteractionEvent($userId, $event->id, $event->action . ':' . $event->info, $event->time);
         }
     }
     return $interactionEvents;
 }
 public static function processUseEnvRequest($xml)
 {
     $intuitel_elements = IntuitelController::getIntuitelXML($xml);
     $uses = IntuitelXMLSerializer::get_required_element($intuitel_elements, 'UseEnv');
     // OUTPUT
     $response = IntuitelXMLSerializer::getIntuitelXMLTemplate();
     $adaptor = Intuitel::getAdaptorInstanceForCourse();
     foreach ($uses as $useenv) {
         $uid = IntuitelXMLSerializer::get_required_attribute($useenv, 'uId');
         $mid = IntuitelXMLSerializer::get_required_attribute($useenv, 'mId');
         $user_id = new UserId((string) $uid);
         try {
             $user = $adaptor->getNativeUserFromUId($user_id);
         } catch (UnknownUserException $ex) {
             $user = null;
         }
         if ($user == null) {
             //the user id is not known
             // 				$response.="<UseEnv uId=\"$uid\" mId=\"$mid\" retVal=\"ERROR\">";
             $useenv_xml = $response->addChild('UseEnv', null, INTUITEL_LMS_NAMESPACE_URI);
             $useenv_xml->addAttribute('uId', $uid);
             $useenv_xml->addAttribute('mId', $mid);
             $useenv_xml->addAttribute('retVal', 'ERROR');
         } else {
             //check if the learner is logged in
             $active_user = array();
             $active_user = block_intuitel_get_online_users(array($user->id));
             if (!empty($active_user)) {
                 // 					$response.="<UseEnv uId=\"$uid\" mId=\"$mid\" retVal=\"OK\">";
                 $useenv_xml = $response->addChild('UseEnv', null, INTUITEL_LMS_NAMESPACE_URI);
                 $useenv_xml->addAttribute('uId', $uid);
                 $useenv_xml->addAttribute('mId', $mid);
                 $useenv_xml->addAttribute('retVal', 'OK');
                 //get use environment data
                 $useenv_data = $adaptor->getUseEnvData($user);
                 foreach ($useenv_data as $env) {
                     // 					   $response.="<Data name=\"$env->type\" value=\"".$env->value."\"/>";
                     $data_xml = $useenv_xml->addChild('Data', null, INTUITEL_LMS_NAMESPACE_URI);
                     $data_xml->addAttribute('name', $env->type);
                     $data_xml->addAttribute('value', $env->value);
                 }
             } else {
                 //user is known but not online
                 // 					$response.="<UseEnv uId=\"$uid\" mId=\"$mid\" retVal=\"PAUSE\">";
                 $useenv_xml = $response->addChild('UseEnv', null, INTUITEL_LMS_NAMESPACE_URI);
                 $useenv_xml->addAttribute('uId', $uid);
                 $useenv_xml->addAttribute('mId', $mid);
                 $useenv_xml->addAttribute('retVal', 'PAUSE');
             }
         }
         // 			$response.="</UseEnv>";
     }
     //end foreach user
     // 		$response.= "</INTUITEL>";
     return IntuitelXMLSerializer::formatXmlString($response->asXML());
 }