Commit 3909f693 authored by Daniel Neis Araujo's avatar Daniel Neis Araujo

initial commit

parents
The following steps should get you up and running with
this block template code.
* DO NOT PANIC!
* Unzip the archive and read this file
* Rename the featuredcourses/ folder to the name of your module (eg "widget").
The module folder MUST be lower case. You should check the Moodle Plugins
Database at https://moodle.org/plugins to make sure that
your name is not already used by an other block. Registering the plugin
name @ http://moodle.org/plugins will secure it for you.
* Edit all the files in this directory and its subdirectories and change
all the instances of the string "featuredcourses" to your module name
(eg "widget"). If you are using Linux, you can use the following command
$ find . -type f -exec sed -i 's/featuredcourses/widget/g' {} \;
* Rename the file lang/en/featuredcourses.php to lang/en/widget.php
where "widget" is the name of your module. Also rename block_featuredcourses.php
in the main directory to block_widget.php
* Place the widget folder into the /block folder of the moodle
directory.
* Go to Settings > Site Administration > Development > XMLDB editor
and modify the module's tables.
* Modify version.php and set the initial version of you module.
* Visit Settings > Site Administration > Notifications, you should find
the module's tables successfully created
* Go to Site Administration > Plugins > Blocks > Manage blocks
and you should find that this featuredcourses has been added to the list of
installed modules.
* You may now proceed to run your own code in an attempt to develop
your module. You will probably want to modify block_newmodule.php
and edit_form.php as a first step. Check db/access.php to add
capabilities.
We encourage you to share your code and experience - visit http://moodle.org
Good luck!
<?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();
class block_featuredcourses extends block_base {
function init() {
$this->title = get_string('pluginname', 'block_featuredcourses');
}
function get_content() {
global $CFG, $OUTPUT;
if ($this->content !== null) {
return $this->content;
}
if (empty($this->instance)) {
$this->content = '';
return $this->content;
}
$this->content = new stdClass();
$this->content->items = array();
$this->content->icons = array();
$this->content->footer = '';
$this->content->text = '';
// user/index.php expect course context, so get one if page has module context.
$currentcontext = $this->page->context->get_course_context(false);
if (empty($currentcontext)) {
return $this->content;
}
if ($this->page->course->id == SITEID) {
$courses = $this->get_featured_courses();
foreach ($courses as $c) {
$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>';
}
}
return $this->content;
}
// my moodle can only have SITEID and it's redundant here, so take it away
public function applicable_formats() {
return array('all' => false,
'site' => true,
'site-index' => true);
}
public function instance_allow_multiple() {
return false;
}
function has_config() {return true;}
public function cron() {
return true;
}
private function get_featured_courses() {
global $DB;
$sql = 'SELECT c.id, c.fullname,
fc.proximaturma, fc. cargahoraria, fc.valor,
fc.linkprograma, fc.linkinscrever, fc.linkimagem
FROM {block_featuredcourses} fc
JOIN {course} c
ON (c.id = fc.courseid)';
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();
$capabilities = array(
'block/featuredcourses:myaddinstance' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'user' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/my:manageblocks'
),
'block/featuredcourses:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/site:manageblocks'
),
);
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="blocks/featuredcourses/db" VERSION="20150427" COMMENT="XMLDB file for Moodle blocks/featuredcourses"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="block_featuredcourses" COMMENT="Default comment for block_featuredcourses, please edit me">
<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"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="uniq_courseid" TYPE="unique" FIELDS="courseid"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
\ No newline at end of file
<?php
class block_featuredcourses_edit_form extends block_edit_form {
protected function specific_definition($mform) {
// Section header title according to language file.
$mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
// A sample string variable with a default value.
$mform->addElement('text', 'config_text', get_string('blockstring', 'block_featuredcourses'));
$mform->setDefault('config_text', 'default value');
$mform->setType('config_text', PARAM_MULTILANG);
}
}
<?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_featuredcourses', language 'en'
*
* @package block_featuredcourses
* @copyright Daniel Neis <danielneis@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['blockstring'] = 'Block string';
$string['descconfig'] = 'Description of the config section';
$string['descfoo'] = 'Config description';
$string['headerconfig'] = 'Config section header';
$string['labelfoo'] = 'Config label';
$string['featuredcourses:addinstance'] = 'Add a Featured Courses block';
$string['featuredcourses:myaddinstance'] = 'Add a Featured Courses block to my moodle';
$string['pluginname'] = 'Featured Courses';
<?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'));
<?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/>.
/**
* Version details
*
* @package block_featuredcourses
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2015042701; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2014110400; // Requires this Moodle version
$plugin->component = 'block_featuredcourses'; // Full name of the plugin (used for diagnostics)
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