aboutsummaryrefslogtreecommitdiff
path: root/lib/evaluation/classes/EvaluationTree.class.php
blob: a369d692a3360fef1de92788563f2b480fd90aac (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
<?php
# Lifter002: TODO
# Lifter007: TODO
# Lifter003: TODO
# Lifter010: TODO
/**
 * The treeclass for an evaluation.
 *
 * @author  mcohrs
 *
 * @copyright   2004 Stud.IP-Project
 * @access      public
 * @package     evaluation
 * @modulegroup evaluation_modules
 *
 */

// +--------------------------------------------------------------------------+
// 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_EVAL;
require_once EVAL_FILE_GROUP;
# ====================================================== end: including files #


class EvaluationTree extends TreeAbstract {
# Define all required variables ============================================= #

 /**
  * Holds the Evaluation object
  * @access   public
  * @var      object Evaluation $eval
  */
  var $eval;

 /**
  * Holds the Evaluation ID
  * @access   public
  * @var      string $evalID
  */
  var $evalID;

 /**
  * Holds the eval constructor load mode
  * @access   public
  * @var      integer $load_mode
  */
  var $load_mode;

  var $root_content;

# ============================================================ end: variables #


# Define constructor and destructor ========================================= #
  /**
    * Constructor
    * @access   public
    * @param    array  the eval's ID (optional - if not given, it must be in $_REQUEST).
    */
  function __construct( $args ) {


      if (isset($args['evalID']))
        $this->evalID = $args['evalID'];
      else
        $this->evalID = Request::option("evalID");

      $this->load_mode = ($args['load_mode'] ? $args['load_mode'] : EVAL_LOAD_NO_CHILDREN);
      if (empty($this->evalID)){
      print _("Fehler in EvaluationTree: Es wurde keine evalID übergeben");
      exit ();
      }

      /* ------------------------------------------------------------------- */
      parent::__construct();
  }
# =========================================== end: constructor and destructor #


# Define public functions =================================================== #

  /**
   * initializes the tree
   * store rows from evaluation tables in array $tree_data
   * @access public
   */
  function init() {
      /* create the evaluation -------------------> */
      $this->eval = new Evaluation( $this->evalID, NULL, $this->load_mode );
      $this->root_name = $this->eval->getTitle();
      $this->root_content = $this->eval->getText();

      /* create the tree structure ---------------> */
      parent::init();

      foreach( $this->eval->getChildren() as $group ) {
      $this->recursiveInit( $group );

      $this->tree_data[$group->getObjectID()]["text"] = $group->getText();
      $this->tree_data[$group->getObjectID()]["object"] = $group;
      $this->storeItem( $group->getObjectID(), "root",
                $group->getTitle(), $group->getPosition() );
      }
      /* <---------------------------------------- */
  }


  /**
   * initialize the sub-groups.
   *
   * @access  private
   * @param   object EvaluationGroup  the current group to be initialized.
   */
  function recursiveInit( $group ) {
      // only groups are interesting here.
      if( $group->x_instanceof() != INSTANCEOF_EVALGROUP )
      return;

      if( $children = $group->getChildren() ) {
      foreach( $children as $child ) {
          $this->recursiveInit( $child );
      }
      }

      // store current object itself
      $this->tree_data[$group->getObjectID()]["object"] = $group;

      $this->storeItem( $group->getObjectID(), $group->getParentID(),
            $group->getTitle(), $group->getPosition() );

  }

  function &getGroupObject($item_id, $renew = false){
      if (isset($this->tree_data[$item_id]['object']) && is_object($this->tree_data[$item_id]['object'])) {
          if ($renew) $this->recursiveInit(new EvaluationGroup($item_id,null,$this->load_mode));
          return $this->tree_data[$item_id]['object'];
      } else {
          $evalGroup = new EvaluationGroup($item_id, null, $this->load_mode);
          return $evalGroup;
      }
  }

# ===================================================== end: public functions #


}

?>