]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-20749 correct error output - sentences/tables checkers fixed.
authorEloy Lafuente <stronk7@moodle.org>
Thu, 5 Nov 2009 15:40:26 +0000 (15:40 +0000)
committerEloy Lafuente <stronk7@moodle.org>
Thu, 5 Nov 2009 15:40:26 +0000 (15:40 +0000)
admin/xmldb/actions/edit_sentence_save/edit_sentence_save.class.php
admin/xmldb/actions/edit_table_save/edit_table_save.class.php

index a0354db808da7ff7cc403417de0d9e50c7fae77c..8a284ee1118e38103f2c5e9bae44090d6867fb94 100644 (file)
@@ -1,31 +1,34 @@
 <?php
 
-///////////////////////////////////////////////////////////////////////////
-//                                                                       //
-// NOTICE OF COPYRIGHT                                                   //
-//                                                                       //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
-//          http://moodle.com                                            //
-//                                                                       //
-// Copyright (C) 1999 onwards Martin Dougiamas        http://dougiamas.com  //
-//           (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com  //
-//                                                                       //
-// This program is free software; you can redistribute it and/or modify  //
-// it under the terms of the GNU General Public License as published by  //
-// the Free Software Foundation; either version 2 of the License, or     //
-// (at your option) any later version.                                   //
-//                                                                       //
-// This program is distributed in the hope that it will be useful,       //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
-// GNU General Public License for more details:                          //
-//                                                                       //
-//          http://www.gnu.org/copyleft/gpl.html                         //
-//                                                                       //
-///////////////////////////////////////////////////////////////////////////
-
-/// This class will save the changes performed to one sentence
-
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @package   xmldb-editor
+ * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+/**
+ * This class verifies all the data introduced when editing a sentence for correctness,
+ * peforming changes / displaying errors depending of the results.
+ *
+ * @package   xmldb-editor
+ * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
 class edit_sentence_save extends XMLDBAction {
 
     /**
@@ -42,6 +45,7 @@ class edit_sentence_save extends XMLDBAction {
             'missingfieldsinsentence' => 'xmldb',
             'missingvaluesinsentence' => 'xmldb',
             'wrongnumberoffieldsorvalues' => 'xmldb',
+            'back' => 'xmldb',
             'administration' => ''
         ));
     }
@@ -57,8 +61,8 @@ class edit_sentence_save extends XMLDBAction {
         $result = true;
 
     /// Set own core attributes
-        $this->does_generate = ACTION_NONE;
-        //$this->does_generate = ACTION_GENERATE_HTML;
+        //$this->does_generate = ACTION_NONE;
+        $this->does_generate = ACTION_GENERATE_HTML;
 
     /// These are always here
         global $CFG, $XMLDB;
@@ -119,16 +123,12 @@ class edit_sentence_save extends XMLDBAction {
 
         if (!empty($errors)) {
         /// Prepare the output
-            $site = get_site();
-            $PAGE->navbar->add($this->str['administration'], '../index.php');
-            $PAGE->navbar->add('XMLDB', 'index.php');
-            $PAGE->set_title("$site->shortname: XMLDB");
-            $PAGE->set_heading($site->fullname);
-            echo $OUTPUT->header();
-            notice ('<p>' .implode(', ', $errors) . '</p>
-                     <p>' . s($sentence) . '</p>',
-                    'index.php?action=edit_sentence&amp;sentence=' .$sentenceparam . '&amp;statement=' . urlencode($statementparam) . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)));
-            die; /// re-die :-P
+            $o = '<p>' .implode(', ', $errors) . '</p>
+                  <p>' . s($sentence) . '</p>';
+            $o.= '<a href="index.php?action=edit_sentence&amp;sentence=' .$sentenceparam . '&amp;statement=' .
+                  urlencode($statementparam) . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) .
+                  '">[' . $this->str['back'] . ']</a>';
+            $this->output = $o;
         }
 
     /// Continue if we aren't under errors
index 69973fadc62e30fdcfd3c921b8aa554e960e2c21..4e0c6c0c866a6009fa79c7cfc1a65bcd8cbe1169 100644 (file)
@@ -43,6 +43,7 @@ class edit_table_save extends XMLDBAction {
             'tablenameempty' => 'xmldb',
             'incorrecttablename' => 'xmldb',
             'duplicatetablename' => 'xmldb',
+            'back' => 'xmldb',
             'administration' => ''
         ));
     }
@@ -58,8 +59,8 @@ class edit_table_save extends XMLDBAction {
         $result = true;
 
     /// Set own core attributes
-        $this->does_generate = ACTION_NONE;
-        //$this->does_generate = ACTION_GENERATE_HTML;
+        //$this->does_generate = ACTION_NONE;
+        $this->does_generate = ACTION_GENERATE_HTML;
 
     /// These are always here
         global $CFG, $XMLDB, $PAGE, $OUTPUT;
@@ -104,58 +105,55 @@ class edit_table_save extends XMLDBAction {
         if (!empty($errors)) {
             $temptable = new xmldb_table($name);
             /// Prepare the output
-            $site = get_site();
-            $PAGE->navbar->add($this->str['administration'], '../index.php');
-            $PAGE->navbar->add('XMLDB', 'index.php');
-            $PAGE->set_title("$site->shortname: XMLDB");
-            $PAGE->set_heading($site->fullname);
-            echo $OUTPUT->header();
-
-            notice ('<p>' .implode(', ', $errors) . '</p>
-                     <p>' . $temptable->readableInfo() . '</p>',
-                     'index.php?action=edit_table&amp;table=' . $tableparam . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)));
-            die; /// re-die :-P
-        }
-
-    /// If there is one name change, do it, changing the prev and next
-    /// atributes of the adjacent tables
-        if ($tableparam != $name) {
-            $table->setName($name);
-            if ($table->getPrevious()) {
-                $prev =& $structure->getTable($table->getPrevious());
-                $prev->setNext($name);
-                $prev->setChanged(true);
-            }
-            if ($table->getNext()) {
-                $next =& $structure->getTable($table->getNext());
-                $next->setPrevious($name);
-                $next->setChanged(true);
+            $o = '<p>' .implode(', ', $errors) . '</p>
+                  <p>' . $temptable->getName() . '</p>';
+            $o.= '<a href="index.php?action=edit_table&amp;table=' . $tableparam .
+                 '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
+            $this->output = $o;
+
+
+    /// Continue if we aren't under errors
+        } else if (empty($errors)) {
+        /// If there is one name change, do it, changing the prev and next
+        /// atributes of the adjacent tables
+            if ($tableparam != $name) {
+                $table->setName($name);
+                if ($table->getPrevious()) {
+                    $prev =& $structure->getTable($table->getPrevious());
+                    $prev->setNext($name);
+                    $prev->setChanged(true);
+                }
+                if ($table->getNext()) {
+                    $next =& $structure->getTable($table->getNext());
+                    $next->setPrevious($name);
+                    $next->setChanged(true);
+                }
+            /// Table has changed
+                $table->setChanged(true);
             }
-        /// Table has changed
-            $table->setChanged(true);
-        }
 
-    /// Set comment
-        if ($table->getComment() != $comment) {
-            $table->setComment($comment);
-        /// Table has changed
-            $table->setChanged(true);
-        }
+        /// Set comment
+            if ($table->getComment() != $comment) {
+                $table->setComment($comment);
+            /// Table has changed
+                $table->setChanged(true);
+            }
 
-    /// Recalculate the hash
-        $structure->calculateHash(true);
+        /// Recalculate the hash
+            $structure->calculateHash(true);
 
-    /// If the hash has changed from the original one, change the version
-    /// and mark the structure as changed
-        $origstructure =& $dbdir->xml_file->getStructure();
-        if ($structure->getHash() != $origstructure->getHash()) {
-            $structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
-            $structure->setChanged(true);
-        }
+        /// If the hash has changed from the original one, change the version
+        /// and mark the structure as changed
+            $origstructure =& $dbdir->xml_file->getStructure();
+            if ($structure->getHash() != $origstructure->getHash()) {
+                $structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
+                $structure->setChanged(true);
+            }
 
-    /// Launch postaction if exists (leave this here!)
-        if ($this->getPostAction() && $result) {
-            return $this->launch($this->getPostAction());
+        /// Launch postaction if exists (leave this here!)
+            if ($this->getPostAction() && $result) {
+                return $this->launch($this->getPostAction());
+            }
         }
 
     /// Return ok if arrived here