]> git.mjollnir.org Git - moodle.git/commitdiff
New naming conventions for class names to bring them in line with the
authordefacer <defacer>
Tue, 23 Nov 2004 18:53:34 +0000 (18:53 +0000)
committerdefacer <defacer>
Tue, 23 Nov 2004 18:53:34 +0000 (18:53 +0000)
rest of Moodle. The convention for blocks is now:

class block_something extends block_base { ... }

HOWTO updated accordingly, plus some more minor polishing. More to come.

18 files changed:
blocks/HOWTO.html
blocks/activity_modules/block_activity_modules.php
blocks/admin/block_admin.php
blocks/calendar_month/block_calendar_month.php
blocks/calendar_upcoming/block_calendar_upcoming.php
blocks/course_list/block_course_list.php
blocks/course_summary/block_course_summary.php
blocks/login/block_login.php
blocks/moodleblock.class.php
blocks/news_items/block_news_items.php
blocks/online_users/block_online_users.php
blocks/participants/block_participants.php
blocks/recent_activity/block_recent_activity.php
blocks/search_forums/block_search_forums.php
blocks/section_links/block_section_links.php
blocks/site_main_menu/block_site_main_menu.php
blocks/social_activities/block_social_activities.php
lib/blocklib.php

index c2dd41146815deef929af51f58d77bef39c37715..832a6cfafe148a7558a18c7d290c9dc034b8e3c3 100644 (file)
 
     <p>To define a "block" in Moodle, in the most basic case we need to provide just one source code file. We start by creating the directory <span class="filename">/blocks/simplehtml/</span> and creating a file named <span class="filename">/blocks/simplehtml/block_simplehtml.php</span> which will hold our code. We then begin coding the block:</p>
 
