/** * Returns the path to the cached rss feed contents. Creates/updates the cache if necessary. * The RSS feed content is a course search result. * @param array $args the arguments received in the url * $args[0] => context id = 2 (Front page) - not used * $args[1] => token * $args[2] => module name (it was needed by the rss/file.php to call this function) - not used * $args[3] => downloadable - PARAM_INT * $args[4] => audience - PARAM_ALPHA * $args[5] => educationallevel - PARAM_ALPHA * $args[6] => subject - PARAM_ALPHA * $args[7] => licence - PARAM_ALPHA * $args[8] => language - PARAM_ALPHANUMEXT * $args[9] => search - PARAM_TEXT (url encoded) * $args[10] => orderby - PARAM_ALPHA * @return string the full path to the cached RSS feed directory. Null if there is a problem. */ function hub_rss_get_feed($context, $args) { global $CFG, $DB; require_once $CFG->dirroot . '/local/hub/lib.php'; //are RSS feeds enabled? $enablerssfeeds = get_config('local_hub', 'enablerssfeeds'); if (empty($enablerssfeeds)) { debugging('DISABLED (module configuration)'); return null; } //check capabilities if (!has_capability('local/hub:view', $context)) { return null; } //TODO: cache $filename = 'rsssearch_' . $args[3] . '_' . $args[4] . '_' . $args[5] . '_' . $args[6] . '_' . $args[7] . '_' . $args[8] . '_' . $args[9] . '_' . $args[10]; $cachedfilepath = rss_get_file_full_name('local_hub', $filename); //get the courses from the search if ($args[7] != 'all') { $options['licenceshortname'] = $args[7]; } if ($args[6] != 'all') { $options['subject'] = $args[6]; } if ($args[4] != 'all') { $options['audience'] = $args[4]; } if ($args[5] != 'all') { $options['educationallevel'] = $args[5]; } if ($args[8] != 'all') { $options['language'] = $args[8]; } if ($args[3] != 'all') { $options['downloadable'] = $args[3]; $options['enrollable'] = !$args[3]; } else { $options['downloadable'] = true; $options['enrollable'] = true; } $options['search'] = empty($args[9]) ? '' : urldecode($args[9]); //if the RSS invisible secret is passed as parameter, display not visible course $rsssecret = get_config('local_hub', 'rsssecret'); if (!empty($rsssecret) and $rsssecret == optional_param('rsssecret', false, PARAM_RAW)) { $options['visibility'] = COURSEVISIBILITY_NOTVISIBLE; } else { $options['visibility'] = COURSEVISIBILITY_VISIBLE; } //order by switch ($args[10]) { case 'newest': $options['orderby'] = 'timemodified DESC'; break; case 'eldest': $options['orderby'] = 'timemodified ASC'; break; case 'publisher': $options['orderby'] = 'publishername ASC'; break; case 'fullname': $options['orderby'] = 'fullname ASC'; break; case 'ratingaverage': $options['orderby'] = 'ratingaverage DESC'; break; default: break; } $hub = new local_hub(); $courses = $hub->get_courses($options, 0, 10); //generate the information for rss $rssfeedinfo = local_hub_rss_generate_feed_info($courses); //generate the rss content require_once $CFG->libdir . "/rsslib.php"; //First the RSS header $searchurl = new moodle_url($CFG->wwwroot . '/', array('downloadable' => $args[3], 'audience' => $args[4], 'educationallevel' => $args[5], 'subject' => $args[6], 'licence' => $args[7], 'language' => $args[8], 'search' => $args[9], 'orderby' => $args[10], 'submitbutton' => 'Search+for+courses')); $rsscontent = rss_standard_header(get_config('local_hub', 'name'), $searchurl->out(), get_string('hubcoursessearch', 'local_hub')); $rsscontent .= rss_add_items($rssfeedinfo); //Now the RSS footer $rsscontent .= rss_standard_footer(); if (!empty($rsscontent)) { rss_save_file('local_hub', $filename, $rsscontent); } //return the path to the cached version return $cachedfilepath; }
$fromformdata['educationallevel'] = optional_param('educationallevel', 'all', PARAM_ALPHANUMEXT); $fromformdata['visibility'] = optional_param('visibility', COURSEVISIBILITY_NOTVISIBLE, PARAM_ALPHANUMEXT); $fromformdata['downloadable'] = optional_param('downloadable', 'all', PARAM_ALPHANUM); $fromformdata['orderby'] = optional_param('orderby', 'newest', PARAM_ALPHA); $fromformdata['adminform'] = 1; $fromformdata['search'] = $search; $coursesearchform = new course_search_form('', $fromformdata); $fromform = $coursesearchform->get_data(); $coursesearchform->set_data($fromformdata); $fromform = (object) $fromformdata; /// COURSE DATA if (!empty($courseid)) { $options['ids'] = array($courseid); $options['downloadable'] = true; $options['enrollable'] = true; $courses = $hub->get_courses($options); unset($options['ids']); unset($options['downloadable']); unset($options['enrollable']); $coursetotal = 1; } else { if (!empty($fromform->coverage)) { $options['coverage'] = $fromform->coverage; } if ($fromform->licence != 'all') { $options['licenceshortname'] = $fromform->licence; } if ($fromform->subject != 'all') { $options['subject'] = $fromform->subject; } if ($fromform->audience != 'all') {
/** * Get courses * @return array courses */ public static function get_courses($search, $downloadable, $enrollable, $options = array()) { global $DB, $CFG, $USER; // Ensure the current user is allowed to run this function $context = context_system::instance(); self::validate_context($context); require_capability('local/hub:view', $context); $params = self::validate_parameters(self::get_courses_parameters(), array('search' => $search, 'downloadable' => $downloadable, 'enrollable' => $enrollable, 'options' => $options)); //retieve siteid $onlyvisible = true; $token = optional_param('wstoken', '', PARAM_ALPHANUM); $localhub = new local_hub(); $communication = $localhub->get_communication(WSSERVER, REGISTEREDSITE, null, $token); if (!empty($communication)) { $siteurl = $communication->remoteurl; if (!empty($siteurl)) { $site = $localhub->get_site_by_url($siteurl); if (!empty($site) and !empty($params['options']['allsitecourses'])) { $params['options']['siteid'] = $site->id; $onlyvisible = false; } } } $cleanedoptions = $params['options']; $cleanedoptions['onlyvisible'] = $onlyvisible; $cleanedoptions['search'] = $params['search']; $cleanedoptions['downloadable'] = $params['downloadable']; $cleanedoptions['enrollable'] = $params['enrollable']; //sort method if (!empty($params['options']['orderby'])) { switch ($params['options']['orderby']) { case 'newest': $cleanedoptions['orderby'] = 'timemodified DESC'; break; case 'eldest': $cleanedoptions['orderby'] = 'timemodified ASC'; break; case 'publisher': $cleanedoptions['orderby'] = 'publishername ASC'; break; case 'fullname': $cleanedoptions['orderby'] = 'fullname ASC'; break; case 'ratingaverage': $cleanedoptions['orderby'] = 'ratingaverage DESC'; break; default: unset($cleanedoptions['orderby']); break; } } //retrieve the range of courses to return $maxcourses = get_config('local_hub', 'maxwscourseresult'); if (empty($maxcourses)) { throw new moodle_exception('nocoursereturn', 'local_hub'); } $hub = new local_hub(); //the site is requesting all his own course if (!empty($params['options']['siteid'])) { $maxcourses = 0; $limitfrom = 0; } else { //the site is doing a normal courses request (not focussed on its own courses) //the hub server limit the return number of course $limitfrom = isset($params['options']['givememore']) ? $params['options']['givememore'] : 0; } $courses = $hub->get_courses($cleanedoptions, $limitfrom, $maxcourses); $coursetotal = $hub->get_courses($cleanedoptions, 0, 0, true); //load ratings and comments if (!empty($courses)) { require_once $CFG->dirroot . '/comment/lib.php'; } //create result $coursesresult = array(); foreach ($courses as $course) { $courseinfo = array(); $courseinfo['id'] = $course->id; $courseinfo['fullname'] = $course->fullname; $courseinfo['shortname'] = $course->shortname; $courseinfo['description'] = $course->description; $courseinfo['language'] = $course->language; $courseinfo['publishername'] = $course->publishername; //return publisher email, privacy and site course id // only if the request has been done by the site if (!empty($site) and $course->siteid == $site->id) { $courseinfo['publisheremail'] = $course->publisheremail; $courseinfo['privacy'] = $course->privacy; $courseinfo['sitecourseid'] = $course->sitecourseid; } $courseinfo['contributornames'] = $course->contributornames; $courseinfo['coverage'] = $course->coverage; $courseinfo['creatorname'] = $course->creatorname; $courseinfo['licenceshortname'] = $course->licenceshortname; $courseinfo['subject'] = $course->subject; $courseinfo['audience'] = $course->audience; $courseinfo['educationallevel'] = $course->educationallevel; $courseinfo['creatornotes'] = $course->creatornotes; $courseinfo['creatornotesformat'] = $course->creatornotesformat; $courseinfo['enrollable'] = $course->enrollable; $courseinfo['screenshots'] = $course->screenshots; $courseinfo['timemodified'] = $course->timemodified; if (!empty($course->courseurl)) { $courseinfo['courseurl'] = $course->courseurl; } else { if (!empty($course->demourl)) { //courseurl is mandatory, demo url can be blank $courseinfo['demourl'] = $course->demourl; } else { $courseurl = new moodle_url($CFG->wwwroot, array('sesskey' => sesskey(), 'redirectcourseid' => $course->id)); $courseinfo['demourl'] = $courseurl->out(false); } } //outcomes if (!empty($course->outcomes)) { foreach ($course->outcomes as $outcome) { $courseinfo['outcomes'][] = array('fullname' => $outcome); } } //get content $contents = $hub->get_course_contents($course->id); if (!empty($contents)) { foreach ($contents as $content) { $tmpcontent = array(); $tmpcontent['moduletype'] = $content->moduletype; $tmpcontent['modulename'] = $content->modulename; $tmpcontent['contentcount'] = $content->contentcount; $courseinfo['contents'][] = $tmpcontent; } } //set ratings if ($course->ratingcount) { //$courseinfo['rating']['aggregate'] = (float) $course->ratingaverage; //the ratings has been changed from scale 0 to 10 to a "Featured" award $courseinfo['rating']['aggregate'] = HUB_COURSE_RATING_SCALE; } $courseinfo['rating']['count'] = (int) $course->ratingcount; $courseinfo['rating']['scaleid'] = HUB_COURSE_RATING_SCALE; //get comments $commentoptions->context = context_course::instance(SITEID); $commentoptions->area = 'local_hub'; $commentoptions->itemid = $course->id; $commentoptions->showcount = true; $commentoptions->component = 'local_hub'; $course->comment = new comment($commentoptions); $comments = $course->comment->get_comments(); foreach ($comments as $comment) { $coursecomment = array(); $coursecomment['comment'] = clean_param($comment->content, PARAM_TEXT); $coursecomment['commentator'] = clean_param($comment->fullname, PARAM_TEXT); $coursecomment['date'] = $comment->timecreated; $courseinfo['comments'][] = $coursecomment; } //get backup size $returnthecourse = true; if (!$course->enrollable) { if ($hub->backup_exits($course->id)) { $courseinfo['backupsize'] = $hub->get_backup_size($course->id); } else { // We don't return the course when backup file is not found. $returnthecourse = false; } } if ($returnthecourse) { $coursesresult[] = $courseinfo; } } return array('courses' => $coursesresult, 'coursetotal' => $coursetotal); }