protected function parseNext()
 {
     //Получаем последний hh id из базы и увеличиваем на 1
     //если база пустая берем значение по умолчанию
     $vacancy = new Vacancy();
     $lastId = $vacancy->maxId();
     if ($lastId) {
         $lastVacancy = $vacancy->find($lastId);
         $hhId = $lastVacancy->hh_id;
     }
     if (isset($hhId)) {
         $hhId = intval($hhId) + 1;
         $link = $this->link_tpl . $hhId;
     } else {
         $hhId = $this->default_hh_id;
         $link = $this->link_tpl . $hhId;
     }
     // Simple HTML Dom
     //Ищем страницу вакансии
     //если есть в базе вычисляем новый Id
     //Получение страниц ведется сначала в большую сторону
     //если превышен лимит, меняем направление
     $index = 0;
     $maxLoadIndex = 10;
     $operand = '+';
     $html = $vacancy->getHtmlDom($link);
     while (!$html) {
         if ($operand == '+') {
             $hhId = intval($hhId) + 1;
         } else {
             $hhId = intval($hhId) - 1;
         }
         if ($vacancy->where('hh_id', '=', $hhId)->first()) {
             continue;
         }
         if ($index++ > $maxLoadIndex) {
             $operand = '-';
             $maxLoadIndex = 100;
             $index = 0;
             $hhId = $vacancy->minId();
         }
         $link = $this->link_tpl . $hhId;
         $html = $vacancy->getHtmlDom($link);
     }
     // парсинг полученной страницы вакансии
     // и запись в базу
     $ret = $vacancy->parseAndSave($html, $hhId, $link);
     if ($ret === true) {
         return $link;
     } else {
         return $ret;
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Business $business, Request $request)
 {
     $this->log->info("BusinessServiceController: store: businessId:{$business->id}");
     $dates = $request->get('vacancy');
     $success = false;
     foreach ($dates as $date => $vacancy) {
         foreach ($vacancy as $serviceId => $capacity) {
             switch (trim($capacity)) {
                 case '':
                     // Dont update, leave as is
                     $this->log->info("BusinessServiceController: store: [ADVICE] Blank vacancy capacity value businessId:{$business->id}");
                     break;
                 default:
                     $start_at = Carbon::parse($date . ' ' . $business->pref('start_at'))->timezone($business->timezone);
                     $finish_at = Carbon::parse($date . ' ' . $business->pref('finish_at', '20:00:00'))->timezone($business->timezone);
                     $vacancy = Vacancy::updateOrCreate(['business_id' => $business->id, 'service_id' => $serviceId, 'date' => $date], ['capacity' => intval($capacity), 'start_at' => $start_at, 'finish_at' => $finish_at]);
                     $success = true;
                     break;
             }
         }
     }
     if ($success) {
         Flash::success(trans('manager.vacancies.msg.store.success'));
         return redirect()->route('manager.business.show', [$business]);
     }
     $this->log->info("BusinessServiceController: store: [ADVICE] Nothing to update businessId:{$business->id}");
     Flash::warning(trans('manager.vacancies.msg.store.nothing_changed'));
     return redirect()->back();
 }
 public function index($token)
 {
     if ($token === 'W2Xcoiq28sLNasiszA819qgLk42CTc5b') {
         $addressees = Model::all();
         $news = News::getForDelivery();
         $tenders = Tender::getForDelivery();
         $vacancies = Vacancy::getForDelivery();
         $shares = Share::getForDelivery();
         $expert_advices = ExpertAdvice::getForDelivery();
         foreach ($addressees as $addressee) {
             $params['title'] = $addressee->locale . '_title';
             $params['text'] = $addressee->locale . '_text';
             $params['locale'] = $addressee->locale;
             $addressee->news && count($news) ? $params['delivery']['news'] = $news : null;
             $addressee->tenders && count($tenders) ? $params['delivery']['tenders'] = $tenders : null;
             $addressee->vacancies && count($vacancies) ? $params['delivery']['vacancies'] = $vacancies : null;
             $addressee->shares && count($shares) ? $params['delivery']['shares'] = $shares : null;
             $addressee->expert_advices && count($expert_advices) ? $params['delivery']['expert_advices'] = $expert_advices : null;
             if (isset($params['delivery'])) {
                 Mail::send('emails.delivery', $params, function ($message) use($addressee) {
                     $from_address = MailConfig::first();
                     $from_name = Config::get('mail.from');
                     $message->from($from_address->feedback_mail, $from_name['name']);
                     $message->to($addressee->email)->subject(trans('front-end' . DS . 'emails' . DS . 'delivery.subject'));
                 });
             }
             unset($params);
         }
         News::where('sended', 0)->update(['sended' => 1]);
         Tender::where('sended', 0)->update(['sended' => 1]);
         Vacancy::where('sended', 0)->update(['sended' => 1]);
         Share::where('sended', 0)->update(['sended' => 1]);
         ExpertAdvice::where('sended', 0)->update(['sended' => 1]);
     }
 }
 public function store(VacancyStoreRequest $request)
 {
     $validate = \Validator::make($request->all(), $request->rules(), $request->messages());
     if ($validate->fails()) {
         return redirect('/dashboard/vacancies/create')->withErrors($validate->errors())->withInput();
     } else {
         Vacancy::create($request->only('position', 'description', 'salary', 'hot'));
         return redirect()->to('/dashboard/vacancies');
     }
 }
 public function show($id)
 {
     $infoConfig = InfoConfig::first()->toArray();
     $object = Model::find($id);
     if (!$object) {
         $object = Model::where('alias', $id)->first();
     }
     if ($object) {
         return view('info.vacancy', ['object' => $object, 'type' => 'vacancies', 'title' => LANG . '_title', 'description' => LANG . '_description', 'text' => LANG . '_text', 'requirements' => LANG . '_requirements', 'contacts' => LANG . '_contacts', 'infoConfig' => $infoConfig]);
     }
     return redirect('info-center');
 }
 public function show(Request $request)
 {
     if (!$request->has('q')) {
         return redirect('/' . LANG);
     }
     $params = $request->only('q');
     $searchParams = explode(" ", trim($params['q']));
     $productsResults = Product::search($searchParams);
     $portfoliosResults = Portfolio::search($searchParams);
     $newsResults = News::search($searchParams);
     $tendersResults = Tender::search($searchParams);
     $vacanciesResults = Vacancy::search($searchParams);
     $sharesResults = Share::search($searchParams);
     $experEdvicesResults = ExpertAdvice::search($searchParams);
     $count = count($productsResults) + count($portfoliosResults) + count($newsResults) + count($tendersResults) + count($vacanciesResults) + count($sharesResults) + count($experEdvicesResults);
     return view('search', ['products' => $productsResults, 'portfolios' => $portfoliosResults, 'news' => $newsResults, 'tenders' => $tendersResults, 'vacancies' => $vacanciesResults, 'shares' => $sharesResults, 'experEdvices' => $experEdvicesResults, 'count' => $count, 'title' => LANG . '_title', 'description' => LANG . '_description', 'adderss' => LANG . '_adderss', 'type' => 'news']);
 }
Exemple #7
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     foreach (RssFeed::limit(1)->get() as $feed) {
         $this->crawler->addContent($feed->html);
         foreach ($this->pointers as $key => $value) {
             try {
                 $data[$key] = $this->crawler->filterXPath($value)->text();
             } catch (\Exception $e) {
                 $data[$key] = null;
             }
         }
         $data['url'] = $feed->url;
         $organisation = $this->saveOrganisation($data);
         $location = $this->saveLocation();
         $organisation->location()->save($location);
         $vacancy = Vacancy::firstOrNew(['ref' => $data['ref']]);
     }
 }
