function recruiters() { global $MRecruiter, $MJob, $MCompany, $MApp; $recruiterArray = []; $recruiterColumns = ["email", "firstname", "lastname", "company", "datejoined", "postedjob", "madecompany", "approved"]; $jobColumns = ["jobname", "jobviews", "jobclicks", "applicants"]; $recruiterArray[] = implode(',', $recruiterColumns) . ',' . implode(',', $jobColumns); $r = $MRecruiter->find(); $j = $MJob->find(); $rids = array(); // an array of recruiters ids that have posted jobs foreach ($j as $job) { $rids[] = $job['recruiter']->{'$id'}; } foreach ($r as $recruiter) { $info = []; $id = $recruiter['_id']; $rdoc = $MRecruiter->getById($id); if (isset($recruiter['email'])) { $info['email'] = $recruiter['email']; } else { $info['email'] = 'no email'; } if (isset($recruiter['firstname'])) { $info['firstname'] = $recruiter['firstname']; } else { $info['firstname'] = 'no firstname'; } if (isset($recruiter['lastname'])) { $info['lastname'] = $recruiter['lastname']; } else { $info['lastname'] = 'no lastname'; } if (isset($recruiter['company'])) { if (MongoID::isValid($recruiter['company'])) { // if the company is a MongoID $info['company'] = $MCompany->getName($recruiter['company']); } else { $info['company'] = $recruiter['company']; } } else { $info['company'] = 'no company'; } $info['dateJoined'] = fdate($recruiter['_id']->getTimestamp()); if (in_array($id, $rids)) { // recruiters who have posted at least one job and have a company profile $info['postedJob'] = 'YES'; $info['madeCompany'] = 'YES'; $info['approved'] = 'YES'; } else { // recruiters who have not posted a job $info['postedJob'] = 'NO'; if (MongoID::isValid($recruiter['company'])) { // recruiters who have a company profile $info['madeCompany'] = 'YES'; $info['approved'] = 'YES'; } else { // recruiters who don't have a company profile $info['madeCompany'] = 'NO'; if ($recruiter['approved'] == 'approved') { // recruiters who are approved $info['approved'] = 'YES'; } else { // recruiters who are not approved $info['approved'] = 'NO'; } } } $recruiterArray[] = implode(',', self::quoteStringsInArray($info)); $jobs = $MJob->getByRecruiter($id); // get jobs for recruiter foreach ($jobs as $job) { //make rows under each recruiter for their listed jobs $jobInfo = []; if (isset($job['title'])) { $jobInfo['title'] = $job['title']; } else { 'No Job Title'; } $jobInfo['views'] = $job['stats']['views']; $jobInfo['clicks'] = $job['stats']['clicks']; $jobInfo['applicants'] = ApplicationModel::countByJob($job['_id']); $recruiterArray[] = str_repeat(',', count($recruiterColumns)) . implode(',', self::quoteStringsInArray($jobInfo)); } } return ["recruiterArray" => $recruiterArray]; }