Course plugins can now show information in regions see BT#11080

Add course block
pull/2487/head
jmontoyaa 9 years ago
parent 650dff4c20
commit 851ca9c84f
  1. 1
      main/admin/settings.lib.php
  2. 6
      main/inc/ajax/plugin.ajax.php
  3. 33
      main/inc/lib/plugin.class.php
  4. 22
      main/inc/lib/plugin.lib.php
  5. 40
      main/inc/lib/template.lib.php
  6. 87
      plugin/courseblock/CourseBlockPlugin.php
  7. 22
      plugin/courseblock/README.md
  8. 5
      plugin/courseblock/config.php
  9. 2
      plugin/courseblock/index.php
  10. 9
      plugin/courseblock/install.php
  11. 11
      plugin/courseblock/lang/english.php
  12. 2
      plugin/courseblock/lang/french.php
  13. 2
      plugin/courseblock/lang/spanish.php
  14. 4
      plugin/courseblock/plugin.php

@ -167,7 +167,6 @@ function handle_plugins()
echo '<input type="checkbox" name="plugin_'.$plugin.'[]">';
}
echo '</td><td>';
echo '<h4>'.$plugin_info['title'].' <small>v '.$plugin_info['version'].'</small></h4>';
echo '<p>'.$plugin_info['comment'].'</p>';
echo '<p>'.get_lang('Author').': '.$plugin_info['author'].'</p>';

