$title = $j->getSlugTitle(); $notif = new Notifications(); $notif->sendEmailsToSubscribersMail($id); $app->flash('success', "Job {$id} has been activated successfully."); $app->redirect(ADMIN_URL . "jobs/{$job->id}/{$title}"); } else { $app->flash('danger', "Job {$id} could not be activated."); $app->redirect(ADMIN_URL . "jobs/{$id}"); } }); // deactivate job $app->get('/:id/deactivate/:token', 'validateUser', function ($id, $token) use($app) { $j = new Jobs($id); if ($j->deactivateJob($token)) { $job = $j->showJobDetails(); $title = $j->getSlugTitle(); $app->flash('success', "Job {$id} has been deactivated successfully."); $app->redirect(ADMIN_URL . "jobs/{$job->id}/{$title}"); } else { $app->flash('danger', "Job {$id} could not be deactivated."); $app->redirect(ADMIN_URL . "jobs/{$id}"); } }); // show job information $app->get('/:id(/:title)', 'validateUser', function ($id, $title = null) use($app) { $j = new Jobs($id); $job = $j->showJobDetails(); $city = $j->getJobCity($job->city); $category = $j->getJobCategory($job->category); $applications = $j->countJobApplications(); if (isset($job) && $job->id) {
public function sendEmailsToSubscribersMail($job_id) { global $categories, $cities; $message = ''; $content = ''; // get job information $j = new Jobs($job_id); $job = $j->showJobDetails(); $title = $j->getSlugTitle(); $category_name = $categories[$job->category]['name']; $city_name = $cities[$job->city]['name']; $job_link = BASE_URL . "jobs/{$job->id}/{$title}"; $description = Parsedown::instance()->parse($job->description); $content .= "<p>Job Details</p>"; $content .= "<p>-----------</p>"; $content .= "<p><a href={$job_link}>{$job_link}</a></p>"; $content .= "<p>Title: <strong>{$job->title}</strong></p>"; $content .= "<p>Description: {$description}</p>"; if ($job->perks != '') { $content .= "<p>Perks: {$job->perks}</p>"; } $content .= "<p>How to apply: {$job->how_to_apply}</p>"; $content .= "<p>-----------</p>"; // get all users subscribed to the job $users = R::findAll('subscriptions', " is_confirmed=1 AND (category_id=:category_id OR city_id=:city_id) ", array(':category_id' => $job->category, ':city_id' => $job->city)); foreach ($users as $user) { $link = BASE_URL . "subscribe/{$user->id}/delete/{$user->token}"; $name = $user->category_id > 0 ? $category_name : $city_name; $subject = "A new {$name} job was posted at {$this->app_name}"; $message .= "<p>You subcribed to receive {$name} jobs on {$this->app_name}.</p>"; $message .= $content; $message .= "<p>To unsubscribe, click this link to stop receiving alerts.</p>"; $message .= "<p><a href={$link}>{$link}</a></p>"; if ($this->sendNotification($subject, $message, $user->email)) { $update = R::load('subscriptions', $user->id); $update->last_sent = R::isoDateTime(); R::store($update); } } }