function list_activities($vplid)
 {
     global $DB;
     $list = array('' => '');
     $cn = $this->vpl->get_course()->shortname;
     //Low privilegies
     $courses = get_user_capability_course(VPL_VIEW_CAPABILITY, null, true, 'shortname');
     //Reorder courses by name similar to current
     usort($courses, function ($a, $b) use($cn) {
         $na = $a->shortname;
         $nb = $b->shortname;
         $da = levenshtein($na, $cn);
         $db = levenshtein($nb, $cn);
         if ($da != $db) {
             return $da < $db ? -1 : 1;
         }
         if ($na == $cn) {
             return -1;
         }
         if ($nb == $cn) {
             return 1;
         }
         if ($na != $nb) {
             return $na < $nb ? -1 : 1;
         }
         return 0;
     });
     foreach ($courses as $course) {
         $vpls = $DB->get_records(VPL, array('course' => $course->id));
         foreach ($vpls as $vplinstace) {
             if ($vplinstace->id == $vplid) {
                 continue;
             }
             $othervpl = new mod_vpl(false, $vplinstace->id);
             if (!$othervpl->get_course_module()) {
                 continue;
             }
             if ($othervpl->has_capability(VPL_SIMILARITY_CAPABILITY)) {
                 $list[$othervpl->get_course_module()->id] = $othervpl->get_course()->shortname . ' ' . $othervpl->get_printable_name();
             }
         }
         if (count($list) > 1000) {
             break;
             //Stop loading instances
         }
     }
     $list[''] = get_string('select');
     return $list;
 }
 function definition()
 {
     $mform =& $this->_form;
     $id = $this->vpl->get_course_module()->id;
     $mform->addElement('hidden', 'id', $id);
     $mform->setType('id', PARAM_INT);
     $mform->addElement('header', 'header_execution_options', get_string('executionoptions', VPL));
     $strbasedon = get_string('basedon', VPL);
     $basedonlist = array();
     $basedonlist[0] = '';
     $courseid = $this->vpl->get_course()->id;
     $listcm = get_coursemodules_in_course(VPL, $courseid);
     $instance = $this->vpl->get_instance();
     $vplid = $instance->id;
     foreach ($listcm as $aux) {
         if ($aux->instance != $vplid) {
             $vpl = new mod_vpl($aux->id);
             $basedonlist[$aux->instance] = $vpl->get_printable_name();
         }
     }
     asort($basedonlist);
     $basedonlist[0] = get_string('select');
     $mform->addElement('select', 'basedon', $strbasedon, $basedonlist);
     $mform->setDefault('basedon', $instance->basedon);
     $mform->addElement('selectyesno', 'run', get_string('run', VPL));
     $mform->setDefault('run', 1);
     $mform->addElement('selectyesno', 'debug', get_string('debug', VPL));
     $mform->setDefault('debug', $instance->debug);
     $mform->addElement('selectyesno', 'evaluate', get_string('evaluate', VPL));
     $mform->setDefault('evaluate', 1);
     $mform->addElement('selectyesno', 'evaluateonsubmission', get_string('evaluateonsubmission', VPL));
     $mform->setDefault('evaluateonsubmission', 1);
     $mform->disabledIf('evaluateonsubmission', 'evaluate', 'eq', 0);
     $mform->addElement('selectyesno', 'automaticgrading', get_string('automaticgrading', VPL));
     $mform->setDefault('automaticgrading', 1);
     $mform->disabledIf('automaticgrading', 'evaluate', 'eq', 0);
     $mform->addElement('submit', 'saveoptions', get_string('saveoptions', VPL));
 }
Example #3
0
/**
 * Run periodically to check for vpl visibility update
 *
 * @uses $CFG
 * @return boolean
 **/
