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 sloodleprimdrop
  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.             $num_prims $sloodle_submission->num_prims;
  101.             if ($num_prims == 0$num_prims '?';
  102.             echo ' ('.get_string('numprims''sloodle'$num_prims).')</td></tr>';
  103.         }
  104.         echo '</table>';
  105.         print_simple_box_end();
  106.     }
  107.  
  108.     /**
  109.     * Update the submission with the provided data.
  110.     * @param int $userid Integer ID of the user making the submission
  111.     * @param assignment_sloodleobject_submission $data A structure containing data about the Sloodle assignment submission
  112.     * @return bool True if successful, or false otherwise.
  113.     */
  114.     function update_submission($userid$data)
  115.     {
  116.         $submission $this->get_submission($useridtrue);
  117.  
  118.         $update new object();
  119.         $update->id           $submission->id;
  120.         $update->data1        "{$data->obj_name}|{$data->num_prims}";
  121.         $update->data2        "{$data->primdrop_name}|{$data->primdrop_uuid}|{$data->primdrop_region}|{$data->primdrop_pos}";
  122.         $update->timemodified time();
  123.  
  124.         return update_record('assignment_submissions'$update);
  125.     }
  126.  
  127.  
  128.     function print_student_answer($userid$return=true){
  129.         global $CFG;
  130.         $text '';
  131.         
  132.         if (!($submission $this->get_submission($userid))) {
  133.             $text '';
  134.         else {
  135.             // Output the Submission data
  136.             $sloodle_submission new assignment_sloodleobject_submission();
  137.             $sloodle_submission->load_submission($submission);
  138.             
  139.             //$text = '<b>'.shorten_text(trim(strip_tags($sloodle_submission->obj_name)), 20).'</b><br>';
  140.             
  141.             $text '<div class="files">'.
  142.                   '<img src="'.$CFG->pixpath.'/f/html.gif" class="icon" alt="html" />'.
  143.                   link_to_popup_window ('/mod/assignment/type/sloodleobject/file.php?id='.$this->cm->id.'&amp;userid='.
  144.                   $submission->userid'file'.$useridshorten_text(trim(strip_tags($sloodle_submission->obj_name))20)450580,
  145.                   get_string('submission''assignment')'none'true).
  146.                   '</div>';
  147.         }
  148.         
  149.         if ($returnreturn $text;
  150.         echo $text;
  151.     }
  152.     
  153.     
  154.     function print_user_files($userid$return=false{
  155.         global $CFG;
  156.         if (!$submission $this->get_submission($userid)) {
  157.             return '';
  158.         }
  159.         
  160.         // Construct a Sloodle submission object
  161.         $sloodle_submission new assignment_sloodleobject_submission();
  162.         $sloodle_submission->load_submission($submission);
  163.  
  164.         // Display the number of prims
  165.         $num_prims $sloodle_submission->num_prims;
  166.         if ($num_prims == 0$num_prims '?';
  167.         print_simple_box_start('center'''''0'generalbox''wordcount');
  168.         echo ' ('.get_string('numprims''sloodle'$num_prims).')';
  169.         print_simple_box_end();
  170.         
  171.         // Display the text summary of this submission
  172.         print_simple_box($sloodle_submission->text_summary()'center''100%');
  173.     }
  174.     
  175.  
  176.     function preprocess_submission(&$submission{
  177.         
  178.     }
  179.  
  180.     function setup_elements(&$mform{
  181.         global $CFG$COURSE;
  182.  
  183.         $ynoptions array=> get_string('no')=> get_string('yes'));
  184.  
  185.         $mform->addElement('select''resubmit'get_string("allowresubmit""assignment")$ynoptions);
  186.         $mform->setHelpButton('resubmit'array('resubmit'get_string('allowresubmit''assignment')'assignment'));
  187.         $mform->setDefault('resubmit'0);
  188.  
  189.         $mform->addElement('select''emailteachers'get_string("emailteachers""assignment")$ynoptions);
  190.         $mform->setHelpButton('emailteachers'array('emailteachers'get_string('emailteachers''assignment')'assignment'));
  191.         $mform->setDefault('emailteachers'0);
  192.     }
  193.  
  194. }
  195.  
  196.  
  197. /**
  198. * Defines a submission for a Sloodle assignment.
  199. @package sloodle
  200. */
  201. {
  202.     /**
  203.     * Indicates whether or not a submission is loaded
  204.     * @var bool 
  205.     * @access public
  206.     */
  207.     var $is_loaded = false;
  208.  
  209.     /**
  210.     * Name of the object which has been submitted.
  211.     * @var string 
  212.     * @access public
  213.     */
  214.     var $obj_name = '';
  215.     
  216.     /**
  217.     * Number of prims in the object which has been submitted
  218.     * @var int 
  219.     * @access public
  220.     */
  221.     var $num_prims = 0;
  222.     
  223.     /**
  224.     * Name of the PrimDrop object into which this object was submitted.
  225.     * @var string 
  226.     * @access public
  227.     */
  228.     var $primdrop_name = '';
  229.     
  230.     /**
  231.     * UUID of the PrimDrop object into which this object was submitted.
  232.     * @var string 
  233.     * @access public
  234.     */
  235.     var $primdrop_uuid = '';
  236.     
  237.     /**
  238.     * Name of the region where this object was submitted
  239.     * @var string 
  240.     * @access public
  241.     */
  242.     var $primdrop_region = '';
  243.     
  244.     /**
  245.     * Position where this object was submitted (as a vector, "<x,y,z>")
  246.     * @var string 
  247.     * @access public
  248.     */
  249.     var $primdrop_pos = '';
  250.     
  251.     
  252.     /**
  253.     * Parses the data from a Submission database record object.
  254.     * @var object $submission The submission database record object.
  255.     */
  256.     function load_submission($submission)
  257.     {
  258.         // Make sure the submission is valid
  259.         $this->is_loaded = false;
  260.         if ($submission == false || $submission == nullreturn;
  261.     
  262.         // Parse the data lines
  263.         $object_data explode('|'$submission->data1);
  264.         $primdrop_data explode('|'$submission->data2);
  265.         
  266.         // Make sure there's enough data in both
  267.         if (count($object_data|| count($primdrop_data4return;
  268.         
  269.         // Extract the data items
  270.         $this->obj_name = $object_data[0];
  271.         $this->num_prims = (int)$object_data[1];
  272.         $this->primdrop_name = $primdrop_data[0];
  273.         $this->primdrop_uuid = $primdrop_data[1];
  274.         $this->primdrop_region = $primdrop_data[2];
  275.         $this->primdrop_pos = $primdrop_data[3];
  276.         
  277.         $this->is_loaded = true;
  278.     }
  279.     
  280.     /**
  281.     * Sets the position as 3 components.
  282.     * @param float x The X coordinate
  283.     * @param float y The Y coordinate
  284.     * @param float z The Z coordinate
  285.     */
  286.     function set_pos($x$y$z)
  287.     {
  288.         $this->primdrop_pos = "<$x,$y,$z>";
  289.     }
  290.     
  291.     /**
  292.     * Gets the X coordinate of the position
  293.     * @return float The X coordinate of the position
  294.     */
  295.     function get_x()
  296.     {
  297.         $arr sloodle_vector_to_array($this->primdrop_pos);
  298.         if (!$arrreturn 0.0;
  299.         return (float)$arr['x'];
  300.     }
  301.     
  302.     /**
  303.     * Gets the Y coordinate of the position
  304.     * @return float The Y coordinate of the position
  305.     */
  306.     function get_y()
  307.     {
  308.         $arr sloodle_vector_to_array($this->primdrop_pos);
  309.         if (!$arrreturn 0.0;
  310.         return (float)$arr['y'];
  311.     }
  312.     
  313.     /**
  314.     * Gets the Z coordinate of the position
  315.     * @return float The Z coordinate of the position
  316.     */
  317.     function get_z()
  318.     {
  319.         $arr sloodle_vector_to_array($this->primdrop_pos);
  320.         if (!$arrreturn 0.0;
  321.         return (float)$arr['z'];
  322.     }
  323.     
  324.     /**
  325.     * Construct a text summary of this submission.
  326.     * @param bool $return If TRUE (default) then the text will be submitted instead of printed.
  327.     * @return string If parameter $return was TRUE, then it returns the string. Otherwise, an empty string.
  328.     */
  329.     function text_summary($return true)
  330.     {
  331.         // Make sure something is loaded
  332.         if (!$this->is_loaded{
  333.             $text get_string('emptysubmission''assignment');
  334.         else {
  335.             $text "Object name: <b>{$this->obj_name}</b><br><br>";
  336.             $text .= "Submitted to: {$this->primdrop_name}<br>";
  337.             $text .= " <i>({$this->primdrop_uuid})</i><br><br>";
  338.             
  339.             $arr = sloodle_vector_to_array($this->primdrop_pos);
  340.             if (!$arr$arr array('x'=>0'y'=>0'z'=>0);
  341.             else {
  342.                 $arr['x'] = round($arr['x']);
  343.                 $arr['y'] = round($arr['y']);
  344.                 $arr['z'] = round($arr['z']);
  345.             }
  346.             
  347.             $loc = "secondlife://{$this->primdrop_region}/{$arr['x']}/{$arr['y']}/{$arr['z']}";
  348.             $text .= "<b><a href=\"$loc\">$loc</a></b><br>";
  349.         }
  350.         
  351.         if ($return) return $text;
  352.         echo $text;
  353.         return '';
  354.     }
  355. }
  356.  
  357.  
  358.  

Documentation generated on Mon, 07 Jul 2008 12:32:12 +0100 by phpDocumentor 1.4.0