/** * Rounds the specified 3d vector integer values. * Can handle/return a string vector, or an array vector. * (Output type matches input type). * @param mixed $pos Either a string vector or an array vector * @return mixed */ function sloodle_round_vector($pos) { // We will work with an array, but allow for conversion to/from string $arrayvec = $pos; $returnstring = FALSE; // Is it a string? if (is_string($pos)) { $arrayvec = sloodle_vector_to_array($pos); $returnstring = TRUE; } else { if (!is_array($pos)) { return $pos; } } // Construct an output array $output = array(); foreach ($arrayvec as $key => $val) { $output[$key] = round($val, 0); } // If we need to convert it back to a string, then do so if ($returnstring) { return sloodle_array_to_vector($output); } return $output; }
/** * Finds the user identified by LoginZone allocation, and loads it into the given user object. * Note: does not delete the allocation. * @param string $pos Absolute position vector (relative to sim, not to LoginZone) * @param SloodleUser &$user The user object which will be manipulated (by reference) * @return bool True if successful, or false otherwise */ function load_user_by_loginzone($pos, &$user) { // Calculate the relative position of the allocation $abspos = sloodle_vector_to_array($pos); $loginzonepos = sloodle_vector_to_array($this->sloodle_course_data->loginzonepos); $relpos = array('x' => $abspos['x'] - $loginzonepos['x'], 'y' => $abspos['y'] - $loginzonepos['y'], 'z' => $abspos['z'] - $loginzonepos['z']); $relpos = sloodle_array_to_vector($relpos); // Attempt to find a matching LoginZone position in the database $rec = get_record('sloodle_loginzone_allocation', 'course', $this->get_course_id(), 'position', $relpos); if (!$rec) { return false; } // Load the user return $user->load_user($rec->userid); }