-    <pre class="code">class CourseBlock_simplehtml extends MoodleBlock {
+    <pre class="code">class block_simplehtml extends block_base {
     function init() {
         $this->title = get_string('simplehtml', 'block_simplehtml');
         $this->content_type = BLOCK_TYPE_TEXT;
 
     <p>The first line is our block class definition; it must be named exactly in the manner shown. Again, only the "simplehtml" part can (and indeed must) change; everything else is standardized.</p>
 
-    <p>Our class is then given a small method: init(). This is essential for all blocks, and its function is to set the three class member variables listed inside it. But what do these values actually mean? Here's a more detailed description.</p>
+    <p>Our class is then given a small method: <a class="function_title" href="#method_init">init</a>. This is essential for all blocks, and its function is to set the three class member variables listed inside it. But what do these values actually mean? Here's a more detailed description.</p>
 
-    <p>$this->title is the title displayed in the header of our block. We can set it to whatever we like; in this case it's set to read the actual title from a language file we are presumably distributing together with the block. I 'll skip ahead a bit here and say that if you want your block to display NO title at all, then you should set this to any descriptive value you want (but NOT make it empty). We will later see in <a href=#">Part 9</a> how to disable the title's display.</p>
+    <p>$this->title is the title displayed in the header of our block. We can set it to whatever we like; in this case it's set to read the actual title from a language file we are presumably distributing together with the block. I 'll skip ahead a bit here and say that if you want your block to display NO title at all, then you should set this to any descriptive value you want (but NOT make it empty). We will later see <a href="#section_eye_candy">how to disable the title's display</a>.</p>
 
     <p>$this->content_type tells Moodle what kind of content to expect from this block. Here we have two simple choices. Either we set content_type to BLOCK_TYPE_TEXT, which tells Moodle to just take our content and display it on screen as-is; or we set it to BLOCK_TYPE_LIST, which tells Moodle that we want our block to display a nicely formatted list of items with optional icons next to each one. We can use BLOCK_TYPE_TEXT to manually create any content we want (do not be fooled by the name; HTML is allowed in the block's content without restriction) or use BLOCK_TYPE_LIST to easily create a simple menu.</p>
 
@@ -413,7 +413,7 @@ function instance_config_save($data) {
 
 </li>
 
-<li>
+<li id="section_eye_candy">
 
     <h3>Eye Candy</h3>
 
@@ -525,7 +525,7 @@ function get_content() {
 
 <h2 id="appendix_a">Appendix A: Reference</h2>
 
-<p>This Appendix will discuss the base class MoodleBlock from which all other block classes derive, and present each and every method that can be overridden by block developers in detail. Methods that should NOT be overridden are explicitly referred to as such. After reading this Appendix, you will have a clear understanding of every method which you should or could override to implement functionality for your block.</p>
+<p>This Appendix will discuss the base class block_base from which all other block classes derive, and present each and every method that can be overridden by block developers in detail. Methods that should NOT be overridden are explicitly referred to as such. After reading this Appendix, you will have a clear understanding of every method which you should or could override to implement functionality for your block.</p>
 
 <p>The methods are divided into three categories: those you may use and override in your block, those that you may NOT override but might want to use, and those that should NEITHER be used NOR overridden. In each category, methods are presented in alphabetical order.</p>
 
@@ -846,6 +846,24 @@ function specialization() {
 
 <ol>
 
+<li>
+
+    <h3>Class naming conventions changed</h3>
+    
+    <p>In Moodle 1.4, all block classes were required to have a name like <strong>CourseBlock_something</strong> and the base class from which the derived was <strong>MoodleBlock</strong>. This has changed in Moodle 1.5, to bring the naming conventions in line with other object-oriented aspects of Moodle (for example there are classes enrolment_base, resource_base etc). The new block classes should instead be named like <strong>block_something</strong> and derive from <strong>block_base</strong>. This means that in order to make a block compatible with Moodle 1.5, you need to change the class definition
+    
+    <pre class="code">
+class CourseBlock_online_users extends MoodleBlock { ... }
+</pre>
+
+<p>to</p>
+
+    <pre class="code">
+class block_online_users extends block_base { ... }
+</pre>
+
+</li>
+
 <li>
 
     <h3>Constructor versus init()</h3>
index c8a1b757aeefd8035564b0dd940d05a1c6317d3f..1cddbae615ba7020374fe2d4818d05680a6198c0 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP //$Id$
 
-class CourseBlock_activity_modules extends MoodleBlock {
+class block_activity_modules extends block_base {
     function init() {
         $this->title = get_string('activities');
         $this->content_type = BLOCK_TYPE_LIST;
index a7a6405c303ff2fe4902d36ae429bf48bc8b6b3f..71100875f3256978e8062e32a9cf20555d6f0bd2 100644 (file)
@@ -1,6 +1,6 @@
 <?php //$Id$
 
-class CourseBlock_admin extends MoodleBlock {
+class block_admin extends block_base {
     function init() {
         $this->title = get_string('administration');
         $this->content_type = BLOCK_TYPE_LIST;
index defb8bdc8d2726f2903ed2d22869e173c15ee924..244c1f16114a922043c56ce0c742d05fadc78ee7 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP //$Id$
 
-class CourseBlock_calendar_month extends MoodleBlock {
+class block_calendar_month extends block_base {
     function init() {
         $this->title = get_string('calendar', 'calendar');
         $this->content_type = BLOCK_TYPE_TEXT;
index 15dff0111e45898480e40b0cc3adf543f22f5ff8..e0aee8fe05311ff267bd8b5a8b8e9256cec95482 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP //$Id$
 
-class CourseBlock_calendar_upcoming extends MoodleBlock {
+class block_calendar_upcoming extends block_base {
     function init() {
         $this->title = get_string('upcomingevents', 'calendar');
         $this->content_type = BLOCK_TYPE_TEXT;
index 88b5c4b45eec02aa12308afb6d5e6487e2f97400..d7735dfcfe0892bf4e8afd777c71cc17cf2ab905 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP //$Id$
 
-class CourseBlock_course_list extends MoodleBlock {
+class block_course_list extends block_base {
     function init() {
         $this->title = get_string('courses');
         $this->content_type = BLOCK_TYPE_LIST;
index 9639735e38ef833702bbc10503a9dd4ed8471ba7..24b7dbffc45ca041daf87171b981a0c50a0551e4 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP //$Id$
 
-class CourseBlock_course_summary extends MoodleBlock {
+class block_course_summary extends block_base {
     function init() {
         $this->title = get_string('pagedescription', 'block_course_summary');
         $this->content_type = BLOCK_TYPE_TEXT;
index 7919ad38549fc2bee39faa0badf03be57512cb7e..bdc02741e05a45898e6d1a38991df01faa35b19f 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP //$Id$
 
-class CourseBlock_login extends MoodleBlock {
+class block_login extends block_base {
     function init() {
         $this->title = get_string('login');
         $this->content_type = BLOCK_TYPE_TEXT;
index 8585057b5af27657a5f81617307c310c1b51e2ca..d7267ba356e7bc862d7cd1f12aed1df58d664540 100644 (file)
@@ -33,7 +33,7 @@ define('BLOCK_TYPE_NUKE',    3);
  * @author Jon Papaioannou
  * @package blocks
  */
-class MoodleBlock {
+class block_base {
 
     /**
      * Internal var for storing/caching translated strings
@@ -90,7 +90,7 @@ class MoodleBlock {
      * The class constructor
      *
      */
-    function MoodleBlock() {
+    function block_base() {
         $this->init();
     }
 
@@ -99,7 +99,7 @@ class MoodleBlock {
      *
      */
     function __construct() {
-        $this->MoodleBlock();
+        $this->block_base();
     }
 
     /**
@@ -558,7 +558,7 @@ class MoodleBlock {
  * @author Jon Papaioannou
  * @package blocks
  */
-class MoodleBlock_Nuke extends MoodleBlock {
+class block_nuke extends block_base {
     function get_content() {
 
         if ($this->content !== NULL) {
index b896f2d750186459dff2a1b7ce9818d787ccd91d..50e07b677b3ed500912ef4b441eca201212dc026 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP //$Id$
 
-class CourseBlock_news_items extends MoodleBlock {
+class block_news_items extends block_base {
     function init() {
         $this->title = get_string('latestnews');
         $this->content_type = BLOCK_TYPE_TEXT;
index 53c80548df4ba25b7360721e7b4610d39d786acd..18afee531b7a5c7f8370ee862f4c4261f62c2d16 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP //$Id$
 
-class CourseBlock_online_users extends MoodleBlock {
+class block_online_users extends block_base {
     function init() {
         $this->title = get_string('blockname','block_online_users');
         $this->content_type = BLOCK_TYPE_TEXT;
index 02e181bc96addc633eb34d3f4cb9f8d530c7d269..f709e224a616add42ac92278e4613d4803844461 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP //$Id$
 
-class CourseBlock_participants extends MoodleBlock {
+class block_participants extends block_base {
     function init() {
         $this->title = get_string('people');
         $this->content_type = BLOCK_TYPE_LIST;
index 4a64ddbe6248c915268df0b53dc85a788639f5f0..31305ff56118ed8ddf109c31c16731eff9ad4843 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP //$Id$
 
-class CourseBlock_recent_activity extends MoodleBlock {
+class block_recent_activity extends block_base {
     function init() {
         $this->title = get_string('recentactivity');
         $this->content_type = BLOCK_TYPE_TEXT;
index 75c78fdb694cc8aec4ce1eedbb3fd8d6b8b03c42..dffe1ff800d059ac1c2e81e09cf45f8dfdeccf9f 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP //$Id$
 
-class CourseBlock_search_forums extends MoodleBlock {
+class block_search_forums extends block_base {
     function init() {
         $this->title = get_string('search', 'forum');
         $this->content_type = BLOCK_TYPE_TEXT;
index ec4dfc844966cbefaf400f9058204179a1031172..e1fda967ea07eeec9aa42abd93c18caa9b10e1e1 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP //$Id$
 
-class CourseBlock_section_links extends MoodleBlock {
+class block_section_links extends block_base {
 
     function init() {
         $this->title = get_string('blockname', 'block_section_links');
index 72bd588cf7da7f99604134bb230fea0f718458b0..f6acc694028ee89fde2f0c3c7f9e277377b1f590 100644 (file)
@@ -1,6 +1,6 @@
 <?php   //$Id$
 
-class CourseBlock_site_main_menu extends MoodleBlock {
+class block_site_main_menu extends block_base {
     function init() {
         $this->title = get_string('mainmenu');
         $this->content_type = BLOCK_TYPE_LIST;
index bb980e634e3c4851a7031ea72c6d9c766f11e058..d56a6a2aab39a9b382cd0e8d97891432b4ff09d5 100644 (file)
@@ -1,6 +1,6 @@
 <?php //$Id$
 
-class CourseBlock_social_activities extends MoodleBlock {
+class block_social_activities extends block_base {
     function init(){
         $this->title = get_string('blockname','block_social_activities');
         $this->content_type = BLOCK_TYPE_LIST;
index 3bfac65b6ed71090973fb7708d434b4918749d0e..59af30d340c838d1843eb703b9750930faee4767 100644 (file)
@@ -61,7 +61,7 @@ function block_method_result($blockname, $method) {
     if(!block_load_class($blockname)) {
         return NULL;
     }
-    return eval('return CourseBlock_'.$blockname.'::'.$method.'();');
+    return eval('return block_'.$blockname.'::'.$method.'();');
 }
 
 //This function creates a new object of the specified block class
@@ -69,7 +69,7 @@ function block_instance($blockname, $instance = NULL) {
     if(!block_load_class($blockname)) {
         return false;
     }
-    $classname = 'CourseBlock_'.$blockname;
+    $classname = 'block_'.$blockname;
     $retval = new $classname;
     if($instance !== NULL) {
         $retval->load_instance($instance);
@@ -83,7 +83,7 @@ function block_load_class($blockname) {
     global $CFG;
 
     @include_once($CFG->dirroot.'/blocks/moodleblock.class.php');
-    $classname = 'CourseBlock_'.$blockname;
+    $classname = 'block_'.$blockname;
     @include_once($CFG->dirroot.'/blocks/'.$blockname.'/block_'.$blockname.'.php');
 
     // After all this, return value indicating success or failure
@@ -677,8 +677,8 @@ function upgrade_blocks_plugins($continueto) {
     }
 
     include_once($CFG->dirroot .'/blocks/moodleblock.class.php');
-    if(!class_exists('moodleblock')) {
-        error('Class MoodleBlock is not defined or file not found for /blocks/moodleblock.class.php');
+    if(!class_exists('block_base')) {
+        error('Class block_base is not defined or file not found for /blocks/moodleblock.class.php');
     }
 
     foreach ($blocks as $blockname) {
@@ -705,7 +705,7 @@ function upgrade_blocks_plugins($continueto) {
             }
         }
 
-        $classname = 'CourseBlock_'.$blockname;
+        $classname = 'block_'.$blockname;
         if(!class_exists($classname)) {
             $notices[] = 'Block '. $blockname .': '. $classname .' not implemented';
             continue;
@@ -732,9 +732,9 @@ function upgrade_blocks_plugins($continueto) {
         $block    = new stdClass;     // This may be used to update the db below
         $blockobj = new $classname;   // This is what we 'll be testing
 
-        // Inherits from MoodleBlock?
-        if(!is_subclass_of($blockobj, 'moodleblock')) {
-            $notices[] = 'Block '. $blockname .': class does not inherit from MoodleBlock';
+        // Inherits from block_base?
+        if(!is_subclass_of($blockobj, 'block_base')) {
+            $notices[] = 'Block '. $blockname .': class does not inherit from block_base';
             continue;
         }