Example #1
0
 /**
  * @return Model
  */
 public function model($namespace, $alias = 'a')
 {
     $instance = null;
     if (is_object($namespace)) {
         $instance = $namespace;
     } else {
         if (strpos($namespace, ':')) {
             $namespace = Util::getNamespaceModel($namespace);
         }
         if (!class_exists($namespace)) {
             throw new \Exception("El modelo '{$namespace}' no fue encontrado.");
         }
         $instance = new $namespace();
     }
     $this->propertiesInstance = $this->getPropertiesInstance($instance);
     $this->propertiesInstance['alias'] = $alias;
     $this->Model->setPropertiesInstance($this->propertiesInstance, $this);
     return $this->Model;
 }
Example #2
0
 public function onKernelRequest(GetResponseEvent $event)
 {
     // Si no es una peticion maestra ignora el evento
     if (!$event->isMasterRequest()) {
         return;
     }
     $request = $event->getRequest();
     $rules = $this->Config->get('security', 'access_control');
     foreach ($rules as $rule) {
         $requestMatcher = new RequestMatcher($rule['pattern']);
         // Si es verdadero es una area restringida
         if ($requestMatcher->matches($request)) {
             // Busca en la session si existe una tarjeta del usuario
             // La tajeta debe ser un objecto de serializado que implemente la interfaz CardInterface
             $user_card = $this->CardManager->getCard('user_card');
             // Si la tarjeta existe
             if ($user_card) {
                 $role = $user_card->getRole();
                 // Si no tiene el rol correcto retorna una respuesta para redireccionar
                 if ($role == null || strtoupper($role) != strtoupper($rule['role'])) {
                     // Detiene la propagacion del evento
                     $event->stopPropagation();
                     if ($request->isXmlHttpRequest()) {
                         $event->setResponse(new JsonResponse(array('status' => 'forbidden')), Response::HTTP_FORBIDDEN);
                     } else {
                         $event->setResponse(new redirectResponse(Util::buildUrl($rule['forbidden_route'])));
                     }
                     return;
                 }
             } else {
                 $event->stopPropagation();
                 if ($request->isXmlHttpRequest()) {
                     $event->setResponse(new JsonResponse(array('status' => 'forbidden')), Response::HTTP_FORBIDDEN);
                 } else {
                     $event->setResponse(new redirectResponse(Util::buildUrl($rule['login_route'])));
                 }
                 return;
             }
         }
     }
 }
Example #3
0
 private function buildJoin($namespace, $alias, $type_join)
 {
     $QueryBuilder = $this->getQueryBuilder();
     $type_join = strtoupper($type_join);
     if (strpos($namespace, ':')) {
         $shortNamespace = $namespace;
         $namespace = Util::getNamespaceModel($namespace);
     } else {
         $shortNamespace = Util::getShortNamespaceModel($namespace);
     }
     $instance = new $namespace();
     $relations = $this->propertiesInstance['instance']->getDefinitionRelations();
     if (array_key_exists($shortNamespace, $relations)) {
         $QueryBuilder->from($this->propertiesInstance['table'], $this->propertiesInstance['alias']);
         if ($type_join == 'INNER_JOIN') {
             $QueryBuilder->innerJoin($this->propertiesInstance['alias'], $this->propertiesInstance['prefix'] . $instance::table, $alias, "{$alias}." . $instance::primary . " = {$this->propertiesInstance['alias']}.{$relations[$shortNamespace]['fieldLocal']}");
         } else {
             if ($type_join == 'LEFT_JOIN') {
                 $QueryBuilder->leftJoin($this->propertiesInstance['alias'], $this->propertiesInstance['prefix'] . $instance::table, $alias, "{$alias}." . $instance::primary . " = {$this->propertiesInstance['alias']}.{$relations[$shortNamespace]['fieldLocal']}");
             } else {
                 if ($type_join == 'RIGHT_JOIN') {
                     $QueryBuilder->rightJoin($this->propertiesInstance['alias'], $this->propertiesInstance['prefix'] . $instance::table, $alias, "{$alias}." . $instance::primary . " = {$this->propertiesInstance['alias']}.{$relations[$shortNamespace]['fieldLocal']}");
                 }
             }
         }
     }
     // Si no se ha agregado un selecto se coloca todos los campos de ambos modelos
     if (count($QueryBuilder->getQueryPart('select')) == 0) {
         $QueryBuilder->select("{$this->propertiesInstance['alias']}.*, {$alias}.*");
     }
 }
