Source for file assignment.class.php

Documentation is available at assignment.class.php

  1. <?php
  2.     // This file is part of the Sloodle project (www.sloodle.org)
  3.     
  4.     /**
  5.     * This file defines the "Sloodle Object" assignment sub-type.
  6.     * It allows students to submit 3d objects in Second Life as Moodle assignments.
  7.     *
  8.     * @package sloodle
  9.     * @copyright Copyright (c) 2008 Sloodle (various contributors)
  10.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  11.     *
  12.     * @contributor (various Moodle guys!)
  13.     * @contributor Peter R. Bloomfield
  14.     */
  15.  
  16. /** Attempt to include the Sloodle configuration. */
  17. require_once($CFG->dirroot.'/mod/sloodle/sl_config.php');
  18. /** Include the general Sloodle functions. */
  19. require_once($CFG->dirroot.'/mod/sloodle/lib/general.php');
  20.  
  21. /** Include the base assignment class, if necessary. */
  22. require_once($CFG->dirroot.'/mod/assignment/lib.php');
  23.  
  24. /**
  25.  * Extend the base assignment class for assignments where you submit an SL object in-world.
  26.  * This has been modified from the "assignment_online" type.
  27.  * @package sloodle
  28.  */
  29. class assignment_sloodleobject extends assignment_base {
  30.  
  31.     function assignment_sloodleobject($cmid='staticonly'$assignment=NULL$cm=NULL$course=NULL{
  32.         parent::assignment_base($cmid$assignment$cm$course);
  33.         $this->type 'sloodleobject';
  34.     }
  35.  
  36.     function view({
  37.         
  38.         // Bring in the global user data
  39.         global $USER;
  40.  
  41.         // Check that this user can view assignments
  42.         $context get_context_instance(CONTEXT_MODULE$this->cm->id);
  43.         require_capability('mod/assignment:view'$context);
  44.         
  45.         // Fetch the submission data
  46.         $submission $this->get_submission();
  47.         $sloodle_submission new assignment_sloodleobject_submission();
  48.         $sloodle_submission->load_submission($submission);
  49.  
  50.         $this->view_header();
  51.         $this->view_intro();
  52.         $this->view_dates();
  53.         
  54.         // Display a texture summary of the submission
  55.         print_simple_box_start('center''70%'''0'generalbox''online');
  56.         $sloodle_submission->text_summary(false);
  57.         print_simple_box_end();
  58.         
  59.         
  60.         $this->view_feedback();
  61.         $this->view_footer();
  62.     }
  63.  
  64.     /*
  65.      * Display the assignment dates
  66.      */
  67.     function view_dates({
  68.         // Bring in the global user and configuration data
  69.         global $USER$CFG;
  70.  
  71.         // Make sure the time available and time due dates are set
  72.         if (!$this->assignment->timeavailable && !$this->assignment->timedue{
  73.             return;
  74.         }
  75.         // Start a display box
  76.         print_simple_box_start('center'''''0'generalbox''dates');
  77.         echo '<table>';
  78.         // Display the time the assignment is available from
  79.         if ($this->assignment->timeavailable{
  80.             echo '<tr><td class="c0">'.get_string('availabledate','assignment').':</td>';
  81.             echo '    <td class="c1">'.userdate($this->assignment->timeavailable).'</td></tr>';
  82.         }
  83.         // Display the time the assignment is due by
  84.         if ($this->assignment->timedue{
  85.             echo '<tr><td class="c0">'.get_string('duedate','assignment').':</td>';
  86.             echo '    <td class="c1">'.userdate($this->assignment->timedue).'</td></tr>';
  87.         }
  88.         // Is there a submission by this user?
  89.         $submission $this->get_submission($USER->id);
  90.         if ($submission{
  91.             // Convert the submission to a Sloodle assignment object
  92.             $sloodle_submission new assignment_sloodleobject_submission();
  93.             $sloodle_submission->load_submission($submission);
  94.         
  95.             // Display the date it was last updated
  96.             echo '<tr><td class="c0">'.get_string('lastedited').':</td>';
  97.             echo '    <td class="c1">'.userdate($submission->timemodified);
  98.             
  99.             // Display the number of prims in the submission
  100.             echo ' ('.get_string('numprims''sloodle'$sloodle_submission->num_prims).')</td></tr>';
  101.         }
  102.         echo '</table>';
  103.         print_simple_box_end();
  104.     }
  105.  
  106.     /**
  107.     * Update the submission with the provided data.
  108.     * @param int $userid Integer ID of the user making the submission
  109.     * @param assignment_sloodleobject_submission $data A structure containing data about the Sloodle assignment submission
  110.     * @return bool True if successful, or false otherwise.
  111.     */
  112.     function update_submission($userid$data)
  113.     {
  114.         $submission $this->get_submission($useridtrue);
  115.  
  116.         $update new object();
  117.         $update->id           $submission->id;
  118.         $update->data1        "{$data->obj_name}|{$data->num_prims}";
  119.         $update->data2        "{$data->primdrop_name}|{$data->primdrop_uuid}|{$data->primdrop_region}|{$data->primdrop_pos}";
  120.         $update->timemodified time();
  121.  
  122.         return update_record('assignment_submissions'$update);
  123.     }
  124.  
  125.  
  126.     function print_student_answer($userid$return=true){
  127.         global $CFG;
  128.         $text '';
  129.         
  130.         if (!($submission $this->get_submission($userid))) {
  131.             $text '';
  132.         else {
  133.             // Output the Submission data
  134.             $sloodle_submission new assignment_sloodleobject_submission();
  135.             $sloodle_submission->load_submission($submission);
  136.             
  137.             //$text = '<b>'.shorten_text(trim(strip_tags($sloodle_submission->obj_name)), 20).'</b><br>';
  138.             
  139.             $text '<div class="files">'.
  140.                   '<img src="'.$CFG->pixpath.'/f/html.gif" class="icon" alt="html" />'.
  141.                   link_to_popup_window ('/mod/assignment/type/sloodleobject/file.php?id='.$this->cm->id.'&amp;userid='.
  142.                   $submission->userid'file'.$useridshorten_text(trim(strip_tags($sloodle_submission->obj_name))20)450580,
  143.                   get_string('submission''assignment')'none'true).
  144.                   '</div>';
  145.         }
  146.         
  147.         if ($returnreturn $text;
  148.         echo $text;
  149.     }
  150.     
  151.     
  152.     function print_user_files($userid$return=false{
  153.         global $CFG;
  154.         if (!$submission $this->get_submission($userid)) {
  155.             return '';
  156.         }
  157.         
  158.         // Construct a Sloodle submission object
  159.         $sloodle_submission new assignment_sloodleobject_submission();
  160.         $sloodle_submission->load_submission($submission);
  161.  
  162.         // Display the number of prims
  163.         print_simple_box_start('center'''''0'generalbox''wordcount');
  164.         echo ' ('.get_string('numprims''sloodle'$sloodle_submission->num_prims).')';
  165.         print_simple_box_end();
  166.         
  167.         // Display the text summary of this submission
  168.         print_simple_box($sloodle_submission->text_summary()'center''100%');
  169.     }
  170.     
  171.  
  172.     function preprocess_submission(&$submission{
  173.         
  174.     }
  175.  
  176.     function setup_elements(&$mform{
  177.         global $CFG$COURSE;
  178.  
  179.         $ynoptions array=> get_string('no')=> get_string('yes'));
  180.  
  181.         $mform->addElement('select''resubmit'get_string("allowresubmit""assignment")$ynoptions);
  182.         $mform->setHelpButton('resubmit'array('resubmit'get_string('allowresubmit''assignment')'assignment'));
  183.         $mform->setDefault('resubmit'0);
  184.  
  185.         $mform->addElement('select''emailteachers'get_string("emailteachers""assignment")$ynoptions);
  186.         $mform->setHelpButton('emailteachers'array('emailteachers'get_string('emailteachers''assignment')'assignment'));
  187.         $mform->setDefault('emailteachers'0);
  188.     }
  189.  
  190. }
  191.  
  192.  
  193. /**
  194. * Defines a submission for a Sloodle assignment.
  195. @package sloodle
  196. */
  197. {
  198.     /**
  199.     * Indicates whether or not a submission is loaded
  200.     * @var bool 
  201.     * @access public
  202.     */
  203.     var $is_loaded = false;
  204.  
  205.     /**
  206.     * Name of the object which has been submitted.
  207.     * @var string 
  208.     * @access public
  209.     */
  210.     var $obj_name = '';
  211.     
  212.     /**
  213.     * Number of prims in the object which has been submitted
  214.     * @var int 
  215.     * @access public
  216.     */
  217.     var $num_prims = 0;
  218.     
  219.     /**
  220.     * Name of the PrimDrop object into which this object was submitted.
  221.     * @var string 
  222.     * @access public
  223.     */
  224.     var $primdrop_name = '';
  225.     
  226.     /**
  227.     * UUID of the PrimDrop object into which this object was submitted.
  228.     * @var string 
  229.     * @access public
  230.     */
  231.     var $primdrop_uuid = '';
  232.     
  233.     /**
  234.     * Name of the region where this object was submitted
  235.     * @var string 
  236.     * @access public
  237.     */
  238.     var $primdrop_region = '';
  239.     
  240.     /**
  241.     * Position where this object was submitted (as a vector, "<x,y,z>")
  242.     * @var string 
  243.     * @access public
  244.     */
  245.     var $primdrop_pos = '';
  246.     
  247.     
  248.     /**
  249.     * Parses the data from a Submission database record object.
  250.     * @var object $submission The submission database record object.
  251.     */
  252.     function load_submission($submission)
  253.     {
  254.         // Make sure the submission is valid
  255.         $this->is_loaded = false;
  256.         if ($submission == false || $submission == nullreturn;
  257.     
  258.         // Parse the data lines
  259.         $object_data explode('|'$submission->data1);
  260.         $primdrop_data explode('|'$submission->data2);
  261.         
  262.         // Make sure there's enough data in both
  263.         if (count($object_data|| count($primdrop_data4return;
  264.         
  265.         // Extract the data items
  266.         $this->obj_name = $object_data[0];
  267.         $this->num_prims = (int)$object_data[1];
  268.         $this->primdrop_name = $primdrop_data[0];
  269.         $this->primdrop_uuid = $primdrop_data[1];
  270.         $this->primdrop_region = $primdrop_data[2];
  271.         $this->primdrop_pos = $primdrop_data[3];
  272.         
  273.         $this->is_loaded = true;
  274.     }
  275.     
  276.     /**
  277.     * Sets the position as 3 components.
  278.     * @param float x The X coordinate
  279.     * @param float y The Y coordinate
  280.     * @param float z The Z coordinate
  281.     */
  282.     function set_pos($x$y$z)
  283.     {
  284.         $this->primdrop_pos = "<$x,$y,$z>";
  285.     }
  286.     
  287.     /**
  288.     * Gets the X coordinate of the position
  289.     * @return float The X coordinate of the position
  290.     */
  291.     function get_x()
  292.     {
  293.         $arr sloodle_vector_to_array($this->primdrop_pos);
  294.         if (!$arrreturn 0.0;
  295.         return (float)$arr['x'];
  296.     }
  297.     
  298.     /**
  299.     * Gets the Y coordinate of the position
  300.     * @return float The Y coordinate of the position
  301.     */
  302.     function get_y()
  303.     {
  304.         $arr sloodle_vector_to_array($this->primdrop_pos);
  305.         if (!$arrreturn 0.0;
  306.         return (float)$arr['y'];
  307.     }
  308.     
  309.     /**
  310.     * Gets the Z coordinate of the position
  311.     * @return float The Z coordinate of the position
  312.     */
  313.     function get_z()
  314.     {
  315.         $arr sloodle_vector_to_array($this->primdrop_pos);
  316.         if (!$arrreturn 0.0;
  317.         return (float)$arr['z'];
  318.     }
  319.     
  320.     /**
  321.     * Construct a text summary of this submission.
  322.     * @param bool $return If TRUE (default) then the text will be submitted instead of printed.
  323.     * @return string If parameter $return was TRUE, then it returns the string. Otherwise, an empty string.
  324.     */
  325.     function text_summary($return true)
  326.     {
  327.         // Make sure something is loaded
  328.         if (!$this->is_loaded{
  329.             $text get_string('emptysubmission''assignment');
  330.         else {
  331.             $text "Object name: <b>{$this->obj_name}</b><br><br>";
  332.             $text .= "Submitted to: {$this->primdrop_name}<br>";
  333.             $text .= " <i>({$this->primdrop_uuid})</i><br><br>";
  334.             
  335.             $arr = sloodle_vector_to_array($this->primdrop_pos);
  336.             if (!$arr$arr array('x'=>0'y'=>0'z'=>0);
  337.             
  338.             $loc "secondlife://{$this->primdrop_region}/{$arr['x']}/{$arr['y']}/{$arr['z']}";
  339.             $text .= "<b><a href=\"$loc\">$loc</a></b><br>";
  340.         }
  341.         
  342.         if ($return) return $text;
  343.         echo $text;
  344.         return '';
  345.     }
  346. }
  347.  
  348.  
  349.  

Documentation generated on Mon, 16 Jun 2008 15:56:06 +0100 by phpDocumentor 1.4.0