@ -14,12 +14,14 @@ switch ($action) {
case 'md_to_html':
$plugin = isset($_GET['plugin']) ? $_GET['plugin'] : '';
$appPlugin = new AppPlugin();
$pluginList = $appPlugin->get_installed_plugins();
$pluginInfo = $appPlugin->getPluginInfo($plugin);
$html = '';
if (in_array($plugin, $pluginList)) {
if (!empty($pluginInfo)) {
$file = api_get_path(SYS_PLUGIN_PATH).$plugin.'/README.md';
if (file_exists($file)) {
$content = file_get_contents($file);
$html = MarkdownExtra::defaultTransform($content);
}
}

@ -19,8 +19,8 @@ class Plugin
{
protected $version = '';
protected $author = '';
protected $fields = array();
private $settings = null;
protected $fields = [];
private $settings = [];
// Translation strings.
private $strings = null;
public $isCoursePlugin = false;
@ -70,6 +70,7 @@ class Plugin
public function get_info()
{
$result = array();
$result['obj'] = $this;
$result['title'] = $this->get_title();
$result['comment'] = $this->get_comment();
$result['version'] = $this->get_version();
@ -321,7 +322,7 @@ class Plugin
$interfaceLanguageId = api_get_language_id($language_interface);
$interfaceLanguageInfo = api_get_language_info($interfaceLanguageId);
$languageParentId = (!empty($interfaceLanguageInfo['parent_id'])?intval($interfaceLanguageInfo['parent_id']):0);
$languageParentId = !empty($interfaceLanguageInfo['parent_id']) ? (int) $interfaceLanguageInfo['parent_id'] : 0;
//1. Loading english if exists
$english_path = $root.$plugin_name."/lang/english.php";
@ -333,8 +334,7 @@ class Plugin
}
$path = $root.$plugin_name."/lang/$language_interface.php";
//2. Loading the system language
// 2. Loading the system language
if (is_readable($path)) {
include $path;
if (!empty($strings)) {
@ -391,9 +391,10 @@ class Plugin
{
$plugin_name = $this->get_name();
$t_course = Database::get_course_table(TABLE_COURSE_SETTING);
$courseId = intval($courseId);
$courseId = (int) $courseId;
if (empty($courseId)) {
return false;
}
@ -428,7 +429,8 @@ class Plugin
'subkey' => $variable,
'value' => $value,
'category' => 'plugins',
'type' => $type
'type' => $type,
'title' => ''
];
Database::insert($t_course, $params);
}
@ -444,7 +446,8 @@ class Plugin
'subkey' => $plugin_name,
'value' => $value,
'category' => 'plugins',
'type' => $type
'type' => $type,
'title' => ''
];
Database::insert($t_course, $params);
}
@ -464,8 +467,6 @@ class Plugin
$result = Database::query($sql);
if (!Database::num_rows($result)) {
$tool_link = "$plugin_name/start.php";
//$visibility = AddCourse::string2binary(api_get_setting('course_create_active_tools', $plugin_name));
$cToolId = AddCourse::generateToolId($courseId);
Database::insert(
@ -498,7 +499,9 @@ class Plugin
public function uninstall_course_fields($courseId)
{
$courseId = intval($courseId);
if (empty($courseId)) {
return false;
}
$plugin_name = $this->get_name();
@ -627,6 +630,7 @@ class Plugin
$checkDuplicate = Database::select('*', 'settings_current', $checkCondition);
if (!empty($checkDuplicate)) {
return false;
}
@ -759,4 +763,13 @@ class Plugin
{
return true;
}
/**
* @param string $region
* @return string
*/
public function renderRegion($region)
{
return '';
}
}

@ -261,8 +261,9 @@ class AppPlugin
public function load_region($region, $template, $forced = false)
{
if ($region == 'course_tool_plugin') {
return null;
return '';
}
ob_start();
$this->get_all_plugin_contents_by_region($region, $template, $forced);
$content = ob_get_contents();
@ -331,9 +332,9 @@ class AppPlugin
}
/**
* @param string $region
* @param Template $template
* @param bool $forced
* @param string $region
* @param Template $template
* @param bool $forced
*
* @return bool
*
@ -343,14 +344,13 @@ class AppPlugin
{
global $_plugins;
if (isset($_plugins[$region]) && is_array($_plugins[$region])) {
//if (1) {
//Load the plugin information
// Load the plugin information
foreach ($_plugins[$region] as $plugin_name) {
//The plugin_info variable is available inside the plugin index
// The plugin_info variable is available inside the plugin index
$plugin_info = $this->getPluginInfo($plugin_name, $forced);
//We also know where the plugin is
// We also know where the plugin is
$plugin_info['current_region'] = $region;
// Loading the plugin/XXX/index.php file
@ -361,10 +361,10 @@ class AppPlugin
//Loading the lang variables of the plugin if exists
self::load_plugin_lang_variables($plugin_name);
//Printing the plugin index.php file
// Printing the plugin index.php file
require $plugin_file;
//If the variable $_template is set we assign those values to be accesible in Twig
// If the variable $_template is set we assign those values to be accessible in Twig
if (isset($_template)) {
$_template['plugin_info'] = $plugin_info;
} else {
@ -384,7 +384,6 @@ class AppPlugin
if (!empty($template_list)) {
foreach ($template_list as $plugin_tpl) {
if (!empty($plugin_tpl)) {
//$template_plugin_file = api_get_path(SYS_PLUGIN_PATH)."$plugin_name/$plugin_tpl"; //for smarty
$template_plugin_file = "$plugin_name/$plugin_tpl"; // for twig
$template->display($template_plugin_file, false);
}
@ -418,6 +417,7 @@ class AppPlugin
$plugin_info = array();
if (file_exists($plugin_file)) {
require $plugin_file;
}

@ -185,8 +185,8 @@ class Template
$this->plugin = new AppPlugin();
//1. Showing installed plugins in regions
$plugin_regions = $this->plugin->get_plugin_regions();
foreach ($plugin_regions as $region) {
$pluginRegions = $this->plugin->get_plugin_regions();
foreach ($pluginRegions as $region) {
$this->set_plugin_region($region);
}
@ -1150,17 +1150,39 @@ class Template
/**
* Sets the plugin content in a template variable
* @param string $plugin_region
* @param string $pluginRegion
* @return null
*/
public function set_plugin_region($plugin_region)
public function set_plugin_region($pluginRegion)
{
if (!empty($plugin_region)) {
$region_content = $this->plugin->load_region($plugin_region, $this, $this->force_plugin_load);
if (!empty($region_content)) {
$this->assign('plugin_'.$plugin_region, $region_content);
if (!empty($pluginRegion)) {
$regionContent = $this->plugin->load_region($pluginRegion, $this, $this->force_plugin_load);
$pluginList = $this->plugin->get_installed_plugins();
foreach ($pluginList as $plugin_name) {
// The plugin_info variable is available inside the plugin index
$pluginInfo = $this->plugin->getPluginInfo($plugin_name);
if (isset($pluginInfo['is_course_plugin']) && $pluginInfo['is_course_plugin']) {
$courseInfo = api_get_course_info();
if (!empty($courseInfo)) {
if (isset($pluginInfo['obj']) && $pluginInfo['obj'] instanceof Plugin) {
/** @var Plugin $plugin */
$plugin = $pluginInfo['obj'];
$regionContent .= $plugin->renderRegion($pluginRegion);
}
}
} else {
continue;
}
}
if (!empty($regionContent)) {
$this->assign('plugin_'.$pluginRegion, $regionContent);
} else {
$this->assign('plugin_'.$plugin_region, null);
$this->assign('plugin_'.$pluginRegion, null);
}
}
return null;

@ -0,0 +1,87 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Class CourseBlockPlugin
*/
class CourseBlockPlugin extends Plugin
{
public $isCoursePlugin = true;
// When creating a new course this settings are added to the course
public $course_settings = array(
array(
'name' => 'course_block_footer_left',
'type' => 'textarea'
),
array(
'name' => 'course_block_footer_center',
'type' => 'textarea'
),
array(
'name' => 'course_block_footer_right',
'type' => 'textarea'
)
);
/**
* @return CourseBlockPlugin
*/
public static function create()
{
static $result = null;
return $result ? $result : $result = new self();
}
/**
*
*/
protected function __construct()
{
parent::__construct(
'0.1',
'Julio Montoya',
array(
'tool_enable' => 'boolean'
)
);
}
///public function
public function install()
{
// Installing course settings
$this->install_course_fields_in_all_courses(false);
}
public function uninstall()
{
// Deleting course settings
$this->uninstall_course_fields_in_all_courses();
}
/**
* @param string $region
* @return string
*/
public function renderRegion($region)
{
$content = '';
switch ($region) {
case 'footer_left':
$content = api_get_course_setting('course_block_footer_left');
$content = $content === -1 ? '' : $content;
break;
case 'footer_center':
$content = api_get_course_setting('course_block_footer_center');
$content = $content === -1 ? '' : $content;
break;
case 'footer_right':
$content = api_get_course_setting('course_block_footer_right');
$content = $content === -1 ? '' : $content;
break;
}
return $content;
}
}

@ -0,0 +1,22 @@
1. Enabled the plugin from the list of plugins.
2. Click "Configure" once the plugin was enabled.
3. Select tool_enable = Yes and save.
4. Go into a *course* (not course session) and enter the Settings tool.
5. In the "Course access" section select "Enable legal terms" and
change the course visibility to "Private" and save.
6. Go to a course or a course in a session a new button "Legal" will appear
in the course home.
7. Click the button "Legal". Fill the form with the content and a file you want
to be shown to the students. There are other options in the form, like:
- Send an email to all users.
- Delete all previous agreements
- Delete the file.
The file are saved in courses/XX/courselegal/
8. Once the form was saved, a new form will appear for the registered users.
The student has to accept the form.
When the form is accepted an email will be sent to the user via email and
then Chamilo message tool
9. The user has to click in the URL. Once the user clicked to the URL the user
will have access to the course.

@ -0,0 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
require_once __DIR__ . '/../../main/inc/global.inc.php';
require_once __DIR__.'/CourseBlockPlugin.php';

@ -0,0 +1,9 @@
<?php
/* For license terms, see /license.txt */
require_once dirname(__FILE__) . '/config.php';
if (!api_is_platform_admin()) {
die ('You must have admin permissions to install plugins');
}
CourseBlockPlugin::create()->install();

@ -0,0 +1,11 @@
<?php
$strings['plugin_title'] = "Course block";
$strings['plugin_comment'] = "Add header and footer in a course";
$strings['tool_enable'] = 'Enable plugin';
$strings['tool_enable_help'] = 'Once enabled, you will have to configure the plugin inside the course configuration, then from the course homepage (a button will appear there only for the teacher)';
$strings['course_block_footer_left'] = 'Footer left';
$strings['course_block_footer_center'] = 'Footer center';
$strings['course_block_footer_right'] = 'Footer right';

@ -0,0 +1,4 @@
<?php
require_once __DIR__ . '/config.php';
$plugin_info = CourseBlockPlugin::create()->get_info();
Loading…
Cancel
Save