Example #4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $path_schema = Ki_APP . 'src/storage/schemas/';
     $action = $input->getArgument('action');
     $namespace = $input->getArgument('namespace');
     $yaml = new Parser();
     if (!in_array($action, array('create', 'delete'))) {
         $output->writeln(PHP_EOL . 'El parametro "action" debe ser create o delete. Por defecto es create.' . PHP_EOL);
         exit;
     }
     switch (strtoupper($action)) {
         case 'CREATE':
             if (is_dir(Ki_BUNDLES . $namespace)) {
                 $output->writeln(PHP_EOL . 'Ya existe un bundle con el  mismo espacio de nombre.' . PHP_EOL);
                 exit;
             }
             // Crea el directorio config/
             $this->mkdir(Ki_BUNDLES . $namespace . '/config/schema');
             // Crea el directorio Controllers/
             $this->mkdir(Ki_BUNDLES . $namespace . '/Controllers');
             // Crea el directorio i18n/
             $this->mkdir(Ki_BUNDLES . $namespace . '/i18n');
             // Crea el directorio Main/
             $this->mkdir(Ki_BUNDLES . $namespace . '/Main');
             // Crea el directorio Providers/
             $this->mkdir(Ki_BUNDLES . $namespace . '/Providers');
             // Crea el directorio Services/
             $this->mkdir(Ki_BUNDLES . $namespace . '/Services');
             // Crea el directorio vies/
             $this->mkdir(Ki_BUNDLES . $namespace . '/views/home');
             $GenerateClass = Service::get('generate_class');
             // Crea la clase HomeController
             $GenerateClass->setTemplate('Controller');
             $GenerateClass->setValues(array('bundle' => str_replace('/', '\\', $namespace)));
             $GenerateClass->create(Ki_BUNDLES . $namespace . '/Controllers/HomeController');
             // Crea la clase BundleController
             $GenerateClass->setTemplate('BundleController');
             $GenerateClass->setValues(array('bundle' => str_replace('/', '\\', $namespace)));
             $GenerateClass->create(Ki_BUNDLES . $namespace . '/Main/BundleController');
             // Crea las rutas del bundle
             $GenerateClass->setTemplate('routes');
             $GenerateClass->setValues(array('bundle' => str_replace('/', '\\', $namespace), 'route' => str_replace(array('/', '\\'), '-', strtolower($namespace))));
             $GenerateClass->create(Ki_BUNDLES . $namespace . '/config/routes.cf');
             // Crea la plantilla index.twig
             $GenerateClass->setTemplate('index');
             $GenerateClass->create(Ki_BUNDLES . $namespace . '/views/home/index', array(), '.twig');
             // Crea el HookBundle
             $GenerateClass->setTemplate('HookBundle');
             $GenerateClass->setValues(array('namespace' => str_replace('/', '\\', $namespace)));
             $GenerateClass->create(Ki_BUNDLES . $namespace . '/HookBundle');
             \Kodazzi\Tools\Util::bundle($namespace, 'new');
             $output->writeln(PHP_EOL . 'El bundle ' . str_replace('/', '\\', $namespace) . ' ha sido creado con exito' . PHP_EOL);
             exit;
             break;
         case 'DELETE':
             if (!is_dir(Ki_BUNDLES . $namespace)) {
                 $output->writeln(PHP_EOL . 'No se ha encontrado el bundle' . PHP_EOL);
                 exit;
             }
             \Kodazzi\Tools\Util::bundle($namespace, 'delete');
             $output->writeln(PHP_EOL . 'El bundle ' . str_replace('/', '\\', $namespace) . ' ha sido eliminado con exito' . PHP_EOL);
             break;
     }
 }
Example #5
0
 public function buildUrl($route, $parameters = array(), $locale = null)
 {
     return \Kodazzi\Tools\Util::buildUrl($route, $parameters, $locale);
 }
