<?php

//require_once('lib/sfYaml.php');
/**
 * servicios_yaml actions.
 *
 * @package    canon
 * @subpackage servicios_yaml
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class servicios_yamlActions extends sfActions {

    /**
     * Executes list action
     *
     * @param sfRequest $request A request object
     */
    public function executeList(sfWebRequest $request) {


        try {

            //validar root 
            if (isset($request['root'])) {

                //name-atrib
                if ($request['root'] == 0) {

                    $arrayName = array();

                    $array = sfYaml::load(dirname(__FILE__) . '/../../../config/app-gwt.yml');

                    $int = 0;
                    foreach ($array as $routeName => $routeData) {
                        $arrayName[$int++]['name'] = $routeName;
                    }

//            print_r($arrayName);
//            var_dump($arrayName);
//            die();

                    $this->list_data = $arrayName;
                    $this->logMessage("[SERVICIOS_YAML] Consulta exitosa.");
                } elseif (isset($request['name'])) {

                    $arrayAtrib = array();

                    $array = sfYaml::load(dirname(__FILE__) . '/../../../config/app-gwt.yml');

                    $int = 0;
                    foreach ($array as $routeName => $routeData) {
                        foreach ($routeData as $key => $value) {
                            if ($routeName == $request['name']) {
                                $arrayAtrib[$int][$key] = $value;
                            }
                        }
                        $int++;
                    }

//            print_r($arrayAtrib);
//            var_dump($arrayAtrib);
//            die();

                    $this->list_data = $arrayAtrib;
                    $this->logMessage("[SERVICIOS_YAML] Consulta exitosa.");
                } else {
                    $this->list_data = array();
                    $this->logMessage("[SERVICIOS_YAML] No esta variable name.");
                }
            } else {

                $array = sfYaml::load(dirname(__FILE__) . '/../../../config/app-gwt.yml');

//            foreach ($array as $value) {
//                echo $value;
//            }
//            print_r($array);
//            var_dump($data);
//            die();

                $this->list_data = $array;
                $this->logMessage("[SERVICIOS_YAML] Consulta exitosa.");
            }
        } catch (ParseException $e) {

            $this->status = 1;
            $this->mensajeError = "ERROR!!! Unable to parse the YAML string: %s";
            $this->list_data = array();
            $this->logMessage("ERROR!!! Unable to parse the YAML string: %s");
            $this->logMessage($e->getMessage());
        } catch (Exception $e) {

            $this->status = 1;
            $this->mensajeError = "ERROR!!!";
            $this->list_data = array();
            $this->logMessage("ERROR!!!");
            $this->logMessage($e->getMessage());
        }
    }

}
