mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
hub MDL-19309 new site registration form + course publication + community block
This commit is contained in:
parent
7b4c6d34b8
commit
07ab0c80ec
36 changed files with 3208 additions and 21 deletions
66
blocks/community/block_community.php
Normal file
66
blocks/community/block_community.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?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/>.
|
||||
|
||||
/*
|
||||
* @package blocks
|
||||
* @subpackage community
|
||||
* @author Jerome Mouneyrac <jerome@mouneyrac.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
|
||||
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
|
||||
*
|
||||
* The community block
|
||||
*/
|
||||
|
||||
require_once('locallib.php');
|
||||
|
||||
class block_community extends block_list {
|
||||
function init() {
|
||||
$this->title = get_string('pluginname', 'block_community');
|
||||
$this->version = 2010042701;
|
||||
}
|
||||
|
||||
function get_content() {
|
||||
|
||||
global $CFG, $OUTPUT, $USER;
|
||||
|
||||
$this->content = new stdClass();
|
||||
$this->content->items = array();
|
||||
$this->content->icons = array();
|
||||
$this->content->footer = '';
|
||||
|
||||
$this->content->items[] = '<a href='.$CFG->wwwroot.'/blocks/community/communitycourse.php?add=true>'.get_string('addcourse', 'block_community').'</a>';
|
||||
$this->content->icons[] = '<img src="'.$OUTPUT->pix_url('i/group') . '" class="icon" alt="" />';
|
||||
|
||||
$community = new community();
|
||||
$courses = $community->get_community_courses($USER->id);
|
||||
$this->content->items[] = '';
|
||||
$this->content->icons[] = '';
|
||||
$this->content->items[] = get_string('mycommunities', 'block_community');
|
||||
$this->content->icons[] = '';
|
||||
foreach ($courses as $course) {
|
||||
$this->content->items[] = '<a href='.$course->courseurl.'>'.$course->coursename.'</a>';
|
||||
$this->content->icons[] = '';
|
||||
}
|
||||
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
function applicable_formats() {
|
||||
return array('all' => true);
|
||||
}
|
||||
|
||||
}
|
||||
|
89
blocks/community/communitycourse.php
Normal file
89
blocks/community/communitycourse.php
Normal file
|
@ -0,0 +1,89 @@
|
|||
<?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/>.
|
||||
|
||||
/*
|
||||
* @package blocks
|
||||
* @subpackage community
|
||||
* @author Jerome Mouneyrac <jerome@mouneyrac.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
|
||||
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
|
||||
*
|
||||
* This page display the community course search form.
|
||||
* It also handles adding a course to the community block.
|
||||
* It also handles downloading a course template.
|
||||
*/
|
||||
|
||||
require('../../config.php');
|
||||
require_once($CFG->dirroot.'/blocks/community/locallib.php');
|
||||
require_once($CFG->dirroot.'/blocks/community/forms.php');
|
||||
|
||||
require_login();
|
||||
|
||||
$PAGE->set_url('/blocks/community/communitycourse.php');
|
||||
$PAGE->set_heading($SITE->fullname);
|
||||
$PAGE->set_pagelayout('course');
|
||||
$PAGE->set_title(get_string('searchcourse', 'block_community'));
|
||||
$PAGE->navbar->ignore_active(true);
|
||||
$PAGE->navbar->add(get_string('searchcourse', 'block_community'));
|
||||
|
||||
$search = optional_param('search', '', PARAM_TEXT);
|
||||
|
||||
$community = new community();
|
||||
|
||||
/// Check if the page has been called with trust argument
|
||||
$add = optional_param('add', -1, PARAM_INTEGER);
|
||||
$confirm = optional_param('confirmed', false, PARAM_INTEGER);
|
||||
if ($add != -1 and $confirm and confirm_sesskey()) {
|
||||
$course = new stdClass();
|
||||
$course->name = optional_param('coursefullname', '', PARAM_TEXT);
|
||||
$course->description = optional_param('coursedescription', '', PARAM_TEXT);
|
||||
$course->url = optional_param('courseurl', '', PARAM_URL);
|
||||
$course->imageurl = optional_param('courseimageurl', '', PARAM_URL);
|
||||
$community->add_community_course($course, $USER->id);
|
||||
}
|
||||
|
||||
/// Download
|
||||
$huburl = optional_param('huburl', false, PARAM_URL);
|
||||
$download = optional_param('download', -1, PARAM_INTEGER);
|
||||
$courseid = optional_param('courseid', '', PARAM_INTEGER);
|
||||
if ($download != -1 and !empty($courseid) and confirm_sesskey()) {
|
||||
$community->get_community_course_backup($courseid, $huburl);
|
||||
}
|
||||
|
||||
$renderer = $PAGE->get_renderer('block_community');
|
||||
|
||||
//forms
|
||||
$hubselectorform = new community_hub_search_form('', array('search' => $search));
|
||||
$fromform = $hubselectorform->get_data();
|
||||
|
||||
//Retrieve courses by web service
|
||||
$courses = array();
|
||||
if (!empty($fromform)) {
|
||||
$downloadable = optional_param('downloadable', false, PARAM_INTEGER);
|
||||
$function = 'hub_get_courses';
|
||||
$params = array($search, $downloadable);
|
||||
$serverurl = $huburl."/local/hub/webservice/webservices.php";
|
||||
require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
|
||||
$xmlrpcclient = new webservice_xmlrpc_client();
|
||||
$courses = $xmlrpcclient->call($serverurl, 'publichub', $function, $params);
|
||||
}
|
||||
|
||||
// OUTPUT
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('addcommunitycourse', 'block_community'), 3, 'main');
|
||||
$hubselectorform->display();
|
||||
echo $renderer->course_list($courses, $huburl);
|
||||
echo $OUTPUT->footer();
|
21
blocks/community/db/install.xml
Normal file
21
blocks/community/db/install.xml
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="blocks/community/db" VERSION="20100428" COMMENT="XMLDB file for Moodle blocks/community"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
<TABLES>
|
||||
<TABLE NAME="block_community" COMMENT="Community block">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="userid"/>
|
||||
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="id" NEXT="coursename"/>
|
||||
<FIELD NAME="coursename" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="userid" NEXT="coursedescription"/>
|
||||
<FIELD NAME="coursedescription" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" PREVIOUS="coursename" NEXT="courseurl"/>
|
||||
<FIELD NAME="courseurl" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="coursedescription" NEXT="imageurl"/>
|
||||
<FIELD NAME="imageurl" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="courseurl"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
</XMLDB>
|
79
blocks/community/db/upgrade.php
Normal file
79
blocks/community/db/upgrade.php
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* This file keeps track of upgrades to the community block
|
||||
*
|
||||
* Sometimes, changes between versions involve alterations to database structures
|
||||
* and other major things that may break installations.
|
||||
*
|
||||
* The upgrade function in this file will attempt to perform all the necessary
|
||||
* actions to upgrade your older installtion to the current version.
|
||||
*
|
||||
* If there's something it cannot do itself, it will tell you what you need to do.
|
||||
*
|
||||
* The commands in here will all be database-neutral, using the methods of
|
||||
* database_manager class
|
||||
*
|
||||
* Please do not forget to use upgrade_set_timeout()
|
||||
* before any action that may take longer time to finish.
|
||||
*
|
||||
* @since 2.0
|
||||
* @package blocks
|
||||
* @copyright 2010 Jerome Mouneyrac
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $oldversion
|
||||
* @param object $block
|
||||
*/
|
||||
function xmldb_block_community_upgrade($oldversion) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
$result = true;
|
||||
|
||||
if ($result && $oldversion < 2010042701) {
|
||||
|
||||
/// Define table block_community to be created
|
||||
$table = new xmldb_table('block_community');
|
||||
|
||||
/// Adding fields to table block_community
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('coursename', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('coursedescription', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
|
||||
$table->add_field('courseurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('imageurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
|
||||
/// Adding keys to table block_community
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
|
||||
/// Conditionally launch create table for block_community
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
/// community savepoint reached
|
||||
upgrade_block_savepoint($result, 2010042701, 'community');
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
79
blocks/community/forms.php
Normal file
79
blocks/community/forms.php
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// This file is part of Moodle - http://moodle.org/ //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// //
|
||||
// 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/>. //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
* @package blocks
|
||||
* @subpackage community
|
||||
* @author Jerome Mouneyrac <jerome@mouneyrac.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
|
||||
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
|
||||
*
|
||||
* Form for community search
|
||||
*/
|
||||
|
||||
require_once($CFG->dirroot.'/lib/formslib.php');
|
||||
require_once($CFG->dirroot.'/lib/hublib.php');
|
||||
|
||||
class community_hub_search_form extends moodleform {
|
||||
|
||||
public function definition() {
|
||||
global $CFG;
|
||||
$strrequired = get_string('required');
|
||||
$mform =& $this->_form;
|
||||
$search = $this->_customdata['search'];
|
||||
$mform->addElement('header', 'site', get_string('search', 'block_community'));
|
||||
|
||||
//retrieve the hub list on the hub directory by web service
|
||||
$function = 'hubdirectory_get_hubs';
|
||||
$params = array();
|
||||
$serverurl = HUBDIRECTORYURL."/local/hubdirectory/webservice/webservices.php";
|
||||
require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
|
||||
$xmlrpcclient = new webservice_xmlrpc_client();
|
||||
$hubs = $xmlrpcclient->call($serverurl, 'publichubdirectory', $function, $params);
|
||||
|
||||
//Public hub list
|
||||
$options = array();
|
||||
foreach ($hubs as $hub) {
|
||||
//to not display a name longer than 100 character (too big)
|
||||
if (strlen($hub['name'])>100) {
|
||||
$hubname = substr($hub['name'],0, 100);
|
||||
$hubname = $hubname."...";
|
||||
} else {
|
||||
$hubname = $hub['name'];
|
||||
}
|
||||
$options[$hub['url']] = $hubname;
|
||||
$mform->addElement('hidden', clean_param($hub['url'], PARAM_ALPHANUMEXT), $hubname);
|
||||
}
|
||||
$mform->addElement('select', 'huburl', get_string('hub','block_community'),
|
||||
$options, array("size" => 15));
|
||||
$mform->addRule('huburl', $strrequired, 'required', null, 'client');
|
||||
|
||||
$options = array(0 => get_string('enrollable', 'block_community'),
|
||||
1 => get_string('downloadable', 'block_community'));
|
||||
$mform->addElement('select', 'downloadable', '',
|
||||
$options);
|
||||
|
||||
$mform->addElement('text','search' , get_string('search', 'block_community'));
|
||||
|
||||
$this->add_action_buttons(false, get_string('search', 'block_community'));
|
||||
}
|
||||
|
||||
}
|
44
blocks/community/lang/en/block_community.php
Normal file
44
blocks/community/lang/en/block_community.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* Strings for component 'block_community', language 'en', branch 'MOODLE_20_STABLE'
|
||||
*
|
||||
* @package block_community
|
||||
* @author Jerome Mouneyrac <jerome@mouneyrac.com>
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['addcommunitycourse'] = 'Add community course';
|
||||
$string['additionalcoursedesc'] = 'Contributors: {$a->contributornames} - Coverage: {$a->coverage} - Creator: {$a->creatorname} - Publisher: {$a->publishername} - Subject: {$a->subject}
|
||||
- Audience: {$a->audience} - Educational level: {$a->educationallevel}';
|
||||
$string['addcourse'] = 'Search';
|
||||
$string['coursedesc'] = 'Description';
|
||||
$string['courselang'] = 'Language';
|
||||
$string['coursename'] = 'Name';
|
||||
$string['download'] = 'Download';
|
||||
$string['downloadable'] = 'Downloadable';
|
||||
$string['downloadtemplate'] = 'Create course from template';
|
||||
$string['enrollable'] = 'Enrollable';
|
||||
$string['hub'] = 'hub';
|
||||
$string['mycommunities'] = 'My communities:';
|
||||
$string['nocourse'] = 'No courses found';
|
||||
$string['operation'] = 'Operation';
|
||||
$string['pluginname'] = 'Community';
|
||||
$string['search'] = 'Search';
|
||||
$string['searchcourse'] = 'Search community course';
|
73
blocks/community/locallib.php
Normal file
73
blocks/community/locallib.php
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?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/>.
|
||||
|
||||
/*
|
||||
* @package blocks
|
||||
* @subpackage community
|
||||
* @author Jerome Mouneyrac <jerome@mouneyrac.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
|
||||
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
|
||||
*
|
||||
* Community library
|
||||
*/
|
||||
|
||||
class community {
|
||||
|
||||
///////////////////////////
|
||||
/// DB Facade functions //
|
||||
///////////////////////////
|
||||
|
||||
/**
|
||||
* Add a community course
|
||||
* @param object $course
|
||||
* @param integer $userid
|
||||
*/
|
||||
public function add_community_course($course, $userid) {
|
||||
global $DB;
|
||||
$community->userid = $userid;
|
||||
$community->coursename = $course->name;
|
||||
$community->coursedescription = $course->description;
|
||||
$community->courseurl = $course->url;
|
||||
$community->imageurl = $course->imageurl;
|
||||
return $DB->insert_record('block_community', $community);
|
||||
}
|
||||
|
||||
/**
|
||||
Return all community courses of a user
|
||||
* @param integer $userid
|
||||
* @return array of course
|
||||
*/
|
||||
public function get_community_courses($userid) {
|
||||
global $DB;
|
||||
return $DB->get_records('block_community', array('userid' => $userid), 'coursename');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $courseid
|
||||
* @param <type> $huburl
|
||||
*/
|
||||
public function get_community_course_backup($courseid, $huburl) {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot. "/lib/filelib.php");
|
||||
require_once($CFG->dirroot. "/lib/hublib.php");
|
||||
$curl = new curl();
|
||||
$params['courseid'] = $courseid;
|
||||
$params['filetype'] = BACKUP_FILE_TYPE;
|
||||
$filecontent = $curl->get($huburl.'/local/hub/webservice/download.php', $params);
|
||||
}
|
||||
|
||||
}
|
127
blocks/community/renderer.php
Normal file
127
blocks/community/renderer.php
Normal file
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// This file is part of Moodle - http://moodle.org/ //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// //
|
||||
// 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/>. //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Block community renderer.
|
||||
* @package blocks
|
||||
* @subpackage community
|
||||
* @copyright 2010 Moodle Pty Ltd (http://moodle.com)
|
||||
* @author Jerome Mouneyrac
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class block_community_renderer extends plugin_renderer_base {
|
||||
|
||||
/**
|
||||
* Display a list of courses
|
||||
* @param array $courses
|
||||
* @param boolean $withwriteaccess
|
||||
* @return string
|
||||
*/
|
||||
public function course_list($courses, $huburl) {
|
||||
global $OUTPUT, $CFG;
|
||||
|
||||
$renderedhtml = '';
|
||||
|
||||
$table = new html_table();
|
||||
|
||||
|
||||
$table->head = array(get_string('coursename', 'block_community'),
|
||||
get_string('coursedesc', 'block_community'),
|
||||
get_string('courselang', 'block_community'),
|
||||
get_string('operation', 'block_community'));
|
||||
|
||||
$table->align = array('left', 'left', 'center', 'center');
|
||||
$table->size = array('25%', '40%', '5%', '%5');
|
||||
|
||||
|
||||
if (empty($courses)) {
|
||||
$renderedhtml .= get_string('nocourse', 'block_community');
|
||||
} else {
|
||||
|
||||
$table->width = '100%';
|
||||
$table->data = array();
|
||||
$table->attributes['class'] = 'sitedirectory';
|
||||
|
||||
// iterate through sites and add to the display table
|
||||
foreach ($courses as $course) {
|
||||
|
||||
if (is_array($course)) {
|
||||
$course = (object) $course;
|
||||
}
|
||||
|
||||
//create site name with link
|
||||
if (!empty($course->courseurl)) {
|
||||
$courseurl = new moodle_url($course->courseurl);
|
||||
} else {
|
||||
$courseurl = new moodle_url($course->demourl);
|
||||
}
|
||||
$courseatag = html_writer::tag('a', $course->fullname, array('href' => $courseurl));
|
||||
|
||||
$coursenamehtml = html_writer::tag('span', $courseatag, array());
|
||||
|
||||
|
||||
//create description to display
|
||||
$deschtml = $course->description; //the description
|
||||
/// courses and sites number display under the description, in smaller
|
||||
$deschtml .= html_writer::empty_tag('br');
|
||||
$additionaldesc = get_string('additionalcoursedesc', 'block_community', $course);
|
||||
$deschtml .= html_writer::tag('span', $additionaldesc, array('class' => 'additionaldesc'));
|
||||
|
||||
//retrieve language string
|
||||
//construct languages array
|
||||
if (!empty($course->language)) {
|
||||
$languages = get_string_manager()->get_list_of_languages();
|
||||
$language = $languages[$course->language];
|
||||
} else {
|
||||
$language= '';
|
||||
}
|
||||
|
||||
if ($course->enrollable) {
|
||||
//Add link TODO make it a button and send by post
|
||||
$addurl = new moodle_url("/blocks/community/communitycourse.php",
|
||||
array('sesskey' => sesskey(), 'add' => 1, 'confirmed' => 1,
|
||||
'coursefullname' => $course->fullname, 'courseurl' => $courseurl,
|
||||
'coursedescription' => $course->description));
|
||||
$addlinkhtml = html_writer::tag('a', get_string('add'), array('href' => $addurl));
|
||||
} else {
|
||||
//Add link TODO make it a button and send by post
|
||||
// $addurl = new moodle_url("/blocks/community/communitycourse.php",
|
||||
// array('sesskey' => sesskey(), 'download' => 1, 'confirmed' => 1,
|
||||
// 'courseid' => $course->id, 'huburl' => $huburl));
|
||||
// $addlinkhtml = html_writer::tag('a', get_string('download', 'block_community'), array('href' => $addurl));
|
||||
|
||||
$addlinkhtml = "Download not implemented yet";
|
||||
}
|
||||
|
||||
// add a row to the table
|
||||
$cells = array($coursenamehtml, $deschtml, $language, $addlinkhtml);
|
||||
|
||||
|
||||
$row = new html_table_row($cells);
|
||||
|
||||
$table->data[] = $row;
|
||||
}
|
||||
$renderedhtml .= html_writer::table($table);
|
||||
}
|
||||
return $renderedhtml;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue