[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/admin/xmldb/actions/new_sentence/ -> new_sentence.class.php (source)

   1  <?php // $Id: new_sentence.class.php,v 1.4 2007/10/10 05:25:19 nicolasconnault Exp $
   2  
   3  ///////////////////////////////////////////////////////////////////////////
   4  //                                                                       //
   5  // NOTICE OF COPYRIGHT                                                   //
   6  //                                                                       //
   7  // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
   8  //          http://moodle.com                                            //
   9  //                                                                       //
  10  // Copyright (C) 1999 onwards 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  ///////////////////////////////////////////////////////////////////////////
  26  
  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
  30  
  31  class new_sentence extends XMLDBAction {
  32  
  33      /**
  34       * Init method, every subclass will have its own
  35       */
  36      function init() {
  37          parent::init();
  38  
  39      /// Set own custom attributes
  40  
  41      /// Get needed strings
  42          $this->loadStrings(array(
  43          /// 'key' => 'module',
  44          ));
  45      }
  46  
  47      /**
  48       * Invoke method, every class will have its own
  49       * returns true/false on completion, setting both
  50       * errormsg and output as necessary
  51       */
  52      function invoke() {
  53          parent::invoke();
  54  
  55          $result = true;
  56  
  57      /// Set own core attributes
  58          $this->does_generate = ACTION_NONE;
  59          //$this->does_generate = ACTION_GENERATE_HTML;
  60  
  61      /// These are always here
  62          global $CFG, $XMLDB;
  63  
  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);
  68  
  69      /// Get the correct dirs
  70          if (!empty($XMLDB->dbdirs)) {
  71              $dbdir =& $XMLDB->dbdirs[$dirpath];
  72          } else {
  73              return false;
  74          }
  75          if (!empty($XMLDB->editeddirs)) {
  76              $editeddir =& $XMLDB->editeddirs[$dirpath];
  77              $structure =& $editeddir->xml_file->getStructure();
  78          }
  79      /// ADD YOUR CODE HERE
  80  
  81          $statementparam = required_param('statement', PARAM_CLEAN);
  82          $basesentenceparam  = optional_param('basesentence', NULL, PARAM_CLEAN);
  83  
  84          $statement =& $structure->getStatement($statementparam);
  85          $sentences =& $statement->getSentences();
  86  
  87          $sentence = NULL;
  88  
  89      /// If some sentence has been specified, create the new one
  90      /// based on it
  91          if (!empty($basesentenceparam)) {
  92              $sentence = $sentences[$basesentenceparam];
  93          }
  94      /// Else, try to create the new one based in the last
  95          if (empty($sentence) && !empty($sentences)) {
  96              $sentence = end($sentences);
  97          }
  98      /// Else, create one sentence by hand
  99          if (empty($sentence)) {
 100              $sentence = "(list, of, fields) VALUES ('list', 'of', 'values')";
 101          }
 102  
 103      /// Add the sentence to the statement
 104          $statement->addSentence($sentence);
 105  
 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);
 110  
 111      /// Launch postaction if exists (leave this here!)
 112          if ($this->getPostAction() && $result) {
 113              return $this->launch($this->getPostAction());
 114          }
 115  
 116      /// Return ok if arrived here
 117          return $result;
 118      }
 119  }
 120  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7