├── .editorconfig ├── .gitignore ├── README.md ├── classes └── event │ └── something_changed.php ├── cli └── example_script.php ├── db ├── access.php ├── events.php ├── install.php ├── install.xml.example ├── messages.php ├── renamedclasses.php ├── services.php ├── uninstall.php └── upgrade.php ├── externallib.php ├── lang ├── ar │ └── local_moodle_local_plugin.php └── en │ └── local_moodle_local_plugin.php ├── lib.php ├── settings.php └── version.php /.editorconfig: -------------------------------------------------------------------------------- 1 | root = false 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = false 9 | insert_final_newline = false -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohessaid/moodle_local_plugin/aabd0375809cfbadbc96425e3e58f193ebd82eed/.gitignore -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A complete template of a Local Moodle Plugin 2 | 3 | This is a template of Moodle local plugins. You can use it as a boiler plate for your next plugin. 4 | 5 | # Why should I use this? 6 | 7 | Good question! I started unexpectedly developing for Moodle. Moodle, as you may have noticed, is very academic in all its aspects even code. So you may not find the specific answer to your question quickly. And that's why this project is worth sharing. 8 | This template is a result of reading all the documentation provided in Moodle Developer DOCs. Development of few production-ready plugins for large Moodle powered platforms. And finally, this is what I am using all the time to kick start any new plugin. 9 | 10 | # How do I get started? 11 | 12 | Clone the project to your workspace. 13 | 14 | ```zsh 15 | git clone https://github.com/mohessaid/moodle_local_plugin.git 16 | ``` 17 | It's recommended to clone it to a custom name (name of your plugin). 18 | 19 | ```zsh 20 | git clone https://github.com/mohessaid/moodle_local_plugin.git my_plugin_name` 21 | ``` 22 | ## Edit the `version.php` file with your information. 23 | 24 | The `version.php` file contains important information that helps Moodle install and 25 | load your plugin. It looks like this: 26 | 27 | ```php 28 | $plugin->component = 'local_moodle_local_plugin'; 29 | $plugin->version = 2017112900; 30 | $plugin->requires = 2014051200; 31 | $plugin->maturity = MATURITY_ALPHA; 32 | $plugin->release = 'v0.0.1'; 33 | ``` 34 | ### Name (component) 35 | 36 | ```php 37 | $plugin->component = 'local_course_editor'; 38 | ``` 39 | The component property is the name of your plugin. The name must be in this format `type + name`. Where type is the type of our plugin, And the name is what we want to call our plugin. This naming style is necessary to allow the Moodle autoloader to load our plugin correctly. If we miss something in the name or change it in any place of our plugin, Moodle won't load it or detected it for installation if it's newly added. 40 | The `type` part must be the same with the parent folder where we willing to put our plugin. For example, `local` for local plugins and `mod` for module plugins. Every Moodle plugin type 41 | has a folder in the root directory where we can put our plugins. If we are writing a child plugin, we use the appropriate folder of his parent plugin. 42 | The `name` part is what we want to name the plugin. We can call it whatever we like. If it respects the naming conventions and coding styles of Moodle. 43 | 44 | ### Version 45 | 46 | The version property is an integer. It contains four parts and can be summiried as follow: 47 | 1. The year (`2017` in this case). 48 | 2. The month (`11` November in this case). 49 | 3. The day (`29` in this case). 50 | 4. The version `00`. this related to the day of development or release it your choice. You wil use this part on your daily development process to check the changes that require version upgrade. If you are willing to publish this plugin in the Moodle plugins directory this part will be `00` which is recommended. 51 | 52 | 53 | ### Requises 54 | 55 | This is the Moodle version required by the plugin. 56 | 57 | ### Maturity 58 | 59 | How mature is the plugin. It can be one of these options ( `MATURITY_ALPHA, MATURITY_BETA, MATURITY_RC or MATURITY_STABLE`). 60 | 61 | ### Release 62 | 63 | You can use whatever you want for your plugin release versioning. Moodle core plugins uses `v2.7.-r1` where `2.7` is the version of Moodle and `r1` is the first revision of their `2.7.x` branch. 64 | 65 | ## Update the functions and File names with plugin name 66 | 67 | After we update the `version.php` file with our custom choices. Now we need to rename files that should contain the name and the type of our plugin like the files unders the `lang` folder. Then we have to change the functions names in the `bd` folder files. For example the in the `install.php` file we have this: 68 | 69 | ```php 70 | function xmldb_moodle_local_plugin_install(){ 71 | // Installation code goes here 72 | 73 | } 74 | ``` 75 | Which needs to be updated by replacing the `moodle_local_plugin` part with our plugin name. `local` here is part of our default name so don't get confused with the type of plugin. In these functions you don't need to specify the type. Another example is the `externallib.php` file, where we can implement our external web services to use them through the web services API. 76 | 77 | ```php 78 | class local_moodle_local_plugin_external extends external_api{ 79 | // Functions (methods) goes here. 80 | } 81 | ``` 82 | 83 | # Where Can I find help? 84 | 85 | If the getting started section is not enough for you to get going with your Moodle plugin. Please feel free to check the Moodle documentation on this matter. I included documentation links in every file. You can also check their tracking system and forums to get custom help. 86 | - [Local plugins development][1] 87 | - [Development documentations][2] 88 | - [Plugin files][3] 89 | - [Moodle tracker][4] 90 | - [Moodle forums][5] 91 | - [Moodle developers chat rooms][6] 92 | - IRC channel name of the channel is `moodle` or `#moodle` if the application require the hash sign. You can use it [freenode irc webchat][7] if you are not familair with these chat rooms. 93 | 94 | [1]: https://docs.moodle.org/dev/Local_plugins 95 | [2]: https://docs.moodle.org/dev 96 | [3]: https://docs.moodle.org/dev/Plugin_files 97 | [4]: https://tracker.moodle.org 98 | [5]: https://moodle.org/mod/forum/ 99 | [6]: https://docs.moodle.org/dev/Chatrooms 100 | [7]: https://webchat.freenode.net -------------------------------------------------------------------------------- /classes/event/something_changed.php: -------------------------------------------------------------------------------- 1 | 6 | * @license MIT 7 | * @doc https://docs.moodle.org/dev/Event_2 8 | */ 9 | 10 | namespace moodle_local_plugin\event; 11 | 12 | defined('MOODLE_INTERNAL') || die(); 13 | 14 | 15 | class something_changed extends base { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /cli/example_script.php: -------------------------------------------------------------------------------- 1 | 6 | * @license MIT 7 | * @doc https://docs.moodle.org/dev/Access_API 8 | */ 9 | 10 | // If you change this file, you must upgrade the plugin version inorder for your 11 | // changes to take effect. 12 | 13 | defined('MOODLE_INTERNAL') || die(); 14 | 15 | $capabilities = array( 16 | 'local/cq_availability:secreteyes' => array( 17 | 'riskbitmask' => RISK_CONFIG, // https://docs.moodle.org/dev/Hardening_new_Roles_system 18 | 'captype' => 'write', // read or write 19 | 'contextlevel' => CONTEXT_SYSTEM , // https://docs.moodle.org/dev/Roles#Context 20 | 'archetypes' => array( // https://docs.moodle.org/dev/Role_archetypes (What are archetypes) 21 | // @key https://docs.moodle.org/dev/Roles#Capabilities_2 22 | // Use only the last part of the capability, don't 23 | // include the context or component and all these stuff. 24 | // ex: 25 | // if you want to use 'moodle/legacy:student' from the list. 26 | // you can write it as follow: 27 | // 28 | // 'student' => CAP_ALLOW 29 | // 30 | // don't include the 'moodle/legacy:' part. 31 | // 32 | // @value https://docs.moodle.org/dev/Roles#Capabilities 33 | 'editingteacher' => CAP_ALLOW, 34 | ), 35 | //'clonepermissionsfrom' => 'moodle/quiz:attempt' // From May 2012: Copy defaults capabilities settings from core. 36 | ) 37 | ); -------------------------------------------------------------------------------- /db/events.php: -------------------------------------------------------------------------------- 1 | 6 | * @license MIT 7 | * @doc https://docs.moodle.org/dev/Events_API 8 | */ 9 | 10 | // Event handlers (subscriptions) are defined here. It lists all the events that your plugin want to observe and be notified about. 11 | 12 | defined('MOODLE_INTERNAL') || die(); 13 | 14 | -------------------------------------------------------------------------------- /db/install.php: -------------------------------------------------------------------------------- 1 | 6 | * @license MIT 7 | * @doc 8 | */ 9 | 10 | // Allows you to execute a PHP code right after the plugin's database scheme has been installed. 11 | 12 | defined('MOODLE_INTERNAL') || die(); 13 | 14 | function xmldb_moodle_local_plugin_install(){ 15 | // Installation code goes here 16 | 17 | } -------------------------------------------------------------------------------- /db/install.xml.example: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 11 | 12 | To use this file, you have to rename it by omitting the .example extension at the end. -------------------------------------------------------------------------------- /db/messages.php: -------------------------------------------------------------------------------- 1 | 6 | * @license MIT 7 | * @doc https://docs.moodle.org/dev/Message_API 8 | */ 9 | 10 | // Allow to declare your plugin as the messaging provider. 11 | 12 | defined('MOODLE_INTERNAL') || die(); 13 | 14 | -------------------------------------------------------------------------------- /db/renamedclasses.php: -------------------------------------------------------------------------------- 1 | 6 | * @license MIT 7 | * @doc https://moodle.org/mod/forum/discuss.php?d=262403 8 | */ 9 | 10 | // Details of classes that have been renamed to fit in with autoloading. 11 | 12 | defined('MOODLE_INTERNAL') || die(); 13 | 14 | -------------------------------------------------------------------------------- /db/services.php: -------------------------------------------------------------------------------- 1 | 6 | * @license MIT 7 | * @doc https://docs.moodle.org/dev/Adding_a_web_service_to_a_plugin 8 | * https://docs.moodle.org/dev/Web_services_API 9 | * https://docs.moodle.org/dev/External_functions_API 10 | */ 11 | 12 | // External functions and web services provided by your plugin are described here. 13 | 14 | defined('MOODLE_INTERNAL') || die(); 15 | 16 | // We defined the web service functions to install. 17 | // $functions = array( 18 | // 'moodle_local_plugin_service_function_name_1' => array( 19 | // 'classname' => 'moodle_local_plugin_external', 20 | // 'methodname' => 'service_function_name_1', 21 | // 'classpath' => 'local/moodle_local_plugin/externallib.php', 22 | // 'description' => 'Description about the function', 23 | // 'type' => 'read', // Type of operations (read, write). 24 | // ), 25 | // 'moodle_local_plugin_service_function_name_2' => array( 26 | // 'classname' => 'moodle_local_plugin_external', 27 | // 'methodname' => 'service_function_name_2', 28 | // 'classpath' => 'local/moodle_local_plugin/externallib.php', 29 | // 'description' => 'Description about the function', 30 | // 'type' => 'read', // Type of operations (read, write). 31 | // ), 32 | // ); 33 | 34 | // We define the services to install as pre-build services. A pre-build service is not editable by administrator. 35 | // $services = array( 36 | // 'My service' => array( 37 | // 'functions' => array ('local_zsap_core_check_user_existence'), 38 | // 'restrictedusers' => 0, 39 | // 'enabled'=>1, 40 | // ) 41 | // ); -------------------------------------------------------------------------------- /db/uninstall.php: -------------------------------------------------------------------------------- 1 | 6 | * @license MIT 7 | * @doc 8 | */ 9 | 10 | // Allows you to execute a PHP code before the plugin's database tables and data are dropped during the plugin uninstallation. 11 | 12 | defined('MOODLE_INTERNAL') || die(); 13 | 14 | function xmldb_local_moodle_local_plugin_uninstall(){ 15 | // Uninstallation code goes here 16 | } -------------------------------------------------------------------------------- /db/upgrade.php: -------------------------------------------------------------------------------- 1 | 6 | * @license MIT 7 | * @doc https://docs.moodle.org/dev/Upgrade_API 8 | */ 9 | 10 | // Upgrade steps (such as database scheme changes and other things that must happen when the plugin is being upgraded) are defined here. 11 | // The in-built XMLDB editor can be used to generate the code to change the database scheme. 12 | 13 | defined('MOODLE_INTERNAL') || die(); 14 | 15 | function xmldb_local_moodle_local_plugin_upgrade($oldversion){ 16 | // Upgrade code goes here. 17 | global $CFG, $DB; 18 | return true; 19 | } -------------------------------------------------------------------------------- /externallib.php: -------------------------------------------------------------------------------- 1 | 8 | * @license MIT 9 | */ 10 | 11 | require_once($CFG->libdir."/externallib.php"); 12 | 13 | class local_moodle_local_plugin_external extends external_api{ 14 | 15 | 16 | } -------------------------------------------------------------------------------- /lang/ar/local_moodle_local_plugin.php: -------------------------------------------------------------------------------- 1 | 7 | * @license MIT 8 | * @doc https://docs.moodle.org/dev/String_API 9 | */ 10 | 11 | defined('MOODLE_INTERNAL') || die(); 12 | 13 | $string['plugintitle'] = 'هذه قالب مبدئي مثالي لتطوير إضافات مودل العامة.'; -------------------------------------------------------------------------------- /lang/en/local_moodle_local_plugin.php: -------------------------------------------------------------------------------- 1 | 7 | * @license MIT 8 | * @doc https://docs.moodle.org/dev/String_API 9 | */ 10 | 11 | defined('MOODLE_INTERNAL') || die(); 12 | 13 | $string['plugintitle'] = 'This is a complete template example of a local plugin'; -------------------------------------------------------------------------------- /lib.php: -------------------------------------------------------------------------------- 1 | 6 | * @license MIT 7 | * @doc https://docs.moodle.org/dev/Plugin_files 8 | */ 9 | 10 | defined('MOODLE_INTERNAL') || die(); 11 | 12 | -------------------------------------------------------------------------------- /settings.php: -------------------------------------------------------------------------------- 1 | 6 | * @license MIT 7 | * @doc https://docs.moodle.org/dev/Admin_settings 8 | */ 9 | 10 | defined('MOODLE_INTERNAL') || die(); 11 | 12 | -------------------------------------------------------------------------------- /version.php: -------------------------------------------------------------------------------- 1 | 6 | * @license MIT 7 | * @doc https://docs.moodle.org/dev/version.php 8 | */ 9 | 10 | defined('MOODLE_INTERNAL') || die(); 11 | 12 | $plugin->component = 'local_moodle_local_plugin'; // Declare the type and name of this plugin. 13 | $plugin->version = 2017110700; // Plugin released on 4th November 2017. 14 | $plugin->requires = 2014051200; // Moodle 2.7.0 is required. 15 | $plugin->maturity = MATURITY_ALPHA; // This is considered as ALPHA for production sites. 16 | $plugin->release = 'v0.0.1'; // This is our first. --------------------------------------------------------------------------------