/var/www/vhosts/ihelp.ro/httpdocs/src/Controller/Admin
Edit: /var/www/vhosts/ihelp.ro/httpdocs/src/Controller/Admin/CategoriesController.php (4498B)
paginate = [
'limit' => ADMIN_PAGE_LIMIT,
'contain' => ['ParentCategories'],
'order' => ['Categories.lft' => 'ASC']
];
$categories = $this->paginate($this->Categories);
$this->set(compact('categories'));
}
/**
* View method
*/
public function view($id = null)
{
if (!empty($id)) {
$category = $this->Categories->get($id, [
'contain' => [],
]);
}
$this->set(compact('category'));
}
/**
* Add method
*/
public function add()
{
$category = $this->Categories->newEmptyEntity();
$categories = $this->Categories->find('list')
->where(['Categories.parent_id IS' => null]);
if ($this->request->is('post')) {
$category = $this->Categories->patchEntity($category, $this->request->getData());
if ($this->Categories->save($category)) {
$this->Flash->success(__('The category has been saved.'));
return $this->redirect(['action' => 'edit', $category->id]);
}
$this->Flash->error(__('The category could not be saved. Please, try again.'));
}
$this->set(compact('category', 'categories'));
}
/**
* Edit method
*/
public function edit($id = null)
{
if (!empty($id) && is_numeric($id)) {
$category = $this->Categories->get($id, [
'contain' => [],
]);
$categories = $this->Categories->find('list')
->where(['Categories.parent_id IS' => null]);
if ($this->request->is(['patch', 'post', 'put'])) {
$category = $this->Categories->patchEntity($category, $this->request->getData());
if ($this->Categories->save($category)) {
$this->Flash->success(__('The category has been saved.'));
return $this->redirect($this->referer());
}
$this->Flash->error(__('The category could not be saved. Please, try again.'));
return $this->redirect(['prefix' => 'Admin', 'controller' => 'Categories', 'action' => 'index']);
}
} else {
$this->Flash->error(__('Oops. Please, try again.'));
return $this->redirect(['prefix' => 'Admin', 'controller' => 'Categories', 'action' => 'index']);
}
$this->set(compact('category', 'categories'));
}
public function changePosition($move, $id)
{
$this->autoRender = false;
if (!empty($id && is_numeric($id))) {
$categories = $this->Categories;
$node = $categories->get($id);
switch ($move) {
case 'moveup':
$categories->moveUp($node);
break;
case 'movedown':
$categories->moveDown($node);
break;
default:
break;
}
$this->Flash->success(__('The position has been changed.'));
} else {
$this->Flash->error(__('Oops. Please, try again.'));
}
return $this->redirect($this->referer());
}
public function recover()
{
$this->Categories->recover();
$this->Flash->success(__('Categories are recovered.'));
return $this->redirect(['prefix' => 'Admin', 'controller' => 'Categories', 'action' => 'index']);
}
/**
* Delete method
*/
public function delete($id = null)
{
if (!empty($id) && is_numeric($id)) {
$this->request->allowMethod(['post', 'delete']);
$category = $this->Categories->get($id);
if ($this->Categories->delete($category)) {
$this->Flash->success(__('The category has been deleted.'));
} else {
$this->Flash->error(__('The category could not be deleted. Please, try again.'));
}
} else {
$this->Flash->error(__('Oops. Please, try again.'));
}
return $this->redirect(['prefix' => 'Admin', 'controller' => 'Categories', 'action' => 'index']);
}
}