public function valid() { $default = '^[a-zA-Z\\s]+$'; // Reemplaza todas las vocales acentuadas $value = \Kodazzi\Tools\StringProcessor::replaceVowels($this->value); if ($this->pattern) { $default = $this->pattern; } if (preg_match('/' . $default . '/', $value)) { return true; } return false; }
public function valid() { $default = '^[\\w\\s\\/\\-\\_\\&\\;\\#\\.\\,\\?\\¿\\!\\¡\\(\\)\\{\\}]+$'; // Reemplaza todas las vocales acentuadas $value = \Kodazzi\Tools\StringProcessor::replaceVowels($this->value); if ($this->pattern) { $default = $this->pattern; } if (preg_match('/' . $default . '/', $value)) { return true; } return false; }
public function insert($data) { $QueryBuilder = $this->getQueryBuilder(); if ($this->propertiesInstance['has_sluggable']) { if (!array_key_exists('slug', $data)) { $slug = ''; $fields_slug = $this->propertiesInstance['instance']->getFieldsSluggable(); foreach ($fields_slug as $field_slug) { $slug .= $data[$field_slug] . '-'; } $data['slug'] = \Kodazzi\Tools\StringProcessor::slug($slug); } } if ($this->propertiesInstance['has_timestampable']) { $DateTime = new \DateTime('NOW'); $timestamp = $DateTime->format('Y-m-d H:i:s'); if (!array_key_exists('created', $data)) { $data['created'] = $timestamp; } if (!array_key_exists('updated', $data)) { $data['updated'] = $timestamp; } } $values = array(); $parameters = array(); foreach ($data as $field => $value) { $values[$field] = ":{$field}"; $parameters[":{$field}"] = $value; } return $QueryBuilder->insert($this->propertiesInstance['table'], $data)->values($values)->setParameters($parameters)->execute(); }
public function save($instance) { $this->propertiesInstance = $this->getPropertiesInstance($instance); $this->propertiesInstance['alias'] = 'a'; $this->Model->setPropertiesInstance($this->propertiesInstance, $this); $primary = $this->propertiesInstance['primary']; $data = array(); foreach ($this->propertiesInstance['fields'] as $property) { $field = $property->name; $data[$field] = $instance->{$field}; } // Se verifica si el modelo tiene el metodo getFieldsSluggable if ($this->propertiesInstance['has_sluggable']) { // Si en la data existe un campo slug se utiliza en lugar de crearlo if (!array_key_exists('slug', $data)) { $slug = ''; $fields_slug = $instance->getFieldsSluggable(); foreach ($fields_slug as $field_slug) { $slug .= $data[$field_slug] . '-'; } $data['slug'] = \Kodazzi\Tools\StringProcessor::slug($slug); } } // Verifica si el campo primary existe y contiene algun valor if (array_key_exists($this->propertiesInstance['primary'], $data) && $data[$this->propertiesInstance['primary']]) { unset($data[$this->propertiesInstance['primary']]); // Intentara actualizar la instancia en la bd // Verifica que exista el registro en la bd if ($this->Model->exist($instance->{$primary})) { // Retorna la cantidad de filas afectadas. $result = $this->Model->update($data, $instance->{$primary}); $this->identifier = $instance->{$primary}; return true; } throw new \Exception('El objecto con ' . $primary . ' = ' . $instance->{$this}->propertiesInstance['primary'] . ' no fue encontrado en la BD.'); } $result = $this->Model->insert($data); return $result ? true : false; }
static function bundle($namespace, $action) { $namespace = str_replace('/', '\\', $namespace); $bundles = \Service::getBundles(); $namespace_slug = \Kodazzi\Tools\StringProcessor::slug($namespace); $bundles_activated = array(); $action = strtolower($action); if (!in_array($action, array('new', 'delete', 'deactivate'))) { throw new Exception("El parámetro para el método debe ser 'new' o 'delete'"); } foreach ($bundles as $bundle) { $bundle_slug = \Kodazzi\Tools\StringProcessor::slug($bundle->getNameSpace()); $bundles_activated[$bundle_slug] = trim($bundle->getNameSpace(), '\\'); } if ($action == 'new') { if (!array_key_exists($namespace_slug, $bundles_activated)) { $bundles_activated[$namespace_slug] = trim($namespace, '\\'); } } else { if ($action == 'delete' || $action == 'deactivate') { unset($bundles_activated[$namespace_slug]); } } // Crea la clase AppKernel $GenerateClass = \Service::get('generate_class'); $GenerateClass->setTemplate('bundles.cf'); $GenerateClass->create(Ki_APP . 'config/bundles.cf', array('bundles' => $bundles_activated)); // Elimina el directorio del bundle if ($action == 'delete' && is_dir(Ki_BUNDLES . $namespace)) { $fs = new \Symfony\Component\Filesystem\Filesystem(); $fs->remove(Ki_BUNDLES . $namespace); } }
public function slug($string) { $string = \Kodazzi\Tools\StringProcessor::slug($string); return $string; }
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; }