Created
August 19, 2019 12:04
-
-
Save hackimov/3049bc82cf33c01705bbc05436bdbd98 to your computer and use it in GitHub Desktop.
Revisions
-
hackimov created this gist
Aug 19, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,432 @@ <?php namespace App\Http\Controllers\API; use Illuminate\Http\Request; use DB; use App\Quotation; use ZipArchive; use Illuminate\Support\Facades\Storage; use Carbon\Carbon; class CreateCvWordController extends BaseApiController { /** * @param Request $request */ public function getWordCvRu(Request $request) { if($request->has('FULLNAME')){ $FULLNAME = $request->FULLNAME; } if($request->has('PHONE')){ $PHONE = $request->PHONE; } if($request->has('CITIZENSHIP')){ $CITIZENSHIP = $request->CITIZENSHIP; } if($request->has('EMAIL')){ $EMAIL = $request->EMAIL; } if($request->has('ADRESS')){ $ADRESS = $request->ADRESS; } if($request->has('WANTED_WORK_POSITION')){ $WANTED_WORK_POSITION = $request->WANTED_WORK_POSITION; } if($request->has('SOATO_CODE')){ $SOATO_CODE = $request->SOATO_CODE; } if($request->has('EDUCATION')){ $EDUCATION = $request->EDUCATION; } if($request->has('PROFESSION')){ $PROFESSION = $request->PROFESSION; } if($request->has('WORK_ABROAD')){ $WORK_ABROAD = $request->WORK_ABROAD; if($WORK_ABROAD == true){$WORK_ABROAD = "Да";} if($WORK_ABROAD == false){$WORK_ABROAD = "Нет";} } if($request->has('WORK_ABROAD_COUNTRY')){ $WORK_ABROAD_COUNTRY = $request->WORK_ABROAD_COUNTRY; } if($request->has('FOREIGN_LANGUAGES')){ $FOREIGN_LANGUAGES = $request->FOREIGN_LANGUAGES; } if($request->has('DOP_INFO')){ $DOPINFO = $request->DOP_INFO; } if($request->has('NATURE_OF_WORK')){ $NATURE_OF_WORK = $request->NATURE_OF_WORK; } if($request->has('WANTED_SALARY')){ $WANTED_SALARY = $request->WANTED_SALARY; } if($request->has('WORKSEXP')){ $WORKSEXPARR = json_decode($request->WORKSEXP); $WORKSEXPARR = (array)$WORKSEXPARR; $i = 0; $WORK_EXP_NEW_ARR = []; foreach ($WORKSEXPARR as $WORKSEXP) { $WORKSEXP = (array)$WORKSEXP; $WORK_EXP_NEW_ARR[$i] = $WORKSEXP; $WORK_EXP_NEW_ARR[$i]["JOB_FIRE_DATE"] = Carbon::parse($WORKSEXP["JOB_FIRE_DATE"])->toDateTimeString(); $WORK_EXP_NEW_ARR[$i]["JOB_FIRE_DATE"] = date('Y-m-d', strtotime($WORK_EXP_NEW_ARR[$i]["JOB_FIRE_DATE"])); $WORK_EXP_NEW_ARR[$i]["JOB_HIRE_DATE"] = Carbon::parse($WORKSEXP["JOB_HIRE_DATE"])->toDateTimeString(); $WORK_EXP_NEW_ARR[$i]["JOB_HIRE_DATE"] = date('Y-m-d', strtotime($WORK_EXP_NEW_ARR[$i]["JOB_HIRE_DATE"])); $i++; } } if(!empty($WORK_EXP_NEW_ARR)){ $header = "<w:tbl> <w:tblPr> <w:tblStyle w:val=\"aa\" /> <w:tblW w:w=\"0\" w:type=\"auto\" /> <w:tblInd w:w=\"720\" w:type=\"dxa\" /> <w:tblLook w:val=\"04A0\" w:firstRow=\"1\" w:lastRow=\"0\" w:firstColumn=\"1\" w:lastColumn=\"0\" w:noHBand=\"0\" w:noVBand=\"1\" /> </w:tblPr> <w:tblGrid> <w:gridCol w:w=\"2156\" /> <w:gridCol w:w=\"2158\" /> <w:gridCol w:w=\"2158\" /> <w:gridCol w:w=\"2158\" /> </w:tblGrid> <w:tr w:rsidR=\"00AE7E6D\" w14:paraId=\"6DFDD3D3\" w14:textId=\"77777777\" w:rsidTr=\"00AE7E6D\"> <w:tc> <w:tcPr> <w:tcW w:w=\"2156\" w:type=\"dxa\" /> </w:tcPr> <w:p w14:paraId=\"2D9F0C0C\" w14:textId=\"104D3888\" w:rsidR=\"00AE7E6D\" w:rsidRPr=\"00AE7E6D\" w:rsidRDefault=\"00AE7E6D\" w:rsidP=\"00CD7CD8\"> <w:pPr> <w:ind w:left=\"0\" /> <w:rPr> <w:lang w:val=\"ru-RU\" /> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:lang w:val=\"ru-RU\" /> </w:rPr> <w:t>Дата принятия</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:tcPr> <w:tcW w:w=\"2158\" w:type=\"dxa\" /> </w:tcPr> <w:p w14:paraId=\"3C04BACC\" w14:textId=\"1B758261\" w:rsidR=\"00AE7E6D\" w:rsidRPr=\"00AE7E6D\" w:rsidRDefault=\"00AE7E6D\" w:rsidP=\"00CD7CD8\"> <w:pPr> <w:ind w:left=\"0\" /> <w:rPr> <w:lang w:val=\"ru-RU\" /> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:lang w:val=\"ru-RU\" /> </w:rPr> <w:t>Дата увольнения</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:tcPr> <w:tcW w:w=\"2158\" w:type=\"dxa\" /> </w:tcPr> <w:p w14:paraId=\"499DF127\" w14:textId=\"4B06817F\" w:rsidR=\"00AE7E6D\" w:rsidRPr=\"00AE7E6D\" w:rsidRDefault=\"00AE7E6D\" w:rsidP=\"00CD7CD8\"> <w:pPr> <w:ind w:left=\"0\" /> <w:rPr> <w:lang w:val=\"ru-RU\" /> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:lang w:val=\"ru-RU\" /> </w:rPr> <w:t>Организация</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:tcPr> <w:tcW w:w=\"2158\" w:type=\"dxa\" /> </w:tcPr> <w:p w14:paraId=\"4B393D9F\" w14:textId=\"34C92FAD\" w:rsidR=\"00AE7E6D\" w:rsidRPr=\"00AE7E6D\" w:rsidRDefault=\"00AE7E6D\" w:rsidP=\"00CD7CD8\"> <w:pPr> <w:ind w:left=\"0\" /> <w:rPr> <w:lang w:val=\"ru-RU\" /> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:lang w:val=\"ru-RU\" /> </w:rPr> <w:t>Профессия</w:t> </w:r> </w:p> </w:tc> </w:tr>"; $columns = ""; foreach ($WORK_EXP_NEW_ARR as $WORK_DATA_GRID){ $columns .= "<w:tr w:rsidR=\"00AE7E6D\" w14:paraId=\"65220AEA\" w14:textId=\"77777777\" w:rsidTr=\"00AE7E6D\"> <w:tc> <w:tcPr> <w:tcW w:w=\"2156\" w:type=\"dxa\" /> </w:tcPr> <w:p w14:paraId=\"0D3A90DC\" w14:textId=\"77777777\" w:rsidR=\"00AE7E6D\" w:rsidRDefault=\"00AE7E6D\" w:rsidP=\"00CD7CD8\"> <w:pPr> <w:ind w:left=\"0\" /> <w:rPr> <w:lang w:val=\"ru-RU\" /> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:lang w:val=\"ru-RU\" /> </w:rPr> <w:t>". $WORK_DATA_GRID["JOB_HIRE_DATE"] . "</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:tcPr> <w:tcW w:w=\"2158\" w:type=\"dxa\" /> </w:tcPr> <w:p w14:paraId=\"1AD40990\" w14:textId=\"77777777\" w:rsidR=\"00AE7E6D\" w:rsidRDefault=\"00AE7E6D\" w:rsidP=\"00CD7CD8\"> <w:pPr> <w:ind w:left=\"0\" /> <w:rPr> <w:lang w:val=\"ru-RU\" /> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:lang w:val=\"ru-RU\" /> </w:rPr> <w:t>". $WORK_DATA_GRID["JOB_FIRE_DATE"] . "</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:tcPr> <w:tcW w:w=\"2158\" w:type=\"dxa\" /> </w:tcPr> <w:p w14:paraId=\"537F9148\" w14:textId=\"77777777\" w:rsidR=\"00AE7E6D\" w:rsidRDefault=\"00AE7E6D\" w:rsidP=\"00CD7CD8\"> <w:pPr> <w:ind w:left=\"0\" /> <w:rPr> <w:lang w:val=\"ru-RU\" /> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:lang w:val=\"ru-RU\" /> </w:rPr> <w:t>". $WORK_DATA_GRID["JOB_ORGANIZATION"] . "</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:tcPr> <w:tcW w:w=\"2158\" w:type=\"dxa\" /> </w:tcPr> <w:p w14:paraId=\"5FF56B4B\" w14:textId=\"77777777\" w:rsidR=\"00AE7E6D\" w:rsidRDefault=\"00AE7E6D\" w:rsidP=\"00CD7CD8\"> <w:pPr> <w:ind w:left=\"0\" /> <w:rPr> <w:lang w:val=\"ru-RU\" /> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:lang w:val=\"ru-RU\" /> </w:rPr> <w:t>". $WORK_DATA_GRID["JOB_PROFESSION"] . "</w:t> </w:r> </w:p> </w:tc> </w:tr>"; } $footer = "</w:tbl>"; $gridstring = $header . $columns . $footer; $gridstring = str_replace("\r\n", '', $gridstring); $gridstring = str_replace(' ','',$gridstring); $gridstring = str_replace(' ','',$gridstring); $gridstring = trim($gridstring); } if($request->has('IMAGE')){ $path = $request->IMAGE; if($path === "/storage/nonvatar.jpg"){ $path = $_SERVER["DOCUMENT_ROOT"] . $path; } $data = file_get_contents($path); $im = imagecreatefromstring($data); $width = imagesx($im); $height = imagesy($im); # магия ёпта $kof = $width/157.06375470001; $resultH = $height/$kof; } # создаём зип объект $zip = new ZipArchive(); # путь к файлу шаблону $templateFilename = $_SERVER['DOCUMENT_ROOT'].'/storage/templates/cv_rus_template.docx'; # результирующий файл $inputFilename = $_SERVER['DOCUMENT_ROOT'].'/storage/templates/cv_rus.docx'; if(!copy($templateFilename, $inputFilename)) { die("Не могу скопировать '$templateFilename' to '$inputFilename'"); } # Открываем документ Microsoft Word .docx if ($zip->open($inputFilename, ZipArchive::CREATE)!==TRUE) { echo "Не могу открыть $inputFilename"; die; } # Парсим страничку $xml = $zip->getFromName('word/document.xml'); # Заменяем своими записями if(!empty($FULLNAME)){ $xml = str_replace('FULLNAME', $FULLNAME, $xml); } else { $xml = str_replace('FULLNAME', "", $xml); } if(!empty($ADRESS)){ $xml = str_replace('CITY', trim($ADRESS), $xml); } else { $xml = str_replace('CITY', "", $xml); } if(!empty($PHONE)){ $xml = str_replace('PHONE', $PHONE, $xml); } else { $xml = str_replace('PHONE', "", $xml); } if(!empty($EMAIL)){ $xml = str_replace('EMAIL', $EMAIL, $xml); } else { $xml = str_replace('EMAIL', "", $xml); } if(!empty($CITIZENSHIP)){ $xml = str_replace('CITIZENSHIP', $CITIZENSHIP, $xml); } else { $xml = str_replace('CITIZENSHIP', "", $xml); } if(!empty($WANTED_WORK_POSITION)){ $xml = str_replace('WANTEDWORKPOSITION', $WANTED_WORK_POSITION, $xml); } else { $xml = str_replace('WANTEDWORKPOSITION', "", $xml); } if(!empty($SOATO_CODE)){ $xml = str_replace('SOATOCODE', $SOATO_CODE, $xml); } else { $xml = str_replace('SOATOCODE', "", $xml); } if(!empty($EDUCATION)){ $xml = str_replace('EDUCATION', $EDUCATION, $xml); } else { $xml = str_replace('EDUCATION', "", $xml); } if(!empty($PROFESSION)){ $xml = str_replace('PROFESSION', $PROFESSION, $xml); } else { $xml = str_replace('PROFESSION', "", $xml); } if(!empty($WORK_ABROAD)){ $xml = str_replace('WRVAL', $WORK_ABROAD, $xml); } else { $xml = str_replace('WRVAL', "", $xml); } if(!empty($WORK_ABROAD_COUNTRY)){ $xml = str_replace('WRCOUNTRY', $WORK_ABROAD_COUNTRY, $xml); } else { $xml = str_replace('WRCOUNTRY', "", $xml); } if(!empty($DOPINFO)){ $xml = str_replace('DOPINFO', $DOPINFO, $xml); } else { $xml = str_replace('DOPINFO', "", $xml); } if(!empty($NATURE_OF_WORK)){ $xml = str_replace('FOREIGNLANGUAGES', $FOREIGN_LANGUAGES, $xml); } else { $xml = str_replace('FOREIGNLANGUAGES', "", $xml); } if(!empty($NATURE_OF_WORK)){ $xml = str_replace('NATUREOFWORK', $NATURE_OF_WORK, $xml); } else { $xml = str_replace('NATUREOFWORK', "", $xml); } if(!empty($gridstring)) { $xml = str_replace('GRID', $gridstring, $xml); } else { $xml = str_replace('GRID', "", $xml); } if(!empty($WANTED_SALARY)) { $xml = str_replace('WANTEDSALARY', $WANTED_SALARY, $xml); } else { $xml = str_replace('WANTEDSALARY', "", $xml); } # изменяем ширину картинки $xml = str_replace('height:99pt', 'height:'.$resultH, $xml); # Записываем XML файл if ($zip->addFromString('word/document.xml', $xml)); if ($zip->addFromString('word/media/image1.png', $data)); $zip->close(); $inputFilename = preg_replace('#.*/#', '', $inputFilename); $url = Storage::disk('templates')->url($inputFilename); return $url; } }