예제 #1
0
function data_rss_get_feed($context, $args)
{
    global $CFG, $DB;
    // Check CFG->data_enablerssfeeds.
    if (empty($CFG->data_enablerssfeeds)) {
        debugging("DISABLED (module configuration)");
        return null;
    }
    $dataid = clean_param($args[3], PARAM_INT);
    $cm = get_coursemodule_from_instance('data', $dataid, 0, false, MUST_EXIST);
    if ($cm) {
        $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
        //context id from db should match the submitted one
        if ($context->id != $modcontext->id || !has_capability('mod/data:viewentry', $modcontext)) {
            return null;
        }
    }
    $data = $DB->get_record('data', array('id' => $dataid), '*', MUST_EXIST);
    if (!rss_enabled_for_mod('data', $data, false, true)) {
        return null;
    }
    $sql = data_rss_get_sql($data);
    //get the cache file info
    $filename = rss_get_file_name($data, $sql);
    $cachedfilepath = rss_get_file_full_name('mod_data', $filename);
    //Is the cache out of date?
    $cachedfilelastmodified = 0;
    if (file_exists($cachedfilepath)) {
        $cachedfilelastmodified = filemtime($cachedfilepath);
    }
    //if the cache is more than 60 seconds old and there's new stuff
    $dontrecheckcutoff = time() - 60;
    if ($dontrecheckcutoff > $cachedfilelastmodified && data_rss_newstuff($data, $cachedfilelastmodified)) {
        require_once $CFG->dirroot . '/mod/data/lib.php';
        // Get the first field in the list  (a hack for now until we have a selector)
        if (!($firstfield = $DB->get_record_sql('SELECT id,name FROM {data_fields} WHERE dataid = ? ORDER by id', array($data->id), true))) {
            return null;
        }
        if (!($records = $DB->get_records_sql($sql, array(), 0, $data->rssarticles))) {
            return null;
        }
        $firstrecord = array_shift($records);
        // Get the first and put it back
        array_unshift($records, $firstrecord);
        // Now create all the articles
        $items = array();
        foreach ($records as $record) {
            $recordarray = array();
            array_push($recordarray, $record);
            $item = null;
            // guess title or not
            if (!empty($data->rsstitletemplate)) {
                $item->title = data_print_template('rsstitletemplate', $recordarray, $data, '', 0, true);
            } else {
                // else we guess
                $item->title = strip_tags($DB->get_field('data_content', 'content', array('fieldid' => $firstfield->id, 'recordid' => $record->id)));
            }
            $item->description = data_print_template('rsstemplate', $recordarray, $data, '', 0, true);
            $item->pubdate = $record->timecreated;
            $item->link = $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&rid=' . $record->id;
            array_push($items, $item);
        }
        $course = $DB->get_record('course', array('id' => $data->course));
        $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
        $courseshortname = format_string($course->shortname, true, array('context' => $coursecontext));
        // First all rss feeds common headers.
        $header = rss_standard_header($courseshortname . ': ' . format_string($data->name, true, array('context' => $context)), $CFG->wwwroot . "/mod/data/view.php?d=" . $data->id, format_text($data->intro, $data->introformat, array('context' => $context)));
        if (!empty($header)) {
            $articles = rss_add_items($items);
        }
        // Now all rss feeds common footers.
        if (!empty($header) && !empty($articles)) {
            $footer = rss_standard_footer();
        }
        // Now, if everything is ok, concatenate it.
        if (!empty($header) && !empty($articles) && !empty($footer)) {
            $rss = $header . $articles . $footer;
            //Save the XML contents to file.
            $status = rss_save_file('mod_data', $filename, $rss);
        }
    }
    return $cachedfilepath;
}
예제 #2
0
파일: view.php 프로젝트: hatone/moodle
             // List template
             $baseurl = 'view.php?d=' . $data->id . '&';
             //send the advanced flag through the URL so it is remembered while paging.
             $baseurl .= 'advanced=' . $advanced . '&';
             if (!empty($search)) {
                 $baseurl .= 'filter=1&';
             }
             //pass variable to allow determining whether or not we are paging through results.
             $baseurl .= 'paging=' . $paging . '&';
             echo $OUTPUT->paging_bar($totalcount, $page, $nowperpage, $baseurl);
             if (empty($data->listtemplate)) {
                 echo $OUTPUT->notification(get_string('nolisttemplate', 'data'));
                 data_generate_default_template($data, 'listtemplate', 0, false, false);
             }
             echo $data->listtemplateheader;
             data_print_template('listtemplate', $records, $data, $search, $page);
             echo $data->listtemplatefooter;
             echo $OUTPUT->paging_bar($totalcount, $page, $nowperpage, $baseurl);
         }
     }
 }
 $search = trim($search);
 if (empty($records)) {
     $records = array();
 }
 if ($mode == '' && !empty($CFG->enableportfolios)) {
     require_once $CFG->libdir . '/portfoliolib.php';
     $button = new portfolio_add_button();
     $button->set_callback_options('data_portfolio_caller', array('id' => $cm->id), '/mod/data/locallib.php');
     if (data_portfolio_caller::has_files($data)) {
         $button->set_formats(array(PORTFOLIO_FORMAT_RICHHTML, PORTFOLIO_FORMAT_LEAP2A));
예제 #3
0
function data_rss_feeds()
{
    global $CFG, $DB;
    $status = true;
    // Check CFG->enablerssfeeds.
    if (empty($CFG->enablerssfeeds)) {
        debugging("DISABLED (admin variables)");
    } else {
        if (empty($CFG->data_enablerssfeeds)) {
            debugging("DISABLED (module configuration)");
        } else {
            // Iterate over all data.
            if ($datas = $DB->get_records('data')) {
                foreach ($datas as $data) {
                    if ($data->rssarticles > 0) {
                        // Get the first field in the list  (a hack for now until we have a selector)
                        if (!($firstfield = $DB->get_record_sql('SELECT id,name FROM {data_fields} WHERE dataid = ? ORDER by id', array($data->id), true))) {
                            continue;
                        }
                        // Get the data_records out.
                        $approved = $data->approval ? ' AND dr.approved = 1 ' : ' ';
                        $sql = "SELECT dr.*, u.firstname, u.lastname\n                                  FROM {data_records} dr, {user} u\n                                 WHERE dr.dataid = ? {$approved}\n                                       AND dr.userid = u.id\n                              ORDER BY dr.timecreated DESC";
                        if (!($records = $DB->get_records_sql($sql, array($data->id), 0, $data->rssarticles))) {
                            continue;
                        }
                        $firstrecord = array_shift($records);
                        // Get the first and put it back
                        array_unshift($records, $firstrecord);
                        $filename = rss_file_name('data', $data);
                        if (file_exists($filename)) {
                            if (filemtime($filename) >= $firstrecord->timemodified) {
                                continue;
                            }
                        }
                        // Now create all the articles
                        mtrace('Creating feed for ' . $data->name);
                        $items = array();
                        foreach ($records as $record) {
                            $recordarray = array();
                            array_push($recordarray, $record);
                            $item = null;
                            // guess title or not
                            if (!empty($data->rsstitletemplate)) {
                                $item->title = data_print_template('rsstitletemplate', $recordarray, $data, '', 0, true);
                            } else {
                                // else we guess
                                $item->title = strip_tags($DB->get_field('data_content', 'content', array('fieldid' => $firstfield->id, 'recordid' => $record->id)));
                            }
                            $item->description = data_print_template('rsstemplate', $recordarray, $data, '', 0, true);
                            $item->pubdate = $record->timecreated;
                            $item->link = $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&rid=' . $record->id;
                            array_push($items, $item);
                        }
                        $course = $DB->get_record('course', array('id' => $data->course));
                        // First all rss feeds common headers.
                        $header = rss_standard_header($course->shortname . ': ' . format_string($data->name, true), $CFG->wwwroot . "/mod/data/view.php?d=" . $data->id, format_string($data->intro, true));
                        //TODO: fix format
                        if (!empty($header)) {
                            $articles = rss_add_items($items);
                        }
                        // Now all rss feeds common footers.
                        if (!empty($header) && !empty($articles)) {
                            $footer = rss_standard_footer();
                        }
                        // Now, if everything is ok, concatenate it.
                        if (!empty($header) && !empty($articles) && !empty($footer)) {
                            $rss = $header . $articles . $footer;
                            //Save the XML contents to file.
                            $status = rss_save_file('data', $data, $rss);
                        } else {
                            $status = false;
                        }
                    }
                }
            }
        }
    }
    return $status;
}
예제 #4
0
파일: lib.php 프로젝트: nottmoo/moodle
/**
 * Prints all the records uploaded by this user
 *
 * @global object
 * @param object $course
 * @param object $user
 * @param object $mod
 * @param object $data
 */
function data_user_complete($course, $user, $mod, $data) {
    global $DB, $CFG, $OUTPUT;
    require_once("$CFG->libdir/gradelib.php");

    $grades = grade_get_grades($course->id, 'mod', 'data', $data->id, $user->id);
    if (!empty($grades->items[0]->grades)) {
        $grade = reset($grades->items[0]->grades);
        echo $OUTPUT->container(get_string('grade').': '.$grade->str_long_grade);
        if ($grade->str_feedback) {
            echo $OUTPUT->container(get_string('feedback').': '.$grade->str_feedback);
        }
    }

    if ($records = $DB->get_records('data_records', array('dataid'=>$data->id,'userid'=>$user->id), 'timemodified DESC')) {
        data_print_template('singletemplate', $records, $data);
    }
}
예제 #5
0
파일: view.php 프로젝트: pzhu2004/moodle
             // List template
             $baseurl = 'view.php?d=' . $data->id . '&';
             //send the advanced flag through the URL so it is remembered while paging.
             $baseurl .= 'advanced=' . $advanced . '&';
             if (!empty($search)) {
                 $baseurl .= 'filter=1&';
             }
             //pass variable to allow determining whether or not we are paging through results.
             $baseurl .= 'paging=' . $paging . '&';
             echo $OUTPUT->paging_bar($totalcount, $page, $nowperpage, $baseurl);
             if (empty($data->listtemplate)) {
                 echo $OUTPUT->notification(get_string('nolisttemplate', 'data'));
                 data_generate_default_template($data, 'listtemplate', 0, false, false);
             }
             echo $data->listtemplateheader;
             data_print_template('listtemplate', $records, $data, $search, $page, false, new moodle_url($baseurl));
             echo $data->listtemplatefooter;
             echo $OUTPUT->paging_bar($totalcount, $page, $nowperpage, $baseurl);
         }
         if ($mode != 'single' && $canmanageentries) {
             echo html_writer::empty_tag('input', array('type' => 'button', 'id' => 'checkall', 'value' => get_string('selectall')));
             echo html_writer::empty_tag('input', array('type' => 'button', 'id' => 'checknone', 'value' => get_string('deselectall')));
             echo html_writer::empty_tag('input', array('class' => 'form-submit', 'type' => 'submit', 'value' => get_string('deleteselected')));
             $module = array('name' => 'mod_data', 'fullpath' => '/mod/data/module.js');
             $PAGE->requires->js_init_call('M.mod_data.init_view', null, false, $module);
         }
         echo html_writer::end_tag('form');
     }
 }
 $search = trim($search);
 if (empty($records)) {
예제 #6
0
function data_user_complete($course, $user, $mod, $data)
{
    global $CFG;
    require_once "{$CFG->libdir}/gradelib.php";
    $grades = grade_get_grades($course->id, 'mod', 'data', $data->id, $user->id);
    if (!empty($grades->items[0]->grades)) {
        $grade = reset($grades->items[0]->grades);
        echo '<p>' . get_string('grade') . ': ' . $grade->str_long_grade . '</p>';
        if ($grade->str_feedback) {
            echo '<p>' . get_string('feedback') . ': ' . $grade->str_feedback . '</p>';
        }
    }
    if ($records = get_records_select('data_records', 'dataid = ' . $data->id . ' AND userid = ' . $user->id, 'timemodified DESC')) {
        data_print_template('singletemplate', $records, $data);
    }
}
예제 #7
0
function data_user_complete($course, $user, $mod, $data)
{
    global $DB;
    if ($records = $DB->get_records('data_records', array('dataid' => $data->id, 'userid' => $user->id), 'timemodified DESC')) {
        data_print_template('singletemplate', $records, $data);
    }
}
예제 #8
0
function data_user_complete($course, $user, $mod, $data)
{
    if ($records = get_records_select('data_records', 'dataid = ' . $data->id . ' AND userid = ' . $user->id, 'timemodified DESC')) {
        data_print_template('singletemplate', $records, $data);
    }
}
function print_section_dblistview($course, $section, $mods, $modnamesused, $absolute = false, $width = "100%")
{
    /// Prints a section full of activity modules
    global $CFG, $USER;
    static $initialised;
    static $groupbuttons;
    static $groupbuttonslink;
    static $isediting;
    static $ismoving;
    static $strmovehere;
    static $strmovefull;
    static $strunreadpostsone;
    static $usetracking;
    static $groupings;
    if (!isset($initialised)) {
        $groupbuttons = ($course->groupmode or !$course->groupmodeforce);
        $groupbuttonslink = !$course->groupmodeforce;
        $isediting = isediting($course->id);
        $ismoving = $isediting && ismoving($course->id);
        if ($ismoving) {
            $strmovehere = get_string("movehere");
            $strmovefull = strip_tags(get_string("movefull", "", "'{$USER->activitycopyname}'"));
        }
        include_once $CFG->dirroot . '/mod/forum/lib.php';
        if ($usetracking = forum_tp_can_track_forums()) {
            $strunreadpostsone = get_string('unreadpostsone', 'forum');
        }
        $initialised = true;
    }
    $labelformatoptions = new object();
    $labelformatoptions->noclean = true;
    /// Casting $course->modinfo to string prevents one notice when the field is null
    $modinfo = get_fast_modinfo($course);
    //Acccessibility: replace table with list <ul>, but don't output empty list.
    if (!empty($section->sequence)) {
        // Fix bug #5027, don't want style=\"width:$width\".
        echo "<ul class=\"section img-text\">\n";
        $sectionmods = explode(",", $section->sequence);
        foreach ($sectionmods as $modnumber) {
            if (empty($mods[$modnumber])) {
                continue;
            }
            $mod = $mods[$modnumber];
            if ($ismoving and $mod->id == $USER->activitycopy) {
                // do not display moving mod
                continue;
            }
            if (isset($modinfo->cms[$modnumber])) {
                if (!$modinfo->cms[$modnumber]->uservisible) {
                    // visibility shortcut
                    continue;
                }
            } else {
                if (!file_exists("{$CFG->dirroot}/mod/{$mod->modname}/lib.php")) {
                    // module not installed
                    continue;
                }
                if (!coursemodule_visible_for_user($mod)) {
                    // full visibility check
                    continue;
                }
            }
            // The magic! ... if indent == 1 then ... hide module
            //            if ($mod->indent == 1) {
            //                $hiddemodule = 'hidden';
            //            } else {
            //                $hiddemodule = '';
            //            }
            echo '<li class="activity ' . $mod->modname . ' ' . $hiddemodule . '" id="module-' . $modnumber . '">';
            // Unique ID
            if ($ismoving) {
                echo '<a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&amp;sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a><br />
                     ';
            }
            if ($mod->indent) {
                print_spacer(12, 20 * $mod->indent, false);
            }
            $extra = '';
            if (!empty($modinfo->cms[$modnumber]->extra)) {
                $extra = $modinfo->cms[$modnumber]->extra;
            }
            if ($mod->modname == "label") {
                echo "<span class=\"";
                if (!$mod->visible) {
                    echo 'dimmed_text';
                } else {
                    echo 'label';
                }
                echo '">';
                echo format_text($extra, FORMAT_HTML, $labelformatoptions);
                echo "</span>";
                if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
                    if (!isset($groupings)) {
                        $groupings = groups_get_all_groupings($course->id);
                    }
                    echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>';
                }
            } else {
                // Normal activity
                $instancename = format_string($modinfo->cms[$modnumber]->name, true, $course->id);
                if (!empty($modinfo->cms[$modnumber]->icon)) {
                    $icon = "{$CFG->pixpath}/" . $modinfo->cms[$modnumber]->icon;
                } else {
                    $icon = "{$CFG->modpixpath}/{$mod->modname}/icon.gif";
                }
                //Accessibility: for files get description via icon.
                $altname = '';
                if ('resource' == $mod->modname) {
                    if (!empty($modinfo->cms[$modnumber]->icon)) {
                        $possaltname = $modinfo->cms[$modnumber]->icon;
                        $mimetype = mimeinfo_from_icon('type', $possaltname);
                        $altname = get_mimetype_description($mimetype);
                    } else {
                        $altname = $mod->modfullname;
                    }
                } else {
                    $altname = $mod->modfullname;
                }
                // Avoid unnecessary duplication.
                if (false !== stripos($instancename, $altname)) {
                    $altname = '';
                }
                // File type after name, for alphabetic lists (screen reader).
                if ($altname) {
                    $altname = get_accesshide(' ' . $altname);
                }
                $linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
                if ($mod->modname != 'data') {
                    echo '<a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . $instancename . $altname . '</span></a>';
                }
                //echo " $mod->modname ";
                // Special DBLISTVIEW magic ... show summry from resource and blog's 200 chars from each post OUBlog (nadavkav)
                if ($mod->modname == 'resource') {
                    $article = get_record('resource', 'id', $mod->instance);
                    //print_r($article );
                    echo "{$article->summary}";
                }
                if ($mod->modname == 'data') {
                    require_once $CFG->dirroot . '/mod/data/lib.php';
                    if (!($data = get_record('data', 'id', $mod->instance))) {
                        //error('Course module is incorrect');
                    }
                    $sort = 0;
                    $what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname ';
                    $count = ' COUNT(DISTINCT c.recordid) ';
                    $tables = $CFG->prefix . 'data_content c,' . $CFG->prefix . 'data_records r,' . $CFG->prefix . 'data_content cs, ' . $CFG->prefix . 'user u ';
                    $where = 'WHERE c.recordid = r.id AND r.dataid = ' . $data->id . ' AND r.userid = u.id ';
                    $sortorder = ' ORDER BY r.id ASC ';
                    $searchselect = '';
                    // If requiredentries is not reached, only show current user's entries
                    //if (!$requiredentries_allowed) {
                    //    $where .= ' AND u.id = ' . $USER->id;
                    //}
                    /// To actually fetch the records
                    //$fromsql    = "FROM $tables $advtables $where $advwhere $groupselect $approveselect $searchselect $advsearchselect";
                    $fromsql = "FROM {$tables} {$where} ";
                    $sqlselect = "SELECT {$what} {$fromsql} {$sortorder}";
                    /// Get the actual records
                    if (!($records = get_records_sql($sqlselect))) {
                        // Nothing to show!
                    }
                    if (empty($data->listtemplate)) {
                        //notify(get_string('nolisttemplate','data'));
                        //data_generate_default_template($data, 'listtemplate', 0, false, false);
                    }
                    echo $data->listtemplateheader;
                    data_print_template('listtemplate', $records, $data);
                    echo $data->listtemplatefooter;
                    //print_r($article );
                    //echo "$article->summary";
                    echo '<hr/><a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . get_string('more', 'format_dblistview') . '</span></a>';
                    if (!empty($data->csstemplate)) {
                        echo '<style>' . $data->csstemplate . '</style>';
                    }
                }
                if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
                    if (!isset($groupings)) {
                        $groupings = groups_get_all_groupings($course->id);
                    }
                    echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>';
                }
            }
            if ($usetracking && $mod->modname == 'forum') {
                if ($unread = forum_tp_count_forum_unread_posts($mod, $course)) {
                    echo '<span class="unread"> <a href="' . $CFG->wwwroot . '/mod/forum/view.php?id=' . $mod->id . '">';
                    if ($unread == 1) {
                        echo $strunreadpostsone;
                    } else {
                        print_string('unreadpostsnumber', 'forum', $unread);
                    }
                    echo '</a></span>';
                }
            }
            if ($isediting) {
                // TODO: we must define this as mod property!
                if ($groupbuttons and $mod->modname != 'label' and $mod->modname != 'resource' and $mod->modname != 'glossary') {
                    if (!($mod->groupmodelink = $groupbuttonslink)) {
                        $mod->groupmode = $course->groupmode;
                    }
                } else {
                    $mod->groupmode = false;
                }
                echo '&nbsp;&nbsp;';
                echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section);
            }
            echo "</li>\n";
        }
    } elseif ($ismoving) {
        echo "<ul class=\"section\">\n";
    }
    if ($ismoving) {
        echo '<li><a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&amp;sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a></li>
             ';
    }
    if (!empty($section->sequence) || $ismoving) {
        echo "</ul><!--class='section'-->\n\n";
    }
}