Commit 2cb85338 authored by Daniel Neis Araujo's avatar Daniel Neis Araujo

showing course description and summary files

parent 7fc3de75
......@@ -55,17 +55,56 @@ class block_featuredcourses extends block_base {
return $this->content;
}
if ($this->page->course->id == SITEID) {
$courses = $this->get_featured_courses();
foreach ($courses as $c) {
$courses = self::get_featured_courses();
require_once($CFG->libdir. '/coursecatlib.php');
$chelper = new coursecat_helper();
foreach ($courses as $course) {
$course = new course_in_list($course);
$this->content->text .= '<div class="container-fluid coursebox">';
$this->content->text .= '<h2>'.$c->fullname. '</h2>';
$this->content->text .= '<p>Próxima turma: '.$c->proximaturma. '</p>';
$this->content->text .= '<p>Carga horária: '.$c->cargahoraria. 'h</p>';
$this->content->text .= '<h2>R$ '.$c->valor. '</h2>';
$this->content->text .= '<a href="'.$c->linkprograma. '" class="btn">PROGRAMA</a>';
$this->content->text .= '<a href="'.$c->linkinscrever. '" class="btn">INSCREVER</a>';
$this->content->text .= '<img src="'.$c->linkimagem. '" class="courseimage"/>';
$this->content->text .= '</div>';
$content = '';
// course name
$coursename = $chelper->get_course_formatted_name($course);
$coursenamelink = html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)),
$coursename, array('class' => $course->visible ? '' : 'dimmed'));
$content .= html_writer::tag('div', $coursenamelink, array('class' => 'coursename'));
// display course summary
if ($course->has_summary()) {
$content .= html_writer::start_tag('div', array('class' => 'summary'));
$content .= $chelper->get_course_formatted_summary($course,
array('overflowdiv' => true, 'noclean' => true, 'para' => false));
$content .= html_writer::end_tag('div'); // .summary
}
// display course overview files
$contentimages = $contentfiles = '';
foreach ($course->get_course_overviewfiles() as $file) {
$isimage = $file->is_valid_image();
$url = file_encode_url("$CFG->wwwroot/pluginfile.php",
'/'. $file->get_contextid(). '/'. $file->get_component(). '/'.
$file->get_filearea(). $file->get_filepath(). $file->get_filename(), !$isimage);
if ($isimage) {
$contentimages .= html_writer::tag('div',
html_writer::empty_tag('img', array('src' => $url, 'style' => 'max-height: 150px')),
array('class' => 'courseimage'));
} else {
$image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle');
$filename = html_writer::tag('span', $image, array('class' => 'fp-icon')).
html_writer::tag('span', $file->get_filename(), array('class' => 'fp-filename'));
$contentfiles .= html_writer::tag('span',
html_writer::link($url, $filename),
array('class' => 'coursefile fp-filename-icon'));
}
}
$content .= $contentimages. $contentfiles;
$this->content->text .= $content. '</div>';
}
}
......@@ -89,15 +128,14 @@ class block_featuredcourses extends block_base {
return true;
}
private function get_featured_courses() {
static function get_featured_courses() {
global $DB;
$sql = 'SELECT c.id, c.fullname,
fc.proximaturma, fc. cargahoraria, fc.valor,
fc.linkprograma, fc.linkinscrever, fc.linkimagem
$sql = 'SELECT c.id, c.shortname, c.fullname, fc.sortorder
FROM {block_featuredcourses} fc
JOIN {course} c
ON (c.id = fc.courseid)';
ON (c.id = fc.courseid)
ORDER BY sortorder';
return $DB->get_records_sql($sql);
}
}
......@@ -8,12 +8,7 @@
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="proximaturma" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="cargahoraria" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="valor" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="linkprograma" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="linkinscrever" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="linkimagem" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
......@@ -21,4 +16,4 @@
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
\ No newline at end of file
</XMLDB>
......@@ -2,7 +2,8 @@
require_once('../../config.php');
require_once($CFG->libdir.'/coursecatlib.php');
require_once($CFG->dirroot.'/blocks/featuredcourses/lib.php');
require_once($CFG->dirroot.'/blocks/moodleblock.class.php');
require_once($CFG->dirroot.'/blocks/featuredcourses/block_featuredcourses.php');
require_once($CFG->dirroot.'/blocks/featuredcourses/featuredcourses_form.php');
require_login();
......@@ -17,7 +18,7 @@ $PAGE->set_context($system_context);
$args = array(
'availablecourses' => coursecat::get(0)->get_courses(array('recursive' => true)),
'featuredcourses' => featuredcourses_get_all()
'featuredcourses' => block_featuredcourses::get_featured_courses()
);
$editform = new featuredcourses_form(null, $args);
......@@ -29,7 +30,7 @@ if ($editform->is_cancelled()) {
try {
$DB->insert_record('block_featuredcourses', $data->newfeatured);
} catch (Exception $e) {
throw new moodle_exception();
throw $e;
}
}
......
......@@ -30,35 +30,11 @@ class featuredcourses_form extends moodleform {
$mform->setType('featured['.$c->id.'][id]', PARAM_INT);
$mform->setConstant('featured['.$c->id.'][id]', $c->id);
$mform->addElement('text', 'featured['.$c->id.'][proximaturma]', get_string('proximaturma', 'block_featuredcourses'));
//$mform->addRule('shortname', get_string('missingproximatuma'), 'required', null, 'client');
$mform->setType('featured['.$c->id.'][proximaturma]', PARAM_TEXT);
$mform->setDefault('featured['.$c->id.'][proximaturma]', $c->proximaturma);
$mform->addElement('text', 'featured['.$c->id.'][sortorder]', get_string('sortorder', 'block_featuredcourses'));
$mform->addRule('featured['.$c->id.'][sortorder]', get_string('missingsortorder', 'block_featuredcourses'), 'required', null, 'client');
$mform->setType('featured['.$c->id.'][sortorder]', PARAM_INT);
$mform->setDefault('featured['.$c->id.'][sortorder]', $c->sortorder);
$mform->addElement('text', 'featured['.$c->id.'][cargahoraria]', get_string('cargahoraria', 'block_featuredcourses'));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform->setType('featured['.$c->id.'][cargahoraria]', PARAM_INT);
$mform->setDefault('featured['.$c->id.'][cargahoraria]', $c->cargahoraria);
$mform->addElement('text', 'featured['.$c->id.'][valor]', get_string('price', 'block_featuredcourses'));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform->setType('featured['.$c->id.'][valor]', PARAM_INT);
$mform->setDefault('featured['.$c->id.'][valor]', $c->valor);
$mform->addElement('text', 'featured['.$c->id.'][linkprograma]', get_string('linkprograma', 'block_featuredcourses'));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform->setType('featured['.$c->id.'][linkprograma]', PARAM_URL);
$mform->setDefault('featured['.$c->id.'][linkprograma]', $c->linkprograma);
$mform->addElement('text', 'featured['.$c->id.'][linkinscrever]', get_string('linkinscrever', 'block_featuredcourses'));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform->setType('featured['.$c->id.'][linkinscrever]', PARAM_URL);
$mform->setDefault('featured['.$c->id.'][linkinscrever]', $c->linkinscrever);
$mform->addElement('text', 'featured['.$c->id.'][linkimagem]', get_string('linkimagem', 'block_featuredcourses'));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform->setType('featured['.$c->id.'][linkimagem]', PARAM_URL);
$mform->setDefault('featured['.$c->id.'][linkimagem]', $c->linkimagem);
}
// Add a new featured course
......@@ -67,37 +43,13 @@ class featuredcourses_form extends moodleform {
$mform->addElement('checkbox', 'doadd', get_string('doadd', 'block_featuredcourses'));
$mform->addElement('select', 'newfeatured[courseid]', get_string('courseid', 'block_featuredcourses'), $availablecourseslist);
$mform->addRule('newfeatured[courseid]', get_string('missingcourseid', 'block_featuredcourses'), 'required', null, 'client');
$mform->disabledIf('newfeatured[courseid]', 'doadd', 'notchecked');
$mform->addElement('text', 'newfeatured[proximaturma]', get_string('proximaturma', 'block_featuredcourses'));
//$mform->addRule('shortname', get_string('missingproximatuma'), 'required', null, 'client');
$mform->setType('newfeatured[proximaturma]', PARAM_TEXT);
$mform->disabledIf('newfeatured[proximaturma]', 'doadd', 'notchecked');
$mform->addElement('text', 'newfeatured[cargahoraria]', get_string('cargahoraria', 'block_featuredcourses'));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform->setType('newfeatured[cargahoraria]', PARAM_INT);
$mform->disabledIf('newfeatured[cargahoraria]', 'doadd', 'notchecked');
$mform->addElement('text', 'newfeatured[valor]', get_string('price', 'block_featuredcourses'));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform->setType('newfeatured[valor]', PARAM_INT);
$mform->disabledIf('newfeatured[valor]', 'doadd', 'notchecked');
$mform->addElement('text', 'newfeatured[linkprograma]', get_string('linkprograma', 'block_featuredcourses'));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform->setType('newfeatured[linkprograma]', PARAM_URL);
$mform->disabledIf('newfeatured[linkprograma]', 'doadd', 'notchecked');
$mform->addElement('text', 'newfeatured[linkinscrever]', get_string('linkinscrever', 'block_featuredcourses'));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform->setType('newfeatured[linkinscrever]', PARAM_URL);
$mform->disabledIf('newfeatured[linkinscrever]', 'doadd', 'notchecked');
$mform->addElement('text', 'newfeatured[linkimagem]', get_string('linkimagem', 'block_featuredcourses'));
//$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform->setType('newfeatured[linkimagem]', PARAM_URL);
$mform->disabledIf('newfeatured[linkimagem]', 'doadd', 'notchecked');
$mform->addElement('text', 'newfeatured[sortorder]', get_string('sortorder', 'block_featuredcourses'));
$mform->addRule('newfeatured[sortorder]', get_string('missingsortorder', 'block_featuredcourses'), 'required', null, 'client');
$mform->setType('newfeatured[sortorder]', PARAM_INT);
$mform->disabledIf('newfeatured[sortorder]', 'doadd', 'notchecked');
$mform->addElement('submit', 'save', get_string('savechanges'));
......
......@@ -31,12 +31,9 @@ $string['editpagedesc'] = 'Editing the list of featured courses';
$string['featuredcourses'] = 'Featured courses';
$string['addfeaturedcourse'] = 'Add a new exiting course to featured list';
$string['courseid'] = 'Course';
$string['proximaturma'] = 'Next start date:';
$string['cargahoraria'] = 'Course workload in hours:';
$string['price'] = 'Price:';
$string['linkprograma'] = 'Link to course summary page:';
$string['linkinscrever'] = 'Link to course subscription page:';
$string['linkimagem'] = 'Link to an image to be shown below course info:';
$string['editpagetitle'] = 'Featured courses - editing';
$string['featuredcourse'] = 'Featured course: {$a}';
$string['doadd'] = 'Check to add new featured course';
$string['missingcourseid'] = 'You must select a course.';
$string['sortorder'] = 'Sort order';
$string['missingsortorder'] = 'You must set a sort order.';
<?php
function featuredcourses_get_all() {
global $DB;
$sql = "SELECT c.id, c.shortname, c.fullname,
f.id, f.proximaturma, f.cargahoraria, f.valor,
f.linkprograma, f.linkinscrever, f.linkimagem
FROM {course} c
JOIN {block_featuredcourses} f
ON (c.id = f.courseid)
WHERE c.visible = 1";
return $DB->get_records_sql($sql);
}
<?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/>.
/**
* Newblock block caps.
*
* @package block_featuredcourses
* @copyright Daniel Neis <danielneis@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/*
$settings->add(new admin_setting_heading('sampleheader',
get_string('headerconfig', 'block_featuredcourses'),
get_string('descconfig', 'block_featuredcourses')));
$settings->add(new admin_setting_configcheckbox('featuredcourses/foo',
get_string('labelfoo', 'block_featuredcourses'),
get_string('descfoo', 'block_featuredcourses'),
'0'));
*/
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment