SHARE
TWEET

Untitled

a guest Jun 5th, 2017 503 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         public function job(){
  2.             $data = [];
  3.  
  4.             try {
  5.                 $this->db->select('jobs.jobs_id, jobs.title, jobs.slug, jobs.deficiency, jobs.deficiency_type_id, jobs.area_id, jobs.formation_id');
  6.                 $this->db->select('jobs.function_id');
  7.                 $this->db->select('jobs.course_id, jobs.segment_id, jobs.disciplines_id');
  8.                 $this->db->select('company.name, company.slug as url');
  9.                 $this->db->select('state.name as state, city.city_id as city_id, city.name as city');
  10.                 $this->db->select('area_job.name as area, role.name as role, salary.cost as salary, contract.name as contract, jobs.vacancy');
  11.                 $this->db->select('jobs.description');
  12.                 $this->db->join('company', 'jobs.company_id = company.company_id');
  13.                 $this->db->join('area_job', 'jobs.area_id = area_job.area_id');
  14.                 $this->db->join('role', 'jobs.function_id = role.function_id');
  15.                 $this->db->join('state', 'company.state_id = state.state_id');
  16.                 $this->db->join('city', 'company.city_id = city.city_id');
  17.                 $this->db->join('salary', 'jobs.salary_id = salary.salary_id');
  18.                 $this->db->join('contract', 'jobs.contract_id = contract.contract_id');
  19.                 $this->db->where('jobs.run_cron', 'N');
  20.                 $this->db->where('jobs.visible', 1);
  21.                 $job = $this->db->get('jobs')->result();
  22.  
  23.                 // var_dump(count($job));
  24.                 // die;
  25.  
  26.                 foreach($job as $j){
  27.  
  28.                     $this->db->select('professional.professional_id, professional.name, professional.mail');
  29.                     $this->db->from('professional');
  30.                     $this->db->join('u_professional', 'u_professional.professional_id = professional.professional_id', 'left');
  31.                     $this->db->join('occupation_area', 'occupation_area.professional_id = professional.professional_id', 'left');
  32.                     //$this->db->join('academic_education', 'academic_education.professional_id = professional.professional_id', 'left');
  33.                     //$this->db->join('salary', 'u_professional.salary_id = salary.salary_id');
  34.  
  35.                     $this->db->where('professional.visible', 1);
  36.                     $this->db->where('professional.signature_status', 'paid');
  37.                     $this->db->where('professional.city_id', $j->city_id);
  38.  
  39.                     if(!is_null($j->deficiency_type_id)) { $this->db->where('professional.deficiency_type_id', $j->deficiency_type_id); }
  40.                     if(!is_null($j->area_id)) { $this->db->where('occupation_area.area_id', $j->area_id); }
  41.                     if(!is_null($j->function_id)) { $this->db->where('occupation_area.role_id', $j->function_id); }
  42.                     if(!is_null($j->course_id)) { $this->db->where('occupation_area.course_id', $j->course_id); }
  43.                     if(!is_null($j->segment_id)) { $this->db->where('occupation_area.segment_id', $j->segment_id); }
  44.                     if(!is_null($j->disciplines_id)) { $this->db->where('occupation_area.disciplines_id', $j->disciplines_id); }
  45.  
  46.                     $user = $this->db->get()->result();
  47.  
  48.                     // var_dump(count($user));
  49.  
  50.                     foreach($user as $u){
  51.                         $data[] = [
  52.                             'job' => $j->title,
  53.                             'company' => $j->name,
  54.                             'state' => $j->state,
  55.                             'city' => $j->city,
  56.                             'area' => $j->area,
  57.                             'role' => $j->role,
  58.                             'contract' => $j->contract,
  59.                             'salary' => $j->salary,
  60.                             'vacancy' => $j->vacancy,
  61.                             'description' => $j->description,
  62.                             'user' => $u->name,
  63.                             'mail' => $u->mail,
  64.                             'url' =>  'http://new.escolacontrata.com.br/vagas/resultado/' . $j->slug
  65.                             // 'url' =>  'https://escolacontrata.com.br/vagas/' . $j->url . '/' . $j->slug
  66.                         ];
  67.                     }
  68.  
  69.                 }
  70.  
  71.                 // die;
  72.  
  73.                 // var_dump(count($data));
  74.                 // die;
  75.  
  76.                 $mail = new PHPMailer();
  77.  
  78.                 foreach ($data as $row) {
  79.  
  80.                     $body = file_get_contents('assets/template/new_job.html');
  81.                     $body = preg_replace("{#job#}", $row['job'], $body);
  82.                     $body = preg_replace("{#company#}", $row['company'], $body);
  83.                     $body = preg_replace("{#state#}", $row['state'], $body);
  84.                     $body = preg_replace("{#city#}", $row['city'], $body);
  85.                     $body = preg_replace("{#area#}", $row['area'], $body);
  86.                     $body = preg_replace("{#role#}", $row['role'], $body);
  87.                     $body = preg_replace("{#contract#}", $row['contract'], $body);
  88.                     $body = preg_replace("{#salary#}", $row['salary'], $body);
  89.                     $body = preg_replace("{#vacancy#}", $row['vacancy'], $body);
  90.                     $body = preg_replace("{#description#}", $row['description'], $body);
  91.                     $body = preg_replace("{#user#}", $row['user'], $body);
  92.                     $body = preg_replace("{#url#}", $row['url'], $body);
  93.  
  94.                     $mail->IsSMTP();
  95.                     $mail->SMTPAuth  = true;
  96.                     $mail->SMTPSecure = "ssl";
  97.                     $mail->Host = "br276.hostgator.com.br";
  98.                     $mail->Port = 465;
  99.  
  100.                     $mail->Username = "vagas@escolacontrata.com.br";
  101.                     $mail->Password = "MKT@@EC2017";
  102.  
  103.                     $mail->From = "vagas@escolacontrata.com.br";
  104.  
  105.                     $mail->FromName = "Escola Contrata";
  106.                     $mail->Subject =  "Novo AnĂșncio de Vaga;";
  107.                     $mail->WordWrap = 50;
  108.                     $mail->MsgHTML($body);
  109.                     $mail->AddAddress(strtolower($row['mail']), $row['user']);
  110.                     $mail->CharSet  = "UTF-8";
  111.                     $mail->IsHTML(true);
  112.  
  113.                     if($mail->Send()) {
  114.                         $mail->ClearAddresses();
  115.                         echo 'enviado para: ' . $row['user'] . '<br>';
  116.                     } else {
  117.                         echo $mail->ErrorInfo . '<br>';
  118.                         $mail->ClearAddresses();
  119.                     }
  120.                 }
  121.  
  122.                 foreach($job as $job){
  123.                     $this->db->update('jobs', array('run_cron' => 'Y'), array('jobs_id' => $job->jobs_id));
  124.                 }
  125.             } catch(Exception $e){
  126.                 //echo $e->getMessage() . '<br>';
  127.             }
  128.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top