コード例 #1
0
 /**
  * Render single user participation record for display
  *
  * @param object $user
  * @param array $changes user participation
  * @param object $cm
  * @param object $course
  * @param object $ouwiki
  * @param object $subwiki
  * @param string $pagename
  * @param int $groupid
  * @param string $download
  * @param bool $canview level of participation user can view
  * @param object $context
  * @param string $fullname
  * @param bool $cangrade permissions to grade user participation
  * @param string $groupname
  */
 public function ouwiki_render_user_participation($user, $changes, $cm, $course, $ouwiki, $subwiki, $pagename, $groupid, $download, $canview, $context, $fullname, $cangrade, $groupname)
 {
     global $DB, $CFG, $OUTPUT;
     require_once $CFG->dirroot . '/mod/ouwiki/participation_table.php';
     $filename = "{$course->shortname}-" . format_string($ouwiki->name, true);
     if (!empty($groupname)) {
         $filename .= '-' . format_string($groupname, true);
     }
     $filename .= '-' . format_string($fullname, true);
     // setup the table
     $table = new ouwiki_user_participation_table($cm, $course, $ouwiki, $pagename, $groupname, $user, $fullname);
     $table->setup($download);
     $table->is_downloading($download, $filename, get_string('participation', 'ouwiki'));
     // participation doesn't need standard ouwiki tabs so we need to
     // add this one div in manually
     if (!$table->is_downloading()) {
         echo html_writer::start_tag('div', array('id' => 'ouwiki_belowtabs'));
     }
     $previouswordcount = false;
     $lastdate = null;
     foreach ($changes as $change) {
         $date = userdate($change->timecreated, get_string('strftimedate'));
         $time = userdate($change->timecreated, get_string('strftimetime'));
         if (!$table->is_downloading()) {
             if ($date == $lastdate) {
                 $date = null;
             } else {
                 $lastdate = $date;
             }
             $now = time();
             $edittime = $time;
             if ($now - $edittime < 5 * 60) {
                 $category = 'ouw_recenter';
             } else {
                 if ($now - $edittime < 4 * 60 * 60) {
                     $category = 'ouw_recent';
                 } else {
                     $category = 'ouw_recentnot';
                 }
             }
             $time = html_writer::start_tag('span', array('class' => $category));
             $time .= $edittime;
             $time .= html_writer::end_tag('span');
         }
         $page = $change->title ? htmlspecialchars($change->title) : get_string('startpage', 'ouwiki');
         $row = array($date, $time, $page);
         // word counts
         if ($ouwiki->enablewordcount) {
             $previouswordcount = false;
             if ($change->previouswordcount) {
                 $words = ouwiki_wordcount_difference($change->wordcount, $change->previouswordcount, true);
             } else {
                 $words = ouwiki_wordcount_difference($change->wordcount, 0, false);
             }
             if (!$table->is_downloading()) {
                 $row[] = $words;
             } else {
                 if ($words <= 0) {
                     $row[] = 0;
                     $row[] = $words;
                 } else {
                     $row[] = $words;
                     $row[] = 0;
                 }
             }
         }
         if (!$table->is_downloading()) {
             $pageparams = ouwiki_display_wiki_parameters($change->title, $subwiki, $cm);
             $pagestr = $page . ' ' . $lastdate . ' ' . $edittime;
             if ($change->id != $change->firstversionid) {
                 $accesshidetext = get_string('viewwikichanges', 'ouwiki', $pagestr);
                 $changeurl = new moodle_url("/mod/ouwiki/diff.php?{$pageparams}" . "&v2={$change->id}&v1={$change->previousversionid}");
                 $changelink = html_writer::start_tag('small');
                 $changelink .= ' (';
                 $changelink .= html_writer::link($changeurl, get_string('changes', 'ouwiki'));
                 $changelink .= ')';
                 $changelink .= html_writer::end_tag('small');
             } else {
                 $accesshidetext = get_string('viewwikistartpage', 'ouwiki', $pagestr);
                 $changelink = html_writer::start_tag('small');
                 $changelink .= ' (' . get_string('newpage', 'ouwiki') . ')';
                 $changelink .= html_writer::end_tag('small');
             }
             $current = '';
             if ($change->id == $change->currentversionid) {
                 $viewurl = new moodle_url("/mod/ouwiki/view.php?{$pageparams}");
             } else {
                 $viewurl = new moodle_url("/mod/ouwiki/viewold.php?" . "{$pageparams}&version={$change->id}");
             }
             $actions = html_writer::tag('span', $accesshidetext, array('class' => 'accesshide'));
             $actions .= html_writer::link($viewurl, get_string('view'));
             $actions .= $changelink;
             $row[] = $actions;
         }
         // add to the table
         $table->add_data($row);
     }
     if (!$table->is_downloading()) {
         $table->print_html();
         /// Print the whole table
         // Grade
         if ($cangrade && $ouwiki->grade != 0) {
             $this->ouwiki_render_user_grade($course, $cm, $ouwiki, $user, $pagename, $groupid);
         }
     }
 }
