<?php

/**
 *
 * PHP Pro Bid $Id$ c4UGMY1shkPWkoGLnJP37qgFavx0dB2P0BTKuh5VZ1w=
 *
 * @link        http://www.phpprobid.com
 * @copyright   Copyright (c) 2017 Online Ventures Software & CodeCube SRL
 * @license     http://www.phpprobid.com/license Commercial License
 *
 * @version     7.9 [rev.7.9.01]
 */

namespace Listings\Controller;

use Ppb\Controller\Action\AbstractAction,
    Cube\Controller\Front,
    Ppb\Service,
    Listings\Form;

class Search extends AbstractAction
{

    public function Advanced()
    {
        $form = new Form\Search(array('advanced', 'item'));

        $params = $this->getRequest()->getParams();
        $form->setData($params);

        $view = Front::getInstance()->getBootstrap()->getResource('view');

        $formAction = $view->url(array('module' => 'listings', 'controller' => 'browse', 'action' => 'index'));
        $form->setAction($formAction);

        return array(
            'form'     => $form,
            'headline' => $form->getTitle(),
        );
    }

    public function Basic()
    {
        $storeId = $this->getRequest()->getParam('store_id');
        $listingsSelect = $this->getRequest()->getParam('listings_select');
        $store = null;

        if ($storeId) {
            $usersService = new Service\Users();
            $store = $usersService->findBy('id', $storeId);
        }

        $form = new Form\Search(array('basic', 'item'), null, $store, $listingsSelect);
        $form->setData(
            $this->getRequest()->getParams())
            ->generateBasicForm();

        return array(
            'form' => $form,
        );
    }

    public function Stores()
    {
        $form = new Form\Search(array('stores'));
        $form->setData(
            $this->getRequest()->getParams())
            ->generateBasicForm();

        return array(
            'form' => $form,
        );
    }

}

