Passed
Push — master ( 317711...bba805 )
by Yannick
10:56
created

LpItem   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 78
dl 0
loc 99
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 34 4
A update() 0 27 3
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
/**
5
 * Class lp_item
6
 *  made to manipulate data of lp_item table.
7
 *
8
 * This class is still incomplete
9
 * You can add lp_item database manipulation function here
10
 */
11
class LpItem
12
{
13
    public $c_id = 0;
14
    public $id = 0;
15
    public $lp_id = 0;
16
    public $item_type = '';
17
    public $ref = '';
18
    public $title = '';
19
    public $description = '';
20
    public $path = '';
21
    public $min_score = 0;
22
    public $max_score = 0;
23
    public $mastery_score = 0;
24
    public $parent_item_id = 0;
25
    public $previous_item_id = 0;
26
    public $next_item_id = 0;
27
    public $display_order = 0;
28
    public $prerequisite = '';
29
    public $parameters = '';
30
    public $launch_data = '';
31
    public $max_time_allowed = '';
32
    public $terms = '';
33
    public $search_did = 0;
34
    public $audio = '';
35
36
    /**
37
     * LpItem constructor.
38
     *
39
     * @param int $in_c_id
40
     * @param int $in_id
41
     */
42
    public function __construct($in_c_id = 0, $in_id = 0)
43
    {
44
        if ($in_c_id > 0 && $in_id > 0) {
45
            $item_view_table = Database::get_course_table(TABLE_LP_ITEM);
46
            $sql = "SELECT * FROM $item_view_table
47
                    WHERE
48
                        c_id=".intval($in_c_id)." AND
49
                        id=".intval($in_id);
50
51
            $res = Database::query($sql);
52
            $data = Database::fetch_array($res);
53
            if (Database::num_rows($res) > 0) {
54
                $this->c_id = $data['c_id'];
55
                $this->id = $data['id'];
56
                $this->lp_id = $data['lp_id'];
57
                $this->item_type = $data['item_type'];
58
                $this->ref = $data['ref'];
59
                $this->title = $data['title'];
60
                $this->description = $data['description'];
61
                $this->path = $data['path'];
62
                $this->min_score = $data['min_score'];
63
                $this->max_score = $data['max_score'];
64
                $this->mastery_score = $data['mastery_score'];
65
                $this->parent_item_id = $data['parent_item_id'];
66
                $this->previous_item_id = $data['previous_item_id'];
67
                $this->next_item_id = $data['next_item_id'];
68
                $this->display_order = $data['display_order'];
69
                $this->prerequisite = $data['prerequisite'];
70
                $this->parameters = $data['parameters'];
71
                $this->launch_data = $data['launch_data'];
72
                $this->max_time_allowed = $data['max_time_allowed'];
73
                $this->terms = $data['terms'];
74
                $this->search_did = $data['search_did'];
75
                $this->audio = $data['audio'];
76
            }
77
        }
78
    }
79
80
    /**
81
     * Update in database.
82
     */
83
    public function update()
84
    {
85
        $table = Database::get_course_table(TABLE_LP_ITEM);
86
        if ($this->c_id > 0 && $this->id > 0) {
87
            $sql = "UPDATE $table SET
88
                        lp_id = '".intval($this->lp_id)."' ,
89
                        item_type = '".Database::escape_string($this->item_type)."' ,
90
                        ref = '".Database::escape_string($this->ref)."' ,
91
                        title = '".Database::escape_string($this->title)."' ,
92
                        description = '".Database::escape_string($this->description)."' ,
93
                        path = '".Database::escape_string($this->path)."' ,
94
                        min_score = '".Database::escape_string($this->min_score)."' ,
95
                        max_score = '".Database::escape_string($this->max_score)."' ,
96
                        mastery_score = '".Database::escape_string($this->mastery_score)."' ,
97
                        parent_item_id = '".Database::escape_string($this->parent_item_id)."' ,
98
                        previous_item_id = '".Database::escape_string($this->previous_item_id)."' ,
99
                        next_item_id = '".Database::escape_string($this->next_item_id)."' ,
100
                        display_order = '".Database::escape_string($this->display_order)."' ,
101
                        prerequisite = '".Database::escape_string($this->prerequisite)."' ,
102
                        parameters = '".Database::escape_string($this->parameters)."' ,
103
                        launch_data = '".Database::escape_string($this->launch_data)."' ,
104
                        max_time_allowed = '".Database::escape_string($this->max_time_allowed)."' ,
105
                        terms = '".Database::escape_string($this->terms)."' ,
106
                        search_did = '".Database::escape_string($this->search_did)."' ,
107
                        audio = '".Database::escape_string($this->audio)."'
108
                    WHERE c_id=".$this->c_id." AND id=".$this->id;
109
            Database::query($sql);
110
        }
111
    }
112
}
113