Example #1
0
 static function vpl_get_similfile($f, $vpl, &$HTMLheader, &$filename, &$data)
 {
     global $DB;
     $HTMLheader = '';
     $filename = '';
     $data = '';
     $type = required_param('type' . $f, PARAM_INT);
     if ($type == 1) {
         $subid = required_param('subid' . $f, PARAM_INT);
         $filename = required_param('filename' . $f, PARAM_TEXT);
         $subinstance = $DB->get_record('vpl_submissions', array('id' => $subid));
         if ($subinstance !== false) {
             $vpl = new mod_vpl(false, $subinstance->vpl);
             $vpl->require_capability(VPL_SIMILARITY_CAPABILITY);
             $submission = new mod_vpl_submission($vpl, $subinstance);
             $user = $DB->get_record('user', array('id' => $subinstance->userid));
             if ($user) {
                 $HTMLheader .= '<a href="' . vpl_mod_href('/forms/submissionview.php', 'id', $vpl->get_course_module()->id, 'userid', $subinstance->userid) . '">';
             }
             $HTMLheader .= s($filename) . ' ';
             if ($user) {
                 $HTMLheader .= '</a>';
                 $HTMLheader .= $vpl->user_fullname_picture($user);
             }
             $fg = $submission->get_submitted_fgm();
             $data = $fg->getFileData($filename);
             \mod_vpl\event\vpl_diff_viewed::log($submission);
         }
     } elseif ($type == 2) {
         //FIXME adapt to moodle 2.x
         /*
         global $CFG;
         $dirname = required_param('dirname'.$f,PARAM_RAW);
         $filename = required_param('filename'.$f,PARAM_RAW);
         $base=$CFG->dataroot.'/'.$vpl->get_course()->id.'/';
         $data = file_get_contents($base.$dirname.'/'.$filename);
         $HTMLheader .= $filename.' '.optional_param('username'.$f,'',PARAM_TEXT);
         */
     } elseif ($type == 3) {
         global $CFG;
         $data = '';
         $zipname = required_param('zipfile' . $f, PARAM_RAW);
         $filename = required_param('filename' . $f, PARAM_RAW);
         $HTMLheader .= $filename . ' ' . optional_param('username' . $f, '', PARAM_TEXT);
         $ext = strtoupper(pathinfo($zipname, PATHINFO_EXTENSION));
         if ($ext != 'ZIP') {
             print_error('nozipfile');
         }
         $zip = new ZipArchive();
         $zipfilename = vpl_similarity::get_zip_filepath($zipname);
         if ($zip->open($zipfilename)) {
             $data = $zip->getFromName($filename);
             $zip->close();
         }
     } else {
         print_error('type error');
     }
 }
if(isset($fromform->scandirectory) && $fromform->scandirectory>''){
    @set_time_limit($time_limit);
    $dir_load_box = new vpl_progress_bar(s($fromform->scandirectory));
    $basedir = $CFG->dataroot.'/'.$vpl->get_course()->id;
    debugging("Adding files in directory", DEBUG_DEVELOPER);
    vpl_similarity::scan_directory($simil,$fromform->scandirectory,$vpl,$filesselected,$dir_load_box);
    debugging("Files to check ".count($simil), DEBUG_DEVELOPER);
}
*/
//Search similarity in other files after current VPL instance
if (isset($fromform->searchotherfiles)) {
    $il = count($simil);
}
@set_time_limit($time_limit);
$search_progression = new vpl_progress_bar(get_string('similarity', VPL));
$selected = vpl_similarity::get_selected($simil, $fromform->maxoutput, $il, $search_progression);
//$extinfo=$USER->id==2;
$extinfo = false;
if (count($selected)) {
    $firstname = get_string('firstname');
    $lastname = get_string('lastname');
    if ($CFG->fullnamedisplay == 'lastname firstname') {
        $name = $lastname . ' / ' . $firstname;
    } else {
        $name = $firstname . ' / ' . $lastname;
    }
    $with = get_string('similarto', VPL);
    $table = new html_table();
    $table->head = array('#', $name, '', $with, get_string('numcluster', VPL, '#'));
    $table->align = array('right', 'left', 'center', 'left', 'right');
    $table->size = array('', '60', '60');
 public static function filter_selected(&$vec, $maxselected, &$minlevel, $sid, $last = false)
 {
     if (count($vec) > $maxselected || $last && count($vec) > 0) {
         if (self::$corder === null) {
             self::$corder = new vpl_similarity();
         }
         //usort of old PHP versions don't call static class functions
         if (!usort($vec, array(self::$corder, 'cmp_selected' . $sid))) {
             debugging('usort error');
         }
         $field = 's' . $sid;
         $vec = array_slice($vec, 0, $maxselected);
         $minlevel = $vec[count($vec) - 1]->{$field};
     }
 }
Example #4
0
@set_time_limit($time_limit);
$simil = array();
$activity_load_box = new vpl_progress_bar(s($vpl->get_printable_name()) . ":" . s($filename));
vpl_similarity::scan_activity($simil, $vpl, $filesselected, $activity_load_box, false);
//TODO Find and put first user file
$l = count($simil);
$others = 0;
for ($i = 0; $i < $l; $i++) {
    if ($simil[$i]->from->userid == $userid) {
        $obj = $simil[$others];
        $simil[$others] = $simil[$i];
        $simil[$i] = $obj;
        $others++;
    }
}
if ($others > 0) {
    $search_progression = new vpl_progress_bar(get_string('similarity', VPL));
    $selected = vpl_similarity::get_selected($simil, 2 * $others, $others, $search_progression);
    $table = new html_table();
    $table->head = $head;
    $table->align = $align;
    $table->size = $size;
    $usernumber = 0;
    foreach ($selected as $case) {
        $table->data[] = array(++$usernumber, $case->first->show_info(), $case->get_link(), $case->second->show_info());
    }
    echo html_writer::table($table);
    $search_progression->hide();
}
$activity_load_box->hide();
$vpl->print_footer();