Exemple #1
0
 public function getPDF($type, $code, $style)
 {
     if ($type == 2) {
         return Redirect::to('/cvbuilder/preview/' . $code . '/' . $style . '/' . '2');
     }
     include app_path() . '/dompdf/dompdf_config.inc.php';
     $dompdf = new DOMPDF();
     $cv = Cv::leftJoin('states', 'cvs.state_origin', '=', 'states.id')->leftJoin('religions', 'cvs.religion', '=', 'religions.id')->select('cvs.*', 'states.state', 'religions.religion as religion_name')->where('cv_code', $code)->first();
     $cv_id = $cv->id;
     $dob = explode('-', $cv->dob);
     $workex = WorkExperience::where('cv_id', $cv_id)->orderBy('priority')->get();
     $education = Education::where('cv_id', $cv_id)->orderBy('priority')->get();
     $nysc = Nysc::where('cv_id', $cv_id)->orderBy('priority')->get();
     $language = Language::leftJoin('langs', 'languages.language_id', '=', 'langs.id')->leftJoin('levels', 'languages.level_id', '=', 'levels.id')->select('languages.id', 'languages.language_id', 'languages.language_name', 'langs.language', 'languages.ability_id', 'levels.level')->where('cv_id', $cv_id)->orderBy('priority')->get();
     $sections = Section::where('cv_id', $cv_id)->orderBy('priority')->get();
     $topic = Section::where('cv_id', $cv_id)->orderBy('priority')->get();
     $abilities = DB::table('abilities')->lists('ability', 'id');
     foreach ($language as $value) {
         $value->ability_id = explode(',', $value->ability_id);
         $values = array();
         foreach ($value->ability_id as $ability_id) {
             array_push($values, $abilities[$ability_id]);
         }
         $value->ability = '<b>Ability</b>: ' . implode(' / ', $values);
         $value->level = '<b>Level</b>: ' . $value->level;
     }
     $marital_status_vals = array("1" => "Married", "2" => "UnMarried");
     $html = View::make('cvbuilder.templates.' . $style, array("cv" => $cv, "sections" => $sections, "workex" => $workex, "education" => $education, "dob" => $dob, "nysc" => $nysc, "language" => $language, "marital_status_vals" => $marital_status_vals));
     $dompdf->load_html($html);
     $dompdf->render();
     if ($type == 3) {
         $output = $dompdf->output();
         file_put_contents(app_path() . '/../../cvs/' . $code . '.pdf', $output);
         require app_path() . '/libraries/PHPMailerAutoload.php';
         require app_path() . '/mail.php';
         $mail = new PHPMailer();
         $mail_text = new Mail();
         $mail->isMail();
         $mail->setFrom('*****@*****.**', 'Corper Life');
         $emails = explode(',', Input::get("emails"));
         foreach ($emails as $email) {
             $mail->addAddress($email);
         }
         $mail->addAttachment(app_path() . '/../../cvs/' . $code . '.pdf');
         $mail->isHTML(true);
         $mail->Subject = "Your CV -" . $code . " | Corper Life ";
         $mail->Body = $mail_text->cv_mail($cv->full_name, $code, Input::get("emails"));
         if (!$mail->send()) {
             $response["success"] = false;
             $response["message"] = 'Mailer Error: ' . $mail->ErrorInfo;
         } else {
             $response["success"] = true;
             $response["message"] = "The cv has been mailed to you on " . Input::get("emails");
         }
         return json_encode($response);
     } else {
         $dompdf->stream($code . ".pdf", array('Attachment' => 0));
     }
 }