function vpl_cron()
{
    global $DB;
    $rebuilds = array();
    $now = time();
    $sql = 'SELECT id, startdate, duedate, course, name
    FROM {vpl}
    WHERE startdate > ?
      and startdate <= ?
      and (duedate > ? or duedate = 0)';
    $parms = array($now - 2 * 3600, $now, $now);
    $vpls = $DB->get_records_sql($sql, $parms);
    foreach ($vpls as $instance) {
        if (!instance_is_visible(VPL, $instance)) {
            $vpl = new mod_vpl(null, $instance->id);
            echo 'Setting visible "' . s($vpl->get_printable_name()) . '"';
            $cm = $vpl->get_course_module();
            $rebuilds[$cm->id] = $cm;
        }
    }
    foreach ($rebuilds as $cmid => $cm) {
        set_coursemodule_visible($cm->id, true);
        rebuild_course_cache($cm->course);
    }
    return true;
}
        $grader = FALSE;
        if ($submissionid && $vpl->has_capability(VPL_GRADE_CAPABILITY)) {
            $subinstance = $DB->get_record('vpl_submissions', array('id' => $submissionid));
        } else {
            $subinstance = $vpl->last_user_submission($userid);
        }
        $vpl->password_check();
    }
    //Check consistence
    if (!$subinstance) {
        throw new Exception(get_string('nosubmission', VPL));
    }
    if ($subinstance->vpl != $vpl->get_instance()->id) {
        throw new Exception(get_string('invalidcourseid'));
    }
    $submissionid = $subinstance->id;
    if ($vpl->is_inconsistent_user($subinstance->userid, $userid)) {
        throw new Exception('vpl submission user inconsistence');
    }
    if ($vpl->get_instance()->id != $subinstance->vpl) {
        throw new Exception('vpl submission vpl inconsistence');
    }
    $submission = new mod_vpl_submission($vpl, $subinstance);
    $fgm = $submission->get_submitted_fgm();
    $fgm->download_files($vpl->get_printable_name());
} catch (Exception $e) {
    $vpl->prepare_page('views/downloadsubmission.php', array('id' => $id));
    $vpl->print_header(get_string('download', VPL));
    echo $OUTPUT->box($e->getMessage());
    $vpl->print_footer();
}
Example #5
0
 /**
  * Show vpl submission restriction
  **/
 function print_submission_restriction()
 {
     global $CFG, $USER;
     //TODO print_submission_restriction
     $filegroup = $this->get_required_fgm();
     $files = $filegroup->getFileList();
     if (count($files)) {
         $text = '';
         $need_comma = false;
         foreach ($files as $file) {
             if ($need_comma) {
                 $text .= ', ';
             }
             $text .= s($file);
             $need_comma = true;
         }
         $link = ' (<a href="';
         $link .= vpl_mod_href('views/downloadrequiredfiles.php', 'id', $this->get_course_module()->id);
         $link .= '">';
         $link .= get_string('download', VPL);
         $link .= '</a>)';
         $this->print_restriction('requestedfiles', $text . $link);
     }
     if (count($files) != $this->instance->maxfiles) {
         $this->print_restriction('maxfiles');
     }
     if ($this->instance->maxfilesize) {
         $mfs = $this->get_maxfilesize();
         $this->print_restriction('maxfilesize', vpl_conv_size_to_string($mfs));
     }
     $worktype = $this->instance->worktype;
     $values = array(0 => get_string('individualwork', VPL), 1 => get_string('groupwork', VPL));
     if ($worktype) {
         $this->print_restriction('worktype', $values[$worktype] . ' ' . $this->fullname($USER));
     } else {
         $this->print_restriction('worktype', $values[$worktype]);
     }
     if ($this->has_capability(VPL_GRADE_CAPABILITY)) {
         $str_yes = get_string('yes');
         $str_no = get_string('no');
         require_once $CFG->libdir . '/gradelib.php';
         if ($gie = $this->get_grade_info()) {
             if ($gie->scaleid == 0) {
                 $info = get_string('grademax', 'core_grades') . ': ' . vpl_rtzeros($gie->grademax);
                 $info .= $gie->hidden ? ' <b>' . get_string('hidden', 'core_grades') . '</b>' : '';
                 $info .= $gie->locked ? ' <b>' . get_string('locked', 'core_grades') . '</b>' : '';
             } else {
                 $info = get_string('typescale', 'core_grades');
             }
             $this->print_restriction(get_String('gradessettings', 'core_grades'), $info, true);
         } else {
             $this->print_restriction(get_String('gradessettings', 'core_grades'), get_string('nograde'), true);
         }
         if (trim($this->instance->password) > '') {
             $this->print_restriction(get_string('password'), $str_yes, true);
         }
         if (trim($this->instance->requirednet) > '') {
             $this->print_restriction('requirednet', s($this->instance->requirednet));
         }
         if ($this->instance->restrictededitor) {
             $this->print_restriction('restrictededitor', $str_yes);
         }
         if ($this->instance->example) {
             $this->print_restriction('isexample', $str_yes);
         }
         if (!$this->get_course_module()->visible) {
             $this->print_restriction(get_string('visible'), $str_no, true);
         }
         if ($this->instance->basedon) {
             $basedon = new mod_vpl(null, $this->instance->basedon);
             $link = '<a href="';
             $link .= vpl_mod_href('view.php', 'id', $basedon->cm->id);
             $link .= '">';
             $link .= $basedon->get_printable_name();
             $link .= '</a>';
             $this->print_restriction('basedon', $link);
         }
         $noyes = array($str_no, $str_yes);
         $this->print_restriction('run', $noyes[$this->instance->run], false, false);
         if ($this->instance->debug) {
             $this->print_restriction('debug', $noyes[1], false, false);
         }
         $this->print_restriction('evaluate', $noyes[$this->instance->evaluate], false, !($this->instance->evaluate && $this->instance->evaluateonsubmission));
         if ($this->instance->evaluate && $this->instance->evaluateonsubmission) {
             $this->print_restriction('evaluateonsubmission', $noyes[1]);
         }
         if ($this->instance->automaticgrading) {
             $this->print_restriction('automaticgrading', $noyes[1], false, false);
         }
         if ($this->instance->maxexetime) {
             $this->print_restriction('maxexetime', $this->instance->maxexetime . ' s', false, false);
         }
         if ($this->instance->maxexememory) {
             $this->print_restriction('maxexememory', vpl_conv_size_to_string($this->instance->maxexememory), false, false);
         }
         if ($this->instance->maxexefilesize) {
             $this->print_restriction('maxexefilesize', vpl_conv_size_to_string($this->instance->maxexefilesize), false, false);
         }
         if ($this->instance->maxexeprocesses) {
             $this->print_restriction('maxexeprocesses', null, false, false);
         }
     }
 }
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// VPL for Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with VPL for Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * Download required files in ZIP format
 * @package mod_vpl
 * @copyright 2012 Juan Carlos Rodríguez-del-Pino
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @author Juan Carlos Rodríguez-del-Pino <*****@*****.**>
 */
