function saveNomination() { // Grab candidate ID from the URL $CandidateID = $this->request->param("ID"); $NominationStatus = $this->validateNomation($CandidateID); // Check to see if this is a valid nomination if ($NominationStatus == 'VALID') { // Grab the currently logged in member $currentMember = Member::currentUser(); $CurrentElection = $this->CurrentElection(); // Record the nomination $CandidateNomination = new CandidateNomination(); $CandidateNomination->MemberID = Member::currentUserID(); $CandidateNomination->CandidateID = $CandidateID; $CandidateNomination->ElectionID = $CurrentElection->ID; $CandidateNomination->write(); // Create a candidate record for the nominations page if one does not exist $Candidate = Candidate::get()->filter(array('MemberID' => $CandidateID, 'ElectionID' => $CurrentElection->ID))->first(); if (!$Candidate) { // Create a new candidate entry $Candidate = new Candidate(); $Candidate->MemberID = $CandidateID; $Candidate->ElectionID = $CurrentElection->ID; $Candidate->write(); } // Log this new candidate $logLine = $currentMember->FirstName . " " . $currentMember->Surname . " nominated " . $Candidate->Member()->FirstName . " " . $Candidate->Member()->Surname . " (ID " . $Candidate->Member()->ID . ") on " . $CandidateNomination->Created . " \n"; $file = fopen(ASSETS_PATH . '/candidate-nomination-log.txt', 'a'); fwrite($file, $logLine); fclose($file); // Email the member // In dev and testing, send the nomination emails to the person who did the nomination $To = $currentMember->Email; // In live mode, send the email to the candidate if (Director::isLive()) { $To = $Candidate->Member()->Email; } $Subject = "You have been nominated in the " . $CurrentElection->Title; $email = EmailFactory::getInstance()->buildEmail(CANDIDATE_NOMINATION_FROM_EMAIL, $To, $Subject); $email->setTemplate('NominationEmail'); // Gather Data to send to template $data["Candidate"] = $Candidate; $data["Election"] = $CurrentElection; $email->populateTemplate($data); $email->send(); $this->setMessage('Success', "You've just nominated " . $Candidate->Member()->FirstName . ' for the OpenStack Board.'); $this->redirect($this->Link('candidateStats/' . $Candidate->Member()->ID)); } elseif ($NominationStatus = 'ALREADY NOMINATED') { $this->setMessage('Error', "Oops, you have already nominated this person."); $this->redirect($this->Link()); } elseif ($NominationStatus = 'INVALID CANDIDATE') { $this->setMessage('Error', "Oops, no candidate was selected."); $this->redirect($this->Link()); } else { $this->setMessage('Error', "There was an error logging your nomination."); $this->redirect($this->Link()); } }
function CandidateApplicationForm() { $CandidateApplicationForm = new CandidateApplicationForm($this, 'CandidateApplicationForm'); $CandidateApplicationForm->disableSecurityToken(); // Load the election system $Elections = ElectionSystem::get()->first(); $CurrentElection = $Elections->CurrentElection(); $currentMember = Member::currentUser(); // Check for login if ($currentMember) { $Candidate = Candidate::get()->filter(array('MemberID' => $currentMember->ID, 'ElectionID' => $CurrentElection->ID))->first(); // Fill in the form if ($Candidate) { $CandidateApplicationForm->loadDataFrom($Candidate, False); $CandidateApplicationForm->loadDataFrom($currentMember, False); return $CandidateApplicationForm; } elseif ($this->request->isPost()) { // SS is returning to the form controller to post data return $CandidateApplicationForm; } else { // No candidate for this member; create a new candidate entry $Candidate = new Candidate(); $Candidate->MemberID = $currentMember->ID; $Candidate->ElectionID = $CurrentElection->ID; $Candidate->write(); $CandidateApplicationForm->loadDataFrom($currentMember, False); return $CandidateApplicationForm; } } }