YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/actions/Delete.php

Summary

Maintainability
A
0 mins
Test Coverage
F
0%
<?php
/* +***********************************************************************************
 * The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is:  vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
 * Contributor(s): YetiForce S.A.
 * *********************************************************************************** */

class Vtiger_Delete_Action extends \App\Controller\Action
{
    /**
     * Record model instance.
     *
     * @var Vtiger_Record_Model
     */
    protected $record;

    /** {@inheritdoc} */
    public function checkPermission(App\Request $request)
    {
        if ($request->isEmpty('record', true)) {
            throw new \App\Exceptions\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 406);
        }
        $this->record = Vtiger_Record_Model::getInstanceById($request->getInteger('record'), $request->getModule());
        if (!$this->record->privilegeToDelete()) {
            throw new \App\Exceptions\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 406);
        }
    }

    /** {@inheritdoc} */
    public function process(App\Request $request)
    {
        $this->record->delete();
        $response = new Vtiger_Response();
        if ('List' === $request->getByType('sourceView')) {
            $response->setResult(['notify' => ['type' => 'success', 'text' => \App\Language::translate('LBL_RECORD_HAS_BEEN_DELETED')]]);
        } else {
            $response->setResult($this->record->getModule()->getListViewUrl());
        }
        $response->emit();
    }
}