aboutsummaryrefslogtreecommitdiff
path: root/lib/evaluation/classes/EvaluationGroup.class.php
blob: fbe84af3bc6736d77d59e11c206eb74cc6fa0815 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
# Lifter002: TODO
# Lifter007: TODO
# Lifter003: TODO
# Lifter010: TODO
// +--------------------------------------------------------------------------+
// This file is part of Stud.IP
// Copyright (C) 2001-2004 Stud.IP
// +--------------------------------------------------------------------------+
// 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 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.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// +--------------------------------------------------------------------------+


# Include all required files ================================================ #
require_once 'lib/evaluation/evaluation.config.php';
require_once EVAL_FILE_GROUPDB;
require_once EVAL_FILE_OBJECT;
require_once EVAL_FILE_QUESTION;
# ====================================================== end: including files #


# Define constants ========================================================== #
/**
 * @const INSTANCEOF_EVALGROUP Is instance of an evaluationgroup object
 * @access public
 */
define ("INSTANCEOF_EVALGROUP", "EvaluationGroup");
# ===================================================== end: define constants #


/**
 * This class provides a group for an evaluation for the Stud.IP-project.
 *
 * @author  Alexander Willner <mail@AlexanderWillner.de>
 * @copyright   2004 Stud.IP-Project
 * @access      public
 * @package     evaluation
 *
 */

class EvaluationGroup extends EvaluationObject {

#Define all required variables ============================================= #
  /**
   * Possible Type of thechildren
   * @access   private
   * @var      string   $childType
   */
   var $childType;

  /**
   *  Is it mandatory to answer sub questions
   *  @access  private
   *  @var     boolean  $mandatory
   */
   var $mandatory;

  /**
   * ID of the templateID for the childs
   * @access private
   * @var    string   $templateID
   */
  var $templateID;
# ============================================================ end: variables #


# Define constructor and destructor ========================================= #
   /**
    * Constructor
    * @access   public
    * @param    string            $objectID       The ID of an existing group
    * @param    EvaluationObject  $parentObject   The parent object if exists
    * @param    string            $loadChildren   See const EVAL_LOAD_*_CHILDREN
    */
   function __construct($objectID = "", $parentObject = null,
                              $loadChildren = EVAL_LOAD_NO_CHILDREN) {
    /* Set default values ------------------------------------------------- */
    parent::__construct($objectID, $parentObject, $loadChildren);
    $this->instanceof = INSTANCEOF_EVALGROUP;

    $this->childType = NULL;
    $this->mandatory = NO;
    /* --------------------------------------------------------------------- */

    /* Connect to database ------------------------------------------------- */
    $this->db = new EvaluationGroupDB ();
     if ($this->db->isError ())
       return $this->throwErrorFromClass ($this->db);
     $this->init ($objectID);
    /* --------------------------------------------------------------------- */
  }
# =========================================== end: constructor and destructor #

# Define public functions =================================================== #
   /**
    * Returns wheter the childs are groups or questions
    * @access public
    */
    function getChildType () {
        return $this->childType;
    }

   /**
    * Adds a child
    * @access  public
    * @param   object  EvaluationObject &$child  The child object
    */
   function addChild (&$child) {
        parent::addChild ($child);
        $this->childType = $child->x_instanceof ();
   }

   /**
    * Defines which type of childs the group have
    * @access public
    * @param   string   $childType   The child type
    */
  function setChildType ($childType) {
    $this->childType = $childType;
  }

  /**
   * Is it mandatory to answer sub questions
   * @access public
   * @param  boolean  $boolean  true if it is mandatory
   */
  function setMandatory ($boolean) {
     $this->mandatory = $boolean == YES ? YES : NO;
  }

  /**
   * Is it mandatory to answer sub questions?
   * @access  public
   * @return  boolean  YES if it is true, else NO
   */
  function isMandatory () {
     return $this->mandatory == YES ? YES : NO;
  }

  /**
   * Gets the template id
   * @access   public
   * @return   string   The template id
   */
   function getTemplateID () {
      return $this->templateID;
   }

  /**
   * Sets the template id
   * @access   public
   * @param    string   $templateID   The template id
   */
   function setTemplateID ($templateID) {
      $newQuestionTexts =  [];

#      if ($templateID == $this->templateID)
#         return; // for performance reasons

      $this->templateID = $templateID;

      while ($child = &$this->getChild ()) {
         array_push ($newQuestionTexts, $child->getText ());
         $child->delete ();
      }

      while ($text = array_pop ($newQuestionTexts)) {
         $template = new EvaluationQuestion ($templateID, NULL,
          EVAL_LOAD_ALL_CHILDREN);
         $child = &$template->duplicate ();
         $child->setText ($text);
         $this->addChild ($child);
      }
   }
# ======================================================= end: public nctions #


# Define private functions ================================================== #
# ==================================================== end: private functions #
}

?>