1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionSolutionComparisonExpression.php';
5
6/**
7 * @author		Björn Heyser <bheyser@databay.de>
8 * @version		$Id$
9 *
10 * @package     Modules/Test
11 */
12class ilAssQuestionSolutionComparisonExpressionList
13{
14    /**
15     * @var ilDBInterface
16     */
17    protected $db;
18
19    /**
20     * @var integer
21     */
22    private $questionId;
23
24    /**
25     * @var integer
26     */
27    private $skillBaseId;
28
29    /**
30     * @var integer
31     */
32    private $skillTrefId;
33
34    /**
35     * @var array
36     */
37    private $expressions;
38
39    /**
40     * @param ilDBInterface $db
41     */
42    public function __construct(ilDBInterface $db)
43    {
44        $this->db = $db;
45
46        $this->questionId = null;
47        $this->skillBaseId = null;
48        $this->skillTrefId = null;
49
50        $this->expressions = array();
51    }
52
53    public function load()
54    {
55        $query = "
56			SELECT *
57			FROM qpl_qst_skl_sol_expr
58			WHERE question_fi = %s AND skill_base_fi = %s AND skill_tref_fi = %s
59		";
60
61        $res = $this->db->queryF(
62            $query,
63            array('integer', 'integer', 'integer'),
64            array($this->getQuestionId(), $this->getSkillBaseId(), $this->getSkillTrefId())
65        );
66
67        while ($row = $this->db->fetchAssoc($res)) {
68            $expression = new ilAssQuestionSolutionComparisonExpression();
69            $expression->setDb($this->db);
70            $expression->initInstanceFromArray($row);
71
72            $this->add($expression);
73        }
74    }
75
76    public function save()
77    {
78        $this->delete();
79
80        foreach ($this->expressions as $orderIndex => $expression) {
81            /* @var ilAssQuestionSolutionComparisonExpression $expression */
82
83            $expression->setQuestionId($this->getQuestionId());
84            $expression->save();
85        }
86    }
87
88    public function delete()
89    {
90        $query = "
91			DELETE FROM qpl_qst_skl_sol_expr
92			WHERE question_fi = %s AND skill_base_fi = %s AND skill_tref_fi = %s
93		";
94
95        $this->db->manipulateF(
96            $query,
97            array('integer', 'integer', 'integer'),
98            array($this->getQuestionId(), $this->getSkillBaseId(), $this->getSkillTrefId())
99        );
100    }
101
102    public function add(ilAssQuestionSolutionComparisonExpression $expression)
103    {
104        $expression->setDb($this->db);
105        $expression->setQuestionId($this->getQuestionId());
106        $expression->setSkillBaseId($this->getSkillBaseId());
107        $expression->setSkillTrefId($this->getSkillTrefId());
108
109        $this->expressions[$expression->getOrderIndex()] = $expression;
110    }
111
112    public function get()
113    {
114        return $this->expressions;
115    }
116
117    public function reset()
118    {
119        $this->expressions = array();
120    }
121
122    /**
123     * @return int
124     */
125    public function getQuestionId()
126    {
127        return $this->questionId;
128    }
129
130    /**
131     * @param int $questionId
132     */
133    public function setQuestionId($questionId)
134    {
135        $this->questionId = $questionId;
136    }
137
138    /**
139     * @return int
140     */
141    public function getSkillBaseId()
142    {
143        return $this->skillBaseId;
144    }
145
146    /**
147     * @param int $skillBaseId
148     */
149    public function setSkillBaseId($skillBaseId)
150    {
151        $this->skillBaseId = $skillBaseId;
152    }
153
154    /**
155     * @return int
156     */
157    public function getSkillTrefId()
158    {
159        return $this->skillTrefId;
160    }
161
162    /**
163     * @param int $skillTrefId
164     */
165    public function setSkillTrefId($skillTrefId)
166    {
167        $this->skillTrefId = $skillTrefId;
168    }
169}
170