hub MDL-19309 new site registration form + course publication + community block

This commit is contained in:
jerome mouneyrac 2010-05-01 05:05:55 +00:00
parent 7b4c6d34b8
commit 07ab0c80ec
36 changed files with 3208 additions and 21 deletions

View file

@ -5437,7 +5437,7 @@ function admin_get_root($reload=false, $requirefulltree=true) {
$ADMIN->loaded = true;
}
return $ADMIN;
}
@ -5851,6 +5851,7 @@ function print_plugin_tables() {
'calendar_month',
'calendar_upcoming',
'comments',
'community',
'course_list',
'course_summary',
'glossary_random',

View file

@ -1537,6 +1537,16 @@ $capabilities = array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
),
'moodle/course:publish' => array(
'riskbitmask' => RISK_SPAM | RISK_PERSONAL,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array(
'manager' => CAP_ALLOW
)
),
'moodle/course:markcomplete' => array(
'captype' => 'write',

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20100429" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20100430" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
@ -2539,7 +2539,7 @@
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="license" COMMENT="store licenses used by moodle" PREVIOUS="rating" NEXT="backup_controllers">
<TABLE NAME="license" COMMENT="store licenses used by moodle" PREVIOUS="rating" NEXT="registration_hubs">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="shortname"/>
<FIELD NAME="shortname" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" PREVIOUS="id" NEXT="fullname"/>
@ -2552,7 +2552,19 @@
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="backup_controllers" COMMENT="To store the backup_controllers as they are used" PREVIOUS="license" NEXT="backup_ids_template">
<TABLE NAME="registration_hubs" COMMENT="hub where the site is registered on with their associated token" PREVIOUS="license" NEXT="backup_controllers">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="token"/>
<FIELD NAME="token" TYPE="char" LENGTH="40" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="hubname"/>
<FIELD NAME="hubname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="token" NEXT="huburl"/>
<FIELD NAME="huburl" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="hubname" NEXT="confirmed"/>
<FIELD NAME="confirmed" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="huburl"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="backup_controllers" COMMENT="To store the backup_controllers as they are used" PREVIOUS="registration_hubs" NEXT="backup_ids_template">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="backupid"/>
<FIELD NAME="backupid" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false" COMMENT="unique id of the backup" PREVIOUS="id" NEXT="type"/>
@ -2596,4 +2608,4 @@
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>

View file

@ -2984,7 +2984,7 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
upgrade_main_savepoint($result, 2010031900);
}
if ($result && $oldversion < 2010032400) {
// Upgrade all of those using the standardold theme to the use the standard
// theme instead
@ -3697,7 +3697,7 @@ AND EXISTS (SELECT 'x'
upgrade_main_savepoint($result, 2010042802);
}
if ($result && $oldversion < 2010043000) { // Adding new course completion feature
/// Add course completion tables
@ -3857,6 +3857,30 @@ AND EXISTS (SELECT 'x'
upgrade_main_savepoint($result, 2010043000);
}
if ($result && $oldversion < 2010043001) {
/// Define table registration_hubs to be created
$table = new xmldb_table('registration_hubs');
/// Adding fields to table registration_hubs
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('token', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null);
$table->add_field('hubname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('huburl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('confirmed', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
/// Adding keys to table registration_hubs
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
/// Conditionally launch create table for registration_hubs
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
/// Main savepoint reached
upgrade_main_savepoint($result, 2010043001);
}
return $result;
}

340
lib/hublib.php Normal file
View file

@ -0,0 +1,340 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
*
* Hub library
*
* @package hub
* @copyright 2010 Moodle Pty Ltd (http://moodle.com)
* @author Jerome Mouneyrac
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
///// IMAGE SIZES /////
/**
* SITEIMAGEHEIGHT - the maximum height size of a site logo
*/
define('SITEIMAGEHEIGHT', 150);
/**
* SITEIMAGEWIDTH - the maximum width size of a site logo
*/
define('SITEIMAGEWIDTH', 150);
///// MOODLE.ORG URLS //////
/**
* Hub directory url (should be moodle.org)
*/
//define('HUBDIRECTORYURL', "http://jerome.moodle.local/Moodle_HEAD_hubdirectory/moodle");
define('HUBDIRECTORYURL', "http://hubdirectory.moodle.org");
/**
* Moodle.org url (should be moodle.org)
*/
//define('MOODLEORGHUBURL', "http://jerome.moodle.local/Moodle_HEAD_secure_hub/moodle");
define('MOODLEORGHUBURL', "http://hub.moodle.org");
//// SITE PRIVACY /////
/**
* Site privacy: private
*/
define('SITENOTPUBLISHED', 'notdisplayed');
/**
* Site privacy: public
*/
define('SITENAMEPUBLISHED', 'named');
/**
* Site privacy: public and global
*/
define('SITELINKPUBLISHED', 'linked');
//// Communication /////
/**
* Hub server
*/
define('HUB', 'hub');
/**
* Registered site
*/
define('REGISTEREDSITE', 'site');
/**
* Public site
*/
define('PUBLICSITE', 'publicsite');
/**
* Hub directory
*/
define('HUBDIRECTORY', 'hubdirectory');
/**
* WS server
*/
define('WSSERVER', 'server');
/**
* WS client
*/
define('WSCLIENT', 'client');
//// AUDIENCE ////
/**
* Audience: educators
*/
define('AUDIENCE_EDUCATORS', 'educators');
/**
* Audience: students
*/
define('AUDIENCE_STUDENTS', 'students');
/**
* Audience: admins
*/
define('AUDIENCE_ADMINS', 'admins');
///// EDUCATIONAL LEVEL /////
/**
* Educational level: primary
*/
define('EDULEVEL_PRIMARY', 'primary');
/**
* Educational level: secondary
*/
define('EDULEVEL_SECONDARY', 'secondary');
/**
* Educational level: tertiary
*/
define('EDULEVEL_TERTIARY', 'tertiary');
/**
* Educational level: government
*/
define('EDULEVEL_GOVERNMENT', 'government');
/**
* Educational level: association
*/
define('EDULEVEL_ASSOCIATION', 'association');
/**
* Educational level: corporate
*/
define('EDULEVEL_CORPORATE', 'corporate');
/**
* Educational level: other
*/
define('EDULEVEL_OTHER', 'other');
///// FILE TYPES /////
/**
* FILE TYPE: SCREENSHOTS
*/
define('SCREENSHOT_FILE_TYPE', 'screenshot');
/**
* FILE TYPE: BACKUP
*/
define('BACKUP_FILE_TYPE', 'backup');
class hub {
///////////////////////////
/// DB Facade functions //
///////////////////////////
public function add_registeredhub($hub) {
global $DB;
$id = $DB->insert_record('registration_hubs', $hub);
return $id;
}
public function get_registeredhub($huburl = null, $token = null) {
global $DB;
$params = array();
if (!empty($huburl)) {
$params['huburl'] = $huburl;
}
if (!empty($token)) {
$params['token'] = $token;
}
$token = $DB->get_record('registration_hubs',$params);
return $token;
}
public function update_registeredhub($communication) {
global $DB;
$DB->update_record('registration_hubs', $communication);
}
///////////////////////////
/// Library functions ///
///////////////////////////
/**
* Return site information for a specific hub
* @param string $huburl
* @return array site info
*/
public function get_site_info($huburl) {
global $CFG, $DB;
$siteinfo = array();
$cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT);
$siteinfo['name'] = get_config('hub', 'site_name_'.$cleanhuburl);
$siteinfo['description'] = get_config('hub', 'site_description_'.$cleanhuburl);
$siteinfo['contactname'] = get_config('hub', 'site_contactname_'.$cleanhuburl);
$siteinfo['contactemail'] = get_config('hub', 'site_contactemail_'.$cleanhuburl);
$siteinfo['contactphone'] = get_config('hub', 'site_contactphone_'.$cleanhuburl);
$siteinfo['imageurl'] = get_config('hub', 'site_imageurl_'.$cleanhuburl);
$siteinfo['privacy'] = get_config('hub', 'site_privacy_'.$cleanhuburl);
$siteinfo['street'] = get_config('hub', 'site_address_'.$cleanhuburl);
$siteinfo['regioncode'] = get_config('hub', 'site_region_'.$cleanhuburl);
$siteinfo['countrycode'] = get_config('hub', 'site_country_'.$cleanhuburl);
$siteinfo['geolocation'] = get_config('hub', 'site_geolocation_'.$cleanhuburl);
$siteinfo['contactable'] = get_config('hub', 'site_contactable_'.$cleanhuburl);
$siteinfo['emailalert'] = get_config('hub', 'site_emailalert_'.$cleanhuburl);
if (get_config('hub', 'site_coursesnumber_'.$cleanhuburl) == -1) {
$coursecount = -1;
} else {
$coursecount = $DB->count_records('course')-1;
}
$siteinfo['courses'] = $coursecount;
if (get_config('hub', 'site_usersnumber_'.$cleanhuburl) == -1) {
$usercount = -1;
} else {
$usercount = $DB->count_records('user', array('deleted'=>0));
}
$siteinfo['users'] = $usercount;
if (get_config('hub', 'site_roleassignmentsnumber_'.$cleanhuburl) == -1) {
$roleassigncount = -1;
} else {
$roleassigncount = $DB->count_records('role_assignments');
}
$siteinfo['enrolments'] = $roleassigncount;
if (get_config('hub', 'site_postsnumber_'.$cleanhuburl) == -1) {
$postcount = -1;
} else {
$postcount = $DB->count_records('forum_posts');
}
$siteinfo['posts'] = $postcount;
if (get_config('hub', 'site_questionsnumber_'.$cleanhuburl) == -1) {
$questioncount = -1;
} else {
$questioncount = $DB->count_records('question');
}
$siteinfo['questions'] = $questioncount;
if (get_config('hub', 'site_resourcesnumber_'.$cleanhuburl) == -1) {
$resourcecount = -1;
} else {
$resourcecount = $DB->count_records('resource');
}
$siteinfo['resources'] = $resourcecount;
//TODO
require_once($CFG->dirroot."/course/lib.php");
if (get_config('hub', 'site_participantnumberaverage_'.$cleanhuburl) == -1) {
$participantnumberaverage = -1;
} else {
$participantnumberaverage = average_number_of_participants();
}
$siteinfo['participantnumberaverage'] = $participantnumberaverage;
if (get_config('hub', 'site_modulenumberaverage_'.$cleanhuburl) == -1) {
$modulenumberaverage = -1;
} else {
$modulenumberaverage = average_number_of_courses_modules();
}
$siteinfo['modulenumberaverage'] = $modulenumberaverage;
$siteinfo['language'] = current_language();
$siteinfo['moodleversion'] = $CFG->version;
$siteinfo['moodlerelease'] = $CFG->release;
$siteinfo['url'] = $CFG->wwwroot;
return $siteinfo;
}
/**
* Retrieve the site privacy string matching the define value
* @param string $privacy must match the define into moodlelib.php
* @return string
*/
public function get_site_privacy_string($privacy) {
switch ($privacy) {
case SITENOTPUBLISHED:
$privacystring = get_string('publicdirectory0');
break;
case SITENAMEPUBLISHED:
$privacystring = get_string('publicdirectory1');
break;
case SITELINKPUBLISHED:
$privacystring = get_string('publicdirectory2');
break;
}
if (empty($privacystring)) {
throw new moodle_exception('unknownprivacy');
}
return $privacystring;
}
/**
* Return all hubs where the site is registered on
*/
public function get_registered_on_hubs() {
global $DB;
$hubs = $DB->get_records('registration_hubs', array());
return $hubs;
}
}

View file

@ -935,7 +935,7 @@ function set_config($name, $value, $plugin=NULL) {
* @global object
* @param string $plugin default NULL
* @param string $name default NULL
* @return mixed hash-like object or single value
* @return mixed hash-like object or single value, return false no config found
*/
function get_config($plugin=NULL, $name=NULL) {
global $CFG, $DB;
@ -3449,13 +3449,13 @@ function delete_user($user) {
require_once($CFG->libdir.'/grouplib.php');
require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->dirroot.'/message/lib.php');
// delete all grades - backup is kept in grade_grades_history table
if ($grades = grade_grade::fetch_all(array('userid'=>$user->id))) {
foreach ($grades as $grade) {
$grade->delete('userdelete');
// delete all grades - backup is kept in grade_grades_history table
if ($grades = grade_grade::fetch_all(array('userid'=>$user->id))) {
foreach ($grades as $grade) {
$grade->delete('userdelete');
}
}
}
//move unread messages from this user to read
message_move_userfrom_unread2read($user->id);
@ -6913,6 +6913,7 @@ function get_core_subsystems() {
'debug' => NULL,
'dock' => NULL,
'editor' => 'lib/editor',
'edufields' => NULL,
'error' => NULL,
'filepicker' => NULL,
'filters' => NULL,
@ -6922,6 +6923,7 @@ function get_core_subsystems() {
'grades' => 'grade',
'group' => 'group',
'help' => NULL,
'hub' => NULL,
'imscc' => NULL,
'install' => NULL,
'iso6392' => NULL,
@ -6936,8 +6938,10 @@ function get_core_subsystems() {
'pagetype' => NULL,
'pix' => NULL,
'portfolio' => 'portfolio',
'publish' => 'course/publish',
'question' => 'question',
'rating' => 'rating',
'register' => 'admin/registration',
'repository' => 'repository',
'role' => $CFG->admin.'/role',
'simpletest' => NULL,
@ -9448,7 +9452,7 @@ function is_primary_admin($userid){
}
}
/**
/**
* Returns the site identifier
*
* @global object

View file

@ -2383,6 +2383,12 @@ class settings_navigation extends navigation_node {
$coursenode->add(get_string('import'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/restore', ''));
}
// Publish course on a hub
if (has_capability('moodle/course:publish', $coursecontext)) {
$url = new moodle_url('/course/publish/index.php', array('id'=>$course->id));
$coursenode->add(get_string('publish'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/publish', ''));
}
// Reset this course
if (has_capability('moodle/course:reset', $coursecontext)) {
$url = new moodle_url('/course/reset.php', array('id'=>$course->id));