コード例 #2
0
/**
 * Sorts version data and calculates changes
 * per user for rendering
 *
 * @param array $data
 * @return array
 */
function ouwiki_sort_participation($data)
{
    global $DB;
    if (empty($data['users'])) {
        return array();
        // no users
    }
    if (empty($data['versions'])) {
        return $data['users'];
        // users but no versions
    }
    $byusers = $data['users'];
    foreach ($data['versions'] as $version) {
        if (isset($byusers[$version->userid])) {
            // setup properties
            if (!isset($byusers[$version->userid]->wordsadded)) {
                $byusers[$version->userid]->wordsadded = 0;
            }
            if (!isset($byusers[$version->userid]->wordsdeleted)) {
                $byusers[$version->userid]->wordsdeleted = 0;
            }
            if (!isset($byusers[$version->userid]->pagecreates)) {
                $byusers[$version->userid]->pagecreates = 0;
            }
            if (!isset($byusers[$version->userid]->pageedits)) {
                $byusers[$version->userid]->pageedits = 0;
            }
            // calculations
            if ($version->versionid == $version->firstversionid) {
                $byusers[$version->userid]->pagecreates++;
                // user created this page so entire wordcount is valid
                if (isset($version->wordcount)) {
                    $byusers[$version->userid]->wordsadded += $version->wordcount;
                }
            } else {
                $byusers[$version->userid]->pageedits++;
                // wordcount calculation
                if (isset($version->wordcount)) {
                    if ($version->previouswordcount) {
                        $words = ouwiki_wordcount_difference($version->wordcount, $version->previouswordcount, true);
                    } else {
                        $words = ouwiki_wordcount_difference($version->wordcount, 0, false);
                    }
                    if ($words < 0) {
                        $byusers[$version->userid]->wordsdeleted += abs($words);
                    } else {
                        $byusers[$version->userid]->wordsadded += abs($words);
                    }
                }
            }
        }
    }
    // return sorted array
    return $byusers;
}
コード例 #3
0
        $actions = "<td class='actions'><a href='{$viewlink}'>{$strview}</a>{$changelink}</td>";
    }
    // see bug #3611
    if (!empty($current) && !empty($CFG->ouwikienablecurrentpagehighlight)) {
        // current page so add accessibility stuff
        $accessiblityhide = '<span class="accesshide">' . get_string('currentversionof', 'ouwiki') . '</span>';
        $dummy = $page;
        $page = $accessiblityhide . $dummy;
    }
    print "\n<tr{$current}>\n  <td class='ouw_leftcol'>{$date}</td><td>{$time}</td><td>{$page}</td>\n  {$actions}";
    if ($ouwiki->enablewordcount) {
        if (isset($change->previouswordcount)) {
            $wordcountchanges = ouwiki_wordcount_difference($change->wordcount, $change->previouswordcount, true);
        } else {
            // first page
            $wordcountchanges = ouwiki_wordcount_difference($change->wordcount, 0, false);
        }
        print "<td>{$wordcountchanges}</td>";
    }
    print "\n  <td class='ouw_rightcol'>{$userlink}</td>\n</tr>";
}
print '</table>';
if (empty($changes)) {
    echo get_string('nowikipages', 'ouwiki');
}
if ($count > OUWIKI_PAGESIZE || $from > 0) {
    print '<div class="ouw_paging"><div class="ouw_paging_prev">&nbsp;';
    if ($from > 0) {
        $jump = $from - OUWIKI_PAGESIZE;
        if ($jump < 0) {
            $jump = 0;