Skip to content

Commit

Permalink
Course plugins can now show information in regions see BT#11080
Browse files Browse the repository at this point in the history
Add course block
  • Loading branch information
jmontoyaa committed May 24, 2016
1 parent 650dff4 commit 851ca9c
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 34 deletions.
1 change: 0 additions & 1 deletion main/admin/settings.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>';
Expand Down
6 changes: 4 additions & 2 deletions main/inc/ajax/plugin.ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
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);
}
}
Expand Down
33 changes: 23 additions & 10 deletions main/inc/lib/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,6 +70,7 @@ protected function __construct($version, $author, $settings = array())
public function get_info()
{
$result = array();
$result['obj'] = $this;
$result['title'] = $this->get_title();
$result['comment'] = $this->get_comment();
$result['version'] = $this->get_version();
Expand Down Expand Up @@ -321,7 +322,7 @@ public function get_lang($name)

$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";
Expand All @@ -333,8 +334,7 @@ public function get_lang($name)
}

$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)) {
Expand Down Expand Up @@ -391,9 +391,10 @@ public function install_course_fields($courseId, $add_tool_link = true)
{
$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;
}

Expand Down Expand Up @@ -428,7 +429,8 @@ public function install_course_fields($courseId, $add_tool_link = true)
'subkey' => $variable,
'value' => $value,
'category' => 'plugins',
'type' => $type
'type' => $type,
'title' => ''
];
Database::insert($t_course, $params);
}
Expand All @@ -444,7 +446,8 @@ public function install_course_fields($courseId, $add_tool_link = true)
'subkey' => $plugin_name,
'value' => $value,
'category' => 'plugins',
'type' => $type
'type' => $type,
'title' => ''
];
Database::insert($t_course, $params);
}
Expand All @@ -464,8 +467,6 @@ public function install_course_fields($courseId, $add_tool_link = true)
$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(
Expand Down Expand Up @@ -498,7 +499,9 @@ public function install_course_fields($courseId, $add_tool_link = true)
public function uninstall_course_fields($courseId)
{
$courseId = intval($courseId);

if (empty($courseId)) {

return false;
}
$plugin_name = $this->get_name();
Expand Down Expand Up @@ -627,6 +630,7 @@ public function addTab($tabName, $url)

$checkDuplicate = Database::select('*', 'settings_current', $checkCondition);
if (!empty($checkDuplicate)) {

return false;
}

Expand Down Expand Up @@ -759,4 +763,13 @@ public function validateCourseSetting($variable)
{
return true;
}

/**
* @param string $region
* @return string
*/
public function renderRegion($region)
{
return '';
}
}
22 changes: 11 additions & 11 deletions main/inc/lib/plugin.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,9 @@ public function get_plugin_regions()
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();
Expand Down Expand Up @@ -331,9 +332,9 @@ public function load_plugin_lang_variables($plugin_name)
}

/**
* @param string $region
* @param Template $template
* @param bool $forced
* @param string $region
* @param Template $template
* @param bool $forced
*
* @return bool
*
Expand All @@ -343,14 +344,13 @@ public function get_all_plugin_contents_by_region($region, $template, $forced =
{
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
Expand All @@ -361,10 +361,10 @@ public function get_all_plugin_contents_by_region($region, $template, $forced =
//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 {
Expand All @@ -384,7 +384,6 @@ public function get_all_plugin_contents_by_region($region, $template, $forced =
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);
}
Expand Down Expand Up @@ -418,6 +417,7 @@ public function getPluginInfo($plugin_name, $forced = false)

$plugin_info = array();
if (file_exists($plugin_file)) {

require $plugin_file;
}

Expand Down
42 changes: 32 additions & 10 deletions main/inc/lib/template.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ public function __construct(
$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);
}

Expand Down Expand Up @@ -950,7 +950,7 @@ private function set_header_parameters($sendHeaders)
$portal_name = empty($institution) ? api_get_setting('siteName') : $institution;

$this->assign('portal_name', $portal_name);

//Menu
$menu = menuArray();
$this->assign('menu', $menu);
Expand Down Expand Up @@ -1150,17 +1150,39 @@ public function show_footer_js_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;
Expand Down
87 changes: 87 additions & 0 deletions plugin/courseblock/CourseBlockPlugin.php
Original file line number Diff line number Diff line change
@@ -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;
}
}
22 changes: 22 additions & 0 deletions plugin/courseblock/README.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions plugin/courseblock/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
/* For licensing terms, see /license.txt */

require_once __DIR__ . '/../../main/inc/global.inc.php';
require_once __DIR__.'/CourseBlockPlugin.php';
2 changes: 2 additions & 0 deletions plugin/courseblock/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php

Loading

0 comments on commit 851ca9c

Please sign in to comment.