Note: You are currently viewing documentation for Moodle 3.3. Up-to-date documentation for the latest stable version of Moodle is probably available here: Plugin types.

Development:Plugin types: Difference between revisions

From MoodleDocs
No edit summary
Line 279: Line 279:
     return $handlers;
     return $handlers;
  }
  }
===From accesslib.php===
function get_capability_string($capabilityname) {
    // Typical capabilityname is mod/choice:readresponses
    $names = split('/', $capabilityname);
    $stringname = $names[1];                // choice:readresponses
    $components = split(':', $stringname);
    $componentname = $components[0];              // choice
    switch ($names[0]) {
        case 'report':
            $string = get_string($stringname, 'report_'.$componentname);
        break;
        case 'mod':
            $string = get_string($stringname, $componentname);
        break;
        case 'block':
            $string = get_string($stringname, 'block_'.$componentname);
        break;
        case 'moodle':
            if ($componentname == 'local') {
                $string = get_string($stringname, 'local');
            } else {
                $string = get_string($stringname, 'role');
            }
        break;
        case 'enrol':
            $string = get_string($stringname, 'enrol_'.$componentname);
        break;
        case 'format':
            $string = get_string($stringname, 'format_'.$componentname);
        break;
        case 'gradeexport':
            $string = get_string($stringname, 'gradeexport_'.$componentname);
        break;
        case 'gradeimport':
            $string = get_string($stringname, 'gradeimport_'.$componentname);
        break;
        case 'gradereport':
            $string = get_string($stringname, 'gradereport_'.$componentname);
        break;
        case 'coursereport':
            $string = get_string($stringname, 'coursereport_'.$componentname);
        break;
        case 'quizreport':
            $string = get_string($stringname, 'quiz_'.$componentname);
        break;
        default:
            $string = get_string($stringname);
        break;
    }
    return $string;
}

Revision as of 07:43, 6 January 2009

These are notes to help me work out what to do for MDL-16438, MDL-13816 and how to do MDL-5106 without adding more junk to help.php (indeed it would be nice to refactor the special case code out of help.php!)

Sanitised list of plugin types

Activity modules

Folder 'mod/'
Prefix ''
DB table 'modules'
Has DB Yes
Has caps Yes

Blocks

Folder 'blocks/'
Prefix 'block_'
DB table 'modules'
Has /db Yes
Has caps Yes

Raw data

