FOF30\Controller\DataController::getCrudTask PHP Метод

getCrudTask() защищенный Метод

Determines the CRUD task to use based on the view name and HTTP verb used in the request.
protected getCrudTask ( ) : string
Результат string The CRUD task (browse, read, edit, delete)
    protected function getCrudTask()
    {
        // By default, a plural view means 'browse' and a singular view means 'edit'
        $view = $this->input->getCmd('view', null);
        $task = $this->container->inflector->isPlural($view) ? 'browse' : 'edit';
        // If the task is 'edit' but there's no logged in user switch to a 'read' task
        if ($task == 'edit' && !$this->container->platform->getUser()->id) {
            $task = 'read';
        }
        // Check if there is an id passed in the request
        $id = $this->input->get('id', null, 'int');
        if ($id == 0) {
            $ids = $this->input->get('ids', array(), 'array');
            if (!empty($ids)) {
                $id = array_shift($ids);
            }
        }
        // Get the request HTTP verb
        $requestMethod = 'GET';
        if (isset($_SERVER['REQUEST_METHOD'])) {
            $requestMethod = strtoupper($_SERVER['REQUEST_METHOD']);
        }
        // Alter the task based on the verb
        switch ($requestMethod) {
            // POST and PUT result in a record being saved; no ID means creating a new record
            case 'POST':
            case 'PUT':
                $task = 'save';
                break;
                // DELETE results in a record being deleted, as long as there is an ID
            // DELETE results in a record being deleted, as long as there is an ID
            case 'DELETE':
                if ($id) {
                    $task = 'remove';
                }
                break;
                // GET results in browse, edit or add depending on the ID
            // GET results in browse, edit or add depending on the ID
            case 'GET':
            default:
                // If it's an edit without an ID or ID=0, it's really an add
                if ($task == 'edit' && $id == 0) {
                    $task = 'add';
                }
                break;
        }
        return $task;
    }