<?php

App::uses('AppController', 'Controller');

/**
 * JobOpportunities Controller
 *
 * @property JobOpportunity $JobOpportunity
 */
class JobOpportunitiesController extends AppController {

    public $components = array(
        'Recaptcha'
    );

    /**
     * beforeFilter
     *
     * @return void
     */
    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow(
            'index'
        );
    }

    /**
     * admin_index method
     *
     * @return void
     */
    public function admin_index() {
        $this->JobOpportunity->recursive = 0;
        $this->set('jobOpportunities', $this->paginate());
    }

    /**
     * admin_add method
     *
     * @return void
     */
    public function admin_add() {
        if ($this->request->is('post')) {
            $this->JobOpportunity->create();
            if ($this->JobOpportunity->save($this->request->data)) {
                $this->Session->setFlash(__('The job opportunity has been saved'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The job opportunity could not be saved. Please, try again.'));
            }
        }
    }

    /**
     * admin_edit method
     *
     * @param string $id
     * @return void
     */
    public function admin_edit($id = null) {
        $this->JobOpportunity->id = $id;
        if (!$this->JobOpportunity->exists()) {
            throw new NotFoundException(__('Invalid job opportunity'));
        }
        if ($this->request->is('post') || $this->request->is('put')) {
            if ($this->JobOpportunity->save($this->request->data)) {
                $this->Session->setFlash(__('The job opportunity has been saved'));
                $this->redirect(array('action' => 'edit', $id));
            } else {
                $this->Session->setFlash(__('The job opportunity could not be saved. Please, try again.'));
            }
        } else {
            $this->request->data = $this->JobOpportunity->read(null, $id);
        }
    }

    /**
     * admin_delete method
     *
     * @param string $id
     * @return void
     */
    public function admin_delete($id = null) {
        if (!$this->request->is('post')) {
            throw new MethodNotAllowedException();
        }
        $this->JobOpportunity->id = $id;
        if (!$this->JobOpportunity->exists()) {
            throw new NotFoundException(__('Invalid job opportunity'));
        }
        if ($this->JobOpportunity->delete()) {
            $this->Session->setFlash(__('Job opportunity deleted'));
            $this->redirect(array('action' => 'index'));
        }
        $this->Session->setFlash(__('Job opportunity was not deleted'));
        $this->redirect(array('action' => 'index'));
    }

    /**
     * admin_index method
     *
     * @return void
     */
    public function index() {
        $this->set('title_for_layout', 'Bemmelhor Vagas Disponíveis');

        // montando o meta especifico da pagina
        $node = array();
        $node['Node']['meta_og_title'] = 'Bemmelhor Vagas Disponíveis';
        $node['Node']['meta_og_description'] = 'Veja as vagas disponíveis na Bemmelhor Soluções Inteligentes';
        $node['Node']['meta_keywords'] = 'vagas, emprego, estágio';
        $node['Node']['meta_article_session'] = 'Emprego, Business';
        $node['Node']['slug'] = 'vagas-disponiveis';
        $node['Node']['type'] = '';
        $node['Node']['banner'] = 'https://bemmelhor.com.br/theme/BmSpeed/img/banner-bemmelhor.png';
        $node['Node']['created'] = '2018-10-10';
        $node['Node']['updated'] = '2018-10-20';

        $this->JobOpportunity->recursive = 0;
        $this->set('jobOpportunities', $this->paginate());
        $this->set(compact('node'));
    }

}
