public function filterCheckExists($filterChain) { $data = $this->data(); $request = ElectorRegistrationRequest::model()->with($this->nestedModels)->findByAttributes(array('user_id' => (int) $data['user_id'], 'election_id' => (int) $data['election_id'])); if ($request) { if ($request->user_id == Yii::app()->user->id) { switch ($request->status) { case ElectorRegistrationRequest::STATUS_REGISTERED: $message = 'You have been already registered as elector'; break; default: $message = 'You have already requested permission to become elector. ' . 'Election administrator will consider it soon.'; break; } } else { $message = 'Elector registration request has been already created'; } $this->renderJson(array('success' => true, 'status' => 'exists', 'message' => Yii::t('aes', $message), 'data' => array('totalCount' => 1, 'models' => $this->allToArray(array($request))))); return true; } else { $elector = Elector::model()->find('user_id = :userId AND election_id = :electionId', array(':userId' => $data['user_id'], ':electionId' => $data['election_id'])); if ($elector) { $this->renderJson(array('success' => true, 'status' => 'exists_elector', 'message' => Yii::t('aes', 'You have been already registered as elector'))); return true; } } $filterChain->run(); }
public function testUserAddsToGroupsAfterConfirmationInElectionWithConfirmationNeeded() { $userId = 2; $err = new ElectorRegistrationRequest(); $err->election_id = $electionId = 3; $err->initiator_id = $userId; $err->user_id = $userId; $err->data = array('groups' => array(1, 2)); $this->assertTrue($err->save()); $groupMembers = VoterGroupMember::model()->findAllByAttributes(array('user_id' => $userId)); $this->assertCount(0, $groupMembers); $err->status = ElectorRegistrationRequest::STATUS_REGISTERED; $this->assertTrue($err->save()); $groupMembers = VoterGroupMember::model()->findAllByAttributes(array('user_id' => $userId)); $this->assertCount(2, $groupMembers); $this->assertInstanceOf(VoterGroupMember, VoterGroupMember::model()->findByAttributes(array('user_id' => $userId, 'voter_group_id' => 1))); $this->assertInstanceOf(VoterGroupMember, VoterGroupMember::model()->findByAttributes(array('user_id' => $userId, 'voter_group_id' => 2))); }
public function autoElectorRegistrationAvailable($userId = null) { if (!$userId) { $userId = Yii::app()->user->id; } if (in_array($this->status, array(Election::STATUS_REGISTRATION, Election::STATUS_ELECTION)) && $this->voter_group_restriction == Election::VGR_NO) { $elector = Elector::model()->findByAttributes(array('user_id' => $userId, 'election_id' => $this->id)); if ($elector) { return false; } $registration = ElectorRegistrationRequest::model()->findByAttributes(array('user_id' => $userId, 'election_id' => $this->id)); if ($registration) { return false; } return true; } return false; }