CandidatesModel::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Kineo\Model;
3
4
use Kineo\Component\Database;
5
6
class CandidatesModel extends BaseModel 
7
{
8
	protected $db;
9
	
10
	public $candidates = array();
11
	
12
	public function __construct(Database $db)
13
	{
14
		$this->db = $db;
15
	}
16
	
17
	public function getCandidatesByConstituencyId($constituencyId) 
18
	{
19
		$stmt = $this->db->prepare(
20
			"SELECT a.id, a.name, a.party FROM `tblCandidates` AS a 
21
			LEFT JOIN `tblConstituencies` AS b 
22
			ON a.constituency_id = b.id 
23
			WHERE b.id = :id
24
			ORDER BY a.name ASC"
25
		);
26
		
27
		$stmt->bindValue(':id', $constituencyId, \PDO::PARAM_INT);
28
		
29
		$stmt->execute();
30
		
31
		$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
32
		
33
		if(is_array($result) && !empty($result)) {
34
			$this->candidates = $result;
35
			
36
			return $this->candidates;
37
		} else {
38
			return false;
39
		}
40
	}
41
}