Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / admin / xmldb / actions / new_sentence / new_sentence.class.php
blob502ba1ff9597a706a941d7763df1a127874154af
1 <?php // $Id$
3 ///////////////////////////////////////////////////////////////////////////
4 // //
5 // NOTICE OF COPYRIGHT //
6 // //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
9 // //
10 // Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
11 // (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
12 // //
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. //
17 // //
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: //
22 // //
23 // http://www.gnu.org/copyleft/gpl.html //
24 // //
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 {
33 /**
34 * Init method, every subclass will have its own
36 function init() {
37 parent::init();
39 /// Set own custom attributes
41 /// Get needed strings
42 $this->loadStrings(array(
43 /// 'key' => 'module',
44 ));
47 /**
48 * Invoke method, every class will have its own
49 * returns true/false on completion, setting both
50 * errormsg and output as necessary
52 function invoke() {
53 parent::invoke();
55 $result = true;
57 /// Set own core attributes
58 $this->does_generate = ACTION_NONE;
59 //$this->does_generate = ACTION_GENERATE_HTML;
61 /// These are always here
62 global $CFG, $XMLDB;
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];
72 } else {
73 return false;
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();
87 $sentence = NULL;
89 /// If some sentence has been specified, create the new one
90 /// based on it
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
117 return $result;