Passed
Push — master ( 18111a...f46ab8 )
by Julito
12:19
created

SkillRelProfileModel   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 50
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSkillsByProfile() 0 12 3
A getProfileInfo() 0 11 1
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
class SkillRelProfileModel extends Model
6
{
7
    public $columns = ['id', 'skill_id', 'profile_id'];
8
9
    /**
10
     * Constructor.
11
     */
12
    public function __construct()
13
    {
14
        $this->table = Database::get_main_table(TABLE_MAIN_SKILL_REL_PROFILE);
15
        $this->tableProfile = Database::get_main_table(TABLE_MAIN_SKILL_PROFILE);
16
    }
17
18
    /**
19
     * @param int $profileId
20
     *
21
     * @return array
22
     */
23
    public function getSkillsByProfile($profileId)
24
    {
25
        $profileId = (int) $profileId;
26
        $skills = $this->get_all(['where' => ['profile_id = ? ' => $profileId]]);
27
        $return = [];
28
        if (!empty($skills)) {
29
            foreach ($skills as $skill_data) {
30
                $return[] = $skill_data['skill_id'];
31
            }
32
        }
33
34
        return $return;
35
    }
36
37
    /**
38
     * This function is for getting profile info from profile_id.
39
     *
40
     * @param int $profileId
41
     *
42
     * @return array
43
     */
44
    public function getProfileInfo($profileId)
45
    {
46
        $profileId = (int) $profileId;
47
        $sql = "SELECT * FROM $this->table p
48
                INNER JOIN $this->tableProfile pr
49
                ON (pr.id = p.profile_id)
50
                WHERE p.profile_id = ".$profileId;
51
        $result = Database::query($sql);
52
        $profileData = Database::fetch_array($result, 'ASSOC');
53
54
        return $profileData;
55
    }
56
}
57