List from places_to_search_for_lang_strings

   return array(
       '__exceptions' => array('moodle', 'langconfig'),
       'assignment_' => array('mod/assignment/type'),
       'auth_' => array('auth'),
       'block_' => array('blocks'),
       'datafield_' => array('mod/data/field'),
       'datapreset_' => array('mod/data/preset'),
       'enrol_' => array('enrol'),
       'filter_' => array('filter'),
       'format_' => array('course/format'),
       'quiz_' => array('mod/quiz/report'),
       'qtype_' => array('question/type'),
       'qformat_' => array('question/format'),
       'report_' => array($CFG->admin.'/report', 'course/report'),
       'repository_'=>array('repository'),
       'resource_' => array('mod/resource/type'),
       'gradereport_' => array('grade/report'),
       'gradeimport_' => array('grade/import'),
       'gradeexport_' => array('grade/export'),
       'profilefield_' => array('user/profile/field'),
       'portfolio_' => array('portfolio/type'),
       '' => array('mod')

List from developer documentation index

Code from get_db_directories

/// First, the main one (lib/db)
   $dbdirs[] = $CFG->libdir.'/db';

/// Now, activity modules (mod/xxx/db)
   if ($plugins = get_list_of_plugins('mod')) {
       foreach ($plugins as $plugin) {
           $dbdirs[] = $CFG->dirroot.'/mod/'.$plugin.'/db';
       }
   }

/// Now, assignment submodules (mod/assignment/type/xxx/db)
   if ($plugins = get_list_of_plugins('mod/assignment/type')) {
       foreach ($plugins as $plugin) {
           $dbdirs[] = $CFG->dirroot.'/mod/assignment/type/'.$plugin.'/db';
       }
   }

/// Now, question types (question/type/xxx/db)
   if ($plugins = get_list_of_plugins('question/type')) {
       foreach ($plugins as $plugin) {
           $dbdirs[] = $CFG->dirroot.'/question/type/'.$plugin.'/db';
       }
   }

/// Now, backup/restore stuff (backup/db)
   $dbdirs[] = $CFG->dirroot.'/backup/db';

/// Now, block system stuff (blocks/db)
   $dbdirs[] = $CFG->dirroot.'/blocks/db';

/// Now, blocks (blocks/xxx/db)
   if ($plugins = get_list_of_plugins('blocks', 'db')) {
       foreach ($plugins as $plugin) {
           $dbdirs[] = $CFG->dirroot.'/blocks/'.$plugin.'/db';
       }
   }

/// Now, course formats (course/format/xxx/db)
   if ($plugins = get_list_of_plugins('course/format', 'db')) {
       foreach ($plugins as $plugin) {
           $dbdirs[] = $CFG->dirroot.'/course/format/'.$plugin.'/db';
       }
   }

/// Now, enrolment plugins (enrol/xxx/db)
   if ($plugins = get_list_of_plugins('enrol', 'db')) {
       foreach ($plugins as $plugin) {
           $dbdirs[] = $CFG->dirroot.'/enrol/'.$plugin.'/db';
       }
   }

/// Now admin report plugins (admin/report/xxx/db)
   if ($plugins = get_list_of_plugins($CFG->admin.'/report', 'db')) {
       foreach ($plugins as $plugin) {
           $dbdirs[] = $CFG->dirroot.'/'.$CFG->admin.'/report/'.$plugin.'/db';
       }
   }

/// Now quiz report plugins (mod/quiz/report/xxx/db)
   if ($plugins = get_list_of_plugins('mod/quiz/report', 'db')) {
       foreach ($plugins as $plugin) {
           $dbdirs[] = $CFG->dirroot.'/mod/quiz/report/'.$plugin.'/db';
       }
   }

   if ($plugins = get_list_of_plugins('portfolio/type', 'db')) {
       foreach ($plugins as $plugin) {
           $dbdirs[] = $CFG->dirroot . '/portfolio/type/' . $plugin . '/db';
       }
   }

/// Local database changes, if the local folder exists.
   if (file_exists($CFG->dirroot . '/local')) {
       $dbdirs[] = $CFG->dirroot.'/local/db';
   }

   return $dbdirs;
}

Code from upgrade_db in adminlib.php

/// Find and check all main modules and load them up or upgrade them if necessary
/// first old *.php update and then the new upgrade.php script
   upgrade_activity_modules($return_url);  // Return here afterwards

/// Check all questiontype plugins and upgrade if necessary
/// first old *.php update and then the new upgrade.php script
/// It is important that this is done AFTER the quiz module has been upgraded
   upgrade_plugins('qtype', 'question/type', $return_url);  // Return here afterwards

/// Upgrade backup/restore system if necessary
/// first old *.php update and then the new upgrade.php script
   require_once("$CFG->dirroot/backup/lib.php");
   upgrade_backup_db($return_url);  // Return here afterwards

/// Upgrade blocks system if necessary
/// first old *.php update and then the new upgrade.php script
   require_once("$CFG->dirroot/lib/blocklib.php");
   upgrade_blocks_db($return_url);  // Return here afterwards

/// Check all blocks and load (or upgrade them if necessary)
/// first old *.php update and then the new upgrade.php script
   upgrade_blocks_plugins($return_url);  // Return here afterwards

/// Check all enrolment plugins and upgrade if necessary
/// first old *.php update and then the new upgrade.php script
   upgrade_plugins('enrol', 'enrol', $return_url);  // Return here afterwards

/// Check all auth plugins and upgrade if necessary
   upgrade_plugins('auth','auth',$return_url);

/// Check all course formats and upgrade if necessary
   upgrade_plugins('format','course/format',$return_url);

/// Check for local database customisations
/// first old *.php update and then the new upgrade.php script
   require_once("$CFG->dirroot/lib/locallib.php");
   upgrade_local_db($return_url);  // Return here afterwards

/// Check for changes to RPC functions
   require_once("$CFG->dirroot/$CFG->admin/mnet/adminlib.php");
   upgrade_RPC_functions($return_url);  // Return here afterwards

/// Upgrade all plugins for gradebook
   upgrade_plugins('gradeexport', 'grade/export', $return_url);
   upgrade_plugins('gradeimport', 'grade/import', $return_url);
   upgrade_plugins('gradereport', 'grade/report', $return_url);

