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

SkillRelProfileModel::getProfileInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 11
rs 10
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