<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Luis
 * Date: 16/12/13
 * Time: 20:55
 * To change this template use File | Settings | File Templates.
 */

use Fuel\Core\DB;
use Fuel\Core\Response;
use \Parser\View;
use Auth\Auth;

class Controller_Recetario_Index extends \Controller_App{



    public function get_index(){

        $view = View::forge('recetario/index.twig');

        //Titulo de la vista
        $view->title = "Recetario";

        $view->groups_filters = $this->ws_options_get();

        $view->recipes = $this->ws_recipe_get();

        return Response::forge($view);
    }

    public function post_index(){

        $view = View::forge('recetario/index.twig');

        //Titulo de la vista
        $view->title = "Recetario";

        $view->groups_filters = $this->ws_options_get();

        $inputs = array();

        $criterio_options = array();

        // Preparamos el array para que lo acepte la API
        if(\Input::post('desc') != ""){

            $inputs['desc'] = \Input::post('desc');

        }

        if(!is_null(\Input::post('flags_or'))){

            $inputs['flags_or'] = implode(",",\Input::post('flags_or'));
            $criterio_options = array_merge($criterio_options,\Input::post('flags_or'));

        }

        if(!is_null(\Input::post('flags'))){

            $inputs['flags'] = implode(",",\Input::post('flags'));
            $criterio_options = array_merge($criterio_options,\Input::post('flags'));

        }

        $view->recipes = $this->ws_recipes_post($inputs);

        $view->criterio_desc = \Input::post('desc');

        $view->criterio_options = $criterio_options;

        return Response::forge($view);

    }

}