<?php

namespace ModulesGarden\Servers\OpenXchange\Core\UI\Traits;

use ModulesGarden\Servers\OpenXchange\Core\Http\Request;

/**
 * Search field related functions
 *
 * @author Sławomir Miśkowicz <slawomir@modulesgarden.com>
 */
trait Searchable
{
    protected $searchable = false;

    public function isSearchable()
    {
        return $this->searchable;
    }

    protected function getSearchKey()
    {
        $request = Request::build();
        if ($request->getValue('sSearch', false))
        {
            return $request->getValue('sSearch');
        }

        return false;
    }

    public function insertSearchForm()
    {
        if ($this->searchable)
        {
            $searchForm = new \ModulesGarden\Servers\OpenXchange\Core\UI\Searchable();

            return $searchForm->getHtml();
        }

        return '';
    }
    
    public function insertHiddenSearchForm()
    {
        if ($this->searchable)
        {
            $searchForm = new \ModulesGarden\Servers\OpenXchange\Core\UI\HiddenSearchable();

            return $searchForm->getHtml();
        }

        return '';
    }    
}