/// Check all message output plugins and upgrade if necessary
   upgrade_plugins('message','message/output',$return_url);

/// Check all course report plugins and upgrade if necessary
   upgrade_plugins('coursereport', 'course/report', $return_url);

/// Check all admin report plugins and upgrade if necessary
   upgrade_plugins('report', $CFG->admin.'/report', $return_url);

/// Check all quiz report plugins and upgrade if necessary
   upgrade_plugins('quizreport', 'mod/quiz/report', $return_url);

/// Check all portfolio plugins and upgrade if necessary
   upgrade_plugins('portfolio', 'portfolio/type', $return_url);

/// Check all progress tracker plugins and upgrade if necessary
   upgrade_plugins('trackerexport', 'tracker/export', $return_url);
   upgrade_plugins('trackerimport', 'tracker/import', $return_url);
   upgrade_plugins('trackerreport', 'tracker/report', $return_url);

Code from eventslib.php

function events_load_def($component) {
   global $CFG;

   if ($component == 'moodle') {
       $defpath = $CFG->libdir.'/db/events.php';

   } else if ($component == 'unittest') {
       $defpath = $CFG->libdir.'/simpletest/fixtures/events.php';

   } else {
       $compparts = explode('/', $component);

       if ($compparts[0] == 'block') {
           // Blocks are an exception. Blocks directory is 'blocks', and not
           // 'block'. So we need to jump through hoops.
           $defpath = $CFG->dirroot.'/blocks/'.$compparts[1].'/db/events.php';

       } else if ($compparts[0] == 'format') {
           // Similar to the above, course formats are 'format' while they
           // are stored in 'course/format'.
           $defpath = $CFG->dirroot.'/course/format/'.$compparts[1].'/db/events.php';

       } else if ($compparts[0] == 'gradeimport') {
           $defpath = $CFG->dirroot.'/grade/import/'.$compparts[1].'/db/events.php';  
        
       } else if ($compparts[0] == 'gradeexport') {
           $defpath = $CFG->dirroot.'/grade/export/'.$compparts[1].'/db/events.php'; 
      
       } else if ($compparts[0] == 'gradereport') {
           $defpath = $CFG->dirroot.'/grade/report/'.$compparts[1].'/db/events.php'; 
       } else if ($compparts[0] == 'portfolio'){
           $defpath = $CFG->dirroot.'/portfolio/type/'.$compparts[1].'/db/events.php';
       } else {
           $defpath = $CFG->dirroot.'/'.$component.'/db/events.php';
       }
   }

   $handlers = array();

   if (file_exists($defpath)) {
       require($defpath);
   }

   return $handlers;
}

From accesslib.php

function get_capability_string($capabilityname) {

   // Typical capabilityname is mod/choice:readresponses

   $names = split('/', $capabilityname);
   $stringname = $names[1];                 // choice:readresponses
   $components = split(':', $stringname);
   $componentname = $components[0];               // choice

   switch ($names[0]) {
       case 'report':
           $string = get_string($stringname, 'report_'.$componentname);
       break;

       case 'mod':
           $string = get_string($stringname, $componentname);
       break;

       case 'block':
           $string = get_string($stringname, 'block_'.$componentname);
       break;

       case 'moodle':
           if ($componentname == 'local') {
               $string = get_string($stringname, 'local');
           } else {
               $string = get_string($stringname, 'role');
           }
       break;

       case 'enrol':
           $string = get_string($stringname, 'enrol_'.$componentname);
       break;

       case 'format':
           $string = get_string($stringname, 'format_'.$componentname);
       break;

       case 'gradeexport':
           $string = get_string($stringname, 'gradeexport_'.$componentname);
       break;

       case 'gradeimport':
           $string = get_string($stringname, 'gradeimport_'.$componentname);
       break;

       case 'gradereport':
           $string = get_string($stringname, 'gradereport_'.$componentname);
       break;

       case 'coursereport':
           $string = get_string($stringname, 'coursereport_'.$componentname);
       break;

       case 'quizreport':
           $string = get_string($stringname, 'quiz_'.$componentname);
       break;

       default:
           $string = get_string($stringname);
       break;

   }
   return $string;

}