/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store_a()
 {
     $data = Input::get('data');
     foreach ($data as $data_array1) {
         $candidate = new Candidate();
         $candidate->cname = $data_array1[0];
         $candidate->job_title = $data_array1[1];
         $candidate->sex = $data_array1[2];
         $candidate->vote_id = 42;
         $candidate->total_count = 0;
         $candidate->save();
     }
 }
Example #2
0
    $account->finish_at = "0000-00-00 00:00:00";
    $account->vote()->associate($vote);
    $account->save();
    $account2 = new Account();
    $account2->username = '******';
    $account2->vote_id = 2;
    $account2->finish_at = "0000-00-00 00:00:00";
    $account2->vote()->associate($vote);
    $account2->save();
    $candidate = new Candidate();
    $candidate->cname = 'Naruto Uzumaki';
    $candidate->job_title = 'yy';
    $candidate->sex = '男';
    $candidate->vote_id = 49;
    $candidate->total_count = 2;
    $candidate->save();
    $candidate->accounts()->save($account);
    $candidate->accounts()->save($account2);
    // $account = Account::find(1);
    // $candidate = Candidate::find(10);
    // $candidate->accounts()->detach();
    // // return $candidate->accounts;
    // return Candidate::with('accounts')->find($candidate->id);
});
Route::get('/test2', function () {
    function GeraHash($qx)
    {
        //Under the string $Caracteres you write all the characters you want to be used to randomly generate the code.
        $Caracteres = 'ABCDEFGHIJKLMPQRSTUVXWYZ123456789';
        $QuantidadeCaracteres = strlen($Caracteres);
        $QuantidadeCaracteres--;
Example #3
0
 public function actionCreate()
 {
     // check permissions
     //        if (!Yii::app()->user->checkAccess('manageUser')) {
     //            Helper::authException();
     //        }
     // models
     $UserLogin = new UserLogin();
     $UserProfile = new UserProfile();
     $criteria3 = new CDbCriteria();
     $criteria3->condition = '(companyID = :companyID AND IsActive=1)';
     $criteria3->params = array(':companyID' => Yii::app()->user->companyID);
     $criteria3->order = 'Email';
     $userManagers = UserProfile::model()->with('userLogin')->findAllByAttributes(array(), $criteria3);
     $managersArray = array();
     $managersArray[0] = "Please Select...";
     foreach ($userManagers as $UserManager) {
         //if ($UserManager->ManagerEmail == '') {
         //$managersArray[$UserManager->Email] = $UserManager->Email;
         $managersArray[$UserManager->Email] = $UserManager->Email;
         //} elseif (Helper::hasRole('lacekAdministrator')) {
         //    $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc;
         // }
     }
     // add default (empty value) to front of array
     $managerArray = $managersArray;
     // role array for select
     $userRoles = UserRole::model()->findAll();
     $rolesArray = array();
     foreach ($userRoles as $UserRole) {
         if ($UserRole->RoleType != 'lacekAdministrator') {
             $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc;
         } elseif (Helper::hasRole('lacekAdministrator')) {
             $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc;
         }
     }
     // add default (empty value) to front of array
     $rolesArray = $rolesArray;
     // form processing
     if (isset($_POST['UserLogin'], $_POST['UserProfile'])) {
         // redirect to the dashboard if 'Cancel' button clicked
         if (isset($_POST['button-cancel'])) {
             $this->redirect($this->createUrl('user/dashboard'));
         }
         // set UserLogin attributes and scenario
         $UserLogin->attributes = $_POST['UserLogin'];
         $UserLogin->IsPasswordReset = 1;
         // force password reset on first login
         $UserLogin->IsActive = 1;
         $UserLogin->scenario = 'create';
         $UserLogin->UserRoleID = 1;
         // set UserProfile attributes
         $UserProfile->attributes = $_POST['UserProfile'];
         $UserProfile->CompanyID = Yii::app()->user->companyID;
         $UserProfile->Email = $UserLogin->LoginEmail;
         // validate form submission
         $valid = $UserLogin->validate();
         $valid = $UserProfile->validate() && $valid;
         if ($valid) {
             // save UserLogin
             if (!$UserLogin->save(false)) {
                 throw new CHttpException(400, 'Error when trying to create user.');
             }
             // save UserProfile
             $UserProfile->UserLoginID = $UserLogin->UserLoginID;
             // set newly generated EventID
             if (!$UserProfile->save(false)) {
                 throw new CHttpException(400, 'Error when trying to create user.');
             }
             if ($UserProfile->ManagerEmail) {
                 $UserProfilex = UserProfile::model()->findByAttributes(array('Email' => $UserProfile->ManagerEmail));
                 $candidateModel = new Candidate();
                 $candidateModel->CompanyID = $UserProfile->CompanyID;
                 $candidateModel->EmployeeID = $UserProfile->EmployeeID;
                 $candidateModel->FirstName = $UserProfile->FirstName;
                 $candidateModel->MiddleName = $UserProfile->MiddleName;
                 $candidateModel->LastName = $UserProfile->LastName;
                 $candidateModel->Title = $UserProfile->Title;
                 $candidateModel->Email = $UserProfile->Email;
                 $candidateModel->CompanyPositionID = 1;
                 $candidateModel->HireDate = date("Y-m-d");
                 $candidateModel->PositionDate = date("Y-m-d");
                 $candidateModel->IsActive = 1;
                 $candidateModel->UserProfileID = $UserProfilex->UserProfileID;
                 //$candidateModel->UserProfileId=2;
                 //print_r($candidateModel);
                 // die($UserProfilex->UserProfileID);
                 // if ($candidateModel->validate()) {
                 //      if ($candidateModel->save()) {
                 $candidateModel->save();
                 $performanceModel = new Performance();
                 $ratingModel = new Rating();
                 $planningModel = new Planning();
                 $currentYear = date('Y');
                 // insert new record
                 $performanceModel->CandidateID = $candidateModel->CandidateID;
                 $performanceModel->PerformanceYear = $currentYear;
                 $ratingModel->CandidateID = $candidateModel->CandidateID;
                 $ratingModel->RatingYear = $currentYear;
                 $planningModel->CandidateID = $candidateModel->CandidateID;
                 $planningModel->PlanningYear = $currentYear;
                 $planningModel->CurrentPositionLevel = 3;
                 $planningModel->NextStepPositionLevel = 3;
                 $planningModel->LongTermPositionLevel = 3;
                 $performanceModel->save();
                 $ratingModel->save();
                 $planningModel->save();
                 //}
                 //}
                 // else
                 //{
                 //  $errores = $candidateModel->getErrors();
                 // print_r($errores);
                 // die();
                 // }
             }
             // set success message for user
             Yii::app()->user->setFlash('success', 'A new user was successfully created.');
             // return to empty create user form if adding another, else go to user dashboard
             if (isset($_POST['button-submit-add'])) {
                 $this->redirect($this->createUrl('user/create'));
             } else {
                 $this->redirect($this->createUrl('user/dashboard'));
             }
         }
     }
     // clear password
     $UserLogin->UserPassword = null;
     // render view
     $this->render('create', array('UserLogin' => $UserLogin, 'UserProfile' => $UserProfile, 'rolesArray' => $rolesArray, 'managersArray' => $managerArray));
 }
 public function saveCandidate()
 {
     $validator = Validator::make(Input::all(), array('name' => 'required', 'email' => 'required|email'));
     // check for the required fields before doing anything else
     if ($validator->fails()) {
         return Redirect::back()->withInput()->withErrors($validator->messages());
     }
     // Check to see if we already have a candidate at this email address. There can be only one
     $email = Input::get('email');
     $existingCandidates = Candidate::where('email', '=', $email)->first();
     if ($existingCandidates) {
         $messageBag = new Illuminate\Support\MessageBag();
         $messageBag->add('error', "You have already registered as a candidate, please log in.");
         return Redirect::back()->withErrors($messageBag);
     }
     $c = new Candidate();
     $name = explode(' ', Input::get('name'));
     $name = $name[0];
     // Prep client data for save
     $c->email = Input::get('email');
     $c->name = $name;
     $c->surname = $name[1];
     $c->password = Hash::make(Input::get('password'));
     $c->current_position = Input::get('current_position');
     $c->phone = Input::get('phone');
     $c->sendjobs = Input::get('sendjobs', 0);
     if (Input::hasFile('cv')) {
         $newfilename = Str::slug($name) . '_cv_' . uniqid() . '.' . Input::file('cv')->getClientOriginalExtension();
         Input::file('cv')->move(public_path() . '/uploads/cvs/', $newfilename);
         $c->cv = $newfilename;
         // Send email to KDC
         Candidate::sendBecomeCandidate(Input::all(), $newfilename);
     } else {
         // Send email to KDC
         Candidate::sendBecomeCandidate(Input::all(), '');
     }
     $c->save();
     // Send activation email
     Candidate::sendActivation($c->id);
     // Add the candidate to the session - using this rather than full on auth as that's already being used by admins to access the CMS (dashboard)
     // Session::put('candidate', $c);
     // Just take them to the front page again for now.
     return Redirect::to('/')->with('info', 'Thank you for your registration – we’ll send you your login details as soon as we can.');
 }
Example #5
0
 public function actionAddcandidate()
 {
     if (!isset(Yii::app()->user->userProfileID)) {
         $this->redirect('/user/login');
     }
     // renders the view file 'protected/views/site/index.php'
     // using the default layout 'protected/views/layouts/main.php'
     $candidateModel = new Candidate();
     $performanceModel = new Performance();
     $ratingModel = new Rating();
     $planningModel = new Planning();
     if (isset($_POST['Candidate'])) {
         $candidateModel->attributes = $_POST['Candidate'];
         $candidateModel->IsActive = 1;
         //$candidateModel->UserProfileID = Yii::app()->user->userProfileID;
         $candidateModel->CompanyID = Yii::app()->user->companyID;
         if ($candidateModel->validate()) {
             if ($candidateModel->save()) {
                 $currentYear = date('Y');
                 // insert new record
                 $performanceModel->CandidateID = $candidateModel->CandidateID;
                 $performanceModel->PerformanceYear = $currentYear;
                 $ratingModel->CandidateID = $candidateModel->CandidateID;
                 $ratingModel->RatingYear = $currentYear;
                 $planningModel->CandidateID = $candidateModel->CandidateID;
                 $planningModel->PlanningYear = $currentYear;
                 $planningModel->CurrentPositionLevel = $_POST['Candidate']['CompanyPositionID'];
                 if ($_POST['Candidate']['CompanyPositionID'] == 5) {
                     $planningModel->NextStepPositionLevel = 5;
                     $planningModel->LongTermPositionLevel = 5;
                 } else {
                     $planningModel->NextStepPositionLevel = $_POST['Candidate']['CompanyPositionID'];
                     $planningModel->LongTermPositionLevel = $_POST['Candidate']['CompanyPositionID'];
                 }
                 $performanceModel->save();
                 $ratingModel->save();
                 $planningModel->save();
                 $this->redirect(Yii::app()->createUrl('company/candidates'));
             }
         }
     }
     $criteria3 = new CDbCriteria();
     $criteria3->condition = 'companyID = :companyID';
     $criteria3->params = array(':companyID' => Yii::app()->user->companyID);
     $criteria3->order = 'Email';
     $userManagers = UserProfile::model()->findAllByAttributes(array(), $criteria3);
     $managersArray = array();
     foreach ($userManagers as $UserManager) {
         $managersArray[$UserManager->UserProfileID] = $UserManager->Email;
     }
     $managerArray = $managersArray;
     $companyPositions = Helper::getCompanyPositions(Yii::app()->user->companyID);
     $this->render('candidate-form', array('candidateModel' => $candidateModel, 'planningModel' => $planningModel, 'companyPositionSelect' => $companyPositions, 'managerArray' => $managerArray));
 }