Example #6
0
 public function __construct(ConfigBuilderInterface $config, SessionInterface $user, UrlGenerator $url_generator)
 {
     $this->User = $user;
     $this->Config = $config;
     $this->UrlGenerator = $url_generator;
     $bundles = Service::getBundles();
     $theme_web = $config->get('app', 'theme_web');
     $theme_admin = $config->get('app', 'theme_admin');
     $enabled_path_themes = $config->get('app', 'enabled_path_themes');
     $path_templates = array(Ki_APP . 'src/layouts', Ki_APP . 'src/templates');
     if ($enabled_path_themes) {
         if (is_dir(Ki_THEMES . $theme_web . '/layouts')) {
             $path_templates[] = Ki_THEMES . $theme_web . '/layouts';
         }
         if (is_dir(Ki_THEMES . $theme_web . '/templates')) {
             $path_templates[] = Ki_THEMES . $theme_web . '/templates';
         }
         if (is_dir(Ki_THEMES . $theme_admin . '/layouts')) {
             $path_templates[] = Ki_THEMES . $theme_admin . '/layouts';
         }
         if (is_dir(Ki_THEMES . $theme_admin . '/templates')) {
             $path_templates[] = Ki_THEMES . $theme_admin . '/templates';
         }
     }
     foreach ($bundles as $bundle) {
         $path_bundles_templates = str_replace('\\', '/', $bundle->getPath() . '/templates');
         if (is_dir($path_bundles_templates)) {
             $path_templates[] = $path_bundles_templates;
         }
     }
     $Twig_Loader_Filesystem = new \Twig_Loader_Filesystem($path_templates);
     $Twig = new \Twig_Environment(null, array('cache' => Ki_CACHE . 'views', 'debug' => Ki_DEBUG));
     // Funcion para construir las url
     $build_url = new \Twig_SimpleFunction('build_url', function ($name_route, $parameters = array(), $locale = null) {
         return \Kodazzi\Tools\Util::buildUrl($name_route, $parameters, $locale);
     });
     // Funcion para construir las url
     $cut_text = new \Twig_SimpleFunction('cut_text', function ($string, $limit = 100, $end_char = '...') {
         return \Kodazzi\Tools\StringProcessor::cutText($string, $limit, $end_char);
     });
     // Funcion para cortar texto muy largo.
     $resume = new \Twig_SimpleFunction('resume', function ($string, $limit = 100, $end_char = '...') {
         return \Kodazzi\Tools\StringProcessor::resume($string, $limit, $end_char);
     });
     // Funcion para dar formato a un numero
     $number_format = new \Twig_SimpleFunction('number_format', function ($number, $decimals = 0, $dec_point = ',', $thousands_sep = '.') {
         return number_format($number, $decimals, $dec_point, $thousands_sep);
     });
     // Funcion para dar formato a un numero
     $date_format = new \Twig_SimpleFunction('date_format', function ($date, $format) {
         return \Kodazzi\Tools\Date::format($date, $format);
     });
     // Funcion para dar formato a un numero
     $get_date = new \Twig_SimpleFunction('get_date', function ($string) {
         return \Kodazzi\Tools\Date::getDate($string);
     });
     // Funcion para indicar si existe un archivo
     $isFile = new \Twig_SimpleFunction('isFile', function ($path, $file) {
         return \Kodazzi\Tools\Util::isFile($path, $file);
     });
     // Funcion para indicar si existe un archivo
     $hash = new \Twig_SimpleFunction('hash', function ($id, $str = 'z6i5v36h3F5', $position = 5, $prefix = '') {
         return \Kodazzi\Tools\Util::hash($id, $str, $position, $prefix);
     });
     // Funcion para indicar si existe un archivo
     $ucfirst = new \Twig_SimpleFunction('ucfirst', function ($string) {
         return ucfirst($string);
     });
     // Funcion para acceder al catalogo de traduccion.
     $i18n = new \Twig_SimpleFunction('i18n', function ($string) {
         return Service::get('translator')->get($string);
     });
     // Funcion para indicar si existe un archivo
     $dump = new \Twig_SimpleFunction('dump', function ($var) {
         ob_start();
         var_dump($var);
         $a = ob_get_contents();
         ob_end_clean();
         return $a;
     });
     $Twig->addFunction($build_url);
     $Twig->addFunction($cut_text);
     $Twig->addFunction($get_date);
     $Twig->addFunction($resume);
     $Twig->addFunction($number_format);
     $Twig->addFunction($isFile);
     $Twig->addFunction($date_format);
     $Twig->addFunction($hash);
     $Twig->addFunction($ucfirst);
     $Twig->addFunction($i18n);
     $Twig->addFunction($dump);
     $this->Twig_Loader_Filesystem = $Twig_Loader_Filesystem;
     $this->Twig = $Twig;
 }
Example #7
0
$<?php 
            echo $model;
            ?>
->addUniqueIndex(<?php 
            echo \Kodazzi\Tools\Util::parsetArrayToString($unique);
            ?>
);
<?php 
        }
        if ($primary) {
            ?>
$<?php 
            echo $model;
            ?>
->setPrimaryKey(<?php 
            echo \Kodazzi\Tools\Util::parsetArrayToString($primary);
            ?>
);
<?php 
        }
        $unique = array();
        $primary = array();
    }
    if (isset($data['options']['timestampable']) && $data['options']['timestampable']) {
        ?>
$<?php 
        echo $model;
        ?>
->addColumn("created", "datetime", array('notnull' => true));
$<?php 
        echo $model;
Example #8
0
 public function setNameModel($namespace)
 {
     if (strpos($namespace, ':')) {
         $namespace = \Kodazzi\Tools\Util::getNamespaceModel($namespace);
     }
     $this->name_model = $namespace;
 }
 public function indentifier($hash = null)
 {
     if ($hash) {
         if ($hash && array_key_exists('_indentifier', $this->attributes) && $this->attributes['_indentifier'] === $hash) {
             $this->attributes['_status'] = 'new';
         } else {
             // Antes de eliminar la data la almacena en la papelera para poder ser usada en la misma peticion.
             $this->trash = $this->attributes;
             $this->clear();
             $this->attributes['_indentifier'] = $hash;
             $this->attributes['_status'] = 'new';
         }
         return;
     }
     // Crea un id por defecto.
     if (!array_key_exists('_indentifier', $this->attributes) || array_key_exists('_indentifier', $this->attributes) && $this->attributes['_indentifier'] == '') {
         $this->attributes['_indentifier'] = \Kodazzi\Tools\Util::hash('h1a3sHhnf6bDgS');
     }
     $this->attributes['_status'] = 'new';
 }