<?php
namespace App\Controller\Admin01;

/**
 * SelfCollects Controller
 *
 *
 * @method \App\Model\Entity\SelfCollect[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = [])
 */
class SelfCollectsController extends AppController
{

    /**
     * Index method
     *
     * @return \Cake\Http\Response|void
     */
    public function index()
    {
        $selfCollects = $this->paginate($this->SelfCollects);

        $this->set(compact('selfCollects'));
    }

    /**
     * View method
     *
     * @param string|null $id Self Collect id.
     * @return \Cake\Http\Response|void
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
     */
    public function view($id = null)
    {
        $selfCollect = $this->SelfCollects->get($id, [
            'contain' => []
        ]);

        $this->set('selfCollect', $selfCollect);
    }

    /**
     * Add method
     *
     * @return \Cake\Http\Response|null Redirects on successful add, renders view otherwise.
     */
    public function add()
    {
        $selfCollect = $this->SelfCollects->newEntity();
        if ($this->request->is('post')) {
            $selfCollect = $this->SelfCollects->patchEntity($selfCollect, $this->request->getData());
            if ($this->SelfCollects->save($selfCollect)) {
                $this->Flash->admin01_success(__('The self collect has been saved.'));

                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->admin01_error(__('The self collect could not be saved. Please, try again.'));
        }
        $this->set(compact('selfCollect'));
    }

    /**
     * Edit method
     *
     * @param string|null $id Self Collect id.
     * @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise.
     * @throws \Cake\Network\Exception\NotFoundException When record not found.
     */
    public function edit($id = null)
    {
        $selfCollect = $this->SelfCollects->get($id, [
            'contain' => []
        ]);
        if ($this->request->is(['patch', 'post', 'put'])) {
            $selfCollect = $this->SelfCollects->patchEntity($selfCollect, $this->request->getData());
            if ($this->SelfCollects->save($selfCollect)) {
                $this->Flash->admin01_success(__('The self collect has been saved.'));

                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->admin01_error(__('The self collect could not be saved. Please, try again.'));
        }
        $this->set(compact('selfCollect'));
    }

    /**
     * Delete method
     *
     * @param string|null $id Self Collect id.
     * @return \Cake\Http\Response|null Redirects to index.
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
     */
    public function delete($id = null)
    {
        $this->request->allowMethod(['post', 'delete']);
        $selfCollect = $this->SelfCollects->get($id);
        if ($this->SelfCollects->delete($selfCollect)) {
            $this->Flash->admin01_success(__('The self collect has been deleted.'));
        } else {
            $this->Flash->admin01_error(__('The self collect could not be deleted. Please, try again.'));
        }

        return $this->redirect(['action' => 'index']);
    }
}
