<?php

/**
 * Action class for rtgrid_edit_model
 */
class rtgrid_edit_action extends rtgrid_top_action
{

    public function __construct($name = '', $text = '', $callback = '', $message = '', $template = '')
    {
        $this->name = (!empty($name)) ? 'rtgrid_action_' . $name : '';
        $this->text = $text;
        $this->callback = $callback;
        $this->message = htmlspecialchars($message);
        $this->template = $template;
    }

    public function get_template()
    {
        if (empty($this->template)) {
            $this->template = '<input type="submit" class="btn" name="{action_name}" value="{action_text}" />';
        }

        return $this->_prepare_template();
    }

    protected function _prepare_template($row = array())
    {
        $template = $this->template;
        $row = array(
            'action_name' => $this->name,
            'action_text' => $this->text
        );
        foreach ($row as $key => $value) {
            $template = str_replace('{' . $key . '}', $value, $template);
        }

        return $template;
    }

}
