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 create a new default sentence to be edited.
28 /// If one previous sentence key is specified, it's used as
29 /// base to build the new setence, else a blank one is used
31 class new_sentence
extends XMLDBAction
{
34 * Init method, every subclass will have its own
39 /// Set own custom attributes
41 /// Get needed strings
42 $this->loadStrings(array(
43 /// 'key' => 'module',
48 * Invoke method, every class will have its own
49 * returns true/false on completion, setting both
50 * errormsg and output as necessary
57 /// Set own core attributes
58 $this->does_generate
= ACTION_NONE
;
59 //$this->does_generate = ACTION_GENERATE_HTML;
61 /// These are always here
64 /// Do the job, setting result as needed
65 /// Get the dir containing the file
66 $dirpath = required_param('dir', PARAM_PATH
);
67 $dirpath = $CFG->dirroot
. stripslashes_safe($dirpath);
69 /// Get the correct dirs
70 if (!empty($XMLDB->dbdirs
)) {
71 $dbdir =& $XMLDB->dbdirs
[$dirpath];
75 if (!empty($XMLDB->editeddirs
)) {
76 $editeddir =& $XMLDB->editeddirs
[$dirpath];
77 $structure =& $editeddir->xml_file
->getStructure();
79 /// ADD YOUR CODE HERE
81 $statementparam = required_param('statement', PARAM_CLEAN
);
82 $basesentenceparam = optional_param('basesentence', NULL, PARAM_CLEAN
);
84 $statement =& $structure->getStatement($statementparam);
85 $sentences =& $statement->getSentences();
89 /// If some sentence has been specified, create the new one
91 if (!empty($basesentenceparam)) {
92 $sentence = $sentences[$basesentenceparam];
94 /// Else, try to create the new one based in the last
95 if (empty($sentence) && !empty($sentences)) {
96 $sentence = end($sentences);
98 /// Else, create one sentence by hand
99 if (empty($sentence)) {
100 $sentence = "(list, of, fields) VALUES ('list', 'of', 'values')";
103 /// Add the sentence to the statement
104 $statement->addSentence($sentence);
106 /// We have one new sentence, so the statement and the structure has changed
107 $statement->setChanged(true);
108 $structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
109 $structure->setChanged(true);
111 /// Launch postaction if exists (leave this here!)
112 if ($this->getPostAction() && $result) {
113 return $this->launch($this->getPostAction());
116 /// Return ok if arrived here