Created
August 11, 2019 12:26
-
-
Save hackimov/aa319a513c80eeb99a2f66716c277935 to your computer and use it in GitHub Desktop.
Govnocode Example
This file contains 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 characters
<?php | |
namespace App\Http\Controllers\API; | |
use Illuminate\Http\Request; | |
use DB; | |
use App\Quotation; | |
use Carbon\Carbon; | |
class GetAllCVsAPIController extends BaseApiController | |
{ | |
/** | |
* @param Request $request | |
*/ | |
public function getAllCvs(Request $request) | |
{ | |
if($request->has('DATE_START')){ | |
$request->DATE_START = Carbon::parse($request->DATE_START)->toDateTimeString(); | |
} | |
if($request->has('DATE_STOP')){ | |
$request->DATE_STOP = Carbon::parse($request->DATE_STOP)->toDateTimeString(); | |
} | |
# джойним таблицы | |
$cvs = DB::table('m_cvs')->join('m_individ', 'm_cvs.PERSON_ID', '=', 'm_individ.PERSON_ID'); | |
# делаем фильтр | |
if($request->has('NAME')){ | |
$cvs->where('m_individ.NAME', 'like', "%$request->NAME%"); | |
} | |
if($request->has('SECOND_NAME')){ | |
$cvs->where('m_individ.SECOND_NAME', 'like', "%$request->SECOND_NAME%"); | |
} | |
if($request->has('LAST_NAME')){ | |
$cvs->where('m_individ.LAST_NAME', 'like', "%$request->LAST_NAME%"); | |
} | |
if($request->has('CITIZENSHIP')){ | |
$cvs->where('m_individ.CITIZENSHIP', 'like', "%$request->CITIZENSHIP%"); | |
} | |
if($request->has('NATIONALITY')){ | |
$cvs->where('m_individ.NATIONALITY', 'like', "%$request->NATIONALITY%"); | |
} | |
if($request->has('FOREIGN_LANGUAGES')){ | |
$cvs->where('m_individ.FOREIGN_LANGUAGES', 'like', "%$request->FOREIGN_LANGUAGES%"); | |
} | |
if($request->has('WANTED_WORK_POSITION')){ | |
$cvs->where('m_cvs.WANTED_WORK_POSITION', 'like', "%$request->WANTED_WORK_POSITION%"); | |
} | |
if($request->has('WANTED_SALARY_FROM')){ | |
$cvs->where('m_cvs.WANTED_SALARY', '>=', $request->WANTED_SALARY_FROM); | |
} | |
if($request->has('WANTED_SALARY_TO')){ | |
$cvs->where('m_cvs.WANTED_SALARY', '<=', $request->WANTED_SALARY_TO); | |
} | |
if($request->has('DATE_START')){ | |
$cvs->where('m_cvs.DATE_START', '>=', $request->DATE_START); | |
} | |
if($request->has('DATE_STOP')){ | |
$cvs->where('m_cvs.DATE_STOP', '<=', $request->DATE_STOP); | |
} | |
if($request->has('SOATO_CODE')){ | |
$cvs->where('m_cvs.SOATO_CODE', 'like', "%$request->SOATO_CODE%"); | |
} | |
if($request->has('WORK_ABROAD')){ | |
$cvs->where('m_cvs.WORK_ABROAD', '=', $request->WORK_ABROAD); | |
} | |
if($request->has('NATURE_OF_WORK')){ | |
$cvs->where('m_cvs.NATURE_OF_WORK', 'like', "%$request->NATURE_OF_WORK%"); | |
} | |
if($request->has('DOP_INFO')){ | |
$cvs->where('m_cvs.DOP_INFO', 'like', "%$request->DOP_INFO%"); | |
} | |
if($request->has('WORK_ABROAD_COUNTRY')) { | |
$countries = explode(",", $request->WORK_ABROAD_COUNTRY); | |
$cvs->where('m_cvs.WORK_ABROAD_COUNTRY', 'LIKE', '%' . $countries[0] . '%'); | |
$count = count($countries); | |
if ($count > 1) { | |
foreach ($countries as $country) { | |
$cvs->orWhere('m_cvs.WORK_ABROAD_COUNTRY', 'LIKE', '%' . $country . '%'); | |
} | |
} | |
} | |
if($request->has('CV_IS_UNACTIVE')) { | |
if($request->CV_IS_UNACTIVE === "true") { | |
$cvs->where('m_cvs.CV_STATUS', "=", "0"); | |
} | |
if($request->CV_IS_UNACTIVE === "false") { | |
$cvs->whereIn('m_cvs.CV_STATUS', array("1","2")); | |
} | |
} else { | |
$cvs->whereIn('m_cvs.CV_STATUS', array("1","2")); | |
} | |
if($request->has('start') && $request->has('limit')){ | |
$cvs->skip($request->start)->take($request->limit); | |
} | |
# окончили фильтр и делаем запрос | |
$cvs->select('m_cvs.*', 'm_individ.*'); | |
$result = $cvs->get()->toArray(); | |
$result = (array)$result; | |
return response($result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Говно