/var/www/vhosts/ihelp.ro/httpdocs/src/Controller/Admin
Edit: /var/www/vhosts/ihelp.ro/httpdocs/src/Controller/Admin/BannersController.php (4540B)
paginate = [
'limit' => ADMIN_PAGE_LIMIT,
'conditions' => $conditions,
'sortableFields' => ['Banners.id', 'Banners.name', 'Banners.is_active', 'Banners.created']
];
$banners = $this->paginate($this->Banners);
$positions = $this->Banners->find()
->select(['position', 'position'])
->all();
$positionList = Hash::combine($positions->toArray(), '{n}.position', '{n}.position');
$positionList = [null => __('All')] + $positionList;
$this->set(compact('banners', 'positionList'));
}
/**
* View method
*
* @param string|null $id Banner id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function view($id = null)
{
$banner = $this->Banners->get($id, [
'contain' => [],
]);
$this->set(compact('banner'));
}
/**
* Add method
*
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/
public function add()
{
$banner = $this->Banners->newEmptyEntity();
if ($this->request->is('post')) {
$data = $this->request->getData();
$image = $data['image_path'];
$name = $image->getClientFilename();
$image->moveTo(WWW_ROOT . 'img' . DS . $name);
$data['image_path'] = $name;
$banner = $this->Banners->patchEntity($banner, $data);
if ($this->Banners->save($banner)) {
$this->Flash->success(__('The banner has been saved.'));
return $this->redirect(['prefix' => 'Admin', 'controller' => 'Banners', 'action' => 'index']);
}
$this->Flash->error(__('The banner could not be saved. Please, try again.'));
}
$this->set(compact('banner'));
}
/**
* Edit method
*
* @param string|null $id Banner id.
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function edit($id = null)
{
$banner = $this->Banners->get($id);
if ($this->request->is(['patch', 'post', 'put'])) {
$data = $this->request->getData();
$image = $data['image_path'];
if ($image->getError() == 0) {
$data = $this->request->getData();
$image = $data['image_path'];
$name = $image->getClientFilename();
$image->moveTo(WWW_ROOT . 'img' . DS . $name);
$data['image_path'] = $name;
} else {
unset($data['image_path']);
}
$banner = $this->Banners->patchEntity($banner, $data);
if ($this->Banners->save($banner)) {
$this->Flash->success(__('The banner has been saved.'));
return $this->redirect(['prefix' => 'Admin', 'controller' => 'Banners', 'action' => 'index']);
}
$this->Flash->error(__('The banner could not be saved. Please, try again.'));
}
$this->set(compact('banner'));
}
/**
* Delete method
*
* @param string|null $id Banner id.
* @return \Cake\Http\Response|null|void Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$banner = $this->Banners->get($id);
if ($this->Banners->delete($banner)) {
$this->Flash->success(__('The banner has been deleted.'));
} else {
$this->Flash->error(__('The banner could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
}