├── .travis.yml ├── README.md ├── block_newblock.php ├── composer.json ├── db └── access.php ├── edit_form.php ├── lang └── en │ └── block_newblock.php ├── settings.php └── version.php /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | sudo: false 4 | 5 | cache: 6 | directories: 7 | - $HOME/.composer/cache 8 | 9 | php: 10 | - 5.4 11 | - 5.5 12 | - 5.6 13 | - 7.0 14 | 15 | matrix: 16 | allow_failures: 17 | - php: 7.0 18 | 19 | env: 20 | global: 21 | - MOODLE_BRANCH=MOODLE_30_STABLE 22 | matrix: 23 | - DB=pgsql 24 | - DB=mysqli 25 | 26 | before_install: 27 | - cd ../.. 28 | - composer selfupdate 29 | - composer create-project -n --no-dev moodlerooms/moodle-plugin-ci ci ^1 30 | - export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH" 31 | 32 | install: 33 | - moodle-plugin-ci install 34 | 35 | script: 36 | - moodle-plugin-ci phplint 37 | - moodle-plugin-ci phpcpd 38 | - moodle-plugin-ci phpmd 39 | - moodle-plugin-ci codechecker 40 | - moodle-plugin-ci csslint 41 | - moodle-plugin-ci shifter 42 | - moodle-plugin-ci jshint 43 | - moodle-plugin-ci behat 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Moodle Block Template 2 | ===================== 3 | 4 | This is a template for Moodle blocks. 5 | 6 | It is used by Moosh (http://moosh-online.com/) to generate new block plugins. 7 | 8 | * This template assumes that the block is using a textual content type by default. If you want your block to display a list of items (using $this->content->items and $this->content->icons instead of $this->content->text), change the derived class of the block, from extends block_base to extends block_list. For more information: https://docs.moodle.org/dev/Blocks#Additional_Content_Types. 9 | 10 | * Go to Settings > Site Administration > Development > XMLDB editor and modify the module's tables. 11 | 12 | * Modify version.php and set the initial version of you module. 13 | 14 | * Visit Settings > Site Administration > Notifications, you should find 15 | the module's tables successfully created 16 | 17 | * Go to Site Administration > Plugins > Blocks > Manage blocks 18 | and you should find that this newblock has been added to the list of 19 | installed modules. 20 | 21 | * You may now proceed to run your own code in an attempt to develop 22 | your module. You will probably want to modify block_newmodule.php 23 | and edit_form.php as a first step. Check db/access.php to add 24 | capabilities. 25 | 26 | We encourage you to share your code and experience - visit http://moodle.org 27 | 28 | Good luck! 29 | 30 | [![Build Status](https://travis-ci.org/danielneis/moodle-block_newblock.svg?branch=master)](https://travis-ci.org/danielneis/moodle-block_newblock) 31 | -------------------------------------------------------------------------------- /block_newblock.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Newblock block caps. 19 | * 20 | * @package block_newblock 21 | * @copyright Daniel Neis 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die(); 26 | 27 | class block_newblock extends block_base { 28 | 29 | function init() { 30 | $this->title = get_string('pluginname', 'block_newblock'); 31 | } 32 | 33 | function get_content() { 34 | global $CFG, $OUTPUT; 35 | 36 | if ($this->content !== null) { 37 | return $this->content; 38 | } 39 | 40 | if (empty($this->instance)) { 41 | $this->content = ''; 42 | return $this->content; 43 | } 44 | 45 | $this->content = new stdClass(); 46 | $this->content->items = array(); 47 | $this->content->icons = array(); 48 | $this->content->footer = ''; 49 | 50 | // user/index.php expect course context, so get one if page has module context. 51 | $currentcontext = $this->page->context->get_course_context(false); 52 | 53 | if (! empty($this->config->text)) { 54 | $this->content->text = $this->config->text; 55 | } 56 | 57 | $this->content = ''; 58 | if (empty($currentcontext)) { 59 | return $this->content; 60 | } 61 | if ($this->page->course->id == SITEID) { 62 | $this->content->text .= "site context"; 63 | } 64 | 65 | if (! empty($this->config->text)) { 66 | $this->content->text .= $this->config->text; 67 | } 68 | 69 | return $this->content; 70 | } 71 | 72 | // my moodle can only have SITEID and it's redundant here, so take it away 73 | public function applicable_formats() { 74 | return array('all' => false, 75 | 'site' => true, 76 | 'site-index' => true, 77 | 'course-view' => true, 78 | 'course-view-social' => false, 79 | 'mod' => true, 80 | 'mod-quiz' => false); 81 | } 82 | 83 | public function instance_allow_multiple() { 84 | return true; 85 | } 86 | 87 | function has_config() {return true;} 88 | 89 | public function cron() { 90 | mtrace( "Hey, my cron script is running" ); 91 | 92 | // do something 93 | 94 | return true; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "danielneis/moodle-block_newblock", 3 | "description": "A block template for Moodle based on http://docs.moodle.org/dev/Blocks", 4 | "license": "GPLv3", 5 | "authors": [ 6 | { 7 | "name": "Daniel Neis Araujo", 8 | "email": "danielneis@gmail.com" 9 | } 10 | ], 11 | "type": "moodle-block", 12 | "require": { 13 | "composer/installers": "~1.0" 14 | }, 15 | "extra": { 16 | "installer-name": "newblock" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /db/access.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Newblock block caps. 19 | * 20 | * @package block_newblock 21 | * @copyright Daniel Neis 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die(); 26 | 27 | $capabilities = array( 28 | 29 | 'block/newblock:myaddinstance' => array( 30 | 'captype' => 'write', 31 | 'contextlevel' => CONTEXT_SYSTEM, 32 | 'archetypes' => array( 33 | 'user' => CAP_ALLOW 34 | ), 35 | 36 | 'clonepermissionsfrom' => 'moodle/my:manageblocks' 37 | ), 38 | 39 | 'block/newblock:addinstance' => array( 40 | 'riskbitmask' => RISK_SPAM | RISK_XSS, 41 | 42 | 'captype' => 'write', 43 | 'contextlevel' => CONTEXT_BLOCK, 44 | 'archetypes' => array( 45 | 'editingteacher' => CAP_ALLOW, 46 | 'manager' => CAP_ALLOW 47 | ), 48 | 49 | 'clonepermissionsfrom' => 'moodle/site:manageblocks' 50 | ), 51 | ); 52 | -------------------------------------------------------------------------------- /edit_form.php: -------------------------------------------------------------------------------- 1 | addElement('header', 'configheader', get_string('blocksettings', 'block')); 9 | 10 | // A sample string variable with a default value. 11 | $mform->addElement('text', 'config_text', get_string('blockstring', 'block_newblock')); 12 | $mform->setDefault('config_text', 'default value'); 13 | $mform->setType('config_text', PARAM_TEXT); 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /lang/en/block_newblock.php: -------------------------------------------------------------------------------- 1 | . 17 | 18 | /** 19 | * Strings for component 'block_newblock', language 'en' 20 | * 21 | * @package block_newblock 22 | * @copyright Daniel Neis 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | $string['blockstring'] = 'Block string'; 27 | $string['descconfig'] = 'Description of the config section'; 28 | $string['descfoo'] = 'Config description'; 29 | $string['headerconfig'] = 'Config section header'; 30 | $string['labelfoo'] = 'Config label'; 31 | $string['newblock:addinstance'] = 'Add a newblock block'; 32 | $string['newblock:myaddinstance'] = 'Add a newblock block to my moodle'; 33 | $string['pluginname'] = 'Newblock'; 34 | -------------------------------------------------------------------------------- /settings.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Newblock block caps. 19 | * 20 | * @package block_newblock 21 | * @copyright Daniel Neis 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die(); 26 | 27 | $settings->add(new admin_setting_heading('sampleheader', 28 | get_string('headerconfig', 'block_newblock'), 29 | get_string('descconfig', 'block_newblock'))); 30 | 31 | $settings->add(new admin_setting_configcheckbox('newblock/foo', 32 | get_string('labelfoo', 'block_newblock'), 33 | get_string('descfoo', 'block_newblock'), 34 | '0')); 35 | -------------------------------------------------------------------------------- /version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Version details 19 | * 20 | * @package block_newblock 21 | * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die(); 26 | 27 | $plugin->version = 2017011300; // The current plugin version (Date: YYYYMMDDXX) 28 | $plugin->requires = 2012112900; // Requires this Moodle version 29 | $plugin->component = 'block_newblock'; // Full name of the plugin (used for diagnostics) 30 | --------------------------------------------------------------------------------