<?php

require_once TOOLKIT . '/class.datasource.php';

class datasourcelogged_in_author extends AuthorDatasource
{
    public $dsParamROOTELEMENT = 'logged-in-author';
    public $dsParamORDER = 'desc';
    public $dsParamREDIRECTONEMPTY = 'no';
    public $dsParamREDIRECTONFORBIDDEN = 'no';
    public $dsParamREDIRECTONREQUIRED = 'no';
    public $dsParamSORT = 'id';

    public $dsParamFILTERS = array(
        'username' => '{$cookie-username:0}',
    );

    public $dsParamINCLUDEDELEMENTS = array(
        'username'
    );

    public function __construct($env = null, $process_params = true)
    {
        parent::__construct($env, $process_params);
        $this->_dependencies = array();
    }

    public function about()
    {
        return array(
            'name' => 'Logged in Author',
            'author' => array(
                'name' => 'Symphony Team',
                'website' => 'http://getsymphony.com',
                'email' => 'team@getsymphony.com'),
            'version' => 'Symphony 2.5.0',
            'release-date' => '2014-09-15T10:29:14+00:00'
        );
    }

    public function getSource()
    {
        return 'authors';
    }

    public function allowEditorToParse()
    {
        return true;
    }

    public function execute(array &$param_pool = null)
    {
        $result = new XMLElement($this->dsParamROOTELEMENT);

        try{
            $result = parent::execute($param_pool);
        } catch (FrontendPageNotFoundException $e) {
            // Work around. This ensures the 404 page is displayed and
            // is not picked up by the default catch() statement below
            FrontendPageNotFoundExceptionHandler::render($e);
        } catch (Exception $e) {
            $result->appendChild(new XMLElement('error', $e->getMessage() . ' on ' . $e->getLine() . ' of file ' . $e->getFile()));
            return $result;
        }

        if ($this->_force_empty_result) {
            $result = $this->emptyXMLSet();
        }

        if ($this->_negate_result) {
            $result = $this->negateXMLSet();
        }

        return $result;
    }
}