Ejemplo n.º 1
0
 /**
  * получает  массив вакансий за пол года, содержащих хотябы один навык из перечисленных
  *
  * @param $skillIds - массив навыков
  * @param $areaId - регион
  */
 public static function getJobWithSkills($skillIds, $areaId)
 {
     $currentDate = new \DateTime();
     $halfYear = new \DateInterval('P3M');
     $date = $currentDate->sub($halfYear)->format('Y-m-d');
     $jobs = Job::with('verifiedSkills')->where('area_id', $areaId)->where('endda', '>=', $date)->whereHas('verifiedSkills', function ($query) use($skillIds) {
         $query->whereIn('verified_skills.id', $skillIds);
     })->get();
     $groups = [];
     foreach ($jobs as $job) {
         $groupElement = $job->toGroupElement($skillIds);
         if ($groupElement['additional_skills_count'] <= 3) {
             $groups[$job->getGroupName($skillIds)][] = $groupElement;
         }
     }
     $result = [];
     foreach ($groups as $groupName => $group) {
         $groupAggregation = Job::getGroupAggregation($groupName, $group);
         if ($groupAggregation['aggregation']['actual_count'] > 0) {
             $result[] = $groupAggregation;
         }
     }
     usort($result, function ($group1, $group2) {
         $a = $group1['aggregation']['additional_skills_count'];
         $b = $group2['aggregation']['additional_skills_count'];
         if ($a === $b) {
             return 0;
         }
         return $a > $b ? 1 : -1;
     });
     return $result;
 }