From: sam_marshall Date: Tue, 16 Dec 2008 12:55:21 +0000 (+0000) Subject: MDL-17667: Added simple XSL-based 'doc' feature to xmldb X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=6c59c9c76b8b6fbf7ab419b0ffdb805411dc9f75;p=moodle.git MDL-17667: Added simple XSL-based 'doc' feature to xmldb --- diff --git a/admin/xmldb/actions/generate_documentation/generate_documentation.class.php b/admin/xmldb/actions/generate_documentation/generate_documentation.class.php new file mode 100644 index 0000000000..f733d0ec21 --- /dev/null +++ b/admin/xmldb/actions/generate_documentation/generate_documentation.class.php @@ -0,0 +1,96 @@ +loadStrings(array( + 'backtomainview' => 'xmldb' + )); + } + + /** + * Invoke method, every class will have its own + * returns true/false on completion, setting both + * errormsg and output as necessary + */ + function invoke() { + parent::invoke(); + + $result = true; + + /// Set own core attributes + $this->does_generate = ACTION_GENERATE_HTML; + + /// These are always here + global $CFG, $XMLDB; + + /// Do the job, setting $result as needed + + /// Get the dir containing the file + $dirpath = required_param('dir', PARAM_PATH); + $dirpath = $CFG->dirroot . $dirpath; + $path = $dirpath.'/install.xml'; + if(!file_exists($path) || !is_readable($path)) { + return false; + } + + /// Add link back to home + $b = '

'; + $b .= ' [' . $this->str['backtomainview'] . ']'; + $b .= '

'; + $this->output=$b; + + /// Transform XML file and display it + $doc = new DOMDocument(); + $xsl = new XSLTProcessor(); + + $doc->load(dirname(__FILE__).'/xmldb.xsl'); + $xsl->importStyleSheet($doc); + + $doc->load($path); + $this->output.=$xsl->transformToXML($doc); + $this->output.=$b; + + /// Launch postaction if exists (leave this unmodified) + if ($this->getPostAction() && $result) { + return $this->launch($this->getPostAction()); + } + + return $result; + } +} +?> diff --git a/admin/xmldb/actions/generate_documentation/xmldb.xsl b/admin/xmldb/actions/generate_documentation/xmldb.xsl new file mode 100644 index 0000000000..5197eae3f4 --- /dev/null +++ b/admin/xmldb/actions/generate_documentation/xmldb.xsl @@ -0,0 +1,127 @@ + + + + + +

This documentation is generated automatically from the XMLDB database + definition. It is available only in English.

+

Note: This documentation currently does not show full details of field types.

+ +
+ + + +

+ y + +
+ + + + + + + + + + +
FieldTypeDescription
+
+ + + + + + + () + + + + + + +

Keys

+ + + + + + + + + + + + +
NameTypeField(s)ReferenceDescription
+
+ + + + + + + + + + + () + + + + + + + + + + +

Indexes

+ + + + + + + + + + +
NameTypeField(s)Description
+
+ + + + + + + + + Unique + Not unique + + + + + + + + + + + + + + +

+
+ + + +
+
+
+ +
diff --git a/admin/xmldb/actions/main_view/main_view.class.php b/admin/xmldb/actions/main_view/main_view.class.php index 14b7fbd563..b1b595eee3 100644 --- a/admin/xmldb/actions/main_view/main_view.class.php +++ b/admin/xmldb/actions/main_view/main_view.class.php @@ -51,7 +51,8 @@ class main_view extends XMLDBAction { 'checkindexes' => 'xmldb', 'checkdefaults' => 'xmldb', 'checkforeignkeys' => 'xmldb', - 'checkbigints' => 'xmldb' + 'checkbigints' => 'xmldb', + 'doc' => 'xmldb' )); } @@ -181,6 +182,16 @@ class main_view extends XMLDBAction { $b .= '[' . $this->str['save'] . ']'; } $b .= ''; + /// The document button + if ($dbdir->path_exists && + file_exists($key . '/install.xml') && + is_readable($key . '/install.xml') && + is_readable($key)) { + $b .= '[' . $this->str['doc'] . ']'; + } else { + $b .= '[' . $this->str['doc'] . ']'; + } + $b .= ''; /// The revert button if ($dbdir->path_exists && file_exists($key . '/install.xml') && diff --git a/lang/en_utf8/xmldb.php b/lang/en_utf8/xmldb.php index ad0963140c..c2b87ffe20 100644 --- a/lang/en_utf8/xmldb.php +++ b/lang/en_utf8/xmldb.php @@ -7,7 +7,6 @@ $string['back'] = 'Back'; $string['backtomainview'] = 'Back To Main'; $string['binaryincorrectlength'] = 'Incorrect length for binary field'; $string['cannotuseidfield'] = 'Cannot insert the \"id\" field. It is an autonumeric column'; -$string['cannotinstantiateclass'] = 'Error: cannot instantiate class (actions/$a->action/$a->actionclass)'; $string['change'] = 'Change'; $string['charincorrectlength'] = 'Incorrect length for char field'; $string['checkbigints'] = 'Check bigints'; @@ -53,6 +52,7 @@ $string['delete_sentence'] = 'Delete Sentence'; $string['delete_statement'] = 'Delete Statement'; $string['delete_table'] = 'Delete Table'; $string['delete_xml_file'] = 'Delete XML File'; +$string['doc'] = 'Doc'; $string['down'] = 'Down'; $string['duplicate'] = 'Duplicate'; $string['duplicatefieldname'] = 'Another field with that name exists'; @@ -75,6 +75,7 @@ $string['filenotwriteable'] = 'File not writeable'; $string['fkviolationdetails'] = 'Foreign key $a->keyname on table $a->tablename is violated by $a->numviolations out of $a->numrows rows.'; $string['floatincorrectdecimals'] = 'Incorrect number of decimals for float field'; $string['floatincorrectlength'] = 'Incorrect length for float field'; +$string['generate_documentation']='Documentation'; $string['gotolastused'] = 'Go to last used file'; $string['incorrectfieldname'] = 'Incorrect name'; $string['index'] = 'Index';