Esempio n. 1
0
 public function filterCheckExists($filterChain)
 {
     $data = $this->data();
     $candidate = Candidate::model()->with($this->nestedModels)->findByAttributes(array('user_id' => (int) $data['user_id'], 'election_id' => (int) $data['election_id']));
     if ($candidate) {
         if ($candidate->user_id == Yii::app()->user->id) {
             switch ($candidate->status) {
                 case Candidate::STATUS_REGISTERED:
                     $message = 'You have been already registered as candidate';
                     break;
                 case Candidate::STATUS_INVITED:
                     $message = 'Election administrator has already invited you ' . 'to become candidate. Please confirm your intention at ' . '<a href="' . Yii::app()->createAbsoluteUrl('userPage/nominations', array('id' => Yii::app()->user->id)) . '">nominations</a> page.';
                     break;
                 default:
                     $message = 'You have already applied to become candidate';
             }
         } else {
             $message = 'Candidate has been already created';
         }
         $this->renderJson(array('success' => true, 'status' => 'exists', 'message' => Yii::t('aes', $message), 'data' => array('totalCount' => 1, 'models' => $this->allToArray(array($candidate)))));
         return true;
     }
     $filterChain->run();
 }
Esempio n. 2
0
 public function testRevokeVoteFailsWithMessageBecauseOfTimeout()
 {
     $this->login("*****@*****.**", "qwerty");
     $this->open('election/candidates/1');
     $this->waitForPageToLoad("30000");
     $voteBox = "css=div.checkbox.vote";
     $this->waitForElementPresent($voteBox);
     //first vote
     $this->click($voteBox);
     $this->waitForElementContainsText($voteBox . ' span.value', '✓');
     //Simulating that timer is expired
     $candidate = Candidate::model()->findByAttributes(array('electoral_list_pos' => 1, 'election_id' => 1));
     $vote = Vote::model()->findByAttributes(array('candidate_id' => $candidate->id, 'user_id' => 1));
     $voted = new DateTime($vote->date);
     $voted->sub(new DateInterval('PT' . (Election::model()->findByPk(1)->remove_vote_time - 1) . 'M' . '54S'));
     $voted = $voted->format('Y-m-d H:i:s');
     Yii::app()->db->createCommand()->update('vote', array('date' => $voted), 'id = ' . $vote->id);
     $this->open('election/candidates/1');
     $this->sleep(7000);
     $this->click($voteBox);
     $this->assertElementPresent($errorBox = 'css=div.flash-messages div.alert-error');
     $this->assertElementContainsText($errorBox, 'Action is unavailable because of timeout');
     //check all candidates are inactive for voting
     $this->waitForCssCount($voteBox . '.inactive', 3);
 }
Esempio n. 3
0
 public function actionCandidates($id)
 {
     $model = $this->getModel($id);
     $this->layout = '//layouts/election';
     $this->election = $model;
     $candidate = false;
     if (Yii::app()->user->id) {
         $candidate = Candidate::model()->findByAttributes(array('user_id' => Yii::app()->user->id, 'election_id' => $model->id));
     }
     $this->render('candidates', array('model' => $model, 'candidate' => $candidate));
 }
Esempio n. 4
0
 public function getUsersMandates($userId)
 {
     $candidates = Candidate::model()->findAllByAttributes(array('user_id' => (int) $userId));
     $cand_ids = array();
     foreach ($candidates as $candidate) {
         $cand_ids[] = $candidate->id;
     }
     return $this->findAllByAttributes(array('candidate_id' => $cand_ids));
 }
Esempio n. 5
0
 public function checkAccess()
 {
     Yii::app()->authManager->defaultRoles = array_merge(Yii::app()->authManager->defaultRoles, array('election_updateVoteStatus'));
     $data = $this->data();
     if (!empty($_GET['id'])) {
         $id = $_GET['id'];
         $model = $this->loadOneModel((int) $id);
         if (!$model) {
             throw new Exception('Vote with id = ' . $id . ' was not found');
         }
         $candidate = $model->candidate;
         $election = $candidate->election;
     } else {
         $candidate = Candidate::model()->findByPk($data['candidate_id']);
         $election = $candidate->election;
     }
     if (!$candidate) {
         throw new Exception('Related Candidate was not found');
     }
     if (!$election) {
         throw new Exception('Related Election was not found');
     }
     $params['election'] = $election;
     $params['candidate'] = $candidate;
     if ($model) {
         $params['vote'] = $model;
         if (isset($data['status'])) {
             $params['status'] = $data['status'];
         }
     }
     if ($this->action->id == 'restCreate' && Yii::app()->user->checkAccess('election_createVote', $params)) {
         return true;
     }
     if ($this->action->id == 'restDelete' && Yii::app()->user->checkAccess('election_deleteVote', $params)) {
         return true;
     }
     if ($this->action->id == 'restUpdate' && Yii::app()->user->checkAccess('election_updateVoteStatus', $params)) {
         return true;
     }
     return false;
 }
