/** * Retrieve job information by given ID. * * @param $job_id Integer - Given job id. * @return Array - Job information */ public function findBy($job_id) { // validate the given ID. $this->validate(['id' => $job_id]); // return validation error if the given ID is not valid. if (count($this->validation_log) > 0) { return ['validation', $this->validation_log]; } $this->query = "SELECT * FROM jobs WHERE id = :job_id"; $this->params = [':job_id' => $job_id]; $job = $this->query()->fetchAll(); // return empty array if there are no jobs. if (count($job) < 1) { return []; } // fetch all candidates for the given job. $candidates = new Candidates(); $job[0]['candidates'] = $candidates->findByJobId($job_id); return $job; }