Exemple #8
0
 public function parseAndSave($html, $hhId, $link = null)
 {
     if (!$html) {
         return 'Parse error';
     }
     $vacancy = new Vacancy();
     if ($vacancy->where('hh_id', '=', $hhId)->first()) {
         return 'Vacancy ' . $hhId . ' found in database';
     }
     //name
     if ($obj = $html->find('.b-vacancy-title', 0)) {
         $title = $obj->plaintext;
     }
     //description
     if ($obj = $html->find('.b-vacancy-desc-wrapper', 0)) {
         $description = $obj->innertext;
     }
     //address
     if ($obj = $html->find('.vacancy-address-text', 0)) {
         $address = $obj->innertext;
     }
     //company_name
     if ($obj = $html->find('.companyname', 0)) {
         $companyName = $obj->plaintext;
     }
     //employmentMode
     $employmentMode = array();
     foreach ($html->find('.b-vacancy-employmentmode span') as $span) {
         $employmentMode[] = $span->innertext;
     }
     $head = $html->find('.b-vacancy-info .l-content-3colums', 0)->innertext;
     if ($res = $html->str_get_html($head)) {
         //content
         if ($obj = $res->find('.l-content-colum-1', 1)) {
             if ($tag = $obj->find('.l-paddings meta', 0)) {
                 $currency = $tag->content;
             }
         }
         //salary
         if ($obj = $res->find('.l-content-colum-1', 1)) {
             if ($tag = $obj->find('.l-paddings', 0)) {
                 $salaryText = $tag->plaintext;
             }
         }
         if (!empty($salaryText)) {
             if (!preg_match('/[\\d]{1}/i', $salaryText)) {
                 $salary_from = 0;
                 $salary_to = 0;
             } else {
                 $salary = explode('до', $salaryText);
                 if (isset($salary[0]) && strlen(trim($salary[0])) > 0) {
                     preg_match_all('/[\\w]{2}(.*)[\\w\\s\\.]{1,4}/', $salary[0], $matches);
                     $str = str_replace(chr(194) . chr(160), '', $matches[0][0]);
                     $str = str_replace(' ', '', $str);
                     $salary_from = intval($str);
                 }
                 if (isset($salary[1]) && strlen(trim($salary[1])) > 0) {
                     preg_match_all('/[\\w\\s]{1,2}(.*)[\\w\\s]{1,3}/', $salary[1], $matches);
                     $str = str_replace(chr(194) . chr(160), '', $matches[0][0]);
                     $str = str_replace(' ', '', $str);
                     $salary_to = intval($str);
                 }
             }
         }
         //cityName
         if ($obj = $res->find('.l-content-colum-2', 1)) {
             if ($tag = $obj->find('.l-paddings', 0)) {
                 $cityName = $tag->plaintext;
             }
         }
         //metro
         if ($obj = $res->find('.l-content-colum-2', 1)) {
             if ($tag = $obj->find('.metro-station', 0)) {
                 $metro = $tag->plaintext;
             }
         }
         if (isset($metro)) {
             $cityName = str_replace(',', '', $cityName);
             $cityName = str_replace(',', '', $metro);
             $cityName = trim($cityName);
         }
         //experience
         if ($obj = $res->find('.l-content-colum-3', 1)) {
             if ($tag = $obj->find('.l-paddings', 0)) {
                 $experience = $tag->plaintext;
             }
         }
     }
     // Save Vacancy
     $vacancy = new Vacancy();
     if (isset($title)) {
         $vacancy->name = $title;
     }
     if (isset($companyName)) {
         $vacancy->company_name = $companyName;
     }
     if (isset($hhId)) {
         $vacancy->hh_id = $hhId;
     }
     if (isset($link)) {
         $vacancy->hh_link = $link;
     }
     if (isset($salary_from)) {
         $vacancy->salary_from = $salary_from;
     }
     if (isset($salary_to)) {
         $vacancy->salary_to = $salary_to;
     }
     if (isset($currency)) {
         $vacancy->currency = $currency;
     }
     if (isset($cityName)) {
         $cities = new City();
         if ($city = $cities->where('name', '=', $cityName)->first()) {
             $vacancy->city_id = $city->id;
         } else {
             // save new city
             $city = new City();
             $city->name = $cityName;
             $city->save();
             $vacancy->city_id = $city->id;
         }
     }
     if (isset($experience)) {
         $vacancy->experience = $experience;
     }
     if (isset($description)) {
         $vacancy->description = $description;
     }
     if (isset($address)) {
         $vacancy->address = $address;
     }
     // save
     if (!$vacancy->save()) {
         return 'Vacancy not saved';
     }
     // Employment Types Save
     if (count($employmentMode) > 0) {
         $empType = new \App\EmploymentType();
         foreach ($employmentMode as $emp) {
             if ($find = $empType->where('name', 'LIKE', '%' . $emp . '%')->first()) {
                 $empIds[] = $find->id;
             } else {
                 // save new EmploymentType
                 $employ = new EmploymentType();
                 $employ->name = $emp;
                 $employ->save();
                 $empIds[] = $employ->id;
             }
         }
         $empType = new \App\EmploymentType();
         $vacancy->employmentTypes()->attach($empIds);
     }
     return true;
 }
 public function view(Request $request, $id)
 {
     $vacancy = Vacancy::find($id);
     $page = $request->input('backpage');
     return view('vacancy.view', array('vacancy' => $vacancy, 'backpage' => $page));
 }
 public function vacancies()
 {
     $vacancies = Vacancy::all();
     return response(view('back.vacancies.index', compact('vacancies')));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $item = Vacancy::findOrFail($id);
     $this->authorize('destroy', $item);
     $item->delete();
     $redis = LRedis::connection();
     //DEL key [key ...]
     $redis->del('vacancy_title::' . $item->id);
     // LREM key count value
     $redis->lrem('latest_vacancy_ids', $item->id, 0);
     return redirect('/vacancy/index');
 }
 public function vacancies()
 {
     $vacancies = Vacancy::all();
     return response(view('front.about.vacancies', compact('vacancies')))->setExpires(Carbon::now()->addHour());
 }
 protected function getNextHHId()
 {
     $vacancy = new Vacancy();
     $lastId = $vacancy->maxId();
     if ($lastId) {
         $lastVacancy = $vacancy->find($lastId);
         $hhId = $lastVacancy->hh_id;
     }
     if (isset($hhId)) {
         return intval($hhId) + 1;
     } else {
         return $this->default_hh_id;
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $object = Model::find($id);
     if ($object) {
         $object->delete();
     }
     return redirect()->back();
 }