Esempio n. 6
0
 public function actionDelete()
 {
     // check permissions
     function generateRandomString($length = 10)
     {
         $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
         $charactersLength = strlen($characters);
         $randomString = '';
         if ($length > 0) {
             for ($i = 0; $i < $length; $i++) {
                 $randomString .= $characters[rand(0, $charactersLength - 1)];
             }
         }
         return $randomString;
     }
     if (!Yii::app()->user->checkAccess('manageUser')) {
         //    Helper::authException();
     }
     // make sure the UserLoginID is defined
     //$userLoginId = Helper::verifyId($_GET['id'], 'UserLogin');
     $userLoginId = $_GET['id'];
     // get user name for message
     $UserProfile = UserProfile::model()->findByAttributes(array('UserLoginID' => $userLoginId));
     $archivedEmail = $UserProfile->Email . '_' . generateRandomString(4);
     $userName = sprintf('%s %s', $UserProfile->FirstName, $UserProfile->LastName);
     $Candidate = Candidate::model()->findByAttributes(array('UserProfileID' => $UserProfile->UserProfileID));
     if ($Candidate) {
         echo "<br><br><div style='font-size:12px; font-family:arial'>";
         echo $Candidate->FirstName . ' ' . $Candidate->LastName . ' and all other candidates reporting to this rating manager need to be reassigned before rating manager can be deleted.<br><br><a href="/user/dashboard">Back</a>';
         echo "</div>";
         die;
     }
     $candidateModel = new Candidate();
     //$planningModel = new Planning();
     $deleteCandidate = Candidate::model()->findByAttributes(array('Email' => $UserProfile->Email));
     $tempstring = generateRandomString(4);
     if ($deleteCandidate) {
         $deleteCandidate->IsActive = 0;
         $deleteCandidate->Email = $archivedEmail;
         $deleteCandidate->update(array('IsActive'));
         $deleteCandidate->update(array('Email'));
     }
     $UserProfile->Email = $archivedEmail;
     $UserProfile->update(array('Email'));
     // set user IsActive to 0
     $UserLogin = UserLogin::model()->findByPk($userLoginId);
     $UserLogin->IsActive = 0;
     $UserLogin->scenario = 'delete';
     //die($UserLogin->LoginEmail);
     if ($UserLogin->save()) {
         // set success message for user
         $UserLogin->LoginEmail = $archivedEmail;
         $UserLogin->update(array('LoginEmail'));
         //Update doesn't test Rules.. Save does
         //  Yii::app()->user->setFlash('success', sprintf('The user \'%s\' has been deactivated.', $userName));
     } else {
         // set success message for user
         // Yii::app()->user->setFlash('failure', sprintf('The user \'%s\' could not be deactivated.', $userName));
     }
     // return to dashboard
     $this->redirect($this->createUrl('user/dashboard'));
 }
Esempio n. 7
0
 public function actionDashboard()
 {
     if (Yii::app()->user->agreeToTerms == 0) {
         $this->redirect(Yii::app()->createUrl('company/terms'));
     }
     $criteria = new CDbCriteria();
     //$criteria->condition = 'Candidate.CompanyID = :CompanyID';
     $criteria->params = array(':CompanyID' => Yii::app()->user->companyID);
     $candidatesModels = Candidate::model()->findAllByAttributes(array(), $criteria);
     $candidates = array();
     foreach (array_keys($candidatesModels) as $key) {
         $candidate = $candidatesModels[$key];
         $candidates[$key] = new stdClass();
         $candidates[$key]->ID = $candidate->CandidateID;
         $candidates[$key]->Name = sprintf('%s, %s', $candidate->LastName, $candidate->FirstName);
         $candidates[$key]->Email = $candidate->Email;
         $candidates[$key]->UserProfileID = $candidate->UserProfileID;
         $UserProfile = userProfile::model()->findbypk($candidate->UserProfileID);
         if (!isset($UserProfile)) {
             $candidates[$key]->RatingManager = "Rating Manager";
         } else {
             $candidates[$key]->RatingManager = $UserProfile->FirstName . " " . $UserProfile->LastName;
         }
         $candidates[$key]->Title = $candidate->Title;
         $candidates[$key]->HireDate = $candidate->HireDate;
         $candidates[$key]->EmployeeID = $candidate->EmployeeID;
     }
     $this->render('dashboard', array('candidates' => $candidates));
 }