Permalink
Browse files

add mod template for matrix

  • Loading branch information...
1 parent 0ce1860 commit 10351696ff985dca90dab2e31874d098e900f952 @zhendi zhendi committed Dec 12, 2012
View
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<XMLDB PATH="mod/matrix/db" VERSION="20070401" COMMENT="XMLDB file for Moodle mod/matrix"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
+>
+ <TABLES>
+ <TABLE NAME="matrix" COMMENT="Default comment for matrix, please edit me">
+ <FIELDS>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="course"/>
+ <FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Course matrix activity belongs to" PREVIOUS="id" NEXT="name"/>
+ <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="name field for moodle instances" PREVIOUS="course" NEXT="intro"/>
+ <FIELD NAME="intro" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="General introduction of the matrix activity" PREVIOUS="name" NEXT="introformat"/>
+ <FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Format of the intro field (MOODLE, HTML, MARKDOWN...)" PREVIOUS="intro" NEXT="timecreated"/>
+ <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="introformat" NEXT="timemodified"/>
+ <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="timecreated"/>
+ </FIELDS>
+ <KEYS>
+ <KEY NAME="primary" TYPE="primary" FIELDS="id" />
+ </KEYS>
+ <INDEXES>
+ <INDEX NAME="course" UNIQUE="false" FIELDS="course"/>
+ </INDEXES>
+ </TABLE>
+ </TABLES>
+ <STATEMENTS>
+ <STATEMENT NAME="insert log_display" TYPE="insert" TABLE="log_display" COMMENT="Initial insert of records on table log_display. Each record describes how data will be showed by log reports.">
+ <SENTENCES>
+ <SENTENCE TEXT="(module, action, mtable, field) VALUES ('matrix', 'add', 'matrix', 'name')" />
+ <SENTENCE TEXT="(module, action, mtable, field) VALUES ('matrix', 'update', 'matrix', 'name')" />
+ <SENTENCE TEXT="(module, action, mtable, field) VALUES ('matrix', 'view', 'matrix', 'name')" />
+ </SENTENCES>
+ </STATEMENT>
+ </STATEMENTS>
+</XMLDB>
View
@@ -0,0 +1,134 @@
+<?php //$Id: upgrade.php,v 1.2 2007/08/08 22:36:54 stronk7 Exp $
+
+// This file keeps track of upgrades to
+// the matrix module
+//
+// Sometimes, changes between versions involve
+// alterations to database structures and other
+// major things that may break installations.
+//
+// The upgrade function in this file will attempt
+// to perform all the necessary actions to upgrade
+// your older installtion to the current version.
+//
+// If there's something it cannot do itself, it
+// will tell you what you need to do.
+//
+// The commands in here will all be database-neutral,
+// using the functions defined in lib/ddllib.php
+
+function xmldb_matrix_upgrade($oldversion=0) {
+
+ global $CFG, $THEME, $db;
+
+ $result = true;
+
+/// And upgrade begins here. For each one, you'll need one
+/// block of code similar to the next one. Please, delete
+/// this comment lines once this file start handling proper
+/// upgrade code.
+
+/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
+/// $result = result of "/lib/ddllib.php" function calls
+/// }
+
+/// Lines below (this included) MUST BE DELETED once you get the first version
+/// of your module ready to be installed. They are here only
+/// for demonstrative purposes and to show how the matrix
+/// iself has been upgraded.
+
+/// For each upgrade block, the file matrix/version.php
+/// needs to be updated . Such change allows Moodle to know
+/// that this file has to be processed.
+
+/// To know more about how to write correct DB upgrade scripts it's
+/// highly recommended to read information available at:
+/// http://docs.moodle.org/en/Development:XMLDB_Documentation
+/// and to play with the XMLDB Editor (in the admin menu) and its
+/// PHP generation posibilities.
+
+/// First example, some fields were added to the module on 20070400
+ if ($result && $oldversion < 2007040100) {
+
+ /// Define field course to be added to matrix
+ $table = new XMLDBTable('matrix');
+ $field = new XMLDBField('course');
+ $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id');
+ /// Launch add field course
+ $result = $result && add_field($table, $field);
+
+ /// Define field intro to be added to matrix
+ $table = new XMLDBTable('matrix');
+ $field = new XMLDBField('intro');
+ $field->setAttributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, 'name');
+ /// Launch add field intro
+ $result = $result && add_field($table, $field);
+
+ /// Define field introformat to be added to matrix
+ $table = new XMLDBTable('matrix');
+ $field = new XMLDBField('introformat');
+ $field->setAttributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'intro');
+ /// Launch add field introformat
+ $result = $result && add_field($table, $field);
+ }
+
+/// Second example, some hours later, the same day 20070401
+/// two more fields and one index were added (note the increment
+/// "01" in the last two digits of the version
+ if ($result && $oldversion < 2007040101) {
+
+ /// Define field timecreated to be added to matrix
+ $table = new XMLDBTable('matrix');
+ $field = new XMLDBField('timecreated');
+ $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'introformat');
+ /// Launch add field timecreated
+ $result = $result && add_field($table, $field);
+
+ /// Define field timemodified to be added to matrix
+ $table = new XMLDBTable('matrix');
+ $field = new XMLDBField('timemodified');
+ $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timecreated');
+ /// Launch add field timemodified
+ $result = $result && add_field($table, $field);
+
+ /// Define index course (not unique) to be added to matrix
+ $table = new XMLDBTable('matrix');
+ $index = new XMLDBIndex('course');
+ $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('course'));
+ /// Launch add index course
+ $result = $result && add_index($table, $index);
+ }
+
+/// Third example, the next day, 20070402 (with the trailing 00), some inserts were performed, related with the module
+ if ($result && $oldversion < 2007040200) {
+ /// Add some actions to get them properly displayed in the logs
+ $rec = new stdClass;
+ $rec->module = 'matrix';
+ $rec->action = 'add';
+ $rec->mtable = 'matrix';
+ $rec->filed = 'name';
+ /// Insert the add action in log_display
+ $result = insert_record('log_display', $rec);
+ /// Now the update action
+ $rec->action = 'update';
+ $result = insert_record('log_display', $rec);
+ /// Now the view action
+ $rec->action = 'view';
+ $result = insert_record('log_display', $rec);
+ }
+
+/// And that's all. Please, examine and understand the 3 example blocks above. Also
+/// it's interesting to look how other modules are using this script. Remember that
+/// the basic idea is to have "blocks" of code (each one being executed only once,
+/// when the module version (version.php) is updated.
+
+/// Lines above (this included) MUST BE DELETED once you get the first version of
+/// yout module working. Each time you need to modify something in the module (DB
+/// related, you'll raise the version and add one upgrade block here.
+
+/// Final return of upgrade result (true/false) to Moodle. Must be
+/// always the last line in the script
+ return $result;
+}
+
+?>
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,89 @@
+<?php // $Id: index.php,v 1.7.2.3 2009/08/31 22:00:00 mudrd8mz Exp $
+
+/**
+ * This page lists all the instances of matrix in a particular course
+ *
+ * @author Your Name <your@email.address>
+ * @version $Id: index.php,v 1.7.2.3 2009/08/31 22:00:00 mudrd8mz Exp $
+ * @package mod/matrix
+ */
+
+/// Replace matrix with the name of your module and remove this line
+
+require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
+require_once(dirname(__FILE__).'/lib.php');
+
+$id = required_param('id', PARAM_INT); // course
+
+if (! $course = get_record('course', 'id', $id)) {
+ error('Course ID is incorrect');
+}
+
+require_course_login($course);
+
+add_to_log($course->id, 'matrix', 'view all', "index.php?id=$course->id", '');
+
+
+/// Get all required stringsmatrix
+
+$strmatrixs = get_string('modulenameplural', 'matrix');
+$strmatrix = get_string('modulename', 'matrix');
+
+
+/// Print the header
+
+$navlinks = array();
+$navlinks[] = array('name' => $strmatrixs, 'link' => '', 'type' => 'activity');
+$navigation = build_navigation($navlinks);
+
+print_header_simple($strmatrixs, '', $navigation, '', '', true, '', navmenu($course));
+
+/// Get all the appropriate data
+
+if (! $matrixs = get_all_instances_in_course('matrix', $course)) {
+ notice('There are no instances of matrix', "../../course/view.php?id=$course->id");
+ die;
+}
+
+/// Print the list of instances (your module will probably extend this)
+
+$timenow = time();
+$strname = get_string('name');
+$strweek = get_string('week');
+$strtopic = get_string('topic');
+
+if ($course->format == 'weeks') {
+ $table->head = array ($strweek, $strname);
+ $table->align = array ('center', 'left');
+} else if ($course->format == 'topics') {
+ $table->head = array ($strtopic, $strname);
+ $table->align = array ('center', 'left', 'left', 'left');
+} else {
+ $table->head = array ($strname);
+ $table->align = array ('left', 'left', 'left');
+}
+
+foreach ($matrixs as $matrix) {
+ if (!$matrix->visible) {
+ //Show dimmed if the mod is hidden
+ $link = '<a class="dimmed" href="view.php?id='.$matrix->coursemodule.'">'.format_string($matrix->name).'</a>';
+ } else {
+ //Show normal if the mod is visible
+ $link = '<a href="view.php?id='.$matrix->coursemodule.'">'.format_string($matrix->name).'</a>';
+ }
+
+ if ($course->format == 'weeks' or $course->format == 'topics') {
+ $table->data[] = array ($matrix->section, $link);
+ } else {
+ $table->data[] = array ($link);
+ }
+}
+
+print_heading($strmatrixs);
+print_table($table);
+
+/// Finish the page
+
+print_footer($course);
+
+?>
@@ -0,0 +1,6 @@
+<p>matrix</p>
+<p>Delete me! This file contains a list of all the help files available for the module. Don't
+ forget to add each individual help file to the html list below. Delete me!</p>
+<ul>
+ <li><a href="help.php?module=matrix&amp;file=mods.html">matrix General Info</a></li>
+</ul>
@@ -0,0 +1,18 @@
+<p><img alt="" src="<?php echo $CFG->wwwroot?>/mod/matrix/icon.gif" />&nbsp;<b>matrix</b></p>
+<div class="indent">
+<p>This file contains the main description of the matrix module. Usually, it's used to
+explain the main features of the activity, with a natural language. Also, the overall
+process of the activity is detailed here with its pedagogical foundation.</p>
+
+<p>From a developer perspective, this "help" directory will contain simple html files
+like this that you will be able to link from matrix code when any sort of
+explanation is necessary (it's easier to add those links automatically, both from
+the formslib stuff (see mod_form.php) and from everywhere else (see the helpbutton()
+function).</p>
+
+<p>Also, don't forget to add one link to this help file from the matrix/help "index.html"
+file, it will allow Moodle to show all the existing help files related to the module when the
+complete list of available help files is requested.</p>
+
+<p>Please, replace me with the real information about the matrix!</p>
+</div>
@@ -0,0 +1,12 @@
+<?php
+
+$string['matrix'] = 'matrix';
+
+$string['modulename'] = 'matrix';
+$string['modulenameplural'] = 'matrixS';
+
+$string['matrixfieldset'] = 'Custom example fieldset';
+$string['matrixintro'] = 'matrix Intro';
+$string['matrixname'] = 'matrix Name';
+
+?>
Oops, something went wrong.

0 comments on commit 1035169

Please sign in to comment.