Ip\Internal\Grid\Model\Table::update PHP Method

update() protected method

protected update ( $data )
    protected function update($data)
    {
        if (empty($data[$this->subgridConfig->idField()])) {
            throw new \Ip\Exception('Missing parameters. Most likely \'AUTO_INCREMENT\' attribute is missing on the database id field');
        }
        $this->runTransformations($data);
        $recordId = $data[$this->subgridConfig->idField()];
        $display = $this->getDisplay();
        $updateForm = $display->updateForm($recordId);
        $errors = $updateForm->validate($data);
        if ($errors) {
            $data = array('error' => 1, 'errors' => $errors);
        } else {
            $newData = $updateForm->filterValues($data);
            $callables = $this->subgridConfig->beforeUpdate();
            if ($callables) {
                if (is_array($callables) && !is_callable($callables)) {
                    foreach ($callables as $callable) {
                        call_user_func($callable, $recordId, $newData);
                    }
                } else {
                    call_user_func($callables, $recordId, $newData);
                }
            }
            $actions = $this->getActions();
            $actions->update($recordId, $newData);
            $callables = $this->subgridConfig->afterUpdate();
            if ($callables) {
                if (is_array($callables) && !is_callable($callables)) {
                    foreach ($callables as $callable) {
                        call_user_func($callable, $recordId, $newData);
                    }
                } else {
                    call_user_func($callables, $recordId, $newData);
                }
            }
            $display = $this->getDisplay();
            $html = $display->fullHtml();
            $commands[] = Commands::setHtml($html);
            $data = array('error' => 0, 'commands' => $commands);
        }
        return $data;
    }