Ejemplo n.º 1
0
 function CurrentElection()
 {
     // Load the election system
     $Elections = ElectionSystem::get()->first();
     if ($Elections && $Elections->CurrentElectionID != 0) {
         return $Elections->CurrentElection();
     }
 }
Ejemplo n.º 2
0
 function CurrentElection()
 {
     // Load the election system
     $Elections = ElectionSystem::get()->first();
     if (!$Elections) {
         return false;
     }
     return $Elections->CurrentElection();
 }
Ejemplo n.º 3
0
 /**
  * @return ICandidate|null
  */
 public function getCurrentCandidate()
 {
     $res = null;
     $election = ElectionSystem::get()->first();
     if ($election && $election->CurrentElectionID != 0) {
         $current_election = $election->CurrentElection();
         if (!is_null($current_election)) {
             $candidate = Candidate::get()->filter(array('MemberID' => $this->getIdentifier(), 'ElectionID' => $current_election->ID))->first();
             $res = $candidate;
             if (!is_null($candidate)) {
                 UnitOfWork::getInstance()->setToCache($candidate);
                 UnitOfWork::getInstance()->scheduleForUpdate($candidate);
             }
         }
     }
     return $res;
 }
Ejemplo n.º 4
0
 function saveCandidateApplicationForm($data, $form)
 {
     $currentMember = Member::currentUser();
     // A user is logged in
     if ($currentMember) {
         // Load the election system
         $Elections = ElectionSystem::get()->first();
         $CurrentElection = $Elections->CurrentElection();
         if ($Candidate = Candidate::get()->filter(array('MemberID' => $currentMember->ID, 'ElectionID' => $CurrentElection->ID))->first()) {
             // Candidate profile exists
             // Clean up entries ////////////////
             // Set up HTML Purifier
             $config = HTMLPurifier_Config::createDefault();
             // Remove any CSS or inline styles
             $config->set('CSS.AllowedProperties', array());
             $purifier = new HTMLPurifier($config);
             // Clean Bio field
             if ($data["Bio"]) {
                 $currentMember->Bio = $purifier->purify($data["Bio"]);
                 $currentMember->write();
             }
             // Clean RelationshipToOpenStack field
             if ($toClean = $data["RelationshipToOpenStack"]) {
                 $Candidate->RelationshipToOpenStack = $purifier->purify($toClean);
             }
             // Clean Experience field
             if ($toClean = $data["Experience"]) {
                 $Candidate->Experience = $purifier->purify($toClean);
             }
             // Clean BoardsRole field
             if ($toClean = $data["BoardsRole"]) {
                 $Candidate->BoardsRole = $purifier->purify($toClean);
             }
             // Clean HasAcceptedNomination field
             if ($toClean = $data["TopPriority"]) {
                 $Candidate->TopPriority = $purifier->purify($toClean);
             }
             $Candidate->write();
             $questions = array('Bio' => 'Bio', 'RelationshipToOpenStack' => 'RelationshipToOpenStack', 'Experience' => 'Experience', 'BoardsRole' => 'BoardsRole', 'TopPriority' => 'TopPriority');
             // Must answer all questions, but can save work as they go, so we're going to check here rather than set up validators
             if (strlen($data['Bio']) < 4 || strlen($data['RelationshipToOpenStack']) < 4 || strlen($data['Experience']) < 4 || strlen($data['BoardsRole']) < 4 || strlen($data['TopPriority']) < 4) {
                 $Candidate->HasAcceptedNomination = FALSE;
                 $form->saveInto($Candidate);
                 $Candidate->write();
                 $form->clearMessage();
                 $form->sessionMessage("Your edits have been saved but you will need to provide full answers to all these questions to be eligible as a candidate.", "bad");
                 $this->redirectBack();
                 return;
             }
             $Candidate->HasAcceptedNomination = TRUE;
             $Candidate->write();
             $form->clearMessage();
             $this->redirect($this->Link() . 'election/');
         } else {
             $form->clearMessage();
             $form->sessionMessage('There was an error saving your edits.', "bad");
             $this->redirectBack();
         }
     }
 }