Exemple #1
0
 public function action_delete($id = null)
 {
     if ($job = \Model\Job::find($id)) {
         $job->delete();
         \Session::set_flash('success', 'Deleted job #' . $id);
     } else {
         \Session::set_flash('error', 'Could not delete job #' . $id);
     }
     \Response::redirect('admin/job');
 }
Exemple #2
0
 public function action_view($id = null)
 {
     is_null($id) and Response::redirect('job');
     $data['job'] = \Model\Job::find($id);
     $data['actions'] = ['back' => ['label' => 'Back', 'url' => '/']];
     if (\Auth::check()) {
         list(, $userid) = \Auth::get_user_id();
         // check if the job has been saved by the current user
         $data['favorite'] = \Model\Favorite::find('all', array('where' => array(array('user_id', $userid), array('job_id', $id))));
     }
     $this->template->title = "Jobs";
     $this->template->content = View::forge('job/_details.twig', $data);
 }
Exemple #3
0
 public function action_add($id = null)
 {
     if ($id) {
         $job = \Model\Job::find($id);
         list(, $userid) = \Auth::get_user_id();
         if ($job and $userid) {
             $favorite = \Model\Favorite::find('first', array('where' => array(array('user_id', $userid), array('job_id', $id))));
             if ($favorite) {
                 $favorite->delete();
                 unset($favorite);
                 \Session::set_flash('success', 'The job has been removed from your favorites.');
                 \Response::redirect('/job/view/' . $job->id . '');
             }
             $props = array('user_id' => $userid, 'job_id' => $id);
             $favorite = new \Model\Favorite($props);
             try {
                 $favorite->save();
             } catch (Exception $e) {
                 \Session::set_flash('error', 'Job already saved');
                 \Response::redirect('/job/view/' . $job->id . '');
             }
             \Session::set_flash('success', 'Job #' . $job->id . ' has been added to your favorites.');
             \Response::redirect('/job/view/' . $job->id . '');
         } else {
             if ($job == null) {
                 \Session::set_flash('error', 'This job doesn\'t exist.');
                 \Response::redirect('/');
             } else {
                 if ($userid == null) {
                     \Session::set_flash('error', 'You must be logged in in order to add a job to your favorite');
                     \Response::redirect('/');
                 }
             }
         }
     } else {
         \Response::redirect('/');
     }
 }