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'); }
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; } }
public function view(Request $request, $id) { $vacancy = Vacancy::find($id); $page = $request->input('backpage'); return view('vacancy.view', array('vacancy' => $vacancy, 'backpage' => $page)); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * * @return \Illuminate\Http\Response */ public function update(Request $request) { $item = Vacancy::find($request->vacancy_id); $this->authorize('update', $item); $item->title = $request->title; $item->company = $request->company; $item->salarymin = $request->salarymin; $item->salarymax = $request->salarymax; $item->city = $request->city; $item->description = $request->description; $item->email = $request->email; $item->tel = $request->tel; $item->update(); $redis = LRedis::connection(); $redis->set('vacancy_title::' . $item->id, $item->title); return redirect('/vacancy/index'); }
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(); }