FOF30\Controller\DataController::deleteOrTrash PHP Method

deleteOrTrash() protected method

protected deleteOrTrash ( $forceDelete = false )
    protected function deleteOrTrash($forceDelete = false)
    {
        // CSRF prevention
        $this->csrfProtection();
        $model = $this->getModel()->savestate(false);
        $ids = $this->getIDsFromRequest($model, false);
        $error = null;
        try {
            $status = true;
            foreach ($ids as $id) {
                $model->find($id);
                $userId = $this->container->platform->getUser()->id;
                if ($model->isLocked($userId)) {
                    $model->checkIn($userId);
                }
                if ($forceDelete) {
                    $model->forceDelete();
                } else {
                    $model->delete();
                }
            }
        } catch (\Exception $e) {
            $status = false;
            $error = $e->getMessage();
        }
        // Redirect
        if ($customURL = $this->input->getBase64('returnurl', '')) {
            $customURL = base64_decode($customURL);
        }
        $url = !empty($customURL) ? $customURL : 'index.php?option=' . $this->container->componentName . '&view=' . $this->container->inflector->pluralize($this->view) . $this->getItemidURLSuffix();
        if (!$status) {
            $this->setRedirect($url, $error, 'error');
        } else {
            $textKey = strtoupper($this->container->componentName . '_LBL_' . $this->container->inflector->singularize($this->view) . '_DELETED');
            $this->setRedirect($url, \JText::_($textKey));
        }
    }