require_once dirname(__FILE__) . '/../../../config.php';
require_once dirname(__FILE__) . '/../locallib.php';
require_once dirname(__FILE__) . '/../vpl.class.php';
require_login();
$id = required_param('id', PARAM_INT);
$vpl = new mod_vpl($id);
$vpl->password_check();
$vpl->network_check();
if (!$vpl->is_visible()) {
    notice(get_string('notavailable'));
}
$filegroup = $vpl->get_required_fgm();
$filegroup->download_files($vpl->get_printable_name());
die;
}
$usernumber = 0;
$nwm = 0;
$simil = array();
//Preprocess current VPL instance
@set_time_limit($time_limit);
$activity_load_box = new vpl_progress_bar(s($vpl->get_printable_name()));
//debugging("Adding activity files", DEBUG_DEVELOPER);
vpl_similarity::scan_activity($simil, $vpl, $filesselected, $activity_load_box);
//debugging("Files to check ".count($simil), DEBUG_DEVELOPER);
$il = count($simil);
//Preprocess other VPL instance
if (isset($fromform->scanactivity) && $fromform->scanactivity > 0) {
    @set_time_limit($time_limit);
    $othervpl = new mod_vpl($fromform->scanactivity);
    $other_activity_load_box = new vpl_progress_bar(s($othervpl->get_printable_name()));
    //debugging("Adding other activity files", DEBUG_DEVELOPER);
    vpl_similarity::scan_activity($simil, $othervpl, $filesselected, $other_activity_load_box);
    //debugging("Files to check ".count($simil), DEBUG_DEVELOPER);
}
//Preprocess files in a ZIP file
$name = $form->get_new_filename('scanzipfile0');
$data = $form->get_file_content('scanzipfile0');
if ($data !== false && $name !== false) {
    @set_time_limit($time_limit);
    $zip_load_box0 = new vpl_progress_bar(s($name));
    //debugging("Adding files in zip file", DEBUG_DEVELOPER);
    vpl_similarity::scan_zip($simil, $name, $data, $vpl, $filesselected, $zip_load_box0);
    //debugging("Files to check ".count($simil), DEBUG_DEVELOPER);
}
/* remove when 1.9 => 2.x
Example #8
0
    $name = $firstname . ' / ' . $lastname;
}
$with = get_string('similarto', VPL);
$head = array('#', $name, '', $with);
$align = array('right', 'left', 'center', 'left');
$size = array('', '60', '60', '');
//Preprocess current VPL instance
$subfgm = $submission->get_submitted_fgm();
foreach ($subfgm->getFileList() as $filename) {
    if (isset($filesselected[$filename])) {
        //Check if this is a required filename
        echo '<h3>' . s($filename) . '</h3>';
        @set_time_limit($time_limit);
        $simil = array();
        $fselected = array();
        $activity_load_box = new vpl_progress_bar(s($vpl->get_printable_name()) . ":" . s($filename));
        $fselected[$filename] = true;
        vpl_similarity::scan_activity($simil, $vpl, $fselected, $activity_load_box);
        //TODO Find and put first user file
        $l = count($simil);
        for ($i = 0; $i < $l; $i++) {
            if ($simil[$i]->from->userid == $userid) {
                $obj = $simil[0];
                $simil[0] = $simil[$i];
                $simil[$i] = $obj;
                break;
            }
        }
        $search_progression = new vpl_progress_bar(get_string('similarity', VPL));
        $selected = vpl_similarity::get_selected($simil, 4, 1, $search_progression);
        $table = new html_table();
Example #9
0
    $table->head[] = get_string('submissions', VPL);
    $table->head[] = get_string('graded', VPL);
    $table->align[] = 'right';
    $table->align[] = 'right';
}
if ($student && !$no_grade) {
    $table->head[] = get_string('grade');
    $table->align[] = 'left';
}
$table->data = array();
$totalsubs = 0;
$totalgraded = 0;
foreach ($vpls as $vpl) {
    $instance = $vpl->get_instance();
    $url = vpl_rel_url('view.php', 'id', $vpl->get_course_module()->id);
    $row = array(count($table->data) + 1, "<a href='{$url}'>{$vpl->get_printable_name()}</a>", s($instance->shortdescription));
    if ($startdate) {
        $row[] = $instance->startdate > 0 ? userdate($instance->startdate) : '';
    }
    if ($duedate) {
        $row[] = $instance->duedate > 0 ? userdate($instance->duedate) : '';
    }
    if ($grader) {
        if ($vpl->has_capability(VPL_GRADE_CAPABILITY) && $vpl->get_grade() != 0 && !$instance->example) {
            $info = vpl_list_util::count_graded($vpl);
            $totalsubs += $info['submissions'];
            $totalgraded += $info['graded'];
            $url = vpl_rel_url('views/submissionslist.php', 'id', $vpl->get_course_module()->id, 'selection', 'allsubmissions');
            $row[] = '<a href="' . $url . '">' . $info['submissions'] . '</a>';
            //Need mark?
            if ($info['submissions'] > $info['graded'] && $vpl->get_grade() != 0 && !($instance->duedate != 0 && $instance->duedate > time())) {
Example #10
0
            if ($subshow >= $subshowl) {
                break;
            }
        }
    }
    $nsub = 1;
    foreach ($subs as $sub) {
        $subsn[] = $nsub % $subshow == 0 ? $nsub : '';
        $nsub++;
        $files_array = $sub->get_submitted_files();
        $files = array();
        //Used to give stack format last bar has less size
        $total_size = 0;
        foreach ($files_array as $file) {
            $size = strlen($file['data']);
            $files[$file['name']] = $size;
            $total_size += $size;
        }
        foreach ($names as $name) {
            if (isset($files[$name])) {
                $series[$name][] = $total_size;
                $total_size -= $files[$name];
            } else {
                $series[$name][] = $total_size;
            }
        }
    }
}
$user = $DB->get_record('user', array('id' => $userid));
vpl_graph::draw($vpl->get_printable_name() . ' - ' . $vpl->fullname($user, false), get_string('submissions', VPL), get_string("sizeb"), $subsn, $series, $names);