3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
10 // Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
11 // (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
13 // This program is free software; you can redistribute it and/or modify //
14 // it under the terms of the GNU General Public License as published by //
15 // the Free Software Foundation; either version 2 of the License, or //
16 // (at your option) any later version. //
18 // This program is distributed in the hope that it will be useful, //
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
21 // GNU General Public License for more details: //
23 // http://www.gnu.org/copyleft/gpl.html //
25 ///////////////////////////////////////////////////////////////////////////
27 /// This class will save the changes performed to the name and comment of
30 class edit_statement_save
extends XMLDBAction
{
33 * Init method, every subclass will have its own
38 /// Set own custom attributes
40 /// Get needed strings
41 $this->loadStrings(array(
42 'administration' => ''
47 * Invoke method, every class will have its own
48 * returns true/false on completion, setting both
49 * errormsg and output as necessary
56 /// Set own core attributes
57 $this->does_generate
= ACTION_NONE
;
58 //$this->does_generate = ACTION_GENERATE_HTML;
60 /// These are always here
63 /// Do the job, setting result as needed
66 $dirpath = required_param('dir', PARAM_PATH
);
67 $dirpath = $CFG->dirroot
. stripslashes_safe($dirpath);
69 $statementparam = strtolower(required_param('statement', PARAM_CLEAN
));
70 $name = trim(strtolower(required_param('name', PARAM_CLEAN
)));
71 $comment = required_param('comment', PARAM_CLEAN
);
72 $comment = stripslashes_safe($comment);
74 $editeddir =& $XMLDB->editeddirs
[$dirpath];
75 $structure =& $editeddir->xml_file
->getStructure();
76 $statement =& $structure->getStatement($statementparam);
78 $errors = array(); /// To store all the errors found
80 /// If there is one name change, do it, changing the prev and next
81 /// atributes of the adjacent tables
82 if ($statementparam != $name) {
83 $statement->setName($name);
84 if ($statement->getPrevious()) {
85 $prev =& $structure->getStatement($statement->getPrevious());
86 $prev->setNext($name);
87 $prev->setChanged(true);
89 if ($statement->getNext()) {
90 $next =& $structure->getStatement($statement->getNext());
91 $next->setPrevious($name);
92 $next->setChanged(true);
97 $statement->setComment($comment);
99 /// Launch postaction if exists (leave this here!)
100 if ($this->getPostAction() && $result) {
101 return $this->launch($this->getPostAction());
104 /// Return ok if arrived here