1<?php
2
3/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5/**
6 * Skill tresholds for 360 surveys
7 *
8 * @author Alex Killing <alex.killing@gmx.de>
9 * @version $Id$
10 * @ingroup ModulesSurvey
11 */
12class ilSurveySkillThresholds
13{
14    /**
15     * @var ilDB
16     */
17    protected $db;
18
19
20    /**
21     * Constructor
22     *
23     * @param
24     * @return
25     */
26    public function __construct(ilObjSurvey $a_survey)
27    {
28        global $DIC;
29
30        $this->db = $DIC->database();
31        $this->survey = $a_survey;
32        $this->read();
33    }
34
35    /**
36     * Read
37     *
38     * @param
39     * @return
40     */
41    public function read()
42    {
43        $ilDB = $this->db;
44
45        $set = $ilDB->query(
46            "SELECT * FROM svy_skill_threshold " .
47            " WHERE survey_id = " . $ilDB->quote($this->survey->getId(), "integer")
48        );
49        while ($rec = $ilDB->fetchAssoc($set)) {
50            $this->threshold[$rec['level_id']][$rec['tref_id']] =
51                $rec['threshold'];
52        }
53    }
54
55    /**
56     * Get thresholds
57     *
58     * @param
59     * @return
60     */
61    public function getThresholds()
62    {
63        return $this->threshold;
64    }
65
66    /**
67     * Write threshold
68     *
69     * @param
70     * @return
71     */
72    public function writeThreshold($a_base_skill_id, $a_tref_id, $a_level_id, $a_threshold)
73    {
74        $ilDB = $this->db;
75
76        $ilDB->replace(
77            "svy_skill_threshold",
78            array("survey_id" => array("integer", $this->survey->getId()),
79                "base_skill_id" => array("integer", (int) $a_base_skill_id),
80                "tref_id" => array("integer", (int) $a_tref_id),
81                "level_id" => array("integer", (int) $a_level_id)
82                ),
83            array("threshold" => array("integer", (int) $a_threshold))
84        );
85    }
86}
87