Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DeleteItemsProcess extends Nette\Object
- {
- private $model;
- public function __construct(Nette\Http\User $user, ItemsModel $model)
- {
- if(!$user->isInRole('administrator')) {
- throw new Nette\InvalidStateException("User is not allowed to delete items");
- }
- $this->model = $model;
- }
- public function run($itemId)
- {
- $item = $this->model->getItem($itemId);
- $item->delete();
- $contents = $this->model->findAllContents(NULL, array('item_id' => $itemId));
- foreach ($contents as $content){
- $content->delete();
- }
- }
- }
- // signal
- public function handleDelete($id)
- {
- try {
- $process = new DeleteItemsProcess($this->getUser(), $this->model);
- $process->run($id);
- $this->flashMessage('Item has been deleted');
- } catch (Nette\InvalidStateException $e) { }
- $this->redirect('this');
- }
Advertisement
Add Comment
Please, Sign In to add comment