forked from OpenStackweb/openstack-org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCandidate.php
More file actions
108 lines (94 loc) · 3.37 KB
/
Copy pathCandidate.php
File metadata and controls
108 lines (94 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* Copyright 2014 Openstack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
class Candidate extends DataObject implements ICandidate
{
static $db = array(
'Nominated' => 'Boolean',
'HasAcceptedNomination' => 'Boolean',
'RelationshipToOpenStack' => 'HTMLText', // Candidate's answer to the application question
'Experience' => 'HTMLText',
'BoardsRole' => 'HTMLText',
'TopPriority' => 'HTMLText',
'IsGoldMemberCandidate' => 'Boolean'
);
static $has_one = array(
'Election' => 'ElectionPage', // Used to track which election this candidate belongs to.
'Member' => 'Member' // Links the candidate to the member record
);
static $singular_name = 'Candidate';
static $plural_name = 'Candidates';
static $defaults = array(
"Nominated" => 1,
);
function CurrentElection()
{
// Load the election system
$Elections = ElectionSystem::get()->first();
if(!$Elections) return false;
return $Elections->CurrentElection();
}
// Return the number of nominations for this candidate
function countNominations()
{
$current_election = $this->CurrentElection();
if(!$current_election) return 0;
$Nominations = $current_election->CandidateNominations("`CandidateID` = " . $this->MemberID);
return $Nominations->Count();
}
// Return whether the logged-in candidate has nominated this person in the current election
function hasNominated()
{
if ($LoggedInMemberID = Member::currentUserID()) {
$current_election = $this->CurrentElection();
if(!$current_election) return false;
return $current_election->CandidateNominations("`CandidateID` = " . $this->MemberID . " AND `MemberID` = " . $LoggedInMemberID);
}
}
// Return if this candidate has received more than 10 nominations
function MoreThanTen()
{
$current_election = $this->CurrentElection();
if(!$current_election) return false;
$Nominations = $current_election->CandidateNominations("`CandidateID` = " . $this->MemberID);
return ($Nominations->Count() >= 10);
}
// Return if this candidate has received more than 10 nominations
function LessThanTen()
{
$current_election = $this->CurrentElection();
if(!$current_election) return false;
$Nominations = $current_election->CandidateNominations("`CandidateID` = " . $this->MemberID);
return ($Nominations->Count() < 10);
}
// Return the nominations for this candidate
function getNominations()
{
$current_election = $this->CurrentElection();
if(!$current_election) return false;
return $current_election->CandidateNominations("`CandidateID` = " . $this->MemberID);
}
/**
* @param ICommunityMember $member
* @return void
*/
public function updateMember(ICommunityMember $member){
AssociationFactory::getInstance()->getMany2OneAssociation($this,'Member')->setTarget($member);
}
/**
* @return int
*/
public function getIdentifier(){
return (int)$this->getField('ID');
}
}